From owner-svn-src-all@freebsd.org Fri Jun 28 00:36:28 2019 Return-Path: Delivered-To: svn-src-all@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 19CF015D336F; Fri, 28 Jun 2019 00:36:28 +0000 (UTC) (envelope-from mhorne@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) server-signature RSA-PSS (4096 bits) client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id AF13080EC3; Fri, 28 Jun 2019 00:36:27 +0000 (UTC) (envelope-from mhorne@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 8A81D1F2CF; Fri, 28 Jun 2019 00:36:27 +0000 (UTC) (envelope-from mhorne@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id x5S0aRbR071941; Fri, 28 Jun 2019 00:36:27 GMT (envelope-from mhorne@FreeBSD.org) Received: (from mhorne@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id x5S0aRxM071939; Fri, 28 Jun 2019 00:36:27 GMT (envelope-from mhorne@FreeBSD.org) Message-Id: <201906280036.x5S0aRxM071939@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: mhorne set sender to mhorne@FreeBSD.org using -f From: Mitchell Horne Date: Fri, 28 Jun 2019 00:36:27 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-12@freebsd.org Subject: svn commit: r349484 - in stable/12/sys/riscv: include riscv X-SVN-Group: stable-12 X-SVN-Commit-Author: mhorne X-SVN-Commit-Paths: in stable/12/sys/riscv: include riscv X-SVN-Commit-Revision: 349484 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Rspamd-Queue-Id: AF13080EC3 X-Spamd-Bar: -- Authentication-Results: mx1.freebsd.org X-Spamd-Result: default: False [-2.97 / 15.00]; local_wl_from(0.00)[FreeBSD.org]; NEURAL_HAM_MEDIUM(-1.00)[-0.999,0]; NEURAL_HAM_SHORT(-0.97)[-0.973,0]; ASN(0.00)[asn:11403, ipnet:2610:1c1:1::/48, country:US]; NEURAL_HAM_LONG(-1.00)[-1.000,0] X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 28 Jun 2019 00:36:28 -0000 Author: mhorne Date: Fri Jun 28 00:36:26 2019 New Revision: 349484 URL: https://svnweb.freebsd.org/changeset/base/349484 Log: MFC r346021: RISC-V: initialize pcpu slightly earlier In certain scenarios, it is possible for PCPU data to be accessed before it has been initialized (e.g. during printf if the kernel was built with the TSLOG option). Initialize the PCPU pointer for hart 0 at the beginning of initriscv() rather than near the end. Approved by: markj (mentor) Modified: stable/12/sys/riscv/include/pcpu.h stable/12/sys/riscv/riscv/machdep.c Modified: stable/12/sys/riscv/include/pcpu.h ============================================================================== --- stable/12/sys/riscv/include/pcpu.h Fri Jun 28 00:14:12 2019 (r349483) +++ stable/12/sys/riscv/include/pcpu.h Fri Jun 28 00:36:26 2019 (r349484) @@ -54,7 +54,6 @@ struct pcb; struct pcpu; -extern struct pcpu *pcpup; static inline struct pcpu * get_pcpu(void) Modified: stable/12/sys/riscv/riscv/machdep.c ============================================================================== --- stable/12/sys/riscv/riscv/machdep.c Fri Jun 28 00:14:12 2019 (r349483) +++ stable/12/sys/riscv/riscv/machdep.c Fri Jun 28 00:36:26 2019 (r349484) @@ -123,8 +123,6 @@ cpuset_t all_harts; extern int *end; extern int *initstack_end; -struct pcpu *pcpup; - uintptr_t mcall_trap(uintptr_t mcause, uintptr_t* regs); uintptr_t @@ -632,6 +630,7 @@ sendsig(sig_t catcher, ksiginfo_t *ksi, sigset_t *mask static void init_proc0(vm_offset_t kstack) { + struct pcpu *pcpup; pcpup = &__pcpu[0]; @@ -807,6 +806,7 @@ void initriscv(struct riscv_bootparams *rvbp) { struct mem_region mem_regions[FDT_MEM_REGIONS]; + struct pcpu *pcpup; vm_offset_t rstart, rend; vm_offset_t s, e; int mem_regions_sz; @@ -815,6 +815,16 @@ initriscv(struct riscv_bootparams *rvbp) caddr_t kmdp; int i; + /* Set the pcpu data, this is needed by pmap_bootstrap */ + pcpup = &__pcpu[0]; + pcpu_init(pcpup, 0, sizeof(struct pcpu)); + pcpup->pc_hart = boot_hart; + + /* Set the pcpu pointer */ + __asm __volatile("mv gp, %0" :: "r"(pcpup)); + + PCPU_SET(curthread, &thread0); + /* Set the module data location */ lastaddr = fake_preload_metadata(rvbp); @@ -857,16 +867,6 @@ initriscv(struct riscv_bootparams *rvbp) } } #endif - - /* Set the pcpu data, this is needed by pmap_bootstrap */ - pcpup = &__pcpu[0]; - pcpu_init(pcpup, 0, sizeof(struct pcpu)); - pcpup->pc_hart = boot_hart; - - /* Set the pcpu pointer */ - __asm __volatile("mv gp, %0" :: "r"(pcpup)); - - PCPU_SET(curthread, &thread0); /* Do basic tuning, hz etc */ init_param1();