PERFORCE change 185119 for review

John Baldwin jhb at FreeBSD.org
Tue Oct 26 16:06:30 UTC 2010


http://p4web.freebsd.org/@@185119?ac=10

Change 185119 by jhb at jhb_jhbbsd on 2010/10/26 16:05:30

	Disable interrupts before bumping td_md.md_spinlock_count to 1
	to fix races with single stepping through spinlock_enter clobbering
	td.md_saved_*.

Affected files ...

.. //depot/projects/smpng/sys/amd64/amd64/machdep.c#97 edit
.. //depot/projects/smpng/sys/arm/arm/machdep.c#32 edit
.. //depot/projects/smpng/sys/i386/i386/machdep.c#162 edit
.. //depot/projects/smpng/sys/ia64/ia64/machdep.c#126 edit
.. //depot/projects/smpng/sys/mips/mips/machdep.c#17 edit
.. //depot/projects/smpng/sys/pc98/pc98/machdep.c#43 edit
.. //depot/projects/smpng/sys/powerpc/aim/machdep.c#22 edit
.. //depot/projects/smpng/sys/powerpc/booke/machdep.c#19 edit
.. //depot/projects/smpng/sys/sparc64/sparc64/machdep.c#105 edit
.. //depot/projects/smpng/sys/sun4v/sun4v/machdep.c#16 edit

Differences ...

==== //depot/projects/smpng/sys/amd64/amd64/machdep.c#97 (text+ko) ====

@@ -1761,11 +1761,15 @@
 spinlock_enter(void)
 {
 	struct thread *td;
+	register_t flags;
 
 	td = curthread;
-	if (td->td_md.md_spinlock_count == 0)
-		td->td_md.md_saved_flags = intr_disable();
-	td->td_md.md_spinlock_count++;
+	if (td->td_md.md_spinlock_count == 0) {
+		flags = intr_disable();
+		td->td_md.md_spinlock_count == 1;
+		td->td_md.md_saved_flags = flags;
+	} else
+		td->td_md.md_spinlock_count++;
 	critical_enter();
 }
 

==== //depot/projects/smpng/sys/arm/arm/machdep.c#32 (text+ko) ====

@@ -493,11 +493,15 @@
 spinlock_enter(void)
 {
 	struct thread *td;
+	register_t cspr;
 
 	td = curthread;
-	if (td->td_md.md_spinlock_count == 0)
-		td->td_md.md_saved_cspr = disable_interrupts(I32_bit | F32_bit);
-	td->td_md.md_spinlock_count++;
+	if (td->td_md.md_spinlock_count == 0) {
+		cspr = disable_interrupts(I32_bit | F32_bit);
+		td->td_md.md_spinlock_count == 1;
+		td->td_md.md_saved_cspr = cspr;
+	} else
+		td->td_md.md_spinlock_count++;
 	critical_enter();
 }
 

==== //depot/projects/smpng/sys/i386/i386/machdep.c#162 (text+ko) ====

@@ -2996,11 +2996,15 @@
 spinlock_enter(void)
 {
 	struct thread *td;
+	register_t flags;
 
 	td = curthread;
-	if (td->td_md.md_spinlock_count == 0)
-		td->td_md.md_saved_flags = intr_disable();
-	td->td_md.md_spinlock_count++;
+	if (td->td_md.md_spinlock_count == 0) {
+		flags = intr_disable();
+		td->td_md.md_spinlock_count == 1;
+		td->td_md.md_saved_flags = flags;
+	} else
+		td->td_md.md_spinlock_count++;
 	critical_enter();
 }
 

==== //depot/projects/smpng/sys/ia64/ia64/machdep.c#126 (text+ko) ====

@@ -513,11 +513,15 @@
 spinlock_enter(void)
 {
 	struct thread *td;
+	int intr;
 
 	td = curthread;
-	if (td->td_md.md_spinlock_count == 0)
-		td->td_md.md_saved_intr = intr_disable();
-	td->td_md.md_spinlock_count++;
+	if (td->td_md.md_spinlock_count == 0) {
+		intr = intr_disable();
+		td->td_md.md_spinlock_count == 1;
+		td->td_md.md_saved_intr = intr;
+	} else
+		td->td_md.md_spinlock_count++;
 	critical_enter();
 }
 

