All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] iommu/amd: Add Secure ATS support
@ 2025-02-25 10:58 Vasant Hegde
  2025-02-25 12:30 ` Yi Liu
  0 siblings, 1 reply; 68+ messages in thread
From: Vasant Hegde @ 2025-02-25 10:58 UTC (permalink / raw)
  To: iommu, joro; +Cc: will, robin.murphy, suravee.suthikulpanit, Vasant Hegde

AMD IOMMU supports processing ATS requests as Secure ATS requests when IOTLB
is supported and enabled (See section "2.11 Secure ATS Supports" in AMD IOMMU
spec [1] for more detail).

With Secure ATS, for ATS requests IOMMU return GPA to device instead of SPA.
When receiving Translated DMA from a device the IOMMU performs in-line
GPA to SPA translation. This ensures that any malicious devices or
vulnerable IOTLB implementations do not have access to the full SPA
space even if they can generate Translated DMA with arbitrary addresses.
This provides security against untrusted devices.

Introduce new command line parameter (amd_iommu=sats) to enable Secure
ATS. This can be used to provide security against untrusted device ATS.
Also enable Secure ATS when SNP is enabled.

[1] https://www.amd.com/en/support/tech-docs/amd-io-virtualization-technology-iommu-specification

Signed-off-by: Vasant Hegde <vasant.hegde@amd.com>
---
 drivers/iommu/amd/amd_iommu.h       |  1 +
 drivers/iommu/amd/amd_iommu_types.h |  2 ++
 drivers/iommu/amd/init.c            | 17 +++++++++++++++++
 drivers/iommu/amd/iommu.c           | 11 ++++++++++-
 4 files changed, 30 insertions(+), 1 deletion(-)

diff --git a/drivers/iommu/amd/amd_iommu.h b/drivers/iommu/amd/amd_iommu.h
index 68debf5ee2d7..b9a6f5844e50 100644
--- a/drivers/iommu/amd/amd_iommu.h
+++ b/drivers/iommu/amd/amd_iommu.h
@@ -43,6 +43,7 @@ extern int amd_iommu_guest_ir;
 extern enum protection_domain_mode amd_iommu_pgtable;
 extern int amd_iommu_gpt_level;
 extern unsigned long amd_iommu_pgsize_bitmap;
+extern bool amd_iommu_sats;
 
 /* Protection domain ops */
 void amd_iommu_init_identity_domain(void);
diff --git a/drivers/iommu/amd/amd_iommu_types.h b/drivers/iommu/amd/amd_iommu_types.h
index 23caea22f8dc..bffb6ebb3d3e 100644
--- a/drivers/iommu/amd/amd_iommu_types.h
+++ b/drivers/iommu/amd/amd_iommu_types.h
@@ -99,6 +99,7 @@
 #define FEATURE_GATS		GENMASK_ULL(13, 12)
 #define FEATURE_GLX		GENMASK_ULL(15, 14)
 #define FEATURE_GAM_VAPIC	BIT_ULL(21)
+#define FEATURE_SATSSUP		BIT_ULL(31)
 #define FEATURE_PASMAX		GENMASK_ULL(36, 32)
 #define FEATURE_GIOSUP		BIT_ULL(48)
 #define FEATURE_HASUP		BIT_ULL(49)
@@ -417,6 +418,7 @@
 #define DTE_FLAG_IOTLB	BIT_ULL(32)
 #define DTE_FLAG_MASK	(0x3ffULL << 32)
 #define DEV_DOMID_MASK	0xffffULL
+#define DTE_FLAG_SATS	BIT_ULL(42)
 
 #define DTE_GCR3_14_12	GENMASK_ULL(60, 58)
 #define DTE_GCR3_30_15	GENMASK_ULL(31, 16)
diff --git a/drivers/iommu/amd/init.c b/drivers/iommu/amd/init.c
index cb536d372b12..9b28c1fd32bf 100644
--- a/drivers/iommu/amd/init.c
+++ b/drivers/iommu/amd/init.c
@@ -156,6 +156,9 @@ enum protection_domain_mode amd_iommu_pgtable = PD_MODE_V1;
 /* Guest page table level */
 int amd_iommu_gpt_level = PAGE_MODE_4_LEVEL;
 
+/* Secure ATS support */
+bool amd_iommu_sats;
+
 int amd_iommu_guest_ir = AMD_IOMMU_GUEST_IR_VAPIC;
 static int amd_iommu_xt_mode = IRQ_REMAP_XAPIC_MODE;
 
@@ -3093,6 +3096,15 @@ static int __init early_amd_iommu_init(void)
 		}
 	}
 
+	/* Secure ATS supported when DTE[mode] != 0 */
+	if (amd_iommu_sats) {
+		if (!check_feature(FEATURE_SATSSUP) ||
+		    (amd_iommu_pgtable != PD_MODE_V1)) {
+			pr_info("Secure ATS is not supported");
+			amd_iommu_sats = false;
+		}
+	}
+
 	/* Disable any previously enabled IOMMUs */
 	if (!is_kdump_kernel() || amd_iommu_disabled)
 		disable_iommus();
@@ -3231,6 +3243,9 @@ static __init void iommu_snp_enable(void)
 		goto disable_snp;
 	}
 
+	if (check_feature(FEATURE_SATSSUP))
+		amd_iommu_sats = true;
+
 	pr_info("IOMMU SNP support enabled.\n");
 	return;
 
@@ -3526,6 +3541,8 @@ static int __init parse_amd_iommu_options(char *str)
 		} else if (strncmp(str, "v2_pgsizes_only", 15) == 0) {
 			pr_info("Restricting V1 page-sizes to 4KiB/2MiB/1GiB");
 			amd_iommu_pgsize_bitmap = AMD_IOMMU_PGSIZES_V2;
+		} else if (strncmp(str, "sats", 4) == 0) {
+			amd_iommu_sats = true;
 		} else {
 			pr_notice("Unknown option - '%s'\n", str);
 		}
diff --git a/drivers/iommu/amd/iommu.c b/drivers/iommu/amd/iommu.c
index b48a72bd7b23..c7c9b5112828 100644
--- a/drivers/iommu/amd/iommu.c
+++ b/drivers/iommu/amd/iommu.c
@@ -2064,9 +2064,18 @@ static void set_dte_entry(struct amd_iommu *iommu,
 	if (domain->dirty_tracking)
 		new.data[0] |= DTE_FLAG_HAD;
 
-	if (dev_data->ats_enabled)
+	if (dev_data->ats_enabled) {
 		new.data[1] |= DTE_FLAG_IOTLB;
 
+		/* Secure ATS is supported when DTE[mode] != 0 */
+		if (amd_iommu_sats && domain->iop.mode != PAGE_MODE_NONE)
+			new.data[1] |= DTE_FLAG_SATS;
+		else if (amd_iommu_sats) {
+			pr_devel("Secure ATS not enabled for dev 0x%x as "
+				 "DTE[mode]=0\n", dev_data->devid);
+		}
+	}
+
 	old_domid = READ_ONCE(dte->data[1]) & DEV_DOMID_MASK;
 	new.data[1] |= domid;
 
-- 
2.31.1


^ permalink raw reply related	[flat|nested] 68+ messages in thread

end of thread, other threads:[~2025-04-07  5:28 UTC | newest]

Thread overview: 68+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-02-25 10:58 [PATCH] iommu/amd: Add Secure ATS support Vasant Hegde
2025-02-25 12:30 ` Yi Liu
2025-02-25 13:18   ` Robin Murphy
2025-02-25 13:57     ` Yi Liu
2025-02-25 14:55     ` Jason Gunthorpe
2025-02-26  1:09       ` Yi Liu
2025-02-26  1:13         ` Jason Gunthorpe
2025-02-26  1:27           ` Yi Liu
2025-02-26  2:52           ` Tian, Kevin
2025-02-26  1:12       ` Tian, Kevin
2025-02-26  1:17         ` Jason Gunthorpe
2025-02-26  2:50           ` Tian, Kevin
2025-02-26 12:57             ` Jason Gunthorpe
2025-02-26  7:05           ` Tian, Kevin
2025-02-26 12:58             ` Jason Gunthorpe
2025-02-27 15:27             ` Vasant Hegde
2025-02-28  6:32               ` Tian, Kevin
2025-02-28  7:43                 ` Yi Liu
2025-02-28  8:30                   ` Vasant Hegde
2025-02-28  8:47                     ` Yi Liu
2025-02-28  8:47                       ` Vasant Hegde
2025-03-02  8:10                         ` Yi Liu
2025-03-03  3:00                           ` Tian, Kevin
2025-03-04  6:58                             ` Yi Liu
2025-03-03 11:42                           ` Vasant Hegde
2025-03-05  3:24                             ` Tian, Kevin
2025-03-10 17:07                               ` Vasant Hegde
2025-03-12  7:15                                 ` Tian, Kevin
2025-03-17  8:56                                   ` Vasant Hegde
2025-04-07  5:28                                     ` Tian, Kevin
2025-03-03 18:38                           ` Jason Gunthorpe
2025-03-04  2:16                             ` Baolu Lu
2025-03-04 14:18                               ` Jason Gunthorpe
2025-03-05  2:45                                 ` Baolu Lu
2025-03-05  2:46                                 ` Tian, Kevin
2025-03-04  6:50                             ` Yi Liu
2025-03-04 10:46                               ` Vasant Hegde
2025-03-04 14:20                               ` Jason Gunthorpe
2025-03-05  2:50                                 ` Tian, Kevin
2025-03-05 17:22                                   ` Jason Gunthorpe
2025-03-06  2:41                                     ` Tian, Kevin
2025-03-14 12:54                                 ` Yi Liu
2025-03-04 10:15                             ` Vasant Hegde
2025-03-04 14:24                               ` Jason Gunthorpe
2025-03-10 16:35                                 ` Vasant Hegde
2025-03-14 12:09                                 ` Yi Liu
2025-03-19 19:52                                   ` Jason Gunthorpe
2025-03-14 12:22                               ` Yi Liu
2025-02-28  8:26                 ` Vasant Hegde
2025-02-28 14:56               ` Jason Gunthorpe
2025-03-03  2:55                 ` Tian, Kevin
2025-03-10 14:13                   ` Vasant Hegde
2025-03-12  6:55                     ` Tian, Kevin
2025-03-03 11:56                 ` Vasant Hegde
2025-02-26  4:47       ` Vasant Hegde
2025-02-26  7:10         ` Tian, Kevin
2025-02-26 13:01           ` Jason Gunthorpe
2025-02-26 22:42           ` Jerry Snitselaar
2025-02-27 16:04           ` Vasant Hegde
2025-02-28  0:04             ` Jason Gunthorpe
2025-02-28  6:18               ` Tian, Kevin
2025-02-28  1:47             ` Baolu Lu
2025-02-28  6:15               ` Tian, Kevin
2025-02-28  8:53                 ` Vasant Hegde
2025-02-28 14:53                 ` Jason Gunthorpe
2025-03-03  2:43                   ` Tian, Kevin
2025-02-28  8:38               ` Vasant Hegde
2025-02-26  4:33   ` 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.