Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 28 Jun 2019 00:36:27 +0000 (UTC)
From:      Mitchell Horne <mhorne@FreeBSD.org>
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
Message-ID:  <201906280036.x5S0aRxM071939@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
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();



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201906280036.x5S0aRxM071939>