==== //depot/projects/smpng/sys/mips/mips/machdep.c#17 (text+ko) ====

@@ -450,11 +450,15 @@
 spinlock_enter(void)
 {
 	struct thread *td;
+	register_t intr;
 
 	td = curthread;
-	if (td->td_md.md_spinlock_count == 0)
-		td->td_md.md_saved_intr = intr_disable();
-	td->td_md.md_spinlock_count++;
+	if (td->td_md.md_spinlock_count == 0) {
+		intr = intr_disable();
+		td->td_md.md_spinlock_count == 1;
+		td->td_md.md_saved_intr = intr;
+	} else
+		td->td_md.md_spinlock_count++;
 	critical_enter();
 }
 

==== //depot/projects/smpng/sys/pc98/pc98/machdep.c#43 (text+ko) ====

@@ -2328,11 +2328,15 @@
 spinlock_enter(void)
 {
 	struct thread *td;
+	register_t flags;
 
 	td = curthread;
-	if (td->td_md.md_spinlock_count == 0)
-		td->td_md.md_saved_flags = intr_disable();
-	td->td_md.md_spinlock_count++;
+	if (td->td_md.md_spinlock_count == 0) {
+		flags = intr_disable();
+		td->td_md.md_spinlock_count == 1;
+		td->td_md.md_saved_flags = flags;
+	} else
+		td->td_md.md_spinlock_count++;
 	critical_enter();
 }
 

==== //depot/projects/smpng/sys/powerpc/aim/machdep.c#22 (text+ko) ====

@@ -751,11 +751,15 @@
 spinlock_enter(void)
 {
 	struct thread *td;
+	register_t msr;
 
 	td = curthread;
-	if (td->td_md.md_spinlock_count == 0)
-		td->td_md.md_saved_msr = intr_disable();
-	td->td_md.md_spinlock_count++;
+	if (td->td_md.md_spinlock_count == 0) {
+		msr = intr_disable();
+		td->td_md.md_spinlock_count == 1;
+		td->td_md.md_saved_msr = msr;
+	} else
+		td->td_md.md_spinlock_count++;
 	critical_enter();
 }
 

==== //depot/projects/smpng/sys/powerpc/booke/machdep.c#19 (text+ko) ====

@@ -516,11 +516,15 @@
 spinlock_enter(void)
 {
 	struct thread *td;
+	register_t msr;
 
 	td = curthread;
-	if (td->td_md.md_spinlock_count == 0)
-		td->td_md.md_saved_msr = intr_disable();
-	td->td_md.md_spinlock_count++;
+	if (td->td_md.md_spinlock_count == 0) {
+		msr = intr_disable();
+		td->td_md.md_spinlock_count == 1;
+		td->td_md.md_saved_msr = msr;
+	} else
+		td->td_md.md_spinlock_count++;
 	critical_enter();
 }
 

==== //depot/projects/smpng/sys/sparc64/sparc64/machdep.c#105 (text+ko) ====

@@ -224,9 +224,10 @@
 	if (td->td_md.md_spinlock_count == 0) {
 		pil = rdpr(pil);
 		wrpr(pil, 0, PIL_TICK);
+		td->td_md.md_spinlock_count == 1;
 		td->td_md.md_saved_pil = pil;
-	}
-	td->td_md.md_spinlock_count++;
+	} else
+		td->td_md.md_spinlock_count++;
 	critical_enter();
 }
 

==== //depot/projects/smpng/sys/sun4v/sun4v/machdep.c#16 (text+ko) ====

@@ -269,9 +269,10 @@
 	td = curthread;
 	if (td->td_md.md_spinlock_count == 0) {
 		pil = intr_disable();
+		td->td_md.md_spinlock_count == 1;
 		td->td_md.md_saved_pil = pil;
-	}
-	td->td_md.md_spinlock_count++;
+	} else
+		td->td_md.md_spinlock_count++;
 	critical_enter();
 }
 
@@ -285,9 +286,8 @@
 	critical_exit();
 	pil = td->td_md.md_saved_pil;
 	td->td_md.md_spinlock_count--;
-	if (td->td_md.md_spinlock_count == 0) {
+	if (td->td_md.md_spinlock_count == 0)
 		intr_restore(pil);
-	}
 }
 
 unsigned


More information about the p4-projects mailing list