Skip to contentSkip to conversation

i386: handle all exceptions with interrupts off initially

RFC/PATCH In review [email protected] 4 participants 35 messages Sep 9, 2008 – Jan 12, 2009 x86

lore
Share & tools
lore
#0 lore raw

From: Alexander van Heukelum <[email protected]>

x86_64 handles all exceptions with interrupts off initially, this bisectable patch set does the same for i386, in (very) small steps. If this is acceptable, it would make further unification of traps_32.c and traps_64.c a lot easier. If it is not... why?

Patches are against current -git.

Every step in the series runs fine in a simple system under qemu.

Greetings,
Alexander

#1 lore raw

PATCH 1/24 i386: remove kprobes' restore_interrupts in favour of conditional_sti

From: Alexander van Heukelum <[email protected]>

x86_64 uses a helper function conditional_sti in traps_64.c which is equal to restore_interrupts in kprobes.h. The only user of restore_interrupts is in traps_32.c. Introduce conditional_sti for i386 and remove restore_interrupts.

---
 arch/x86/kernel/traps_32.c |    8 +++++++-
 include/asm-x86/kprobes.h  |    9 ---------
 2 files changed, 7 insertions(+), 10 deletions(-)
arch/x86/kernel/traps_32.c +7 -1
index 03df8e4..c8096f7 100644
@@ -84,6 +84,12 @@ static unsigned int code_bytes = 64;
 static int ignore_nmis;
 static int die_counter;
 
+static inline void conditional_sti(struct pt_regs *regs)
+{
+	if (regs->flags & X86_EFLAGS_IF)
+		local_irq_enable();
+}
+
 void printk_address(unsigned long address, int reliable)
 {
 #ifdef CONFIG_KALLSYMS
@@ -859,7 +865,7 @@ void __kprobes do_int3(struct pt_regs *regs, long error_code)
 	 * This is an interrupt gate, because kprobes wants interrupts
 	 * disabled. Normal trap handlers don't.
 	 */
-	restore_interrupts(regs);
+	conditional_sti(regs);
 
 	do_trap(3, SIGTRAP, "int3", 1, regs, error_code, NULL);
 }
include/asm-x86/kprobes.h +0 -9
index 54980b0..93a7f49 100644
@@ -82,15 +82,6 @@ struct kprobe_ctlblk {
 	struct prev_kprobe prev_kprobe;
 };
 
-/* trap3/1 are intr gates for kprobes.  So, restore the status of IF,
- * if necessary, before executing the original int3/1 (trap) handler.
- */
-static inline void restore_interrupts(struct pt_regs *regs)
-{
-	if (regs->flags & X86_EFLAGS_IF)
-		local_irq_enable();
-}
-
 extern int kprobe_fault_handler(struct pt_regs *regs, int trapnr);
 extern int kprobe_exceptions_notify(struct notifier_block *self,
 				    unsigned long val, void *data);
Signature · 1 line
1.5.4.3
#2 lore raw

PATCH 2/24 i386: prepare to convert exceptions to interrupts

From: Alexander van Heukelum <[email protected]>

There is some macro magic in traps_32.c to construct standard exception dispatch functions. This patch renames the DO_ERROR- like macros to DO_TRAP, and introduces new DO_ERROR ones that conditionally reenable interrupts explicitly, like x86_64.

No code changes.

---
 arch/x86/kernel/traps_32.c |   76 +++++++++++++++++++++++++++++++++++++------
 1 files changed, 65 insertions(+), 11 deletions(-)
arch/x86/kernel/traps_32.c +65 -11
index c8096f7..9ac59e0 100644
@@ -528,6 +528,56 @@ vm86_trap:
 	return;
 }
 
+#define DO_TRAP(trapnr, signr, str, name)				\
+void do_##name(struct pt_regs *regs, long error_code)			\
+{									\
+	trace_hardirqs_fixup();						\
+	if (notify_die(DIE_TRAP, str, regs, error_code, trapnr, signr)	\
+							== NOTIFY_STOP)	\
+		return;							\
+	do_trap(trapnr, signr, str, 0, regs, error_code, NULL);		\
+}
+
+#define DO_TRAP_INFO(trapnr, signr, str, name, sicode, siaddr, irq)	\
+void do_##name(struct pt_regs *regs, long error_code)			\
+{									\
+	siginfo_t info;							\
+	if (irq)							\
+		local_irq_enable();					\
+	info.si_signo = signr;						\
+	info.si_errno = 0;						\
+	info.si_code = sicode;						\
+	info.si_addr = (void __user *)siaddr;				\
+	if (notify_die(DIE_TRAP, str, regs, error_code, trapnr, signr)	\
+							== NOTIFY_STOP)	\
+		return;							\
+	do_trap(trapnr, signr, str, 0, regs, error_code, &info);	\
+}
+
+#define DO_VM86_TRAP(trapnr, signr, str, name)				\
+void do_##name(struct pt_regs *regs, long error_code)			\
+{									\
+	if (notify_die(DIE_TRAP, str, regs, error_code, trapnr, signr)	\
+							== NOTIFY_STOP)	\
+		return;							\
+	do_trap(trapnr, signr, str, 1, regs, error_code, NULL);		\
+}
+
+#define DO_VM86_TRAP_INFO(trapnr, signr, str, name, sicode, siaddr)	\
+void do_##name(struct pt_regs *regs, long error_code)			\
+{									\
+	siginfo_t info;							\
+	info.si_signo = signr;						\
+	info.si_errno = 0;						\
+	info.si_code = sicode;						\
+	info.si_addr = (void __user *)siaddr;				\
+	trace_hardirqs_fixup();						\
+	if (notify_die(DIE_TRAP, str, regs, error_code, trapnr, signr)	\
+							== NOTIFY_STOP)	\
+		return;							\
+	do_trap(trapnr, signr, str, 1, regs, error_code, &info);	\
+}
+
 #define DO_ERROR(trapnr, signr, str, name)				\
 void do_##name(struct pt_regs *regs, long error_code)			\
 {									\
@@ -535,6 +585,7 @@ void do_##name(struct pt_regs *regs, long error_code)			\
 	if (notify_die(DIE_TRAP, str, regs, error_code, trapnr, signr)	\
 							== NOTIFY_STOP)	\
 		return;							\
+	conditional_sti(regs);						\
 	do_trap(trapnr, signr, str, 0, regs, error_code, NULL);		\
 }
 
@@ -551,6 +602,7 @@ void do_##name(struct pt_regs *regs, long error_code)			\
 	if (notify_die(DIE_TRAP, str, regs, error_code, trapnr, signr)	\
 							== NOTIFY_STOP)	\
 		return;							\
+	conditional_sti(regs);						\
 	do_trap(trapnr, signr, str, 0, regs, error_code, &info);	\
 }
 
@@ -560,6 +612,7 @@ void do_##name(struct pt_regs *regs, long error_code)			\
 	if (notify_die(DIE_TRAP, str, regs, error_code, trapnr, signr)	\
 							== NOTIFY_STOP)	\
 		return;							\
+	conditional_sti(regs);						\
 	do_trap(trapnr, signr, str, 1, regs, error_code, NULL);		\
 }
 
@@ -575,22 +628,23 @@ void do_##name(struct pt_regs *regs, long error_code)			\
 	if (notify_die(DIE_TRAP, str, regs, error_code, trapnr, signr)	\
 							== NOTIFY_STOP)	\
 		return;							\
+	conditional_sti(regs);						\
 	do_trap(trapnr, signr, str, 1, regs, error_code, &info);	\
 }
 
