Skip to content

Commit 8130714

Browse files
ssuthiku-amdjoergroedel
authored andcommitted
iommu/amd: Check feature support bit before accessing MSI capability registers
The IOMMU MMIO access to MSI capability registers is available only if the EFR[MsiCapMmioSup] is set. Current implementation assumes this bit is set if the EFR[XtSup] is set, which might not be the case. Fix by checking the EFR[MsiCapMmioSup] before accessing the MSI address low/high and MSI data registers via the MMIO. Fixes: 6692981 ('iommu/amd: Add support for X2APIC IOMMU interrupts') Signed-off-by: Suravee Suthikulpanit <[email protected]> Signed-off-by: Joerg Roedel <[email protected]>
1 parent 387caf0 commit 8130714

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

drivers/iommu/amd_iommu_init.c

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ bool amd_iommu_dump;
149149
bool amd_iommu_irq_remap __read_mostly;
150150

151151
int amd_iommu_guest_ir = AMD_IOMMU_GUEST_IR_VAPIC;
152-
static int amd_iommu_xt_mode = IRQ_REMAP_X2APIC_MODE;
152+
static int amd_iommu_xt_mode = IRQ_REMAP_XAPIC_MODE;
153153

154154
static bool amd_iommu_detected;
155155
static bool __initdata amd_iommu_disabled;
@@ -1534,8 +1534,15 @@ static int __init init_iommu_one(struct amd_iommu *iommu, struct ivhd_header *h)
15341534
iommu->mmio_phys_end = MMIO_CNTR_CONF_OFFSET;
15351535
if (((h->efr_reg & (0x1 << IOMMU_EFR_GASUP_SHIFT)) == 0))
15361536
amd_iommu_guest_ir = AMD_IOMMU_GUEST_IR_LEGACY;
1537-
if (((h->efr_reg & (0x1 << IOMMU_EFR_XTSUP_SHIFT)) == 0))
1538-
amd_iommu_xt_mode = IRQ_REMAP_XAPIC_MODE;
1537+
/*
1538+
* Note: Since iommu_update_intcapxt() leverages
1539+
* the IOMMU MMIO access to MSI capability block registers
1540+
* for MSI address lo/hi/data, we need to check both
1541+
* EFR[XtSup] and EFR[MsiCapMmioSup] for x2APIC support.
1542+
*/
1543+
if ((h->efr_reg & BIT(IOMMU_EFR_XTSUP_SHIFT)) &&
1544+
(h->efr_reg & BIT(IOMMU_EFR_MSICAPMMIOSUP_SHIFT)))
1545+
amd_iommu_xt_mode = IRQ_REMAP_X2APIC_MODE;
15391546
break;
15401547
default:
15411548
return -EINVAL;
@@ -1984,8 +1991,8 @@ static int iommu_init_intcapxt(struct amd_iommu *iommu)
19841991
struct irq_affinity_notify *notify = &iommu->intcapxt_notify;
19851992

19861993
/**
1987-
* IntCapXT requires XTSup=1, which can be inferred
1988-
* amd_iommu_xt_mode.
1994+
* IntCapXT requires XTSup=1 and MsiCapMmioSup=1,
1995+
* which can be inferred from amd_iommu_xt_mode.
19891996
*/
19901997
if (amd_iommu_xt_mode != IRQ_REMAP_X2APIC_MODE)
19911998
return 0;

drivers/iommu/amd_iommu_types.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -383,6 +383,7 @@
383383
/* IOMMU Extended Feature Register (EFR) */
384384
#define IOMMU_EFR_XTSUP_SHIFT 2
385385
#define IOMMU_EFR_GASUP_SHIFT 7
386+
#define IOMMU_EFR_MSICAPMMIOSUP_SHIFT 46
386387

387388
#define MAX_DOMAIN_ID 65536
388389

0 commit comments

Comments
 (0)