xen/x86: prevent local APIC errors at shutdown
v2 cover xen/x86: prevent local APIC errors at shutdown
Hello,
The following series aims to prevent local APIC errors from stalling the shtudown process. On XenServer testing we have seen reports of AMD boxes sporadically getting stuck in a spam of:
APIC error on CPU0: 00(08), Receive accept error
Messages during shutdown, as a result of device interrupts targeting CPUs that are offline (and have the local APIC disabled).
First patch strictly solves the issue of shutdown getting stuck, further patches aim to quiesce interrupts from all devices (known by Xen) as an attempt to prevent a spurious "APIC error on CPU0: 00(00)" plus also make kexec more reliable.
Thanks, Roger.
Roger Pau Monne (5):
x86/shutdown: offline APs with interrupts disabled on all CPUs x86/irq: drop fixup_irqs() parameters
x86/smp: perform disabling on interrupts ahead of AP shutdown x86/pci: disable MSI(-X) on all devices at shutdown x86/iommu: disable interrupts at shutdown
xen/arch/x86/crash.c | 2 ++ xen/arch/x86/include/asm/irq.h | 4 +-- xen/arch/x86/include/asm/msi.h | 1 + xen/arch/x86/irq.c | 30 ++++++++----------- xen/arch/x86/msi.c | 18 +++++++++++ xen/arch/x86/smp.c | 33 +++++++++++++++------ xen/arch/x86/smpboot.c | 2 +- xen/drivers/passthrough/amd/iommu.h | 1 + xen/drivers/passthrough/amd/iommu_init.c | 17 +++++++++++ xen/drivers/passthrough/amd/pci_amd_iommu.c | 1 + xen/drivers/passthrough/iommu.c | 6 ++++ xen/drivers/passthrough/pci.c | 33 +++++++++++++++++++++ xen/drivers/passthrough/vtd/iommu.c | 19 ++++++++++++ xen/include/xen/iommu.h | 3 ++ xen/include/xen/pci.h | 4 +++ 15 files changed, 145 insertions(+), 29 deletions(-)
Signature · 1 line
2.46.0
PATCH v2 1/5 x86/shutdown: offline APs with interrupts disabled on all CPUs
The current shutdown logic in smp_send_stop() will disable the APs while having interrupts enabled on the BSP or possibly other APs. On AMD systems this can lead to local APIC errors:
APIC error on CPU0: 00(08), Receive accept error
Such error message can be printed in a loop, thus blocking the system from rebooting. I assume this loop is created by the error being triggered by the console interrupt, which is further stirred by the ESR handler printing to the console.
Intel SDM states:
"Receive Accept Error.
Set when the local APIC detects that the message it received was not accepted by any APIC on the APIC bus, including itself. Used only on P6 family and Pentium processors."
So the error shouldn't trigger on any Intel CPU supported by Xen.
However AMD doesn't make such claims, and indeed the error is broadcasted to all local APICs when an interrupt targets a CPU that's already offline.
To prevent the error from stalling the shutdown process perform the disabling of APs and the BSP local APIC with interrupts disabled on all CPUs in the system, so that by the time interrupts are unmasked on the BSP the local APIC is already disabled. This can still lead to a spurious:
APIC error on CPU0: 00(00)
As a result of an LVT Error getting injected while interrupts are masked on the CPU, and the vector only handled after the local APIC is already disabled.
Note the NMI crash path doesn't have such issue, because disabling of APs and the caller local APIC is already done in the same contiguous region with interrupts disabled. There's a possible window on the NMI crash path (nmi_shootdown_cpus()) where some APs might be disabled (and thus interrupts targeting them raising "Receive accept error") before others APs have interrupts disabled. However the shutdown NMI will be handled, regardless of whether the AP is processing a local APIC error, and hence such interrupts will not cause the shutdown process to get stuck.
Remove the call to fixup_irqs() in smp_send_stop(), as it doesn't achieve the intended goal of moving all interrupts to the BSP anyway, because when called the APs are still set as online in cpu_online_map.
---
Changes since v1:
- Change the approach and instead rely on having interrupts uniformly disabled when offlining APs.
--- xen/arch/x86/smp.c | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-)
xen/arch/x86/smp.c +20 -7
@@ -345,6 +345,11 @@ void __stop_this_cpu(void) static void cf_check stop_this_cpu(void *dummy) { +const bool *stop_aps = dummy; + +while ( !*stop_aps ) +cpu_relax (); +__stop_this_cpu ();for ( ; ; )halt ();
@@ -357,16 +362,25 @@ static void cf_check stop_this_cpu(void *dummy)void smp_send_stop (void ) {unsigned int cpu =smp_processor_id (); +bool stop_aps = false; + +/* +* Perform AP offlining and disabling of interrupt controllers with all +* CPUs on the system having interrupts disabled to prevent interrupt +* delivery errors. On AMD systems "Receive accept error" will be +* broadcasted to local APICs if interrupts target CPUs that are offline. +*/ +if (num_online_cpus () >1 ) +smp_call_function (stop_this_cpu, &stop_aps,0 ); + +local_irq_disable ();if (num_online_cpus () >1 ) {int timeout =10 ; -local_irq_disable (); -fixup_irqs (cpumask_of (cpu),0 ); -local_irq_enable (); - -smp_call_function (stop_this_cpu,NULL ,0 ); +/* Signal APs to stop. */ + stop_aps = true;/* Wait 10ms for all other CPUs to go offline. */ while ( (num_online_cpus () >1 ) && (timeout-- >0 ) )
@@ -375,13 +389,12 @@ void smp_send_stop(void)if (cpu_online (cpu) ) { -local_irq_disable ();disable_IO_APIC ();hpet_disable ();__stop_this_cpu (); x2apic_enabled = (current_local_apic_mode () ==APIC_MODE_X2APIC ); -local_irq_enable (); } +local_irq_enable (); }void smp_send_nmi_allbutself (void )
Signature · 1 line
2.46.0
Re: [PATCH v2 1/5] x86/shutdown: offline APs with interrupts disabled on all CPUs
Quoted 29 lines · Roger Pau Monne
The current shutdown logic in
smp_send_stop()will disable the APs while having interrupts enabled on the BSP or possibly other APs. On AMD systems this can lead to local APIC errors:APIC error on CPU0: 00(08), Receive accept error
Such error message can be printed in a loop, thus blocking the system from rebooting. I assume this loop is created by the error being triggered by the console interrupt, which is further stirred by the ESR handler printing to the console.
Intel SDM states:
"Receive Accept Error.
Set when the local APIC detects that the message it received was not accepted by any APIC on the APIC bus, including itself. Used only on P6 family and Pentium processors."
So the error shouldn't trigger on any Intel CPU supported by Xen.
However AMD doesn't make such claims, and indeed the error is broadcasted to all local APICs when an interrupt targets a CPU that's already offline.
To prevent the error from stalling the shutdown process perform the disabling of APs and the BSP local APIC with interrupts disabled on all CPUs in the system, so that by the time interrupts are unmasked on the BSP the local APIC is already disabled. This can still lead to a spurious:
Quoted 5 lines
APIC error on CPU0: 00(00)
As a result of an LVT Error getting injected while interrupts are masked on the CPU, and the vector only handled after the local APIC is already disabled.
Isn't this bogus, too? As in: Error interrupt without any ESR bits set? Since I can already see our QA folks report this as another issue, can we perhaps somehow amend the log message in that case, indicating we think it's bogus?
Quoted 9 lines
Note the NMI crash path doesn't have such issue, because disabling of APs and the caller local APIC is already done in the same contiguous region with interrupts disabled. There's a possible window on the NMI crash path (
nmi_shootdown_cpus()) where some APs might be disabled (and thus interrupts targeting them raising "Receive accept error") before others APs have interrupts disabled. However the shutdown NMI will be handled, regardless of whether the AP is processing a local APIC error, and hence such interrupts will not cause the shutdown process to get stuck.
Quoted 3 lines
Remove the call to
fixup_irqs()insmp_send_stop(), as it doesn't achieve the intended goal of moving all interrupts to the BSP anyway, because when called the APs are still set as online incpu_online_map.
This is a little too little for my taste: The fact the APs are still online was, after all, intended to be covered by passing cpumask_of(cpu).
Quoted 1 line
Signed-off-by Roger Pau Monné <[email protected]>
I suppose there simply is no "good" commit to blame here with a Fixes: tag.
Quoted 20 lines
xen/arch/x86/smp.c +7
-0@@ -345,6 +345,11 @@ void __stop_this_cpu(void) static void cf_check stop_this_cpu(void *dummy) { +const bool *stop_aps = dummy; + +while ( !*stop_aps ) +cpu_relax (); +__stop_this_cpu ();for ( ; ; )halt ();@@ -357,16 +362,25 @@ static void cf_check stop_this_cpu(void *dummy)void smp_send_stop (void ) {unsigned int cpu =smp_processor_id (); +bool stop_aps = false; +
xen/arch/x86/smp.c static void cf_check stop_this_cpu(void *dummy) · line 376
Quoted 10 lines
xen/arch/x86/smp.c +10
-0+/* +* Perform AP offlining and disabling of interrupt controllers with all +* CPUs on the system having interrupts disabled to prevent interrupt +* delivery errors. On AMD systems "Receive accept error" will be +* broadcasted to local APICs if interrupts target CPUs that are offline. +*/ +if (num_online_cpus () >1 ) +smp_call_function (stop_this_cpu, &stop_aps,0 ); + +local_irq_disable ();
With the extensive comment I think this is going to be okay. Just one grammar thing (and I'm curious myself), mainly to Andrew as a native speaker (or any other native speakers who read this): While I can find the form you use even in things calling themselves dictionaries, I've still been under the impression that it is "be broadcast". (If so, also somewhere in the description then.)
Jan
Re: [PATCH v2 1/5] x86/shutdown: offline APs with interrupts disabled on all CPUs
Quoted 32 lines · Jan Beulich
Quoted 31 lines · Roger Pau Monne
The current shutdown logic in
smp_send_stop()will disable the APs while having interrupts enabled on the BSP or possibly other APs. On AMD systems this can lead to local APIC errors:APIC error on CPU0: 00(08), Receive accept error
Such error message can be printed in a loop, thus blocking the system from rebooting. I assume this loop is created by the error being triggered by the console interrupt, which is further stirred by the ESR handler printing to the console.
Intel SDM states:
"Receive Accept Error.
Set when the local APIC detects that the message it received was not accepted by any APIC on the APIC bus, including itself. Used only on P6 family and Pentium processors."
So the error shouldn't trigger on any Intel CPU supported by Xen.
However AMD doesn't make such claims, and indeed the error is broadcasted to all local APICs when an interrupt targets a CPU that's already offline.
To prevent the error from stalling the shutdown process perform the disabling of APs and the BSP local APIC with interrupts disabled on all CPUs in the system, so that by the time interrupts are unmasked on the BSP the local APIC is already disabled. This can still lead to a spurious:
APIC error on CPU0: 00(00)
Quoted 7 lines
Quoted 3 lines
As a result of an LVT Error getting injected while interrupts are masked on the CPU, and the vector only handled after the local APIC is already disabled.
Isn't this bogus, too? As in: Error interrupt without any ESR bits set? Since I can already see our QA folks report this as another issue, can we perhaps somehow amend the log message in that case, indicating we think it's bogus?
Note that the disable_local_APIC() call in __stop_this_cpu() does also call clear_local_APIC(), which will attempt to clear ESR also.
Further patches in the series prevent the error from triggering in the first place, since an attempt is made to disable or mask all possible external interrupt sources Xen knows about before doing AP shutdown.
Quoted 14 lines
Quoted 10 lines
Note the NMI crash path doesn't have such issue, because disabling of APs and the caller local APIC is already done in the same contiguous region with interrupts disabled. There's a possible window on the NMI crash path (
nmi_shootdown_cpus()) where some APs might be disabled (and thus interrupts targeting them raising "Receive accept error") before others APs have interrupts disabled. However the shutdown NMI will be handled, regardless of whether the AP is processing a local APIC error, and hence such interrupts will not cause the shutdown process to get stuck.Quoted 3 lines
Remove the call to
fixup_irqs()insmp_send_stop(), as it doesn't achieve the intended goal of moving all interrupts to the BSP anyway, because when called the APs are still set as online incpu_online_map.
Quoted 6 lines
This is a little too little for my taste: The fact the APs are still online was, after all, intended to be covered by passing
cpumask_of(cpu).Quoted 1 line
Signed-off-by Roger Pau Monné <[email protected]>I suppose there simply is no "good" commit to blame here with a Fixes: tag.
Wondered the same, but I couldn't find any suitable commit. It's been like this forever as far as I can tell. It's possible my previous fixes for fixup_irqs() made this worse, but I don't think it was correct to begin with.
Quoted 29 lines
Quoted 29 lines
xen/arch/x86/smp.c +15
-0@@ -345,6 +345,11 @@ void __stop_this_cpu(void) static void cf_check stop_this_cpu(void *dummy) { +const bool *stop_aps = dummy; + +while ( !*stop_aps ) +cpu_relax (); +__stop_this_cpu ();for ( ; ; )halt ();@@ -357,16 +362,25 @@ static void cf_check stop_this_cpu(void *dummy)void smp_send_stop (void ) {unsigned int cpu =smp_processor_id (); +bool stop_aps = false; + +/* +* Perform AP offlining and disabling of interrupt controllers with all +* CPUs on the system having interrupts disabled to prevent interrupt +* delivery errors. On AMD systems "Receive accept error" will be +* broadcasted to local APICs if interrupts target CPUs that are offline. +*/ +if (num_online_cpus () >1 ) +smp_call_function (stop_this_cpu, &stop_aps,0 );
Quoted 8 lines
xen/arch/x86/smp.c static void cf_check stop_this_cpu(void *dummy) · line 376
Quoted 2 lines
xen/arch/x86/smp.c +2
-0+ +local_irq_disable ();With the extensive comment I think this is going to be okay. Just one grammar thing (and I'm curious myself), mainly to Andrew as a native speaker (or any other native speakers who read this): While I can find the form you use even in things calling themselves dictionaries, I've still been under the impression that it is "be broadcast". (If so, also somewhere in the description then.)
I don't have a strong opinion. I also looked it up and seemed to be correct, but might not be fine to use in this context.
Thanks, Roger.
Re: [PATCH v2 1/5] x86/shutdown: offline APs with interrupts disabled on all CPUs
Quoted 37 lines · Roger Pau Monné
Quoted 36 lines · Jan Beulich
Quoted 34 lines · Roger Pau Monne
The current shutdown logic in
smp_send_stop()will disable the APs while having interrupts enabled on the BSP or possibly other APs. On AMD systems this can lead to local APIC errors:APIC error on CPU0: 00(08), Receive accept error
Such error message can be printed in a loop, thus blocking the system from rebooting. I assume this loop is created by the error being triggered by the console interrupt, which is further stirred by the ESR handler printing to the console.
Intel SDM states:
"Receive Accept Error.
Set when the local APIC detects that the message it received was not accepted by any APIC on the APIC bus, including itself. Used only on P6 family and Pentium processors."
So the error shouldn't trigger on any Intel CPU supported by Xen.
However AMD doesn't make such claims, and indeed the error is broadcasted to all local APICs when an interrupt targets a CPU that's already offline.
To prevent the error from stalling the shutdown process perform the disabling of APs and the BSP local APIC with interrupts disabled on all CPUs in the system, so that by the time interrupts are unmasked on the BSP the local APIC is already disabled. This can still lead to a spurious:
APIC error on CPU0: 00(00)
As a result of an LVT Error getting injected while interrupts are masked on the CPU, and the vector only handled after the local APIC is already disabled.
Quoted 6 lines
Quoted 3 lines
Isn't this bogus, too? As in: Error interrupt without any ESR bits set? Since I can already see our QA folks report this as another issue, can we perhaps somehow amend the log message in that case, indicating we think it's bogus?
Note that the
disable_local_APIC()call in__stop_this_cpu()does also callclear_local_APIC(), which will attempt to clear ESR also.
Hmm, that's odd. I wonder whether we shouldn't suppress this when called from disable_local_APIC().
Quoted 3 lines
Further patches in the series prevent the error from triggering in the first place, since an attempt is made to disable or mask all possible external interrupt sources Xen knows about before doing AP shutdown.
Right.
Jan
PATCH v2 2/5 x86/irq: drop fixup_irqs() parameters
In reply to Roger Pau MonneThe solely remaining caller always passes the same globally available parameters. Drop the parameters and modify fixup_irqs() to use cpu_online_map in place of the input mask parameter, and always be verbose in its output printing.
While there remove some of the checks given the single context where fixup_irqs() is now called, which should always be in the CPU offline path, after the CPU going offline has been removed from cpu_online_map.
No functional change intended.
---
There's more cleanup that can likely be done here, but it's best if such cleanup is done after the cpu_mask and old_cpu_mask irq_desc fields are converted from cpu masks to integers, as logic delivery mode should never be used for external interrupts now.
--- xen/arch/x86/include/asm/irq.h | 4 ++-- xen/arch/x86/irq.c | 30 +++++++++++++----------------- xen/arch/x86/smpboot.c | 2 +- 3 files changed, 16 insertions(+), 20 deletions(-)
xen/arch/x86/include/asm/irq.h +2 -2
@@ -168,8 +168,8 @@ void free_domain_pirqs(struct domain *d);int map_domain_emuirq_pirq (struct domain *d,int pirq,int emuirq);int unmap_domain_pirq_emuirq (struct domain *d,int pirq); -/* Evacuate interrupts assigned to CPUs not present in the input CPU mask. */ -void fixup_irqs (const cpumask_t *mask,bool verbose); +/* Evacuate interrupts assigned to CPUs not present in the CPU online map. */ +void fixup_irqs (void );void fixup_eoi (void );int init_irq_data (void );
xen/arch/x86/irq.c +13 -17
@@ -2590,17 +2590,21 @@ static int __init cf_check setup_dump_irqs(void) }__initcall (setup_dump_irqs); -/* Evacuate interrupts assigned to CPUs not present in the input CPU mask. */ -void fixup_irqs (const cpumask_t *mask,bool verbose) +/* Evacuate interrupts assigned to CPUs not present in the CPU online map. */ +void fixup_irqs (void ) { +const unsigned int cpu =smp_processor_id ();unsigned int irq;static int warned;struct irq_desc *desc; +/* Only to be called from the context of a CPU going offline. */ +ASSERT (!cpu_online (cpu)); +for ( irq =0 ; irq < nr_irqs; irq++ ) {bool break_affinity = false, set_affinity = true, check_irr = false; -unsigned int vector, cpu =smp_processor_id (); +unsigned int vector;cpumask_t *affinity =this_cpu (scratch_cpumask);if ( irq ==2 )
@@ -2644,12 +2648,6 @@ void fixup_irqs(const cpumask_t *mask, bool verbose) }if ( desc->arch.move_in_progress && -/* -* Only attempt to adjust the mask if the current CPU is going -* offline, otherwise the whole system is going down and leaving -* stale data in the masks is fine. -*/ - !cpu_online (cpu) &&cpumask_test_cpu (cpu, desc->arch.old_cpu_mask) ) {/*
@@ -2691,16 +2689,17 @@ void fixup_irqs(const cpumask_t *mask, bool verbose)/* * Avoid shuffling the interrupt around as long as current target CPUs -* are a subset of the input mask. What fixup_irqs() cares about is -* evacuating interrupts from CPUs not in the input mask. +* are a subset of the online mask. What fixup_irqs() cares about is +* evacuating interrupts from CPUs not in the online mask. */ -if ( !desc->action ||cpumask_subset (desc->arch.cpu_mask, mask) ) +if ( !desc->action ||cpumask_subset (desc->arch.cpu_mask, + &cpu_online_map) ) {spin_unlock (&desc->lock);continue ; } -if ( !cpumask_intersects (mask, desc->affinity) ) +if ( !cpumask_intersects (&cpu_online_map, desc->affinity) ) { break_affinity = true;cpumask_setall (affinity);
@@ -2716,7 +2715,7 @@ void fixup_irqs(const cpumask_t *mask, bool verbose)* the interrupt, signal to check whether there are any pending vectors * to be handled in the local APIC after the interrupt has been moved. */ -if ( !cpu_online (cpu) &&cpumask_test_cpu (cpu, desc->arch.cpu_mask) ) +if (cpumask_test_cpu (cpu, desc->arch.cpu_mask) ) check_irr = true;if ( desc->handler->set_affinity )
@@ -2743,9 +2742,6 @@ void fixup_irqs(const cpumask_t *mask, bool verbose)spin_unlock (&desc->lock); -if ( !verbose ) -continue ; -if ( !set_affinity )printk ("Cannot set affinity for IRQ%u\n" , irq);else if ( break_affinity )
xen/arch/x86/smpboot.c +1 -1
@@ -1282,7 +1282,7 @@ void __cpu_disable(void)/* It's now safe to remove this processor from the online map */ cpumask_clear_cpu (cpu, &cpu_online_map); -fixup_irqs (&cpu_online_map,1 ); +fixup_irqs ();fixup_eoi (); }
Signature · 1 line
2.46.0
PATCH v2 3/5 x86/smp: perform disabling on interrupts ahead of AP shutdown
In reply to Roger Pau MonneMove the disabling of interrupt sources so it's done ahead of the offlining of APs. This is to prevent AMD systems triggering "Receive accept error" when interrupts target CPUs that are no longer online.
---
Changes since v1:
- New in this version.
--- xen/arch/x86/smp.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
xen/arch/x86/smp.c +2 -2
@@ -374,6 +374,8 @@ void smp_send_stop(void)smp_call_function (stop_this_cpu, &stop_aps,0 );local_irq_disable (); +disable_IO_APIC (); +hpet_disable ();if (num_online_cpus () >1 ) {
@@ -389,8 +391,6 @@ void smp_send_stop(void)if (cpu_online (cpu) ) { -disable_IO_APIC (); -hpet_disable ();__stop_this_cpu (); x2apic_enabled = (current_local_apic_mode () ==APIC_MODE_X2APIC ); }
Signature · 1 line
2.46.0
Re: [PATCH v2 3/5] x86/smp: perform disabling on interrupts ahead of AP shutdown
Quoted 8 lines · Roger Pau Monne
Move the disabling of interrupt sources so it's done ahead of the offlining of APs. This is to prevent AMD systems triggering "Receive accept error" when interrupts target CPUs that are no longer online.
Signed-off-by Roger Pau Monné <[email protected]>---
Changes since v1:
- New in this version.
Ah, you decided to effectively split the original patch.
with a question:
xen/arch/x86/smp.c void smp_send_stop(void) · line 378
Quoted 8 lines
xen/arch/x86/smp.c +2
-0@@ -374,6 +374,8 @@ void smp_send_stop(void)smp_call_function (stop_this_cpu, &stop_aps,0 );local_irq_disable (); +disable_IO_APIC (); +hpet_disable ();
Is this then taking care of the bogus error interrupt observing ESR=0x00?
Jan
Re: [PATCH v2 3/5] x86/smp: perform disabling on interrupts ahead of AP shutdown
Quoted 20 lines · Jan Beulich
Quoted 8 lines · Roger Pau Monne
Move the disabling of interrupt sources so it's done ahead of the offlining of APs. This is to prevent AMD systems triggering "Receive accept error" when interrupts target CPUs that are no longer online.
Signed-off-by Roger Pau Monné <[email protected]>---
Changes since v1:
- New in this version.Ah, you decided to effectively split the original patch.
Reviewed-by Jan Beulich <[email protected]>with a question:
Quoted 5 lines
xen/arch/x86/smp.c +0
-0@@ -374,6 +374,8 @@ void smp_send_stop(void)smp_call_function (stop_this_cpu, &stop_aps,0 );
Quoted 5 lines
xen/arch/x86/smp.c void smp_send_stop(void) · line 378
Quoted 3 lines
xen/arch/x86/smp.c +2
-0local_irq_disable (); +disable_IO_APIC (); +hpet_disable ();Is this then taking care of the bogus error interrupt observing ESR=0x00?
This, with the extra commits that follow should prevent the error from triggering yes. With all patches in the series applied I'm no longer able to see the ESR=0x00 message.
Thanks, Roger.
PATCH v2 4/5 x86/pci: disable MSI(-X) on all devices at shutdown
In reply to Roger Pau MonneAttempt to disable MSI(-X) capabilities on all PCI devices know by Xen at shutdown. Doing such disabling should facilitate kexec chained kernel from booting more reliably, as device MSI(-X) interrupt generation should be quiesced.
It would also prevent "Receive accept error" being raised as a result of non-disabled interrupts targeting offline CPUs.
---
Changes since v1:
- Split from bigger patch.
- Iterate over all devices, even if the handler returns failure.
--- xen/arch/x86/crash.c | 1 + xen/arch/x86/include/asm/msi.h | 1 + xen/arch/x86/msi.c | 18 ++++++++++++++++++ xen/arch/x86/smp.c | 1 + xen/drivers/passthrough/pci.c | 33 +++++++++++++++++++++++++++++++++ xen/include/xen/pci.h | 4 ++++ 6 files changed, 58 insertions(+)
xen/arch/x86/crash.c +1 -0
@@ -177,6 +177,7 @@ static void nmi_shootdown_cpus(void)disable_IO_APIC ();hpet_disable (); +pci_disable_msi_all (); } }
xen/arch/x86/include/asm/msi.h +1 -0
@@ -86,6 +86,7 @@ extern int pci_enable_msi(struct pci_dev *pdev, struct msi_info *msi,extern void pci_disable_msi (struct msi_desc *msi_desc);extern int pci_prepare_msix (u16 seg,u8 bus,u8 devfn,bool off);extern void pci_cleanup_msi (struct pci_dev *pdev); +extern void pci_disable_msi_all (void );extern int setup_msi_irq (struct irq_desc *desc,struct msi_desc *msidesc);extern int __setup_msi_irq (struct irq_desc *desc,struct msi_desc *msidesc,hw_irq_controller *handler);
xen/arch/x86/msi.c +18 -0
@@ -1248,6 +1248,24 @@ void pci_cleanup_msi(struct pci_dev *pdev)msi_free_irqs (pdev); } +static int cf_check disable_msi(struct pci_dev *pdev, void *arg) +{ +msi_set_enable (pdev,0 ); +msix_set_enable (pdev,0 ); + +return 0 ; +} + +/* Disable MSI and/or MSI-X on all devices known by Xen. */ +void pci_disable_msi_all (void ) +{ +int rc =pci_iterate_devices (disable_msi,NULL ); + +if ( rc ) +printk (XENLOG_ERR +"Failed to disable MSI(-X) on some devices: %d\n" , rc); +} +int pci_reset_msix_state (struct pci_dev *pdev) {unsigned int pos = pdev->msix_pos;
xen/arch/x86/smp.c +1 -0
@@ -376,6 +376,7 @@ void smp_send_stop(void)local_irq_disable ();disable_IO_APIC ();hpet_disable (); +pci_disable_msi_all ();if (num_online_cpus () >1 ) {
xen/drivers/passthrough/pci.c +33 -0
@@ -1803,6 +1803,39 @@ int iommu_do_pci_domctl(return ret; } +struct segment_iter { +int (*handler)(struct pci_dev *pdev,void *arg); +void *arg; +int rc; +}; + +static int cf_check iterate_all(struct pci_seg *pseg, void *arg) +{ +struct segment_iter *iter = arg; +struct pci_dev *pdev; + + list_for_each_entry ( pdev, &pseg->alldevs_list, alldevs_list ) + { +int rc = iter->handler (pdev, iter->arg); + +if ( !iter->rc ) + iter->rc = rc; + } + +return 0 ; +} + +int pci_iterate_devices (int (*handler)(struct pci_dev *pdev,void *arg), +void *arg) +{ +struct segment_iter iter = { + .handler = handler, + .arg = arg, + }; + +return pci_segments_iterate (iterate_all, &iter) ?: iter.rc; +} +/* * Local variables: * mode: C
xen/include/xen/pci.h +4 -0
@@ -226,6 +226,10 @@ struct pci_dev *pci_get_pdev(const struct domain *d, pci_sbdf_t sbdf);struct pci_dev *pci_get_real_pdev (pci_sbdf_t sbdf);void pci_check_disable_device (u16 seg,u8 bus,u8 devfn); +/* Iterate without locking or preemption over all PCI devices known by Xen. */ +int pci_iterate_devices (int (*handler)(struct pci_dev *pdev,void *arg), +void *arg); +uint8_t pci_conf_read8 (pci_sbdf_t sbdf,unsigned int reg);uint16_t pci_conf_read16 (pci_sbdf_t sbdf,unsigned int reg);uint32_t pci_conf_read32 (pci_sbdf_t sbdf,unsigned int reg);
Signature · 1 line
2.46.0
Re: [PATCH v2 4/5] x86/pci: disable MSI(-X) on all devices at shutdown
xen/arch/x86/crash.c static void nmi_shootdown_cpus(void) · line 181
Quoted 8 lines · Roger Pau Monne
xen/arch/x86/crash.c +1
-0@@ -177,6 +177,7 @@ static void nmi_shootdown_cpus(void)disable_IO_APIC ();hpet_disable (); +pci_disable_msi_all (); }
Apart from my concern below regarding use of the function in this context, for both uses I wonder in how far the order of the three calls above may matter. I can't really give a precise reason, but to me it feels like the PCI device processing may better be done first.
Quoted 28 lines
xen/drivers/passthrough/pci.c +22
-0@@ -1803,6 +1803,39 @@ int iommu_do_pci_domctl(return ret; } +struct segment_iter { +int (*handler)(struct pci_dev *pdev,void *arg); +void *arg; +int rc; +}; + +static int cf_check iterate_all(struct pci_seg *pseg, void *arg) +{ +struct segment_iter *iter = arg; +struct pci_dev *pdev; + + list_for_each_entry ( pdev, &pseg->alldevs_list, alldevs_list ) + { +int rc = iter->handler (pdev, iter->arg); + +if ( !iter->rc ) + iter->rc = rc; + } + +return 0 ; +} +
xen/drivers/passthrough/pci.c int iommu_do_pci_domctl( · line 1837
Quoted 10 lines
xen/drivers/passthrough/pci.c +10
-0+int pci_iterate_devices (int (*handler)(struct pci_dev *pdev,void *arg), +void *arg) +{ +struct segment_iter iter = { + .handler = handler, + .arg = arg, + }; + +return pci_segments_iterate (iterate_all, &iter) ?: iter.rc; +}
My earlier concern remains as far as e.g. list traversal goes, especially when we're called from nmi_shootdown_cpus() context. The lists themselves may be screwed, after all. Whereas disable_IO_APIC() and hpet_disable() don't involve any list traversal, and even if they did those lists would be stable post-boot.
We may want to talk about the up- and down-sides of this on the x86 call later in the day.
xen/include/xen/pci.h struct pci_dev *pci_get_pdev(const struct domain *d, pci_sbdf_t sbdf); · line 231
Quoted 9 lines
xen/include/xen/pci.h +3
-0@@ -226,6 +226,10 @@ struct pci_dev *pci_get_pdev(const struct domain *d, pci_sbdf_t sbdf);struct pci_dev *pci_get_real_pdev (pci_sbdf_t sbdf);void pci_check_disable_device (u16 seg,u8 bus,u8 devfn); +/* Iterate without locking or preemption over all PCI devices known by Xen. */ +int pci_iterate_devices (int (*handler)(struct pci_dev *pdev,void *arg), +void *arg);
Oh, I see you added the comment here that I did ask for. As it's pretty important for people to notice, may I ask that it be replicated in (or ahead of) the function definition? And then there perhaps also mentioning that one needs to be aware of the function being expected to run with IRQs off (to make clear that it's not a simple matter of adding preemption checks, for example).
Jan
PATCH v2 5/5 x86/iommu: disable interrupts at shutdown
In reply to Roger Pau MonneAdd a new hook to inhibit interrupt generation by the IOMMU(s). Note the hook is currently only implemented for x86 IOMMUs. The purpose is to disable interrupt generation at shutdown so any kexec chained image finds the IOMMU(s) in a quiesced state.
It would also prevent "Receive accept error" being raised as a result of non-disabled interrupts targeting offline CPUs.
---
Changes since v1:
- New in this version.
--- xen/arch/x86/crash.c | 1 + xen/arch/x86/smp.c | 1 + xen/drivers/passthrough/amd/iommu.h | 1 + xen/drivers/passthrough/amd/iommu_init.c | 17 +++++++++++++++++ xen/drivers/passthrough/amd/pci_amd_iommu.c | 1 + xen/drivers/passthrough/iommu.c | 6 ++++++ xen/drivers/passthrough/vtd/iommu.c | 19 +++++++++++++++++++ xen/include/xen/iommu.h | 3 +++ 8 files changed, 49 insertions(+)
xen/arch/x86/crash.c +1 -0
@@ -178,6 +178,7 @@ static void nmi_shootdown_cpus(void)disable_IO_APIC ();hpet_disable ();pci_disable_msi_all (); +iommu_quiesce (); } }
xen/arch/x86/smp.c +1 -0
@@ -377,6 +377,7 @@ void smp_send_stop(void)disable_IO_APIC ();hpet_disable ();pci_disable_msi_all (); +iommu_quiesce ();if (num_online_cpus () >1 ) {
xen/drivers/passthrough/amd/iommu.h +1 -0
@@ -292,6 +292,7 @@ extern unsigned long *shared_intremap_inuse; void cf_check amd_iommu_resume(void); int __must_check cf_check amd_iommu_suspend(void); void cf_check amd_iommu_crash_shutdown(void); +void cf_check amd_iommu_quiesce(void);static inline u32 get_field_from_reg_u32 (u32 reg_value,u32 mask,u32 shift) {
xen/drivers/passthrough/amd/iommu_init.c +17 -0
@@ -1611,3 +1611,20 @@ void cf_check amd_iommu_resume(void)invalidate_all_domain_pages (); } } + +void cf_check amd_iommu_quiesce(void) +{ +struct amd_iommu *iommu; + +for_each_amd_iommu ( iommu ) + { +if ( iommu->ctrl.int_cap_xt_en ) + { + iommu->ctrl.int_cap_xt_en = false; +writeq (iommu->ctrl.raw, + iommu->mmio_base +IOMMU_CONTROL_MMIO_OFFSET ); + } +else +amd_iommu_msi_enable (iommu,IOMMU_CONTROL_DISABLED ); + } +}
xen/drivers/passthrough/amd/pci_amd_iommu.c +1 -0
@@ -791,6 +791,7 @@ static const struct iommu_ops __initconst_cf_clobber _iommu_ops = { .crash_shutdown = amd_iommu_crash_shutdown, .get_reserved_device_memory = amd_iommu_get_reserved_device_memory, .dump_page_tables = amd_dump_page_tables, + .quiesce = amd_iommu_quiesce, }; static const struct iommu_init_ops __initconstrel _iommu_init_ops = {
xen/drivers/passthrough/iommu.c +6 -0
@@ -663,6 +663,12 @@ void iommu_crash_shutdown(void)#endif } +void iommu_quiesce (void ) +{ +if ( iommu_enabled ) +iommu_vcall (iommu_get_ops (), quiesce); +} +int iommu_get_reserved_device_memory (iommu_grdm_t *func,void *ctxt) {const struct iommu_ops *ops;
xen/drivers/passthrough/vtd/iommu.c +19 -0
@@ -3207,6 +3207,24 @@ static int cf_check intel_iommu_quarantine_init(struct pci_dev *pdev,return rc; } +static void cf_check vtd_quiesce(void) +{ +const struct acpi_drhd_unit *drhd; + +for_each_drhd_unit ( drhd ) + { +const struct vtd_iommu *iommu = drhd->iommu; +uint32_t sts =dmar_readl (iommu->reg,DMAR_FECTL_REG ); + +/* +* Open code dma_msi_mask() to avoid taking the spinlock which could +* deadlock if called from crash context. +*/ + sts |=DMA_FECTL_IM ; +dmar_writel (iommu->reg,DMAR_FECTL_REG , sts); + } +} + static const struct iommu_ops __initconst_cf_clobber vtd_ops = { .page_sizes =PAGE_SIZE_4K , .init = intel_iommu_domain_init,
@@ -3236,6 +3254,7 @@ static const struct iommu_ops __initconst_cf_clobber vtd_ops = { .iotlb_flush = iommu_flush_iotlb, .get_reserved_device_memory = intel_iommu_get_reserved_device_memory, .dump_page_tables = vtd_dump_page_tables, + .quiesce = vtd_quiesce, }; const struct iommu_init_ops __initconstrel intel_iommu_init_ops = {
xen/include/xen/iommu.h +3 -0
@@ -314,6 +314,8 @@ struct iommu_ops {*/ int (*dt_xlate)(device_t *dev,const struct dt_phandle_args *args);#endif +/* Inhibit all interrupt generation, to be used at shutdown. */ +void (*quiesce)(void ); };/*
@@ -404,6 +406,7 @@ static inline int iommu_do_domctl(struct xen_domctl *domctl, struct domain *d,int __must_check iommu_suspend (void );void iommu_resume (void );void iommu_crash_shutdown (void ); +void iommu_quiesce (void );int iommu_get_reserved_device_memory (iommu_grdm_t *func,void *ctxt);int iommu_quarantine_dev_init (device_t *dev);
Signature · 1 line
2.46.0
Re: [PATCH v2 5/5] x86/iommu: disable interrupts at shutdown
Quoted 2 lines · Roger Pau Monne
Add a new hook to inhibit interrupt generation by the IOMMU(s). Note the hook is currently only implemented for x86 IOMMUs.
Yet then ...
xen/drivers/passthrough/iommu.c void iommu_crash_shutdown(void) · line 670
Quoted 11 lines
xen/drivers/passthrough/iommu.c +5
-0@@ -663,6 +663,12 @@ void iommu_crash_shutdown(void)#endif } +void iommu_quiesce (void ) +{ +if ( iommu_enabled ) +iommu_vcall (iommu_get_ops (), quiesce); +}
..., with this being in common code, the function wants checking that the pointer to be called through isn't NULL.
As to the use on the crash path - iommu_crash_shutdown() was called a few lines earlier. Why would we still need iommu_quiesce() there?
Jan
Hello,
This should have had a 'for-4.20?' tag in the subject name, as otherwise we will need to add an errata to the release notes to notice that reboot can sometimes fail on AMD boxes.
Also adding Oleksii.
Thanks, Roger.
Quoted 45 lines · Roger Pau Monne
Hello,
The following series aims to prevent local APIC errors from stalling the shtudown process. On XenServer testing we have seen reports of AMD boxes sporadically getting stuck in a spam of:
APIC error on CPU0: 00(08), Receive accept error
Messages during shutdown, as a result of device interrupts targeting CPUs that are offline (and have the local APIC disabled).
First patch strictly solves the issue of shutdown getting stuck, further patches aim to quiesce interrupts from all devices (known by Xen) as an attempt to prevent a spurious "APIC error on CPU0: 00(00)" plus also make kexec more reliable.
Thanks, Roger.
Roger Pau Monne (5):
x86/shutdown: offline APs with interrupts disabled on all CPUs x86/irq: dropfixup_irqs()parameters
x86/smp: perform disabling on interrupts ahead of AP shutdown x86/pci: disable MSI(-X) on all devices at shutdown x86/iommu: disable interrupts at shutdownxen/arch/x86/crash.c | 2 ++ xen/arch/x86/include/asm/irq.h | 4 +-- xen/arch/x86/include/asm/msi.h | 1 + xen/arch/x86/irq.c | 30 ++++++++----------- xen/arch/x86/msi.c | 18 +++++++++++ xen/arch/x86/smp.c | 33 +++++++++++++++------ xen/arch/x86/smpboot.c | 2 +- xen/drivers/passthrough/amd/iommu.h | 1 + xen/drivers/passthrough/amd/iommu_init.c | 17 +++++++++++ xen/drivers/passthrough/amd/pci_amd_iommu.c | 1 + xen/drivers/passthrough/iommu.c | 6 ++++ xen/drivers/passthrough/pci.c | 33 +++++++++++++++++++++ xen/drivers/passthrough/vtd/iommu.c | 19 ++++++++++++ xen/include/xen/iommu.h | 3 ++ xen/include/xen/pci.h | 4 +++ 15 files changed, 145 insertions(+), 29 deletions(-)Signature · 1 line
2.46.0
Hello Roger,
Quoted 6 lines · Roger Pau Monné
Hello,
This should have had a 'for-4.20?' tag in the subject name, as otherwise we will need to add an errata to the release notes to notice that reboot can sometimes fail on AMD boxes.
Quoted 10 lines
Also adding Oleksii.
Thanks, Roger.
Quoted 5 lines · Roger Pau Monne
Hello,
The following series aims to prevent local APIC errors from stalling the shtudown process. On XenServer testing we have seen reports of AMD boxes sporadically getting stuck in a spam of:
How often this issue happen?
Quoted 10 lines
Quoted 10 lines
APIC error on CPU0: 00(08), Receive accept error
Messages during shutdown, as a result of device interrupts targeting CPUs that are offline (and have the local APIC disabled).
First patch strictly solves the issue of shutdown getting stuck, further patches aim to quiesce interrupts from all devices (known by Xen) as an attempt to prevent a spurious "APIC error on CPU0: 00(00)" plus also make kexec more reliable.
If the first patch solves does it make sense to consider, at least, it to be merged?
~ Oleksii
Quoted 30 lines
Quoted 30 lines
Thanks, Roger.
Roger Pau Monne (5):
x86/shutdown: offline APs with interrupts disabled on all CPUs x86/irq: dropfixup_irqs()parameters
x86/smp: perform disabling on interrupts ahead of AP shutdown x86/pci: disable MSI(-X) on all devices at shutdown x86/iommu: disable interrupts at shutdownxen/arch/x86/crash.c | 2 ++ xen/arch/x86/include/asm/irq.h | 4 +-- xen/arch/x86/include/asm/msi.h | 1 + xen/arch/x86/irq.c | 30 ++++++++----------- xen/arch/x86/msi.c | 18 +++++++++++ xen/arch/x86/smp.c | 33 +++++++++++++++------ xen/arch/x86/smpboot.c | 2 +- xen/drivers/passthrough/amd/iommu.h | 1 + xen/drivers/passthrough/amd/iommu_init.c | 17 +++++++++++ xen/drivers/passthrough/amd/pci_amd_iommu.c | 1 + xen/drivers/passthrough/iommu.c | 6 ++++ xen/drivers/passthrough/pci.c | 33 +++++++++++++++++++++ xen/drivers/passthrough/vtd/iommu.c | 19 ++++++++++++ xen/include/xen/iommu.h | 3 ++ xen/include/xen/pci.h | 4 +++ 15 files changed, 145 insertions(+), 29 deletions(-)Signature · 1 line
2.46.0
Quoted 13 lines · Oleksii Kurochko
Hello Roger,
Quoted 10 lines · Roger Pau Monné
Hello,
This should have had a 'for-4.20?' tag in the subject name, as otherwise we will need to add an errata to the release notes to notice that reboot can sometimes fail on AMD boxes.
Also adding Oleksii.
Thanks, Roger.
Quoted 8 lines
Quoted 6 lines · Roger Pau Monne
Quoted 5 lines
Hello,
The following series aims to prevent local APIC errors from stalling the shtudown process. On XenServer testing we have seen reports of AMD boxes sporadically getting stuck in a spam of:
How often this issue happen?
Hard to tell, we have certainly hit it more than once on XenRT, but I don't have figures about its probability. I have at least 14 reports from XenRT from the last 6 months, but there's possibly a lot more that could have been classified as a different kind of issue.
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
APIC error on CPU0: 00(08), Receive accept error
Messages during shutdown, as a result of device interrupts targeting CPUs that are offline (and have the local APIC disabled).
Quoted 6 lines
Quoted 4 lines
Quoted 4 lines
First patch strictly solves the issue of shutdown getting stuck, further patches aim to quiesce interrupts from all devices (known by Xen) as an attempt to prevent a spurious "APIC error on CPU0: 00(00)" plus also make kexec more reliable.
If the first patch solves does it make sense to consider, at least, it to be merged?
First one sure, the rest I think are also worth considering. They get rid of the resulting innocuous "APIC error on CPU0: 00(00)" message. Also remaining patches are likely to provide the kexec kernel with a better context, as they quiesce interrupts from devices.
I will send a new version soon, hopefully we can discuss over that one which patches we want to pick. With my XenServer hat on I plan to backport the whole series into our patch queue.
Thanks, Roger.
Quoted 17 lines · Roger Pau Monné
Quoted 16 lines · Oleksii Kurochko
Quoted 14 lines · Roger Pau Monné
This should have had a 'for-4.20?' tag in the subject name, as otherwise we will need to add an errata to the release notes to notice that reboot can sometimes fail on AMD boxes.
Also adding Oleksii.
Thanks, Roger.
Quoted 5 lines · Roger Pau Monne
Hello,
The following series aims to prevent local APIC errors from stalling the shtudown process. On XenServer testing we have seen reports of AMD boxes sporadically getting stuck in a spam of:
Quoted 6 lines
Quoted 1 line
How often this issue happen?
Hard to tell, we have certainly hit it more than once on XenRT, but I don't have figures about its probability. I have at least 14 reports from XenRT from the last 6 months, but there's possibly a lot more that could have been classified as a different kind of issue.
Our QA tells me that this is severely hindering their work.
Jan
Quoted 8 lines · Roger Pau Monne
The following series aims to prevent local APIC errors from stalling the shtudown process. On XenServer testing we have seen reports of AMD boxes sporadically getting stuck in a spam of:
APIC error on CPU0: 00(08), Receive accept error
Messages during shutdown, as a result of device interrupts targeting CPUs that are offline (and have the local APIC disabled).
One more thought here: Have you/we perhaps discovered the reason why there was that 1ms delay at the end of fixup_irqs() that was badly commented, and that you removed in e2bb28d62158 ("x86/irq: forward pending interrupts to new destination in fixup_irqs()")? May be worth mentioning that by way of a Fixes: tag.
Jan
Quoted 7 lines · Jan Beulich
Quoted 6 lines · Roger Pau Monne
The following series aims to prevent local APIC errors from stalling the shtudown process. On XenServer testing we have seen reports of AMD boxes sporadically getting stuck in a spam of:
APIC error on CPU0: 00(08), Receive accept error
Quoted 8 lines
Quoted 2 lines
Messages during shutdown, as a result of device interrupts targeting CPUs that are offline (and have the local APIC disabled).
One more thought here: Have you/we perhaps discovered the reason why there was that 1ms delay at the end of
fixup_irqs()that was badly commented, and that you removed ine2bb28d62158("x86/irq: forward pending interrupts to new destination infixup_irqs()")? May be worth mentioning that by way of a Fixes: tag.
Hm, so you think the delay was added there as a way to ensure any pending interrupts would get drained (ie: serviced) on the old target?
I'm maybe a bit confused, but I don't think the delay would help much with preventing the local APIC errors? Regardless of the wait, if the interrupts target offline CPUs there's a chance receive accept errors will be triggered on AMD.
Thanks, Roger.
Quoted 11 lines · Roger Pau Monné
Quoted 10 lines · Jan Beulich
Quoted 8 lines · Roger Pau Monne
The following series aims to prevent local APIC errors from stalling the shtudown process. On XenServer testing we have seen reports of AMD boxes sporadically getting stuck in a spam of:
APIC error on CPU0: 00(08), Receive accept error
Messages during shutdown, as a result of device interrupts targeting CPUs that are offline (and have the local APIC disabled).
Quoted 8 lines
Quoted 5 lines
One more thought here: Have you/we perhaps discovered the reason why there was that 1ms delay at the end of
fixup_irqs()that was badly commented, and that you removed ine2bb28d62158("x86/irq: forward pending interrupts to new destination infixup_irqs()")? May be worth mentioning that by way of a Fixes: tag.Hm, so you think the delay was added there as a way to ensure any pending interrupts would get drained (ie: serviced) on the old target?
So far I didn't have the slightest idea why that call had been there. This at least gives a possible reason.
Quoted 4 lines
I'm maybe a bit confused, but I don't think the delay would help much with preventing the local APIC errors? Regardless of the wait, if the interrupts target offline CPUs there's a chance receive accept errors will be triggered on AMD.
But fixup_irqs() right now runs ahead of actually offlining the APs.
Jan