-DO_VM86_ERROR_INFO(0, SIGFPE, "divide error", divide_error, FPE_INTDIV, regs->ip)
+DO_VM86_TRAP_INFO(0, SIGFPE, "divide error", divide_error, FPE_INTDIV, regs->ip)
 #ifndef CONFIG_KPROBES
-DO_VM86_ERROR(3, SIGTRAP, "int3", int3)
+DO_VM86_TRAP(3, SIGTRAP, "int3", int3)
 #endif
-DO_VM86_ERROR(4, SIGSEGV, "overflow", overflow)
-DO_VM86_ERROR(5, SIGSEGV, "bounds", bounds)
-DO_ERROR_INFO(6, SIGILL, "invalid opcode", invalid_op, ILL_ILLOPN, regs->ip, 0)
-DO_ERROR(9, SIGFPE, "coprocessor segment overrun", coprocessor_segment_overrun)
-DO_ERROR(10, SIGSEGV, "invalid TSS", invalid_TSS)
-DO_ERROR(11, SIGBUS, "segment not present", segment_not_present)
-DO_ERROR(12, SIGBUS, "stack segment", stack_segment)
-DO_ERROR_INFO(17, SIGBUS, "alignment check", alignment_check, BUS_ADRALN, 0, 0)
-DO_ERROR_INFO(32, SIGILL, "iret exception", iret_error, ILL_BADSTK, 0, 1)
+DO_VM86_TRAP(4, SIGSEGV, "overflow", overflow)
+DO_VM86_TRAP(5, SIGSEGV, "bounds", bounds)
+DO_TRAP_INFO(6, SIGILL, "invalid opcode", invalid_op, ILL_ILLOPN, regs->ip, 0)
+DO_TRAP(9, SIGFPE, "coprocessor segment overrun", coprocessor_segment_overrun)
+DO_TRAP(10, SIGSEGV, "invalid TSS", invalid_TSS)
+DO_TRAP(11, SIGBUS, "segment not present", segment_not_present)
+DO_TRAP(12, SIGBUS, "stack segment", stack_segment)
+DO_TRAP_INFO(17, SIGBUS, "alignment check", alignment_check, BUS_ADRALN, 0, 0)
+DO_TRAP_INFO(32, SIGILL, "iret exception", iret_error, ILL_BADSTK, 0, 1)
 
 void __kprobes
 do_general_protection(struct pt_regs *regs, long error_code)
Signature · 1 line
1.5.4.3
#3 lore raw

PATCH 3/24 i386: convert hardware exception 0 to an interrupt gate

From: Alexander van Heukelum <[email protected]>

Handle divide error exception with interrupt initially off.

---
 arch/x86/kernel/traps_32.c |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)
arch/x86/kernel/traps_32.c +2 -2
index 9ac59e0..97d193c 100644
@@ -632,7 +632,7 @@ void do_##name(struct pt_regs *regs, long error_code)			\
 	do_trap(trapnr, signr, str, 1, regs, error_code, &info);	\
 }
 
-DO_VM86_TRAP_INFO(0, SIGFPE, "divide error", divide_error, FPE_INTDIV, regs->ip)
+DO_VM86_ERROR_INFO(0, SIGFPE, "divide error", divide_error, FPE_INTDIV, regs->ip)
 #ifndef CONFIG_KPROBES
 DO_VM86_TRAP(3, SIGTRAP, "int3", int3)
 #endif
@@ -1245,7 +1245,7 @@ void __init trap_init(void)
 	early_iounmap(p, 4);
 #endif
 
-	set_trap_gate(0, &divide_error);
+	set_intr_gate(0, &divide_error);
 	set_intr_gate(1, &debug);
 	set_intr_gate(2, &nmi);
 	set_system_intr_gate(3, &int3); /* int3 can be called from all */
Signature · 1 line
1.5.4.3
#4 lore raw

PATCH 4/24 i386: expand exception 3 DO_TRAP macro

From: Alexander van Heukelum <[email protected]>

The int3 exception was already takes as an interrupt and do_int3 does not fit in the new DO_ERROR macro. This patch just expands the DO_TRAP macro and rearranges the code a bit.

No functional changes intended.

---
 arch/x86/kernel/traps_32.c |   11 ++++++-----
 1 files changed, 6 insertions(+), 5 deletions(-)
arch/x86/kernel/traps_32.c +6 -5
index 97d193c..944641a 100644
@@ -633,9 +633,6 @@ void do_##name(struct pt_regs *regs, long error_code)			\
 }
 
 DO_VM86_ERROR_INFO(0, SIGFPE, "divide error", divide_error, FPE_INTDIV, regs->ip)
-#ifndef CONFIG_KPROBES
-DO_VM86_TRAP(3, SIGTRAP, "int3", int3)
-#endif
 DO_VM86_TRAP(4, SIGSEGV, "overflow", overflow)
 DO_VM86_TRAP(5, SIGSEGV, "bounds", bounds)
 DO_TRAP_INFO(6, SIGILL, "invalid opcode", invalid_op, ILL_ILLOPN, regs->ip, 0)
@@ -907,9 +904,9 @@ void restart_nmi(void)
 	acpi_nmi_enable();
 }
 
-#ifdef CONFIG_KPROBES
 void __kprobes do_int3(struct pt_regs *regs, long error_code)
 {
+#ifdef CONFIG_KPROBES
 	trace_hardirqs_fixup();
 
 	if (notify_die(DIE_INT3, "int3", regs, error_code, 3, SIGTRAP)
@@ -920,10 +917,14 @@ void __kprobes do_int3(struct pt_regs *regs, long error_code)
 	 * disabled. Normal trap handlers don't.
 	 */
 	conditional_sti(regs);
+#else
+	if (notify_die(DIE_TRAP, "int3", regs, error_code, 3, SIGTRAP)
+			== NOTIFY_STOP)
+		return;
+#endif
 
 	do_trap(3, SIGTRAP, "int3", 1, regs, error_code, NULL);
 }
-#endif
 
 /*
  * Our handling of the processor debug registers is non-trivial.
Signature · 1 line
1.5.4.3
#5 lore raw

PATCH 5/24 i386: convert hardware exception 4 to an interrupt gate

From: Alexander van Heukelum <[email protected]>

Handle overflow exception with interrupt initially off.

---
 arch/x86/kernel/traps_32.c |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)
arch/x86/kernel/traps_32.c +2 -2
index 944641a..5d762a8 100644
@@ -633,7 +633,7 @@ void do_##name(struct pt_regs *regs, long error_code)			\
 }
 
 DO_VM86_ERROR_INFO(0, SIGFPE, "divide error", divide_error, FPE_INTDIV, regs->ip)
-DO_VM86_TRAP(4, SIGSEGV, "overflow", overflow)
+DO_VM86_ERROR(4, SIGSEGV, "overflow", overflow)
 DO_VM86_TRAP(5, SIGSEGV, "bounds", bounds)
 DO_TRAP_INFO(6, SIGILL, "invalid opcode", invalid_op, ILL_ILLOPN, regs->ip, 0)
 DO_TRAP(9, SIGFPE, "coprocessor segment overrun", coprocessor_segment_overrun)
@@ -1250,7 +1250,7 @@ void __init trap_init(void)
 	set_intr_gate(1, &debug);
 	set_intr_gate(2, &nmi);
 	set_system_intr_gate(3, &int3); /* int3 can be called from all */
-	set_system_gate(4, &overflow); /* int4 can be called from all */
+	set_system_intr_gate(4, &overflow); /* int4 can be called from all */
 	set_trap_gate(5, &bounds);
 	set_trap_gate(6, &invalid_op);
 	set_trap_gate(7, &device_not_available);
Signature · 1 line
1.5.4.3
#6 lore raw

PATCH 6/24 i386: convert hardware exception 5 to an interrupt gate

From: Alexander van Heukelum <[email protected]>

Handle bounds exception with interrupt initially off.

---
 arch/x86/kernel/traps_32.c |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)
