Skip to contentSkip to conversation

x86, NMI: give NMI handler a face-lift

PATCH Superseded Don Zickus 6 participants 34 messages Oct 16, 2010 – Oct 21, 2010

Subsystems (5)

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Don Zickus

author
#0 lore raw

cover x86, NMI: give NMI handler a face-lift

Restructuring the nmi handler to be more readable and simpler.

This is just laying the ground work for future improvements in this area.

I know people were complaining about having DIE_NMI and DIE_NMI_IPI, but for now it is consistent with what was there before. Hopefully, we can modify the notifier chain to make it smarter and combine the two events.

I also left out one of Huang's patch until we figure out how we are going to proceed with a new notifier.

Tested 32-bit and 64-bit on AMD and Intel machines.

Cheers,
Don

Huang Ying (5):
x86, NMI: Add NMI symbol constants and rename memory parity to PCI
SERR
x86, NMI: Add touch_nmi_watchdog to io_check_error delay x86, NMI: Rewrite NMI handler
x86, NMI: Allow NMI reason io port (0x61) to be processed on any CPU x86, NMI: Remove do_nmi_callback logic

 arch/x86/include/asm/mach_traps.h |   12 +++-
 arch/x86/include/asm/nmi.h        |   10 +++-
 arch/x86/kernel/apic/hw_nmi.c     |    1 -
 arch/x86/kernel/apic/nmi.c        |   29 +-------
 arch/x86/kernel/cpu/perf_event.c  |    1 -
 arch/x86/kernel/traps.c           |  141 ++++++++++++++++++++----------------
 arch/x86/oprofile/nmi_int.c       |    1 -
 arch/x86/oprofile/nmi_timer_int.c |    2 +-
 drivers/char/ipmi/ipmi_watchdog.c |    2 +-
 drivers/watchdog/hpwdt.c          |    2 +-
 10 files changed, 102 insertions(+), 99 deletions(-)
Signature · 1 line
1.7.2.3
author
#1 lore raw

PATCH 1/5 x86, NMI: Add NMI symbol constants and rename memory parity to PCI SERR

From: Huang Ying <[email protected]>

Replace the NMI related magic numbers with symbol constants.

memory parity error is only valid for IBM PC-AT, newer machine use bit 7 (0x80) of 0x61 port for PCI SERR. While memory error is usually reported via MCE. So corresponding function name and kernel log string is changed.

But on some machines, PCI SERR line is still used to report memory errors. This is used by EDAC, so corresponding EDAC call is reserved.

v3:

- Merge adding symbol constants and renaming patches

v2:

- EDAC call in pci_serr_error is reserved.

---
 arch/x86/include/asm/mach_traps.h |   12 ++++++++-
 arch/x86/kernel/traps.c           |   51 +++++++++++++++++++------------------
 2 files changed, 37 insertions(+), 26 deletions(-)
arch/x86/include/asm/mach_traps.h +11 -1
index f792060..72a8b52 100644
@@ -7,9 +7,19 @@
 
 #include <asm/mc146818rtc.h>
 
+#define NMI_REASON_PORT		0x61
+
+#define NMI_REASON_SERR		0x80
+#define NMI_REASON_IOCHK	0x40
+#define NMI_REASON_MASK		(NMI_REASON_SERR | NMI_REASON_IOCHK)
+
+#define NMI_REASON_CLEAR_SERR	0x04
+#define NMI_REASON_CLEAR_IOCHK	0x08
+#define NMI_REASON_CLEAR_MASK	0x0f
+
 static inline unsigned char get_nmi_reason(void)
 {
-	return inb(0x61);
+	return inb(NMI_REASON_PORT);
 }
 
 static inline void reassert_nmi(void)
arch/x86/kernel/traps.c +26 -25

105 lines not on this page · raw message

Signature · 1 line
1.7.2.3
#2 lore raw

[tip:perf/core] x86, NMI: Add NMI symbol constants and rename memory parity to PCI SERR

Commit-ID:  88de48ce3d1c384079bf5b603d3056ae2d60a185
Gitweb:     http://git.kernel.org/tip/88de48ce3d1c384079bf5b603d3056ae2d60a185
Author:     Huang Ying <[email protected]>
AuthorDate: Fri, 15 Oct 2010 22:22:14 -0400
Committer:  Ingo Molnar <[email protected]>
CommitDate: Sat, 16 Oct 2010 15:01:27 +0200

x86, NMI: Add NMI symbol constants and rename memory parity to PCI SERR

Replace the NMI related magic numbers with symbol constants.

memory parity error is only valid for IBM PC-AT, newer machine use bit 7 (0x80) of 0x61 port for PCI SERR. While memory error is usually reported via MCE. So corresponding function name and kernel log string is changed.

But on some machines, PCI SERR line is still used to report memory errors. This is used by EDAC, so corresponding EDAC call is reserved.

v3:

- Merge adding symbol constants and renaming patches

v2:

- EDAC call in pci_serr_error is reserved.

LKML-Reference: <[email protected]>

---
 arch/x86/include/asm/mach_traps.h |   12 ++++++++-
 arch/x86/kernel/traps.c           |   51 +++++++++++++++++++------------------
 2 files changed, 37 insertions(+), 26 deletions(-)
arch/x86/include/asm/mach_traps.h +11 -1
index f792060..72a8b52 100644
@@ -7,9 +7,19 @@
 
 #include <asm/mc146818rtc.h>
 
+#define NMI_REASON_PORT		0x61
+
+#define NMI_REASON_SERR		0x80
+#define NMI_REASON_IOCHK	0x40
+#define NMI_REASON_MASK		(NMI_REASON_SERR | NMI_REASON_IOCHK)
+
+#define NMI_REASON_CLEAR_SERR	0x04
+#define NMI_REASON_CLEAR_IOCHK	0x08
+#define NMI_REASON_CLEAR_MASK	0x0f
+
 static inline unsigned char get_nmi_reason(void)
 {
-	return inb(0x61);
+	return inb(NMI_REASON_PORT);
 }
 
 static inline void reassert_nmi(void)
arch/x86/kernel/traps.c +26 -25

105 lines not on this page · raw message

author
#3 lore raw

PATCH 2/5 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 e04e59b..bef859e 100644
@@ -344,9 +344,11 @@ io_check_error(unsigned char reason, struct pt_regs *regs)
 	reason = (reason & NMI_REASON_CLEAR_MASK) | NMI_REASON_CLEAR_IOCHK;
 	outb(reason, NMI_REASON_PORT);
 
-	i = 2000;
-	while (--i)
-		udelay(1000);
+	i = 20000;
+	while (--i) {
+		touch_nmi_watchdog();
+		udelay(100);
+	}
 
 	reason &= ~NMI_REASON_CLEAR_IOCHK;
 	outb(reason, NMI_REASON_PORT);
Signature · 1 line
1.7.2.3
#4 lore raw

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

Commit-ID:  3ef3df20bcfa7d271b40ec79ea6db9534ecd1322
Gitweb:     http://git.kernel.org/tip/3ef3df20bcfa7d271b40ec79ea6db9534ecd1322
Author:     Huang Ying <[email protected]>
AuthorDate: Fri, 15 Oct 2010 22:22:15 -0400
Committer:  Ingo Molnar <[email protected]>
CommitDate: Sat, 16 Oct 2010 15:01:27 +0200

x86, NMI: Add touch_nmi_watchdog to io_check_error delay

Prevent the long delay in io_check_error triggering a 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 e04e59b..bef859e 100644
@@ -344,9 +344,11 @@ io_check_error(unsigned char reason, struct pt_regs *regs)
 	reason = (reason & NMI_REASON_CLEAR_MASK) | NMI_REASON_CLEAR_IOCHK;
 	outb(reason, NMI_REASON_PORT);
 
-	i = 2000;
-	while (--i)
-		udelay(1000);
+	i = 20000;
+	while (--i) {
+		touch_nmi_watchdog();
+		udelay(100);
+	}
 
 	reason &= ~NMI_REASON_CLEAR_IOCHK;
 	outb(reason, NMI_REASON_PORT);
author
#5 lore raw

PATCH 3/5 x86, NMI: Rewrite NMI handler

In reply to Don Zickus

From: Huang Ying <[email protected]>

The original NMI handler is quite outdated in many aspects. This patch try to fix it.

The order to process the NMI sources are changed as follow:

notify_die(DIE_NMI_IPI);
notify_die(DIE_NMI);
/* process io port 0x61 */
nmi_watchdog_touch();
unknown_nmi();

DIE_NMI_IPI is used to process CPU specific NMI sources, such as perf event, oprofile, crash IPI, etc. While DIE_NMI is used to process non-CPU-specific NMI sources, such as APEI (ACPI Platform Error Interface) GHES (Generic Hardware Error Source), etc. Non-CPU-specific NMI sources can be processed on any CPU,

