tco: do not generate an NMI
PATCH 1/1 tco: do not generate an NMI
This behavior is not indicated in the datasheet and can confuse the OS.
--- hw/acpi/tco.c | 2 -- hw/isa/lpc_ich9.c | 5 ----- include/hw/i386/ich9.h | 1 - 3 files changed, 8 deletions(-)
hw/acpi/tco.c +0 -2
@@ -75,8 +75,6 @@ static void tco_timer_expired(void *opaque)if (pm->smi_en &ICH9_PMIO_SMI_EN_TCO_EN ) {ich9_generate_smi (); - }else { -ich9_generate_nmi (); } tr->tco.rld = tr->tco.tmr;tco_timer_reload (tr);
hw/isa/lpc_ich9.c +0 -5
@@ -312,11 +312,6 @@ void ich9_generate_smi(void)cpu_interrupt (first_cpu,CPU_INTERRUPT_SMI ); } -void ich9_generate_nmi (void ) -{ -cpu_interrupt (first_cpu,CPU_INTERRUPT_NMI ); -} -static int ich9_lpc_sci_irq (ICH9LPCState *lpc) { switch (lpc->d.config[ICH9_LPC_ACPI_CTRL] &
include/hw/i386/ich9.h +0 -1
@@ -21,7 +21,6 @@ void ich9_lpc_pm_init(PCIDevice *pci_lpc, bool smm_enabled);I2CBus *ich9_smb_init (PCIBus *bus,int devfn,uint32_t smb_io_base);void ich9_generate_smi (void ); -void ich9_generate_nmi (void );#define ICH9_CC_SIZE (16 * 1024)/* 16KB. Chipset configuration registers */
Signature · 1 line
2.9.3
CC Paulo
Quoted 1 line · Paolo Bonzini
This behavior is not indicated in the datasheet and can confuse the OS.
* The message of commit 920557971b60 ("ich9: add TCO interface emulation", 2015-06-28) says
Quoted 3 lines
... This patch adds support to TCO watchdog logic and few other features like mapping NMIs to SMIs (
NMI2SMI_ENbit), system intruder detection, etc. are not implemented yet.
(Terrible punctuation -- "and" should have been replaced by a full stop -- but the intent is clear.)
Looking at the ICH9 spec,
- TCO1_STS has a bit called NMI2SMI_STS, where value 1 means "Set by the ICH9 when an SMI# occurs because an event occurred that would otherwise have caused an NMI (because NMI2SMI_EN is set)."
- TCO1_CNT contains the bit called NMI2SMI_EN, where value 0 corresponds to "Normal NMI functionality."
These do appear to suggest that the normal timeout action for the watchdog is to inject and NMI, don't they?
* Does this patch keep "tests/tco-test.c" in working shape?
* Would blacklisting the iTCO_wdt module in the guest be a suitable counter-measure? Should OS installers be modified to blacklist "iTCO_wdt" by default if they detect a KVM guest?
(Idea taken from "Documentation/sysctl/kernel.txt", near "nmi_watchdog" -- "The NMI watchdog is disabled by default if the kernel is running as a guest in a KVM virtual machine.")
Thanks,
Laszlo
Quoted 50 lines
Signed-off-by Paolo Bonzini <[email protected]>--- hw/acpi/tco.c | 2 -- hw/isa/lpc_ich9.c | 5 ----- include/hw/i386/ich9.h | 1 - 3 files changed, 8 deletions(-)hw/acpi/tco.c +0
-2@@ -75,8 +75,6 @@ static void tco_timer_expired(void *opaque)if (pm->smi_en &ICH9_PMIO_SMI_EN_TCO_EN ) {ich9_generate_smi (); - }else { -ich9_generate_nmi (); } tr->tco.rld = tr->tco.tmr;tco_timer_reload (tr);hw/isa/lpc_ich9.c +0
-5@@ -312,11 +312,6 @@ void ich9_generate_smi(void)cpu_interrupt (first_cpu,CPU_INTERRUPT_SMI ); } -void ich9_generate_nmi (void ) -{ -cpu_interrupt (first_cpu,CPU_INTERRUPT_NMI ); -} -static int ich9_lpc_sci_irq (ICH9LPCState *lpc) { switch (lpc->d.config[ICH9_LPC_ACPI_CTRL] &include/hw/i386/ich9.h +0
-1@@ -21,7 +21,6 @@ void ich9_lpc_pm_init(PCIDevice *pci_lpc, bool smm_enabled);I2CBus *ich9_smb_init (PCIBus *bus,int devfn,uint32_t smb_io_base);void ich9_generate_smi (void ); -void ich9_generate_nmi (void );#define ICH9_CC_SIZE (16 * 1024)/* 16KB. Chipset configuration registers */
Quoted 21 lines · Laszlo Ersek
CC Paulo
Quoted 1 line · Paolo Bonzini
This behavior is not indicated in the datasheet and can confuse the OS.
* The message of commit
920557971b60("ich9: add TCO interface emulation", 2015-06-28) saysQuoted 3 lines
... This patch adds support to TCO watchdog logic and few other features like mapping NMIs to SMIs (
NMI2SMI_ENbit), system intruder detection, etc. are not implemented yet.(Terrible punctuation -- "and" should have been replaced by a full stop -- but the intent is clear.)
Looking at the ICH9 spec,
-
TCO1_STShas a bit calledNMI2SMI_STS, where value 1 means "Set by the ICH9 when an SMI# occurs because an event occurred that would otherwise have caused an NMI (becauseNMI2SMI_ENis set)."
Quoted 5 lines
-
TCO1_CNTcontains the bit calledNMI2SMI_EN, where value 0 corresponds to "Normal NMI functionality."These do appear to suggest that the normal timeout action for the watchdog is to inject and NMI, don't they?
They do, but that's not the normal timeout action. There is evidence through the ICH9 spec, but you need multiple clues to understand what's really going on.
If you look at Table 5-28 (Causes of SMI# and SCI), you have the following entries:
TCO SMI Logic
enabled by TCO_EN=1, reported in TCO_STS
TCO SMI — TCO TIMEROUT
no additional enables, reported in TIMEOUT
TCO SMI — NMI occurred (and NMIs mapped to SMI)
enabled by NMI2SMI_EN=1, reported in NMI2SMI_STS
The NMI2SMI_STS bit in TCO1_STS is read-only (unlike TIMEOUT and others) and it says (13.9.4):
0 = Cleared by clearing the associated NMI status bit.
1 = Set by the ICH9 when an SMI# occurs because an event occurred that
would otherwise have caused an NMI (because NMI2SMI_EN is set).
"Otherwise" is the key word here, and is confirmed by two other parts of the manual. In 13.9.6, NMI2SMI_EN is described like this:
0 = Normal NMI functionality.
1 = Forces all NMIs to instead cause SMIs.
In Table 5-23, the following NMI sources are listed:
- SERR# goes active (either internally, externally via SERR# signal, or via message from (G)MCH)
- IOCHK# goes active via SERIRQ# stream (ISA system Error)
Ignoring the acronym soup, the right column is interesting: "Can instead be routed to generate an SCI, through the NMI2SCI_EN bit (Device 31:Function 0, TCO Base + 08h, bit 11)". There is _no_ NMI2SCI_EN bit; that bit is "TCO Timer Halt" while NMI2SMI_EN is bit 9 in TCOBASE+08h.
The typo has been propagated in pretty much every Intel southbridge manual including ICH2 (year 2000) and X79 (aka Patsburg, year 2013), but a plausible way to read it is "Can instead be routed to generate an SMI, through the NMI2SMI_EN bit (Device 31:Function 0, TCO Base + 08h, bit 9)".
So if you put all these together:
- NMI2SMI_EN refers to system error NMIs (SERR#/IOCHK#). The SERR/IOCHK status bits in port 61h (ICH9 datasheet 13.7.1) are the "associated NMI status bits" mentioned in the documentation for NMI2SMI_STS
- both watchdog SMIs and "mapped NMI" SMIs are enabled by TCO_EN
- even if firmware needed TCO SMIs, it would not necessarily prevent the operating system from using the TCO watchdog. As long as the firmware's TCO SMI handler does not touch TCO_RLD, the extra SMI is not an issue (of course, in the real world many firmwares do).
Quoted 1 line
* Does this patch keep "
tests/tco-test.c" in working shape?
Yes, tco-test only tests the registers and the watchdog actions, not the interrupts.
Quoted 3 lines
* Would blacklisting the
iTCO_wdtmodule in the guest be a suitable counter-measure? Should OS installers be modified to blacklist "iTCO_wdt" by default if they detect a KVM guest?
No, on the contrary I'd like to use iTCO_wdt :) but right now the unexpected NMI causes a "dazed and confused" message on Linux. If I disable both NMI and SMI (and pass "-global ICH9-LPC.noreboot=false" so that the watchdog does reboot the machine), everything works without ugly messages.
Quoted 3 lines
(Idea taken from "
Documentation/sysctl/kernel.txt", near "nmi_watchdog" -- "The NMI watchdog is disabled by default if the kernel is running as a guest in a KVM virtual machine.")
The Linux NMI watchdog is something else, it is obtained by programming a hardware performance counter on every processor. On Linux, performance counters raise NMIs.
Paolo
Quoted 51 lines
Quoted 50 lines
Signed-off-by Paolo Bonzini <[email protected]>--- hw/acpi/tco.c | 2 -- hw/isa/lpc_ich9.c | 5 ----- include/hw/i386/ich9.h | 1 - 3 files changed, 8 deletions(-)hw/acpi/tco.c +0
-2@@ -75,8 +75,6 @@ static void tco_timer_expired(void *opaque)if (pm->smi_en &ICH9_PMIO_SMI_EN_TCO_EN ) {ich9_generate_smi (); - }else { -ich9_generate_nmi (); } tr->tco.rld = tr->tco.tmr;tco_timer_reload (tr);hw/isa/lpc_ich9.c +0
-5@@ -312,11 +312,6 @@ void ich9_generate_smi(void)cpu_interrupt (first_cpu,CPU_INTERRUPT_SMI ); } -void ich9_generate_nmi (void ) -{ -cpu_interrupt (first_cpu,CPU_INTERRUPT_NMI ); -} -static int ich9_lpc_sci_irq (ICH9LPCState *lpc) { switch (lpc->d.config[ICH9_LPC_ACPI_CTRL] &include/hw/i386/ich9.h +0
-1@@ -21,7 +21,6 @@ void ich9_lpc_pm_init(PCIDevice *pci_lpc, bool smm_enabled);I2CBus *ich9_smb_init (PCIBus *bus,int devfn,uint32_t smb_io_base);void ich9_generate_smi (void ); -void ich9_generate_nmi (void );#define ICH9_CC_SIZE (16 * 1024)/* 16KB. Chipset configuration registers */
Quoted 77 lines · Paolo Bonzini
Quoted 21 lines · Laszlo Ersek
CC Paulo
Quoted 1 line · Paolo Bonzini
This behavior is not indicated in the datasheet and can confuse the OS.
* The message of commit
920557971b60("ich9: add TCO interface emulation", 2015-06-28) saysQuoted 3 lines
... This patch adds support to TCO watchdog logic and few other features like mapping NMIs to SMIs (
NMI2SMI_ENbit), system intruder detection, etc. are not implemented yet.(Terrible punctuation -- "and" should have been replaced by a full stop -- but the intent is clear.)
Looking at the ICH9 spec,
-
TCO1_STShas a bit calledNMI2SMI_STS, where value 1 means "Set by the ICH9 when an SMI# occurs because an event occurred that would otherwise have caused an NMI (becauseNMI2SMI_ENis set)."Quoted 5 lines
-
TCO1_CNTcontains the bit calledNMI2SMI_EN, where value 0 corresponds to "Normal NMI functionality."These do appear to suggest that the normal timeout action for the watchdog is to inject and NMI, don't they?
They do, but that's not the normal timeout action. There is evidence through the ICH9 spec, but you need multiple clues to understand what's really going on.
If you look at Table 5-28 (Causes of SMI# and SCI), you have the following entries:
TCO SMI Logic
enabled by TCO_EN=1, reported inTCO_STS
TCO SMI — TCO TIMEROUT
no additional enables, reported in TIMEOUT
TCO SMI — NMI occurred (and NMIs mapped to SMI)
enabled by NMI2SMI_EN=1, reported inNMI2SMI_STSThe
NMI2SMI_STSbit inTCO1_STSis read-only (unlike TIMEOUT and others) and it says (13.9.4):0 = Cleared by clearing the associated NMI status bit.
1 = Set by the ICH9 when an SMI# occurs because an event occurred that
would otherwise have caused an NMI (becauseNMI2SMI_ENis set)."Otherwise" is the key word here, and is confirmed by two other parts of the manual. In 13.9.6,
NMI2SMI_ENis described like this:0 = Normal NMI functionality.
1 = Forces all NMIs to instead cause SMIs.In Table 5-23, the following NMI sources are listed:
- SERR# goes active (either internally, externally via SERR# signal, or via message from (G)MCH)
- IOCHK# goes active via SERIRQ# stream (ISA system Error)
Ignoring the acronym soup, the right column is interesting: "Can instead be routed to generate an SCI, through the
NMI2SCI_ENbit (Device 31:Function 0, TCO Base + 08h, bit 11)". There is _no_NMI2SCI_ENbit; that bit is "TCO Timer Halt" whileNMI2SMI_ENis bit 9 in TCOBASE+08h.The typo has been propagated in pretty much every Intel southbridge manual including ICH2 (year 2000) and X79 (aka Patsburg, year 2013), but a plausible way to read it is "Can instead be routed to generate an SMI, through the
NMI2SMI_ENbit (Device 31:Function 0, TCO Base + 08h, bit 9)".
Quoted 5 lines
So if you put all these together:
-
NMI2SMI_ENrefers to system error NMIs (SERR#/IOCHK#). The SERR/IOCHK status bits in port 61h (ICH9 datasheet 13.7.1) are the "associated NMI status bits" mentioned in the documentation forNMI2SMI_STS
Yes, I did track it back to SERR#/IOCHK#.
What wasn't obvious to me why the TCO watchdog couldn't activate SERR#.
I guess I missed the "SERR#" explanation in Table-2.6 "PCI Interface Signals", where it is described as
System Error: SERR# can be pulsed active by any PCI device that detects a system error condition. Upon sampling SERR# active, the ICH9 has the ability to generate an NMI, SMI#, or interrupt.
... Well, I still don't see why the watchdog cannot activate SERR#. Why can't it? :)
Quoted 8 lines
- both watchdog SMIs and "mapped NMI" SMIs are enabled by
TCO_EN- even if firmware needed TCO SMIs, it would not necessarily prevent the operating system from using the TCO watchdog. As long as the firmware's TCO SMI handler does not touch
TCO_RLD, the extra SMI is not an issue (of course, in the real world many firmwares do).
Quoted 4 lines
Quoted 1 line
* Does this patch keep "
tests/tco-test.c" in working shape?Yes, tco-test only tests the registers and the watchdog actions, not the interrupts.
Ah okay, I genuinely missed that the watchdog actions are handled separately in QEMU.
Where is the TCO watchdog hooked up to the general watchdog stuff (like, to emitting a WATCHDOG event)?
... I see it now. It's the watchdog_perform_action() call in tco_timer_expired(). And, it is indeed handled separately from the interrupt injection.
Quoted 7 lines
Quoted 3 lines
* Would blacklisting the
iTCO_wdtmodule in the guest be a suitable counter-measure? Should OS installers be modified to blacklist "iTCO_wdt" by default if they detect a KVM guest?No, on the contrary I'd like to use
iTCO_wdt:) but right now the unexpected NMI causes a "dazed and confused" message on Linux. If I disable both NMI and SMI
You mean "by applying is patch, and then not setting ICH9_PMIO_SMI_EN_TCO_EN in the guest"?
Quoted 1 line
(and pass "-global ICH9-LPC.noreboot=false"
This was confusing, but I see it un-gates the very watchdog_perform_action() call that I just found above, via (!lpc->pin_strap.spkr_hi). I also had to read commit 5add35bec1e2 ("ich9: implement strap SPKR pin logic", 2015-06-28).
Quoted 3 lines
so
that the watchdog does reboot the machine), everything works without ugly messages.
Thanks for the explanation. I now wonder why Paulo decided to add the NMI in the first place -- was he too confused by the SERR# definition?
Quoted 8 lines
Quoted 4 lines
(Idea taken from "
Documentation/sysctl/kernel.txt", near "nmi_watchdog" -- "The NMI watchdog is disabled by default if the kernel is running as a guest in a KVM virtual machine.")The Linux NMI watchdog is something else, it is obtained by programming a hardware performance counter on every processor. On Linux, performance counters raise NMIs.
I understood that, yes. "Documentation/sysctl/kernel.txt" -- unlike the other text files under Documentation/ that mention "nmi_watchdog" -- made it clear. My point was rather that we could follow this (independent) example.
Namely, for whatever reason it was wrong to raise an NMI in a KVM guest through those performance counters, the same reason would be enough to not raise an NMI through the iTCO_wdt driver either.
If the culprit is the device model in QEMU though, then I agree the driver should not be blacklisted.
So why is SERR# activation off-limits for the TCO watchdog? I think if I can understand that, then I'll see that this patch is correct too.
Thanks,
Laszlo
Quoted 54 lines
Paolo
Quoted 51 lines
Quoted 50 lines
Signed-off-by Paolo Bonzini <[email protected]>--- hw/acpi/tco.c | 2 -- hw/isa/lpc_ich9.c | 5 ----- include/hw/i386/ich9.h | 1 - 3 files changed, 8 deletions(-)hw/acpi/tco.c +0
-2@@ -75,8 +75,6 @@ static void tco_timer_expired(void *opaque)if (pm->smi_en &ICH9_PMIO_SMI_EN_TCO_EN ) {ich9_generate_smi (); - }else { -ich9_generate_nmi (); } tr->tco.rld = tr->tco.tmr;tco_timer_reload (tr);hw/isa/lpc_ich9.c +0
-5@@ -312,11 +312,6 @@ void ich9_generate_smi(void)cpu_interrupt (first_cpu,CPU_INTERRUPT_SMI ); } -void ich9_generate_nmi (void ) -{ -cpu_interrupt (first_cpu,CPU_INTERRUPT_NMI ); -} -static int ich9_lpc_sci_irq (ICH9LPCState *lpc) { switch (lpc->d.config[ICH9_LPC_ACPI_CTRL] &include/hw/i386/ich9.h +0
-1@@ -21,7 +21,6 @@ void ich9_lpc_pm_init(PCIDevice *pci_lpc, bool smm_enabled);I2CBus *ich9_smb_init (PCIBus *bus,int devfn,uint32_t smb_io_base);void ich9_generate_smi (void ); -void ich9_generate_nmi (void );#define ICH9_CC_SIZE (16 * 1024)/* 16KB. Chipset configuration registers */
Quoted 7 lines · Laszlo Ersek
Yes, I did track it back to SERR#/IOCHK#.
What wasn't obvious to me why the TCO watchdog couldn't activate SERR#.
I guess I missed the "SERR#" explanation in Table-2.6 "PCI Interface Signals", where it is described as
Quoted 6 lines
System Error: SERR# can be pulsed active by any PCI device that detects a system error condition. Upon sampling SERR# active, the ICH9 has the ability to generate an NMI, SMI#, or interrupt.
... Well, I still don't see why the watchdog cannot activate SERR#. Why can't it? :)
Because that's not what SERR# is for? :) And especially because the effect of a watchdog timeout is described elsewhere without including SERR# in the picture.
Quoted 5 lines
Quoted 2 lines
so that the watchdog does reboot the machine), everything works without ugly messages.
Thanks for the explanation. I now wonder why Paulo decided to add the NMI in the first place -- was he too confused by the SERR# definition?
Both Paulo and Paolo were confused. :)
Quoted 11 lines
Quoted 7 lines
Quoted 3 lines
(Idea taken from "
Documentation/sysctl/kernel.txt", near "nmi_watchdog" -- "The NMI watchdog is disabled by default if the kernel is running as a guest in a KVM virtual machine.")The Linux NMI watchdog is something else, it is obtained by programming a hardware performance counter on every processor. On Linux, performance counters raise NMIs.
Namely, for whatever reason it was wrong to raise an NMI in a KVM guest through those performance counters, the same reason would be enough to not raise an NMI through the
iTCO_wdtdriver either.
I think the reason is not that it's wrong; it's that by default KVM guests do not have performance counters at all.
Paolo
Laszlo Ersek
Reviewed-byQuoted 14 lines · Paolo Bonzini
Quoted 11 lines · Laszlo Ersek
Yes, I did track it back to SERR#/IOCHK#.
What wasn't obvious to me why the TCO watchdog couldn't activate SERR#.
I guess I missed the "SERR#" explanation in Table-2.6 "PCI Interface Signals", where it is described as
System Error: SERR# can be pulsed active by any PCI device that detects a system error condition. Upon sampling SERR# active, the ICH9 has the ability to generate an NMI, SMI#, or interrupt.
Quoted 6 lines
Quoted 2 lines
... Well, I still don't see why the watchdog cannot activate SERR#. Why can't it? :)
Because that's not what SERR# is for? :) And especially because the effect of a watchdog timeout is described elsewhere without including SERR# in the picture.
That's a valid argument.
Quoted 17 lines
Quoted 6 lines
Quoted 3 lines
so that the watchdog does reboot the machine), everything works without ugly messages.
Thanks for the explanation. I now wonder why Paulo decided to add the NMI in the first place -- was he too confused by the SERR# definition?
Both Paulo and Paolo were confused. :)
Quoted 8 lines
Quoted 7 lines
Quoted 3 lines
(Idea taken from "
Documentation/sysctl/kernel.txt", near "nmi_watchdog" -- "The NMI watchdog is disabled by default if the kernel is running as a guest in a KVM virtual machine.")The Linux NMI watchdog is something else, it is obtained by programming a hardware performance counter on every processor. On Linux, performance counters raise NMIs.
Quoted 6 lines
Quoted 3 lines
Namely, for whatever reason it was wrong to raise an NMI in a KVM guest through those performance counters, the same reason would be enough to not raise an NMI through the
iTCO_wdtdriver either.I think the reason is not that it's wrong; it's that by default KVM guests do not have performance counters at all.
Makes sense.
Thank you for taking the time to explain it all.
Cheers!
Laszlo