arch/x86/kernel/traps_32.c +2 -2
index 5d762a8..becfc84 100644
@@ -634,7 +634,7 @@ void do_##name(struct pt_regs *regs, long error_code)			\
 
 DO_VM86_ERROR_INFO(0, SIGFPE, "divide error", divide_error, FPE_INTDIV, regs->ip)
 DO_VM86_ERROR(4, SIGSEGV, "overflow", overflow)
-DO_VM86_TRAP(5, SIGSEGV, "bounds", bounds)
+DO_VM86_ERROR(5, SIGSEGV, "bounds", bounds)
 DO_TRAP_INFO(6, SIGILL, "invalid opcode", invalid_op, ILL_ILLOPN, regs->ip, 0)
 DO_TRAP(9, SIGFPE, "coprocessor segment overrun", coprocessor_segment_overrun)
 DO_TRAP(10, SIGSEGV, "invalid TSS", invalid_TSS)
@@ -1251,7 +1251,7 @@ void __init trap_init(void)
 	set_intr_gate(2, &nmi);
 	set_system_intr_gate(3, &int3); /* int3 can be called from all */
 	set_system_intr_gate(4, &overflow); /* int4 can be called from all */
-	set_trap_gate(5, &bounds);
+	set_intr_gate(5, &bounds);
 	set_trap_gate(6, &invalid_op);
 	set_trap_gate(7, &device_not_available);
 	set_task_gate(8, GDT_ENTRY_DOUBLEFAULT_TSS);
Signature · 1 line
1.5.4.3
#7 lore raw

PATCH 7/24 i386: convert hardware exception 6 to an interrupt gate

From: Alexander van Heukelum <[email protected]>

Handle invalid opcode exception with interrupt initially off.

---
 arch/x86/kernel/traps_32.c |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)
arch/x86/kernel/traps_32.c +2 -2
index becfc84..5d8d057 100644
@@ -635,7 +635,7 @@ void do_##name(struct pt_regs *regs, long error_code)			\
 DO_VM86_ERROR_INFO(0, SIGFPE, "divide error", divide_error, FPE_INTDIV, regs->ip)
 DO_VM86_ERROR(4, SIGSEGV, "overflow", overflow)
 DO_VM86_ERROR(5, SIGSEGV, "bounds", bounds)
-DO_TRAP_INFO(6, SIGILL, "invalid opcode", invalid_op, ILL_ILLOPN, regs->ip, 0)
+DO_ERROR_INFO(6, SIGILL, "invalid opcode", invalid_op, ILL_ILLOPN, regs->ip, 0)
 DO_TRAP(9, SIGFPE, "coprocessor segment overrun", coprocessor_segment_overrun)
 DO_TRAP(10, SIGSEGV, "invalid TSS", invalid_TSS)
 DO_TRAP(11, SIGBUS, "segment not present", segment_not_present)
@@ -1252,7 +1252,7 @@ void __init trap_init(void)
 	set_system_intr_gate(3, &int3); /* int3 can be called from all */
 	set_system_intr_gate(4, &overflow); /* int4 can be called from all */
 	set_intr_gate(5, &bounds);
-	set_trap_gate(6, &invalid_op);
+	set_intr_gate(6, &invalid_op);
 	set_trap_gate(7, &device_not_available);
 	set_task_gate(8, GDT_ENTRY_DOUBLEFAULT_TSS);
 	set_trap_gate(9, &coprocessor_segment_overrun);
Signature · 1 line
1.5.4.3
#8 lore raw

PATCH 8/24 i386: convert hardware exception 7 to an interrupt gate

From: Alexander van Heukelum <[email protected]>

Handle no coprocessor exception with interrupt initially off.

device_not_available in entry_32.S calls either math_state_restore or math_emulate. This patch adds an extra indirection to be able to re-enable interrupts explicitly in traps_32.c

---
 arch/x86/kernel/entry_32.S |   15 ++-------------
 arch/x86/kernel/traps_32.c |   14 +++++++++++++-
 2 files changed, 15 insertions(+), 14 deletions(-)
arch/x86/kernel/entry_32.S +2 -13
index 109792b..5a88585 100644
@@ -760,20 +760,9 @@ ENTRY(device_not_available)
 	RING0_INT_FRAME
 	pushl $-1			# mark this as an int
 	CFI_ADJUST_CFA_OFFSET 4
-	SAVE_ALL
-	GET_CR0_INTO_EAX
-	testl $0x4, %eax		# EM (math emulation bit)
-	jne device_not_available_emulate
-	preempt_stop(CLBR_ANY)
-	call math_state_restore
-	jmp ret_from_exception
-device_not_available_emulate:
-	pushl $0			# temporary storage for ORIG_EIP
+	pushl $do_device_not_available
 	CFI_ADJUST_CFA_OFFSET 4
-	call math_emulate
-	addl $4, %esp
-	CFI_ADJUST_CFA_OFFSET -4
-	jmp ret_from_exception
+	jmp error_code
 	CFI_ENDPROC
 END(device_not_available)
 
arch/x86/kernel/traps_32.c +13 -1
index 5d8d057..3ddd71b 100644
@@ -46,6 +46,7 @@
 #include <linux/edac.h>
 #endif
 
+#include <asm/processor-flags.h>
 #include <asm/arch_hooks.h>
 #include <asm/stacktrace.h>
 #include <asm/processor.h>
@@ -1234,6 +1235,17 @@ asmlinkage void math_emulate(long arg)
 
 #endif /* CONFIG_MATH_EMULATION */
 
+void __kprobes do_device_not_available(struct pt_regs *regs, long error)
+{
+	if (read_cr0() & X86_CR0_EM) {
+		conditional_sti(regs);
+		math_emulate(0);
+	} else {
+		math_state_restore(); /* interrupts still off */
+		conditional_sti(regs);
+	}
+}
+
 void __init trap_init(void)
 {
 	int i;
@@ -1253,7 +1265,7 @@ void __init trap_init(void)
 	set_system_intr_gate(4, &overflow); /* int4 can be called from all */
 	set_intr_gate(5, &bounds);
 	set_intr_gate(6, &invalid_op);
-	set_trap_gate(7, &device_not_available);
+	set_intr_gate(7, &device_not_available);
 	set_task_gate(8, GDT_ENTRY_DOUBLEFAULT_TSS);
 	set_trap_gate(9, &coprocessor_segment_overrun);
 	set_trap_gate(10, &invalid_TSS);
Signature · 1 line
1.5.4.3
#9 lore raw

PATCH 9/24 i386: convert hardware exception 9 to an interrupt gate

From: Alexander van Heukelum <[email protected]>

Handle coprocessor segment overrun exception with interrupt initially off.

---
 arch/x86/kernel/traps_32.c |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)
