Skip to content

Commit 688124c

Browse files
sean-jcjoergroedel
authored andcommitted
iommu/vt-d: Don't clobber posted vCPU IRTE when host IRQ affinity changes
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: ed1e48e ("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> Link: https://lore.kernel.org/r/20250315025135.2365846-3-seanjc@google.com Signed-off-by: Lu Baolu <baolu.lu@linux.intel.com> Signed-off-by: Joerg Roedel <jroedel@suse.de>
1 parent 2454823 commit 688124c

File tree

1 file changed

+15
-10
lines changed

1 file changed

+15
-10
lines changed

drivers/iommu/intel/irq_remapping.c

+15-10
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,6 @@
2525
#include "../irq_remapping.h"
2626
#include "../iommu-pages.h"
2727

28-
enum irq_mode {
29-
IRQ_REMAPPING,
30-
IRQ_POSTING,
31-
};
32-
3328
struct ioapic_scope {
3429
struct intel_iommu *iommu;
3530
unsigned int id;
@@ -49,8 +44,8 @@ struct irq_2_iommu {
4944
u16 irte_index;
5045
u16 sub_handle;
5146
u8 irte_mask;
52-
enum irq_mode mode;
5347
bool posted_msi;
48+
bool posted_vcpu;
5449
};
5550

5651
struct intel_ir_data {
@@ -138,7 +133,6 @@ static int alloc_irte(struct intel_iommu *iommu,
138133
irq_iommu->irte_index = index;
139134
irq_iommu->sub_handle = 0;
140135
irq_iommu->irte_mask = mask;
141-
irq_iommu->mode = IRQ_REMAPPING;
142136
}
143137
raw_spin_unlock_irqrestore(&irq_2_ir_lock, flags);
144138

@@ -193,8 +187,6 @@ static int modify_irte(struct irq_2_iommu *irq_iommu,
193187

194188
rc = qi_flush_iec(iommu, index, 0);
195189

196-
/* Update iommu mode according to the IRTE mode */
197-
irq_iommu->mode = irte->pst ? IRQ_POSTING : IRQ_REMAPPING;
198190
raw_spin_unlock_irqrestore(&irq_2_ir_lock, flags);
199191

200192
return rc;
@@ -1173,9 +1165,18 @@ static void __intel_ir_reconfigure_irte(struct irq_data *irqd, bool force_host)
11731165
{
11741166
struct intel_ir_data *ir_data = irqd->chip_data;
11751167

1168+
/*
1169+
* Don't modify IRTEs for IRQs that are being posted to vCPUs if the
1170+
* host CPU affinity changes.
1171+
*/
1172+
if (ir_data->irq_2_iommu.posted_vcpu && !force_host)
1173+
return;
1174+
1175+
ir_data->irq_2_iommu.posted_vcpu = false;
1176+
11761177
if (ir_data->irq_2_iommu.posted_msi)
11771178
intel_ir_reconfigure_irte_posted(irqd);
1178-
else if (force_host || ir_data->irq_2_iommu.mode == IRQ_REMAPPING)
1179+
else
11791180
modify_irte(&ir_data->irq_2_iommu, &ir_data->irte_entry);
11801181
}
11811182

@@ -1270,6 +1271,7 @@ static int intel_ir_set_vcpu_affinity(struct irq_data *data, void *info)
12701271
irte_pi.pda_h = (vcpu_pi_info->pi_desc_addr >> 32) &
12711272
~(-1UL << PDA_HIGH_BIT);
12721273

1274+
ir_data->irq_2_iommu.posted_vcpu = true;
12731275
modify_irte(&ir_data->irq_2_iommu, &irte_pi);
12741276
}
12751277

@@ -1496,6 +1498,9 @@ static void intel_irq_remapping_deactivate(struct irq_domain *domain,
14961498
struct intel_ir_data *data = irq_data->chip_data;
14971499
struct irte entry;
14981500

1501+
WARN_ON_ONCE(data->irq_2_iommu.posted_vcpu);
1502+
data->irq_2_iommu.posted_vcpu = false;
1503+
14991504
memset(&entry, 0, sizeof(entry));
15001505
modify_irte(&data->irq_2_iommu, &entry);
15011506
}

0 commit comments

Comments
 (0)