Skip to content

Commit 643feb0

Browse files
ssuthiku-amdjoergroedel
authored andcommitted
iommu/amd: Add support for Guest IO protection
AMD IOMMU introduces support for Guest I/O protection where the request from the I/O device without a PASID are treated as if they have PASID 0. Co-developed-by: Vasant Hegde <[email protected]> Signed-off-by: Vasant Hegde <[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 aaac38f commit 643feb0

File tree

3 files changed

+19
-0
lines changed

3 files changed

+19
-0
lines changed

drivers/iommu/amd/amd_iommu_types.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@
9494
#define FEATURE_HE (1ULL<<8)
9595
#define FEATURE_PC (1ULL<<9)
9696
#define FEATURE_GAM_VAPIC (1ULL<<21)
97+
#define FEATURE_GIOSUP (1ULL<<48)
9798
#define FEATURE_EPHSUP (1ULL<<50)
9899
#define FEATURE_SNP (1ULL<<63)
99100

@@ -378,6 +379,7 @@
378379
#define DTE_FLAG_IW (1ULL << 62)
379380

380381
#define DTE_FLAG_IOTLB (1ULL << 32)
382+
#define DTE_FLAG_GIOV (1ULL << 54)
381383
#define DTE_FLAG_GV (1ULL << 55)
382384
#define DTE_FLAG_MASK (0x3ffULL << 32)
383385
#define DTE_GLX_SHIFT (56)
@@ -436,6 +438,7 @@
436438
#define PD_PASSTHROUGH_MASK (1UL << 2) /* domain has no page
437439
translation */
438440
#define PD_IOMMUV2_MASK (1UL << 3) /* domain has gcr3 table */
441+
#define PD_GIOV_MASK (1UL << 4) /* domain enable GIOV support */
439442

440443
extern bool amd_iommu_dump;
441444
#define DUMP_printk(format, arg...) \

drivers/iommu/amd/init.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2068,6 +2068,17 @@ static int __init iommu_init_pci(struct amd_iommu *iommu)
20682068

20692069
init_iommu_perf_ctr(iommu);
20702070

2071+
if (amd_iommu_pgtable == AMD_IOMMU_V2) {
2072+
if (!iommu_feature(iommu, FEATURE_GIOSUP) ||
2073+
!iommu_feature(iommu, FEATURE_GT)) {
2074+
pr_warn("Cannot enable v2 page table for DMA-API. Fallback to v1.\n");
2075+
amd_iommu_pgtable = AMD_IOMMU_V1;
2076+
} else if (iommu_default_passthrough()) {
2077+
pr_warn("V2 page table doesn't support passthrough mode. Fallback to v1.\n");
2078+
amd_iommu_pgtable = AMD_IOMMU_V1;
2079+
}
2080+
}
2081+
20712082
if (is_rd890_iommu(iommu->dev)) {
20722083
int i, j;
20732084

@@ -2146,6 +2157,8 @@ static void print_iommu_info(void)
21462157
if (amd_iommu_xt_mode == IRQ_REMAP_X2APIC_MODE)
21472158
pr_info("X2APIC enabled\n");
21482159
}
2160+
if (amd_iommu_pgtable == AMD_IOMMU_V2)
2161+
pr_info("V2 page table enabled\n");
21492162
}
21502163

21512164
static int __init amd_iommu_init_pci(void)

drivers/iommu/amd/iommu.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1597,6 +1597,9 @@ static void set_dte_entry(struct amd_iommu *iommu, u16 devid,
15971597

15981598
tmp = DTE_GCR3_VAL_C(gcr3) << DTE_GCR3_SHIFT_C;
15991599
flags |= tmp;
1600+
1601+
if (domain->flags & PD_GIOV_MASK)
1602+
pte_root |= DTE_FLAG_GIOV;
16001603
}
16011604

16021605
flags &= ~DEV_DOMID_MASK;

0 commit comments

Comments
 (0)