Skip to contentSkip to conversation

iommu/amd: Add Generic IO Page Table Framework Support for v2 Page Table

PATCH Superseded Vasant Hegde 3 participants 11 messages Jul 13, 2022 – Jul 21, 2022

Subsystems (3)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Vasant Hegde

author maintainer
#0 lore raw

v2 cover iommu/amd: Add Generic IO Page Table Framework Support for v2 Page Table

This series introduces a new usage model for the v2 page table, where it can be used to implement support for DMA-API by adopting the generic IO page table framework.

One of the target usecases is to support nested IO page tables where the guest uses the guest IO page table (v2) for translating GVA to GPA, and the hypervisor uses the host I/O page table (v1) for translating GPA to SPA. This is a pre-requisite for supporting the new HW-assisted vIOMMU presented at the KVM Forum 2020.

https://static.sched.com/hosted_files/kvmforum2020/26/vIOMMU%20KVM%20Forum%202020.pdf

The following components are introduced in this series:

- Part 1 (patch 1-3 and 5)
Refactor the current IOMMU page table code to adopt the generic IO page table framework, and add AMD IOMMU Guest (v2) page table management code.

- Part 2 (patch 4)
Add support for the AMD IOMMU Guest IO Protection feature (GIOV) where requests from the I/O device without a PASID are treated as if they have PASID of 0.

- Part 3 (patch 6)
Introduce new "amd_iommu_pgtable" command-line to allow users to select the mode of operation (v1 or v2).

See AMD I/O Virtualization Technology Specification for more detail.

http://www.amd.com/system/files/TechDocs/48882_IOMMU_3.05_PUB.pdf

@Robin,
We are not addressing your comment on cleaning up pgsize_bitmap in this series. As mentioned in other thread [1] we can work on that as separate cleanup series.

[1] https://lore.kernel.org/linux-iommu/[email protected]/

Thanks,
Vasant

Changes from v1 -> v2 :
- Allow v2 page table only when FEATURE_GT is enabled
- V2 page table doesn't support IOMMU passthrough mode. Hence added check to fall back to v1 mode if system is booted with iommu=pt
- Overloaded amd_iommu command line option (removed amd_iommu_pgtable option)
- Override supported page sizes dynamically instead of selecting at boot time.

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

Changes from RFC -> v1:
- Addressed review comments from Joerg
- Reimplemented v2 page table

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

Suravee Suthikulpanit (4):
iommu/amd: Refactor amd_iommu_domain_enable_v2 to remove locking iommu/amd: Update sanity check when enable PRI/ATS for IOMMU v1 table iommu/amd: Add support for Guest IO protection
iommu/amd: Add support for using AMD IOMMU v2 page table for DMA-API

Vasant Hegde (2):
iommu/amd: Initial support for AMD IOMMU v2 page table iommu/amd: Add command-line option to enable different page table

 .../admin-guide/kernel-parameters.txt         |   2 +
 drivers/iommu/amd/Makefile                    |   2 +-
 drivers/iommu/amd/amd_iommu_types.h           |   8 +-
 drivers/iommu/amd/init.c                      |  36 +-
 drivers/iommu/amd/io_pgtable_v2.c             | 407 ++++++++++++++++++
 drivers/iommu/amd/iommu.c                     |  89 +++-
 drivers/iommu/io-pgtable.c                    |   1 +
 include/linux/io-pgtable.h                    |   2 +
 8 files changed, 518 insertions(+), 29 deletions(-)
 create mode 100644 drivers/iommu/amd/io_pgtable_v2.c
Signature · 1 line
2.31.1
author maintainer
#1 lore raw

PATCH v2 1/6 iommu/amd: Refactor amd_iommu_domain_enable_v2 to remove locking

From: Suravee Suthikulpanit <[email protected]>

The current function to enable IOMMU v2 also lock the domain. In order to reuse the same code in different code path, in which the domain has already been locked, refactor the function to separate the locking from the enabling logic.

---
Changes in v2:
- Remove unused has_ppr function param.

 drivers/iommu/amd/iommu.c | 46 +++++++++++++++++++++++----------------
 1 file changed, 27 insertions(+), 19 deletions(-)
