Skip to content

Commit f4ffc85

Browse files
sean-jcjfvogel
authored andcommitted
iommu/vt-d: Don't clobber posted vCPU IRTE when host IRQ affinity changes
commit 688124cc541f60d26a7547f45637b23dada4e527 upstream. 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: [email protected] Cc: Thomas Gleixner <[email protected]> Cc: Jacob Pan <[email protected]> Signed-off-by: Sean Christopherson <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Lu Baolu <[email protected]> Signed-off-by: Joerg Roedel <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]> (cherry picked from commit e953e11123aa703241418ee69a82e5538e58eaff) Signed-off-by: Jack Vogel <[email protected]>
1 parent 4ae13c2 commit f4ffc85

File tree

1 file changed

+15
-10
lines changed

1 file changed

+15
-10
lines changed

drivers/iommu/intel/irq_remapping.c

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,6 @@
2626
#include "../iommu-pages.h"
2727
#include "cap_audit.h"
2828

29-
enum irq_mode {
30-
IRQ_REMAPPING,
31-
IRQ_POSTING,
32-
};
33-
3429
struct ioapic_scope {
3530
struct intel_iommu *iommu;
3631
unsigned int id;
@@ -50,8 +45,8 @@ struct irq_2_iommu {
5045
u16 irte_index;
5146
u16 sub_handle;
5247
u8 irte_mask;
53-
enum irq_mode mode;
5448
bool posted_msi;
49+
bool posted_vcpu;
5550
};
5651

5752
struct intel_ir_data {
@@ -139,7 +134,6 @@ static int alloc_irte(struct intel_iommu *iommu,
139134
irq_iommu->irte_index = index;
140135
irq_iommu->sub_handle = 0;
141136
irq_iommu->irte_mask = mask;
142-
irq_iommu->mode = IRQ_REMAPPING;
143137
}
144138
raw_spin_unlock_irqrestore(&irq_2_ir_lock, flags);
145139

@@ -194,8 +188,6 @@ static int modify_irte(struct irq_2_iommu *irq_iommu,
194188

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

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

201193
return rc;
@@ -1177,9 +1169,18 @@ static void __intel_ir_reconfigure_irte(struct irq_data *irqd, bool force_host)
11771169
{
11781170
struct intel_ir_data *ir_data = irqd->chip_data;
11791171

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

@@ -1274,6 +1275,7 @@ static int intel_ir_set_vcpu_affinity(struct irq_data *data, void *info)
12741275
irte_pi.pda_h = (vcpu_pi_info->pi_desc_addr >> 32) &
12751276
~(-1UL << PDA_HIGH_BIT);
12761277

1278+
ir_data->irq_2_iommu.posted_vcpu = true;
12771279
modify_irte(&ir_data->irq_2_iommu, &irte_pi);
12781280
}
12791281

@@ -1501,6 +1503,9 @@ static void intel_irq_remapping_deactivate(struct irq_domain *domain,
15011503
struct intel_ir_data *data = irq_data->chip_data;
15021504
struct irte entry;
15031505

1506+
WARN_ON_ONCE(data->irq_2_iommu.posted_vcpu);
1507+
data->irq_2_iommu.posted_vcpu = false;
1508+
15041509
memset(&entry, 0, sizeof(entry));
15051510
modify_irte(&data->irq_2_iommu, &entry);
15061511
}

0 commit comments

Comments
 (0)