Skip to contentSkip to conversation

iommu/amd: Add SNP page mode 0 support

PATCH Superseded Vasant Hegde 2 participants 4 messages Jul 23 – Aug 11

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Vasant Hegde

author maintainer
#0 lore raw

PATCH 1/1 iommu/amd: Add SNP page mode 0 support

Newer AMD IOMMUs supports DTE[Mode]=0 for SNP-enabled system. This is detected using new feature bit (EFR2[SNP_Page_Mode_0_Sup]). If this feature is enabled, then IOMMU supports:
- Passthrough mode (i.e. iommu=pt)
- amd_iommu=pgtbl_v2: Forcing Linux DMA-API to use IOMMU v2 page table
- Setting up device for SVA mode in the host.

---
 drivers/iommu/amd/amd_iommu_types.h |  4 +++
 drivers/iommu/amd/init.c            | 42 ++++++++++++++++++++---------
 drivers/iommu/amd/iommu.c           | 11 +++++---
 3 files changed, 40 insertions(+), 17 deletions(-)
drivers/iommu/amd/amd_iommu_types.h +4 -0
index 3c292fdfa95a..d421151e9b7a 100644
@@ -113,6 +113,7 @@
 #define FEATURE_SNPAVICSUP_GAM(x) \
 	(FIELD_GET(FEATURE_SNPAVICSUP, x) == 0x1)
 #define FEATURE_HT_RANGE_IGNORE		BIT_ULL(11)
+#define FEATURE_SNP_PAGE_MODE0_SUP	BIT_ULL(13)
 
 #define FEATURE_NUM_INT_REMAP_SUP	GENMASK_ULL(9, 8)
 #define FEATURE_NUM_INT_REMAP_SUP_2K(x) \
@@ -416,6 +417,9 @@ extern bool amd_iommu_dump;
 			pr_info(format, ## arg);	\
 	} while(0);
 
+/* SNP page mode 0 support */
+extern bool amd_iommu_snp_mode0_sup;
+
 /* global flag if IOMMUs cache non-present entries */
 extern bool amd_iommu_np_cache;
 /* Only true if all IOMMUs support device IOTLBs */
drivers/iommu/amd/init.c +29 -13

65 lines not on this page · raw message

drivers/iommu/amd/iommu.c +7 -4
index fe642e33c87d..8be138c9bec3 100644
@@ -2910,9 +2910,9 @@ static int amd_iommu_identity_attach(struct iommu_domain *dom, struct device *de
 {
 	/*
 	 * Don't allow attaching a device to the identity domain if SNP is
-	 * enabled.
+	 * enabled and SNP Mode0 support is not present.
 	 */
-	if (amd_iommu_snp_en)
+	if (amd_iommu_snp_en && !amd_iommu_snp_mode0_sup)
 		return -EINVAL;
 
 	return amd_iommu_attach_device(dom, dev, old);
@@ -3164,8 +3164,11 @@ static int amd_iommu_def_domain_type(struct device *dev)
 		if (cc_platform_has(CC_ATTR_MEM_ENCRYPT))
 			return 0;
 
-		/* DTE[Mode]=0 is prohibited when SNP is enabled */
-		if (amd_iommu_snp_en)
+		/*
+		 * DTE[Mode]=0 is prohibited when SNP is enabled and SNP
+		 * Mode 0 is not supported.
+		 */
+		if (amd_iommu_snp_en && !amd_iommu_snp_mode0_sup)
 			return 0;
 
 		return IOMMU_DOMAIN_IDENTITY;
Signature · 1 line
2.31.1
author maintainer
#1 lore raw
Quoted 10 lines · Vasant Hegde

Newer AMD IOMMUs supports DTE[Mode]=0 for SNP-enabled system. This is detected using new feature bit (EFR2[SNP_Page_Mode_0_Sup]). If this feature is enabled, then IOMMU supports:
- Passthrough mode (i.e. iommu=pt)
- amd_iommu=pgtbl_v2: Forcing Linux DMA-API to use IOMMU v2 page table
- Setting up device for SVA mode in the host.

Missed to mention. This patch applies on top of

https://lore.kernel.org/linux-iommu/[email protected]/T/#t

-Vasant

author maintainer
#3 lore raw

Joerg,

Quoted 9 lines · Jörg Rödel

Hi Vasant,

Quoted 3 lines · Vasant Hegde

Missed to mention. This patch applies on top of

https://lore.kernel.org/linux-iommu/[email protected]/T/#t

Please include this into the repost of the above patch-set and base the series on the amd/amd-vi branch.

Sorry. I missed to send it as single series. I have rebased and sent v2 as separate patch.

-Vasant