arch/x86/kernel/traps_32.c +2 -2
index 3ddd71b..477946a 100644
@@ -637,7 +637,7 @@ DO_VM86_ERROR_INFO(0, SIGFPE, "divide error", divide_error, FPE_INTDIV, regs->ip
 DO_VM86_ERROR(4, SIGSEGV, "overflow", overflow)
 DO_VM86_ERROR(5, SIGSEGV, "bounds", bounds)
 DO_ERROR_INFO(6, SIGILL, "invalid opcode", invalid_op, ILL_ILLOPN, regs->ip, 0)
-DO_TRAP(9, SIGFPE, "coprocessor segment overrun", coprocessor_segment_overrun)
+DO_ERROR(9, SIGFPE, "coprocessor segment overrun", coprocessor_segment_overrun)
 DO_TRAP(10, SIGSEGV, "invalid TSS", invalid_TSS)
 DO_TRAP(11, SIGBUS, "segment not present", segment_not_present)
 DO_TRAP(12, SIGBUS, "stack segment", stack_segment)
@@ -1267,7 +1267,7 @@ void __init trap_init(void)
 	set_intr_gate(6, &invalid_op);
 	set_intr_gate(7, &device_not_available);
 	set_task_gate(8, GDT_ENTRY_DOUBLEFAULT_TSS);
-	set_trap_gate(9, &coprocessor_segment_overrun);
+	set_intr_gate(9, &coprocessor_segment_overrun);
 	set_trap_gate(10, &invalid_TSS);
 	set_trap_gate(11, &segment_not_present);
 	set_trap_gate(12, &stack_segment);
Signature · 1 line
1.5.4.3
#10 lore raw

PATCH 10/24 i386: convert hardware exception 10 to an interrupt gate

From: Alexander van Heukelum <[email protected]>

Handle invalid TSS exception with interrupt initially off.

---
 arch/x86/kernel/traps_32.c |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)
arch/x86/kernel/traps_32.c +2 -2
index 477946a..8ace1e2 100644
@@ -638,7 +638,7 @@ DO_VM86_ERROR(4, SIGSEGV, "overflow", overflow)
 DO_VM86_ERROR(5, SIGSEGV, "bounds", bounds)
 DO_ERROR_INFO(6, SIGILL, "invalid opcode", invalid_op, ILL_ILLOPN, regs->ip, 0)
 DO_ERROR(9, SIGFPE, "coprocessor segment overrun", coprocessor_segment_overrun)
-DO_TRAP(10, SIGSEGV, "invalid TSS", invalid_TSS)
+DO_ERROR(10, SIGSEGV, "invalid TSS", invalid_TSS)
 DO_TRAP(11, SIGBUS, "segment not present", segment_not_present)
 DO_TRAP(12, SIGBUS, "stack segment", stack_segment)
 DO_TRAP_INFO(17, SIGBUS, "alignment check", alignment_check, BUS_ADRALN, 0, 0)
@@ -1268,7 +1268,7 @@ void __init trap_init(void)
 	set_intr_gate(7, &device_not_available);
 	set_task_gate(8, GDT_ENTRY_DOUBLEFAULT_TSS);
 	set_intr_gate(9, &coprocessor_segment_overrun);
-	set_trap_gate(10, &invalid_TSS);
+	set_intr_gate(10, &invalid_TSS);
 	set_trap_gate(11, &segment_not_present);
 	set_trap_gate(12, &stack_segment);
 	set_trap_gate(13, &general_protection);
Signature · 1 line
1.5.4.3
#11 lore raw

PATCH 11/24 i386: convert hardware exception 11 to an interrupt gate

From: Alexander van Heukelum <[email protected]>

Handle segment not present exception with interrupt initially off.

---
 arch/x86/kernel/traps_32.c |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)
arch/x86/kernel/traps_32.c +2 -2
index 8ace1e2..572ea9f 100644
@@ -639,7 +639,7 @@ DO_VM86_ERROR(5, SIGSEGV, "bounds", bounds)
 DO_ERROR_INFO(6, SIGILL, "invalid opcode", invalid_op, ILL_ILLOPN, regs->ip, 0)
 DO_ERROR(9, SIGFPE, "coprocessor segment overrun", coprocessor_segment_overrun)
 DO_ERROR(10, SIGSEGV, "invalid TSS", invalid_TSS)
-DO_TRAP(11, SIGBUS, "segment not present", segment_not_present)
+DO_ERROR(11, SIGBUS, "segment not present", segment_not_present)
 DO_TRAP(12, SIGBUS, "stack segment", stack_segment)
 DO_TRAP_INFO(17, SIGBUS, "alignment check", alignment_check, BUS_ADRALN, 0, 0)
 DO_TRAP_INFO(32, SIGILL, "iret exception", iret_error, ILL_BADSTK, 0, 1)
@@ -1269,7 +1269,7 @@ void __init trap_init(void)
 	set_task_gate(8, GDT_ENTRY_DOUBLEFAULT_TSS);
 	set_intr_gate(9, &coprocessor_segment_overrun);
 	set_intr_gate(10, &invalid_TSS);
-	set_trap_gate(11, &segment_not_present);
+	set_intr_gate(11, &segment_not_present);
 	set_trap_gate(12, &stack_segment);
 	set_trap_gate(13, &general_protection);
 	set_intr_gate(14, &page_fault);
Signature · 1 line
1.5.4.3
#12 lore raw

PATCH 12/24 i386: convert hardware exception 12 to an interrupt gate

From: Alexander van Heukelum <[email protected]>

Handle stack segment exception with interrupt initially off.

---
 arch/x86/kernel/traps_32.c |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)
arch/x86/kernel/traps_32.c +2 -2
index 572ea9f..e535324 100644
@@ -640,7 +640,7 @@ DO_ERROR_INFO(6, SIGILL, "invalid opcode", invalid_op, ILL_ILLOPN, regs->ip, 0)
 DO_ERROR(9, SIGFPE, "coprocessor segment overrun", coprocessor_segment_overrun)
 DO_ERROR(10, SIGSEGV, "invalid TSS", invalid_TSS)
 DO_ERROR(11, SIGBUS, "segment not present", segment_not_present)
-DO_TRAP(12, SIGBUS, "stack segment", stack_segment)
+DO_ERROR(12, SIGBUS, "stack segment", stack_segment)
 DO_TRAP_INFO(17, SIGBUS, "alignment check", alignment_check, BUS_ADRALN, 0, 0)
 DO_TRAP_INFO(32, SIGILL, "iret exception", iret_error, ILL_BADSTK, 0, 1)
 
@@ -1270,7 +1270,7 @@ void __init trap_init(void)
 	set_intr_gate(9, &coprocessor_segment_overrun);
 	set_intr_gate(10, &invalid_TSS);
 	set_intr_gate(11, &segment_not_present);
-	set_trap_gate(12, &stack_segment);
+	set_intr_gate(12, &stack_segment);
 	set_trap_gate(13, &general_protection);
 	set_intr_gate(14, &page_fault);
 	set_trap_gate(15, &spurious_interrupt_bug);
Signature · 1 line
1.5.4.3
#13 lore raw

PATCH 13/24 i386: convert hardware exception 13 to an interrupt gate

From: Alexander van Heukelum <[email protected]>

Handle general protection exception with interrupt initially off.

---
 arch/x86/kernel/traps_32.c |    4 +++-
 1 files changed, 3 insertions(+), 1 deletions(-)
arch/x86/kernel/traps_32.c +3 -1
index e535324..c3b636e 100644
@@ -652,6 +652,8 @@ do_general_protection(struct pt_regs *regs, long error_code)
 	struct tss_struct *tss;
 	int cpu;
 
+	conditional_sti(regs);
+
 	cpu = get_cpu();
 	tss = &per_cpu(init_tss, cpu);
 	thread = &current->thread;
@@ -1271,7 +1273,7 @@ void __init trap_init(void)
 	set_intr_gate(10, &invalid_TSS);
 	set_intr_gate(11, &segment_not_present);
 	set_intr_gate(12, &stack_segment);
-	set_trap_gate(13, &general_protection);
+	set_intr_gate(13, &general_protection);
 	set_intr_gate(14, &page_fault);
 	set_trap_gate(15, &spurious_interrupt_bug);
 	set_trap_gate(16, &coprocessor_error);
Signature · 1 line
1.5.4.3
#14 lore raw

PATCH 14/24 i386: convert hardware exception 15 to an interrupt gate

From: Alexander van Heukelum <[email protected]>