DIE_NMI_IPI must be processed before DIE_NMI. For example, perf event trigger a NMI on CPU 1, at the same time, APEI GHES trigger another NMI on CPU 0. If DIE_NMI is processed before DIE_NMI_IPI, it is possible that APEI GHES is processed on CPU 1, while unknown NMI is gotten on CPU 0.

In this new order of processing, performance sensitive NMI sources such as oprofile or perf event will have better performance because the time consuming IO port reading is done after them.

Only one NMI is eaten for each NMI handler call, even for PCI SERR and IOCHK NMIs. Because one NMI should be raised for each of them, eating too many NMI will cause unnecessary unknown NMI.

The die value used in NMI sources are fixed accordingly.

The NMI handler in the patch is designed by Andi Kleen.

v3:

- Make DIE_NMI and DIE_NMI_UNKNOWN work in more traditional way.

v2:

- Split process NMI reason (0x61) on non-BSP into another patch

---
 arch/x86/kernel/cpu/perf_event.c  |    1 -
 arch/x86/kernel/traps.c           |   78 +++++++++++++++++++------------------
 arch/x86/oprofile/nmi_int.c       |    1 -
 arch/x86/oprofile/nmi_timer_int.c |    2 +-
 drivers/char/ipmi/ipmi_watchdog.c |    2 +-
 drivers/watchdog/hpwdt.c          |    2 +-
 6 files changed, 43 insertions(+), 43 deletions(-)
