Skip to contentSkip to conversation

x86: Only call smp_processor_id in non-preempt cases

PATCH In review Don Zickus 3 participants 6 messages Jan 5, 2011 x86

lore
Share & tools
lore

Don Zickus

author
#0 lore raw

PATCH 1/3 x86: Only call smp_processor_id in non-preempt cases

There are some paths that walk the die_chain with preemption on. Make sure we are in an NMI call before we start doing anything.

This was triggered by do_general_protection calling notify_die with DIE_GPF.

---
 arch/x86/kernel/apic/hw_nmi.c |    3 ++-
 1 files changed, 2 insertions(+), 1 deletions(-)
arch/x86/kernel/apic/hw_nmi.c +2 -1
index c57d0b5..2b40a60 100644
@@ -51,7 +51,7 @@ arch_trigger_all_cpu_backtrace_handler(struct notifier_block *self,
 {
 	struct die_args *args = __args;
 	struct pt_regs *regs;
-	int cpu = smp_processor_id();
+	int cpu;
 
 	switch (cmd) {
 	case DIE_NMI:
@@ -63,6 +63,7 @@ arch_trigger_all_cpu_backtrace_handler(struct notifier_block *self,
 	}
 
 	regs = args->regs;
+	cpu = smp_processor_id();
 
 	if (cpumask_test_cpu(cpu, to_cpumask(backtrace_mask))) {
 		static arch_spinlock_t lock = __ARCH_SPIN_LOCK_UNLOCKED;
Signature · 1 line
1.7.3.4
author
#1 lore raw

PATCH 2/3 x86: Avoid calling arch_trigger_all_cpu_backtrace() at the same time

From: Dongdong Deng <[email protected]>

The spin_lock_debug/rcu_cpu_stall detector uses trigger_all_cpu_backtrace() to dump cpu backtrace. Therefore it is possible that trigger_all_cpu_backtrace() could be called at the same time on different CPUs, which triggers and 'unknown reason NMI' warning. The following case illustrates the problem:

CPU1 CPU2 ... CPU N
trigger_all_cpu_backtrace() set "backtrace_mask" to cpu mask
|
generate NMI interrupts generate NMI interrupts ...
\ | /
\ | /

The "backtrace_mask" will be cleaned by the first NMI interrupt at nmi_watchdog_tick(), then the following NMI interrupts generated by other cpus's arch_trigger_all_cpu_backtrace() will be taken as unknown reason NMI interrupts.

This patch uses a test_and_set to avoid the problem, and stop the arch_trigger_all_cpu_backtrace() from calling to avoid dumping a double cpu backtrace info when there is already a trigger_all_cpu_backtrace() in progress.

---
 arch/x86/kernel/apic/hw_nmi.c |   13 +++++++++++++
 1 files changed, 13 insertions(+), 0 deletions(-)
arch/x86/kernel/apic/hw_nmi.c +13 -0
index 2b40a60..72ec29e 100644
@@ -28,10 +28,20 @@ u64 hw_nmi_get_sample_period(void)
 /* For reliability, we're prepared to waste bits here. */
 static DECLARE_BITMAP(backtrace_mask, NR_CPUS) __read_mostly;
 
+/* "in progress" flag of arch_trigger_all_cpu_backtrace */
+static unsigned long backtrace_flag;
+
 void arch_trigger_all_cpu_backtrace(void)
 {
 	int i;
 
+	if (test_and_set_bit(0, &backtrace_flag))
+		/*
+		 * If there is already a trigger_all_cpu_backtrace() in progress
+		 * (backtrace_flag == 1), don't output double cpu dump infos.
+		 */
+		return;
+
 	cpumask_copy(to_cpumask(backtrace_mask), cpu_online_mask);
 
 	printk(KERN_INFO "sending NMI to all CPUs:\n");
@@ -43,6 +53,9 @@ void arch_trigger_all_cpu_backtrace(void)
 			break;
 		mdelay(1);
 	}
+
+	clear_bit(0, &backtrace_flag);
+	smp_mb__after_clear_bit();
 }
 
 static int __kprobes
Signature · 1 line
1.7.3.4
#2 lore raw

[tip:perf/core] x86: Avoid calling arch_trigger_all_cpu_backtrace() at the same time

Commit-ID:  554ec063982752e9a569ab9189eeffa3d96731b2
Gitweb:     http://git.kernel.org/tip/554ec063982752e9a569ab9189eeffa3d96731b2
Author:     Dongdong Deng <[email protected]>
AuthorDate: Tue, 4 Jan 2011 22:38:08 -0500
Committer:  Ingo Molnar <[email protected]>
CommitDate: Wed, 5 Jan 2011 14:22:57 +0100

x86: Avoid calling arch_trigger_all_cpu_backtrace() at the same time

The spin_lock_debug/rcu_cpu_stall detector uses trigger_all_cpu_backtrace() to dump cpu backtrace. Therefore it is possible that trigger_all_cpu_backtrace() could be called at the same time on different CPUs, which triggers and 'unknown reason NMI' warning. The following case illustrates the problem:

CPU1 CPU2 ... CPU N
trigger_all_cpu_backtrace() set "backtrace_mask" to cpu mask
|
generate NMI interrupts generate NMI interrupts ...
\ | /
\ | /

The "backtrace_mask" will be cleaned by the first NMI interrupt at nmi_watchdog_tick(), then the following NMI interrupts generated by other cpus's arch_trigger_all_cpu_backtrace() will be taken as unknown reason NMI interrupts.

This patch uses a test_and_set to avoid the problem, and stop the arch_trigger_all_cpu_backtrace() from calling to avoid dumping a double cpu backtrace info when there is already a trigger_all_cpu_backtrace() in progress.

LKML-Reference: <[email protected]>

---
 arch/x86/kernel/apic/hw_nmi.c |   13 +++++++++++++
 1 files changed, 13 insertions(+), 0 deletions(-)
arch/x86/kernel/apic/hw_nmi.c +13 -0
index 2b40a60..72ec29e 100644
@@ -28,10 +28,20 @@ u64 hw_nmi_get_sample_period(void)
 /* For reliability, we're prepared to waste bits here. */
 static DECLARE_BITMAP(backtrace_mask, NR_CPUS) __read_mostly;
 
+/* "in progress" flag of arch_trigger_all_cpu_backtrace */
+static unsigned long backtrace_flag;
+
 void arch_trigger_all_cpu_backtrace(void)
 {
 	int i;
 
+	if (test_and_set_bit(0, &backtrace_flag))
+		/*
+		 * If there is already a trigger_all_cpu_backtrace() in progress
+		 * (backtrace_flag == 1), don't output double cpu dump infos.
+		 */
+		return;
+
 	cpumask_copy(to_cpumask(backtrace_mask), cpu_online_mask);
 
 	printk(KERN_INFO "sending NMI to all CPUs:\n");
@@ -43,6 +53,9 @@ void arch_trigger_all_cpu_backtrace(void)
 			break;
 		mdelay(1);
 	}
+
+	clear_bit(0, &backtrace_flag);
+	smp_mb__after_clear_bit();
 }
 
 static int __kprobes
author
#3 lore raw

PATCH 3/3 x86, NMI: Add touch_nmi_watchdog to io_check_error delay

In reply to Don Zickus

From: Huang Ying <[email protected]>

Prevent the long delay in io_check_error making NMI watchdog timeout.

---
 arch/x86/kernel/traps.c |    8 +++++---
 1 files changed, 5 insertions(+), 3 deletions(-)
arch/x86/kernel/traps.c +5 -3
index bb6f041..c76aaca 100644
@@ -351,9 +351,11 @@ io_check_error(unsigned char reason, struct pt_regs *regs)
 	reason = (reason & 0xf) | 8;
 	outb(reason, 0x61);
 
-	i = 2000;
-	while (--i)
-		udelay(1000);
+	i = 20000;
+	while (--i) {
+		touch_nmi_watchdog();
+		udelay(100);
+	}
 
 	reason &= ~8;
 	outb(reason, 0x61);
Signature · 1 line
1.7.3.4
#4 lore raw

[tip:perf/core] x86, NMI: Add touch_nmi_watchdog to io_check_error delay

Commit-ID:  74d91e3c6a66359bb754fb5d8a5b54fb6ba2f9a6
Gitweb:     http://git.kernel.org/tip/74d91e3c6a66359bb754fb5d8a5b54fb6ba2f9a6
Author:     Huang Ying <[email protected]>
AuthorDate: Tue, 4 Jan 2011 22:38:09 -0500
Committer:  Ingo Molnar <[email protected]>
CommitDate: Wed, 5 Jan 2011 14:22:58 +0100

x86, NMI: Add touch_nmi_watchdog to io_check_error delay

Prevent the long delay in io_check_error making NMI watchdog timeout.

LKML-Reference: <[email protected]>

---
 arch/x86/kernel/traps.c |    8 +++++---
 1 files changed, 5 insertions(+), 3 deletions(-)
arch/x86/kernel/traps.c +5 -3
index bb6f041..c76aaca 100644
@@ -351,9 +351,11 @@ io_check_error(unsigned char reason, struct pt_regs *regs)
 	reason = (reason & 0xf) | 8;
 	outb(reason, 0x61);
 
-	i = 2000;
-	while (--i)
-		udelay(1000);
+	i = 20000;
+	while (--i) {
+		touch_nmi_watchdog();
+		udelay(100);
+	}
 
 	reason &= ~8;
 	outb(reason, 0x61);
#5 lore raw
In reply to Don Zickus
Commit-ID:  9ab181fa9ff73a38fccd0a4f1c40a38dfe62b535
Gitweb:     http://git.kernel.org/tip/9ab181fa9ff73a38fccd0a4f1c40a38dfe62b535
Author:     Don Zickus <[email protected]>
AuthorDate: Tue, 4 Jan 2011 22:38:07 -0500
Committer:  Ingo Molnar <[email protected]>
CommitDate: Wed, 5 Jan 2011 14:22:57 +0100

x86: Only call smp_processor_id in non-preempt cases

There are some paths that walk the die_chain with preemption on. Make sure we are in an NMI call before we start doing anything.

This was triggered by do_general_protection calling notify_die with DIE_GPF.

LKML-Reference: <[email protected]>

---
 arch/x86/kernel/apic/hw_nmi.c |    3 ++-
 1 files changed, 2 insertions(+), 1 deletions(-)
arch/x86/kernel/apic/hw_nmi.c +2 -1
index c57d0b5..2b40a60 100644
@@ -51,7 +51,7 @@ arch_trigger_all_cpu_backtrace_handler(struct notifier_block *self,
 {
 	struct die_args *args = __args;
 	struct pt_regs *regs;
-	int cpu = smp_processor_id();
+	int cpu;
 
 	switch (cmd) {
 	case DIE_NMI:
@@ -63,6 +63,7 @@ arch_trigger_all_cpu_backtrace_handler(struct notifier_block *self,
 	}
 
 	regs = args->regs;
+	cpu = smp_processor_id();
 
 	if (cpumask_test_cpu(cpu, to_cpumask(backtrace_mask))) {
 		static arch_spinlock_t lock = __ARCH_SPIN_LOCK_UNLOCKED;