drivers/iommu/amd/iommu.c +27 -19
index a56a9ad3273e..fd5dc6541569 100644
@@ -85,6 +85,7 @@ struct iommu_cmd {
 struct kmem_cache *amd_iommu_irq_cache;
 
 static void detach_device(struct device *dev);
+static int domain_enable_v2(struct protection_domain *domain, int pasids);
 
 /****************************************************************************
  *
@@ -2429,11 +2430,10 @@ void amd_iommu_domain_direct_map(struct iommu_domain *dom)
 }
 EXPORT_SYMBOL(amd_iommu_domain_direct_map);
 
-int amd_iommu_domain_enable_v2(struct iommu_domain *dom, int pasids)
+/* Note: This function expects iommu_domain->lock to be held prior calling the function. */
+static int domain_enable_v2(struct protection_domain *domain, int pasids)
 {
-	struct protection_domain *domain = to_pdomain(dom);
-	unsigned long flags;
-	int levels, ret;
+	int levels;
 
 	/* Number of GCR3 table levels required */
 	for (levels = 0; (pasids - 1) & ~0x1ff; pasids >>= 9)
@@ -2442,7 +2442,25 @@ int amd_iommu_domain_enable_v2(struct iommu_domain *dom, int pasids)
 	if (levels > amd_iommu_max_glx_val)
 		return -EINVAL;
 
-	spin_lock_irqsave(&domain->lock, flags);
+	domain->gcr3_tbl = (void *)get_zeroed_page(GFP_ATOMIC);
+	if (domain->gcr3_tbl == NULL)
+		return -ENOMEM;
+
+	domain->glx      = levels;
+	domain->flags   |= PD_IOMMUV2_MASK;
+
+	amd_iommu_domain_update(domain);
+
+	return 0;
+}
+
+int amd_iommu_domain_enable_v2(struct iommu_domain *dom, int pasids)
+{
+	struct protection_domain *pdom = to_pdomain(dom);
+	unsigned long flags;
+	int ret;
+
+	spin_lock_irqsave(&pdom->lock, flags);
 
 	/*
 	 * Save us all sanity checks whether devices already in the
@@ -2450,24 +2468,14 @@ int amd_iommu_domain_enable_v2(struct iommu_domain *dom, int pasids)
 	 * devices attached when it is switched into IOMMUv2 mode.
 	 */
 	ret = -EBUSY;
-	if (domain->dev_cnt > 0 || domain->flags & PD_IOMMUV2_MASK)
-		goto out;
-
-	ret = -ENOMEM;
-	domain->gcr3_tbl = (void *)get_zeroed_page(GFP_ATOMIC);
-	if (domain->gcr3_tbl == NULL)
+	if (pdom->dev_cnt > 0 || pdom->flags & PD_IOMMUV2_MASK)
 		goto out;
 
-	domain->glx      = levels;
-	domain->flags   |= PD_IOMMUV2_MASK;
-
-	amd_iommu_domain_update(domain);
-
-	ret = 0;
+	if (!pdom->gcr3_tbl)
+		ret = domain_enable_v2(pdom, pasids);
 
 out:
-	spin_unlock_irqrestore(&domain->lock, flags);
-
+	spin_unlock_irqrestore(&pdom->lock, flags);
 	return ret;
 }
 EXPORT_SYMBOL(amd_iommu_domain_enable_v2);
Signature · 1 line
2.31.1
author maintainer
#2 lore raw

PATCH v2 2/6 iommu/amd: Update sanity check when enable PRI/ATS for IOMMU v1 table

In reply to Vasant Hegde

From: Suravee Suthikulpanit <[email protected]>

Currently, PPR/ATS can be enabled only if the domain is type identity mapping. However, when allowing the IOMMU v2 page table to be used for DMA-API, the check is no longer valid.

Update the sanity check to only apply for when using AMD_IOMMU_V1 page table mode.

---
 drivers/iommu/amd/iommu.c | 14 +++++++++++---
 1 file changed, 11 insertions(+), 3 deletions(-)
drivers/iommu/amd/iommu.c +11 -3
index fd5dc6541569..027ecd5fb4b2 100644
@@ -1682,7 +1682,7 @@ static void pdev_iommuv2_disable(struct pci_dev *pdev)
 	pci_disable_pasid(pdev);
 }
 
