Skip to contentSkip to conversation

PPC/PPC64: Fix FP state corruption on UP

PATCH New Paul Mackerras 1 participant 1 message Oct 27, 2004

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 PPC/PPC64: Fix FP state corruption on UP

Unfortunately the patch Ben sent last week to fix a bug in the saving and restoring of floating-point and altivec context across signal handlers introduced another bug, which tends to corrupt the FP and altivec contexts of other tasks. This patch fixes the problem for both ppc32 and ppc64. Please apply.

arch/ppc/kernel/signal.c +9 -4
diff -urN linux-2.5/arch/ppc/kernel/signal.c test/arch/ppc/kernel/signal.c
@@ -290,7 +290,7 @@
 
 	/* force the process to reload the FP registers from
 	   current->thread when it next does FP instructions */
-	regs->msr &= ~MSR_FP;
+	regs->msr &= ~(MSR_FP | MSR_FE0 | MSR_FE1);
 	if (__copy_from_user(current->thread.fpr, &sr->mc_fregs,
 			     sizeof(sr->mc_fregs)))
 		return 1;
@@ -330,9 +330,14 @@
 #endif /* CONFIG_SPE */
 
 #ifndef CONFIG_SMP
-	last_task_used_math = NULL;
-	last_task_used_altivec = NULL;
-	last_task_used_spe = NULL;
+	preempt_disable();
+	if (last_task_used_math == current)
+		last_task_used_math = NULL;
+	if (last_task_used_altivec == current)
+		last_task_used_altivec = NULL;
+	if (last_task_used_spe == current)
+		last_task_used_spe = NULL;
+	preempt_enable();
 #endif
 	return 0;
 }
arch/ppc64/kernel/signal.c +6 -2
diff -urN linux-2.5/arch/ppc64/kernel/signal.c test/arch/ppc64/kernel/signal.c
@@ -224,8 +224,12 @@
 #endif /* CONFIG_ALTIVEC */
 
 #ifndef CONFIG_SMP
-	last_task_used_math = NULL;
-	last_task_used_altivec = NULL;
+	preempt_disable();
+	if (last_task_used_math == current)
+		last_task_used_math = NULL;
+	if (last_task_used_altivec == current)
+		last_task_used_altivec = NULL;
+	preempt_enable();
 #endif
 	/* Force reload of FP/VEC */
 	regs->msr &= ~(MSR_FP | MSR_FE0 | MSR_FE1 | MSR_VEC);
arch/ppc64/kernel/signal32.c +6 -2
diff -urN linux-2.5/arch/ppc64/kernel/signal32.c test/arch/ppc64/kernel/signal32.c
@@ -235,8 +235,12 @@
 #endif /* CONFIG_ALTIVEC */
 
 #ifndef CONFIG_SMP
-	last_task_used_math = NULL;
-	last_task_used_altivec = NULL;
+	preempt_disable();
+	if (last_task_used_math == current)
+		last_task_used_math = NULL;
+	if (last_task_used_altivec == current)
+		last_task_used_altivec = NULL;
+	preempt_enable();
 #endif
 	return 0;
 }