iommu/amd: Add Generic IO Page Table Framework Support for v2 Page Table
Subsystems (3)
Vasant Hegde
maintainerv3 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)
Move AMD v1 page table to use [un]map_pages interfaces and minor fixes to unmap path.
- Part 1 (patch 4-5 and 8)
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 7)
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 9)
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
Thanks,
Vasant
Changes from v2 -> v3 :
- As Robin suggested added support to use [un]map_pages interface (Patch 1 - 3)
- Removed [un]map interface from AMD IOMMU driver
- Updated v2 page table to use [un]map_pages interface
V2 patchset: https://lore.kernel.org/linux-iommu/[email protected]/
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 (5):
iommu/amd/io-pgtable: Implement map_pages io_pgtable_ops callback iommu/amd/io-pgtable: Implement unmap_pages io_pgtable_ops callback iommu/amd: Add map/unmap_pages() iommu_domain_ops callback support 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.c | 76 ++-- drivers/iommu/amd/io_pgtable_v2.c | 415 ++++++++++++++++++ drivers/iommu/amd/iommu.c | 117 +++-- drivers/iommu/io-pgtable.c | 1 + include/linux/io-pgtable.h | 2 + 9 files changed, 584 insertions(+), 75 deletions(-) create mode 100644 drivers/iommu/amd/io_pgtable_v2.c
Signature · 1 line
2.31.1
Vasant Hegde
maintainerPATCH v3 1/9 iommu/amd/io-pgtable: Implement map_pages io_pgtable_ops callback
Implement the io_pgtable_ops->map_pages() callback for AMD driver. Also deprecate io_pgtable->map callback.
--- drivers/iommu/amd/io_pgtable.c | 59 ++++++++++++++++++++-------------- 1 file changed, 34 insertions(+), 25 deletions(-)
drivers/iommu/amd/io_pgtable.c +34 -25
@@ -360,8 +360,9 @@ static void free_clear_pte(u64 *pte, u64 pteval, struct list_head *freelist)* supporting all features of AMD IOMMU page tables like level skipping * and full 64 bit address spaces. */ -static int iommu_v1_map_page (struct io_pgtable_ops *ops,unsigned long iova, -phys_addr_t paddr,size_t size,int prot,gfp_t gfp) +static int iommu_v1_map_pages (struct io_pgtable_ops *ops,unsigned long iova, +phys_addr_t paddr,size_t pgsize,size_t pgcount, +int prot,gfp_t gfp,size_t *mapped) {struct protection_domain *dom =io_pgtable_ops_to_domain (ops);LIST_HEAD (freelist);
@@ -369,39 +370,47 @@ static int iommu_v1_map_page(struct io_pgtable_ops *ops, unsigned long iova,u64 __pte, *pte;int ret, i, count; -BUG_ON (!IS_ALIGNED (iova, size)); -BUG_ON (!IS_ALIGNED (paddr, size)); +BUG_ON (!IS_ALIGNED (iova, pgsize)); +BUG_ON (!IS_ALIGNED (paddr, pgsize)); ret = -EINVAL ;if (!(prot &IOMMU_PROT_MASK )) goto out; - count =PAGE_SIZE_PTE_COUNT (size); - pte =alloc_pte (dom, iova, size,NULL , gfp, &updated); +while (pgcount >0 ) { + count =PAGE_SIZE_PTE_COUNT (pgsize); + pte =alloc_pte (dom, iova, pgsize,NULL , gfp, &updated); - ret = -ENOMEM ; -if (!pte) - goto out; + ret = -ENOMEM ; +if (!pte) + goto out; -for (i =0 ; i < count; ++i) -free_clear_pte (&pte[i], pte[i], &freelist); +for (i =0 ; i < count; ++i) +free_clear_pte (&pte[i], pte[i], &freelist); -if (!list_empty (&freelist)) - updated = true; +if (!list_empty (&freelist)) + updated = true; -if (count >1 ) { - __pte =PAGE_SIZE_PTE (__sme_set (paddr), size); - __pte |=PM_LEVEL_ENC (7 ) |IOMMU_PTE_PR |IOMMU_PTE_FC ; - }else - __pte =__sme_set (paddr) |IOMMU_PTE_PR |IOMMU_PTE_FC ; +if (count >1 ) { + __pte =PAGE_SIZE_PTE (__sme_set (paddr), pgsize); + __pte |=PM_LEVEL_ENC (7 ) |IOMMU_PTE_PR |IOMMU_PTE_FC ; + }else + __pte =__sme_set (paddr) |IOMMU_PTE_PR |IOMMU_PTE_FC ; -if (prot &IOMMU_PROT_IR ) - __pte |=IOMMU_PTE_IR ; -if (prot &IOMMU_PROT_IW ) - __pte |=IOMMU_PTE_IW ; +if (prot &IOMMU_PROT_IR ) + __pte |=IOMMU_PTE_IR ; +if (prot &IOMMU_PROT_IW ) + __pte |=IOMMU_PTE_IW ; -for (i =0 ; i < count; ++i) - pte[i] = __pte; +for (i =0 ; i < count; ++i) + pte[i] = __pte; + + iova += pgsize; + paddr += pgsize; + pgcount--; +if (mapped) + *mapped += pgsize; + } ret =0 ;
@@ -514,7 +523,7 @@ static struct io_pgtable *v1_alloc_pgtable(struct io_pgtable_cfg *cfg, void *coo cfg->oas =IOMMU_OUT_ADDR_BIT_SIZE , cfg->tlb = &v1_flush_ops; - pgtable->iop.ops.map = iommu_v1_map_page; + pgtable->iop.ops.map_pages = iommu_v1_map_pages; pgtable->iop.ops.unmap = iommu_v1_unmap_page; pgtable->iop.ops.iova_to_phys = iommu_v1_iova_to_phys;
Signature · 1 line
2.31.1
Vasant Hegde
maintainerPATCH v3 2/9 iommu/amd/io-pgtable: Implement unmap_pages io_pgtable_ops callback
In reply to Vasant HegdeImplement the io_pgtable_ops->unmap_pages() callback for AMD driver and deprecate io_pgtable_ops->unmap callback.
Also if fetch_pte() returns NULL then return from unmap_mapages() instead of trying to continue to unmap remaining pages.
--- drivers/iommu/amd/io_pgtable.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-)
drivers/iommu/amd/io_pgtable.c +9 -8
@@ -435,17 +435,18 @@ static int iommu_v1_map_pages(struct io_pgtable_ops *ops, unsigned long iova,return ret; } -static unsigned long iommu_v1_unmap_page (struct io_pgtable_ops *ops, -unsigned long iova, -size_t size, -struct iommu_iotlb_gather *gather) +static unsigned long iommu_v1_unmap_pages (struct io_pgtable_ops *ops, +unsigned long iova, +size_t pgsize,size_t pgcount, +struct iommu_iotlb_gather *gather) {struct amd_io_pgtable *pgtable =io_pgtable_ops_to_data (ops);unsigned long long unmapped;unsigned long unmap_size;u64 *pte; +size_t size = pgcount <<__ffs (pgsize); -BUG_ON (!is_power_of_2 (size)); +BUG_ON (!is_power_of_2 (pgsize)); unmapped =0 ;
@@ -457,14 +458,14 @@ static unsigned long iommu_v1_unmap_page(struct io_pgtable_ops *ops, count =PAGE_SIZE_PTE_COUNT (unmap_size);for (i =0 ; i < count; i++) pte[i] =0ULL ; + }else { +return unmapped; } iova = (iova & ~(unmap_size -1 )) + unmap_size; unmapped += unmap_size; } -BUG_ON (unmapped && !is_power_of_2 (unmapped)); -return unmapped; }
@@ -524,7 +525,7 @@ static struct io_pgtable *v1_alloc_pgtable(struct io_pgtable_cfg *cfg, void *coo cfg->tlb = &v1_flush_ops; pgtable->iop.ops.map_pages = iommu_v1_map_pages; - pgtable->iop.ops.unmap = iommu_v1_unmap_page; + pgtable->iop.ops.unmap_pages = iommu_v1_unmap_pages; pgtable->iop.ops.iova_to_phys = iommu_v1_iova_to_phys;return &pgtable->iop;
Signature · 1 line
2.31.1
Vasant Hegde
maintainerPATCH v3 3/9 iommu/amd: Add map/unmap_pages() iommu_domain_ops callback support
In reply to Vasant HegdeImplement the map_pages() and unmap_pages() callback for the AMD IOMMU driver to allow calls from iommu core to map and unmap multiple pages. Also deprecate map/unmap callbacks.
Finally gatherer is not updated by iommu_v1_unmap_pages(). Hence pass NULL instead of gather to iommu_v1_unmap_pages.
--- drivers/iommu/amd/iommu.c | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-)
drivers/iommu/amd/iommu.c +16 -13
@@ -2174,13 +2174,13 @@ static void amd_iommu_iotlb_sync_map(struct iommu_domain *dom,struct protection_domain *domain =to_pdomain (dom);struct io_pgtable_ops *ops = &domain->iop.iop.ops; -if (ops->map) +if (ops->map_pages)domain_flush_np_cache (domain, iova, size); } -static int amd_iommu_map (struct iommu_domain *dom,unsigned long iova, -phys_addr_t paddr,size_t page_size,int iommu_prot, -gfp_t gfp) +static int amd_iommu_map_pages (struct iommu_domain *dom,unsigned long iova, +phys_addr_t paddr,size_t pgsize,size_t pgcount, +int iommu_prot,gfp_t gfp,size_t *mapped) {struct protection_domain *domain =to_pdomain (dom);struct io_pgtable_ops *ops = &domain->iop.iop.ops;
@@ -2196,8 +2196,10 @@ static int amd_iommu_map(struct iommu_domain *dom, unsigned long iova,if (iommu_prot &IOMMU_WRITE ) prot |=IOMMU_PROT_IW ; -if (ops->map) - ret = ops->map (ops, iova, paddr, page_size, prot, gfp); +if (ops->map_pages) { + ret = ops->map_pages (ops, iova, paddr, pgsize, + pgcount, prot, gfp, mapped); + }return ret; }
@@ -2223,9 +2225,9 @@ static void amd_iommu_iotlb_gather_add_page(struct iommu_domain *domain,iommu_iotlb_gather_add_range (gather, iova, size); } -static size_t amd_iommu_unmap (struct iommu_domain *dom,unsigned long iova, -size_t page_size, -struct iommu_iotlb_gather *gather) +static size_t amd_iommu_unmap_pages (struct iommu_domain *dom,unsigned long iova, +size_t pgsize,size_t pgcount, +struct iommu_iotlb_gather *gather) {struct protection_domain *domain =to_pdomain (dom);struct io_pgtable_ops *ops = &domain->iop.iop.ops;
@@ -2235,9 +2237,10 @@ static size_t amd_iommu_unmap(struct iommu_domain *dom, unsigned long iova, (domain->iop.mode == PAGE_MODE_NONE))return 0 ; - r = (ops->unmap) ? ops->unmap (ops, iova, page_size, gather) :0 ; + r = (ops->unmap_pages) ? ops->unmap_pages (ops, iova, pgsize, pgcount,NULL ) :0 ; -amd_iommu_iotlb_gather_add_page (dom, gather, iova, page_size); +if (r) +amd_iommu_iotlb_gather_add_page (dom, gather, iova, r);return r; }
@@ -2400,8 +2403,8 @@ const struct iommu_ops amd_iommu_ops = { .default_domain_ops = &(const struct iommu_domain_ops) { .attach_dev = amd_iommu_attach_device, .detach_dev = amd_iommu_detach_device, - .map = amd_iommu_map, - .unmap = amd_iommu_unmap, + .map_pages = amd_iommu_map_pages, + .unmap_pages = amd_iommu_unmap_pages, .iotlb_sync_map = amd_iommu_iotlb_sync_map, .iova_to_phys = amd_iommu_iova_to_phys, .flush_iotlb_all = amd_iommu_flush_iotlb_all,
Signature · 1 line
2.31.1
Vasant Hegde
maintainerPATCH v3 4/9 iommu/amd: Refactor amd_iommu_domain_enable_v2 to remove locking
In reply to Vasant HegdeFrom: 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
@@ -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);/**************************************************************************** *
@@ -2451,11 +2452,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 )
@@ -2464,7 +2464,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
@@ -2472,24 +2490,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
Vasant Hegde
maintainerPATCH v3 5/9 iommu/amd: Update sanity check when enable PRI/ATS for IOMMU v1 table
In reply to Vasant HegdeFrom: 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
@@ -1694,7 +1694,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;
@@ -1757,11 +1757,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
Vasant Hegde
maintainerPATCH v3 6/9 iommu/amd: Initial support for AMD IOMMU v2 page table
In reply to Vasant HegdeIntroduce 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.
---
Changes in v3:
- Replaced [un]map interface with [un]map_pages interface
- Added error handing support in unmap_pages()
drivers/iommu/amd/Makefile | 2 +- drivers/iommu/amd/amd_iommu_types.h | 5 +- drivers/iommu/amd/io_pgtable_v2.c | 415 ++++++++++++++++++++++++++++ drivers/iommu/io-pgtable.c | 1 + include/linux/io-pgtable.h | 2 + 5 files changed, 423 insertions(+), 2 deletions(-) create mode 100644 drivers/iommu/amd/io_pgtable_v2.c
drivers/iommu/amd/Makefile +1 -1
@@ -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
@@ -269,6 +269,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)
@@ -519,7 +521,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 +415 -0
415 lines not on this page · raw message
drivers/iommu/io-pgtable.c +1 -0
@@ -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
@@ -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
Vasant Hegde
maintainerPATCH v3 7/9 iommu/amd: Add support for Guest IO protection
In reply to Vasant HegdeFrom: 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 | 3 +++ 3 files changed, 19 insertions(+)
drivers/iommu/amd/amd_iommu_types.h +3 -0
@@ -94,6 +94,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)
@@ -371,6 +372,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)
@@ -429,6 +431,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
@@ -2080,6 +2080,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;
@@ -2160,6 +2171,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 +3 -0
@@ -1597,6 +1597,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
Vasant Hegde
maintainerPATCH v3 8/9 iommu/amd: Add support for using AMD IOMMU v2 page table for DMA-API
In reply to Vasant HegdeFrom: 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 based on domain type.
drivers/iommu/amd/iommu.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+)
drivers/iommu/amd/iommu.c +25 -0
@@ -1653,6 +1653,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);
@@ -2032,6 +2036,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;
@@ -2059,6 +2081,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
Vasant Hegde
maintainerPATCH v3 9/9 iommu/amd: Add command-line option to enable different page table
In reply to Vasant HegdeEnhance 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
.../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
@@ -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
@@ -3348,17 +3348,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
Vasant Hegde
maintainerHi Joerg, Robin,
Ping. Did you get a chance to look into this series?
-Vasant
Quoted 88 lines · Vasant Hegde
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)
Move AMD v1 page table to use [un]map_pages interfaces and minor fixes to unmap path.- Part 1 (patch 4-5 and 8)
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 7)
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 9)
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
Thanks,
VasantChanges from v2 -> v3 :
- As Robin suggested added support to use [un]map_pages interface (Patch 1 - 3)
- Removed [un]map interface from AMD IOMMU driver
- Updated v2 page table to use [un]map_pages interfaceV2 patchset: https://lore.kernel.org/linux-iommu/[email protected]/
Changes from v1 -> v2 :
- Allow v2 page table only whenFEATURE_GTis 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
- Overloadedamd_iommucommand line option (removedamd_iommu_pgtableoption)
- 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 tableRFC patchset : https://lore.kernel.org/linux-iommu/[email protected]/T/#t
Suravee Suthikulpanit (4):
iommu/amd: Refactoramd_iommu_domain_enable_v2to 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-APIVasant Hegde (5):
iommu/amd/io-pgtable: Implementmap_pagesio_pgtable_opscallback iommu/amd/io-pgtable: Implementunmap_pagesio_pgtable_opscallback iommu/amd: Add map/unmap_pages()iommu_domain_opscallback support 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.c | 76 ++-- drivers/iommu/amd/io_pgtable_v2.c | 415 ++++++++++++++++++ drivers/iommu/amd/iommu.c | 117 +++-- drivers/iommu/io-pgtable.c | 1 + include/linux/io-pgtable.h | 2 + 9 files changed, 584 insertions(+), 75 deletions(-) create mode 100644 drivers/iommu/amd/io_pgtable_v2.c
Robin Murphy
reviewerQuoted 3 lines · Vasant Hegde
Hi Joerg, Robin,
Ping. Did you get a chance to look into this series?
The io-pgtable patches look OK to me at a glance (I'd be inclined to squash #2 into #1, but it's your choice). One thing that's not so obvious, though, is how this all interacts with amd_iommu_def_domain_type() that currently tries to force identity domains for IOMMUv2 devices - does that mean that this support won't actually be used a lot of the time, and/or is that override still necessary?
There's also a thread going on elsewhere that I suspect might tie in here as well:
https://lore.kernel.org/regressions/[email protected]/
Will this series also mean that the domain shenanigans in amd_iommu_init_device() can be replaced by just making sure the GPU gets the proper type of v2 default domain in the first place, so KFD can use its PASIDs on top of that directly, and the audio driver problem goes away naturally?
Thanks,
Robin.
Quoted 93 lines
-Vasant
Quoted 88 lines · Vasant Hegde
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.pdfThe following components are introduced in this series:
- Part 1 (patch 1-3)
Move AMD v1 page table to use [un]map_pages interfaces and minor fixes to unmap path.- Part 1 (patch 4-5 and 8)
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 7)
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 9)
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.pdfThanks,
VasantChanges from v2 -> v3 :
- As Robin suggested added support to use [un]map_pages interface (Patch 1 - 3)
- Removed [un]map interface from AMD IOMMU driver
- Updated v2 page table to use [un]map_pages interfaceV2 patchset: https://lore.kernel.org/linux-iommu/[email protected]/
Changes from v1 -> v2 :
- Allow v2 page table only whenFEATURE_GTis 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
- Overloadedamd_iommucommand line option (removedamd_iommu_pgtableoption)
- 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 tableRFC patchset : https://lore.kernel.org/linux-iommu/[email protected]/T/#t
Suravee Suthikulpanit (4):
iommu/amd: Refactoramd_iommu_domain_enable_v2to 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-APIVasant Hegde (5):
iommu/amd/io-pgtable: Implementmap_pagesio_pgtable_opscallback iommu/amd/io-pgtable: Implementunmap_pagesio_pgtable_opscallback iommu/amd: Add map/unmap_pages()iommu_domain_opscallback support 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.c | 76 ++-- drivers/iommu/amd/io_pgtable_v2.c | 415 ++++++++++++++++++ drivers/iommu/amd/iommu.c | 117 +++-- drivers/iommu/io-pgtable.c | 1 + include/linux/io-pgtable.h | 2 + 9 files changed, 584 insertions(+), 75 deletions(-)create mode 100644
drivers/iommu/amd/io_pgtable_v2.c
Joerg Roedel
maintainerQuoted 5 lines · Robin Murphy
Will this series also mean that the domain shenanigans in
amd_iommu_init_device()can be replaced by just making sure the GPU gets the proper type of v2 default domain in the first place, so KFD can use its PASIDs on top of that directly, and the audio driver problem goes away naturally?
Yes, on IOMMUs supporting v2 page-tables and declaring a default PASID this hack can go away. Unfortunately a lot of AMD IOMMUs in the field do not, so the identity mapping hack needs to stay around.
Quoted 10 lines · Joerg Roedel
Quoted 5 lines · Robin Murphy
Will this series also mean that the domain shenanigans in
amd_iommu_init_device()can be replaced by just making sure the GPU gets the proper type of v2 default domain in the first place, so KFD can use its PASIDs on top of that directly, and the audio driver problem goes away naturally?Yes, on IOMMUs supporting v2 page-tables and declaring a default PASID this hack can go away. Unfortunately a lot of AMD IOMMUs in the field do not, so the identity mapping hack needs to stay around.
Why can an identity map be attached to the RID in v2, but not a full translation? It seems like a very strange design that entering PASID mode completely breaks RID support..
Jason
Robin Murphy
reviewerQuoted 8 lines · Jason Gunthorpe
Quoted 7 lines · Joerg Roedel
Quoted 5 lines · Robin Murphy
Will this series also mean that the domain shenanigans in
amd_iommu_init_device()can be replaced by just making sure the GPU gets the proper type of v2 default domain in the first place, so KFD can use its PASIDs on top of that directly, and the audio driver problem goes away naturally?
Quoted 7 lines
Quoted 3 lines
Yes, on IOMMUs supporting v2 page-tables and declaring a default PASID this hack can go away. Unfortunately a lot of AMD IOMMUs in the field do not, so the identity mapping hack needs to stay around.
Why can an identity map be attached to the RID in v2, but not a full translation? It seems like a very strange design that entering PASID mode completely breaks RID support..
FWIW we have the opposite problem on SMMUv3 - if we're using PASIDs then we can't bypass the RID, it *has* to map to a translation context (as PASID 0). I can only guess that nobody's yet tried the combination of SVA plus IOMMU_DEFAULT_PASSTHROUGH plus the device sending MSIs (and not on the dodgy machine where MSIs bypass the SMMU in hardware)... :/
Anyway, fair enough if def_domain_type still has to force IOMMU_DOMAIN_IDENTITY in some cases here, but presumably that still wouldn't prevent us from enabling v2 on those from the outset and avoiding the mysterious and problematic "concoct an identity domain to replace the identity domain" dance?
Thanks,
Robin.
Quoted 17 lines · Robin Murphy
Quoted 8 lines · Jason Gunthorpe
Quoted 7 lines · Joerg Roedel
Quoted 5 lines · Robin Murphy
Will this series also mean that the domain shenanigans in
amd_iommu_init_device()can be replaced by just making sure the GPU gets the proper type of v2 default domain in the first place, so KFD can use its PASIDs on top of that directly, and the audio driver problem goes away naturally?Quoted 7 lines
Quoted 3 lines
Yes, on IOMMUs supporting v2 page-tables and declaring a default PASID this hack can go away. Unfortunately a lot of AMD IOMMUs in the field do not, so the identity mapping hack needs to stay around.
Why can an identity map be attached to the RID in v2, but not a full translation? It seems like a very strange design that entering PASID mode completely breaks RID support..
Quoted 5 lines
FWIW we have the opposite problem on SMMUv3 - if we're using PASIDs then we can't bypass the RID, it *has* to map to a translation context (as PASID 0). I can only guess that nobody's yet tried the combination of SVA plus
IOMMU_DEFAULT_PASSTHROUGHplus the device sending MSIs (and not on the dodgy machine where MSIs bypass the SMMU in hardware)... :/
This at least makes more sense to me, SW has the ability to apply a translation and if the requirement is an identity translation it can at least make one, at the cost of performance and memory..
So, looking at bit at the smmuv3 code, if arm_smmu_write_strtab_ent() was called with stage == BYPASS on the RID then it sets a STE up for bypass operation and there is no s1contextptr, but then arm_smmu_write_ctx_desc() will come along later and try to access the cdtab?
It seems like it needs to upgrade the STE to have an s1contextptr and point substream 0 at an iopte setting up an identity mapping?
But doesn't this mean that the SVA is the thing that doesn't work if the RID is set to identity?
Jason
Joerg Roedel
maintainerQuoted 3 lines · Jason Gunthorpe
Why can an identity map be attached to the RID in v2, but not a full translation? It seems like a very strange design that entering PASID mode completely breaks RID support.
The reason is that AMD IOMMUs do two-level translation, which means that the addresses in the PASID page-tables are translated via the v1 page-table again. In order to be able to use Linux page-tables for PASID mappings the v1 page-table needs to be identity mapped.
Regards,
Joerg
Robin Murphy
reviewerQuoted 9 lines · Joerg Roedel
Quoted 3 lines · Jason Gunthorpe
Why can an identity map be attached to the RID in v2, but not a full translation? It seems like a very strange design that entering PASID mode completely breaks RID support.
The reason is that AMD IOMMUs do two-level translation, which means that the addresses in the PASID page-tables are translated via the v1 page-table again. In order to be able to use Linux page-tables for PASID mappings the v1 page-table needs to be identity mapped.
Ah, and without a default PASID, RID traffic goes straight into the second level? That actually sounds much the same as what SMMUv3's S1DSS can do - seems I misremembered yesterday, we *could* in fact twiddle that to handle identity default domains, it's attaching a PASID to an identity domain that remains impossible without installing a full 1:1 pagetable, my bad.
Cheers,
Robin.
Quoted 11 lines · Robin Murphy
Quoted 9 lines · Joerg Roedel
Quoted 3 lines · Jason Gunthorpe
Why can an identity map be attached to the RID in v2, but not a full translation? It seems like a very strange design that entering PASID mode completely breaks RID support.
The reason is that AMD IOMMUs do two-level translation, which means that the addresses in the PASID page-tables are translated via the v1 page-table again. In order to be able to use Linux page-tables for PASID mappings the v1 page-table needs to be identity mapped.
Quoted 5 lines
Ah, and without a default PASID, RID traffic goes straight into the second level? That actually sounds much the same as what SMMUv3's S1DSS can do - seems I misremembered yesterday, we *could* in fact twiddle that to handle identity default domains, it's attaching a PASID to an identity domain that remains impossible without installing a full 1:1 pagetable, my bad.
What is the use case for having PASID nested under another level of translation?
Jason
Joerg Roedel
maintainerQuoted 2 lines · Jason Gunthorpe
What is the use case for having PASID nested under another level of translation?
Virtualization. Basically having a device access process address spaces inside a virtual machine. That got never put into code, but it was the rationale behind it.
Regards,
Joerg
Robin Murphy
reviewerQuoted 7 lines · Joerg Roedel
Quoted 2 lines · Jason Gunthorpe
What is the use case for having PASID nested under another level of translation?
Virtualization. Basically having a device access process address spaces inside a virtual machine. That got never put into code, but it was the rationale behind it.
For SMMUv3 it did actually get as far as a prototype[1] before the iommufd work interjected. I believe there are cloud vendors using those patches in their deployments :O
Cheers,
Robin.
Quoted 5 lines · Robin Murphy
Quoted 4 lines · Joerg Roedel
Quoted 2 lines · Jason Gunthorpe
What is the use case for having PASID nested under another level of translation?
Quoted 7 lines
Quoted 3 lines
Virtualization. Basically having a device access process address spaces inside a virtual machine. That got never put into code, but it was the rationale behind it.
For SMMUv3 it did actually get as far as a prototype[1] before the iommufd work interjected. I believe there are cloud vendors using those patches in their deployments :O
This is a bit different, this is just normal nested translation stuff.
AMD decision has effectively nested the PASID under the RID, while typically nested translation nests PASID and RID equally under a parent table.
I can't think of a use case for nesting the PASID under the RID, in every scenario this seems to be problematic. Glad to see it is undone with the new HW.
Jason
Robin Murphy
reviewerQuoted 14 lines · Jason Gunthorpe
Quoted 5 lines · Robin Murphy
Quoted 4 lines · Joerg Roedel
Quoted 2 lines · Jason Gunthorpe
What is the use case for having PASID nested under another level of translation?
Quoted 7 lines
Quoted 3 lines
Virtualization. Basically having a device access process address spaces inside a virtual machine. That got never put into code, but it was the rationale behind it.
For SMMUv3 it did actually get as far as a prototype[1] before the iommufd work interjected. I believe there are cloud vendors using those patches in their deployments :O
Quoted 5 lines
This is a bit different, this is just normal nested translation stuff.
AMD decision has effectively nested the PASID under the RID, while typically nested translation nests PASID and RID equally under a parent table.
As far as I can tell from a quick scan of the AMD spec, it seems effectively identical to SMMUv3's S1DSS=1 mode, while the "Guest I/O protection" feature is the same as S1DSS=2, treating the RID as PASID 0. SMMU has just always had both options.
Quoted 3 lines
I can't think of a use case for nesting the PASID under the RID, in every scenario this seems to be problematic. Glad to see it is undone with the new HW.
I assume you mean you can't think of a use-case for having the RID bypass stage 1/guest translation, since "nesting the PASID under the RID" is basically just how PASIDs work. AMD phrases it as "An upstream packet with a valid PASID in the PASID TLP prefix contains a canonical GVA; an upstream packet without a valid PASID in the PASID TLP prefix or with no PASID TLP prefix and an untranslated address contains a GPA". So GVA->GPA is per-PASID, then GPA->PA is for the entire RID, which is exactly how SMMU stage 1/2 work as well. As far as I'm aware that's standard for Intel too, until SIOV where they can carry the PASID through to the second level also.
The use-case is that you assume people care about performance, and thus are only going to use translation *inside* a VM for PASID-based SVA which can't be done any other way, and let guest-kernel-owned DMA (without PASID) operate in GPA space to avoid the extra translation latency, invalidation trap overheads, etc.
Cheers,
Robin.
Quoted 6 lines · Robin Murphy
Quoted 4 lines
I can't think of a use case for nesting the PASID under the RID, in every scenario this seems to be problematic. Glad to see it is undone with the new HW.
I assume you mean you can't think of a use-case for having the RID bypass stage 1/guest translation, since "nesting the PASID under the RID" is basically just how PASIDs work. AMD phrases it as "An upstream packet with a valid PASID in the PASID TLP prefix contains a canonical GVA; an upstream packet without a valid PASID in the PASID TLP prefix or with no PASID TLP prefix and an untranslated address contains a GPA". So
GVA->GPAis per-PASID, thenGPA->PAis for the entire RID, which is exactly how SMMU stage 1/2 work as well. As far as I'm aware that's standard for Intel too, until SIOV where they can carry the PASID through to the second level also.
Yes. That's something called ECS mode in VT-d 2.x spec. Then Scalable Mode began to appear in 3.x and replaced the previous ECS. Intel has no real ECS hardware implementation in the shipping products.
Best regards,
baolu
Quoted 20 lines
From: Baolu Lu <[email protected]>
Sent: Friday, September 9, 2022 9:24 AMQuoted 5 lines · Robin Murphy
Quoted 4 lines
I can't think of a use case for nesting the PASID under the RID, in every scenario this seems to be problematic. Glad to see it is undone with the new HW.
Quoted 10 lines
I assume you mean you can't think of a use-case for having the RID bypass stage 1/guest translation, since "nesting the PASID under the RID" is basically just how PASIDs work. AMD phrases it as "An upstream packet with a valid PASID in the PASID TLP prefix contains a canonical GVA; an upstream packet without a valid PASID in the PASID TLP prefix or with no PASID TLP prefix and an untranslated address contains a GPA". So
GVA->GPAis per-PASID, thenGPA->PAis for the entire RID, which is exactly how SMMU stage 1/2 work as well. As far as I'm aware that's standard for Intel too, until SIOV where they can carry the PASID through to the second level also.
Quoted 4 lines
Yes. That's something called ECS mode in VT-d 2.x spec. Then Scalable Mode began to appear in 3.x and replaced the previous ECS. Intel has no real ECS hardware implementation in the shipping products.
They are slightly different.
From AMD spec it supports three configurations:
1) stage-2 only;
2) nested with stage-2 identity mapped so stage-1 can be host page tables;
3) nested with stage-2 in translation so stage-1 points to guest page tables;
w/o the pasid0 trick (treating RID as pasid#0) it means DMA domain and SVA cannot be enabled simultaneously (both in host and guest).
The old ECS mode in VT-d supports four configurations:
1) stage-2 only;
2) stage-1 only;
3) stage-1 + stage-2 (w/o nesting);
4) stage-1 nested on stage-2;
This allows the host to support DMA domain and SVA at the same time. But it doesn't support the pasid0 trick so the restriction in the guest still remains.
In the end the scalable mode supports RID2PASID (similar to pasid0) and provides full translation configurability per pasid.
Thanks
Kevin
Quoted 6 lines · Vasant Hegde
Suravee Suthikulpanit (4):
iommu/amd: Refactoramd_iommu_domain_enable_v2to 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
Quoted 6 lines
Vasant Hegde (5):
iommu/amd/io-pgtable: Implementmap_pagesio_pgtable_opscallback iommu/amd/io-pgtable: Implementunmap_pagesio_pgtable_opscallback iommu/amd: Add map/unmap_pages()iommu_domain_opscallback support iommu/amd: Initial support for AMD IOMMU v2 page table iommu/amd: Add command-line option to enable different page table
Applied, thanks.