Skip to content

Commit e52d58d

Browse files
ssuthiku-amdjoergroedel
authored andcommitted
iommu/amd: Use cmpxchg_double() when updating 128-bit IRTE
When using 128-bit interrupt-remapping table entry (IRTE) (a.k.a GA mode), current driver disables interrupt remapping when it updates the IRTE so that the upper and lower 64-bit values can be updated safely. However, this creates a small window, where the interrupt could arrive and result in IO_PAGE_FAULT (for interrupt) as shown below. IOMMU Driver Device IRQ ============ =========== irte.RemapEn=0 ... change IRTE IRQ from device ==> IO_PAGE_FAULT !! ... irte.RemapEn=1 This scenario has been observed when changing irq affinity on a system running I/O-intensive workload, in which the destination APIC ID in the IRTE is updated. Instead, use cmpxchg_double() to update the 128-bit IRTE at once without disabling the interrupt remapping. However, this means several features, which require GA (128-bit IRTE) support will also be affected if cmpxchg16b is not supported (which is unprecedented for AMD processors w/ IOMMU). Fixes: 880ac60 ("iommu/amd: Introduce interrupt remapping ops structure") Reported-by: Sean Osborne <sean.m.osborne@oracle.com> Signed-off-by: Suravee Suthikulpanit <suravee.suthikulpanit@amd.com> Tested-by: Erik Rockstrom <erik.rockstrom@oracle.com> Reviewed-by: Joao Martins <joao.m.martins@oracle.com> Link: https://lore.kernel.org/r/20200903093822.52012-3-suravee.suthikulpanit@amd.com Signed-off-by: Joerg Roedel <jroedel@suse.de>
1 parent 26e495f commit e52d58d

File tree

3 files changed

+33
-7
lines changed

3 files changed

+33
-7
lines changed

drivers/iommu/amd/Kconfig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ config AMD_IOMMU
1010
select IOMMU_API
1111
select IOMMU_IOVA
1212
select IOMMU_DMA
13-
depends on X86_64 && PCI && ACPI
13+
depends on X86_64 && PCI && ACPI && HAVE_CMPXCHG_DOUBLE
1414
help
1515
With this option you can enable support for AMD IOMMU hardware in
1616
your system. An IOMMU is a hardware component which provides

drivers/iommu/amd/init.c

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1511,7 +1511,14 @@ static int __init init_iommu_one(struct amd_iommu *iommu, struct ivhd_header *h)
15111511
iommu->mmio_phys_end = MMIO_REG_END_OFFSET;
15121512
else
15131513
iommu->mmio_phys_end = MMIO_CNTR_CONF_OFFSET;
1514-
if (((h->efr_attr & (0x1 << IOMMU_FEAT_GASUP_SHIFT)) == 0))
1514+
1515+
/*
1516+
* Note: GA (128-bit IRTE) mode requires cmpxchg16b supports.
1517+
* GAM also requires GA mode. Therefore, we need to
1518+
* check cmpxchg16b support before enabling it.
1519+
*/
1520+
if (!boot_cpu_has(X86_FEATURE_CX16) ||
1521+
((h->efr_attr & (0x1 << IOMMU_FEAT_GASUP_SHIFT)) == 0))
15151522
amd_iommu_guest_ir = AMD_IOMMU_GUEST_IR_LEGACY;
15161523
break;
15171524
case 0x11:
@@ -1520,8 +1527,18 @@ static int __init init_iommu_one(struct amd_iommu *iommu, struct ivhd_header *h)
15201527
iommu->mmio_phys_end = MMIO_REG_END_OFFSET;
15211528
else
15221529
iommu->mmio_phys_end = MMIO_CNTR_CONF_OFFSET;
1523-
if (((h->efr_reg & (0x1 << IOMMU_EFR_GASUP_SHIFT)) == 0))
1530+
1531+
/*
1532+
* Note: GA (128-bit IRTE) mode requires cmpxchg16b supports.
1533+
* XT, GAM also requires GA mode. Therefore, we need to
1534+
* check cmpxchg16b support before enabling them.
1535+
*/
1536+
if (!boot_cpu_has(X86_FEATURE_CX16) ||
1537+
((h->efr_reg & (0x1 << IOMMU_EFR_GASUP_SHIFT)) == 0)) {
15241538
amd_iommu_guest_ir = AMD_IOMMU_GUEST_IR_LEGACY;
1539+
break;
1540+
}
1541+
15251542
/*
15261543
* Note: Since iommu_update_intcapxt() leverages
15271544
* the IOMMU MMIO access to MSI capability block registers

drivers/iommu/amd/iommu.c

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3292,6 +3292,7 @@ static int alloc_irq_index(u16 devid, int count, bool align,
32923292
static int modify_irte_ga(u16 devid, int index, struct irte_ga *irte,
32933293
struct amd_ir_data *data)
32943294
{
3295+
bool ret;
32953296
struct irq_remap_table *table;
32963297
struct amd_iommu *iommu;
32973298
unsigned long flags;
@@ -3309,10 +3310,18 @@ static int modify_irte_ga(u16 devid, int index, struct irte_ga *irte,
33093310

33103311
entry = (struct irte_ga *)table->table;
33113312
entry = &entry[index];
3312-
entry->lo.fields_remap.valid = 0;
3313-
entry->hi.val = irte->hi.val;
3314-
entry->lo.val = irte->lo.val;
3315-
entry->lo.fields_remap.valid = 1;
3313+
3314+
ret = cmpxchg_double(&entry->lo.val, &entry->hi.val,
3315+
entry->lo.val, entry->hi.val,
3316+
irte->lo.val, irte->hi.val);
3317+
/*
3318+
* We use cmpxchg16 to atomically update the 128-bit IRTE,
3319+
* and it cannot be updated by the hardware or other processors
3320+
* behind us, so the return value of cmpxchg16 should be the
3321+
* same as the old value.
3322+
*/
3323+
WARN_ON(!ret);
3324+
33163325
if (data)
33173326
data->ref = entry;
33183327

0 commit comments

Comments
 (0)