iommu: Retire detach_dev callback
Subsystems (18)
Lu Baolu
maintainerv3 cover iommu: Retire detach_dev callback
Hi folks,
The iommu core calls the driver's detach_dev domain op callback only when a device is finished assigning to user space and iommu_group_release_dma_owner() is called to return the device to the kernel, where iommu core wants to set the default domain to the device but the driver didn't provide one. The code looks like:
/*
* New drivers should support default domains and so the detach_dev() op
* will never be called. Otherwise the NULL domain represents some
* platform specific behavior.
*/
if (!new_domain) {
if (WARN_ON(!group->domain->ops->detach_dev))
return -EINVAL;
__iommu_group_for_each_dev(group, group->domain,
iommu_group_do_detach_device);
group->domain = NULL;
return 0;
}In other words, if the iommu driver provides default domains, the .detach_dev callback will never be called; Otherwise, the .detach_dev callback is actually called to return control back to the platform DMA ops, other than detaching the domain from device.
This series cleanups this by:
- If the IOMMU driver provides default domains, remove .detach_dev callback.
- Adds a new set_platform_dma iommu op. Any IOMMU driver that doesn't provide default domain should implement set_platform_dma callback instead.
- Retire .detach_dev callback and rename .attach_dev to .set_dev.
This series originates from various discussion in the community. Thank Jason, Robin and all others for their ideas. This series looks very long. It is necessary because I hope that change in each driver has a confirmation from its stakeholder. I will then be able to merge some of them to make the series cute.
The whole series is available on github:
https://github.com/LuBaolu/intel-iommu/commits/iommu-retire-detach_dev-v3
Please review and suggest.
Best regards,
baolu
Change log:
v3:
- Setting blocking domain is not conceptually equal to detach_dev. Dropped all blocking domain related staffs in the previous version.
v2:
- https://lore.kernel.org/linux-iommu/[email protected]/
- Replace .detach_dev callback with static block domain ops;
- Rename .attach_dev to .set_dev.
v1:
- https://lore.kernel.org/linux-iommu/[email protected]/
Lu Baolu (20):
iommu/amd: Remove detach_dev callback iommu/apple-dart: Remove detach_dev callback iommu/qcom: Remove detach_dev callback iommu/exynos: Remove detach_dev callback iommu/ipmmu: Remove detach_dev callback
iommu/mtk: Remove detach_dev callback iommu/rockchip: Remove detach_dev callback iommu/sprd: Remove detach_dev callback iommu/sun50i: Remove detach_dev callback
iommu: Add set_platform_dma iommu ops iommu/fsl_pamu: Add set_platform_dma callback iommu/msm: Add set_platform_dma callback iommu/mtk_v1: Add set_platform_dma callback iommu/omap: Add set_platform_dma callback iommu/s390: Add set_platform_dma callback iommu/gart: Add set_platform_dma callback iommu/tegra: Add set_platform_dma callback
iommu: Call set_platform_dma if default domain is unavailable
iommu: Retire detach_dev callback
iommu: Rename attach_dev to set_dev
include/linux/iommu.h | 10 ++++--- drivers/iommu/amd/iommu.c | 28 +----------------- drivers/iommu/apple-dart.c | 19 +----------- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 2 +- drivers/iommu/arm/arm-smmu/arm-smmu.c | 2 +- drivers/iommu/arm/arm-smmu/qcom_iommu.c | 25 +--------------- drivers/iommu/exynos-iommu.c | 3 +- drivers/iommu/fsl_pamu_domain.c | 12 ++++++-- drivers/iommu/intel/iommu.c | 4 +-- drivers/iommu/iommu.c | 32 +++++++-------------- drivers/iommu/ipmmu-vmsa.c | 18 +----------- drivers/iommu/msm_iommu.c | 12 ++++++-- drivers/iommu/mtk_iommu.c | 11 +------ drivers/iommu/mtk_iommu_v1.c | 12 ++++++-- drivers/iommu/omap-iommu.c | 12 ++++++-- drivers/iommu/rockchip-iommu.c | 3 +- drivers/iommu/s390-iommu.c | 12 ++++++-- drivers/iommu/sprd-iommu.c | 18 +----------- drivers/iommu/sun50i-iommu.c | 3 +- drivers/iommu/tegra-gart.c | 12 ++++++-- drivers/iommu/tegra-smmu.c | 12 ++++++-- drivers/iommu/virtio-iommu.c | 2 +- 22 files changed, 100 insertions(+), 164 deletions(-)
Signature · 1 line
2.34.1
Lu Baolu
maintainerPATCH v3 1/20 iommu/amd: Remove detach_dev callback
The AMD IOMMU supports default domain, so the detach_dev op will never be called. Remove it to avoid dead code.
--- drivers/iommu/amd/iommu.c | 26 -------------------------- 1 file changed, 26 deletions(-)
drivers/iommu/amd/iommu.c +0 -26
@@ -2126,31 +2126,6 @@ static void amd_iommu_domain_free(struct iommu_domain *dom)protection_domain_free (domain); } -static void amd_iommu_detach_device (struct iommu_domain *dom, -struct device *dev) -{ -struct iommu_dev_data *dev_data =dev_iommu_priv_get (dev); -struct amd_iommu *iommu; - -if (!check_device (dev)) -return ; - -if (dev_data->domain !=NULL ) -detach_device (dev); - - iommu =rlookup_amd_iommu (dev); -if (!iommu) -return ; - -#ifdef CONFIG_IRQ_REMAP -if (AMD_IOMMU_GUEST_IR_VAPIC (amd_iommu_guest_ir) && - (dom->type ==IOMMU_DOMAIN_UNMANAGED )) - dev_data->use_vapic =0 ; -#endif - -iommu_completion_wait (iommu); -} -static int amd_iommu_attach_device (struct iommu_domain *dom,struct device *dev) {
@@ -2414,7 +2389,6 @@ const struct iommu_ops amd_iommu_ops = { .def_domain_type = amd_iommu_def_domain_type, .default_domain_ops = &(const struct iommu_domain_ops ) { .attach_dev = amd_iommu_attach_device, - .detach_dev = amd_iommu_detach_device, .map_pages = amd_iommu_map_pages, .unmap_pages = amd_iommu_unmap_pages, .iotlb_sync_map = amd_iommu_iotlb_sync_map,
Signature · 1 line
2.34.1
Lu Baolu
maintainerPATCH v3 2/20 iommu/apple-dart: Remove detach_dev callback
In reply to Lu BaoluThe IOMMU driver supports default domain, so the detach_dev op will never be called. Remove it to avoid dead code.
--- drivers/iommu/apple-dart.c | 17 ----------------- 1 file changed, 17 deletions(-)
drivers/iommu/apple-dart.c +0 -17
@@ -535,22 +535,6 @@ static int apple_dart_attach_dev(struct iommu_domain *domain,return ret; } -static void apple_dart_detach_dev (struct iommu_domain *domain, -struct device *dev) -{ -int i; -struct apple_dart_stream_map *stream_map; -struct apple_dart_master_cfg *cfg =dev_iommu_priv_get (dev); -struct apple_dart_domain *dart_domain =to_dart_domain (domain); - -for_each_stream_map (i, cfg, stream_map) -apple_dart_hw_disable_dma (stream_map); - -if (domain->type ==IOMMU_DOMAIN_DMA || - domain->type ==IOMMU_DOMAIN_UNMANAGED ) -apple_dart_domain_remove_streams (dart_domain, cfg); -} -static struct iommu_device *apple_dart_probe_device (struct device *dev) {struct apple_dart_master_cfg *cfg =dev_iommu_priv_get (dev);
@@ -780,7 +764,6 @@ static const struct iommu_ops apple_dart_iommu_ops = { .owner = THIS_MODULE, .default_domain_ops = &(const struct iommu_domain_ops ) { .attach_dev = apple_dart_attach_dev, - .detach_dev = apple_dart_detach_dev, .map_pages = apple_dart_map_pages, .unmap_pages = apple_dart_unmap_pages, .flush_iotlb_all = apple_dart_flush_iotlb_all,
Signature · 1 line
2.34.1
Lu Baolu
maintainerPATCH v3 3/20 iommu/qcom: Remove detach_dev callback
In reply to Lu BaoluThe IOMMU driver supports default domain, so the detach_dev op will never be called. Remove it to avoid dead code.
--- drivers/iommu/arm/arm-smmu/qcom_iommu.c | 23 ----------------------- 1 file changed, 23 deletions(-)
drivers/iommu/arm/arm-smmu/qcom_iommu.c +0 -23
@@ -387,28 +387,6 @@ static int qcom_iommu_attach_dev(struct iommu_domain *domain, struct device *devreturn 0 ; } -static void qcom_iommu_detach_dev (struct iommu_domain *domain,struct device *dev) -{ -struct qcom_iommu_domain *qcom_domain =to_qcom_iommu_domain (domain); -struct iommu_fwspec *fwspec =dev_iommu_fwspec_get (dev); -struct qcom_iommu_dev *qcom_iommu =to_iommu (dev); -unsigned i; - -if (WARN_ON (!qcom_domain->iommu)) -return ; - -pm_runtime_get_sync (qcom_iommu->dev); -for (i =0 ; i < fwspec->num_ids; i++) { -struct qcom_iommu_ctx *ctx =to_ctx (qcom_domain, fwspec->ids[i]); - -/* Disable the context bank: */ -iommu_writel (ctx,ARM_SMMU_CB_SCTLR ,0 ); - - ctx->domain =NULL ; - } -pm_runtime_put_sync (qcom_iommu->dev); -} -static int qcom_iommu_map (struct iommu_domain *domain,unsigned long iova,phys_addr_t paddr,size_t pgsize,size_t pgcount,int prot,gfp_t gfp,size_t *mapped)
@@ -583,7 +561,6 @@ static const struct iommu_ops qcom_iommu_ops = { .pgsize_bitmap = SZ_4K | SZ_64K | SZ_1M | SZ_16M, .default_domain_ops = &(const struct iommu_domain_ops ) { .attach_dev = qcom_iommu_attach_dev, - .detach_dev = qcom_iommu_detach_dev, .map_pages = qcom_iommu_map, .unmap_pages = qcom_iommu_unmap, .flush_iotlb_all = qcom_iommu_flush_iotlb_all,
Signature · 1 line
2.34.1
Lu Baolu
maintainerPATCH v3 4/20 iommu/exynos: Remove detach_dev callback
In reply to Lu BaoluThe IOMMU driver supports default domain, so the detach_dev op will never be called. Remove it to avoid dead code.
--- drivers/iommu/exynos-iommu.c | 1 - 1 file changed, 1 deletion(-)
drivers/iommu/exynos-iommu.c +0 -1
@@ -1404,7 +1404,6 @@ static const struct iommu_ops exynos_iommu_ops = { .of_xlate = exynos_iommu_of_xlate, .default_domain_ops = &(const struct iommu_domain_ops ) { .attach_dev = exynos_iommu_attach_device, - .detach_dev = exynos_iommu_detach_device, .map = exynos_iommu_map, .unmap = exynos_iommu_unmap, .iova_to_phys = exynos_iommu_iova_to_phys,
Signature · 1 line
2.34.1
Lu Baolu
maintainerPATCH v3 5/20 iommu/ipmmu: Remove detach_dev callback
In reply to Lu BaoluThe IOMMU driver supports default domain, so the detach_dev op will never be called. Remove it to avoid dead code.
--- drivers/iommu/ipmmu-vmsa.c | 16 ---------------- 1 file changed, 16 deletions(-)
drivers/iommu/ipmmu-vmsa.c +0 -16
@@ -643,21 +643,6 @@ static int ipmmu_attach_device(struct iommu_domain *io_domain,return 0 ; } -static void ipmmu_detach_device (struct iommu_domain *io_domain, -struct device *dev) -{ -struct iommu_fwspec *fwspec =dev_iommu_fwspec_get (dev); -struct ipmmu_vmsa_domain *domain =to_vmsa_domain (io_domain); -unsigned int i; - -for (i =0 ; i < fwspec->num_ids; ++i) -ipmmu_utlb_disable (domain, fwspec->ids[i]); - -/* -* TODO: Optimize by disabling the context when no device is attached. -*/ -} -static int ipmmu_map (struct iommu_domain *io_domain,unsigned long iova,phys_addr_t paddr,size_t pgsize,size_t pgcount,int prot,gfp_t gfp,size_t *mapped)
@@ -876,7 +861,6 @@ static const struct iommu_ops ipmmu_ops = { .of_xlate = ipmmu_of_xlate, .default_domain_ops = &(const struct iommu_domain_ops ) { .attach_dev = ipmmu_attach_device, - .detach_dev = ipmmu_detach_device, .map_pages = ipmmu_map, .unmap_pages = ipmmu_unmap, .flush_iotlb_all = ipmmu_flush_iotlb_all,
Signature · 1 line
2.34.1
Lu Baolu
maintainerPATCH v3 6/20 iommu/mtk: Remove detach_dev callback
In reply to Lu BaoluThe IOMMU driver supports default domain, so the detach_dev op will never be called. Remove it to avoid dead code.
--- drivers/iommu/mtk_iommu.c | 9 --------- 1 file changed, 9 deletions(-)
drivers/iommu/mtk_iommu.c +0 -9
@@ -713,14 +713,6 @@ static int mtk_iommu_attach_device(struct iommu_domain *domain,return ret; } -static void mtk_iommu_detach_device (struct iommu_domain *domain, -struct device *dev) -{ -struct mtk_iommu_data *data =dev_iommu_priv_get (dev); - -mtk_iommu_config (data, dev, false,0 ); -} -static int mtk_iommu_map (struct iommu_domain *domain,unsigned long iova,phys_addr_t paddr,size_t pgsize,size_t pgcount,int prot,gfp_t gfp,size_t *mapped)
@@ -949,7 +941,6 @@ static const struct iommu_ops mtk_iommu_ops = { .owner = THIS_MODULE, .default_domain_ops = &(const struct iommu_domain_ops ) { .attach_dev = mtk_iommu_attach_device, - .detach_dev = mtk_iommu_detach_device, .map_pages = mtk_iommu_map, .unmap_pages = mtk_iommu_unmap, .flush_iotlb_all = mtk_iommu_flush_iotlb_all,
Signature · 1 line
2.34.1
Lu Baolu
maintainerPATCH v3 7/20 iommu/rockchip: Remove detach_dev callback
In reply to Lu BaoluThe IOMMU driver supports default domain, so the detach_dev op will never be called. Remove it to avoid dead code.
--- drivers/iommu/rockchip-iommu.c | 1 - 1 file changed, 1 deletion(-)
drivers/iommu/rockchip-iommu.c +0 -1
@@ -1192,7 +1192,6 @@ static const struct iommu_ops rk_iommu_ops = { .of_xlate = rk_iommu_of_xlate, .default_domain_ops = &(const struct iommu_domain_ops ) { .attach_dev = rk_iommu_attach_device, - .detach_dev = rk_iommu_detach_device, .map = rk_iommu_map, .unmap = rk_iommu_unmap, .iova_to_phys = rk_iommu_iova_to_phys,
Signature · 1 line
2.34.1
Lu Baolu
maintainerPATCH v3 8/20 iommu/sprd: Remove detach_dev callback
In reply to Lu BaoluThe IOMMU driver supports default domain, so the detach_dev op will never be called. Remove it to avoid dead code.
--- drivers/iommu/sprd-iommu.c | 16 ---------------- 1 file changed, 16 deletions(-)
drivers/iommu/sprd-iommu.c +0 -16
@@ -255,21 +255,6 @@ static int sprd_iommu_attach_device(struct iommu_domain *domain,return 0 ; } -static void sprd_iommu_detach_device (struct iommu_domain *domain, -struct device *dev) -{ -struct sprd_iommu_domain *dom =to_sprd_domain (domain); -struct sprd_iommu_device *sdev = dom->sdev; -size_t pgt_size =sprd_iommu_pgt_size (domain); - -if (!sdev) -return ; - -dma_free_coherent (sdev->dev, pgt_size, dom->pgt_va, dom->pgt_pa); -sprd_iommu_hw_en (sdev, false); - dom->sdev =NULL ; -} -static int sprd_iommu_map (struct iommu_domain *domain,unsigned long iova,phys_addr_t paddr,size_t pgsize,size_t pgcount,int prot,gfp_t gfp,size_t *mapped)
@@ -414,7 +399,6 @@ static const struct iommu_ops sprd_iommu_ops = { .owner = THIS_MODULE, .default_domain_ops = &(const struct iommu_domain_ops ) { .attach_dev = sprd_iommu_attach_device, - .detach_dev = sprd_iommu_detach_device, .map_pages = sprd_iommu_map, .unmap_pages = sprd_iommu_unmap, .iotlb_sync_map = sprd_iommu_sync_map,
Signature · 1 line
2.34.1
Lu Baolu
maintainerPATCH v3 9/20 iommu/sun50i: Remove detach_dev callback
In reply to Lu BaoluThe IOMMU driver supports default domain, so the detach_dev op will never be called. Remove it to avoid dead code.
--- drivers/iommu/sun50i-iommu.c | 1 - 1 file changed, 1 deletion(-)
drivers/iommu/sun50i-iommu.c +0 -1
@@ -835,7 +835,6 @@ static const struct iommu_ops sun50i_iommu_ops = { .probe_device = sun50i_iommu_probe_device, .default_domain_ops = &(const struct iommu_domain_ops ) { .attach_dev = sun50i_iommu_attach_device, - .detach_dev = sun50i_iommu_detach_device, .flush_iotlb_all = sun50i_iommu_flush_iotlb_all, .iotlb_sync_map = sun50i_iommu_iotlb_sync_map, .iotlb_sync = sun50i_iommu_iotlb_sync,
Signature · 1 line
2.34.1
Lu Baolu
maintainerPATCH v3 10/20 iommu: Add set_platform_dma iommu ops
In reply to Lu BaoluWhen VFIO finishes assigning a device to user space and calls iommu_group_release_dma_owner() to return the device to kernel, the IOMMU core will attach the default domain to the device. Unfortunately, some IOMMU drivers don't support default domain, hence in the end, the core calls .detach_dev instead.
This adds set_platform_dma iommu ops to make it clear that what it does is returning control back to the platform DMA ops.
--- include/linux/iommu.h | 4 ++++ 1 file changed, 4 insertions(+)
include/linux/iommu.h +4 -0
@@ -223,6 +223,9 @@ struct iommu_iotlb_gather {* @release_device: Remove device from iommu driver handling * @probe_finalize: Do final setup work after the device is added to an IOMMU * group and attached to the groups domain +* @set_platform_dma: Returning control back to the platform DMA ops. Only +* valid for IOMMU drivers which don't support default +* domain. * @device_group: find iommu group for a particular device * @get_resv_regions: Request list of reserved regions for a device * @of_xlate: add OF master IDs to iommu grouping
@@ -251,6 +254,7 @@ struct iommu_ops {struct iommu_device *(*probe_device)(struct device *dev);void (*release_device)(struct device *dev);void (*probe_finalize)(struct device *dev); +void (*set_platform_dma)(struct device *dev);struct iommu_group *(*device_group)(struct device *dev);/* Request/Free a list of reserved regions for a device */
Signature · 1 line
2.34.1
Lu Baolu
maintainerPATCH v3 11/20 iommu/fsl_pamu: Add set_platform_dma callback
In reply to Lu BaoluThis IOMMU driver doesn't support default domain. Add the implementation of set_platform_dma callback so that the IOMMU core could return the DMA control.
--- drivers/iommu/fsl_pamu_domain.c | 9 +++++++++ 1 file changed, 9 insertions(+)
drivers/iommu/fsl_pamu_domain.c +9 -0
@@ -314,6 +314,14 @@ static void fsl_pamu_detach_device(struct iommu_domain *domain,pr_debug ("missing fsl,liodn property at %pOF\n" , dev->of_node); } +static void fsl_pamu_set_platform_dma (struct device *dev) +{ +struct iommu_domain *domain =iommu_get_domain_for_dev (dev); + +if (domain) +fsl_pamu_detach_device (domain, dev); +} +/* Set the domain stash attribute */ int fsl_pamu_configure_l1_stash (struct iommu_domain *domain,u32 cpu) {
@@ -452,6 +460,7 @@ static const struct iommu_ops fsl_pamu_ops = { .domain_alloc = fsl_pamu_domain_alloc, .probe_device = fsl_pamu_probe_device, .device_group = fsl_pamu_device_group, + .set_platform_dma = fsl_pamu_set_platform_dma; .default_domain_ops = &(const struct iommu_domain_ops) { .attach_dev = fsl_pamu_attach_device, .detach_dev = fsl_pamu_detach_device,
Signature · 1 line
2.34.1
Lu Baolu
maintainerPATCH v3 12/20 iommu/msm: Add set_platform_dma callback
In reply to Lu BaoluThis IOMMU driver doesn't support default domain. Add the implementation of set_platform_dma callback so that the IOMMU core could return the DMA control.
--- drivers/iommu/msm_iommu.c | 9 +++++++++ 1 file changed, 9 insertions(+)
drivers/iommu/msm_iommu.c +9 -0
@@ -470,6 +470,14 @@ static void msm_iommu_detach_dev(struct iommu_domain *domain,spin_unlock_irqrestore (&msm_iommu_lock, flags); } +static void msm_iommu_set_platform_dma (struct device *dev) +{ +struct iommu_domain *domain =iommu_get_domain_for_dev (dev); + +if (domain) +msm_iommu_detach_dev (domain, dev); +} +static int msm_iommu_map (struct iommu_domain *domain,unsigned long iova,phys_addr_t pa,size_t pgsize,size_t pgcount,int prot,gfp_t gfp,size_t *mapped)
@@ -678,6 +686,7 @@ static struct iommu_ops msm_iommu_ops = { .domain_alloc = msm_iommu_domain_alloc, .probe_device = msm_iommu_probe_device, .device_group = generic_device_group, + .set_platform_dma = msm_iommu_set_platform_dma, .pgsize_bitmap = MSM_IOMMU_PGSIZES, .of_xlate = qcom_iommu_of_xlate, .default_domain_ops = &(const struct iommu_domain_ops ) {
Signature · 1 line
2.34.1
Lu Baolu
maintainerPATCH v3 13/20 iommu/mtk_v1: Add set_platform_dma callback
In reply to Lu BaoluThis IOMMU driver doesn't support default domain. Add the implementation of set_platform_dma callback so that the IOMMU core could return the DMA control.
--- drivers/iommu/mtk_iommu_v1.c | 9 +++++++++ 1 file changed, 9 insertions(+)
drivers/iommu/mtk_iommu_v1.c +9 -0
@@ -326,6 +326,14 @@ static void mtk_iommu_v1_detach_device(struct iommu_domain *domain, struct devicmtk_iommu_v1_config (data, dev, false); } +static void mtk_iommu_v1_set_platform_dma (struct device *dev) +{ +struct iommu_domain *domain =iommu_get_domain_for_dev (dev); + +if (domain) +mtk_iommu_v1_detach_device (domain, dev); +} +static int mtk_iommu_v1_map (struct iommu_domain *domain,unsigned long iova,phys_addr_t paddr,size_t pgsize,size_t pgcount,int prot,gfp_t gfp,size_t *mapped)
@@ -585,6 +593,7 @@ static const struct iommu_ops mtk_iommu_v1_ops = { .def_domain_type = mtk_iommu_v1_def_domain_type, .device_group = generic_device_group, .pgsize_bitmap = MT2701_IOMMU_PAGE_SIZE, + .set_platform_dma = mtk_iommu_v1_set_platform_dma, .owner = THIS_MODULE, .default_domain_ops = &(const struct iommu_domain_ops ) { .attach_dev = mtk_iommu_v1_attach_device,
Signature · 1 line
2.34.1
Lu Baolu
maintainerPATCH v3 14/20 iommu/omap: Add set_platform_dma callback
In reply to Lu BaoluThis IOMMU driver doesn't support default domain. Add the implementation of set_platform_dma callback so that the IOMMU core could return the DMA control.
--- drivers/iommu/omap-iommu.c | 9 +++++++++ 1 file changed, 9 insertions(+)
drivers/iommu/omap-iommu.c +9 -0
@@ -1566,6 +1566,14 @@ static void omap_iommu_detach_dev(struct iommu_domain *domain,spin_unlock (&omap_domain->lock); } +static void omap_iommu_set_platform_dma (struct device *dev) +{ +struct iommu_domain *domain =iommu_get_domain_for_dev (dev); + +if (domain) +omap_iommu_detach_dev (domain, dev); +} +static struct iommu_domain *omap_iommu_domain_alloc (unsigned type) {struct omap_iommu_domain *omap_domain;
@@ -1737,6 +1745,7 @@ static const struct iommu_ops omap_iommu_ops = { .probe_device = omap_iommu_probe_device, .release_device = omap_iommu_release_device, .device_group = omap_iommu_device_group, + .set_platform_dma = omap_iommu_set_platform_dma, .pgsize_bitmap = OMAP_IOMMU_PGSIZES, .default_domain_ops = &(const struct iommu_domain_ops ) { .attach_dev = omap_iommu_attach_dev,
Signature · 1 line
2.34.1
Lu Baolu
maintainerPATCH v3 15/20 iommu/s390: Add set_platform_dma callback
In reply to Lu BaoluThis IOMMU driver doesn't support default domain. Add the implementation of set_platform_dma callback so that the IOMMU core could return the DMA control.
--- drivers/iommu/s390-iommu.c | 9 +++++++++ 1 file changed, 9 insertions(+)
drivers/iommu/s390-iommu.c +9 -0
@@ -179,6 +179,14 @@ static void s390_iommu_get_resv_regions(struct device *dev, } } +static void s390_iommu_set_platform_dma (struct device *dev) +{ +struct iommu_domain *domain =iommu_get_domain_for_dev (dev); + +if (domain) +s390_iommu_detach_device (domain, dev); +} +static struct iommu_device *s390_iommu_probe_device (struct device *dev) {struct zpci_dev *zdev;
@@ -435,6 +443,7 @@ static const struct iommu_ops s390_iommu_ops = { .probe_device = s390_iommu_probe_device, .release_device = s390_iommu_release_device, .device_group = generic_device_group, + .set_platform_dma = s390_iommu_set_platform_dma, .pgsize_bitmap = SZ_4K, .get_resv_regions = s390_iommu_get_resv_regions, .default_domain_ops = &(const struct iommu_domain_ops ) {
Signature · 1 line
2.34.1
Lu Baolu
maintainerPATCH v3 17/20 iommu/tegra: Add set_platform_dma callback
In reply to Lu BaoluThis IOMMU driver doesn't support default domain. Add the implementation of set_platform_dma callback so that the IOMMU core could return the DMA control.
--- drivers/iommu/tegra-smmu.c | 9 +++++++++ 1 file changed, 9 insertions(+)
drivers/iommu/tegra-smmu.c +9 -0
@@ -527,6 +527,14 @@ static void tegra_smmu_detach_dev(struct iommu_domain *domain, struct device *de } } +static void tegra_smmu_set_platform_dma (struct device *dev) +{ +struct iommu_domain *domain =iommu_get_domain_for_dev (dev); + +if (domain) +tegra_smmu_detach_dev (domain, dev); +} +static void tegra_smmu_set_pde (struct tegra_smmu_as *as,unsigned long iova,u32 value) {
@@ -965,6 +973,7 @@ static const struct iommu_ops tegra_smmu_ops = { .domain_alloc = tegra_smmu_domain_alloc, .probe_device = tegra_smmu_probe_device, .device_group = tegra_smmu_device_group, + .set_platform_dma = tegra_smmu_set_platform_dma, .of_xlate = tegra_smmu_of_xlate, .pgsize_bitmap = SZ_4K, .default_domain_ops = &(const struct iommu_domain_ops ) {
Signature · 1 line
2.34.1
Lu Baolu
maintainerPATCH v3 16/20 iommu/gart: Add set_platform_dma callback
In reply to Lu BaoluThis IOMMU driver doesn't support default domain. Add the implementation of set_platform_dma callback so that the IOMMU core could return the DMA control.
--- drivers/iommu/tegra-gart.c | 9 +++++++++ 1 file changed, 9 insertions(+)
drivers/iommu/tegra-gart.c +9 -0
@@ -141,6 +141,14 @@ static void gart_iommu_detach_dev(struct iommu_domain *domain,spin_unlock (&gart->dom_lock); } +static void gart_iommu_set_platform_dma (struct device *dev) +{ +struct iommu_domain *domain =iommu_get_domain_for_dev (dev); + +if (domain) +gart_iommu_detach_dev (domain, dev); +} +static struct iommu_domain *gart_iommu_domain_alloc (unsigned type) {struct iommu_domain *domain;
@@ -270,6 +278,7 @@ static const struct iommu_ops gart_iommu_ops = { .domain_alloc = gart_iommu_domain_alloc, .probe_device = gart_iommu_probe_device, .device_group = generic_device_group, + .set_platform_dma = gart_iommu_set_platform_dma, .pgsize_bitmap = GART_IOMMU_PGSIZES, .of_xlate = gart_iommu_of_xlate, .default_domain_ops = &(const struct iommu_domain_ops ) {
Signature · 1 line
2.34.1
Lu Baolu
maintainerPATCH v3 18/20 iommu: Call set_platform_dma if default domain is unavailable
In reply to Lu BaoluIf the IOMMU driver has no default domain support, call set_platform_dma explicitly to return the kernel DMA control back to the platform DMA ops.
--- drivers/iommu/iommu.c | 28 ++++++++-------------------- 1 file changed, 8 insertions(+), 20 deletions(-)
drivers/iommu/iommu.c +8 -20
@@ -2040,16 +2040,6 @@ int iommu_deferred_attach(struct device *dev, struct iommu_domain *domain)return 0 ; } -static void __iommu_detach_device (struct iommu_domain *domain, -struct device *dev) -{ -if (iommu_is_attach_deferred (dev)) -return ; - - domain->ops->detach_dev (domain, dev); -trace_detach_device_from_domain (dev); -} -void iommu_detach_device (struct iommu_domain *domain,struct device *dev) {struct iommu_group *group;
@@ -2154,11 +2144,12 @@ int iommu_attach_group(struct iommu_domain *domain, struct iommu_group *group) }EXPORT_SYMBOL_GPL (iommu_attach_group); -static int iommu_group_do_detach_device (struct device *dev,void *data) +static int iommu_group_do_set_platform_dma (struct device *dev,void *data) { -struct iommu_domain *domain = data; +const struct iommu_ops *ops =dev_iommu_ops (dev); -__iommu_detach_device (domain, dev); +if (!WARN_ON (!ops->set_platform_dma)) + ops->set_platform_dma (dev);return 0 ; }
@@ -2172,15 +2163,12 @@ static int __iommu_group_set_domain(struct iommu_group *group,return 0 ;/* -* New drivers should support default domains and so the detach_dev() op -* will never be called. Otherwise the NULL domain represents some -* platform specific behavior. +* New drivers should support default domains. Otherwise the NULL +* domain represents returning control back to the platform DMA. */ if (!new_domain) { -if (WARN_ON (!group->domain->ops->detach_dev)) -return -EINVAL ; -__iommu_group_for_each_dev (group, group->domain, - iommu_group_do_detach_device); +__iommu_group_for_each_dev (group,NULL , + iommu_group_do_set_platform_dma); group->domain =NULL ;return 0 ; }
Signature · 1 line
2.34.1
Lu Baolu
maintainerPATCH v3 19/20 iommu: Retire detach_dev callback
In reply to Lu BaoluThe detach_dev callback of domain ops is not used in the IOMMU core. Remove this callback to avoid dead code.
--- include/linux/iommu.h | 2 -- drivers/iommu/fsl_pamu_domain.c | 1 - drivers/iommu/msm_iommu.c | 1 - drivers/iommu/mtk_iommu_v1.c | 1 - drivers/iommu/omap-iommu.c | 1 - drivers/iommu/s390-iommu.c | 1 - drivers/iommu/tegra-gart.c | 1 - drivers/iommu/tegra-smmu.c | 1 - 8 files changed, 9 deletions(-)
include/linux/iommu.h +0 -2
@@ -294,7 +294,6 @@ struct iommu_ops {* * EBUSY - device is attached to a domain and cannot be changed * * ENODEV - device specific errors, not able to be attached * * <others> - treated as ENODEV by the caller. Use is discouraged -* @detach_dev: detach an iommu domain from a device * @set_dev_pasid: set an iommu domain to a pasid of device * @map: map a physically contiguous memory region to an iommu domain * @map_pages: map a physically contiguous set of pages of the same size to
@@ -315,7 +314,6 @@ struct iommu_ops {*/ struct iommu_domain_ops {int (*attach_dev)(struct iommu_domain *domain,struct device *dev); -void (*detach_dev)(struct iommu_domain *domain,struct device *dev);int (*set_dev_pasid)(struct iommu_domain *domain,struct device *dev,ioasid_t pasid);
drivers/iommu/fsl_pamu_domain.c +0 -1
@@ -463,7 +463,6 @@ static const struct iommu_ops fsl_pamu_ops = { .set_platform_dma = fsl_pamu_set_platform_dma; .default_domain_ops = &(const struct iommu_domain_ops) { .attach_dev = fsl_pamu_attach_device, - .detach_dev = fsl_pamu_detach_device, .iova_to_phys = fsl_pamu_iova_to_phys, .free = fsl_pamu_domain_free, }
drivers/iommu/msm_iommu.c +0 -1
@@ -691,7 +691,6 @@ static struct iommu_ops msm_iommu_ops = { .of_xlate = qcom_iommu_of_xlate, .default_domain_ops = &(const struct iommu_domain_ops ) { .attach_dev = msm_iommu_attach_dev, - .detach_dev = msm_iommu_detach_dev, .map_pages = msm_iommu_map, .unmap_pages = msm_iommu_unmap,/*
drivers/iommu/mtk_iommu_v1.c +0 -1
@@ -597,7 +597,6 @@ static const struct iommu_ops mtk_iommu_v1_ops = { .owner = THIS_MODULE, .default_domain_ops = &(const struct iommu_domain_ops ) { .attach_dev = mtk_iommu_v1_attach_device, - .detach_dev = mtk_iommu_v1_detach_device, .map_pages = mtk_iommu_v1_map, .unmap_pages = mtk_iommu_v1_unmap, .iova_to_phys = mtk_iommu_v1_iova_to_phys,
drivers/iommu/omap-iommu.c +0 -1
@@ -1749,7 +1749,6 @@ static const struct iommu_ops omap_iommu_ops = { .pgsize_bitmap = OMAP_IOMMU_PGSIZES, .default_domain_ops = &(const struct iommu_domain_ops ) { .attach_dev = omap_iommu_attach_dev, - .detach_dev = omap_iommu_detach_dev, .map = omap_iommu_map, .unmap = omap_iommu_unmap, .iova_to_phys = omap_iommu_iova_to_phys,
drivers/iommu/s390-iommu.c +0 -1
@@ -448,7 +448,6 @@ static const struct iommu_ops s390_iommu_ops = { .get_resv_regions = s390_iommu_get_resv_regions, .default_domain_ops = &(const struct iommu_domain_ops ) { .attach_dev = s390_iommu_attach_device, - .detach_dev = s390_iommu_detach_device, .map_pages = s390_iommu_map_pages, .unmap_pages = s390_iommu_unmap_pages, .flush_iotlb_all = s390_iommu_flush_iotlb_all,
drivers/iommu/tegra-gart.c +0 -1
@@ -283,7 +283,6 @@ static const struct iommu_ops gart_iommu_ops = { .of_xlate = gart_iommu_of_xlate, .default_domain_ops = &(const struct iommu_domain_ops ) { .attach_dev = gart_iommu_attach_dev, - .detach_dev = gart_iommu_detach_dev, .map = gart_iommu_map, .unmap = gart_iommu_unmap, .iova_to_phys = gart_iommu_iova_to_phys,
drivers/iommu/tegra-smmu.c +0 -1
@@ -978,7 +978,6 @@ static const struct iommu_ops tegra_smmu_ops = { .pgsize_bitmap = SZ_4K, .default_domain_ops = &(const struct iommu_domain_ops ) { .attach_dev = tegra_smmu_attach_dev, - .detach_dev = tegra_smmu_detach_dev, .map = tegra_smmu_map, .unmap = tegra_smmu_unmap, .iova_to_phys = tegra_smmu_iova_to_phys,
Signature · 1 line
2.34.1
Lu Baolu
maintainerPATCH v3 20/20 iommu: Rename attach_dev to set_dev
In reply to Lu BaoluWith the retirement of the detach_dev callback, the naming of attach_dev isn't meaningful anymore. Rename it to set_dev to restore its real meaning, that is, setting an iommu domain to a device.
--- include/linux/iommu.h | 4 ++-- drivers/iommu/amd/iommu.c | 2 +- drivers/iommu/apple-dart.c | 2 +- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 2 +- drivers/iommu/arm/arm-smmu/arm-smmu.c | 2 +- drivers/iommu/arm/arm-smmu/qcom_iommu.c | 2 +- drivers/iommu/exynos-iommu.c | 2 +- drivers/iommu/fsl_pamu_domain.c | 2 +- drivers/iommu/intel/iommu.c | 4 ++-- drivers/iommu/iommu.c | 4 ++-- drivers/iommu/ipmmu-vmsa.c | 2 +- drivers/iommu/msm_iommu.c | 2 +- drivers/iommu/mtk_iommu.c | 2 +- drivers/iommu/mtk_iommu_v1.c | 2 +- drivers/iommu/omap-iommu.c | 2 +- drivers/iommu/rockchip-iommu.c | 2 +- drivers/iommu/s390-iommu.c | 2 +- drivers/iommu/sprd-iommu.c | 2 +- drivers/iommu/sun50i-iommu.c | 2 +- drivers/iommu/tegra-gart.c | 2 +- drivers/iommu/tegra-smmu.c | 2 +- drivers/iommu/virtio-iommu.c | 2 +- 22 files changed, 25 insertions(+), 25 deletions(-)
include/linux/iommu.h +2 -2
@@ -281,7 +281,7 @@ struct iommu_ops {/** * struct iommu_domain_ops - domain specific operations -* @attach_dev: attach an iommu domain to a device +* @set_dev: set an iommu domain to a device * Return: * * 0 - success * * EINVAL - can indicate that device and domain are incompatible due to
@@ -313,7 +313,7 @@ struct iommu_ops {* @free: Release the domain after use. */ struct iommu_domain_ops { -int (*attach_dev)(struct iommu_domain *domain,struct device *dev); +int (*set_dev)(struct iommu_domain *domain,struct device *dev);int (*set_dev_pasid)(struct iommu_domain *domain,struct device *dev,ioasid_t pasid);
drivers/iommu/amd/iommu.c +1 -1
@@ -2388,7 +2388,7 @@ const struct iommu_ops amd_iommu_ops = { .pgsize_bitmap = AMD_IOMMU_PGSIZES, .def_domain_type = amd_iommu_def_domain_type, .default_domain_ops = &(const struct iommu_domain_ops ) { - .attach_dev = amd_iommu_attach_device, + .set_dev = amd_iommu_attach_device, .map_pages = amd_iommu_map_pages, .unmap_pages = amd_iommu_unmap_pages, .iotlb_sync_map = amd_iommu_iotlb_sync_map,
drivers/iommu/apple-dart.c +1 -1
@@ -763,7 +763,7 @@ static const struct iommu_ops apple_dart_iommu_ops = { .pgsize_bitmap = -1UL, /* Restricted during dart probe */ .owner = THIS_MODULE, .default_domain_ops = &(const struct iommu_domain_ops ) { - .attach_dev = apple_dart_attach_dev, + .set_dev = apple_dart_attach_dev, .map_pages = apple_dart_map_pages, .unmap_pages = apple_dart_unmap_pages, .flush_iotlb_all = apple_dart_flush_iotlb_all,
drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +1 -1
@@ -2859,7 +2859,7 @@ static struct iommu_ops arm_smmu_ops = { .pgsize_bitmap = -1UL, /* Restricted during device attach */ .owner = THIS_MODULE, .default_domain_ops = &(const struct iommu_domain_ops ) { - .attach_dev = arm_smmu_attach_dev, + .set_dev = arm_smmu_attach_dev, .map_pages = arm_smmu_map_pages, .unmap_pages = arm_smmu_unmap_pages, .flush_iotlb_all = arm_smmu_flush_iotlb_all,
drivers/iommu/arm/arm-smmu/arm-smmu.c +1 -1
@@ -1567,7 +1567,7 @@ static struct iommu_ops arm_smmu_ops = { .pgsize_bitmap = -1UL, /* Restricted during device attach */ .owner = THIS_MODULE, .default_domain_ops = &(const struct iommu_domain_ops ) { - .attach_dev = arm_smmu_attach_dev, + .set_dev = arm_smmu_attach_dev, .map_pages = arm_smmu_map_pages, .unmap_pages = arm_smmu_unmap_pages, .flush_iotlb_all = arm_smmu_flush_iotlb_all,
drivers/iommu/arm/arm-smmu/qcom_iommu.c +1 -1
@@ -560,7 +560,7 @@ static const struct iommu_ops qcom_iommu_ops = { .of_xlate = qcom_iommu_of_xlate, .pgsize_bitmap = SZ_4K | SZ_64K | SZ_1M | SZ_16M, .default_domain_ops = &(const struct iommu_domain_ops ) { - .attach_dev = qcom_iommu_attach_dev, + .set_dev = qcom_iommu_attach_dev, .map_pages = qcom_iommu_map, .unmap_pages = qcom_iommu_unmap, .flush_iotlb_all = qcom_iommu_flush_iotlb_all,
drivers/iommu/exynos-iommu.c +1 -1
@@ -1403,7 +1403,7 @@ static const struct iommu_ops exynos_iommu_ops = { .pgsize_bitmap = SECT_SIZE | LPAGE_SIZE | SPAGE_SIZE, .of_xlate = exynos_iommu_of_xlate, .default_domain_ops = &(const struct iommu_domain_ops ) { - .attach_dev = exynos_iommu_attach_device, + .set_dev = exynos_iommu_attach_device, .map = exynos_iommu_map, .unmap = exynos_iommu_unmap, .iova_to_phys = exynos_iommu_iova_to_phys,
drivers/iommu/fsl_pamu_domain.c +1 -1
@@ -462,7 +462,7 @@ static const struct iommu_ops fsl_pamu_ops = { .device_group = fsl_pamu_device_group, .set_platform_dma = fsl_pamu_set_platform_dma; .default_domain_ops = &(const struct iommu_domain_ops) { - .attach_dev = fsl_pamu_attach_device, + .set_dev = fsl_pamu_attach_device, .iova_to_phys = fsl_pamu_iova_to_phys, .free = fsl_pamu_domain_free, }
drivers/iommu/intel/iommu.c +2 -2
@@ -4131,7 +4131,7 @@ static int blocking_domain_attach_dev(struct iommu_domain *domain,static struct iommu_domain blocking_domain = { .ops = &(const struct iommu_domain_ops ) { - .attach_dev = blocking_domain_attach_dev, + .set_dev = blocking_domain_attach_dev, .free = intel_iommu_domain_free } };
@@ -4750,7 +4750,7 @@ const struct iommu_ops intel_iommu_ops = { .page_response = intel_svm_page_response, #endif .default_domain_ops = &(const struct iommu_domain_ops) { - .attach_dev = intel_iommu_attach_device, + .set_dev = intel_iommu_attach_device, .map_pages = intel_iommu_map_pages, .unmap_pages = intel_iommu_unmap_pages, .iotlb_sync_map = intel_iommu_iotlb_sync_map,
drivers/iommu/iommu.c +2 -2
@@ -1983,10 +1983,10 @@ static int __iommu_attach_device(struct iommu_domain *domain, {int ret; -if (unlikely (domain->ops->attach_dev ==NULL )) +if (unlikely (!domain->ops->set_dev))return -ENODEV ; - ret = domain->ops->attach_dev (domain, dev); + ret = domain->ops->set_dev (domain, dev);if (!ret)trace_attach_device_to_domain (dev);return ret;
drivers/iommu/ipmmu-vmsa.c +1 -1
@@ -860,7 +860,7 @@ static const struct iommu_ops ipmmu_ops = { .pgsize_bitmap = SZ_1G | SZ_2M | SZ_4K, .of_xlate = ipmmu_of_xlate, .default_domain_ops = &(const struct iommu_domain_ops ) { - .attach_dev = ipmmu_attach_device, + .set_dev = ipmmu_attach_device, .map_pages = ipmmu_map, .unmap_pages = ipmmu_unmap, .flush_iotlb_all = ipmmu_flush_iotlb_all,
drivers/iommu/msm_iommu.c +1 -1
@@ -690,7 +690,7 @@ static struct iommu_ops msm_iommu_ops = { .pgsize_bitmap = MSM_IOMMU_PGSIZES, .of_xlate = qcom_iommu_of_xlate, .default_domain_ops = &(const struct iommu_domain_ops ) { - .attach_dev = msm_iommu_attach_dev, + .set_dev = msm_iommu_attach_dev, .map_pages = msm_iommu_map, .unmap_pages = msm_iommu_unmap,/*
drivers/iommu/mtk_iommu.c +1 -1
@@ -940,7 +940,7 @@ static const struct iommu_ops mtk_iommu_ops = { .pgsize_bitmap = SZ_4K | SZ_64K | SZ_1M | SZ_16M, .owner = THIS_MODULE, .default_domain_ops = &(const struct iommu_domain_ops ) { - .attach_dev = mtk_iommu_attach_device, + .set_dev = mtk_iommu_attach_device, .map_pages = mtk_iommu_map, .unmap_pages = mtk_iommu_unmap, .flush_iotlb_all = mtk_iommu_flush_iotlb_all,
drivers/iommu/mtk_iommu_v1.c +1 -1
@@ -596,7 +596,7 @@ static const struct iommu_ops mtk_iommu_v1_ops = { .set_platform_dma = mtk_iommu_v1_set_platform_dma, .owner = THIS_MODULE, .default_domain_ops = &(const struct iommu_domain_ops ) { - .attach_dev = mtk_iommu_v1_attach_device, + .set_dev = mtk_iommu_v1_attach_device, .map_pages = mtk_iommu_v1_map, .unmap_pages = mtk_iommu_v1_unmap, .iova_to_phys = mtk_iommu_v1_iova_to_phys,
drivers/iommu/omap-iommu.c +1 -1
@@ -1748,7 +1748,7 @@ static const struct iommu_ops omap_iommu_ops = { .set_platform_dma = omap_iommu_set_platform_dma, .pgsize_bitmap = OMAP_IOMMU_PGSIZES, .default_domain_ops = &(const struct iommu_domain_ops ) { - .attach_dev = omap_iommu_attach_dev, + .set_dev = omap_iommu_attach_dev, .map = omap_iommu_map, .unmap = omap_iommu_unmap, .iova_to_phys = omap_iommu_iova_to_phys,
drivers/iommu/rockchip-iommu.c +1 -1
@@ -1191,7 +1191,7 @@ static const struct iommu_ops rk_iommu_ops = { .pgsize_bitmap = RK_IOMMU_PGSIZE_BITMAP, .of_xlate = rk_iommu_of_xlate, .default_domain_ops = &(const struct iommu_domain_ops ) { - .attach_dev = rk_iommu_attach_device, + .set_dev = rk_iommu_attach_device, .map = rk_iommu_map, .unmap = rk_iommu_unmap, .iova_to_phys = rk_iommu_iova_to_phys,
drivers/iommu/s390-iommu.c +1 -1
@@ -447,7 +447,7 @@ static const struct iommu_ops s390_iommu_ops = { .pgsize_bitmap = SZ_4K, .get_resv_regions = s390_iommu_get_resv_regions, .default_domain_ops = &(const struct iommu_domain_ops ) { - .attach_dev = s390_iommu_attach_device, + .set_dev = s390_iommu_attach_device, .map_pages = s390_iommu_map_pages, .unmap_pages = s390_iommu_unmap_pages, .flush_iotlb_all = s390_iommu_flush_iotlb_all,
drivers/iommu/sprd-iommu.c +1 -1
@@ -398,7 +398,7 @@ static const struct iommu_ops sprd_iommu_ops = { .pgsize_bitmap = SPRD_IOMMU_PAGE_SIZE, .owner = THIS_MODULE, .default_domain_ops = &(const struct iommu_domain_ops ) { - .attach_dev = sprd_iommu_attach_device, + .set_dev = sprd_iommu_attach_device, .map_pages = sprd_iommu_map, .unmap_pages = sprd_iommu_unmap, .iotlb_sync_map = sprd_iommu_sync_map,
drivers/iommu/sun50i-iommu.c +1 -1
@@ -834,7 +834,7 @@ static const struct iommu_ops sun50i_iommu_ops = { .of_xlate = sun50i_iommu_of_xlate, .probe_device = sun50i_iommu_probe_device, .default_domain_ops = &(const struct iommu_domain_ops ) { - .attach_dev = sun50i_iommu_attach_device, + .set_dev = sun50i_iommu_attach_device, .flush_iotlb_all = sun50i_iommu_flush_iotlb_all, .iotlb_sync_map = sun50i_iommu_iotlb_sync_map, .iotlb_sync = sun50i_iommu_iotlb_sync,
drivers/iommu/tegra-gart.c +1 -1
@@ -282,7 +282,7 @@ static const struct iommu_ops gart_iommu_ops = { .pgsize_bitmap = GART_IOMMU_PGSIZES, .of_xlate = gart_iommu_of_xlate, .default_domain_ops = &(const struct iommu_domain_ops ) { - .attach_dev = gart_iommu_attach_dev, + .set_dev = gart_iommu_attach_dev, .map = gart_iommu_map, .unmap = gart_iommu_unmap, .iova_to_phys = gart_iommu_iova_to_phys,
drivers/iommu/tegra-smmu.c +1 -1
@@ -977,7 +977,7 @@ static const struct iommu_ops tegra_smmu_ops = { .of_xlate = tegra_smmu_of_xlate, .pgsize_bitmap = SZ_4K, .default_domain_ops = &(const struct iommu_domain_ops ) { - .attach_dev = tegra_smmu_attach_dev, + .set_dev = tegra_smmu_attach_dev, .map = tegra_smmu_map, .unmap = tegra_smmu_unmap, .iova_to_phys = tegra_smmu_iova_to_phys,
drivers/iommu/virtio-iommu.c +1 -1
@@ -1028,7 +1028,7 @@ static struct iommu_ops viommu_ops = { .of_xlate = viommu_of_xlate, .owner = THIS_MODULE, .default_domain_ops = &(const struct iommu_domain_ops ) { - .attach_dev = viommu_attach_dev, + .set_dev = viommu_attach_dev, .map_pages = viommu_map_pages, .unmap_pages = viommu_unmap_pages, .iova_to_phys = viommu_iova_to_phys,
Signature · 1 line
2.34.1
Robin Murphy
reviewerRe: [PATCH v3 20/20] iommu: Rename attach_dev to set_dev
Quoted 3 lines · Lu Baolu
With the retirement of the
detach_devcallback, the naming ofattach_devisn't meaningful anymore. Rename it toset_devto restore its real meaning, that is, setting an iommu domain to a device.
English grammar alert: this part is confusing, since the usual in-context reading* of "set[ting] X to Y" is going to imply assigning a value of Y to some unique property of X. Given the actual semantic that when we attach the device to the domain, we are setting the (current) domain as a property of the device, I think the most logical and intuitive abbreviation for this method would be set_domain(), where the target device is then clearly implied by the argument (as the target domain was for attach_dev()).
FWIW I also wouldn't say that "attach" loses its meaning in a context where an equivalent "detach" operation is only ever implicit in reattaching to something else, however I do agree that it *is* worth switching the terminology to clearly differentiate this internal behaviour from the public attach/detach API for unmanaged domains.
Thanks,
Robin.
[*] Note that It's not strictly incorrect, but "set to" in the sense of starting work, e.g. "At 6PM I set to cooking dinner", is much less commonly used, especially in code. Although I think technically set_dev_to(dev, domain) would work gramatically to abbreviate that sense of "set device to start using domain", it's still rather obscure and not much less ambiguous.
Quoted 334 lines
Signed-off-by Lu Baolu <[email protected]>--- include/linux/iommu.h | 4 ++-- drivers/iommu/amd/iommu.c | 2 +- drivers/iommu/apple-dart.c | 2 +- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 2 +- drivers/iommu/arm/arm-smmu/arm-smmu.c | 2 +- drivers/iommu/arm/arm-smmu/qcom_iommu.c | 2 +- drivers/iommu/exynos-iommu.c | 2 +- drivers/iommu/fsl_pamu_domain.c | 2 +- drivers/iommu/intel/iommu.c | 4 ++-- drivers/iommu/iommu.c | 4 ++-- drivers/iommu/ipmmu-vmsa.c | 2 +- drivers/iommu/msm_iommu.c | 2 +- drivers/iommu/mtk_iommu.c | 2 +- drivers/iommu/mtk_iommu_v1.c | 2 +- drivers/iommu/omap-iommu.c | 2 +- drivers/iommu/rockchip-iommu.c | 2 +- drivers/iommu/s390-iommu.c | 2 +- drivers/iommu/sprd-iommu.c | 2 +- drivers/iommu/sun50i-iommu.c | 2 +- drivers/iommu/tegra-gart.c | 2 +- drivers/iommu/tegra-smmu.c | 2 +- drivers/iommu/virtio-iommu.c | 2 +- 22 files changed, 25 insertions(+), 25 deletions(-)include/linux/iommu.h +2
-2@@ -281,7 +281,7 @@ struct iommu_ops {/** * struct iommu_domain_ops - domain specific operations -* @attach_dev: attach an iommu domain to a device +* @set_dev: set an iommu domain to a device * Return: * * 0 - success * * EINVAL - can indicate that device and domain are incompatible due to @@ -313,7 +313,7 @@ struct iommu_ops {* @free: Release the domain after use. */ struct iommu_domain_ops { -int (*attach_dev)(struct iommu_domain *domain,struct device *dev); +int (*set_dev)(struct iommu_domain *domain,struct device *dev);int (*set_dev_pasid)(struct iommu_domain *domain,struct device *dev,ioasid_t pasid);drivers/iommu/amd/iommu.c +1
-1@@ -2388,7 +2388,7 @@ const struct iommu_ops amd_iommu_ops = { .pgsize_bitmap = AMD_IOMMU_PGSIZES, .def_domain_type = amd_iommu_def_domain_type, .default_domain_ops = &(const struct iommu_domain_ops ) { - .attach_dev = amd_iommu_attach_device, + .set_dev = amd_iommu_attach_device, .map_pages = amd_iommu_map_pages, .unmap_pages = amd_iommu_unmap_pages, .iotlb_sync_map = amd_iommu_iotlb_sync_map,drivers/iommu/apple-dart.c +1
-1@@ -763,7 +763,7 @@ static const struct iommu_ops apple_dart_iommu_ops = { .pgsize_bitmap = -1UL, /* Restricted during dart probe */ .owner = THIS_MODULE, .default_domain_ops = &(const struct iommu_domain_ops ) { - .attach_dev = apple_dart_attach_dev, + .set_dev = apple_dart_attach_dev, .map_pages = apple_dart_map_pages, .unmap_pages = apple_dart_unmap_pages, .flush_iotlb_all = apple_dart_flush_iotlb_all,drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +1
-1@@ -2859,7 +2859,7 @@ static struct iommu_ops arm_smmu_ops = { .pgsize_bitmap = -1UL, /* Restricted during device attach */ .owner = THIS_MODULE, .default_domain_ops = &(const struct iommu_domain_ops ) { - .attach_dev = arm_smmu_attach_dev, + .set_dev = arm_smmu_attach_dev, .map_pages = arm_smmu_map_pages, .unmap_pages = arm_smmu_unmap_pages, .flush_iotlb_all = arm_smmu_flush_iotlb_all,drivers/iommu/arm/arm-smmu/arm-smmu.c +1
-1@@ -1567,7 +1567,7 @@ static struct iommu_ops arm_smmu_ops = { .pgsize_bitmap = -1UL, /* Restricted during device attach */ .owner = THIS_MODULE, .default_domain_ops = &(const struct iommu_domain_ops ) { - .attach_dev = arm_smmu_attach_dev, + .set_dev = arm_smmu_attach_dev, .map_pages = arm_smmu_map_pages, .unmap_pages = arm_smmu_unmap_pages, .flush_iotlb_all = arm_smmu_flush_iotlb_all,drivers/iommu/arm/arm-smmu/qcom_iommu.c +1
-1@@ -560,7 +560,7 @@ static const struct iommu_ops qcom_iommu_ops = { .of_xlate = qcom_iommu_of_xlate, .pgsize_bitmap = SZ_4K | SZ_64K | SZ_1M | SZ_16M, .default_domain_ops = &(const struct iommu_domain_ops ) { - .attach_dev = qcom_iommu_attach_dev, + .set_dev = qcom_iommu_attach_dev, .map_pages = qcom_iommu_map, .unmap_pages = qcom_iommu_unmap, .flush_iotlb_all = qcom_iommu_flush_iotlb_all,drivers/iommu/exynos-iommu.c +1
-1@@ -1403,7 +1403,7 @@ static const struct iommu_ops exynos_iommu_ops = { .pgsize_bitmap = SECT_SIZE | LPAGE_SIZE | SPAGE_SIZE, .of_xlate = exynos_iommu_of_xlate, .default_domain_ops = &(const struct iommu_domain_ops ) { - .attach_dev = exynos_iommu_attach_device, + .set_dev = exynos_iommu_attach_device, .map = exynos_iommu_map, .unmap = exynos_iommu_unmap, .iova_to_phys = exynos_iommu_iova_to_phys,drivers/iommu/fsl_pamu_domain.c +1
-1@@ -462,7 +462,7 @@ static const struct iommu_ops fsl_pamu_ops = { .device_group = fsl_pamu_device_group, .set_platform_dma = fsl_pamu_set_platform_dma; .default_domain_ops = &(const struct iommu_domain_ops) { - .attach_dev = fsl_pamu_attach_device, + .set_dev = fsl_pamu_attach_device, .iova_to_phys = fsl_pamu_iova_to_phys, .free = fsl_pamu_domain_free, }drivers/iommu/intel/iommu.c +2
-2@@ -4131,7 +4131,7 @@ static int blocking_domain_attach_dev(struct iommu_domain *domain,static struct iommu_domain blocking_domain = { .ops = &(const struct iommu_domain_ops ) { - .attach_dev = blocking_domain_attach_dev, + .set_dev = blocking_domain_attach_dev, .free = intel_iommu_domain_free } };@@ -4750,7 +4750,7 @@ const struct iommu_ops intel_iommu_ops = { .page_response = intel_svm_page_response, #endif .default_domain_ops = &(const struct iommu_domain_ops) { - .attach_dev = intel_iommu_attach_device, + .set_dev = intel_iommu_attach_device, .map_pages = intel_iommu_map_pages, .unmap_pages = intel_iommu_unmap_pages, .iotlb_sync_map = intel_iommu_iotlb_sync_map,drivers/iommu/iommu.c +2
-2@@ -1983,10 +1983,10 @@ static int __iommu_attach_device(struct iommu_domain *domain, {int ret; -if (unlikely (domain->ops->attach_dev ==NULL )) +if (unlikely (!domain->ops->set_dev))return -ENODEV ; - ret = domain->ops->attach_dev (domain, dev); + ret = domain->ops->set_dev (domain, dev);if (!ret)trace_attach_device_to_domain (dev);return ret;drivers/iommu/ipmmu-vmsa.c +1
-1@@ -860,7 +860,7 @@ static const struct iommu_ops ipmmu_ops = { .pgsize_bitmap = SZ_1G | SZ_2M | SZ_4K, .of_xlate = ipmmu_of_xlate, .default_domain_ops = &(const struct iommu_domain_ops ) { - .attach_dev = ipmmu_attach_device, + .set_dev = ipmmu_attach_device, .map_pages = ipmmu_map, .unmap_pages = ipmmu_unmap, .flush_iotlb_all = ipmmu_flush_iotlb_all,drivers/iommu/msm_iommu.c +1
-1@@ -690,7 +690,7 @@ static struct iommu_ops msm_iommu_ops = { .pgsize_bitmap = MSM_IOMMU_PGSIZES, .of_xlate = qcom_iommu_of_xlate, .default_domain_ops = &(const struct iommu_domain_ops ) { - .attach_dev = msm_iommu_attach_dev, + .set_dev = msm_iommu_attach_dev, .map_pages = msm_iommu_map, .unmap_pages = msm_iommu_unmap,/* drivers/iommu/mtk_iommu.c +1
-1@@ -940,7 +940,7 @@ static const struct iommu_ops mtk_iommu_ops = { .pgsize_bitmap = SZ_4K | SZ_64K | SZ_1M | SZ_16M, .owner = THIS_MODULE, .default_domain_ops = &(const struct iommu_domain_ops ) { - .attach_dev = mtk_iommu_attach_device, + .set_dev = mtk_iommu_attach_device, .map_pages = mtk_iommu_map, .unmap_pages = mtk_iommu_unmap, .flush_iotlb_all = mtk_iommu_flush_iotlb_all,drivers/iommu/mtk_iommu_v1.c +1
-1@@ -596,7 +596,7 @@ static const struct iommu_ops mtk_iommu_v1_ops = { .set_platform_dma = mtk_iommu_v1_set_platform_dma, .owner = THIS_MODULE, .default_domain_ops = &(const struct iommu_domain_ops ) { - .attach_dev = mtk_iommu_v1_attach_device, + .set_dev = mtk_iommu_v1_attach_device, .map_pages = mtk_iommu_v1_map, .unmap_pages = mtk_iommu_v1_unmap, .iova_to_phys = mtk_iommu_v1_iova_to_phys,drivers/iommu/omap-iommu.c +1
-1@@ -1748,7 +1748,7 @@ static const struct iommu_ops omap_iommu_ops = { .set_platform_dma = omap_iommu_set_platform_dma, .pgsize_bitmap = OMAP_IOMMU_PGSIZES, .default_domain_ops = &(const struct iommu_domain_ops ) { - .attach_dev = omap_iommu_attach_dev, + .set_dev = omap_iommu_attach_dev, .map = omap_iommu_map, .unmap = omap_iommu_unmap, .iova_to_phys = omap_iommu_iova_to_phys,drivers/iommu/rockchip-iommu.c +1
-1@@ -1191,7 +1191,7 @@ static const struct iommu_ops rk_iommu_ops = { .pgsize_bitmap = RK_IOMMU_PGSIZE_BITMAP, .of_xlate = rk_iommu_of_xlate, .default_domain_ops = &(const struct iommu_domain_ops ) { - .attach_dev = rk_iommu_attach_device, + .set_dev = rk_iommu_attach_device, .map = rk_iommu_map, .unmap = rk_iommu_unmap, .iova_to_phys = rk_iommu_iova_to_phys,drivers/iommu/s390-iommu.c +1
-1@@ -447,7 +447,7 @@ static const struct iommu_ops s390_iommu_ops = { .pgsize_bitmap = SZ_4K, .get_resv_regions = s390_iommu_get_resv_regions, .default_domain_ops = &(const struct iommu_domain_ops ) { - .attach_dev = s390_iommu_attach_device, + .set_dev = s390_iommu_attach_device, .map_pages = s390_iommu_map_pages, .unmap_pages = s390_iommu_unmap_pages, .flush_iotlb_all = s390_iommu_flush_iotlb_all,drivers/iommu/sprd-iommu.c +1
-1@@ -398,7 +398,7 @@ static const struct iommu_ops sprd_iommu_ops = { .pgsize_bitmap = SPRD_IOMMU_PAGE_SIZE, .owner = THIS_MODULE, .default_domain_ops = &(const struct iommu_domain_ops ) { - .attach_dev = sprd_iommu_attach_device, + .set_dev = sprd_iommu_attach_device, .map_pages = sprd_iommu_map, .unmap_pages = sprd_iommu_unmap, .iotlb_sync_map = sprd_iommu_sync_map,drivers/iommu/sun50i-iommu.c +1
-1@@ -834,7 +834,7 @@ static const struct iommu_ops sun50i_iommu_ops = { .of_xlate = sun50i_iommu_of_xlate, .probe_device = sun50i_iommu_probe_device, .default_domain_ops = &(const struct iommu_domain_ops ) { - .attach_dev = sun50i_iommu_attach_device, + .set_dev = sun50i_iommu_attach_device, .flush_iotlb_all = sun50i_iommu_flush_iotlb_all, .iotlb_sync_map = sun50i_iommu_iotlb_sync_map, .iotlb_sync = sun50i_iommu_iotlb_sync,drivers/iommu/tegra-gart.c +1
-1@@ -282,7 +282,7 @@ static const struct iommu_ops gart_iommu_ops = { .pgsize_bitmap = GART_IOMMU_PGSIZES, .of_xlate = gart_iommu_of_xlate, .default_domain_ops = &(const struct iommu_domain_ops ) { - .attach_dev = gart_iommu_attach_dev, + .set_dev = gart_iommu_attach_dev, .map = gart_iommu_map, .unmap = gart_iommu_unmap, .iova_to_phys = gart_iommu_iova_to_phys,drivers/iommu/tegra-smmu.c +1
-1@@ -977,7 +977,7 @@ static const struct iommu_ops tegra_smmu_ops = { .of_xlate = tegra_smmu_of_xlate, .pgsize_bitmap = SZ_4K, .default_domain_ops = &(const struct iommu_domain_ops ) { - .attach_dev = tegra_smmu_attach_dev, + .set_dev = tegra_smmu_attach_dev, .map = tegra_smmu_map, .unmap = tegra_smmu_unmap, .iova_to_phys = tegra_smmu_iova_to_phys,drivers/iommu/virtio-iommu.c +1
-1@@ -1028,7 +1028,7 @@ static struct iommu_ops viommu_ops = { .of_xlate = viommu_of_xlate, .owner = THIS_MODULE, .default_domain_ops = &(const struct iommu_domain_ops ) { - .attach_dev = viommu_attach_dev, + .set_dev = viommu_attach_dev, .map_pages = viommu_map_pages, .unmap_pages = viommu_unmap_pages, .iova_to_phys = viommu_iova_to_phys,
Re: [PATCH v3 01/20] iommu/amd: Remove detach_dev callback
In reply to Lu BaoluQuoted 7 lines · Lu Baolu
The AMD IOMMU supports default domain, so the
detach_devop will never be called. Remove it to avoid dead code.Signed-off-by Lu Baolu <[email protected]>--- drivers/iommu/amd/iommu.c | 26 -------------------------- 1 file changed, 26 deletions(-)
Driver oweners should look at what their detach_dev does and comment in this series - eg if this is actually blocking DMA then it would be great to convert it into a blocking domain.
But there is no issue with deleting it, and the blocking domain is an optimization.
Jason
Re: [PATCH v3 02/20] iommu/apple-dart: Remove detach_dev callback
In reply to Lu BaoluQuoted 7 lines · Lu Baolu
The IOMMU driver supports default domain, so the
detach_devop will never be called. Remove it to avoid dead code.Signed-off-by Lu Baolu <[email protected]>--- drivers/iommu/apple-dart.c | 17 ----------------- 1 file changed, 17 deletions(-)
I suspect this is doing the blocking domain behavior..
Jason
Re: [PATCH v3 03/20] iommu/qcom: Remove detach_dev callback
In reply to Lu BaoluQuoted 7 lines · Lu Baolu
The IOMMU driver supports default domain, so the
detach_devop will never be called. Remove it to avoid dead code.Signed-off-by Lu Baolu <[email protected]>--- drivers/iommu/arm/arm-smmu/qcom_iommu.c | 23 ----------------------- 1 file changed, 23 deletions(-)
Jason
Re: [PATCH v3 04/20] iommu/exynos: Remove detach_dev callback
In reply to Lu BaoluQuoted 7 lines · Lu Baolu
The IOMMU driver supports default domain, so the
detach_devop will never be called. Remove it to avoid dead code.Signed-off-by Lu Baolu <[email protected]>--- drivers/iommu/exynos-iommu.c | 1 - 1 file changed, 1 deletion(-)
Jason
Re: [PATCH v3 05/20] iommu/ipmmu: Remove detach_dev callback
In reply to Lu BaoluQuoted 7 lines · Lu Baolu
The IOMMU driver supports default domain, so the
detach_devop will never be called. Remove it to avoid dead code.Signed-off-by Lu Baolu <[email protected]>--- drivers/iommu/ipmmu-vmsa.c | 16 ---------------- 1 file changed, 16 deletions(-)
Jason
Re: [PATCH v3 06/20] iommu/mtk: Remove detach_dev callback
In reply to Lu BaoluQuoted 7 lines · Lu Baolu
The IOMMU driver supports default domain, so the
detach_devop will never be called. Remove it to avoid dead code.Signed-off-by Lu Baolu <[email protected]>--- drivers/iommu/mtk_iommu.c | 9 --------- 1 file changed, 9 deletions(-)
I listed this driver as not supporting default domains:
https://lore.kernel.org/linux-iommu/[email protected]/
?
Has something changed? Did I get it wrong?
Jason
Re: [PATCH v3 07/20] iommu/rockchip: Remove detach_dev callback
In reply to Lu BaoluQuoted 7 lines · Lu Baolu
The IOMMU driver supports default domain, so the
detach_devop will never be called. Remove it to avoid dead code.Signed-off-by Lu Baolu <[email protected]>--- drivers/iommu/rockchip-iommu.c | 1 - 1 file changed, 1 deletion(-)
Jason
Re: [PATCH v3 08/20] iommu/sprd: Remove detach_dev callback
In reply to Lu BaoluQuoted 7 lines · Lu Baolu
The IOMMU driver supports default domain, so the
detach_devop will never be called. Remove it to avoid dead code.Signed-off-by Lu Baolu <[email protected]>--- drivers/iommu/sprd-iommu.c | 16 ---------------- 1 file changed, 16 deletions(-)
Jason
Robin Murphy
reviewerRe: [PATCH v3 06/20] iommu/mtk: Remove detach_dev callback
In reply to Jason GunthorpeQuoted 9 lines · Jason Gunthorpe
Quoted 7 lines · Lu Baolu
The IOMMU driver supports default domain, so the
detach_devop will never be called. Remove it to avoid dead code.Signed-off-by Lu Baolu <[email protected]>--- drivers/iommu/mtk_iommu.c | 9 --------- 1 file changed, 9 deletions(-)
Quoted 7 lines
I listed this driver as not supporting default domains:
https://lore.kernel.org/linux-iommu/[email protected]/
?
Has something changed? Did I get it wrong?
static struct iommu_domain *mtk_iommu_domain_alloc(unsigned type)
{
struct mtk_iommu_domain *dom;
if (type != IOMMU_DOMAIN_DMA && type != IOMMU_DOMAIN_UNMANAGED)
return NULL;...
This one runs on arm64, so has always supported default domains for iommu-dma to work.
Cheers,
Robin.
Re: [PATCH v3 09/20] iommu/sun50i: Remove detach_dev callback
In reply to Lu BaoluQuoted 7 lines · Lu Baolu
The IOMMU driver supports default domain, so the
detach_devop will never be called. Remove it to avoid dead code.Signed-off-by Lu Baolu <[email protected]>--- drivers/iommu/sun50i-iommu.c | 1 - 1 file changed, 1 deletion(-)
Jason
Re: [PATCH v3 10/20] iommu: Add set_platform_dma iommu ops
In reply to Lu BaoluQuoted 6 lines · Lu Baolu
When VFIO finishes assigning a device to user space and calls
iommu_group_release_dma_owner()to return the device to kernel, the IOMMU core will attach the default domain to the device. Unfortunately, some IOMMU drivers don't support default domain, hence in the end, the core calls .detach_dev instead.
Quoted 8 lines
This adds
set_platform_dmaiommu ops to make it clear that what it does is returning control back to the platform DMA ops.Suggested-by Jason Gunthorpe <[email protected]>Signed-off-by Lu Baolu <[email protected]>--- include/linux/iommu.h | 4 ++++ 1 file changed, 4 insertions(+)
Quoted 3 lines
+ * @set_platform_dma: Returning control back to the platform DMA ops. Only
+ * valid for IOMMU drivers which don't support default
+ * domain.
I would add:
This op is to support old IOMMU drivers, new drivers should use default domains, and the common IOMMU DMA ops.
Jason
Re: [PATCH v3 11/20] iommu/fsl_pamu: Add set_platform_dma callback
In reply to Lu BaoluQuoted 14 lines · Lu Baolu
This IOMMU driver doesn't support default domain. Add the implementation of
set_platform_dmacallback so that the IOMMU core could return the DMA control.Signed-off-by Lu Baolu <[email protected]>--- drivers/iommu/fsl_pamu_domain.c | 9 +++++++++ 1 file changed, 9 insertions(+)drivers/iommu/fsl_pamu_domain.c +0
-0
drivers/iommu/fsl_pamu_domain.c static void fsl_pamu_detach_device(struct iommu_domain *domain, · line 323
Quoted 10 lines
drivers/iommu/fsl_pamu_domain.c +7
-0@@ -314,6 +314,14 @@ static void fsl_pamu_detach_device(struct iommu_domain *domain,pr_debug ("missing fsl,liodn property at %pOF\n" , dev->of_node); } +static void fsl_pamu_set_platform_dma (struct device *dev) +{ +struct iommu_domain *domain =iommu_get_domain_for_dev (dev); + +if (domain) +fsl_pamu_detach_device (domain, dev); +}
This is a bit ugly, it would be better to make the previous patch call set_platform_dma if it is set instead of detach_dev and then these patches should just rename the driver's fsl_pamu_detach_device to fsl_pamu_set_platform_dma
Then the last patch just deletes the op and the core code
Jason
Re: [PATCH v3 18/20] iommu: Call set_platform_dma if default domain is unavailable
In reply to Lu BaoluQuoted 13 lines · Lu Baolu
If the IOMMU driver has no default domain support, call
set_platform_dmaexplicitly to return the kernel DMA control back to the platform DMA ops.Signed-off-by Lu Baolu <[email protected]>--- drivers/iommu/iommu.c | 28 ++++++++-------------------- 1 file changed, 8 insertions(+), 20 deletions(-)drivers/iommu/iommu.c +0
-0
drivers/iommu/iommu.c int iommu_deferred_attach(struct device *dev, struct iommu_domain *domain) · line 2047
Quoted 8 lines
drivers/iommu/iommu.c +0
-5@@ -2040,16 +2040,6 @@ int iommu_deferred_attach(struct device *dev, struct iommu_domain *domain)return 0 ; } -static void __iommu_detach_device (struct iommu_domain *domain, -struct device *dev) -{ -if (iommu_is_attach_deferred (dev)) -return ;
This removal might want to be its own patch with an explanation.
It looks like at the current moment __iommu_detach_device() is only called via call chains that are after the device driver is attached - eg via explicit attach APIs called by the device driver.
So it should just unconditionally work. It is actually looks like a bug that we were blocking detach on these paths since the attach was unconditional and the caller is going to free the (probably) UNAMANGED domain once this returns.
The only place we should be testing for deferred attach is during the initial point the dma device is linked to the group, and then again during the dma api calls to check if the device
This maybe the patch that is needed to explain this:
drivers/iommu/iommu.c +19 -17
@@ -993,8 +993,8 @@ int iommu_group_add_device(struct iommu_group *group, struct device *dev)mutex_lock (&group->mutex);list_add_tail (&device->list, &group->devices); -if (group->domain && !iommu_is_attach_deferred (dev)) - ret =__iommu_attach_device (group->domain, dev); +if (group->domain) + ret =iommu_group_do_dma_first_attach (dev, group->domain);mutex_unlock (&group->mutex);if (ret) goto err_put_group;
@@ -1760,21 +1760,24 @@ static void probe_alloc_default_domain(struct bus_type *bus, } -static int iommu_group_do_dma_attach (struct device *dev,void *data) +static int iommu_group_do_dma_first_attach (struct device *dev,void *data) {struct iommu_domain *domain = data; -int ret =0 ; -if (!iommu_is_attach_deferred (dev)) - ret =__iommu_attach_device (domain, dev); +lockdep_assert_held (&dev->iommu_group->mutex); -return ret; +if (iommu_is_attach_deferred (dev)) { + dev->iommu->attach_deferred =1 ; +return 0 ; + } + +return __iommu_attach_device (domain, dev); } -static int __iommu_group_dma_attach (struct iommu_group *group) +static int __iommu_group_dma_first_attach (struct iommu_group *group) {return __iommu_group_for_each_dev (group, group->default_domain, - iommu_group_do_dma_attach); + iommu_group_do_dma_first_attach); }static int iommu_group_do_probe_finalize (struct device *dev,void *data)
@@ -1839,7 +1842,7 @@ int bus_iommu_probe(struct bus_type *bus)iommu_group_create_direct_mappings (group); - ret =__iommu_group_dma_attach (group); + ret =__iommu_group_dma_first_attach (group);mutex_unlock (&group->mutex);
@@ -1971,9 +1974,11 @@ static int __iommu_attach_device(struct iommu_domain *domain,return -ENODEV ; ret = domain->ops->attach_dev (domain, dev); -if (!ret) -trace_attach_device_to_domain (dev); -return ret; +if (ret) +return ret; + dev->iommu->attach_deferred =0 ; +trace_attach_device_to_domain (dev); +return 0 ; }/**
@@ -2018,7 +2023,7 @@ EXPORT_SYMBOL_GPL(iommu_attach_device);int iommu_deferred_attach (struct device *dev,struct iommu_domain *domain) { -if (iommu_is_attach_deferred (dev)) +if (dev->iommu && dev->iommu->attach_deferred)return __iommu_attach_device (domain, dev);return 0 ;
@@ -2027,9 +2032,6 @@ int iommu_deferred_attach(struct device *dev, struct iommu_domain *domain)static void __iommu_detach_device (struct iommu_domain *domain,struct device *dev) { -if (iommu_is_attach_deferred (dev)) -return ; - domain->ops->detach_dev (domain, dev);trace_detach_device_from_domain (dev); }
include/linux/iommu.h +1 -0
@@ -413,6 +413,7 @@ struct dev_iommu {struct iommu_device *iommu_dev;void *priv;u32 max_pasids; +u8 attach_deferred; }; int iommu_device_register(struct iommu_device *iommu,
Re: [PATCH v3 20/20] iommu: Rename attach_dev to set_dev
In reply to Robin MurphyQuoted 5 lines · Robin Murphy
Quoted 3 lines · Lu Baolu
With the retirement of the
detach_devcallback, the naming ofattach_devisn't meaningful anymore. Rename it toset_devto restore its real meaning, that is, setting an iommu domain to a device.
Quoted 7 lines
English grammar alert: this part is confusing, since the usual in-context reading* of "set[ting] X to Y" is going to imply assigning a value of Y to some unique property of X. Given the actual semantic that when we attach the device to the domain, we are setting the (current) domain as a property of the device, I think the most logical and intuitive abbreviation for this method would be
set_domain(), where the target device is then clearly implied by the argument (as the target domain was forattach_dev()).
This is the iommu_domain_ops, it seems a bit weird to call it set_domain when it is already acting on a domain object.
set_device_domain()
?
Quoted 5 lines
FWIW I also wouldn't say that "attach" loses its meaning in a context where an equivalent "detach" operation is only ever implicit in reattaching to something else, however I do agree that it *is* worth switching the terminology to clearly differentiate this internal behaviour from the public attach/detach API for unmanaged domains.
+1
Jason
Robin Murphy
reviewerRe: [PATCH v3 20/20] iommu: Rename attach_dev to set_dev
Quoted 14 lines · Jason Gunthorpe
Quoted 5 lines · Robin Murphy
Quoted 3 lines · Lu Baolu
With the retirement of the
detach_devcallback, the naming ofattach_devisn't meaningful anymore. Rename it toset_devto restore its real meaning, that is, setting an iommu domain to a device.Quoted 7 lines
English grammar alert: this part is confusing, since the usual in-context reading* of "set[ting] X to Y" is going to imply assigning a value of Y to some unique property of X. Given the actual semantic that when we attach the device to the domain, we are setting the (current) domain as a property of the device, I think the most logical and intuitive abbreviation for this method would be
set_domain(), where the target device is then clearly implied by the argument (as the target domain was forattach_dev()).
Quoted 6 lines
This is the
iommu_domain_ops, it seems a bit weird to call itset_domainwhen it is already acting on a domain object.
set_device_domain()?
Ah, the iommu_domain_ops split had completely slipped my mind - maybe with that additional context, assign_dev() might work well enough to maintain the pattern while still being sufficiently different?
Otherwise, set_device_domain() (or just set_dev_domain()) sounds fair to me.
Cheers,
Robin.
Baolu Lu
maintainerRe: [PATCH v3 06/20] iommu/mtk: Remove detach_dev callback
In reply to Robin MurphyQuoted 22 lines · Robin Murphy
Quoted 9 lines · Jason Gunthorpe
Quoted 7 lines · Lu Baolu
The IOMMU driver supports default domain, so the
detach_devop will never be called. Remove it to avoid dead code.Signed-off-by Lu Baolu <[email protected]>---
drivers/iommu/mtk_iommu.c| 9 ---------1 file changed, 9 deletions(-)Quoted 7 lines
I listed this driver as not supporting default domains:
https://lore.kernel.org/linux-iommu/[email protected]/
?
Has something changed? Did I get it wrong?
static struct
iommu_domain*mtk_iommu_domain_alloc(unsigned type) {
structmtk_iommu_domain*dom;
Quoted 6 lines
if (type !=
IOMMU_DOMAIN_DMA&& type !=IOMMU_DOMAIN_UNMANAGED) return NULL;
...This one runs on arm64, so has always supported default domains for iommu-dma to work.
This, together with several other ones, only support IOMMU_DOMAIN_DMA type of default domain. The iommu core handle this by falling back to IOMMU_DOMAIN_DMA if other types fail.
dom = __iommu_domain_alloc(bus, type);
if (!dom && type != IOMMU_DOMAIN_DMA) {
dom = __iommu_domain_alloc(bus, IOMMU_DOMAIN_DMA);
if (dom)
pr_warn("Failed to allocate default IOMMU
domain of type %u for group %s - Falling back to IOMMU_DOMAIN_DMA",
type, group->name);
}I have another cleanup series:
https://github.com/LuBaolu/intel-iommu/commits/iommu-use-def_default_type-wip
which adds IOMMU_DOMAIN_DMA default domain type requirement in the def_domain_type callback. I planed to bring that to discussion after this one.
Best regards,
baolu
Baolu Lu
maintainerRe: [PATCH v3 10/20] iommu: Add set_platform_dma iommu ops
In reply to Jason GunthorpeQuoted 17 lines · Jason Gunthorpe
Quoted 6 lines · Lu Baolu
When VFIO finishes assigning a device to user space and calls
iommu_group_release_dma_owner()to return the device to kernel, the IOMMU core will attach the default domain to the device. Unfortunately, some IOMMU drivers don't support default domain, hence in the end, the core calls .detach_dev instead.Quoted 8 lines
This adds
set_platform_dmaiommu ops to make it clear that what it does is returning control back to the platform DMA ops.Suggested-by Jason Gunthorpe<[email protected]>Signed-off-by Lu Baolu<[email protected]>--- include/linux/iommu.h | 4 ++++ 1 file changed, 4 insertions(+)Reviewed-by Jason Gunthorpe<[email protected]>
Quoted 7 lines
Quoted 3 lines
+ * @set_platform_dma: Returning control back to the platform DMA ops. Only
+ * valid for IOMMU drivers which don't support default
+ * domain.I would add:
This op is to support old IOMMU drivers, new drivers should use default domains, and the common IOMMU DMA ops.
Done. Thank you!
Best regards,
baolu
RE: [PATCH v3 08/20] iommu/sprd: Remove detach_dev callback
In reply to Lu BaoluQuoted 26 lines
From: Lu Baolu <[email protected]>
Sent: Monday, November 28, 2022 2:47 PMThe IOMMU driver supports default domain, so the
detach_devop will never be called. Remove it to avoid dead code.Signed-off-by Lu Baolu <[email protected]>--- drivers/iommu/sprd-iommu.c | 16 ---------------- 1 file changed, 16 deletions(-)drivers/iommu/sprd-iommu.c +0
-6@@ -255,21 +255,6 @@ static int sprd_iommu_attach_device(structiommu_domain *domain, return 0; } -static void sprd_iommu_detach_device (struct iommu_domain *domain, -struct device *dev) -{ -struct sprd_iommu_domain *dom =to_sprd_domain (domain); -struct sprd_iommu_device *sdev = dom->sdev; -size_t pgt_size =sprd_iommu_pgt_size (domain);
drivers/iommu/sprd-iommu.c static int sprd_iommu_attach_device(struct · line 274
Quoted 10 lines
drivers/iommu/sprd-iommu.c +0
-9- -if (!sdev) -return ; - -dma_free_coherent (sdev->dev, pgt_size, dom->pgt_va, dom- >pgt_pa); -sprd_iommu_hw_en (sdev, false); - dom->sdev =NULL ; -} -
Looks this reveals a bug in this driver (not caused by this removal).
sprd_iommu_attach_device() doesn't check whether the device has been already attached to a domain and do auto detach.
It's written in a way that .detach_dev() must be called to free the dma buffer but ignores the fact that it's not called when default domain support is claimed.
Then the dma buffer allocated for the previous domain was left unhandled, causing memory leak.
Baolu Lu
maintainerRe: [PATCH v3 11/20] iommu/fsl_pamu: Add set_platform_dma callback
In reply to Jason GunthorpeQuoted 30 lines · Jason Gunthorpe
Quoted 14 lines · Lu Baolu
This IOMMU driver doesn't support default domain. Add the implementation of
set_platform_dmacallback so that the IOMMU core could return the DMA control.Signed-off-by Lu Baolu<[email protected]>--- drivers/iommu/fsl_pamu_domain.c | 9 +++++++++ 1 file changed, 9 insertions(+)drivers/iommu/fsl_pamu_domain.c +0
-0drivers/iommu/fsl_pamu_domain.c static void fsl_pamu_detach_device(struct iommu_domain *domain, · line 323
Quoted 10 lines
drivers/iommu/fsl_pamu_domain.c +7
-0@@ -314,6 +314,14 @@ static void fsl_pamu_detach_device(struct iommu_domain *domain,pr_debug ("missing fsl,liodn property at %pOF\n" , dev->of_node); } +static void fsl_pamu_set_platform_dma (struct device *dev) +{ +struct iommu_domain *domain =iommu_get_domain_for_dev (dev); + +if (domain) +fsl_pamu_detach_device (domain, dev); +}This is a bit ugly, it would be better to make the previous patch call
set_platform_dmaif it is set instead ofdetach_devand then these patches should just rename the driver'sfsl_pamu_detach_devicetofsl_pamu_set_platform_dma
Quoted 1 line
Then the last patch just deletes the op and the core code
Yes. That's better. I will update the series.
Best regards,
baolu
RE: [PATCH v3 20/20] iommu: Rename attach_dev to set_dev
In reply to Robin MurphyQuoted 25 lines
From: Robin Murphy <[email protected]>
Sent: Monday, November 28, 2022 11:53 PMQuoted 3 lines · Jason Gunthorpe
Quoted 2 lines · Robin Murphy
Quoted 1 line · Lu Baolu
With the retirement of the
detach_devcallback, the naming of
attach_devQuoted 6 lines
Quoted 6 lines
Quoted 2 lines
isn't meaningful anymore. Rename it to
set_devto restore its real meaning, that is, setting an iommu domain to a device.English grammar alert: this part is confusing, since the usual in-context reading* of "set[ting] X to Y" is going to imply assigning a value of Y to some unique property of X. Given the actual semantic that when we
attach the
Quoted 10 lines
Quoted 4 lines
device to the domain, we are setting the (current) domain as a property of the device, I think the most logical and intuitive abbreviation for this method would be
set_domain(), where the target device is then clearly implied by the argument (as the target domain was forattach_dev()).This is the
iommu_domain_ops, it seems a bit weird to call itset_domainwhen it is already acting on a domain object.
set_device_domain()
Quoted 9 lines
Quoted 1 line
?
Ah, the
iommu_domain_opssplit had completely slipped my mind - maybe with that additional context,assign_dev()might work well enough to maintain the pattern while still being sufficiently different?Otherwise,
set_device_domain()(or justset_dev_domain()) sounds fair to me.
This kind of introduces a new concept as 'device domain'...
I prefer to device_set_domain() similar to __iommu_group_set_domain().
Then set_platform_dma() can be device_set_platform_dma().
Both have 'device' as the subject to differentiate from other domain ops.
Robin Murphy
reviewerRe: [PATCH v3 06/20] iommu/mtk: Remove detach_dev callback
In reply to Baolu LuQuoted 43 lines · Baolu Lu
Quoted 22 lines · Robin Murphy
Quoted 9 lines · Jason Gunthorpe
Quoted 7 lines · Lu Baolu
The IOMMU driver supports default domain, so the
detach_devop will never be called. Remove it to avoid dead code.Signed-off-by Lu Baolu <[email protected]>---
drivers/iommu/mtk_iommu.c| 9 ---------1 file changed, 9 deletions(-)Quoted 7 lines
I listed this driver as not supporting default domains:
https://lore.kernel.org/linux-iommu/[email protected]/
?
Has something changed? Did I get it wrong?
static struct
iommu_domain*mtk_iommu_domain_alloc(unsigned type) {
structmtk_iommu_domain*dom;Quoted 6 lines
if (type !=
IOMMU_DOMAIN_DMA&& type !=IOMMU_DOMAIN_UNMANAGED) return NULL;
...This one runs on arm64, so has always supported default domains for iommu-dma to work.
This, together with several other ones, only support
IOMMU_DOMAIN_DMAtype of default domain. The iommu core handle this by falling back toIOMMU_DOMAIN_DMAif other types fail.dom =
__iommu_domain_alloc(bus, type);
if (!dom && type !=IOMMU_DOMAIN_DMA) {
dom =__iommu_domain_alloc(bus, IOMMU_DOMAIN_DMA); if (dom)
pr_warn("Failed to allocate default IOMMU
domain of type %u for group %s - Falling back toIOMMU_DOMAIN_DMA",
type,group->name);
}
Quoted 7 lines
I have another cleanup series:
https://github.com/LuBaolu/intel-iommu/commits/iommu-use-def_default_type-wip
which adds
IOMMU_DOMAIN_DMAdefault domain type requirement in thedef_domain_typecallback. I planed to bring that to discussion after this one.
Per the discussion over on the s390 thread, I think that would be a step in the wrong direction. I'd prefer to keep .def_domain_type for device-specific requirements and express general driver domain support a different way. If the IOMMU_DOMAIN_DMA fallback is worth removing then the one for IOMMU_DOMAIN_BLOCKED is as well - no point doing half the job ;)
Thanks,
Robin.
Baolu Lu
maintainerRe: [PATCH v3 06/20] iommu/mtk: Remove detach_dev callback
Quoted 45 lines · Robin Murphy
Quoted 44 lines · Baolu Lu
Quoted 22 lines · Robin Murphy
Quoted 9 lines · Jason Gunthorpe
Quoted 7 lines · Lu Baolu
The IOMMU driver supports default domain, so the
detach_devop will never be called. Remove it to avoid dead code.Signed-off-by Lu Baolu <[email protected]>---
drivers/iommu/mtk_iommu.c| 9 ---------1 file changed, 9 deletions(-)Quoted 7 lines
I listed this driver as not supporting default domains:
https://lore.kernel.org/linux-iommu/[email protected]/
?
Has something changed? Did I get it wrong?
static struct
iommu_domain*mtk_iommu_domain_alloc(unsigned type) {
structmtk_iommu_domain*dom;Quoted 6 lines
if (type !=
IOMMU_DOMAIN_DMA&& type !=IOMMU_DOMAIN_UNMANAGED) return NULL;
...This one runs on arm64, so has always supported default domains for iommu-dma to work.
This, together with several other ones, only support
IOMMU_DOMAIN_DMAtype of default domain. The iommu core handle this by falling back toIOMMU_DOMAIN_DMAif other types fail.dom =
__iommu_domain_alloc(bus, type);
if (!dom && type !=IOMMU_DOMAIN_DMA) {
dom =__iommu_domain_alloc(bus, IOMMU_DOMAIN_DMA);
if (dom)
pr_warn("Failed to allocate default IOMMU domain of type %u for group %s - Falling back toIOMMU_DOMAIN_DMA", type,group->name);
}I have another cleanup series:
Quoted 7 lines
Quoted 5 lines
https://github.com/LuBaolu/intel-iommu/commits/iommu-use-def_default_type-wip
which adds
IOMMU_DOMAIN_DMAdefault domain type requirement in thedef_domain_typecallback. I planed to bring that to discussion after this one.Per the discussion over on the s390 thread, I think that would be a step in the wrong direction. I'd prefer to keep .def_domain_type for device-specific requirements and express general driver domain support a different way. If the
IOMMU_DOMAIN_DMAfallback is worth removing then the one forIOMMU_DOMAIN_BLOCKEDis as well - no point doing half the job ;)
Get you. Thanks for pointing this out. Sure, let's keep the code.
Best regards,
baolu
Chunyan Zhang
reviewerRe: [PATCH v3 08/20] iommu/sprd: Remove detach_dev callback
In reply to Tian, KevinQuoted 43 lines · Kevin
Quoted 27 lines
From: Lu Baolu <[email protected]>
Sent: Monday, November 28, 2022 2:47 PMThe IOMMU driver supports default domain, so the
detach_devop will never be called. Remove it to avoid dead code.Signed-off-by Lu Baolu <[email protected]>--- drivers/iommu/sprd-iommu.c | 16 ---------------- 1 file changed, 16 deletions(-)drivers/iommu/sprd-iommu.c +0
-6@@ -255,21 +255,6 @@ static int sprd_iommu_attach_device(structiommu_domain *domain, return 0; } -static void sprd_iommu_detach_device (struct iommu_domain *domain, -struct device *dev) -{ -struct sprd_iommu_domain *dom =to_sprd_domain (domain); -struct sprd_iommu_device *sdev = dom->sdev; -size_t pgt_size =sprd_iommu_pgt_size (domain);drivers/iommu/sprd-iommu.c static int sprd_iommu_attach_device(struct · line 274
Quoted 10 lines
drivers/iommu/sprd-iommu.c +0
-9- -if (!sdev) -return ; - -dma_free_coherent (sdev->dev, pgt_size, dom->pgt_va, dom- >pgt_pa); -sprd_iommu_hw_en (sdev, false); - dom->sdev =NULL ; -} -Looks this reveals a bug in this driver (not caused by this removal).
sprd_iommu_attach_device()doesn't check whether the device has been already attached to a domain and do auto detach.
Quoted 6 lines
It's written in a way that .detach_dev() must be called to free the dma buffer but ignores the fact that it's not called when default domain support is claimed.
Then the dma buffer allocated for the previous domain was left unhandled, causing memory leak.
I'll look into the issue, thanks for pointing this out.
Chunyan
Re: [PATCH v3 08/20] iommu/sprd: Remove detach_dev callback
In reply to Lu BaoluQuoted 5 lines · Lu Baolu
The IOMMU driver supports default domain, so the
detach_devop will never be called. Remove it to avoid dead code.Signed-off-by Lu Baolu <[email protected]>
Thanks,
Chunyan
Quoted 41 lines
--- drivers/iommu/sprd-iommu.c | 16 ---------------- 1 file changed, 16 deletions(-)drivers/iommu/sprd-iommu.c +0
-17@@ -255,21 +255,6 @@ static int sprd_iommu_attach_device(struct iommu_domain *domain,return 0 ; } -static void sprd_iommu_detach_device (struct iommu_domain *domain, -struct device *dev) -{ -struct sprd_iommu_domain *dom =to_sprd_domain (domain); -struct sprd_iommu_device *sdev = dom->sdev; -size_t pgt_size =sprd_iommu_pgt_size (domain); - -if (!sdev) -return ; - -dma_free_coherent (sdev->dev, pgt_size, dom->pgt_va, dom->pgt_pa); -sprd_iommu_hw_en (sdev, false); - dom->sdev =NULL ; -} -static int sprd_iommu_map (struct iommu_domain *domain,unsigned long iova,phys_addr_t paddr,size_t pgsize,size_t pgcount,int prot,gfp_t gfp,size_t *mapped)@@ -414,7 +399,6 @@ static const struct iommu_ops sprd_iommu_ops = { .owner = THIS_MODULE, .default_domain_ops = &(const struct iommu_domain_ops ) { .attach_dev = sprd_iommu_attach_device, - .detach_dev = sprd_iommu_detach_device, .map_pages = sprd_iommu_map, .unmap_pages = sprd_iommu_unmap, .iotlb_sync_map = sprd_iommu_sync_map, --2.34.1
Re: [PATCH v3 02/20] iommu/apple-dart: Remove detach_dev callback
In reply to Lu BaoluHi,
Quoted 5 lines · Lu Baolu
The IOMMU driver supports default domain, so the
detach_devop will never be called. Remove it to avoid dead code.Signed-off-by Lu Baolu <[email protected]>---
Quoted 8 lines
drivers/iommu/apple-dart.c | 17 ----------------- 1 file changed, 17 deletions(-)drivers/iommu/apple-dart.c +0
-0
drivers/iommu/apple-dart.c static int apple_dart_attach_dev(struct · line 541
Quoted 7 lines
drivers/iommu/apple-dart.c +0
-3@@ -535,22 +535,6 @@ static int apple_dart_attach_dev(structiommu_domain *domain, return ret; } -static void apple_dart_detach_dev (struct iommu_domain *domain, -struct device *dev) -{
Thanks for cleaning this entire API up!
It actually turns out that this is slightly broken because I assumed that detach_dev would always be called for any attach_dev. I think the only consequence for a device that used to be assigned to domain A and is now moved to domain B is that any TLB flushes required for A will still flush the TLB for that device.
That's not a big deal but I'll eventually send a fix.
drivers/iommu/apple-dart.c static int apple_dart_attach_dev(struct iommu_domain *domain, · line 551
Quoted 11 lines
drivers/iommu/apple-dart.c +0
-11-int i; -struct apple_dart_stream_map *stream_map; -struct apple_dart_master_cfg *cfg =dev_iommu_priv_get (dev); -struct apple_dart_domain *dart_domain =to_dart_domain (domain); - -for_each_stream_map (i, cfg, stream_map) -apple_dart_hw_disable_dma (stream_map); - -if (domain->type ==IOMMU_DOMAIN_DMA || - domain->type ==IOMMU_DOMAIN_UNMANAGED ) -apple_dart_domain_remove_streams (dart_domain, cfg);
Something might complain about unused apple_dart_domain_remove_streams now. Might make sense to drop that for now as well.
Best,
Sven
Baolu Lu
maintainerRe: [PATCH v3 02/20] iommu/apple-dart: Remove detach_dev callback
Quoted 33 lines · Sven Peter
Quoted 5 lines · Lu Baolu
The IOMMU driver supports default domain, so the
detach_devop will never be called. Remove it to avoid dead code.Signed-off-by Lu Baolu<[email protected]>---
Reviewed-by Sven Peter<[email protected]>Quoted 8 lines
drivers/iommu/apple-dart.c | 17 ----------------- 1 file changed, 17 deletions(-)drivers/iommu/apple-dart.c +0
-0drivers/iommu/apple-dart.c static int apple_dart_attach_dev(struct · line 541
Quoted 7 lines
drivers/iommu/apple-dart.c +0
-3@@ -535,22 +535,6 @@ static int apple_dart_attach_dev(structiommu_domain *domain, return ret; } -static void apple_dart_detach_dev (struct iommu_domain *domain, -struct device *dev) -{Thanks for cleaning this entire API up!
It actually turns out that this is slightly broken because I assumed that
detach_devwould always be called for anyattach_dev. I think the only consequence for a device that used to be assigned to domain A and is now moved to domain B is that any TLB flushes required for A will still flush the TLB for that device.That's not a big deal but I'll eventually send a fix.
Quoted 13 lines
drivers/iommu/apple-dart.c static int apple_dart_attach_dev(struct iommu_domain *domain, · line 551
Quoted 11 lines
drivers/iommu/apple-dart.c +0
-11-int i; -struct apple_dart_stream_map *stream_map; -struct apple_dart_master_cfg *cfg =dev_iommu_priv_get (dev); -struct apple_dart_domain *dart_domain =to_dart_domain (domain); - -for_each_stream_map (i, cfg, stream_map) -apple_dart_hw_disable_dma (stream_map); - -if (domain->type ==IOMMU_DOMAIN_DMA || - domain->type ==IOMMU_DOMAIN_UNMANAGED ) -apple_dart_domain_remove_streams (dart_domain, cfg);Something might complain about unused
apple_dart_domain_remove_streamsnow. Might make sense to drop that for now as well.
Done. Thanks!
Best regards,
baolu
Baolu Lu
maintainerRe: [PATCH v3 18/20] iommu: Call set_platform_dma if default domain is unavailable
In reply to Jason GunthorpeHi Jason,
Quoted 135 lines · Jason Gunthorpe
Quoted 13 lines · Lu Baolu
If the IOMMU driver has no default domain support, call
set_platform_dmaexplicitly to return the kernel DMA control back to the platform DMA ops.Signed-off-by Lu Baolu <[email protected]>--- drivers/iommu/iommu.c | 28 ++++++++-------------------- 1 file changed, 8 insertions(+), 20 deletions(-)drivers/iommu/iommu.c +0
-0drivers/iommu/iommu.c int iommu_deferred_attach(struct device *dev, struct iommu_domain *domain) · line 2047
Quoted 8 lines
drivers/iommu/iommu.c +0
-5@@ -2040,16 +2040,6 @@ int iommu_deferred_attach(struct device *dev, struct iommu_domain *domain)return 0 ; } -static void __iommu_detach_device (struct iommu_domain *domain, -struct device *dev) -{ -if (iommu_is_attach_deferred (dev)) -return ;This removal might want to be its own patch with an explanation.
It looks like at the current moment
__iommu_detach_device()is only called via call chains that are after the device driver is attached - eg via explicit attach APIs called by the device driver.So it should just unconditionally work. It is actually looks like a bug that we were blocking detach on these paths since the attach was unconditional and the caller is going to free the (probably) UNAMANGED domain once this returns.
The only place we should be testing for deferred attach is during the initial point the dma device is linked to the group, and then again during the dma api calls to check if the device
This maybe the patch that is needed to explain this:
drivers/iommu/iommu.c +19
-17@@ -993,8 +993,8 @@ int iommu_group_add_device(struct iommu_group *group, struct device *dev)mutex_lock (&group->mutex);list_add_tail (&device->list, &group->devices); -if (group->domain && !iommu_is_attach_deferred (dev)) - ret =__iommu_attach_device (group->domain, dev); +if (group->domain) + ret =iommu_group_do_dma_first_attach (dev, group->domain);mutex_unlock (&group->mutex);if (ret) goto err_put_group;@@ -1760,21 +1760,24 @@ static void probe_alloc_default_domain(struct bus_type *bus, } -static int iommu_group_do_dma_attach (struct device *dev,void *data) +static int iommu_group_do_dma_first_attach (struct device *dev,void *data) {struct iommu_domain *domain = data; -int ret =0 ; -if (!iommu_is_attach_deferred (dev)) - ret =__iommu_attach_device (domain, dev); +lockdep_assert_held (&dev->iommu_group->mutex); -return ret; +if (iommu_is_attach_deferred (dev)) { + dev->iommu->attach_deferred =1 ; +return 0 ; + } + +return __iommu_attach_device (domain, dev); } -static int __iommu_group_dma_attach (struct iommu_group *group) +static int __iommu_group_dma_first_attach (struct iommu_group *group) {return __iommu_group_for_each_dev (group, group->default_domain, - iommu_group_do_dma_attach); + iommu_group_do_dma_first_attach); }static int iommu_group_do_probe_finalize (struct device *dev,void *data)@@ -1839,7 +1842,7 @@ int bus_iommu_probe(struct bus_type *bus)iommu_group_create_direct_mappings (group); - ret =__iommu_group_dma_attach (group); + ret =__iommu_group_dma_first_attach (group);mutex_unlock (&group->mutex);@@ -1971,9 +1974,11 @@ static int __iommu_attach_device(struct iommu_domain *domain,return -ENODEV ; ret = domain->ops->attach_dev (domain, dev); -if (!ret) -trace_attach_device_to_domain (dev); -return ret; +if (ret) +return ret; + dev->iommu->attach_deferred =0 ; +trace_attach_device_to_domain (dev); +return 0 ; }/** @@ -2018,7 +2023,7 @@ EXPORT_SYMBOL_GPL(iommu_attach_device);int iommu_deferred_attach (struct device *dev,struct iommu_domain *domain) { -if (iommu_is_attach_deferred (dev)) +if (dev->iommu && dev->iommu->attach_deferred)return __iommu_attach_device (domain, dev);return 0 ;@@ -2027,9 +2032,6 @@ int iommu_deferred_attach(struct device *dev, struct iommu_domain *domain)static void __iommu_detach_device (struct iommu_domain *domain,struct device *dev) { -if (iommu_is_attach_deferred (dev)) -return ; - domain->ops->detach_dev (domain, dev);trace_detach_device_from_domain (dev); }include/linux/iommu.h +0
-0
include/linux/iommu.h struct dev_iommu { · line 419
Quoted 7 lines
include/linux/iommu.h +1
-0@@ -413,6 +413,7 @@ struct dev_iommu {struct iommu_device *iommu_dev;void *priv;u32 max_pasids; +u8 attach_deferred; }; int iommu_device_register(struct iommu_device *iommu,
Thanks for the patch! It seems that we also need to call iommu_group_do_dma_first_attach() in the iommu_probe_device() path?
@@ -401,7 +425,7 @@ int iommu_probe_device(struct device *dev)
* attach the default domain.
*/
if (group->default_domain && !group->owner) {
- ret = __iommu_attach_device(group->default_domain, dev);
+ ret = iommu_group_do_dma_first_attach(dev, group->default_domain);
if (ret) {
mutex_unlock(&group->mutex);
iommu_group_put(group);By the way, I'd like to put above code in a separated patch of the next version, can I add your signed-off-by?
--
Best regards,
baolu
Re: [PATCH v3 18/20] iommu: Call set_platform_dma if default domain is unavailable
Quoted 2 lines · Baolu Lu
Thanks for the patch! It seems that we also need to call
iommu_group_do_dma_first_attach()in theiommu_probe_device()path?
Yes
Quoted 2 lines
By the way, I'd like to put above code in a separated patch of the next version, can I add your signed-off-by?
Yes
Jason