arch/x86/kernel/cpu/perf_event.c +0 -1
index e2513f2..8ed55be 100644
@@ -1245,7 +1245,6 @@ perf_event_nmi_handler(struct notifier_block *self,
 		return NOTIFY_DONE;
 
 	switch (cmd) {
-	case DIE_NMI:
 	case DIE_NMI_IPI:
 		break;
 	case DIE_NMIUNKNOWN:
arch/x86/kernel/traps.c +40 -38

93 lines not on this page · raw message

arch/x86/oprofile/nmi_int.c +0 -1
index f1575c9..69f2453 100644
@@ -64,7 +64,6 @@ static int profile_exceptions_notify(struct notifier_block *self,
 	int ret = NOTIFY_DONE;
 
 	switch (val) {
-	case DIE_NMI:
 	case DIE_NMI_IPI:
 		if (ctr_running)
 			model->check_ctrs(args->regs, &__get_cpu_var(cpu_msrs));
arch/x86/oprofile/nmi_timer_int.c +1 -1
index e3ecb71..ab72a21 100644
@@ -25,7 +25,7 @@ static int profile_timer_exceptions_notify(struct notifier_block *self,
 	int ret = NOTIFY_DONE;
 
 	switch (val) {
-	case DIE_NMI:
+	case DIE_NMI_IPI:
 		oprofile_add_sample(args->regs, 0);
 		ret = NOTIFY_STOP;
 		break;
drivers/char/ipmi/ipmi_watchdog.c +1 -1
index 654d566..6a273fb 100644
@@ -1080,7 +1080,7 @@ ipmi_nmi(struct notifier_block *self, unsigned long val, void *data)
 {
 	struct die_args *args = data;
 
-	if (val != DIE_NMI)
+	if (val != DIE_NMIUNKNOWN)
 		return NOTIFY_OK;
 
 	/* Hack, if it's a memory or I/O error, ignore it. */
drivers/watchdog/hpwdt.c +1 -1
index 3d77116..d8010cc 100644
@@ -469,7 +469,7 @@ static int hpwdt_pretimeout(struct notifier_block *nb, unsigned long ulReason,
 	unsigned long rom_pl;
 	static int die_nmi_called;
 
-	if (ulReason != DIE_NMI && ulReason != DIE_NMI_IPI)
+	if (ulReason != DIE_NMIUNKNOWN)
 		goto out;
 
 	if (!hpwdt_nmi_decoding)
Signature · 1 line
1.7.2.3
#6 lore raw

[tip:perf/core] x86, NMI: Rewrite NMI handler

Commit-ID:  e21f3e4957f4a55f546873605a5caa59556bb144
Gitweb:     http://git.kernel.org/tip/e21f3e4957f4a55f546873605a5caa59556bb144
Author:     Huang Ying <[email protected]>
AuthorDate: Fri, 15 Oct 2010 22:22:16 -0400
Committer:  Ingo Molnar <[email protected]>
CommitDate: Sat, 16 Oct 2010 15:01:27 +0200

x86, NMI: Rewrite NMI handler

The original NMI handler is quite outdated in many aspects. This patch tries to fix it.

The order to process the NMI sources are changed as follow:

notify_die(DIE_NMI_IPI);
notify_die(DIE_NMI);
/* process io port 0x61 */
nmi_watchdog_touch();
unknown_nmi();

DIE_NMI_IPI is used to process CPU specific NMI sources, such as perf event, oprofile, crash IPI, etc. While DIE_NMI is used to process non-CPU-specific NMI sources, such as APEI (ACPI Platform Error Interface) GHES (Generic Hardware Error Source), etc. Non-CPU-specific NMI sources can be processed on any CPU,

DIE_NMI_IPI must be processed before DIE_NMI. For example, perf event trigger a NMI on CPU 1, at the same time, APEI GHES trigger another NMI on CPU 0. If DIE_NMI is processed before DIE_NMI_IPI, it is possible that APEI GHES is processed on CPU 1, while unknown NMI is gotten on CPU 0.

In this new order of processing, performance sensitive NMI sources such as oprofile or perf event will have better performance because the time consuming IO port reading is done after them.

Only one NMI is eaten for each NMI handler call, even for PCI SERR and IOCHK NMIs. Because one NMI should be raised for each of them, eating too many NMI will cause unnecessary unknown NMI.

The die value used in NMI sources are fixed accordingly.

The NMI handler in the patch is designed by Andi Kleen.

v3:

- Make DIE_NMI and DIE_NMI_UNKNOWN work in more traditional way.

v2:

- Split process NMI reason (0x61) on non-BSP into another patch

LKML-Reference: <[email protected]>

---
 arch/x86/kernel/cpu/perf_event.c  |    1 -
 arch/x86/kernel/traps.c           |   78 +++++++++++++++++++------------------
 arch/x86/oprofile/nmi_int.c       |    1 -
 arch/x86/oprofile/nmi_timer_int.c |    2 +-
 drivers/char/ipmi/ipmi_watchdog.c |    2 +-
 drivers/watchdog/hpwdt.c          |    2 +-
 6 files changed, 43 insertions(+), 43 deletions(-)
arch/x86/kernel/cpu/perf_event.c +0 -1
index e2513f2..8ed55be 100644
@@ -1245,7 +1245,6 @@ perf_event_nmi_handler(struct notifier_block *self,
 		return NOTIFY_DONE;
 
 	switch (cmd) {
-	case DIE_NMI:
 	case DIE_NMI_IPI:
 		break;
 	case DIE_NMIUNKNOWN:
arch/x86/kernel/traps.c +40 -38

93 lines not on this page · raw message

arch/x86/oprofile/nmi_int.c +0 -1
index f1575c9..69f2453 100644
@@ -64,7 +64,6 @@ static int profile_exceptions_notify(struct notifier_block *self,
 	int ret = NOTIFY_DONE;
 
 	switch (val) {
-	case DIE_NMI:
 	case DIE_NMI_IPI:
 		if (ctr_running)
 			model->check_ctrs(args->regs, &__get_cpu_var(cpu_msrs));
arch/x86/oprofile/nmi_timer_int.c +1 -1
index e3ecb71..ab72a21 100644
@@ -25,7 +25,7 @@ static int profile_timer_exceptions_notify(struct notifier_block *self,
 	int ret = NOTIFY_DONE;
 
 	switch (val) {
-	case DIE_NMI:
+	case DIE_NMI_IPI:
 		oprofile_add_sample(args->regs, 0);
 		ret = NOTIFY_STOP;
 		break;
drivers/char/ipmi/ipmi_watchdog.c +1 -1
index 654d566..6a273fb 100644
@@ -1080,7 +1080,7 @@ ipmi_nmi(struct notifier_block *self, unsigned long val, void *data)
 {
 	struct die_args *args = data;
 
-	if (val != DIE_NMI)
+	if (val != DIE_NMIUNKNOWN)
 		return NOTIFY_OK;
 
 	/* Hack, if it's a memory or I/O error, ignore it. */
drivers/watchdog/hpwdt.c +1 -1
index 3d77116..d8010cc 100644
@@ -469,7 +469,7 @@ static int hpwdt_pretimeout(struct notifier_block *nb, unsigned long ulReason,
 	unsigned long rom_pl;
 	static int die_nmi_called;
 
-	if (ulReason != DIE_NMI && ulReason != DIE_NMI_IPI)
+	if (ulReason != DIE_NMIUNKNOWN)
 		goto out;
 
 	if (!hpwdt_nmi_decoding)
maintainer NAK
#7 lore raw

Re: [tip:perf/core] x86, NMI: Rewrite NMI handler

Quoted 12 lines · tip-bot for Huang Ying
Commit-ID:  e21f3e4957f4a55f546873605a5caa59556bb144
Gitweb:     http://git.kernel.org/tip/e21f3e4957f4a55f546873605a5caa59556bb144
Author:     Huang Ying <[email protected]>
AuthorDate: Fri, 15 Oct 2010 22:22:16 -0400
Committer:  Ingo Molnar <[email protected]>
CommitDate: Sat, 16 Oct 2010 15:01:27 +0200

x86, NMI: Rewrite NMI handler

The original NMI handler is quite outdated in many aspects. This patch tries to fix it.

Quoted 7 lines

The order to process the NMI sources are changed as follow:

notify_die(DIE_NMI_IPI);
notify_die(DIE_NMI);
/* process io port 0x61 */
nmi_watchdog_touch();
unknown_nmi();

NACK!

I object to the DIE_NMI_IPI existance..

#8 lore raw

Re: [tip:perf/core] x86, NMI: Rewrite NMI handler

Quoted 21 lines · Peter Zijlstra
Quoted 12 lines · tip-bot for Huang Ying
Commit-ID:  e21f3e4957f4a55f546873605a5caa59556bb144
Gitweb:     http://git.kernel.org/tip/e21f3e4957f4a55f546873605a5caa59556bb144
Author:     Huang Ying <[email protected]>
AuthorDate: Fri, 15 Oct 2010 22:22:16 -0400
Committer:  Ingo Molnar <[email protected]>
CommitDate: Sat, 16 Oct 2010 15:01:27 +0200

x86, NMI: Rewrite NMI handler

The original NMI handler is quite outdated in many aspects. This patch tries to fix it.

Quoted 7 lines

The order to process the NMI sources are changed as follow:

notify_die(DIE_NMI_IPI);
notify_die(DIE_NMI);
/* process io port 0x61 */
nmi_watchdog_touch();
unknown_nmi();

Quoted 3 lines

NACK!

I object to the DIE_NMI_IPI existance..

Ok - i've zapped the commits for the time being.

Thanks,

Ingo

#9 lore raw

Re: [tip:perf/core] x86, NMI: Rewrite NMI handler

Quoted 5 lines
Quoted 3 lines

NACK!

I object to the DIE_NMI_IPI existance..

Ok - i've zapped the commits for the time being.

Hi, Peter.

If you have any ideas how things can be better, I want to see them. Some code please.

author
#10 lore raw

Re: [tip:perf/core] x86, NMI: Rewrite NMI handler

In reply to Peter Zijlstra
Quoted 21 lines · Peter Zijlstra
Quoted 12 lines · tip-bot for Huang Ying
Commit-ID:  e21f3e4957f4a55f546873605a5caa59556bb144
Gitweb:     http://git.kernel.org/tip/e21f3e4957f4a55f546873605a5caa59556bb144
Author:     Huang Ying <[email protected]>
AuthorDate: Fri, 15 Oct 2010 22:22:16 -0400
Committer:  Ingo Molnar <[email protected]>
CommitDate: Sat, 16 Oct 2010 15:01:27 +0200

x86, NMI: Rewrite NMI handler

The original NMI handler is quite outdated in many aspects. This patch tries to fix it.

Quoted 7 lines

The order to process the NMI sources are changed as follow:

notify_die(DIE_NMI_IPI);
notify_die(DIE_NMI);
/* process io port 0x61 */
nmi_watchdog_touch();
unknown_nmi();

Quoted 3 lines

NACK!

I object to the DIE_NMI_IPI existance..

Hmm, well to his defense, he isn't adding DIE_NMI_IPI. That code is already there. He is just re-arranging it, making it look painfully obvious the die_chain probably isn't as efficient as it should be.

I think a bunch of us agree that we need to revamp the NMI notifier to make it less wasteful. I was hoping we could do that in a separate patch that would be layered on top of Huangs.

Would you object to at least consider having this patch series in a work-in-progress git branch that we can build on top of, with the final outcome containing an nmi notifier that meets your expectations?

Cheers,
Don

maintainer
#11 lore raw

Re: [tip:perf/core] x86, NMI: Rewrite NMI handler

Quoted 11 lines · Don Zickus

Hmm, well to his defense, he isn't adding DIE_NMI_IPI. That code is already there. He is just re-arranging it, making it look painfully obvious the die_chain probably isn't as efficient as it should be.

I think a bunch of us agree that we need to revamp the NMI notifier to make it less wasteful. I was hoping we could do that in a separate patch that would be layered on top of Huangs.

Would you object to at least consider having this patch series in a work-in-progress git branch that we can build on top of, with the final outcome containing an nmi notifier that meets your expectations?

What's the point of keeping it in a git tree? Its just a few patches.

We've spend more time talking about this than it would take to actually do the patch that kills DIE_NMI_IPI.

#12 lore raw

Re: [tip:perf/core] x86, NMI: Rewrite NMI handler

Quoted 10 lines · Peter Zijlstra
Quoted 8 lines · Don Zickus

Hmm, well to his defense, he isn't adding DIE_NMI_IPI. That code is already there. He is just re-arranging it, making it look painfully obvious the die_chain probably isn't as efficient as it should be.

I think a bunch of us agree that we need to revamp the NMI notifier to make it less wasteful. I was hoping we could do that in a separate patch that would be layered on top of Huangs.

Quoted 8 lines
Quoted 3 lines

Would you object to at least consider having this patch series in a work-in-progress git branch that we can build on top of, with the final outcome containing an nmi notifier that meets your expectations?

What's the point of keeping it in a git tree? Its just a few patches.

We've spend more time talking about this than it would take to actually do the patch that kills DIE_NMI_IPI.

You can kill DIE_NMI_IPI. But you will add at least NMI_PRIORITY_LOCAL (like DIE_NMI_IPI), NMI_PRIORITY_GLOBAL (like original DIE_NMI). So thing is similar, just moved from one place to another place.

Best Regards,
Huang Ying

maintainer
#13 lore raw

Re: [tip:perf/core] x86, NMI: Rewrite NMI handler

Quoted 3 lines · Huang Ying

You can kill DIE_NMI_IPI. But you will add at least NMI_PRIORITY_LOCAL (like DIE_NMI_IPI), NMI_PRIORITY_GLOBAL (like original DIE_NMI). So thing is similar, just moved from one place to another place.

The nice thing is that notifier chains aren't limited to 2 priorities, in fact there's a good argument to use a wider range.

Also, like previously mentioned, it gets rid of the double iteration.

author
#14 lore raw

PATCH 4/5 x86, NMI: Allow NMI reason io port (0x61) to be processed on any CPU

In reply to Don Zickus

From: Huang Ying <[email protected]>

In original NMI handler, NMI reason io port (0x61) is only processed on BSP. This makes it impossible to hot-remove BSP. To solve the issue, a raw spinlock is used to make the port can be processed on any CPU.

---
 arch/x86/kernel/traps.c |   45 +++++++++++++++++++++++++--------------------
 1 files changed, 25 insertions(+), 20 deletions(-)
arch/x86/kernel/traps.c +25 -20
index d8acab3..accb2f4 100644
@@ -83,6 +83,12 @@ EXPORT_SYMBOL_GPL(used_vectors);
 
 static int ignore_nmis;
 
+/*
+ * Prevent NMI reason port (0x61) being accessed simultaneously, can
+ * only be used in NMI handler.
+ */
+static DEFINE_RAW_SPINLOCK(nmi_reason_lock);
+
 static inline void conditional_sti(struct pt_regs *regs)
 {
 	if (regs->flags & X86_EFLAGS_IF)
@@ -383,7 +389,6 @@ unknown_nmi_error(unsigned char reason, struct pt_regs *regs)
 static notrace __kprobes void default_do_nmi(struct pt_regs *regs)
 {
 	unsigned char reason = 0;
-	int cpu;
 
 	/*
 	 * CPU-specific NMI must be processed before non-CPU-specific
@@ -400,28 +405,28 @@ static notrace __kprobes void default_do_nmi(struct pt_regs *regs)
 		return;
 
 	/* Non-CPU-specific NMI: NMI sources can be processed on any CPU */
-	cpu = smp_processor_id();
-	/* Only the BSP gets external NMIs from the system. */
-	if (!cpu) {
-		reason = get_nmi_reason();
-		if (reason & NMI_REASON_MASK) {
-			if (notify_die(DIE_NMI, "nmi", regs, reason, 2, SIGINT)
-			    == NOTIFY_STOP)
-				return;
-			if (reason & NMI_REASON_SERR)
-				pci_serr_error(reason, regs);
-			else if (reason & NMI_REASON_IOCHK)
-				io_check_error(reason, regs);
+	raw_spin_lock(&nmi_reason_lock);
+	reason = get_nmi_reason();
+	if (reason & NMI_REASON_MASK) {
+		if (notify_die(DIE_NMI, "nmi", regs, reason, 2, SIGINT)
+		    == NOTIFY_STOP)
+			goto unlock_return;
+		if (reason & NMI_REASON_SERR)
+			pci_serr_error(reason, regs);
+		else if (reason & NMI_REASON_IOCHK)
+			io_check_error(reason, regs);
 #ifdef CONFIG_X86_32
-			/*
-			 * Reassert NMI in case it became active
-			 * meanwhile as it's edge-triggered:
-			 */
-			reassert_nmi();
+		/*
+		 * Reassert NMI in case it became active
+		 * meanwhile as it's edge-triggered:
+		 */
+		reassert_nmi();
 #endif
-			return;
-		}
+unlock_return:
+		raw_spin_unlock(&nmi_reason_lock);
+		return;
 	}
+	raw_spin_unlock(&nmi_reason_lock);
 
 	if (notify_die(DIE_NMI, "nmi", regs, 0, 2, SIGINT) == NOTIFY_STOP)
 		return;
Signature · 1 line
1.7.2.3
#15 lore raw

[tip:perf/core] x86, NMI: Allow NMI reason io port (0x61) to be processed on any CPU

Commit-ID:  4a45b5a06f61b46e7bce1aaf9331e2dc58704fa5
Gitweb:     http://git.kernel.org/tip/4a45b5a06f61b46e7bce1aaf9331e2dc58704fa5
Author:     Huang Ying <[email protected]>
AuthorDate: Fri, 15 Oct 2010 22:22:17 -0400
Committer:  Ingo Molnar <[email protected]>
CommitDate: Sat, 16 Oct 2010 15:01:28 +0200

x86, NMI: Allow NMI reason io port (0x61) to be processed on any CPU

In original NMI handler, NMI reason io port (0x61) is only processed on BSP. This makes it impossible to hot-remove BSP. To solve the issue, a raw spinlock is used to make the port can be processed on any CPU.

LKML-Reference: <[email protected]>

---
 arch/x86/kernel/traps.c |   45 +++++++++++++++++++++++++--------------------
 1 files changed, 25 insertions(+), 20 deletions(-)
arch/x86/kernel/traps.c +25 -20
index d8acab3..accb2f4 100644
@@ -83,6 +83,12 @@ EXPORT_SYMBOL_GPL(used_vectors);
 
 static int ignore_nmis;
 
+/*
+ * Prevent NMI reason port (0x61) being accessed simultaneously, can
+ * only be used in NMI handler.
+ */
+static DEFINE_RAW_SPINLOCK(nmi_reason_lock);
+
 static inline void conditional_sti(struct pt_regs *regs)
 {
 	if (regs->flags & X86_EFLAGS_IF)
@@ -383,7 +389,6 @@ unknown_nmi_error(unsigned char reason, struct pt_regs *regs)
 static notrace __kprobes void default_do_nmi(struct pt_regs *regs)
 {
 	unsigned char reason = 0;
-	int cpu;
 
 	/*
 	 * CPU-specific NMI must be processed before non-CPU-specific
@@ -400,28 +405,28 @@ static notrace __kprobes void default_do_nmi(struct pt_regs *regs)
 		return;
 
 	/* Non-CPU-specific NMI: NMI sources can be processed on any CPU */
-	cpu = smp_processor_id();
-	/* Only the BSP gets external NMIs from the system. */
-	if (!cpu) {
-		reason = get_nmi_reason();
-		if (reason & NMI_REASON_MASK) {
-			if (notify_die(DIE_NMI, "nmi", regs, reason, 2, SIGINT)
-			    == NOTIFY_STOP)
-				return;
-			if (reason & NMI_REASON_SERR)
-				pci_serr_error(reason, regs);
-			else if (reason & NMI_REASON_IOCHK)
-				io_check_error(reason, regs);
+	raw_spin_lock(&nmi_reason_lock);
+	reason = get_nmi_reason();
+	if (reason & NMI_REASON_MASK) {
+		if (notify_die(DIE_NMI, "nmi", regs, reason, 2, SIGINT)
+		    == NOTIFY_STOP)
+			goto unlock_return;
+		if (reason & NMI_REASON_SERR)
+			pci_serr_error(reason, regs);
+		else if (reason & NMI_REASON_IOCHK)
+			io_check_error(reason, regs);
 #ifdef CONFIG_X86_32
-			/*
-			 * Reassert NMI in case it became active
-			 * meanwhile as it's edge-triggered:
-			 */
-			reassert_nmi();
+		/*
+		 * Reassert NMI in case it became active
+		 * meanwhile as it's edge-triggered:
+		 */
+		reassert_nmi();
 #endif
-			return;
-		}
+unlock_return:
+		raw_spin_unlock(&nmi_reason_lock);
+		return;
 	}
+	raw_spin_unlock(&nmi_reason_lock);
 
 	if (notify_die(DIE_NMI, "nmi", regs, 0, 2, SIGINT) == NOTIFY_STOP)
 		return;
#16 lore raw

Re: [PATCH 4/5] x86, NMI: Allow NMI reason io port (0x61) to be processed on any CPU

In reply to Don Zickus
Quoted 45 lines · Don Zickus

From: Huang Ying <[email protected]>

In original NMI handler, NMI reason io port (0x61) is only processed on BSP. This makes it impossible to hot-remove BSP. To solve the issue, a raw spinlock is used to make the port can be processed on any CPU.

---
 arch/x86/kernel/traps.c |   45 +++++++++++++++++++++++++--------------------
 1 files changed, 25 insertions(+), 20 deletions(-)
arch/x86/kernel/traps.c +6 -4
index d8acab3..accb2f4 100644
@@ -83,6 +83,12 @@ EXPORT_SYMBOL_GPL(used_vectors);
 
 static int ignore_nmis;
 
+/*
+ * Prevent NMI reason port (0x61) being accessed simultaneously, can
+ * only be used in NMI handler.
+ */
+static DEFINE_RAW_SPINLOCK(nmi_reason_lock);
+
 static inline void conditional_sti(struct pt_regs *regs)
 {
 	if (regs->flags & X86_EFLAGS_IF)
@@ -383,7 +389,6 @@ unknown_nmi_error(unsigned char reason, struct pt_regs *regs)
 static notrace __kprobes void default_do_nmi(struct pt_regs *regs)
 {
 	unsigned char reason = 0;
-	int cpu;
 
 	/*
 	 * CPU-specific NMI must be processed before non-CPU-specific
@@ -400,28 +405,28 @@ static notrace __kprobes void default_do_nmi(struct pt_regs *regs)
 		return;
 
 	/* Non-CPU-specific NMI: NMI sources can be processed on any CPU */
-	cpu = smp_processor_id();
-	/* Only the BSP gets external NMIs from the system. */
-	if (!cpu) {

arch/x86/kernel/traps.c static notrace __kprobes void default_do_nmi(struct pt_regs *regs) · line 408

Quoted 10 lines
arch/x86/kernel/traps.c +1 -9
-		reason = get_nmi_reason();
-		if (reason & NMI_REASON_MASK) {
-			if (notify_die(DIE_NMI, "nmi", regs, reason, 2, SIGINT)
-			    == NOTIFY_STOP)
-				return;
-			if (reason & NMI_REASON_SERR)
-				pci_serr_error(reason, regs);
-			else if (reason & NMI_REASON_IOCHK)
-				io_check_error(reason, regs);
+	raw_spin_lock(&nmi_reason_lock);

What about using raw_spin_trylock() instead? We don't have to wait here since we are already processing it by another cpu.

-Robert

Quoted 35 lines
arch/x86/kernel/traps.c +18 -7
+	reason = get_nmi_reason();
+	if (reason & NMI_REASON_MASK) {
+		if (notify_die(DIE_NMI, "nmi", regs, reason, 2, SIGINT)
+		    == NOTIFY_STOP)
+			goto unlock_return;
+		if (reason & NMI_REASON_SERR)
+			pci_serr_error(reason, regs);
+		else if (reason & NMI_REASON_IOCHK)
+			io_check_error(reason, regs);
 #ifdef CONFIG_X86_32
-			/*
-			 * Reassert NMI in case it became active
-			 * meanwhile as it's edge-triggered:
-			 */
-			reassert_nmi();
+		/*
+		 * Reassert NMI in case it became active
+		 * meanwhile as it's edge-triggered:
+		 */
+		reassert_nmi();
 #endif
-			return;
-		}
+unlock_return:
+		raw_spin_unlock(&nmi_reason_lock);
+		return;
 	}
+	raw_spin_unlock(&nmi_reason_lock);
 
 	if (notify_die(DIE_NMI, "nmi", regs, 0, 2, SIGINT) == NOTIFY_STOP)
 		return;
Signature · 1 line
1.7.2.3
Signature · 2 lines
Advanced Micro Devices, Inc.
Operating System Research Center
#17 lore raw

Re: [PATCH 4/5] x86, NMI: Allow NMI reason io port (0x61) to be processed on any CPU

Quoted 26 lines · Robert Richter
Quoted 25 lines · Don Zickus

From: Huang Ying <[email protected]>

In original NMI handler, NMI reason io port (0x61) is only processed on BSP. This makes it impossible to hot-remove BSP. To solve the issue, a raw spinlock is used to make the port can be processed on any CPU.

---
 arch/x86/kernel/traps.c |   45 +++++++++++++++++++++++++--------------------
 1 files changed, 25 insertions(+), 20 deletions(-)
arch/x86/kernel/traps.c +0 -8
@@ -400,28 +405,28 @@ static notrace __kprobes void default_do_nmi(struct pt_regs *regs)
 		return;
 
 	/* Non-CPU-specific NMI: NMI sources can be processed on any CPU */
-	cpu = smp_processor_id();
-	/* Only the BSP gets external NMIs from the system. */
-	if (!cpu) {
-		reason = get_nmi_reason();
-		if (reason & NMI_REASON_MASK) {
-			if (notify_die(DIE_NMI, "nmi", regs, reason, 2, SIGINT)
-			    == NOTIFY_STOP)
-				return;
Quoted 8 lines

arch/x86/kernel/traps.c static notrace __kprobes void default_do_nmi(struct pt_regs *regs) · line 408

Quoted 5 lines
arch/x86/kernel/traps.c +1 -4
-			if (reason & NMI_REASON_SERR)
-				pci_serr_error(reason, regs);
-			else if (reason & NMI_REASON_IOCHK)
-				io_check_error(reason, regs);
+	raw_spin_lock(&nmi_reason_lock);

What about using raw_spin_trylock() instead? We don't have to wait here since we are already processing it by another cpu.

This would avoid a global lock and also deadlocking in case of a potential #gp in the nmi handler.

-Robert

Signature · 2 lines
Advanced Micro Devices, Inc.
Operating System Research Center
author
#18 lore raw

Re: [PATCH 4/5] x86, NMI: Allow NMI reason io port (0x61) to be processed on any CPU

Quoted 36 lines · Robert Richter
Quoted 26 lines · Robert Richter
Quoted 25 lines · Don Zickus

From: Huang Ying <[email protected]>

In original NMI handler, NMI reason io port (0x61) is only processed on BSP. This makes it impossible to hot-remove BSP. To solve the issue, a raw spinlock is used to make the port can be processed on any CPU.

---
 arch/x86/kernel/traps.c |   45 +++++++++++++++++++++++++--------------------
 1 files changed, 25 insertions(+), 20 deletions(-)
arch/x86/kernel/traps.c +0 -8
@@ -400,28 +405,28 @@ static notrace __kprobes void default_do_nmi(struct pt_regs *regs)
 		return;
 
 	/* Non-CPU-specific NMI: NMI sources can be processed on any CPU */
-	cpu = smp_processor_id();
-	/* Only the BSP gets external NMIs from the system. */
-	if (!cpu) {
-		reason = get_nmi_reason();
-		if (reason & NMI_REASON_MASK) {
-			if (notify_die(DIE_NMI, "nmi", regs, reason, 2, SIGINT)
-			    == NOTIFY_STOP)
-				return;
Quoted 8 lines

arch/x86/kernel/traps.c static notrace __kprobes void default_do_nmi(struct pt_regs *regs) · line 408

Quoted 5 lines
arch/x86/kernel/traps.c +1 -4
-			if (reason & NMI_REASON_SERR)
-				pci_serr_error(reason, regs);
-			else if (reason & NMI_REASON_IOCHK)
-				io_check_error(reason, regs);
+	raw_spin_lock(&nmi_reason_lock);

What about using raw_spin_trylock() instead? We don't have to wait here since we are already processing it by another cpu.

Quoted 2 lines

This would avoid a global lock and also deadlocking in case of a potential #gp in the nmi handler.

I would feel more comfortable with it too. I can't find a reason where trylock would do harm.

Cheers,
Don

#19 lore raw

Re: [PATCH 4/5] x86, NMI: Allow NMI reason io port (0x61) to be processed on any CPU

Quoted 37 lines · Don Zickus
Quoted 36 lines · Robert Richter
Quoted 34 lines · Robert Richter
Quoted 20 lines · Don Zickus

From: Huang Ying <[email protected]>

In original NMI handler, NMI reason io port (0x61) is only processed on BSP. This makes it impossible to hot-remove BSP. To solve the issue, a raw spinlock is used to make the port can be processed on any CPU.

---
 arch/x86/kernel/traps.c |   45 +++++++++++++++++++++++++--------------------
 1 files changed, 25 insertions(+), 20 deletions(-)
arch/x86/kernel/traps.c +0 -3
@@ -400,28 +405,28 @@ static notrace __kprobes void default_do_nmi(struct pt_regs *regs)
 		return;
 
 	/* Non-CPU-specific NMI: NMI sources can be processed on any CPU */
-	cpu = smp_processor_id();
-	/* Only the BSP gets external NMIs from the system. */
-	if (!cpu) {

arch/x86/kernel/traps.c static notrace __kprobes void default_do_nmi(struct pt_regs *regs) · line 408

Quoted 10 lines
arch/x86/kernel/traps.c +1 -9
-		reason = get_nmi_reason();
-		if (reason & NMI_REASON_MASK) {
-			if (notify_die(DIE_NMI, "nmi", regs, reason, 2, SIGINT)
-			    == NOTIFY_STOP)
-				return;
-			if (reason & NMI_REASON_SERR)
-				pci_serr_error(reason, regs);
-			else if (reason & NMI_REASON_IOCHK)
-				io_check_error(reason, regs);
+	raw_spin_lock(&nmi_reason_lock);

What about using raw_spin_trylock() instead? We don't have to wait here since we are already processing it by another cpu.

Quoted 5 lines
Quoted 2 lines

This would avoid a global lock and also deadlocking in case of a potential #gp in the nmi handler.

I would feel more comfortable with it too. I can't find a reason where trylock would do harm.

One possible issue can be as follow:

- PCI SERR NMI raised on CPU 0
- IOCHK NMI raised on CPU 1

If we use try lock, we may get unknown NMI on one CPU. Do you guys think so?

Best Regards,
Huang Ying

#20 lore raw

Re: [PATCH 4/5] x86, NMI: Allow NMI reason io port (0x61) to be processed on any CPU

Quoted 44 lines · Huang Ying
Quoted 37 lines · Don Zickus
Quoted 36 lines · Robert Richter
Quoted 34 lines · Robert Richter
Quoted 20 lines · Don Zickus

From: Huang Ying <[email protected]>

In original NMI handler, NMI reason io port (0x61) is only processed on BSP. This makes it impossible to hot-remove BSP. To solve the issue, a raw spinlock is used to make the port can be processed on any CPU.

---
 arch/x86/kernel/traps.c |   45 +++++++++++++++++++++++++--------------------
 1 files changed, 25 insertions(+), 20 deletions(-)
arch/x86/kernel/traps.c +0 -3
@@ -400,28 +405,28 @@ static notrace __kprobes void default_do_nmi(struct pt_regs *regs)
 		return;
 
 	/* Non-CPU-specific NMI: NMI sources can be processed on any CPU */
-	cpu = smp_processor_id();
-	/* Only the BSP gets external NMIs from the system. */
-	if (!cpu) {

arch/x86/kernel/traps.c static notrace __kprobes void default_do_nmi(struct pt_regs *regs) · line 408

Quoted 10 lines
arch/x86/kernel/traps.c +1 -9
-		reason = get_nmi_reason();
-		if (reason & NMI_REASON_MASK) {
-			if (notify_die(DIE_NMI, "nmi", regs, reason, 2, SIGINT)
-			    == NOTIFY_STOP)
-				return;
-			if (reason & NMI_REASON_SERR)
-				pci_serr_error(reason, regs);
-			else if (reason & NMI_REASON_IOCHK)
-				io_check_error(reason, regs);
+	raw_spin_lock(&nmi_reason_lock);

What about using raw_spin_trylock() instead? We don't have to wait here since we are already processing it by another cpu.

Quoted 5 lines
Quoted 2 lines

This would avoid a global lock and also deadlocking in case of a potential #gp in the nmi handler.

I would feel more comfortable with it too. I can't find a reason where trylock would do harm.

Quoted 7 lines

One possible issue can be as follow:

- PCI SERR NMI raised on CPU 0
- IOCHK NMI raised on CPU 1

If we use try lock, we may get unknown NMI on one CPU. Do you guys think so?

This could be a valid point. On the other side the former implementation to let only handle cpu #0 i/o interrupts didn't trigger unknown nmis, so try_lock wouldn't change much compared to this. To be sure we might do a NOTIFY_STOP in the unknown path if we don't get the lock.

-Robert

Signature · 2 lines
Advanced Micro Devices, Inc.
Operating System Research Center
#21 lore raw

Re: [PATCH 4/5] x86, NMI: Allow NMI reason io port (0x61) to be processed on any CPU

Quoted 14 lines · Robert Richter
Quoted 14 lines
Quoted 8 lines
Quoted 5 lines
Quoted 2 lines

What about using raw_spin_trylock() instead? We don't have to wait here since we are already processing it by another cpu.

This would avoid a global lock and also deadlocking in case of a potential #gp in the nmi handler.

I would feel more comfortable with it too. I can't find a reason where trylock would do harm.

One possible issue can be as follow:

- PCI SERR NMI raised on CPU 0
- IOCHK NMI raised on CPU 1

Quoted 6 lines
Quoted 2 lines

If we use try lock, we may get unknown NMI on one CPU. Do you guys think so?

This could be a valid point. On the other side the former implementation to let only handle cpu #0 i/o interrupts didn't trigger unknown nmis, so try_lock wouldn't change much compared to this.

Because we want to support BSP hot-remove, these NMIs may be redirected to other CPUs. I think it may be possible after we hot-remove the BSP PCI SERR NMI is routed to CPU 1, while IOCHK NMI is routed to CPU 2. The raw_spin_lock() here is for that.

Best Regards,
Huang Ying

author
#22 lore raw

Re: [PATCH 4/5] x86, NMI: Allow NMI reason io port (0x61) to be processed on any CPU

In reply to Huang Ying
Quoted 9 lines · Huang Ying
Quoted 8 lines
Quoted 5 lines
Quoted 2 lines

What about using raw_spin_trylock() instead? We don't have to wait here since we are already processing it by another cpu.

This would avoid a global lock and also deadlocking in case of a potential #gp in the nmi handler.

I would feel more comfortable with it too. I can't find a reason where trylock would do harm.

Quoted 7 lines

One possible issue can be as follow:

- PCI SERR NMI raised on CPU 0
- IOCHK NMI raised on CPU 1

If we use try lock, we may get unknown NMI on one CPU. Do you guys think so?

I thought both PCI SERR and IOCK NMI's were external and routed through the IOAPIC, which means only one cpu could receive those (unless the IOAPIC was updated to route them elsewhere). This would make the issue moot. Unless I am misunderstanding where those NMIs come from?

Also as Robert said, we used to handle them on the bsp cpu only before without any issues. I believed that was because everything in the IOAPIC was routed that way.

I thought the point of this patch was to remove that restriction in the nmi handler, which would allow future patches to re-route these NMIs to another cpu, thus finally allowing people to hot-remove the bsp cpu, no?

Cheers,
Don

#23 lore raw

Re: [PATCH 4/5] x86, NMI: Allow NMI reason io port (0x61) to be processed on any CPU

Quoted 23 lines · Don Zickus
Quoted 9 lines · Huang Ying
Quoted 8 lines
Quoted 5 lines
Quoted 2 lines

What about using raw_spin_trylock() instead? We don't have to wait here since we are already processing it by another cpu.

This would avoid a global lock and also deadlocking in case of a potential #gp in the nmi handler.

I would feel more comfortable with it too. I can't find a reason where trylock would do harm.

Quoted 7 lines

One possible issue can be as follow:

- PCI SERR NMI raised on CPU 0
- IOCHK NMI raised on CPU 1

If we use try lock, we may get unknown NMI on one CPU. Do you guys think so?

I thought both PCI SERR and IOCK NMI's were external and routed through the IOAPIC, which means only one cpu could receive those (unless the IOAPIC was updated to route them elsewhere). This would make the issue moot. Unless I am misunderstanding where those NMIs come from?

Quoted 7 lines

Also as Robert said, we used to handle them on the bsp cpu only before without any issues. I believed that was because everything in the IOAPIC was routed that way.

I thought the point of this patch was to remove that restriction in the nmi handler, which would allow future patches to re-route these NMIs to another cpu, thus finally allowing people to hot-remove the bsp cpu, no?

Yes. We just want to make it possible to hot-remove the bsp cpu. Because IOAPIC is configurable, I think it is possible to configure IOAPIC to send PCI SERR NMI to one CPU while IOCK NMI to another CPU. Why not support this situation too? It does not harm anything but performance to use raw_spin_lock() instead of raw_spin_trylock() here. And for hardware error processing, performance is not so important in fact.

Best Regards,
Huang Ying

author
#24 lore raw

Re: [PATCH 4/5] x86, NMI: Allow NMI reason io port (0x61) to be processed on any CPU

Quoted 9 lines · Huang Ying
Quoted 3 lines · Don Zickus

I thought the point of this patch was to remove that restriction in the nmi handler, which would allow future patches to re-route these NMIs to another cpu, thus finally allowing people to hot-remove the bsp cpu, no?

Yes. We just want to make it possible to hot-remove the bsp cpu. Because IOAPIC is configurable, I think it is possible to configure IOAPIC to send PCI SERR NMI to one CPU while IOCK NMI to another CPU. Why not support this situation too? It does not harm anything but performance to

Why would we want to? It seems simpler to have one cpu dedicated to handling the external NMIs.

Quoted 2 lines

use raw_spin_lock() instead of raw_spin_trylock() here. And for hardware error processing, performance is not so important in fact.

I don't know. I was always a little uncomfortable with a spin_lock there, so I am more supportive of a trylock.

Cheers,
Don

#25 lore raw

Re: [PATCH 4/5] x86, NMI: Allow NMI reason io port (0x61) to be processed on any CPU

Quoted 6 lines · Don Zickus
Quoted 5 lines · Huang Ying
Quoted 3 lines · Don Zickus

I thought the point of this patch was to remove that restriction in the nmi handler, which would allow future patches to re-route these NMIs to another cpu, thus finally allowing people to hot-remove the bsp cpu, no?

Quoted 7 lines
Quoted 4 lines

Yes. We just want to make it possible to hot-remove the bsp cpu. Because IOAPIC is configurable, I think it is possible to configure IOAPIC to send PCI SERR NMI to one CPU while IOCK NMI to another CPU. Why not support this situation too? It does not harm anything but performance to

Why would we want to? It seems simpler to have one cpu dedicated to handling the external NMIs.

If we can guarantee that these NMIs will be only sent to one CPU, I am fine with trylock.

Quoted 5 lines
Quoted 2 lines

use raw_spin_lock() instead of raw_spin_trylock() here. And for hardware error processing, performance is not so important in fact.

I don't know. I was always a little uncomfortable with a spin_lock there, so I am more supportive of a trylock.

Best Regards,
Huang Ying

author
#26 lore raw

Re: [PATCH 4/5] x86, NMI: Allow NMI reason io port (0x61) to be processed on any CPU

Quoted 12 lines · Huang Ying
Quoted 11 lines · Don Zickus
Quoted 9 lines · Huang Ying
Quoted 3 lines · Don Zickus

I thought the point of this patch was to remove that restriction in the nmi handler, which would allow future patches to re-route these NMIs to another cpu, thus finally allowing people to hot-remove the bsp cpu, no?

Yes. We just want to make it possible to hot-remove the bsp cpu. Because IOAPIC is configurable, I think it is possible to configure IOAPIC to send PCI SERR NMI to one CPU while IOCK NMI to another CPU. Why not support this situation too? It does not harm anything but performance to

Quoted 5 lines
Quoted 2 lines

Why would we want to? It seems simpler to have one cpu dedicated to handling the external NMIs.

If we can guarantee that these NMIs will be only sent to one CPU, I am fine with trylock.

I guess I assumed the BIOS would only use the bsp CPU for the NMI, which would be passed on to the kernel. Otherwise what happens if an NMI happens while the kernel is still bringing up the first cpu and it is routed to another CPU or if we boot with MAX_CPUS=1?

Then again people keep saying BIOS writers are crazy, so my assumption could be completely wrong. ;-p

Cheers,
Don

#27 lore raw

Re: [PATCH 4/5] x86, NMI: Allow NMI reason io port (0x61) to be processed on any CPU

Quoted 16 lines · Don Zickus
Quoted 15 lines · Huang Ying
Quoted 13 lines · Don Zickus
Quoted 9 lines · Huang Ying
Quoted 3 lines · Don Zickus

I thought the point of this patch was to remove that restriction in the nmi handler, which would allow future patches to re-route these NMIs to another cpu, thus finally allowing people to hot-remove the bsp cpu, no?

Yes. We just want to make it possible to hot-remove the bsp cpu. Because IOAPIC is configurable, I think it is possible to configure IOAPIC to send PCI SERR NMI to one CPU while IOCK NMI to another CPU. Why not support this situation too? It does not harm anything but performance to

Why would we want to? It seems simpler to have one cpu dedicated to handling the external NMIs.

Quoted 7 lines
Quoted 2 lines

If we can guarantee that these NMIs will be only sent to one CPU, I am fine with trylock.

I guess I assumed the BIOS would only use the bsp CPU for the NMI, which would be passed on to the kernel. Otherwise what happens if an NMI happens while the kernel is still bringing up the first cpu and it is routed to another CPU or if we boot with MAX_CPUS=1?

After CPU hot-remove (should go through BIOS), BIOS may route the NMI to other CPU I think. That should have no above issues. The question here is that, BIOS will route different NMIs to one CPU or several CPUs?

Best Regards,
Huang Ying

author
#28 lore raw

PATCH 5/5 x86, NMI: Remove do_nmi_callback logic

In reply to Don Zickus

From: Huang Ying <[email protected]>

do_nmi_callback related logic is removed, because it is useless, just adds code complexity.

unknown_nmi_panic sysctl is reserved to keep kernel ABI unchanged.

---
 arch/x86/include/asm/nmi.h    |   10 +++++++++-
 arch/x86/kernel/apic/hw_nmi.c |    1 -
 arch/x86/kernel/apic/nmi.c    |   29 +----------------------------
 arch/x86/kernel/traps.c       |   17 +++++++++++------
 4 files changed, 21 insertions(+), 36 deletions(-)
arch/x86/include/asm/nmi.h +9 -1
index 932f0f8..d5a5793 100644
@@ -30,9 +30,17 @@ extern void setup_apic_nmi_watchdog(void *);
 extern void stop_apic_nmi_watchdog(void *);
 extern void disable_timer_nmi_watchdog(void);
 extern void enable_timer_nmi_watchdog(void);
-extern int nmi_watchdog_tick(struct pt_regs *regs, unsigned reason);
 extern void cpu_nmi_set_wd_enabled(void);
 
+#if defined(CONFIG_X86_LOCAL_APIC) && !defined(CONFIG_LOCKUP_DETECTOR)
+extern int nmi_watchdog_tick(struct pt_regs *regs);
+#else
+static inline int nmi_watchdog_tick(struct pt_regs *regs)
+{
+	return 0;
+}
+#endif
+
 extern atomic_t nmi_active;
 extern unsigned int nmi_watchdog;
 #define NMI_NONE	0
arch/x86/kernel/apic/hw_nmi.c +0 -1
index cefd694..e66b16d 100644
@@ -100,7 +100,6 @@ void acpi_nmi_disable(void) { return; }
 #endif
 atomic_t nmi_active = ATOMIC_INIT(0);           /* oprofile uses this */
 EXPORT_SYMBOL(nmi_active);
-int unknown_nmi_panic;
 void cpu_nmi_set_wd_enabled(void) { return; }
 void stop_apic_nmi_watchdog(void *unused) { return; }
 void setup_apic_nmi_watchdog(void *unused) { return; }
arch/x86/kernel/apic/nmi.c +1 -28
index a43f71c..f407b6b 100644
@@ -37,7 +37,6 @@
 
 #include <asm/mach_traps.h>
 
-int unknown_nmi_panic;
 int nmi_watchdog_enabled;
 
 /* For reliability, we're prepared to waste bits here. */
@@ -389,7 +388,7 @@ void touch_nmi_watchdog(void)
 EXPORT_SYMBOL(touch_nmi_watchdog);
 
 notrace __kprobes int
-nmi_watchdog_tick(struct pt_regs *regs, unsigned reason)
+nmi_watchdog_tick(struct pt_regs *regs)
 {
 	/*
 	 * Since current_thread_info()-> is always on the stack, and we
@@ -483,23 +482,6 @@ static void disable_ioapic_nmi_watchdog(void)
 	on_each_cpu(stop_apic_nmi_watchdog, NULL, 1);
 }
 
-static int __init setup_unknown_nmi_panic(char *str)
-{
-	unknown_nmi_panic = 1;
-	return 1;
-}
-__setup("unknown_nmi_panic", setup_unknown_nmi_panic);
-
-static int unknown_nmi_panic_callback(struct pt_regs *regs, int cpu)
-{
-	unsigned char reason = get_nmi_reason();
-	char buf[64];
-
-	sprintf(buf, "NMI received for unknown reason %02x\n", reason);
-	die_nmi(buf, regs, 1); /* Always panic here */
-	return 0;
-}
-
 /*
  * proc handler for /proc/sys/kernel/nmi
  */
@@ -540,15 +522,6 @@ int proc_nmi_enabled(struct ctl_table *table, int write,
 
 #endif /* CONFIG_SYSCTL */
 
-int do_nmi_callback(struct pt_regs *regs, int cpu)
-{
-#ifdef CONFIG_SYSCTL
-	if (unknown_nmi_panic)
-		return unknown_nmi_panic_callback(regs, cpu);
-#endif
-	return 0;
-}
-
 void arch_trigger_all_cpu_backtrace(void)
 {
 	int i;
arch/x86/kernel/traps.c +11 -6
index accb2f4..9ef8e15 100644
@@ -83,6 +83,8 @@ EXPORT_SYMBOL_GPL(used_vectors);
 
 static int ignore_nmis;
 
+int unknown_nmi_panic;
+
 /*
  * Prevent NMI reason port (0x61) being accessed simultaneously, can
  * only be used in NMI handler.
@@ -306,6 +308,13 @@ gp_in_kernel:
 	die("general protection fault", regs, error_code);
 }
 
+static int __init setup_unknown_nmi_panic(char *str)
+{
+	unknown_nmi_panic = 1;
+	return 1;
+}
+__setup("unknown_nmi_panic", setup_unknown_nmi_panic);
+
 static notrace __kprobes void
 pci_serr_error(unsigned char reason, struct pt_regs *regs)
 {
@@ -380,7 +389,7 @@ unknown_nmi_error(unsigned char reason, struct pt_regs *regs)
 		 reason, smp_processor_id());
 
 	pr_emerg("Do you have a strange power saving mode enabled?\n");
-	if (panic_on_unrecovered_nmi)
+	if (unknown_nmi_panic || panic_on_unrecovered_nmi)
 		panic("NMI: Not continuing");
 
 	pr_emerg("Dazed and confused, but trying to continue\n");
@@ -431,12 +440,8 @@ unlock_return:
 	if (notify_die(DIE_NMI, "nmi", regs, 0, 2, SIGINT) == NOTIFY_STOP)
 		return;
 
-#if defined(CONFIG_X86_LOCAL_APIC) && !defined(CONFIG_LOCKUP_DETECTOR)
-	if (nmi_watchdog_tick(regs, reason))
-		return;
-	if (do_nmi_callback(regs, cpu))
+	if (nmi_watchdog_tick(regs))
 		return;
-#endif
 
 	unknown_nmi_error(reason, regs);
 }
Signature · 1 line
1.7.2.3
#29 lore raw

[tip:perf/core] x86, NMI: Remove do_nmi_callback logic

Commit-ID:  c218868fcc8f80c34bead7e887003b79faa89c48
Gitweb:     http://git.kernel.org/tip/c218868fcc8f80c34bead7e887003b79faa89c48
Author:     Huang Ying <[email protected]>
AuthorDate: Fri, 15 Oct 2010 22:22:18 -0400
Committer:  Ingo Molnar <[email protected]>
CommitDate: Sat, 16 Oct 2010 15:01:28 +0200

x86, NMI: Remove do_nmi_callback logic

do_nmi_callback related logic is removed, because it is useless, just adds code complexity.

unknown_nmi_panic sysctl is reserved to keep kernel ABI unchanged.

LKML-Reference: <[email protected]>

---
 arch/x86/include/asm/nmi.h    |   10 +++++++++-
 arch/x86/kernel/apic/hw_nmi.c |    1 -
 arch/x86/kernel/apic/nmi.c    |   29 +----------------------------
 arch/x86/kernel/traps.c       |   17 +++++++++++------
 4 files changed, 21 insertions(+), 36 deletions(-)
arch/x86/include/asm/nmi.h +9 -1
index 932f0f8..d5a5793 100644
@@ -30,9 +30,17 @@ extern void setup_apic_nmi_watchdog(void *);
 extern void stop_apic_nmi_watchdog(void *);
 extern void disable_timer_nmi_watchdog(void);
 extern void enable_timer_nmi_watchdog(void);
-extern int nmi_watchdog_tick(struct pt_regs *regs, unsigned reason);
 extern void cpu_nmi_set_wd_enabled(void);
 
+#if defined(CONFIG_X86_LOCAL_APIC) && !defined(CONFIG_LOCKUP_DETECTOR)
+extern int nmi_watchdog_tick(struct pt_regs *regs);
+#else
+static inline int nmi_watchdog_tick(struct pt_regs *regs)
+{
+	return 0;
+}
+#endif
+
 extern atomic_t nmi_active;
 extern unsigned int nmi_watchdog;
 #define NMI_NONE	0
arch/x86/kernel/apic/hw_nmi.c +0 -1
index cefd694..e66b16d 100644
@@ -100,7 +100,6 @@ void acpi_nmi_disable(void) { return; }
 #endif
 atomic_t nmi_active = ATOMIC_INIT(0);           /* oprofile uses this */
 EXPORT_SYMBOL(nmi_active);
-int unknown_nmi_panic;
 void cpu_nmi_set_wd_enabled(void) { return; }
 void stop_apic_nmi_watchdog(void *unused) { return; }
 void setup_apic_nmi_watchdog(void *unused) { return; }
arch/x86/kernel/apic/nmi.c +1 -28
index a43f71c..f407b6b 100644
@@ -37,7 +37,6 @@
 
 #include <asm/mach_traps.h>
 
-int unknown_nmi_panic;
 int nmi_watchdog_enabled;
 
 /* For reliability, we're prepared to waste bits here. */
@@ -389,7 +388,7 @@ void touch_nmi_watchdog(void)
 EXPORT_SYMBOL(touch_nmi_watchdog);
 
 notrace __kprobes int
-nmi_watchdog_tick(struct pt_regs *regs, unsigned reason)
+nmi_watchdog_tick(struct pt_regs *regs)
 {
 	/*
 	 * Since current_thread_info()-> is always on the stack, and we
@@ -483,23 +482,6 @@ static void disable_ioapic_nmi_watchdog(void)
 	on_each_cpu(stop_apic_nmi_watchdog, NULL, 1);
 }
 
-static int __init setup_unknown_nmi_panic(char *str)
-{
-	unknown_nmi_panic = 1;
-	return 1;
-}
-__setup("unknown_nmi_panic", setup_unknown_nmi_panic);
-
-static int unknown_nmi_panic_callback(struct pt_regs *regs, int cpu)
-{
-	unsigned char reason = get_nmi_reason();
-	char buf[64];
-
-	sprintf(buf, "NMI received for unknown reason %02x\n", reason);
-	die_nmi(buf, regs, 1); /* Always panic here */
-	return 0;
-}
-
 /*
  * proc handler for /proc/sys/kernel/nmi
  */
@@ -540,15 +522,6 @@ int proc_nmi_enabled(struct ctl_table *table, int write,
 
 #endif /* CONFIG_SYSCTL */
 
-int do_nmi_callback(struct pt_regs *regs, int cpu)
-{
-#ifdef CONFIG_SYSCTL
-	if (unknown_nmi_panic)
-		return unknown_nmi_panic_callback(regs, cpu);
-#endif
-	return 0;
-}
-
 void arch_trigger_all_cpu_backtrace(void)
 {
 	int i;
arch/x86/kernel/traps.c +11 -6
index accb2f4..9ef8e15 100644
@@ -83,6 +83,8 @@ EXPORT_SYMBOL_GPL(used_vectors);
 
 static int ignore_nmis;
 
+int unknown_nmi_panic;
+
 /*
  * Prevent NMI reason port (0x61) being accessed simultaneously, can
  * only be used in NMI handler.
@@ -306,6 +308,13 @@ gp_in_kernel:
 	die("general protection fault", regs, error_code);
 }
 
+static int __init setup_unknown_nmi_panic(char *str)
+{
+	unknown_nmi_panic = 1;
+	return 1;
+}
+__setup("unknown_nmi_panic", setup_unknown_nmi_panic);
+
 static notrace __kprobes void
 pci_serr_error(unsigned char reason, struct pt_regs *regs)
 {
@@ -380,7 +389,7 @@ unknown_nmi_error(unsigned char reason, struct pt_regs *regs)
 		 reason, smp_processor_id());
 
 	pr_emerg("Do you have a strange power saving mode enabled?\n");
-	if (panic_on_unrecovered_nmi)
+	if (unknown_nmi_panic || panic_on_unrecovered_nmi)
 		panic("NMI: Not continuing");
 
 	pr_emerg("Dazed and confused, but trying to continue\n");
@@ -431,12 +440,8 @@ unlock_return:
 	if (notify_die(DIE_NMI, "nmi", regs, 0, 2, SIGINT) == NOTIFY_STOP)
 		return;
 
-#if defined(CONFIG_X86_LOCAL_APIC) && !defined(CONFIG_LOCKUP_DETECTOR)
-	if (nmi_watchdog_tick(regs, reason))
-		return;
-	if (do_nmi_callback(regs, cpu))
+	if (nmi_watchdog_tick(regs))
 		return;
-#endif
 
 	unknown_nmi_error(reason, regs);
 }
#30 lore raw

Re: [PATCH 5/5] x86, NMI: Remove do_nmi_callback logic

In reply to Don Zickus
Quoted 21 lines · Don Zickus

From: Huang Ying <[email protected]>

do_nmi_callback related logic is removed, because it is useless, just adds code complexity.

unknown_nmi_panic sysctl is reserved to keep kernel ABI unchanged.

---
 arch/x86/include/asm/nmi.h    |   10 +++++++++-
 arch/x86/kernel/apic/hw_nmi.c |    1 -
 arch/x86/kernel/apic/nmi.c    |   29 +----------------------------
 arch/x86/kernel/traps.c       |   17 +++++++++++------
 4 files changed, 21 insertions(+), 36 deletions(-)
arch/x86/kernel/traps.c +0 -0
index accb2f4..9ef8e15 100644

arch/x86/kernel/traps.c EXPORT_SYMBOL_GPL(used_vectors); · line 86

Quoted 4 lines
arch/x86/kernel/traps.c +1 -0
@@ -83,6 +83,8 @@ EXPORT_SYMBOL_GPL(used_vectors);
 
 static int ignore_nmis;
 
+int unknown_nmi_panic;

I didn't apply the patches, so I am not really sure, but I think this could be static now.

-Robert

Signature · 2 lines
Advanced Micro Devices, Inc.
Operating System Research Center
author
#31 lore raw

Re: [PATCH 5/5] x86, NMI: Remove do_nmi_callback logic

Quoted 9 lines · Robert Richter

arch/x86/kernel/traps.c EXPORT_SYMBOL_GPL(used_vectors); · line 86

Quoted 6 lines

+++ b/arch/x86/kernel/traps.c

arch/x86/kernel/traps.c +1 -0
@@ -83,6 +83,8 @@ EXPORT_SYMBOL_GPL(used_vectors);
 
 static int ignore_nmis;
 
+int unknown_nmi_panic;

I didn't apply the patches, so I am not really sure, but I think this could be static now.

It is used in kernel/sysctl.c so I don't think it can.

Cheers,
Don

#32 lore raw

Re: [PATCH 5/5] x86, NMI: Remove do_nmi_callback logic

Quoted 4 lines · Don Zickus
Quoted 3 lines · Robert Richter
Quoted 3 lines

+++ b/arch/x86/kernel/traps.c

(quoted diff) +0 -0
@@ -83,6 +83,8 @@ EXPORT_SYMBOL_GPL(used_vectors);
 
Quoted 8 lines
Quoted 6 lines

arch/x86/kernel/traps.c EXPORT_SYMBOL_GPL(used_vectors); · line 86

Quoted 3 lines
arch/x86/kernel/traps.c +1 -0
 static int ignore_nmis;
 
+int unknown_nmi_panic;

I didn't apply the patches, so I am not really sure, but I think this could be static now.

It is used in kernel/sysctl.c so I don't think it can.

Ah, ok. Was only looking in arch/x86.

Thanks,

-Robert

Signature · 2 lines
Advanced Micro Devices, Inc.
Operating System Research Center
#33 lore raw
In reply to Don Zickus
Quoted 16 lines · Don Zickus

Restructuring the nmi handler to be more readable and simpler.

This is just laying the ground work for future improvements in this area.

I know people were complaining about having DIE_NMI and DIE_NMI_IPI, but for now it is consistent with what was there before. Hopefully, we can modify the notifier chain to make it smarter and combine the two events.

I also left out one of Huang's patch until we figure out how we are going to proceed with a new notifier.

Tested 32-bit and 64-bit on AMD and Intel machines.

Cheers,
Don

Quoted 7 lines

Huang Ying (5):
x86, NMI: Add NMI symbol constants and rename memory parity to PCI
SERR
x86, NMI: Add touch_nmi_watchdog to io_check_error delay x86, NMI: Rewrite NMI handler
x86, NMI: Allow NMI reason io port (0x61) to be processed on any CPU x86, NMI: Remove do_nmi_callback logic

I am fine with applying the patches, thanks Huang and Don.

I have some 2 comments on them and will reply directly.

-Robert

Quoted 17 lines
 arch/x86/include/asm/mach_traps.h |   12 +++-
 arch/x86/include/asm/nmi.h        |   10 +++-
 arch/x86/kernel/apic/hw_nmi.c     |    1 -
 arch/x86/kernel/apic/nmi.c        |   29 +-------
 arch/x86/kernel/cpu/perf_event.c  |    1 -
 arch/x86/kernel/traps.c           |  141 ++++++++++++++++++++----------------
 arch/x86/oprofile/nmi_int.c       |    1 -
 arch/x86/oprofile/nmi_timer_int.c |    2 +-
 drivers/char/ipmi/ipmi_watchdog.c |    2 +-
 drivers/watchdog/hpwdt.c          |    2 +-
 10 files changed, 102 insertions(+), 99 deletions(-)
Signature · 1 line
1.7.2.3
Signature · 2 lines
Advanced Micro Devices, Inc.
Operating System Research Center