Handle exception 15 with interrupt initially off.

---
 arch/x86/kernel/traps_32.c |    3 ++-
 1 files changed, 2 insertions(+), 1 deletions(-)
arch/x86/kernel/traps_32.c +2 -1
index c3b636e..ef934a2 100644
@@ -1162,6 +1162,7 @@ void do_simd_coprocessor_error(struct pt_regs *regs, long error_code)
 
 void do_spurious_interrupt_bug(struct pt_regs *regs, long error_code)
 {
+	conditional_sti(regs);
 #if 0
 	/* No need to warn about this any longer. */
 	printk(KERN_INFO "Ignoring P6 Local APIC Spurious Interrupt Bug...\n");
@@ -1275,7 +1276,7 @@ void __init trap_init(void)
 	set_intr_gate(12, &stack_segment);
 	set_intr_gate(13, &general_protection);
 	set_intr_gate(14, &page_fault);
-	set_trap_gate(15, &spurious_interrupt_bug);
+	set_intr_gate(15, &spurious_interrupt_bug);
 	set_trap_gate(16, &coprocessor_error);
 	set_trap_gate(17, &alignment_check);
 #ifdef CONFIG_X86_MCE
Signature · 1 line
1.5.4.3
#15 lore raw

PATCH 15/24 i386: convert hardware exception 16 to an interrupt gate

From: Alexander van Heukelum <[email protected]>

Handle coprocessor error exception with interrupt initially off.

---
 arch/x86/kernel/traps_32.c |    3 ++-
 1 files changed, 2 insertions(+), 1 deletions(-)
arch/x86/kernel/traps_32.c +2 -1
index ef934a2..733c0e3 100644
@@ -1086,6 +1086,7 @@ void math_error(void __user *ip)
 
 void do_coprocessor_error(struct pt_regs *regs, long error_code)
 {
+	conditional_sti(regs);
 	ignore_fpu_irq = 1;
 	math_error((void __user *)regs->ip);
 }
@@ -1277,7 +1278,7 @@ void __init trap_init(void)
 	set_intr_gate(13, &general_protection);
 	set_intr_gate(14, &page_fault);
 	set_intr_gate(15, &spurious_interrupt_bug);
-	set_trap_gate(16, &coprocessor_error);
+	set_intr_gate(16, &coprocessor_error);
 	set_trap_gate(17, &alignment_check);
 #ifdef CONFIG_X86_MCE
 	set_trap_gate(18, &machine_check);
Signature · 1 line
1.5.4.3
#16 lore raw

PATCH 16/24 i386: convert hardware exception 17 to an interrupt gate

From: Alexander van Heukelum <[email protected]>

Handle alignment check exception with interrupt initially off.

---
 arch/x86/kernel/traps_32.c |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)
arch/x86/kernel/traps_32.c +2 -2
index 733c0e3..bc8b21d 100644
@@ -641,7 +641,7 @@ DO_ERROR(9, SIGFPE, "coprocessor segment overrun", coprocessor_segment_overrun)
 DO_ERROR(10, SIGSEGV, "invalid TSS", invalid_TSS)
 DO_ERROR(11, SIGBUS, "segment not present", segment_not_present)
 DO_ERROR(12, SIGBUS, "stack segment", stack_segment)
-DO_TRAP_INFO(17, SIGBUS, "alignment check", alignment_check, BUS_ADRALN, 0, 0)
+DO_ERROR_INFO(17, SIGBUS, "alignment check", alignment_check, BUS_ADRALN, 0, 0)
 DO_TRAP_INFO(32, SIGILL, "iret exception", iret_error, ILL_BADSTK, 0, 1)
 
 void __kprobes
@@ -1279,7 +1279,7 @@ void __init trap_init(void)
 	set_intr_gate(14, &page_fault);
 	set_intr_gate(15, &spurious_interrupt_bug);
 	set_intr_gate(16, &coprocessor_error);
-	set_trap_gate(17, &alignment_check);
+	set_intr_gate(17, &alignment_check);
 #ifdef CONFIG_X86_MCE
 	set_trap_gate(18, &machine_check);
 #endif
Signature · 1 line
1.5.4.3
#17 lore raw

PATCH 17/24 i386: convert hardware exception 18 to an interrupt gate

From: Alexander van Heukelum <[email protected]>

Handle machine check exception with interrupt initially off.

---
 arch/x86/kernel/entry_32.S |    2 +-
 arch/x86/kernel/traps_32.c |   11 ++++++++++-
 2 files changed, 11 insertions(+), 2 deletions(-)
arch/x86/kernel/entry_32.S +1 -1
index 5a88585..c5fe01b 100644
@@ -1019,7 +1019,7 @@ ENTRY(machine_check)
 	RING0_INT_FRAME
 	pushl $0
 	CFI_ADJUST_CFA_OFFSET 4
-	pushl machine_check_vector
+	pushl $do_machine_check
 	CFI_ADJUST_CFA_OFFSET 4
 	jmp error_code
 	CFI_ENDPROC
arch/x86/kernel/traps_32.c +10 -1
index bc8b21d..f696914 100644
@@ -62,6 +62,7 @@
 #include <asm/traps.h>
 
 #include "mach_traps.h"
+#include "cpu/mcheck/mce.h"
 
 DECLARE_BITMAP(used_vectors, NR_VECTORS);
 EXPORT_SYMBOL_GPL(used_vectors);
@@ -1250,6 +1251,14 @@ void __kprobes do_device_not_available(struct pt_regs *regs, long error)
 	}
 }
 
