Skip to content

Commit 82582f8

Browse files
ssuthiku-amdjoergroedel
authored andcommitted
iommu/amd: Disable AMD IOMMU if CMPXCHG16B feature is not supported
According to the AMD IOMMU spec, IOMMU hardware reads the entire DTE in a single 256-bit transaction. It is recommended to update DTE using 128-bit operation followed by an INVALIDATE_DEVTAB_ENTYRY command when the IV=1b or V=1b before the change. According to the AMD BIOS and Kernel Developer's Guide (BDKG) dated back to family 10h Processor [1], which is the first introduction of AMD IOMMU, AMD processor always has CPUID Fn0000_0001_ECX[CMPXCHG16B]=1. Therefore, it is safe to assume cmpxchg128 is available with all AMD processor w/ IOMMU. In addition, the CMPXCHG16B feature has already been checked separately before enabling the GA, XT, and GAM modes. Consolidate the detection logic, and fail the IOMMU initialization if the feature is not supported. [1] https://www.amd.com/content/dam/amd/en/documents/archived-tech-docs/programmer-references/31116.pdf Reviewed-by: Jason Gunthorpe <[email protected]> Suggested-by: Jason Gunthorpe <[email protected]> Signed-off-by: Suravee Suthikulpanit <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Joerg Roedel <[email protected]>
1 parent f20a6e3 commit 82582f8

File tree

1 file changed

+9
-14
lines changed

1 file changed

+9
-14
lines changed

drivers/iommu/amd/init.c

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1752,13 +1752,8 @@ static int __init init_iommu_one(struct amd_iommu *iommu, struct ivhd_header *h,
17521752
else
17531753
iommu->mmio_phys_end = MMIO_CNTR_CONF_OFFSET;
17541754

1755-
/*
1756-
* Note: GA (128-bit IRTE) mode requires cmpxchg16b supports.
1757-
* GAM also requires GA mode. Therefore, we need to
1758-
* check cmpxchg16b support before enabling it.
1759-
*/
1760-
if (!boot_cpu_has(X86_FEATURE_CX16) ||
1761-
((h->efr_attr & (0x1 << IOMMU_FEAT_GASUP_SHIFT)) == 0))
1755+
/* GAM requires GA mode. */
1756+
if ((h->efr_attr & (0x1 << IOMMU_FEAT_GASUP_SHIFT)) == 0)
17621757
amd_iommu_guest_ir = AMD_IOMMU_GUEST_IR_LEGACY;
17631758
break;
17641759
case 0x11:
@@ -1768,13 +1763,8 @@ static int __init init_iommu_one(struct amd_iommu *iommu, struct ivhd_header *h,
17681763
else
17691764
iommu->mmio_phys_end = MMIO_CNTR_CONF_OFFSET;
17701765

1771-
/*
1772-
* Note: GA (128-bit IRTE) mode requires cmpxchg16b supports.
1773-
* XT, GAM also requires GA mode. Therefore, we need to
1774-
* check cmpxchg16b support before enabling them.
1775-
*/
1776-
if (!boot_cpu_has(X86_FEATURE_CX16) ||
1777-
((h->efr_reg & (0x1 << IOMMU_EFR_GASUP_SHIFT)) == 0)) {
1766+
/* XT and GAM require GA mode. */
1767+
if ((h->efr_reg & (0x1 << IOMMU_EFR_GASUP_SHIFT)) == 0) {
17781768
amd_iommu_guest_ir = AMD_IOMMU_GUEST_IR_LEGACY;
17791769
break;
17801770
}
@@ -3028,6 +3018,11 @@ static int __init early_amd_iommu_init(void)
30283018
return -EINVAL;
30293019
}
30303020

3021+
if (!boot_cpu_has(X86_FEATURE_CX16)) {
3022+
pr_err("Failed to initialize. The CMPXCHG16B feature is required.\n");
3023+
return -EINVAL;
3024+
}
3025+
30313026
/*
30323027
* Validate checksum here so we don't need to do it when
30333028
* we actually parse the table

0 commit comments

Comments
 (0)