* [PATCH] iommu/amd: Add SNP page mode 0 support
@ 2026-07-23 8:43 Vasant Hegde
2026-07-23 8:46 ` Vasant Hegde
0 siblings, 1 reply; 4+ messages in thread
From: Vasant Hegde @ 2026-07-23 8:43 UTC (permalink / raw)
To: iommu, joro
Cc: will, robin.murphy, suravee.suthikulpanit, Vasant Hegde,
Amandeep Kaur Longia
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.
Signed-off-by: Vasant Hegde <vasant.hegde@amd.com>
Reviewed-by: Suravee Suthikulpanit <suravee.suthikulpanit@amd.com>
Tested-by: Amandeep Kaur Longia <AmandeepKaur.Longia@amd.com>
---
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(-)
diff --git a/drivers/iommu/amd/amd_iommu_types.h b/drivers/iommu/amd/amd_iommu_types.h
index 3c292fdfa95a..d421151e9b7a 100644
--- a/drivers/iommu/amd/amd_iommu_types.h
+++ b/drivers/iommu/amd/amd_iommu_types.h
@@ -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 */
diff --git a/drivers/iommu/amd/init.c b/drivers/iommu/amd/init.c
index e93bcb5eef70..1fdd83a14dfb 100644
--- a/drivers/iommu/amd/init.c
+++ b/drivers/iommu/amd/init.c
@@ -180,6 +180,9 @@ bool amd_iommu_hatdis;
bool amd_iommu_snp_en;
EXPORT_SYMBOL(amd_iommu_snp_en);
+/* SNP page mode 0 support */
+bool amd_iommu_snp_mode0_sup;
+
LIST_HEAD(amd_iommu_pci_seg_list); /* list of all PCI segments */
LIST_HEAD(amd_iommu_list); /* list of all AMD IOMMUs in the system */
LIST_HEAD(amd_ivhd_dev_flags_list); /* list of all IVHD device entry settings */
@@ -3365,18 +3368,28 @@ static __init void iommu_snp_enable(void)
#ifdef CONFIG_KVM_AMD_SEV
if (!cc_platform_has(CC_ATTR_HOST_SEV_SNP))
return;
- /*
- * The SNP support requires that IOMMU must be enabled, and is
- * configured with V1 page table (DTE[Mode] = 0 is not supported).
- */
- if (no_iommu || iommu_default_passthrough()) {
- pr_warn("SNP: IOMMU disabled or configured in passthrough mode, SNP cannot be supported.\n");
+
+ /* SNP support required IOMMU to be ON */
+ if (no_iommu) {
+ pr_warn("SNP: IOMMU disabled, SNP cannot be supported.\n");
goto disable_snp;
}
- if (amd_iommu_pgtable != PD_MODE_V1) {
- pr_warn("SNP: IOMMU is configured with V2 page table mode, SNP cannot be supported.\n");
- goto disable_snp;
+ amd_iommu_snp_mode0_sup = check_feature2(FEATURE_SNP_PAGE_MODE0_SUP);
+ /*
+ * If SNP page mode 0 is not enabled, then SNP support requires that IOMMU
+ * must be configured with V1 page table (DTE[Mode] != 0).
+ */
+ if (!amd_iommu_snp_mode0_sup) {
+ if (iommu_default_passthrough()) {
+ pr_warn("SNP: IOMMU configured in passthrough mode, SNP cannot be supported.\n");
+ goto disable_snp;
+ }
+
+ if (amd_iommu_pgtable != PD_MODE_V1) {
+ pr_warn("SNP: IOMMU is configured with V2 page table mode, SNP cannot be supported.\n");
+ goto disable_snp;
+ }
}
amd_iommu_snp_en = check_feature(FEATURE_SNP);
@@ -3911,12 +3924,15 @@ bool amd_iommu_pasid_supported(void)
amd_iommu_gpt_level != PAGE_MODE_5_LEVEL)
return false;
+ if (!amd_iommu_gt_ppr_supported())
+ return false;
+
/*
- * Since DTE[Mode]=0 is prohibited on SNP-enabled system
- * (i.e. EFR[SNPSup]=1), IOMMUv2 page table cannot be used without
- * setting up IOMMUv1 page table.
+ * If SNP page mode 0 is not supported, then DTE[Mode]=0 is prohibited
+ * on SNP-enabled system (i.e. EFR[SNPSup]=1). IOMMUv2 page table
+ * cannot be used without setting up IOMMUv1 page table.
*/
- return amd_iommu_gt_ppr_supported() && !amd_iommu_snp_en;
+ return (!amd_iommu_snp_en) || (amd_iommu_snp_en && amd_iommu_snp_mode0_sup);
}
struct amd_iommu *get_amd_iommu(unsigned int idx)
diff --git a/drivers/iommu/amd/iommu.c b/drivers/iommu/amd/iommu.c
index fe642e33c87d..8be138c9bec3 100644
--- a/drivers/iommu/amd/iommu.c
+++ b/drivers/iommu/amd/iommu.c
@@ -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;
--
2.31.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] iommu/amd: Add SNP page mode 0 support
2026-07-23 8:43 [PATCH] iommu/amd: Add SNP page mode 0 support Vasant Hegde
@ 2026-07-23 8:46 ` Vasant Hegde
2026-08-10 7:50 ` Jörg Rödel
0 siblings, 1 reply; 4+ messages in thread
From: Vasant Hegde @ 2026-07-23 8:46 UTC (permalink / raw)
To: iommu, joro
Cc: will, robin.murphy, suravee.suthikulpanit, Amandeep Kaur Longia
On 7/23/2026 2:13 PM, Vasant Hegde wrote:
> 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.
>
> Signed-off-by: Vasant Hegde <vasant.hegde@amd.com>
> Reviewed-by: Suravee Suthikulpanit <suravee.suthikulpanit@amd.com>
> Tested-by: Amandeep Kaur Longia <AmandeepKaur.Longia@amd.com>
Missed to mention. This patch applies on top of
https://lore.kernel.org/linux-iommu/20260723061548.10187-1-vasant.hegde@amd.com/T/#t
-Vasant
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] iommu/amd: Add SNP page mode 0 support
2026-07-23 8:46 ` Vasant Hegde
@ 2026-08-10 7:50 ` Jörg Rödel
2026-08-11 6:39 ` Vasant Hegde
0 siblings, 1 reply; 4+ messages in thread
From: Jörg Rödel @ 2026-08-10 7:50 UTC (permalink / raw)
To: Vasant Hegde
Cc: iommu, will, robin.murphy, suravee.suthikulpanit,
Amandeep Kaur Longia
Hi Vasant,
On Thu, Jul 23, 2026 at 02:16:37PM +0530, Vasant Hegde wrote:
> Missed to mention. This patch applies on top of
>
> https://lore.kernel.org/linux-iommu/20260723061548.10187-1-vasant.hegde@amd.com/T/#t
Please include this into the repost of the above patch-set and base the series
on the amd/amd-vi branch.
Thanks,
Joerg
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] iommu/amd: Add SNP page mode 0 support
2026-08-10 7:50 ` Jörg Rödel
@ 2026-08-11 6:39 ` Vasant Hegde
0 siblings, 0 replies; 4+ messages in thread
From: Vasant Hegde @ 2026-08-11 6:39 UTC (permalink / raw)
To: Jörg Rödel
Cc: iommu, will, robin.murphy, suravee.suthikulpanit,
Amandeep Kaur Longia
Joerg,
On 8/10/2026 1:20 PM, Jörg Rödel wrote:
> Hi Vasant,
>
> On Thu, Jul 23, 2026 at 02:16:37PM +0530, Vasant Hegde wrote:
>> Missed to mention. This patch applies on top of
>>
>> https://lore.kernel.org/linux-iommu/20260723061548.10187-1-vasant.hegde@amd.com/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
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2026-08-11 6:39 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-07-23 8:43 [PATCH] iommu/amd: Add SNP page mode 0 support Vasant Hegde
2026-07-23 8:46 ` Vasant Hegde
2026-08-10 7:50 ` Jörg Rödel
2026-08-11 6:39 ` Vasant Hegde
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.