iommu/amd: SVA Support (part 2) - deprecate iommu_v2 module
Subsystems (2)
Vasant Hegde
maintainercover iommu/amd: SVA Support (part 2) - deprecate iommu_v2 module
This is part 2 of the 4-part series to introduce Share Virtual Address (SVA) support. This series removes iommu_v2 module support.
AMD GPU driver which was the only in-kernel user of iommu_v2 module is removing dependency on iommu_v2 module [1].
[1] https://patchwork.freedesktop.org/series/122124/
Also subsequent series will add SVA spuport in AMD IOMMU driver. Device drivers are expected to use common SVA framework to enable device PASID/PRI features.
Hence this series removes iommu_v2 module and the functions used to support iommu_v2 modue. Note that there are certain functions (ex: PPR interrupt handling code) which will be used in subsequent series for SVA support. Hence not removed those functions.
This patch series is based on top of SVA Part 1 [1] :
https://lore.kernel.org/linux-iommu/[email protected]/T/#t
Also to build kernel with this series either we need above AMD GPU related changes [1] -OR- compile with kernel config 'CONFIG_HSA_AMD=n'.
This is also available at github :
https://github.com/AMDESE/linux/tree/iommu_sva_part2_v1_iommu_v2_v6.5_rc1
Thank you,
Vasant / Suravee
Vasant Hegde (4):
iommu/amd: Remove iommu_v2 module
iommu/amd: Remove PPR support
iommu/amd: Remove amd_iommu_device_info()
iommu/amd: Remove unused EXPORT_SYMBOLS
drivers/iommu/amd/Kconfig | 9 - drivers/iommu/amd/Makefile | 1 - drivers/iommu/amd/amd_iommu.h | 7 - drivers/iommu/amd/amd_iommu_types.h | 21 +- drivers/iommu/amd/init.c | 1 - drivers/iommu/amd/iommu.c | 133 +--- drivers/iommu/amd/iommu_v2.c | 996 ---------------------------- include/linux/amd-iommu.h | 120 ---- 8 files changed, 9 insertions(+), 1279 deletions(-) delete mode 100644 drivers/iommu/amd/iommu_v2.c
Signature · 1 line
2.31.1
Vasant Hegde
maintainerPATCH 1/4 iommu/amd: Remove iommu_v2 module
AMD GPU driver which was the only in-kernel user of iommu_v2 module is removing dependency on iommu_v2 module [1].
[1] https://patchwork.freedesktop.org/series/122124/
Also we are working on adding SVA support in AMD IOMMU driver. Device drivers are expected to use common SVA framework to enable device PASID/PRI features.
Removing iommu_v2 module and then adding SVA simplifies the development. Hence remove iommu_v2 module.
--- drivers/iommu/amd/Kconfig | 9 - drivers/iommu/amd/Makefile | 1 - drivers/iommu/amd/amd_iommu.h | 5 - drivers/iommu/amd/iommu.c | 40 -- drivers/iommu/amd/iommu_v2.c | 996 ---------------------------------- include/linux/amd-iommu.h | 94 ---- 6 files changed, 1145 deletions(-) delete mode 100644 drivers/iommu/amd/iommu_v2.c
drivers/iommu/amd/Kconfig +0 -9
@@ -22,15 +22,6 @@ config AMD_IOMMU your BIOS for an option to enable it or if you have an IVRS ACPI table. -config AMD_IOMMU_V2 - tristate "AMD IOMMU Version 2 driver" - depends on AMD_IOMMU - select MMU_NOTIFIER - help - This option enables support for the AMD IOMMUv2 features of the IOMMU - hardware. Select this option if you want to use devices that support - the PCI PRI and PASID interface. - config AMD_IOMMU_DEBUGFS bool "Enable AMD IOMMU internals in DebugFS" depends on AMD_IOMMU && IOMMU_DEBUGFS
drivers/iommu/amd/Makefile +0 -1
@@ -1,4 +1,3 @@ # SPDX-License-Identifier: GPL-2.0-only 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.h +0 -5
@@ -41,9 +41,6 @@ extern int amd_iommu_guest_ir;extern enum io_pgtable_fmt amd_iommu_pgtable;extern int amd_iommu_gpt_level; -/* IOMMUv2 specific functions */ -struct iommu_domain ; -bool amd_iommu_v2_supported (void );struct amd_iommu *get_amd_iommu (unsigned int idx);u8 amd_iommu_pc_get_max_banks (unsigned int idx);
@@ -60,8 +57,6 @@ void amd_iommu_pdev_disable_cap_pri(struct pci_dev *pdev);int amd_iommu_register_ppr_notifier (struct notifier_block *nb);int amd_iommu_unregister_ppr_notifier (struct notifier_block *nb); -void amd_iommu_domain_direct_map (struct iommu_domain *dom); -int amd_iommu_domain_enable_v2 (struct iommu_domain *dom,int pasids);int amd_iommu_flush_page (struct iommu_domain *dom,u32 pasid,u64 address);void amd_iommu_update_and_flush_device_table (struct protection_domain *domain);void amd_iommu_domain_update (struct protection_domain *domain);
drivers/iommu/amd/iommu.c +0 -40
@@ -2568,46 +2568,6 @@ int amd_iommu_unregister_ppr_notifier(struct notifier_block *nb) }EXPORT_SYMBOL (amd_iommu_unregister_ppr_notifier); -void amd_iommu_domain_direct_map (struct iommu_domain *dom) -{ -struct protection_domain *domain =to_pdomain (dom); -unsigned long flags; - -spin_lock_irqsave (&domain->lock, flags); - -if (domain->iop.pgtbl_cfg.tlb) -free_io_pgtable_ops (&domain->iop.iop.ops); - -spin_unlock_irqrestore (&domain->lock, flags); -} -EXPORT_SYMBOL (amd_iommu_domain_direct_map); - -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 -* domain support IOMMUv2. Just force that the domain has no -* devices attached when it is switched into IOMMUv2 mode. -*/ - ret = -EBUSY ; -if (pdom->dev_cnt >0 || pdom->flags &PD_IOMMUV2_MASK ) - goto out; - -if (!pdom->gcr3_tbl) - ret =setup_gcr3_table (pdom, pasids); - -out: -spin_unlock_irqrestore (&pdom->lock, flags); -return ret; -} -EXPORT_SYMBOL (amd_iommu_domain_enable_v2); -static int __flush_pasid (struct protection_domain *domain,u32 pasid,u64 address,bool size) {
drivers/iommu/amd/iommu_v2.c deleted +0 -996
996 lines not on this page · raw message
include/linux/amd-iommu.h +0 -94
106 lines not on this page · raw message
Signature · 1 line
2.31.1
Re: [PATCH 1/4] iommu/amd: Remove iommu_v2 module
Quoted 43 lines · Vasant Hegde
drivers/iommu/amd/iommu_v2.c deleted +0
-43-int amd_iommu_init_device (struct pci_dev *pdev,int pasids) -{ -struct device_state *dev_state; -struct iommu_group *group; -unsigned long flags; -int ret, tmp; -u32 sbdf; - -might_sleep (); - -/* -* When memory encryption is active the device is likely not in a -* direct-mapped domain. Forbid using IOMMUv2 functionality for now. -*/ -if (cc_platform_has (CC_ATTR_MEM_ENCRYPT )) -return -ENODEV ; - -if (!amd_iommu_v2_supported ()) -return -ENODEV ; - -if (pasids <=0 || pasids > (PASID_MASK +1 )) -return -EINVAL ; - - sbdf =get_pci_sbdf_id (pdev); - - dev_state =kzalloc (sizeof (*dev_state),GFP_KERNEL ); -if (dev_state ==NULL ) -return -ENOMEM ; - -spin_lock_init (&dev_state->lock); -init_waitqueue_head (&dev_state->wq); - dev_state->pdev = pdev; - dev_state->sbdf = sbdf; - - tmp = pasids; -for (dev_state->pasid_levels =0 ; (tmp -1 ) & ~0x1ff ; tmp >>=9 ) - dev_state->pasid_levels +=1 ; - -atomic_set (&dev_state->count,1 ); - dev_state->max_pasids = pasids; - - ret = -ENOMEM ; - dev_state->states = (void *)get_zeroed_page (GFP_KERNEL );
drivers/iommu/amd/iommu_v2.c line 788
Quoted 10 lines
drivers/iommu/amd/iommu_v2.c deleted +0
-10-if (dev_state->states ==NULL ) - goto out_free_dev_state; - - dev_state->domain =iommu_domain_alloc (&pci_bus_type); -if (dev_state->domain ==NULL ) - goto out_free_states; - -/* See iommu_is_default_domain() */ - dev_state->domain->type =IOMMU_DOMAIN_IDENTITY ; -amd_iommu_domain_direct_map (dev_state->domain);
Since this code has been removed please also add a revert for the core bodge that was supporting it:
commit 2380f1e8195ef612deea1dc7a3d611c5d2b9b56a
Author: Jason Gunthorpe <[email protected]> Date: Fri Sep 9 16:46:31 2022 -0300
iommu: Fix false ownership failure on AMD systems with PASID activated
The AMD IOMMU driver cannot activate PASID mode on a RID without the RID's translation being set to IDENTITY. Further it requires changing the RID's page table layout from the normal v1 IOMMU_DOMAIN_IDENTITY layout to a different v2 layout.
It does this by creating a new iommu_domain, configuring that domain for v2 identity operation and then attaching it to the group, from within the driver. This logic assumes the group is already set to the IDENTITY domain and is being used by the DMA API.
However, since the ownership logic is based on the group's domain pointer equaling the default domain to detect DMA API ownership, this causes it to look like the group is not attached to the DMA API any more. This blocks attaching drivers to any other devices in the group.
In a real system this manifests itself as the HD-audio devices on some AMD platforms losing their device drivers.
Work around this unique behavior of the AMD driver by checking for equality of IDENTITY domains based on their type, not their pointer value. This allows the AMD driver to have two IDENTITY domains for internal purposes without breaking the check.
Have the AMD driver properly declare that the special domain it created is actually an IDENTITY domain.
Jason
Vasant Hegde
maintainerRe: [PATCH 1/4] iommu/amd: Remove iommu_v2 module
Quoted 50 lines · Jason Gunthorpe
Quoted 48 lines · Vasant Hegde
drivers/iommu/amd/iommu_v2.c deleted +0
-48-int amd_iommu_init_device (struct pci_dev *pdev,int pasids) -{ -struct device_state *dev_state; -struct iommu_group *group; -unsigned long flags; -int ret, tmp; -u32 sbdf; - -might_sleep (); - -/* -* When memory encryption is active the device is likely not in a -* direct-mapped domain. Forbid using IOMMUv2 functionality for now. -*/ -if (cc_platform_has (CC_ATTR_MEM_ENCRYPT )) -return -ENODEV ; - -if (!amd_iommu_v2_supported ()) -return -ENODEV ; - -if (pasids <=0 || pasids > (PASID_MASK +1 )) -return -EINVAL ; - - sbdf =get_pci_sbdf_id (pdev); - - dev_state =kzalloc (sizeof (*dev_state),GFP_KERNEL ); -if (dev_state ==NULL ) -return -ENOMEM ; - -spin_lock_init (&dev_state->lock); -init_waitqueue_head (&dev_state->wq); - dev_state->pdev = pdev; - dev_state->sbdf = sbdf; - - tmp = pasids; -for (dev_state->pasid_levels =0 ; (tmp -1 ) & ~0x1ff ; tmp >>=9 ) - dev_state->pasid_levels +=1 ; - -atomic_set (&dev_state->count,1 ); - dev_state->max_pasids = pasids; - - ret = -ENOMEM ; - dev_state->states = (void *)get_zeroed_page (GFP_KERNEL ); -if (dev_state->states ==NULL ) - goto out_free_dev_state; - - dev_state->domain =iommu_domain_alloc (&pci_bus_type); -if (dev_state->domain ==NULL )
Quoted 8 lines
drivers/iommu/amd/iommu_v2.c line 788
Quoted 5 lines
drivers/iommu/amd/iommu_v2.c deleted +0
-5- goto out_free_states; - -/* See iommu_is_default_domain() */ - dev_state->domain->type =IOMMU_DOMAIN_IDENTITY ; -amd_iommu_domain_direct_map (dev_state->domain);Since this code has been removed please also add a revert for the core bodge that was supporting it:
Sure. I will add patch to revert this one.
-Vasant
Quoted 34 lines
commit
2380f1e8195ef612deea1dc7a3d611c5d2b9b56aAuthor: Jason Gunthorpe <[email protected]> Date: Fri Sep 9 16:46:31 2022 -0300iommu: Fix false ownership failure on AMD systems with PASID activated
The AMD IOMMU driver cannot activate PASID mode on a RID without the RID's translation being set to IDENTITY. Further it requires changing the RID's page table layout from the normal v1
IOMMU_DOMAIN_IDENTITYlayout to a different v2 layout.It does this by creating a new
iommu_domain, configuring that domain for v2 identity operation and then attaching it to the group, from within the driver. This logic assumes the group is already set to the IDENTITY domain and is being used by the DMA API.However, since the ownership logic is based on the group's domain pointer equaling the default domain to detect DMA API ownership, this causes it to look like the group is not attached to the DMA API any more. This blocks attaching drivers to any other devices in the group.
In a real system this manifests itself as the HD-audio devices on some AMD platforms losing their device drivers.
Work around this unique behavior of the AMD driver by checking for equality of IDENTITY domains based on their type, not their pointer value. This allows the AMD driver to have two IDENTITY domains for internal purposes without breaking the check.
Have the AMD driver properly declare that the special domain it created is actually an IDENTITY domain.
Jason
Vasant Hegde
maintainerPATCH 2/4 iommu/amd: Remove PPR support
In reply to Vasant HegdeRemove PPR handler and notifier related functions as its not used anymore. Note that we are retaining PPR interrupt handler support as it will be re-used when we introduce IOPF support.
--- drivers/iommu/amd/amd_iommu.h | 2 -- drivers/iommu/amd/amd_iommu_types.h | 13 --------- drivers/iommu/amd/iommu.c | 45 +---------------------------- 3 files changed, 1 insertion(+), 59 deletions(-)
drivers/iommu/amd/amd_iommu.h +0 -2
@@ -55,8 +55,6 @@ int amd_iommu_pc_set_reg(struct amd_iommu *iommu, u8 bank, u8 cntr,int amd_iommu_pdev_enable_cap_pri (struct pci_dev *pdev);void amd_iommu_pdev_disable_cap_pri (struct pci_dev *pdev); -int amd_iommu_register_ppr_notifier (struct notifier_block *nb); -int amd_iommu_unregister_ppr_notifier (struct notifier_block *nb);int amd_iommu_flush_page (struct iommu_domain *dom,u32 pasid,u64 address);void amd_iommu_update_and_flush_device_table (struct protection_domain *domain);void amd_iommu_domain_update (struct protection_domain *domain);
drivers/iommu/amd/amd_iommu_types.h +0 -13
@@ -509,19 +509,6 @@ extern struct kmem_cache *amd_iommu_irq_cache;#define APERTURE_RANGE_INDEX (a) ((a) >> APERTURE_RANGE_SHIFT)#define APERTURE_PAGE_INDEX (a) (((a) >> 21) & 0x3fULL) -/* -* This struct is used to pass information about -* incoming PPR faults around. -*/ -struct amd_iommu_fault { -u64 address;/* IO virtual address of the fault*/ -u32 pasid;/* Address space identifier */ -u32 sbdf;/* Originating PCI device id */ -u16 tag;/* PPR tag */ -u16 flags;/* Fault flags */ - -}; -struct amd_iommu ;struct iommu_domain ;
drivers/iommu/amd/iommu.c +1 -44
69 lines not on this page · raw message
Signature · 1 line
2.31.1
Vasant Hegde
maintainerPATCH 3/4 iommu/amd: Remove amd_iommu_device_info()
In reply to Vasant HegdeNo one is using this function. Hence remove it. Also move PCI device feature detection flags to amd_iommu_types.h as its only used inside AMD IOMMU driver.
--- drivers/iommu/amd/amd_iommu_types.h | 8 ++++++ drivers/iommu/amd/iommu.c | 42 ----------------------------- include/linux/amd-iommu.h | 26 ------------------ 3 files changed, 8 insertions(+), 68 deletions(-)
drivers/iommu/amd/amd_iommu_types.h +8 -0
@@ -786,6 +786,14 @@ struct devid_map {bool cmd_line; }; +#define AMD_IOMMU_DEVICE_FLAG_ATS_SUP 0x1/* ATS feature supported */ +#define AMD_IOMMU_DEVICE_FLAG_PRI_SUP 0x2/* PRI feature supported */ +#define AMD_IOMMU_DEVICE_FLAG_PASID_SUP 0x4/* PASID context supported */ +/* Device may request execution on memory pages */ +#define AMD_IOMMU_DEVICE_FLAG_EXEC_SUP 0x8 +/* Device may request super-user privileges */ +#define AMD_IOMMU_DEVICE_FLAG_PRIV_SUP 0x10 +/* * This struct contains device specific data for the IOMMU */
drivers/iommu/amd/iommu.c +0 -42
48 lines not on this page · raw message
include/linux/amd-iommu.h +0 -26
@@ -33,32 +33,6 @@ struct pci_dev;extern int amd_iommu_detect (void ); -/** -* amd_iommu_device_info() - Get information about IOMMUv2 support of a -* PCI device -* @pdev: PCI device to query information from -* @info: A pointer to an amd_iommu_device_info structure which will contain -* the information about the PCI device -* -* Returns 0 on success, negative value on error -*/ - -#define AMD_IOMMU_DEVICE_FLAG_ATS_SUP 0x1/* ATS feature supported */ -#define AMD_IOMMU_DEVICE_FLAG_PRI_SUP 0x2/* PRI feature supported */ -#define AMD_IOMMU_DEVICE_FLAG_PASID_SUP 0x4/* PASID context supported */ -#define AMD_IOMMU_DEVICE_FLAG_EXEC_SUP 0x8/* Device may request execution -on memory pages */ -#define AMD_IOMMU_DEVICE_FLAG_PRIV_SUP 0x10/* Device may request -super-user privileges */ - -struct amd_iommu_device_info { -int max_pasids; -u32 flags; -}; - -extern int amd_iommu_device_info (struct pci_dev *pdev, -struct amd_iommu_device_info *info); -#else /* CONFIG_AMD_IOMMU */ static inline int amd_iommu_detect (void ) {return -ENODEV ; }
Signature · 1 line
2.31.1
Vasant Hegde
maintainerPATCH 4/4 iommu/amd: Remove unused EXPORT_SYMBOLS
In reply to Vasant HegdeDrop EXPORT_SYMBOLS for the functions that are not used by any modules.
--- drivers/iommu/amd/init.c | 1 - drivers/iommu/amd/iommu.c | 6 ------ 2 files changed, 7 deletions(-)
drivers/iommu/amd/init.c +0 -1
@@ -3667,7 +3667,6 @@ bool amd_iommu_v2_supported(void)*/ return amd_iommu_gt_ppr_supported () && !amd_iommu_snp_en; } -EXPORT_SYMBOL (amd_iommu_v2_supported);struct amd_iommu *get_amd_iommu (unsigned int idx) {
drivers/iommu/amd/iommu.c +0 -6
@@ -2446,7 +2446,6 @@ bool amd_iommu_is_attach_deferred(struct device *dev)return dev_data->defer_attach; } -EXPORT_SYMBOL_GPL (amd_iommu_is_attach_deferred);static void amd_iommu_flush_iotlb_all (struct iommu_domain *domain) {
@@ -2606,7 +2605,6 @@ int amd_iommu_flush_page(struct iommu_domain *dom, u32 pasid,return ret; } -EXPORT_SYMBOL (amd_iommu_flush_page);static int __amd_iommu_flush_tlb (struct protection_domain *domain,u32 pasid) {
@@ -2626,7 +2624,6 @@ int amd_iommu_flush_tlb(struct iommu_domain *dom, u32 pasid)return ret; } -EXPORT_SYMBOL (amd_iommu_flush_tlb);static u64 *__get_gcr3_pte (u64 *root,int level,u32 pasid,bool alloc) {
@@ -2706,7 +2703,6 @@ int amd_iommu_domain_set_gcr3(struct iommu_domain *dom, u32 pasid,return ret; } -EXPORT_SYMBOL (amd_iommu_domain_set_gcr3);int amd_iommu_domain_clear_gcr3 (struct iommu_domain *dom,u32 pasid) {
@@ -2720,7 +2716,6 @@ int amd_iommu_domain_clear_gcr3(struct iommu_domain *dom, u32 pasid)return ret; } -EXPORT_SYMBOL (amd_iommu_domain_clear_gcr3);int amd_iommu_complete_ppr (struct pci_dev *pdev,u32 pasid,int status,int tag)
@@ -2739,7 +2734,6 @@ int amd_iommu_complete_ppr(struct pci_dev *pdev, u32 pasid,return iommu_queue_command (iommu, &cmd); } -EXPORT_SYMBOL (amd_iommu_complete_ppr);#ifdef CONFIG_IRQ_REMAP
Signature · 1 line
2.31.1
Quoted 17 lines · Vasant Hegde
This is part 2 of the 4-part series to introduce Share Virtual Address (SVA) support. This series removes
iommu_v2module support.AMD GPU driver which was the only in-kernel user of
iommu_v2module is removing dependency oniommu_v2module [1].[1] https://patchwork.freedesktop.org/series/122124/
Also subsequent series will add SVA spuport in AMD IOMMU driver. Device drivers are expected to use common SVA framework to enable device PASID/PRI features.
Hence this series removes
iommu_v2module and the functions used to supportiommu_v2modue. Note that there are certain functions (ex: PPR interrupt handling code) which will be used in subsequent series for SVA support. Hence not removed those functions.
Quoted 5 lines
This patch series is based on top of SVA Part 1 [1] :
https://lore.kernel.org/linux-iommu/[email protected]/T/#tAlso to build kernel with this series either we need above AMD GPU related changes [1] -OR- compile with kernel config '
CONFIG_HSA_AMD=n'.
Why did you order it this way? Wouldn't part 1 be nicer if it doesn't have to worry about this code? Especially since part 1 is now not changing this code?
Jason
Vasant Hegde
maintainerJason,
Quoted 21 lines · Jason Gunthorpe
Quoted 20 lines · Vasant Hegde
This is part 2 of the 4-part series to introduce Share Virtual Address (SVA) support. This series removes
iommu_v2module support.AMD GPU driver which was the only in-kernel user of
iommu_v2module is removing dependency oniommu_v2module [1].[1] https://patchwork.freedesktop.org/series/122124/
Also subsequent series will add SVA spuport in AMD IOMMU driver. Device drivers are expected to use common SVA framework to enable device PASID/PRI features.
Hence this series removes
iommu_v2module and the functions used to supportiommu_v2modue. Note that there are certain functions (ex: PPR interrupt handling code) which will be used in subsequent series for SVA support. Hence not removed those functions.This patch series is based on top of SVA Part 1 [1] :
https://lore.kernel.org/linux-iommu/[email protected]/T/#t
Quoted 6 lines
Quoted 2 lines
Also to build kernel with this series either we need above AMD GPU related changes [1] -OR- compile with kernel config '
CONFIG_HSA_AMD=n'.Why did you order it this way? Wouldn't part 1 be nicer if it doesn't have to worry about this code? Especially since part 1 is now not changing this code?
My bad. I should have posted this series without any Part number if subject and then rebase Part1 on top of it.
I will continue to post next version with subject Part2 (just to avoid further confusion).
-Vasant