[PATCH] kdump: NMI handler segment selector, stack pointer fix
authorVivek Goyal <vgoyal@in.ibm.com>
Sat, 25 Jun 2005 21:58:13 +0000 (14:58 -0700)
committerLinus Torvalds <torvalds@ppc970.osdl.org>
Sat, 25 Jun 2005 23:24:52 +0000 (16:24 -0700)
CPU does not save ss and esp on stack if execution was already in kernel mode
at the time of NMI occurrence.  This leads to saving of erractic values for ss
and esp.  This patch fixes the issue.

Signed-off-by: Vivek Goyal <vgoyal@in.ibm.com>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
arch/i386/kernel/crash.c

index 3645ad7ac20056bfda2b801f4549366e6df33ee7..31e077bb0caad729df75f65b4bcb7a1e3cb9b9da 100644 (file)
@@ -112,7 +112,20 @@ static atomic_t waiting_for_crash_ipi;
 
 static int crash_nmi_callback(struct pt_regs *regs, int cpu)
 {
+       struct pt_regs fixed_regs;
        local_irq_disable();
+
+       /* CPU does not save ss and esp on stack if execution is already
+        * running in kernel mode at the time of NMI occurrence. This code
+        * fixes it.
+        */
+       if (!user_mode(regs)) {
+               memcpy(&fixed_regs, regs, sizeof(*regs));
+               fixed_regs.esp = (unsigned long)&(regs->esp);
+               __asm__ __volatile__("xorl %eax, %eax;");
+               __asm__ __volatile__ ("movw %%ss, %%ax;" :"=a"(fixed_regs.xss));
+               regs = &fixed_regs;
+       }
        crash_save_this_cpu(regs, cpu);
        disable_local_APIC();
        atomic_dec(&waiting_for_crash_ipi);