[PATCH] invalid instructions in kernel mode

Fillod Stephane stephane.fillod at thomson.net
Fri Apr 1 03:47:32 EST 2005


Hi,

When CPU has no (classic) FPU, and math emulation is disabled,
fp instructions are not allowed in kernel mode.
This bug has been found with crashme (crash01) of LTP, on a e500 system.

The patch was made against linux 2.6.11.6.
A trivial typo fix has been appended.

Rem: a CONFIG_PPCFPU define could make life easier.


Signed-off-by: Stephane Fillod <fillods at gmail.com>

--- linux/arch/ppc/kernel/align.c	6 Dec 2004 16:18:11 -0000
1.1.1.1
+++ linux/arch/ppc/kernel/align.c	31 Mar 2005 16:33:25 -0000
@@ -333,10 +333,14 @@
 	}
 
 	if (flags & F) {
+#if !(defined(CONFIG_4xx) || defined(CONFIG_8xx) ||
defined(CONFIG_E500)) || defined(CONFIG_MATH_EMULATION)
 		preempt_disable();
 		if (regs->msr & MSR_FP)
 			giveup_fpu(current);
 		preempt_enable();
+#else
+		return 0;
+#endif
 	}
 
 	/* If we read the operand, copy it in, else get register values
*/
@@ -366,6 +370,8 @@
 		}
 		break;
 
+#if !(defined(CONFIG_4xx) || defined(CONFIG_8xx) ||
defined(CONFIG_E500)) || defined(CONFIG_MATH_EMULATION)
+
 	/* Single-precision FP load and store require conversions... */
 	case LD+F+S:
 		preempt_disable();
@@ -379,6 +385,7 @@
 		cvt_df(&data.d, &data.f, &current->thread.fpscr);
 		preempt_enable();
 		break;
+#endif
 	}
 
 	if (flags & ST) {
--- linux/arch/ppc/kernel/misc.S	26 Mar 2005 03:28:36 -0000
1.1.1.2
+++ linux/arch/ppc/kernel/misc.S	31 Mar 2005 16:33:25 -0000
@@ -1096,7 +1096,8 @@
  * and exceptions as if the cpu had performed the load or store.
  */
 
-#if defined(CONFIG_4xx) || defined(CONFIG_E500)
+#if !(defined(CONFIG_4xx) || defined(CONFIG_E500) ||
defined(CONFIG_8xx)) ||  defined(CONFIG_MATH_EMULATION)
+#if defined(CONFIG_4xx) || defined(CONFIG_E500)
 _GLOBAL(cvt_fd)
 	lfs	0,0(r3)
 	stfd	0,0(r4)
@@ -1125,6 +1126,7 @@
 	stfd	0,-4(r5)
 	blr
 #endif
+#endif
 
 /*
  * Create a kernel thread
--- linux/arch/ppc/kernel/process.c	26 Mar 2005 03:28:20 -0000
1.1.1.2
+++ linux/arch/ppc/kernel/process.c	31 Mar 2005 16:33:25 -0000
@@ -342,7 +342,7 @@
 	printk("\n");
 #ifdef CONFIG_KALLSYMS
 	/*
-	 * Lookup NIP late so we have the best change of getting the
+	 * Lookup NIP late so we have the best chance of getting the
 	 * above info out without failing
 	 */
 	printk("NIP [%08lx] ", regs->nip);


Best Regards,

-- 
Stephane




More information about the Linuxppc-dev mailing list