Skip to contentSkip to conversation

NMI handler segment selector, stack pointer fix

PATCH In review Vivek Goyal 1 participant 1 message Mar 28, 2005

lore
Share & tools
lore
#0 lore raw

PATCH 6/17 NMI handler segment selector, stack pointer fix

From: "Vivek Goyal" <[email protected]>

o 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.

---

 linux-2.6.12-rc1-mm3-1M-root/arch/i386/kernel/crash.c |   13 +++++++++++++
 1 files changed, 13 insertions(+)
arch/i386/kernel/crash.c renamed from arch/i386/kernel/crash.c~x86-nmi-handler-ss-esp-fix +13 -0
diff -puN arch/i386/kernel/crash.c~x86-nmi-handler-ss-esp-fix arch/i386/kernel/crash.c
@@ -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);

_