-static int pdev_iommuv2_enable(struct pci_dev *pdev)
+static int pdev_pri_ats_enable(struct pci_dev *pdev)
 {
 	int ret;
 
@@ -1745,11 +1745,19 @@ static int attach_device(struct device *dev,
 		struct iommu_domain *def_domain = iommu_get_dma_domain(dev);
 
 		ret = -EINVAL;
-		if (def_domain->type != IOMMU_DOMAIN_IDENTITY)
+
+		/*
+		 * In case of using AMD_IOMMU_V1 page table mode and the device
+		 * is enabling for PPR/ATS support (using v2 table),
+		 * we need to make sure that the domain type is identity map.
+		 */
+		if ((amd_iommu_pgtable == AMD_IOMMU_V1) &&
+		    def_domain->type != IOMMU_DOMAIN_IDENTITY) {
 			goto out;
+		}
 
 		if (dev_data->iommu_v2) {
-			if (pdev_iommuv2_enable(pdev) != 0)
+			if (pdev_pri_ats_enable(pdev) != 0)
 				goto out;
 
 			dev_data->ats.enabled = true;
Signature · 1 line
2.31.1
author maintainer
#3 lore raw

PATCH v2 3/6 iommu/amd: Initial support for AMD IOMMU v2 page table

In reply to Vasant Hegde

Introduce IO page table framework support for AMD IOMMU v2 page table. This patch implements 4 level page table within iommu amd driver and supports 4K/2M/1G page sizes.

---
 drivers/iommu/amd/Makefile          |   2 +-
 drivers/iommu/amd/amd_iommu_types.h |   5 +-
 drivers/iommu/amd/io_pgtable_v2.c   | 407 ++++++++++++++++++++++++++++
 drivers/iommu/io-pgtable.c          |   1 +
 include/linux/io-pgtable.h          |   2 +
 5 files changed, 415 insertions(+), 2 deletions(-)
 create mode 100644 drivers/iommu/amd/io_pgtable_v2.c
drivers/iommu/amd/Makefile +1 -1
index a935f8f4b974..773d8aa00283 100644
@@ -1,4 +1,4 @@
 # SPDX-License-Identifier: GPL-2.0-only
-obj-$(CONFIG_AMD_IOMMU) += iommu.o init.o quirks.o io_pgtable.o
+obj-$(CONFIG_AMD_IOMMU) += iommu.o init.o quirks.o io_pgtable.o io_pgtable_v2.o
 obj-$(CONFIG_AMD_IOMMU_DEBUGFS) += debugfs.o
 obj-$(CONFIG_AMD_IOMMU_V2) += iommu_v2.o
drivers/iommu/amd/amd_iommu_types.h +4 -1
index 40f52d02c5b9..a6d6a3c7c5f3 100644
@@ -268,6 +268,8 @@
  * 512GB Pages are not supported due to a hardware bug
  */
 #define AMD_IOMMU_PGSIZES	((~0xFFFUL) & ~(2ULL << 38))
+/* 4K, 2MB, 1G page sizes are supported */
+#define AMD_IOMMU_PGSIZES_V2	(PAGE_SIZE | (1ULL << 21) | (1ULL << 30))
 
 /* Bit value definition for dte irq remapping fields*/
 #define DTE_IRQ_PHYS_ADDR_MASK	(((1ULL << 45)-1) << 6)
@@ -518,7 +520,8 @@ struct amd_io_pgtable {
 	struct io_pgtable	iop;
 	int			mode;
 	u64			*root;
-	atomic64_t		pt_root;    /* pgtable root and pgtable mode */
+	atomic64_t		pt_root;	/* pgtable root and pgtable mode */
+	u64			*pgd;		/* v2 pgtable pgd pointer */
 };
 
 /*
drivers/iommu/amd/io_pgtable_v2.c new file +407 -0

407 lines not on this page · raw message

drivers/iommu/io-pgtable.c +1 -0
index f4bfcef98297..ac02a45ed798 100644
@@ -27,6 +27,7 @@ io_pgtable_init_table[IO_PGTABLE_NUM_FMTS] = {
 #endif
 #ifdef CONFIG_AMD_IOMMU
 	[AMD_IOMMU_V1] = &io_pgtable_amd_iommu_v1_init_fns,
+	[AMD_IOMMU_V2] = &io_pgtable_amd_iommu_v2_init_fns,
 #endif
 };
 
include/linux/io-pgtable.h +2 -0
index 86af6f0a00a2..dc0f50bbdfa9 100644
@@ -16,6 +16,7 @@ enum io_pgtable_fmt {
 	ARM_V7S,
 	ARM_MALI_LPAE,
 	AMD_IOMMU_V1,
+	AMD_IOMMU_V2,
 	APPLE_DART,
 	IO_PGTABLE_NUM_FMTS,
 };
@@ -255,6 +256,7 @@ extern struct io_pgtable_init_fns io_pgtable_arm_64_lpae_s2_init_fns;
 extern struct io_pgtable_init_fns io_pgtable_arm_v7s_init_fns;
 extern struct io_pgtable_init_fns io_pgtable_arm_mali_lpae_init_fns;
 extern struct io_pgtable_init_fns io_pgtable_amd_iommu_v1_init_fns;
+extern struct io_pgtable_init_fns io_pgtable_amd_iommu_v2_init_fns;
 extern struct io_pgtable_init_fns io_pgtable_apple_dart_init_fns;
 
 #endif /* __IO_PGTABLE_H */
Signature · 1 line
2.31.1
reviewer
#4 lore raw

Re: [PATCH v2 3/6] iommu/amd: Initial support for AMD IOMMU v2 page table

On 2022-07-13 06:30, Vasant Hegde wrote:
[...]

Quoted 6 lines
drivers/iommu/amd/io_pgtable_v2.c new file +6 -0
+static struct io_pgtable *v2_alloc_pgtable(struct io_pgtable_cfg *cfg, void *cookie)
+{
+	struct amd_io_pgtable *pgtable = io_pgtable_cfg_to_data(cfg);
+	struct protection_domain *pdom = (struct protection_domain *)cookie;
+	int ret;
+

drivers/iommu/amd/io_pgtable_v2.c line 388

Quoted 10 lines
drivers/iommu/amd/io_pgtable_v2.c new file +10 -0
+	pgtable->pgd = alloc_pgtable_page();
+	if (!pgtable->pgd)
+		return NULL;
+
+	ret = amd_iommu_domain_set_gcr3(&pdom->domain, 0, iommu_virt_to_phys(pgtable->pgd));
+	if (ret)
+		goto err_free_pgd;
+
+	pgtable->iop.ops.map          = iommu_v2_map_page;
+	pgtable->iop.ops.unmap        = iommu_v2_unmap_page;

It would be good to use this opportunity to convert AMD over to map_pages/unmap_pages - not only for the future goal of removing map/unmap (it's not worth maintaining two interfaces where one is a trivial subset of the other), but also since it should be appreciably more efficient for you in practice, especially for v2 with the more limited set of basic page sizes.

Cheers,
Robin.

Quoted 14 lines
drivers/iommu/amd/io_pgtable_v2.c new file +14 -0
+	pgtable->iop.ops.iova_to_phys = iommu_v2_iova_to_phys;
+
+	cfg->pgsize_bitmap = AMD_IOMMU_PGSIZES_V2,
+	cfg->ias           = IOMMU_IN_ADDR_BIT_SIZE,
+	cfg->oas           = IOMMU_OUT_ADDR_BIT_SIZE,
+	cfg->tlb           = &v2_flush_ops;
+
+	return &pgtable->iop;
+
+err_free_pgd:
+	free_pgtable_page(pgtable->pgd);
+
+	return NULL;
+}
author maintainer
#5 lore raw

Re: [PATCH v2 3/6] iommu/amd: Initial support for AMD IOMMU v2 page table

Hi Robin,

Quoted 12 lines · Robin Murphy

On 2022-07-13 06:30, Vasant Hegde wrote:
[...]

Quoted 10 lines
drivers/iommu/amd/io_pgtable_v2.c new file +10 -0
+static struct io_pgtable *v2_alloc_pgtable(struct io_pgtable_cfg *cfg, void *cookie)
+{
+    struct amd_io_pgtable *pgtable = io_pgtable_cfg_to_data(cfg);
+    struct protection_domain *pdom = (struct protection_domain *)cookie;
+    int ret;
+
+    pgtable->pgd = alloc_pgtable_page();
+    if (!pgtable->pgd)
+        return NULL;
+
Quoted 9 lines
Quoted 6 lines

+    ret = amd_iommu_domain_set_gcr3(&pdom->domain, 0, iommu_virt_to_phys(pgtable->pgd)); +    if (ret)
+        goto err_free_pgd;
+
+    pgtable->iop.ops.map          = iommu_v2_map_page;
+    pgtable->iop.ops.unmap        = iommu_v2_unmap_page;

It would be good to use this opportunity to convert AMD over to map_pages/unmap_pages - not only for the future goal of removing map/unmap (it's not worth maintaining two interfaces where one is a trivial subset of the other), but also since it should be appreciably more efficient for you in practice, especially for v2 with the more limited set of basic page sizes.

Makes sense. I will work on this and post v3 soon.

Thanks
-Vasant

author maintainer
#6 lore raw

PATCH v2 4/6 iommu/amd: Add support for Guest IO protection

In reply to Vasant Hegde

From: Suravee Suthikulpanit <[email protected]>

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.

---
Changes in v2:
- Added passthrough mode check
- Added FEATURE_GT check

 drivers/iommu/amd/amd_iommu_types.h |  3 +++
 drivers/iommu/amd/init.c            | 13 +++++++++++++
 drivers/iommu/amd/iommu.c           |  4 ++++
 3 files changed, 20 insertions(+)
drivers/iommu/amd/amd_iommu_types.h +3 -0
index a6d6a3c7c5f3..63bf521ba20c 100644
@@ -93,6 +93,7 @@
 #define FEATURE_HE		(1ULL<<8)
 #define FEATURE_PC		(1ULL<<9)
 #define FEATURE_GAM_VAPIC	(1ULL<<21)
+#define FEATURE_GIOSUP		(1ULL<<48)
 #define FEATURE_EPHSUP		(1ULL<<50)
 #define FEATURE_SNP		(1ULL<<63)
 
@@ -370,6 +371,7 @@
 #define DTE_FLAG_IW (1ULL << 62)
 
 #define DTE_FLAG_IOTLB	(1ULL << 32)
+#define DTE_FLAG_GIOV	(1ULL << 54)
 #define DTE_FLAG_GV	(1ULL << 55)
 #define DTE_FLAG_MASK	(0x3ffULL << 32)
 #define DTE_GLX_SHIFT	(56)
@@ -428,6 +430,7 @@
 #define PD_PASSTHROUGH_MASK	(1UL << 2) /* domain has no page
 					      translation */
 #define PD_IOMMUV2_MASK		(1UL << 3) /* domain has gcr3 table */
+#define PD_GIOV_MASK		(1UL << 4) /* domain enable GIOV support */
 
 extern bool amd_iommu_dump;
 #define DUMP_printk(format, arg...)				\
drivers/iommu/amd/init.c +13 -0
index 3c82d9c5f1c0..a2929d8b44f4 100644
@@ -2026,6 +2026,17 @@ static int __init iommu_init_pci(struct amd_iommu *iommu)
 
 	init_iommu_perf_ctr(iommu);
 
+	if (amd_iommu_pgtable == AMD_IOMMU_V2) {
+		if (!iommu_feature(iommu, FEATURE_GIOSUP) ||
+		    !iommu_feature(iommu, FEATURE_GT)) {
+			pr_warn("Cannot enable v2 page table for DMA-API. Fallback to v1.\n");
+			amd_iommu_pgtable = AMD_IOMMU_V1;
+		} else if (iommu_default_passthrough()) {
+			pr_warn("V2 page table doesn't support passthrough mode. Fallback to v1.\n");
+			amd_iommu_pgtable = AMD_IOMMU_V1;
+		}
+	}
+
 	if (is_rd890_iommu(iommu->dev)) {
 		int i, j;
 
@@ -2100,6 +2111,8 @@ static void print_iommu_info(void)
 		if (amd_iommu_xt_mode == IRQ_REMAP_X2APIC_MODE)
 			pr_info("X2APIC enabled\n");
 	}
+	if (amd_iommu_pgtable == AMD_IOMMU_V2)
+		pr_info("V2 page table enabled\n");
 }
 
 static int __init amd_iommu_init_pci(void)
drivers/iommu/amd/iommu.c +4 -0
index 027ecd5fb4b2..2e67e6eecc31 100644
@@ -1553,6 +1553,7 @@ static void set_dte_entry(struct amd_iommu *iommu, u16 devid,
 
 	pte_root |= (domain->iop.mode & DEV_ENTRY_MODE_MASK)
 		    << DEV_ENTRY_MODE_SHIFT;
+
 	pte_root |= DTE_FLAG_IR | DTE_FLAG_IW | DTE_FLAG_V | DTE_FLAG_TV;
 
 	flags = dev_table[devid].data[1];
@@ -1589,6 +1590,9 @@ static void set_dte_entry(struct amd_iommu *iommu, u16 devid,
 
 		tmp = DTE_GCR3_VAL_C(gcr3) << DTE_GCR3_SHIFT_C;
 		flags    |= tmp;
+
+		if (domain->flags & PD_GIOV_MASK)
+			pte_root |= DTE_FLAG_GIOV;
 	}
 
 	flags &= ~DEV_DOMID_MASK;
Signature · 1 line
2.31.1
author maintainer
#7 lore raw

PATCH v2 5/6 iommu/amd: Add support for using AMD IOMMU v2 page table for DMA-API

In reply to Vasant Hegde

From: Suravee Suthikulpanit <[email protected]>

Introduce init function for setting up DMA domain for DMA-API with the IOMMU v2 page table.

---
Changes in v2:
- Added support to change supported page sizes dynamically based on domain type.

 drivers/iommu/amd/iommu.c | 25 +++++++++++++++++++++++++
 1 file changed, 25 insertions(+)
drivers/iommu/amd/iommu.c +25 -0
index 2e67e6eecc31..372621dfc526 100644
@@ -1642,6 +1642,10 @@ static void do_attach(struct iommu_dev_data *dev_data,
 	domain->dev_iommu[iommu->index] += 1;
 	domain->dev_cnt                 += 1;
 
+	/* Override supported page sizes */
+	if (domain->flags & PD_GIOV_MASK)
+		domain->domain.pgsize_bitmap = AMD_IOMMU_PGSIZES_V2;
+
 	/* Update device table */
 	set_dte_entry(iommu, dev_data->devid, domain,
 		      ats, dev_data->iommu_v2);
@@ -2021,6 +2025,24 @@ static int protection_domain_init_v1(struct protection_domain *domain, int mode)
 	return 0;
 }
 
+static int protection_domain_init_v2(struct protection_domain *domain)
+{
+	spin_lock_init(&domain->lock);
+	domain->id = domain_id_alloc();
+	if (!domain->id)
+		return -ENOMEM;
+	INIT_LIST_HEAD(&domain->dev_list);
+
+	domain->flags |= PD_GIOV_MASK;
+
+	if (domain_enable_v2(domain, 1)) {
+		domain_id_free(domain->id);
+		return -ENOMEM;
+	}
+
+	return 0;
+}
+
 static struct protection_domain *protection_domain_alloc(unsigned int type)
 {
 	struct io_pgtable_ops *pgtbl_ops;
@@ -2048,6 +2070,9 @@ static struct protection_domain *protection_domain_alloc(unsigned int type)
 	case AMD_IOMMU_V1:
 		ret = protection_domain_init_v1(domain, mode);
 		break;
+	case AMD_IOMMU_V2:
+		ret = protection_domain_init_v2(domain);
+		break;
 	default:
 		ret = -EINVAL;
 	}
Signature · 1 line
2.31.1
author maintainer
#8 lore raw

PATCH v2 6/6 iommu/amd: Add command-line option to enable different page table

In reply to Vasant Hegde

Enhance amd_iommu command line option to specify v1 or v2 page table. By default system will boot in V1 page table mode.

---
Changes in v2:
- Removed separate command line option and enhace amd_iommu option
- Update document

 .../admin-guide/kernel-parameters.txt         |  2 ++
 drivers/iommu/amd/init.c                      | 23 +++++++++++++++----
 2 files changed, 20 insertions(+), 5 deletions(-)
Documentation/admin-guide/kernel-parameters.txt +2 -0
index d45e58328ce6..d1919bf4f37a 100644
@@ -321,6 +321,8 @@
 			force_enable - Force enable the IOMMU on platforms known
 				       to be buggy with IOMMU enabled. Use this
 				       option with care.
+			pgtbl_v1     - Use v1 page table for DMA-API (Default).
+			pgtbl_v2     - Use v2 page table for DMA-API.
 
 	amd_iommu_dump=	[HW,X86-64]
 			Enable AMD IOMMU driver option to dump the ACPI table
drivers/iommu/amd/init.c +18 -5
index a2929d8b44f4..673c263fea8d 100644
@@ -3287,17 +3287,30 @@ static int __init parse_amd_iommu_intr(char *str)
 
 static int __init parse_amd_iommu_options(char *str)
 {
-	for (; *str; ++str) {
+	if (!str)
+		return -EINVAL;
+
+	while (*str) {
 		if (strncmp(str, "fullflush", 9) == 0) {
 			pr_warn("amd_iommu=fullflush deprecated; use iommu.strict=1 instead\n");
 			iommu_set_dma_strict();
-		}
-		if (strncmp(str, "force_enable", 12) == 0)
+		} else if (strncmp(str, "force_enable", 12) == 0) {
 			amd_iommu_force_enable = true;
-		if (strncmp(str, "off", 3) == 0)
+		} else if (strncmp(str, "off", 3) == 0) {
 			amd_iommu_disabled = true;
-		if (strncmp(str, "force_isolation", 15) == 0)
+		} else if (strncmp(str, "force_isolation", 15) == 0) {
 			amd_iommu_force_isolation = true;
+		} else if (strncmp(str, "pgtbl_v1", 8) == 0) {
+			amd_iommu_pgtable = AMD_IOMMU_V1;
+		} else if (strncmp(str, "pgtbl_v2", 8) == 0) {
+			amd_iommu_pgtable = AMD_IOMMU_V2;
+		} else {
+			pr_notice("Unknown option - '%s'\n", str);
+		}
+
+		str += strcspn(str, ",");
+		while (*str == ',')
+			str++;
 	}
 
 	return 1;
Signature · 1 line
2.31.1
maintainer
#9 lore raw
In reply to Vasant Hegde

Hi Vassant,

Quoted 9 lines · Vasant Hegde

Suravee Suthikulpanit (4):
iommu/amd: Refactor amd_iommu_domain_enable_v2 to remove locking iommu/amd: Update sanity check when enable PRI/ATS for IOMMU v1 table iommu/amd: Add support for Guest IO protection
iommu/amd: Add support for using AMD IOMMU v2 page table for DMA-API

Vasant Hegde (2):
iommu/amd: Initial support for AMD IOMMU v2 page table iommu/amd: Add command-line option to enable different page table

Thanks for the submission, but I have to defer it until the next cycle. With the PCI multi-domain support and the SNP-enablement there are already some intrusive patches queued up for the AMD driver, and I want to let the dust settle around those first.

Please remind me after the next merge window about this series.

Thanks,

Joerg

author maintainer
#10 lore raw

Hi Joerg,

Quoted 13 lines · Joerg Roedel

Hi Vassant,

Quoted 9 lines · Vasant Hegde

Suravee Suthikulpanit (4):
iommu/amd: Refactor amd_iommu_domain_enable_v2 to remove locking iommu/amd: Update sanity check when enable PRI/ATS for IOMMU v1 table iommu/amd: Add support for Guest IO protection
iommu/amd: Add support for using AMD IOMMU v2 page table for DMA-API

Vasant Hegde (2):
iommu/amd: Initial support for AMD IOMMU v2 page table iommu/amd: Add command-line option to enable different page table

Quoted 6 lines

Thanks for the submission, but I have to defer it until the next cycle. With the PCI multi-domain support and the SNP-enablement there are already some intrusive patches queued up for the AMD driver, and I want to let the dust settle around those first.

Please remind me after the next merge window about this series.

Sure. Probably I will do v3 soon with map/unmap_pages interface.

Thanks
-Vasant

Quoted 4 lines

Thanks,

Joerg