iommu/amd: Prevent spurious IRQ disable on high-rate GALog MSIs
Subsystems (3)
PATCH 1/1 iommu/amd: Prevent spurious IRQ disable on high-rate GALog MSIs
On AMD EPYC (Turin) hosts with AVIC enabled, passed-through SR-IOV VFs in KVM guests log interrupts targeting non-running vCPUs into the IOMMU Guest Virtual APIC Log (GALog) ring buffer and signal the host via an edge-triggered IntCapXT MSI (AMD-Vi*-GA).
Both __iommu_setup_intcapxt() and iommu_setup_msi() register their handlers via request_threaded_irq(..., NULL, thread_fn, IRQF_ONESHOT, ...), using irq_default_primary_handler() (which returns IRQ_WAKE_THREAD), while intcapxt_irqdomain_alloc() sets handle_edge_irq which does not mask edge-triggered MSIs during oneshot thread execution.
Previously, amd_iommu_handle_irq() cleared MMIO_STATUS_OFFSET at the top of the while (status & mask) loop before calling int_handler(iommu) (iommu_poll_ga_log()). Under overcommitted multi-VM TCP_RR workloads (1,000 to 10,000 flows across 4-8 VMs with vCPU overcommit), new VF interrupts for non-running vCPUs arrive while iommu_poll_ga_log() is draining the ring buffer, causing GALogInt to transition 0 -> 1 and fire additional hardware edge MSIs while the IRQ thread is still inside amd_iommu_handle_irq(). Because desc->threads_handled only increments in irq_thread_fn() after action->thread_fn() returns, note_interrupt() (kernel/irq/spurious.c) accounts every intermediate edge MSI as IRQ_NONE (desc->irqs_unhandled++). Once desc->irqs_unhandled exceeds 99,900 out of 100,000 interrupts, __report_bad_irq() logs "irq <N>: nobody cared" and permanently disables the IOMMU GALog IRQ, breaking guest VF MSI-X wakeups.
Fix this in two ways:
1. Drain the log ring buffer via int_handler(iommu) before writing status & mask to MMIO_STATUS_OFFSET (clearing only the status bits observed set so a concurrent overflow bit is never cleared without running overflow_handler()), followed by a post-clear poll pass so entries written before the status clear took effect are processed without generating redundant edge MSIs or leaving entries stranded.
2. Set IRQ_IS_POLLED on the AMD-Vi MSI and IntCapXT IRQs (clearing it on request_threaded_irq() failure paths) so note_interrupt() never spuriously disables the dedicated IOMMU event/PPR/GALog IRQ lines under sustained high-rate edge MSI bursts.
Discovered in production testing on AMD EPYC (Turin) hosts running multi-VM KVM guests with passed-through SR-IOV VFs where the host permanently disabled AMD-Vi-GA under heavy TCP_RR traffic, and verified on the same AMD EPYC (Turin) hardware across 4-VM and 8-VM SR-IOV VF test suites.
--- drivers/iommu/amd/init.c | 4 ++++ drivers/iommu/amd/iommu.c | 13 ++++++++++--- 2 files changed, 14 insertions(+), 3 deletions(-)
drivers/iommu/amd/init.c +4 -0
@@ -2404,9 +2404,11 @@ static int iommu_setup_msi(struct amd_iommu *iommu)if (r)return r; +irq_set_status_flags (iommu->dev->irq,IRQ_IS_POLLED ); r =request_threaded_irq (iommu->dev->irq,NULL , amd_iommu_int_thread,IRQF_ONESHOT ,"AMD-Vi" , iommu);if (r) { +irq_clear_status_flags (iommu->dev->irq,IRQ_IS_POLLED );pci_disable_msi (iommu->dev);return r; }
@@ -2579,9 +2581,11 @@ static int __iommu_setup_intcapxt(struct amd_iommu *iommu, const char *devname,return irq; } +irq_set_status_flags (irq,IRQ_IS_POLLED ); ret =request_threaded_irq (irq,NULL , thread_fn,IRQF_ONESHOT , devname, iommu);if (ret) { +irq_clear_status_flags (irq,IRQ_IS_POLLED );irq_domain_free_irqs (irq,1 );irq_domain_remove (domain);return ret;
drivers/iommu/amd/iommu.c +10 -3
@@ -1112,9 +1112,6 @@ static void amd_iommu_handle_irq(void *data, const char *evt_type,u32 mask = int_mask | overflow_mask;while (status & mask) { -/* Enable interrupt sources again */ -writel (mask, iommu->mmio_base +MMIO_STATUS_OFFSET ); -if (int_handler) {pr_devel ("Processing IOMMU (ivhd%d) %s Log\n" , iommu->index, evt_type);
@@ -1124,6 +1121,16 @@ static void amd_iommu_handle_irq(void *data, const char *evt_type,if ((status & overflow_mask) && overflow_handler)overflow_handler (iommu); +/* +* Clear only the status bits observed above, then poll once +* more so entries written before the clear took effect are not +* left unprocessed with the interrupt status bit cleared. +*/ +writel (status & mask, iommu->mmio_base +MMIO_STATUS_OFFSET ); + +if (int_handler) +int_handler (iommu); +/* * Hardware bug: ERBT1312 * When re-enabling interrupt (by writing 1
base-commit: 4dd16e31135ea8437a720222df34e8745f385d6d
Signature · 1 line
2.56.0.385.gac671c819a-goog
Quoted 112 lines · Mina Almasry
On AMD EPYC (Turin) hosts with AVIC enabled, passed-through SR-IOV VFs in KVM guests log interrupts targeting non-running vCPUs into the IOMMU Guest Virtual APIC Log (GALog) ring buffer and signal the host via an edge-triggered IntCapXT MSI (AMD-Vi*-GA).
Both
__iommu_setup_intcapxt()andiommu_setup_msi()register their handlers viarequest_threaded_irq(..., NULL, thread_fn, IRQF_ONESHOT, ...), usingirq_default_primary_handler()(which returnsIRQ_WAKE_THREAD), whileintcapxt_irqdomain_alloc()setshandle_edge_irqwhich does not mask edge-triggered MSIs during oneshot thread execution.Previously,
amd_iommu_handle_irq()clearedMMIO_STATUS_OFFSETat the top of the while (status & mask) loop before callingint_handler(iommu)(iommu_poll_ga_log()). Under overcommitted multi-VMTCP_RRworkloads (1,000 to 10,000 flows across 4-8 VMs with vCPU overcommit), new VF interrupts for non-running vCPUs arrive whileiommu_poll_ga_log()is draining the ring buffer, causing GALogInt to transition 0 -> 1 and fire additional hardware edge MSIs while the IRQ thread is still insideamd_iommu_handle_irq(). Becausedesc->threads_handledonly increments inirq_thread_fn()afteraction->thread_fn()returns,note_interrupt()(kernel/irq/spurious.c) accounts every intermediate edge MSI asIRQ_NONE(desc->irqs_unhandled++). Oncedesc->irqs_unhandledexceeds 99,900 out of 100,000 interrupts,__report_bad_irq()logs "irq <N>: nobody cared" and permanently disables the IOMMU GALog IRQ, breaking guest VF MSI-X wakeups.Fix this in two ways:
1. Drain the log ring buffer viaint_handler(iommu)before writing status & mask toMMIO_STATUS_OFFSET(clearing only the status bits observed set so a concurrent overflow bit is never cleared without runningoverflow_handler()), followed by a post-clear poll pass so entries written before the status clear took effect are processed without generating redundant edge MSIs or leaving entries stranded.
2. SetIRQ_IS_POLLEDon the AMD-Vi MSI and IntCapXT IRQs (clearing it onrequest_threaded_irq()failure paths) sonote_interrupt()never spuriously disables the dedicated IOMMU event/PPR/GALog IRQ lines under sustained high-rate edge MSI bursts.Discovered in production testing on AMD EPYC (Turin) hosts running multi-VM KVM guests with passed-through SR-IOV VFs where the host permanently disabled AMD-Vi-GA under heavy
TCP_RRtraffic, and verified on the same AMD EPYC (Turin) hardware across 4-VM and 8-VM SR-IOV VF test suites.Fixes 2379f3485239 ("iommu/amd: Refactor IOMMU interrupt handling logic for Event, PPR, and GA logs")Signed-off-by Mina Almasry <[email protected]>--- drivers/iommu/amd/init.c | 4 ++++ drivers/iommu/amd/iommu.c | 13 ++++++++++--- 2 files changed, 14 insertions(+), 3 deletions(-)drivers/iommu/amd/init.c +4
-0@@ -2404,9 +2404,11 @@ static int iommu_setup_msi(struct amd_iommu *iommu)if (r)return r; +irq_set_status_flags (iommu->dev->irq,IRQ_IS_POLLED ); r =request_threaded_irq (iommu->dev->irq,NULL , amd_iommu_int_thread,IRQF_ONESHOT ,"AMD-Vi" , iommu);if (r) { +irq_clear_status_flags (iommu->dev->irq,IRQ_IS_POLLED );pci_disable_msi (iommu->dev);return r; }@@ -2579,9 +2581,11 @@ static int __iommu_setup_intcapxt(struct amd_iommu *iommu, const char *devname,return irq; } +irq_set_status_flags (irq,IRQ_IS_POLLED ); ret =request_threaded_irq (irq,NULL , thread_fn,IRQF_ONESHOT , devname, iommu);if (ret) { +irq_clear_status_flags (irq,IRQ_IS_POLLED );irq_domain_free_irqs (irq,1 );irq_domain_remove (domain);return ret;drivers/iommu/amd/iommu.c +10
-3@@ -1112,9 +1112,6 @@ static void amd_iommu_handle_irq(void *data, const char *evt_type,u32 mask = int_mask | overflow_mask;while (status & mask) { -/* Enable interrupt sources again */ -writel (mask, iommu->mmio_base +MMIO_STATUS_OFFSET ); -if (int_handler) {pr_devel ("Processing IOMMU (ivhd%d) %s Log\n" , iommu->index, evt_type);@@ -1124,6 +1121,16 @@ static void amd_iommu_handle_irq(void *data, const char *evt_type,if ((status & overflow_mask) && overflow_handler)overflow_handler (iommu); +/* +* Clear only the status bits observed above, then poll once +* more so entries written before the clear took effect are not +* left unprocessed with the interrupt status bit cleared. +*/ +writel (status & mask, iommu->mmio_base +MMIO_STATUS_OFFSET ); + +if (int_handler) +int_handler (iommu); +/* * Hardware bug: ERBT1312 * When re-enabling interrupt (by writing 1
Quoted 1 line
base-commit:
4dd16e31135ea8437a720222df34e8745f385d6d
Hi Mina,
I think marking IRQ_IS_POLLED seems like a bad work around, IRQ_IS_POLLED is used for fake/software irqs and I dont think it is right way to use it for the hardware IRQ.
Additionally, code movement in the iommu.c seems redundant and does not provide any real benefit. we will encounter following condition again, this time while calling int_handler() for second time
Quoted 4 lines
interrupts for non-running vCPUs arrive while
iommu_poll_ga_log()is draining the ring buffer, causing GALogInt to transition 0 -> 1 and fire additional hardware edge MSIs while the IRQ thread is still insideamd_iommu_handle_irq()
The read from status bit will cause handler to keep running without incrementing threads_handled.
We also encountered same issue recently, I think right way to fix is to address the underlying root cause -->
1. GALOG is a circular buffer and any new entries created by the IOMMU can be handled in a single interrupt.
2. In an high interrupt rate environment The ga-log handler keeps looping without incrementing threads_handled.
3. This causes note_interrupt to disable irq since it thinks that handler is stuck.
The solution that I had in mind (not sure if its a right way) is to break the while loop inside amd_iommu_handle_irq() after certain number of iterations.
This works because.
1. We enable the interrupts before processing the entries
2. Any new interrupts that arrive during the entry processing will set IRQTF_RUNTHREAD.
3. If we break the loop after that, the irq_thread_fn() will increment threads_handled.
4. And irq_wait_for_interrupt() will return true because it sees IRQTF_RUNTHREAD and irq_thread() will call the handler again.
Although I am not sure what should be a right value for number of iterations, the initial tests with 10000 iterations resolves this issue but increases the interrupt latency.
Thanks
Sairaj
Vasant Hegde
maintainerMina, Sairaj,
Quoted 12 lines · Sairaj Kodilkar
Quoted 11 lines · Mina Almasry
On AMD EPYC (Turin) hosts with AVIC enabled, passed-through SR-IOV VFs in KVM guests log interrupts targeting non-running vCPUs into the IOMMU Guest Virtual APIC Log (GALog) ring buffer and signal the host via an edge-triggered IntCapXT MSI (AMD-Vi*-GA).
Both
__iommu_setup_intcapxt()andiommu_setup_msi()register their handlers viarequest_threaded_irq(..., NULL, thread_fn, IRQF_ONESHOT, ...), usingirq_default_primary_handler()(which returnsIRQ_WAKE_THREAD), whileintcapxt_irqdomain_alloc()setshandle_edge_irqwhich does not mask edge-triggered MSIs during oneshot thread execution.
Quoted 14 lines
Quoted 6 lines
Previously,
amd_iommu_handle_irq()clearedMMIO_STATUS_OFFSETat the top of the while (status & mask) loop before callingint_handler(iommu)(iommu_poll_ga_log()). Under overcommitted multi-VMTCP_RRworkloads (1,000 to 10,000 flows across 4-8 VMs with vCPU overcommit), new VF interrupts for non-running vCPUs arrive whileiommu_poll_ga_log()is draining the ring buffer, causing GALogInt to transition 0 -> 1 and fireQuoted 8 lines
additional hardware edge MSIs while the IRQ thread is still inside
amd_iommu_handle_irq(). Becausedesc->threads_handledonly increments inirq_thread_fn()afteraction->thread_fn()returns,note_interrupt()(kernel/irq/spurious.c) accounts every intermediate edge MSI asIRQ_NONE(desc->irqs_unhandled++). Oncedesc->irqs_unhandledexceeds 99,900 out of 100,000 interrupts,__report_bad_irq()logs "irq <N>: nobody cared" and permanently disables the IOMMU GALog IRQ, breaking guest VF MSI-X wakeups.
.../...
Quoted 23 lines
We also encountered same issue recently, I think right way to fix is to address the underlying root cause -->
1. GALOG is a circular buffer and any new entries created by the IOMMU can be handled in a single interrupt.
2. In an high interrupt rate environment The ga-log handler keeps looping without incrementingthreads_handled.
3. This causesnote_interruptto disable irq since it thinks that handler is stuck.The solution that I had in mind (not sure if its a right way) is to break the while loop inside
amd_iommu_handle_irq()after certain number of iterations.This works because.
1. We enable the interrupts before processing the entries
2. Any new interrupts that arrive during the entry processing will setIRQTF_RUNTHREAD.
3. If we break the loop after that, theirq_thread_fn()will incrementthreads_handled.
4. Andirq_wait_for_interrupt()will return true because it seesIRQTF_RUNTHREADandirq_thread()will call the handler again.
Quoted 3 lines
Although I am not sure what should be a right value for number of iterations, the initial tests with 10000 iterations resolves this issue but increases the interrupt latency.
I did look into errata, spec and kernel change history.
Orignnial commit: d3263bc29706 iommu/amd: Workaround for ERBT1312 (Joerg) never had continuous loop issue.
Later Commit 3f398bc7762a iommu/AMD: Per-thread IOMMU Interrupt Handling (Suravee) introduced this continuous loop issue.
Of course we have bunch of follow up patches which tried to improve interrupt handler path.
Looking into the errata, looks like its with MSI Interrupt generation mode only. I don' think newer INTCAPX (x2apic mode) has this issue (I will double check with HW folks).
So IOMMU is configured with x2apic interrupt mode, then I am tempted to break this continuous loop. Other option is to wait until interrupt bit like GAInt becomes zero. But in stressed environment this may result in overflow issue.
@Sairaj, Can you try above approach and see if that works?
-Vasant