Re: 2.6.14: CR4 not needed to be inspected on the 486 anymore?

From: Zachary Amsden
Date: Mon Nov 07 2005 - 10:44:43 EST


Maciej W. Rozycki wrote:

On Sat, 5 Nov 2005, Andi Kleen wrote:



I don't think it's a good idea. Relying on nested faults in oops
is a bit unsafe because it could lead to recursive faults in the worst case.


Good point.



Better keep the if



Except the condition is wrong. Presence of CR4 could be tested elsewhere
though, with the result being the condition here.

Maciej




While this is at least no worse in the nested fault case than earlier kernels, I really wish I had one of those weird 486s so I could test the faulting mechanism. It seems the trap handling code has gotten quite complicated now, with notifiers adding nice functionality, but making the ordering of potential fault paths difficult to reason about (in particular when considering functionality like kexec, kprobes, NMIs and friends).

Zach So some 486 processors do have CR4 register. Allow them to present it in
register dumps by using the old fault technique rather than testing processor
family.

Thanks to Maciej for noticing this.

Signed-off-by: Zachary Amsden <zach@xxxxxxxxxx>
Index: linux-2.6.14-zach-work/arch/i386/kernel/process.c
===================================================================
--- linux-2.6.14-zach-work.orig/arch/i386/kernel/process.c 2005-11-05 01:19:21.000000000 -0800
+++ linux-2.6.14-zach-work/arch/i386/kernel/process.c 2005-11-05 03:02:21.000000000 -0800
@@ -314,9 +314,7 @@ void show_regs(struct pt_regs * regs)
cr0 = read_cr0();
cr2 = read_cr2();
cr3 = read_cr3();
- if (current_cpu_data.x86 > 4) {
- cr4 = read_cr4();
- }
+ cr4 = read_cr4_safe();
printk("CR0: %08lx CR2: %08lx CR3: %08lx CR4: %08lx\n", cr0, cr2, cr3, cr4);
show_trace(NULL, &regs->esp);
}
Index: linux-2.6.14-zach-work/include/asm-i386/system.h
===================================================================
--- linux-2.6.14-zach-work.orig/include/asm-i386/system.h 2005-11-05 01:11:32.000000000 -0800
+++ linux-2.6.14-zach-work/include/asm-i386/system.h 2005-11-05 03:06:57.000000000 -0800
@@ -97,6 +97,19 @@ extern struct task_struct * FASTCALL(__s
:"=r" (__dummy)); \
__dummy; \
})
+
+#define read_cr4_safe() ({ \
+ unsigned int __dummy; \
+ /* This could fault if %cr4 does not exist */ \
+ __asm__("1: movl %%cr4, %0 \n" \
+ "2: \n" \
+ ".section __ex_table,\"a\" \n" \
+ ".long 1b,2b \n" \
+ ".previous \n" \
+ : "=r" (__dummy): "0" (0)); \
+ __dummy; \
+})
+
#define write_cr4(x) \
__asm__ __volatile__("movl %0,%%cr4": :"r" (x));
#define stts() write_cr0(8 | read_cr0())