Skip to content

Commit 432e5df

Browse files
ssuthiku-amdjoergroedel
authored andcommitted
iommu/amd: Add support for AVIC when SNP is enabled
In order to support AVIC on SNP-enabled system, The IOMMU driver needs to check EFR2[SNPAVICSup] and enables the support by setting SNPAVICEn bit in the IOMMU control register (MMIO offset 18h). For detail, please see section "SEV-SNP Guest Virtual APIC Support" of the AMD I/O Virtualization Technology (IOMMU) Specification. (https://www.amd.com/system/files/TechDocs/48882_IOMMU.pdf) Signed-off-by: Suravee Suthikulpanit <[email protected]> Reviewed-by: Jerry Snitselaar <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Joerg Roedel <[email protected]>
1 parent c5e1a1e commit 432e5df

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

drivers/iommu/amd/amd_iommu_types.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,12 @@
103103
#define FEATURE_GLXVAL_SHIFT 14
104104
#define FEATURE_GLXVAL_MASK (0x03ULL << FEATURE_GLXVAL_SHIFT)
105105

106+
/* Extended Feature 2 Bits */
107+
#define FEATURE_SNPAVICSUP_SHIFT 5
108+
#define FEATURE_SNPAVICSUP_MASK (0x07ULL << FEATURE_SNPAVICSUP_SHIFT)
109+
#define FEATURE_SNPAVICSUP_GAM(x) \
110+
((x & FEATURE_SNPAVICSUP_MASK) >> FEATURE_SNPAVICSUP_SHIFT == 0x1)
111+
106112
/* Note:
107113
* The current driver only support 16-bit PASID.
108114
* Currently, hardware only implement upto 16-bit PASID
@@ -165,6 +171,7 @@
165171
#define CONTROL_GAINT_EN 29
166172
#define CONTROL_XT_EN 50
167173
#define CONTROL_INTCAPXT_EN 51
174+
#define CONTROL_SNPAVIC_EN 61
168175

169176
#define CTRL_INV_TO_MASK (7 << CONTROL_INV_TIMEOUT)
170177
#define CTRL_INV_TO_NONE 0

drivers/iommu/amd/init.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2794,13 +2794,22 @@ static void enable_iommus_vapic(void)
27942794
return;
27952795
}
27962796

2797-
/* Enabling GAM support */
2797+
if (amd_iommu_snp_en &&
2798+
!FEATURE_SNPAVICSUP_GAM(amd_iommu_efr2)) {
2799+
pr_warn("Force to disable Virtual APIC due to SNP\n");
2800+
amd_iommu_guest_ir = AMD_IOMMU_GUEST_IR_LEGACY_GA;
2801+
return;
2802+
}
2803+
2804+
/* Enabling GAM and SNPAVIC support */
27982805
for_each_iommu(iommu) {
27992806
if (iommu_init_ga_log(iommu) ||
28002807
iommu_ga_log_enable(iommu))
28012808
return;
28022809

28032810
iommu_feature_enable(iommu, CONTROL_GAM_EN);
2811+
if (amd_iommu_snp_en)
2812+
iommu_feature_enable(iommu, CONTROL_SNPAVIC_EN);
28042813
}
28052814

28062815
amd_iommu_irq_ops.capability |= (1 << IRQ_POSTING_CAP);

0 commit comments

Comments
 (0)