+#ifdef CONFIG_X86_MCE
+void __kprobes do_machine_check(struct pt_regs *regs, long error)
+{
+	conditional_sti(regs);
+	machine_check_vector(regs, error);
+}
+#endif
+
 void __init trap_init(void)
 {
 	int i;
@@ -1281,7 +1290,7 @@ void __init trap_init(void)
 	set_intr_gate(16, &coprocessor_error);
 	set_intr_gate(17, &alignment_check);
 #ifdef CONFIG_X86_MCE
-	set_trap_gate(18, &machine_check);
+	set_intr_gate(18, &machine_check);
 #endif
 	set_trap_gate(19, &simd_coprocessor_error);
 
Signature · 1 line
1.5.4.3
#18 lore raw

PATCH 18/24 i386: convert hardware exception 19 to an interrupt gate

From: Alexander van Heukelum <[email protected]>

Handle SIMD coprocessor exception with interrupt initially off.

---
 arch/x86/kernel/traps_32.c |    4 +++-
 1 files changed, 3 insertions(+), 1 deletions(-)
arch/x86/kernel/traps_32.c +3 -1
index f696914..1ad7697 100644
@@ -1142,6 +1142,8 @@ static void simd_math_error(void __user *ip)
 
 void do_simd_coprocessor_error(struct pt_regs *regs, long error_code)
 {
+	conditional_sti(regs);
+
 	if (cpu_has_xmm) {
 		/* Handle SIMD FPU exceptions on PIII+ processors. */
 		ignore_fpu_irq = 1;
@@ -1292,7 +1294,7 @@ void __init trap_init(void)
 #ifdef CONFIG_X86_MCE
 	set_intr_gate(18, &machine_check);
 #endif
-	set_trap_gate(19, &simd_coprocessor_error);
+	set_intr_gate(19, &simd_coprocessor_error);
 
 	if (cpu_has_fxsr) {
 		printk(KERN_INFO "Enabling fast FPU save and restore... ");
Signature · 1 line
1.5.4.3
#19 lore raw

PATCH 19/24 i386: remove temporary DO_TRAP macros, expanding the last one used

From: Alexander van Heukelum <[email protected]>

Only one use of the DO_TRAP macros remains. Expand that one and remove the macros now.

---
 arch/x86/kernel/traps_32.c |   66 ++++++++++----------------------------------
 1 files changed, 15 insertions(+), 51 deletions(-)
arch/x86/kernel/traps_32.c +15 -51
index 1ad7697..7047760 100644
@@ -530,56 +530,6 @@ vm86_trap:
 	return;
 }
 
-#define DO_TRAP(trapnr, signr, str, name)				\
-void do_##name(struct pt_regs *regs, long error_code)			\
-{									\
-	trace_hardirqs_fixup();						\
-	if (notify_die(DIE_TRAP, str, regs, error_code, trapnr, signr)	\
-							== NOTIFY_STOP)	\
-		return;							\
-	do_trap(trapnr, signr, str, 0, regs, error_code, NULL);		\
-}
-
-#define DO_TRAP_INFO(trapnr, signr, str, name, sicode, siaddr, irq)	\
-void do_##name(struct pt_regs *regs, long error_code)			\
-{									\
-	siginfo_t info;							\
-	if (irq)							\
-		local_irq_enable();					\
-	info.si_signo = signr;						\
-	info.si_errno = 0;						\
-	info.si_code = sicode;						\
-	info.si_addr = (void __user *)siaddr;				\
-	if (notify_die(DIE_TRAP, str, regs, error_code, trapnr, signr)	\
-							== NOTIFY_STOP)	\
-		return;							\
-	do_trap(trapnr, signr, str, 0, regs, error_code, &info);	\
-}
-
-#define DO_VM86_TRAP(trapnr, signr, str, name)				\
-void do_##name(struct pt_regs *regs, long error_code)			\
-{									\
-	if (notify_die(DIE_TRAP, str, regs, error_code, trapnr, signr)	\
-							== NOTIFY_STOP)	\
-		return;							\
-	do_trap(trapnr, signr, str, 1, regs, error_code, NULL);		\
-}
-
-#define DO_VM86_TRAP_INFO(trapnr, signr, str, name, sicode, siaddr)	\
-void do_##name(struct pt_regs *regs, long error_code)			\
-{									\
-	siginfo_t info;							\
-	info.si_signo = signr;						\
-	info.si_errno = 0;						\
-	info.si_code = sicode;						\
-	info.si_addr = (void __user *)siaddr;				\
-	trace_hardirqs_fixup();						\
-	if (notify_die(DIE_TRAP, str, regs, error_code, trapnr, signr)	\
-							== NOTIFY_STOP)	\
-		return;							\
-	do_trap(trapnr, signr, str, 1, regs, error_code, &info);	\
-}
-
 #define DO_ERROR(trapnr, signr, str, name)				\
 void do_##name(struct pt_regs *regs, long error_code)			\
 {									\
@@ -643,7 +593,6 @@ DO_ERROR(10, SIGSEGV, "invalid TSS", invalid_TSS)
 DO_ERROR(11, SIGBUS, "segment not present", segment_not_present)
 DO_ERROR(12, SIGBUS, "stack segment", stack_segment)
 DO_ERROR_INFO(17, SIGBUS, "alignment check", alignment_check, BUS_ADRALN, 0, 0)
-DO_TRAP_INFO(32, SIGILL, "iret exception", iret_error, ILL_BADSTK, 0, 1)
 
 void __kprobes
 do_general_protection(struct pt_regs *regs, long error_code)
@@ -1261,6 +1210,21 @@ void __kprobes do_machine_check(struct pt_regs *regs, long error)
 }
 #endif
 
+void do_iret_error(struct pt_regs *regs, long error_code)
+{
+	siginfo_t info;
+	local_irq_enable();
+
+	info.si_signo = SIGILL;
+	info.si_errno = 0;
+	info.si_code = ILL_BADSTK;
+	info.si_addr = 0;
+	if (notify_die(DIE_TRAP, "iret exception",
+			regs, error_code, 32, SIGILL) == NOTIFY_STOP)
+		return;
+	do_trap(32, SIGILL, "iret exception", 0, regs, error_code, &info);
+}
+
 void __init trap_init(void)
 {
 	int i;
Signature · 1 line
1.5.4.3
#20 lore raw

PATCH 20/24 i386: add TRACE_IRQS_OFF to entry_32.S in 'error_code'

From: Alexander van Heukelum <[email protected]>

Many exceptions use the same code path via the label 'error_code' in entry_32.S. At this point interrupts are off, so let's inform the tracing code of that fact before calling into C.

---
 arch/x86/kernel/entry_32.S |    1 +
 1 files changed, 1 insertions(+), 0 deletions(-)
arch/x86/kernel/entry_32.S +1 -0
index c5fe01b..49438e5 100644
@@ -730,6 +730,7 @@ error_code:
 	movl $(__USER_DS), %ecx
 	movl %ecx, %ds
 	movl %ecx, %es
+	TRACE_IRQS_OFF
 	movl %esp,%eax			# pt_regs pointer
 	call *%edi
 	jmp ret_from_exception
Signature · 1 line
1.5.4.3
#21 lore raw

PATCH 21/24 i386: add TRACE_IRQS_OFF for exception 1 (debug)

From: Alexander van Heukelum <[email protected]>

At this point interrupts are off, so let's inform the tracing code of that fact before calling into C.

---
 arch/x86/kernel/entry_32.S |    1 +
 1 files changed, 1 insertions(+), 0 deletions(-)
arch/x86/kernel/entry_32.S +1 -0
index 49438e5..a278505 100644
@@ -804,6 +804,7 @@ debug_stack_correct:
 	pushl $-1			# mark this as an int
 	CFI_ADJUST_CFA_OFFSET 4
 	SAVE_ALL
+	TRACE_IRQS_OFF
 	xorl %edx,%edx			# error code 0
 	movl %esp,%eax			# pt_regs pointer
 	call do_debug
Signature · 1 line
1.5.4.3
#22 lore raw

PATCH 22/24 i386: add TRACE_IRQS_OFF for the nmi

From: Alexander van Heukelum <[email protected]>

At this point interrupts are off, so let's inform the tracing code of that fact before calling into C.

---
 arch/x86/kernel/entry_32.S |    2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)
arch/x86/kernel/entry_32.S +2 -0
index a278505..2abdc9a 100644
@@ -849,6 +849,7 @@ nmi_stack_correct:
 	pushl %eax
 	CFI_ADJUST_CFA_OFFSET 4
 	SAVE_ALL
+	TRACE_IRQS_OFF
 	xorl %edx,%edx		# zero error code
 	movl %esp,%eax		# pt_regs pointer
 	call do_nmi
@@ -889,6 +890,7 @@ nmi_espfix_stack:
 	pushl %eax
 	CFI_ADJUST_CFA_OFFSET 4
 	SAVE_ALL
+	TRACE_IRQS_OFF
 	FIXUP_ESPFIX_STACK		# %eax == %esp
 	xorl %edx,%edx			# zero error code
 	call do_nmi
Signature · 1 line
1.5.4.3
#23 lore raw

PATCH 23/24 i386: add TRACE_IRQS_OFF for the exception 3 (int3)

From: Alexander van Heukelum <[email protected]>

At this point interrupts are off, so let's inform the tracing code of that fact before calling into C.

---
 arch/x86/kernel/entry_32.S |    1 +
 1 files changed, 1 insertions(+), 0 deletions(-)
arch/x86/kernel/entry_32.S +1 -0
index 2abdc9a..b21fbfa 100644
@@ -921,6 +921,7 @@ KPROBE_ENTRY(int3)
 	pushl $-1			# mark this as an int
 	CFI_ADJUST_CFA_OFFSET 4
 	SAVE_ALL
+	TRACE_IRQS_OFF
 	xorl %edx,%edx		# zero error code
 	movl %esp,%eax		# pt_regs pointer
 	call do_int3
Signature · 1 line
1.5.4.3
#24 lore raw

PATCH 24/24 i386: trace_hardirqs_fixup should now not be necessary: irqs are off.

From: Alexander van Heukelum <[email protected]>

The exception handlers in entry_32.S should now all call TRACE_IRQS_OFF before calling the C code. The calls to trace_hardirqs_fixup should now be unnecessary. Remove them.

---
 arch/x86/kernel/traps_32.c |   10 ----------
 1 files changed, 0 insertions(+), 10 deletions(-)
arch/x86/kernel/traps_32.c +0 -10
index 7047760..041a25e 100644
@@ -533,7 +533,6 @@ vm86_trap:
 #define DO_ERROR(trapnr, signr, str, name)				\
 void do_##name(struct pt_regs *regs, long error_code)			\
 {									\
-	trace_hardirqs_fixup();						\
 	if (notify_die(DIE_TRAP, str, regs, error_code, trapnr, signr)	\
 							== NOTIFY_STOP)	\
 		return;							\
@@ -576,7 +575,6 @@ void do_##name(struct pt_regs *regs, long error_code)			\
 	info.si_errno = 0;						\
 	info.si_code = sicode;						\
 	info.si_addr = (void __user *)siaddr;				\
-	trace_hardirqs_fixup();						\
 	if (notify_die(DIE_TRAP, str, regs, error_code, trapnr, signr)	\
 							== NOTIFY_STOP)	\
 		return;							\
@@ -860,15 +858,9 @@ void restart_nmi(void)
 void __kprobes do_int3(struct pt_regs *regs, long error_code)
 {
 #ifdef CONFIG_KPROBES
-	trace_hardirqs_fixup();
-
 	if (notify_die(DIE_INT3, "int3", regs, error_code, 3, SIGTRAP)
 			== NOTIFY_STOP)
 		return;
-	/*
-	 * This is an interrupt gate, because kprobes wants interrupts
-	 * disabled. Normal trap handlers don't.
-	 */
 	conditional_sti(regs);
 #else
 	if (notify_die(DIE_TRAP, "int3", regs, error_code, 3, SIGTRAP)
@@ -906,8 +898,6 @@ void __kprobes do_debug(struct pt_regs *regs, long error_code)
 	struct task_struct *tsk = current;
 	unsigned int condition;
 
-	trace_hardirqs_fixup();
-
 	get_debugreg(condition, 6);
 
 	/*
Signature · 1 line
1.5.4.3
#25 lore raw

Re: [PATCH 22/24] i386: add TRACE_IRQS_OFF for the nmi

In reply to [email protected]
Quoted 4 lines · On Tue, 2008-09-09 at 21:56 +0200, [email protected] wrote:

From: Alexander van Heukelum <[email protected]>

At this point interrupts are off, so let's inform the tracing code of that fact before calling into C.

Sorry but this is an obvious dud, lockdep (and thus the irq state tracer) aren't nmi safe.

Ingo, please revert, as people are already seeing lockdep warnings due to this.

Quoted 25 lines
---
 arch/x86/kernel/entry_32.S |    2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)
arch/x86/kernel/entry_32.S +2 -0
index a278505..2abdc9a 100644
@@ -849,6 +849,7 @@ nmi_stack_correct:
 	pushl %eax
 	CFI_ADJUST_CFA_OFFSET 4
 	SAVE_ALL
+	TRACE_IRQS_OFF
 	xorl %edx,%edx		# zero error code
 	movl %esp,%eax		# pt_regs pointer
 	call do_nmi
@@ -889,6 +890,7 @@ nmi_espfix_stack:
 	pushl %eax
 	CFI_ADJUST_CFA_OFFSET 4
 	SAVE_ALL
+	TRACE_IRQS_OFF
 	FIXUP_ESPFIX_STACK		# %eax == %esp
 	xorl %edx,%edx			# zero error code
 	call do_nmi
#26 lore raw

Re: [PATCH 22/24] i386: add TRACE_IRQS_OFF for the nmi

Quoted 11 lines · Peter Zijlstra
Quoted 4 lines · On Tue, 2008-09-09 at 21:56 +0200, [email protected] wrote:

From: Alexander van Heukelum <[email protected]>

At this point interrupts are off, so let's inform the tracing code of that fact before calling into C.

Sorry but this is an obvious dud, lockdep (and thus the irq state tracer) aren't nmi safe.

Ingo, please revert, as people are already seeing lockdep warnings due to this.

done - reverted it in tip/x86/urgent, see the commit below. Is that all that we need, wasnt there a 64-bit side done too?

Ingo

--------------->

Quoted 1 line

From e8cea892dff8e3ebed42954c46730309b617196f Mon Sep 17 00:00:00 2001

From: Ingo Molnar <[email protected]>
Date: Mon, 12 Jan 2009 19:36:59 +0100
Subject: [PATCH] Revert "i386: add TRACE_IRQS_OFF for the nmi"

This reverts commit e0c7317557c8fc8eacf611e30c2a80f4e24e47a3.

This patch was wrong, as lockdep (and thus the irq state tracer) aren't nmi safe. People are already seeing lockdep warnings due to this.

---
 arch/x86/kernel/entry_32.S |    2 --
 1 files changed, 0 insertions(+), 2 deletions(-)
arch/x86/kernel/entry_32.S +0 -2
index d6f0490..4646902 100644
@@ -1203,7 +1203,6 @@ nmi_stack_correct:
 	pushl %eax
 	CFI_ADJUST_CFA_OFFSET 4
 	SAVE_ALL
-	TRACE_IRQS_OFF
 	xorl %edx,%edx		# zero error code
 	movl %esp,%eax		# pt_regs pointer
 	call do_nmi
@@ -1244,7 +1243,6 @@ nmi_espfix_stack:
 	pushl %eax
 	CFI_ADJUST_CFA_OFFSET 4
 	SAVE_ALL
-	TRACE_IRQS_OFF
 	FIXUP_ESPFIX_STACK		# %eax == %esp
 	xorl %edx,%edx			# zero error code
 	call do_nmi
#27 lore raw

Re: [PATCH 22/24] i386: add TRACE_IRQS_OFF for the nmi

Quoted 8 lines · Ingo Molnar
Quoted 6 lines · Peter Zijlstra
Quoted 4 lines · On Tue, 2008-09-09 at 21:56 +0200, [email protected] wrote:

From: Alexander van Heukelum <[email protected]>

At this point interrupts are off, so let's inform the tracing code of that fact before calling into C.

Quoted 8 lines
Quoted 5 lines

Sorry but this is an obvious dud, lockdep (and thus the irq state tracer) aren't nmi safe.

Ingo, please revert, as people are already seeing lockdep warnings due to this.

done - reverted it in tip/x86/urgent, see the commit below. Is that all that we need, wasnt there a 64-bit side done too?

I had a _very_ quick peek but couldn't fine one, Alexander, does your memory go back that far? :-)

#28 lore raw

Re: [PATCH 22/24] i386: add TRACE_IRQS_OFF for the nmi

Quoted 12 lines · Peter Zijlstra
Quoted 11 lines · Ingo Molnar
Quoted 9 lines · Peter Zijlstra
Quoted 4 lines · On Tue, 2008-09-09 at 21:56 +0200, [email protected] wrote:

From: Alexander van Heukelum <[email protected]>

At this point interrupts are off, so let's inform the tracing code of that fact before calling into C.

Sorry but this is an obvious dud, lockdep (and thus the irq state tracer) aren't nmi safe.

Quoted 8 lines
Quoted 5 lines
Quoted 2 lines

Ingo, please revert, as people are already seeing lockdep warnings due to this.

done - reverted it in tip/x86/urgent, see the commit below. Is that all that we need, wasnt there a 64-bit side done too?

I had a _very_ quick peek but couldn't fine one, Alexander, does your memory go back that far? :-)

Git helped a bit, I must admit. The 64-bit version does not include TRACE_IRQS_ON/TRACE_IRQS_OFF in the nmi handler. The comment above "ENTRY(paranoid_exit)" in entry_64.S should be updated, though. That code is not used for NMIs.

The revert is obviously the correct thing to do, but a comment would not hurt here either.

Greetings,
Alexander

Signature · 5 lines
  Alexander van Heukelum
  [email protected]

-- 
http://www.fastmail.fm - Access your email from home and the web
#29 lore raw
In reply to [email protected]
Quoted 7 lines · [email protected] wrote:

From: Alexander van Heukelum <[email protected]>

x86_64 handles all exceptions with interrupts off initially, this bisectable patch set does the same for i386, in (very) small steps. If this is acceptable, it would make further unification of traps_32.c and traps_64.c a lot easier. If it is not... why?

The only reason not to is that one generally doesn't want to disable interrupts unless necessary (bad for latency.) On 64 bits there are stack switches which make disabling interrupts mandatory. The only pitfall is if there is any code which is likely to take time, but I highly doubt it.

In other words, it's not something we want to do "just because", but to the extent that it provides real benefit, it makes sense.

-hpa

#30 lore raw
Quoted 9 lines · H. Peter Anvin
Quoted 7 lines · [email protected] wrote:

From: Alexander van Heukelum <[email protected]>

x86_64 handles all exceptions with interrupts off initially, this bisectable patch set does the same for i386, in (very) small steps. If this is acceptable, it would make further unification of traps_32.c and traps_64.c a lot easier. If it is not... why?

Quoted 5 lines

The only reason not to is that one generally doesn't want to disable interrupts unless necessary (bad for latency.) On 64 bits there are stack switches which make disabling interrupts mandatory. The only pitfall is if there is any code which is likely to take time, but I highly doubt it.

the entry paths here are really short (we enable irqs almost immediately) so it's a non-issue in terms of worst-case latencies.

Quoted 2 lines

In other words, it's not something we want to do "just because", but to the extent that it provides real benefit, it makes sense.

this is historically pretty fragile code so bringing the 32-bit and 64-bit variants more in line sounds like a good reason to me. For example we had various long-living irq state annotation bugs (the combination of kprobes and lockdep, etc.) that remained unfixed partly due to this assymetry.

There will be details i'm sure, but the series looks quite bisectable.

Ingo

#31 lore raw
Quoted 7 lines · Ingo Molnar

the entry paths here are really short (we enable irqs almost immediately) so it's a non-issue in terms of worst-case latencies.

Quoted 1 line

In other words, it's not something we want to do "just because", but to the extent that it provides real benefit, it makes sense.

this is historically pretty fragile code so bringing the 32-bit and 64-bit variants more in line sounds like a good reason to me. For example we had various long-living irq state annotation bugs (the combination of kprobes and lockdep, etc.) that remained unfixed partly due to this assymetry.

Agreed completely. I certainly didn't mean to come across sounding negative.

-hpa

#32 lore raw
Quoted 8 lines · H. Peter Anvin
Quoted 7 lines · Ingo Molnar

the entry paths here are really short (we enable irqs almost immediately) so it's a non-issue in terms of worst-case latencies.

Quoted 2 lines

In other words, it's not something we want to do "just because", but to the extent that it provides real benefit, it makes sense.

Quoted 8 lines
Quoted 5 lines

this is historically pretty fragile code so bringing the 32-bit and 64-bit variants more in line sounds like a good reason to me. For example we had various long-living irq state annotation bugs (the combination of kprobes and lockdep, etc.) that remained unfixed partly due to this assymetry.

Agreed completely. I certainly didn't mean to come across sounding negative.

great - i'll check which topic this fits in best. I suspect it will get its own topic - but there could be interactions as traps*.c is a central (and hence popular) file - here are the currently pending changes in -tip:

db4b0f1: kmemcheck: implement REP MOVS/STOS emulation 48e2bd5: x86: coding style fixes to arch/x86/kernel/traps_64.c
c9c3ddd: x86_64: remove empty lines from stack traces/oopses 4df9e51: x86: coding style fixes to arch/x86/kernel/traps_64.c
b359e8a: x86, xsave: context switch support using xsave/xrstor
dc1e35c: x86, xsave: enable xsave/xrstor on cpus with xsave support 862849a: x86: add hooks for kmemcheck on x86_64
787ecfa: x86: add hooks for kmemcheck
afdb702: x86: __show_registers() and __show_regs() API unification 0d84b78: x86 NMI-safe INT3 and Page Fault

we'll see.

Ingo

#33 lore raw
Quoted 3 lines · Ingo Molnar

great - i'll check which topic this fits in best. I suspect it will get its own topic - but there could be interactions as traps*.c is a central (and hence popular) file [...]

i've put Alexander's patches into a new -git based topic: tip/x86/traps
- and git sorted the merge into tip/master out automatically, so this will be ok logistically. The commits are below.

Ingo

------------------------>
71d6990: i386: trace_hardirqs_fixup should now not be necessary: irqs are off. 0dbf58b: i386: add TRACE_IRQS_OFF for the exception 3 (int3) 340f725: i386: add TRACE_IRQS_OFF for the nmi
c320a17: i386: add TRACE_IRQS_OFF for exception 1 (debug)
b51f1c3: i386: add TRACE_IRQS_OFF to entry_32.S in 'error_code'
d7af1f9: i386: remove temporary DO_TRAP macros, expanding the last one used 8915399: i386: convert hardware exception 19 to an interrupt gate
cc0302d: i386: convert hardware exception 18 to an interrupt gate
ed530ad: i386: convert hardware exception 17 to an interrupt gate 97082d7: i386: convert hardware exception 16 to an interrupt gate
d2ac8fa: i386: convert hardware exception 15 to an interrupt gate 0fdfcc7: i386: convert hardware exception 13 to an interrupt gate
f490c71: i386: convert hardware exception 12 to an interrupt gate
c4781f3: i386: convert hardware exception 11 to an interrupt gate 22d09d5: i386: convert hardware exception 10 to an interrupt gate 00f28ef: i386: convert hardware exception 9 to an interrupt gate 3a08e35: i386: convert hardware exception 7 to an interrupt gate 1fb2f60: i386: convert hardware exception 6 to an interrupt gate 4b00f5f: i386: convert hardware exception 5 to an interrupt gate 118ab1a: i386: convert hardware exception 4 to an interrupt gate 376de73: i386: expand exception 3 DO_TRAP macro
bec6f72: i386: convert hardware exception 0 to an interrupt gate
d72fa10: i386: prepare to convert exceptions to interrupts
b5721fe9: i386: remove kprobes' restore_interrupts in favour of conditional_sti

#34 lore raw
Quoted 9 lines · Ingo Molnar
Quoted 3 lines · Ingo Molnar

great - i'll check which topic this fits in best. I suspect it will get its own topic - but there could be interactions as traps*.c is a central (and hence popular) file [...]

i've put Alexander's patches into a new -git based topic: tip/x86/traps
- and git sorted the merge into tip/master out automatically, so this will be ok logistically. The commits are below.

Great! Let's see if it works out.

Thanks,
Alexander

Quoted 1 line

Ingo

Signature · 5 lines
  Alexander van Heukelum
  [email protected]

-- 
http://www.fastmail.fm - Does exactly what it says on the tin