* [PATCH 0/2] iommu/vt-d: Fix posted vCPU vs. posted MSI bugs
@ 2025-03-15 2:51 Sean Christopherson
2025-03-15 2:51 ` [PATCH 1/2] iommu/vt-d: Put IRTE back into posted MSI mode if vCPU posting is disabled Sean Christopherson
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Sean Christopherson @ 2025-03-15 2:51 UTC (permalink / raw)
To: David Woodhouse, Lu Baolu
Cc: iommu, linux-kernel, Thomas Gleixner, Jacob Pan,
Sean Christopherson
Fix bugs where using posted MSIs will clobber IRTEs that are configured to
post IRQs to a vCPU, and where undoing vCPU posting fails to put the IRTE
backing into posted MSI mode.
Sean Christopherson (2):
iommu/vt-d: Put IRTE back into posted MSI mode if vCPU posting is
disabled
iommu/vt-d: Don't clobber posted vCPU IRTE when host IRQ affinity
changes
drivers/iommu/intel/irq_remapping.c | 42 ++++++++++++++++++-----------
1 file changed, 27 insertions(+), 15 deletions(-)
base-commit: ea9bd29a9c0d757b3384ae3e633e6bbaddf00725
--
2.49.0.rc1.451.g8f38331e32-goog
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH 1/2] iommu/vt-d: Put IRTE back into posted MSI mode if vCPU posting is disabled
2025-03-15 2:51 [PATCH 0/2] iommu/vt-d: Fix posted vCPU vs. posted MSI bugs Sean Christopherson
@ 2025-03-15 2:51 ` Sean Christopherson
2025-03-15 2:51 ` [PATCH 2/2] iommu/vt-d: Don't clobber posted vCPU IRTE when host IRQ affinity changes Sean Christopherson
2025-03-19 1:57 ` [PATCH 0/2] iommu/vt-d: Fix posted vCPU vs. posted MSI bugs Baolu Lu
2 siblings, 0 replies; 4+ messages in thread
From: Sean Christopherson @ 2025-03-15 2:51 UTC (permalink / raw)
To: David Woodhouse, Lu Baolu
Cc: iommu, linux-kernel, Thomas Gleixner, Jacob Pan,
Sean Christopherson
Add a helper to take care of reconfiguring an IRTE to deliver IRQs to the
host, i.e. not to a vCPU, and use the helper when an IRTE's vCPU affinity
is nullified, i.e. when KVM puts an IRTE back into "host" mode. Because
posted MSIs use an ephemeral IRTE, using modify_irte() puts the IRTE into
full remapped mode, i.e. unintentionally disables posted MSIs on the IRQ.
Fixes: ed1e48ea4370 ("iommu/vt-d: Enable posted mode for device MSIs")
Cc: stable@vger.kernel.org
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Jacob Pan <jacob.jun.pan@linux.intel.com>
Signed-off-by: Sean Christopherson <seanjc@google.com>
---
drivers/iommu/intel/irq_remapping.c | 19 +++++++++++++------
1 file changed, 13 insertions(+), 6 deletions(-)
diff --git a/drivers/iommu/intel/irq_remapping.c b/drivers/iommu/intel/irq_remapping.c
index ad795c772f21..c495b533103f 100644
--- a/drivers/iommu/intel/irq_remapping.c
+++ b/drivers/iommu/intel/irq_remapping.c
@@ -1169,7 +1169,17 @@ static void intel_ir_reconfigure_irte_posted(struct irq_data *irqd)
static inline void intel_ir_reconfigure_irte_posted(struct irq_data *irqd) {}
#endif
-static void intel_ir_reconfigure_irte(struct irq_data *irqd, bool force)
+static void __intel_ir_reconfigure_irte(struct irq_data *irqd, bool force_host)
+{
+ struct intel_ir_data *ir_data = irqd->chip_data;
+
+ if (ir_data->irq_2_iommu.posted_msi)
+ intel_ir_reconfigure_irte_posted(irqd);
+ else if (force_host || ir_data->irq_2_iommu.mode == IRQ_REMAPPING)
+ modify_irte(&ir_data->irq_2_iommu, &ir_data->irte_entry);
+}
+
+static void intel_ir_reconfigure_irte(struct irq_data *irqd, bool force_host)
{
struct intel_ir_data *ir_data = irqd->chip_data;
struct irte *irte = &ir_data->irte_entry;
@@ -1182,10 +1192,7 @@ static void intel_ir_reconfigure_irte(struct irq_data *irqd, bool force)
irte->vector = cfg->vector;
irte->dest_id = IRTE_DEST(cfg->dest_apicid);
- if (ir_data->irq_2_iommu.posted_msi)
- intel_ir_reconfigure_irte_posted(irqd);
- else if (force || ir_data->irq_2_iommu.mode == IRQ_REMAPPING)
- modify_irte(&ir_data->irq_2_iommu, irte);
+ __intel_ir_reconfigure_irte(irqd, force_host);
}
/*
@@ -1240,7 +1247,7 @@ static int intel_ir_set_vcpu_affinity(struct irq_data *data, void *info)
/* stop posting interrupts, back to the default mode */
if (!vcpu_pi_info) {
- modify_irte(&ir_data->irq_2_iommu, &ir_data->irte_entry);
+ __intel_ir_reconfigure_irte(data, true);
} else {
struct irte irte_pi;
--
2.49.0.rc1.451.g8f38331e32-goog
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH 2/2] iommu/vt-d: Don't clobber posted vCPU IRTE when host IRQ affinity changes
2025-03-15 2:51 [PATCH 0/2] iommu/vt-d: Fix posted vCPU vs. posted MSI bugs Sean Christopherson
2025-03-15 2:51 ` [PATCH 1/2] iommu/vt-d: Put IRTE back into posted MSI mode if vCPU posting is disabled Sean Christopherson
@ 2025-03-15 2:51 ` Sean Christopherson
2025-03-19 1:57 ` [PATCH 0/2] iommu/vt-d: Fix posted vCPU vs. posted MSI bugs Baolu Lu
2 siblings, 0 replies; 4+ messages in thread
From: Sean Christopherson @ 2025-03-15 2:51 UTC (permalink / raw)
To: David Woodhouse, Lu Baolu
Cc: iommu, linux-kernel, Thomas Gleixner, Jacob Pan,
Sean Christopherson
Don't overwrite an IRTE that is posting IRQs to a vCPU with a posted MSI
entry if the host IRQ affinity happens to change. If/when the IRTE is
reverted back to "host mode", it will be reconfigured as a posted MSI or
remapped entry as appropriate.
Drop the "mode" field, which doesn't differentiate between posted MSIs and
posted vCPUs, in favor of a dedicated posted_vcpu flag. Note! The two
posted_{msi,vcpu} flags are intentionally not mutually exclusive; an IRTE
can transition between posted MSI and posted vCPU.
Fixes: ed1e48ea4370 ("iommu/vt-d: Enable posted mode for device MSIs")
Cc: stable@vger.kernel.org
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Jacob Pan <jacob.jun.pan@linux.intel.com>
Signed-off-by: Sean Christopherson <seanjc@google.com>
---
drivers/iommu/intel/irq_remapping.c | 25 +++++++++++++++----------
1 file changed, 15 insertions(+), 10 deletions(-)
diff --git a/drivers/iommu/intel/irq_remapping.c b/drivers/iommu/intel/irq_remapping.c
index c495b533103f..ea3ca5203919 100644
--- a/drivers/iommu/intel/irq_remapping.c
+++ b/drivers/iommu/intel/irq_remapping.c
@@ -25,11 +25,6 @@
#include "../irq_remapping.h"
#include "../iommu-pages.h"
-enum irq_mode {
- IRQ_REMAPPING,
- IRQ_POSTING,
-};
-
struct ioapic_scope {
struct intel_iommu *iommu;
unsigned int id;
@@ -49,8 +44,8 @@ struct irq_2_iommu {
u16 irte_index;
u16 sub_handle;
u8 irte_mask;
- enum irq_mode mode;
bool posted_msi;
+ bool posted_vcpu;
};
struct intel_ir_data {
@@ -138,7 +133,6 @@ static int alloc_irte(struct intel_iommu *iommu,
irq_iommu->irte_index = index;
irq_iommu->sub_handle = 0;
irq_iommu->irte_mask = mask;
- irq_iommu->mode = IRQ_REMAPPING;
}
raw_spin_unlock_irqrestore(&irq_2_ir_lock, flags);
@@ -193,8 +187,6 @@ static int modify_irte(struct irq_2_iommu *irq_iommu,
rc = qi_flush_iec(iommu, index, 0);
- /* Update iommu mode according to the IRTE mode */
- irq_iommu->mode = irte->pst ? IRQ_POSTING : IRQ_REMAPPING;
raw_spin_unlock_irqrestore(&irq_2_ir_lock, flags);
return rc;
@@ -1173,9 +1165,18 @@ static void __intel_ir_reconfigure_irte(struct irq_data *irqd, bool force_host)
{
struct intel_ir_data *ir_data = irqd->chip_data;
+ /*
+ * Don't modify IRTEs for IRQs that are being posted to vCPUs if the
+ * host CPU affinity changes.
+ */
+ if (ir_data->irq_2_iommu.posted_vcpu && !force_host)
+ return;
+
+ ir_data->irq_2_iommu.posted_vcpu = false;
+
if (ir_data->irq_2_iommu.posted_msi)
intel_ir_reconfigure_irte_posted(irqd);
- else if (force_host || ir_data->irq_2_iommu.mode == IRQ_REMAPPING)
+ else
modify_irte(&ir_data->irq_2_iommu, &ir_data->irte_entry);
}
@@ -1270,6 +1271,7 @@ static int intel_ir_set_vcpu_affinity(struct irq_data *data, void *info)
irte_pi.pda_h = (vcpu_pi_info->pi_desc_addr >> 32) &
~(-1UL << PDA_HIGH_BIT);
+ ir_data->irq_2_iommu.posted_vcpu = true;
modify_irte(&ir_data->irq_2_iommu, &irte_pi);
}
@@ -1496,6 +1498,9 @@ static void intel_irq_remapping_deactivate(struct irq_domain *domain,
struct intel_ir_data *data = irq_data->chip_data;
struct irte entry;
+ WARN_ON_ONCE(data->irq_2_iommu.posted_vcpu);
+ data->irq_2_iommu.posted_vcpu = false;
+
memset(&entry, 0, sizeof(entry));
modify_irte(&data->irq_2_iommu, &entry);
}
--
2.49.0.rc1.451.g8f38331e32-goog
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH 0/2] iommu/vt-d: Fix posted vCPU vs. posted MSI bugs
2025-03-15 2:51 [PATCH 0/2] iommu/vt-d: Fix posted vCPU vs. posted MSI bugs Sean Christopherson
2025-03-15 2:51 ` [PATCH 1/2] iommu/vt-d: Put IRTE back into posted MSI mode if vCPU posting is disabled Sean Christopherson
2025-03-15 2:51 ` [PATCH 2/2] iommu/vt-d: Don't clobber posted vCPU IRTE when host IRQ affinity changes Sean Christopherson
@ 2025-03-19 1:57 ` Baolu Lu
2 siblings, 0 replies; 4+ messages in thread
From: Baolu Lu @ 2025-03-19 1:57 UTC (permalink / raw)
To: Sean Christopherson, David Woodhouse
Cc: iommu, linux-kernel, Thomas Gleixner, Jacob Pan
On 3/15/25 10:51, Sean Christopherson wrote:
> Fix bugs where using posted MSIs will clobber IRTEs that are configured to
> post IRQs to a vCPU, and where undoing vCPU posting fails to put the IRTE
> backing into posted MSI mode.
>
> Sean Christopherson (2):
> iommu/vt-d: Put IRTE back into posted MSI mode if vCPU posting is
> disabled
> iommu/vt-d: Don't clobber posted vCPU IRTE when host IRQ affinity
> changes
Queued these two patches for the iommu tree. Thank you!
Thanks,
baolu
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2025-03-19 2:00 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-03-15 2:51 [PATCH 0/2] iommu/vt-d: Fix posted vCPU vs. posted MSI bugs Sean Christopherson
2025-03-15 2:51 ` [PATCH 1/2] iommu/vt-d: Put IRTE back into posted MSI mode if vCPU posting is disabled Sean Christopherson
2025-03-15 2:51 ` [PATCH 2/2] iommu/vt-d: Don't clobber posted vCPU IRTE when host IRQ affinity changes Sean Christopherson
2025-03-19 1:57 ` [PATCH 0/2] iommu/vt-d: Fix posted vCPU vs. posted MSI bugs Baolu Lu
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox