Re: [PATCH 1/8] iommu: Move IOMMU_DOMAIN_BLOCKED global statics to ops->blocked_domain

2023-09-24 Thread Baolu Lu
On 9/23/23 1:07 AM, Jason Gunthorpe wrote: Following the pattern of identity domains, just assign the BLOCKED domain global statics to a value in ops. Update the core code to use the global static directly. Update powerpc to use the new scheme and remove its empty domain_alloc callback. Signed-

Re: [PATCH 2/8] iommu/vt-d: Update the definition of the blocking domain

2023-09-24 Thread Baolu Lu
On 9/23/23 1:07 AM, Jason Gunthorpe wrote: The global static should pre-define the type and the NOP free function can be now left as NULL. Signed-off-by: Jason Gunthorpe --- drivers/iommu/intel/iommu.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) Reviewed-by: Lu Baolu Best re

Re: [PATCH 3/8] iommu/vt-d: Use ops->blocked_domain

2023-09-24 Thread Baolu Lu
On 9/23/23 1:07 AM, Jason Gunthorpe wrote: Trivially migrate to the ops->blocked_domain for the existing global static. Signed-off-by: Jason Gunthorpe --- drivers/iommu/intel/iommu.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) Reviewed-by: Lu Baolu P.S. We can further do the s

Re: [PATCH 3/8] iommu/vt-d: Use ops->blocked_domain

2023-09-25 Thread Baolu Lu
On 9/25/23 7:41 PM, Jason Gunthorpe wrote: On Mon, Sep 25, 2023 at 10:29:52AM +0800, Baolu Lu wrote: On 9/23/23 1:07 AM, Jason Gunthorpe wrote: Trivially migrate to the ops->blocked_domain for the existing global static. Signed-off-by: Jason Gunthorpe --- drivers/iommu/intel/iommu.c

Re: [PATCH v5 01/25] iommu: Add iommu_ops->identity_domain

2023-07-25 Thread Baolu Lu
On 2023/7/25 1:21, Jason Gunthorpe wrote: This allows a driver to set a global static to an IDENTITY domain and the core code will automatically use it whenever an IDENTITY domain is requested. By making it always available it means the IDENTITY can be used in error handling paths to force the i

Re: [PATCH v5 02/25] iommu: Add IOMMU_DOMAIN_PLATFORM

2023-07-25 Thread Baolu Lu
On 2023/7/25 1:21, Jason Gunthorpe wrote: This is used when the iommu driver is taking control of the dma_ops, currently only on S390 and power spapr. It is designed to preserve the original ops->detach_dev() semantic that these S390 was built around. Provide an opaque domain type and a 'default

Re: [PATCH v5 08/25] iommu: Reorganize iommu_get_default_domain_type() to respect def_domain_type()

2023-07-26 Thread Baolu Lu
On 2023/7/25 1:21, Jason Gunthorpe wrote: Except for dart every driver returns 0 or IDENTITY from def_domain_type(). The drivers that return IDENTITY have some kind of good reason, typically that quirky hardware really can't support anything other than IDENTITY. Arrange things so that if the dr

Re: [PATCH v5 16/25] iommu: Remove ops->set_platform_dma_ops()

2023-07-26 Thread Baolu Lu
On 2023/7/25 1:22, Jason Gunthorpe wrote: All drivers are now using IDENTITY or PLATFORM domains for what this did, we can remove it now. It is no longer possible to attach to a NULL domain. Tested-by: Heiko Stuebner Tested-by: Niklas Schnelle Tested-by: Steven Price Tested-by: Marek Szyprowski

Re: [PATCH v5 21/25] iommu: Require a default_domain for all iommu drivers

2023-07-26 Thread Baolu Lu
On 2023/7/25 1:22, Jason Gunthorpe wrote: At this point every iommu driver will cause a default_domain to be selected, so we can finally remove this gap from the core code. The following table explains what each driver supports and what the resulting default_domain will be:

Re: [PATCH v5 22/25] iommu: Add __iommu_group_domain_alloc()

2023-07-26 Thread Baolu Lu
On 2023/7/25 1:22, Jason Gunthorpe wrote: Allocate a domain from a group. Automatically obtains the iommu_ops to use from the device list of the group. Convert the internal callers to use it. Tested-by: Steven Price Tested-by: Marek Szyprowski Tested-by: Nicolin Chen Signed-off-by: Jason Gunthor

Re: [PATCH v5 23/25] iommu: Add ops->domain_alloc_paging()

2023-07-26 Thread Baolu Lu
On 2023/7/25 1:22, Jason Gunthorpe wrote: This callback requests the driver to create only a __IOMMU_DOMAIN_PAGING domain, so it saves a few lines in a lot of drivers needlessly checking the type. More critically, this allows us to sweep out all the IOMMU_DOMAIN_UNMANAGED and IOMMU_DOMAIN_DMA ch

Re: [PATCH v6 02/25] iommu: Add IOMMU_DOMAIN_PLATFORM

2023-08-11 Thread Baolu Lu
On 2023/8/3 8:07, Jason Gunthorpe wrote: This is used when the iommu driver is taking control of the dma_ops, currently only on S390 and power spapr. It is designed to preserve the original ops->detach_dev() semantic that these S390 was built around. Provide an opaque domain type and a 'default_

Re: [PATCH v6 02/25] iommu: Add IOMMU_DOMAIN_PLATFORM

2023-08-11 Thread Baolu Lu
On 2023/8/3 8:07, Jason Gunthorpe wrote: @@ -1967,7 +1978,8 @@ void iommu_domain_free(struct iommu_domain *domain) if (domain->type == IOMMU_DOMAIN_SVA) mmdrop(domain->mm); iommu_put_dma_cookie(domain); - domain->ops->free(domain); + if (domain->ops->fr

Re: [PATCH v6 06/25] iommu/tegra-gart: Remove tegra-gart

2023-08-11 Thread Baolu Lu
On 2023/8/3 8:07, Jason Gunthorpe wrote: Thierry says this is not used anymore, and doesn't think it makes sense as an iommu driver. The HW it supports is about 10 years old now and newer HW uses different IOMMU drivers. As this is the only driver with a GART approach, and it doesn't really meet

Re: [PATCH v6 08/25] iommu: Reorganize iommu_get_default_domain_type() to respect def_domain_type()

2023-08-11 Thread Baolu Lu
On 2023/8/3 8:07, Jason Gunthorpe wrote: Except for dart every driver returns 0 or IDENTITY from def_domain_type(). The drivers that return IDENTITY have some kind of good reason, typically that quirky hardware really can't support anything other than IDENTITY. Arrange things so that if the dri

Re: [PATCH v6 15/25] iommufd/selftest: Make the mock iommu driver into a real driver

2023-08-11 Thread Baolu Lu
On 2023/8/3 8:08, Jason Gunthorpe wrote: I've avoided doing this because there is no way to make this happen without an intrusion into the core code. Up till now this has avoided needing the core code's probe path with some hackery - but now that default domains are becoming mandatory it is unavo

Re: [PATCH v6 15/25] iommufd/selftest: Make the mock iommu driver into a real driver

2023-08-11 Thread Baolu Lu
On 2023/8/3 8:08, Jason Gunthorpe wrote: +/* + * Register an iommu driver against a single bus. This is only used by iommufd + * selftest to create a mock iommu driver. The caller must provide + * some memory to hold a notifier_block. + */ +int iommu_device_register_bus(struct iommu_device *iommu

Re: [PATCH v6 02/25] iommu: Add IOMMU_DOMAIN_PLATFORM

2023-08-13 Thread Baolu Lu
On 2023/8/12 19:28, Jason Gunthorpe wrote: On Sat, Aug 12, 2023 at 09:36:33AM +0800, Baolu Lu wrote: @@ -290,6 +295,7 @@ struct iommu_ops { unsigned long pgsize_bitmap; struct module *owner; struct iommu_domain *identity_domain; + struct iommu_domain

Re: [PATCH v6 03/25] powerpc/iommu: Setup a default domain and remove set_platform_dma_ops

2023-08-13 Thread Baolu Lu
On 2023/8/3 8:07, Jason Gunthorpe wrote: POWER is using the set_platform_dma_ops() callback to hook up its private dma_ops, but this is buired under some indirection and is weirdly happening for a BLOCKED domain as well. For better documentation create a PLATFORM domain to manage the dma_ops, si

Re: [PATCH v6 04/25] iommu: Add IOMMU_DOMAIN_PLATFORM for S390

2023-08-13 Thread Baolu Lu
On 2023/8/3 8:07, Jason Gunthorpe wrote: The PLATFORM domain will be set as the default domain and attached as normal during probe. The driver will ignore the initial attach from a NULL domain to the PLATFORM domain. After this, the PLATFORM domain's attach_dev will be called whenever we detach

Re: [PATCH v6 05/25] iommu/fsl_pamu: Implement a PLATFORM domain

2023-08-13 Thread Baolu Lu
On 2023/8/3 8:07, Jason Gunthorpe wrote: This driver is nonsensical. To not block migrating the core API away from NULL default_domains give it a hacky of a PLATFORM domain that keeps it working exactly as it always did. Leave some comments around to warn away any future people looking at this.

Re: [PATCH v6 07/25] iommu/mtk_iommu_v1: Implement an IDENTITY domain

2023-08-13 Thread Baolu Lu
On 2023/8/3 8:07, Jason Gunthorpe wrote: What mtk does during mtk_iommu_v1_set_platform_dma() is actually putting the iommu into identity mode. Make this available as a proper IDENTITY domain. The mtk_iommu_v1_def_domain_type() from commit 8bbe13f52cb7 ("iommu/mediatek-v1: Add def_domain_type")

Re: [PATCH v6 09/25] iommu: Allow an IDENTITY domain as the default_domain in ARM32

2023-08-13 Thread Baolu Lu
On 2023/8/3 8:07, Jason Gunthorpe wrote: Even though dma-iommu.c and CONFIG_ARM_DMA_USE_IOMMU do approximately the same stuff, the way they relate to the IOMMU core is quiet different. dma-iommu.c expects the core code to setup an UNMANAGED domain (of type IOMMU_DOMAIN_DMA) and then configures i

Re: [PATCH v6 10/25] iommu/exynos: Implement an IDENTITY domain

2023-08-13 Thread Baolu Lu
On 2023/8/3 8:07, Jason Gunthorpe wrote: What exynos calls exynos_iommu_detach_device is actually putting the iommu into identity mode. Move to the new core support for ARM_DMA_USE_IOMMU by defining ops->identity_domain. Tested-by: Marek Szyprowski Acked-by: Marek Szyprowski Signed-off-by: Jaso

Re: [PATCH v6 11/25] iommu/tegra-smmu: Implement an IDENTITY domain

2023-08-13 Thread Baolu Lu
On 2023/8/3 8:07, Jason Gunthorpe wrote: What tegra-smmu does during tegra_smmu_set_platform_dma() is actually putting the iommu into identity mode. Move to the new core support for ARM_DMA_USE_IOMMU by defining ops->identity_domain. Signed-off-by: Jason Gunthorpe --- drivers/iommu/tegra-smmu

Re: [PATCH v6 12/25] iommu/tegra-smmu: Support DMA domains in tegra

2023-08-13 Thread Baolu Lu
On 2023/8/3 8:07, Jason Gunthorpe wrote: All ARM64 iommu drivers should support IOMMU_DOMAIN_DMA to enable dma-iommu.c. tegra is blocking dma-iommu usage, and also default_domain's, because it wants an identity translation. This is needed for some device quirk. The correct way to do this is to s

Re: [PATCH v6 13/25] iommu/omap: Implement an IDENTITY domain

2023-08-13 Thread Baolu Lu
On 2023/8/3 8:08, Jason Gunthorpe wrote: What omap does during omap_iommu_set_platform_dma() is actually putting the iommu into identity mode. Move to the new core support for ARM_DMA_USE_IOMMU by defining ops->identity_domain. This driver does not support IOMMU_DOMAIN_DMA, however it cannot be

Re: [PATCH v6 14/25] iommu/msm: Implement an IDENTITY domain

2023-08-13 Thread Baolu Lu
On 2023/8/3 8:08, Jason Gunthorpe wrote: What msm does during msm_iommu_set_platform_dma() is actually putting the iommu into identity mode. Move to the new core support for ARM_DMA_USE_IOMMU by defining ops->identity_domain. This driver does not support IOMMU_DOMAIN_DMA, however it cannot be c

Re: [PATCH v6 17/25] iommu/qcom_iommu: Add an IOMMU_IDENTITIY_DOMAIN

2023-08-13 Thread Baolu Lu
On 2023/8/3 8:08, Jason Gunthorpe wrote: This brings back the ops->detach_dev() code that commit 1b932ceddd19 ("iommu: Remove detach_dev callbacks") deleted and turns it into an IDENTITY domain. Signed-off-by: Jason Gunthorpe --- drivers/iommu/arm/arm-smmu/qcom_iommu.c | 39 ++

Re: [PATCH v6 18/25] iommu/ipmmu: Add an IOMMU_IDENTITIY_DOMAIN

2023-08-13 Thread Baolu Lu
On 2023/8/3 8:08, Jason Gunthorpe wrote: This brings back the ops->detach_dev() code that commit 1b932ceddd19 ("iommu: Remove detach_dev callbacks") deleted and turns it into an IDENTITY domain. Also reverts commit 584d334b1393 ("iommu/ipmmu-vmsa: Remove ipmmu_utlb_disable()") Signed-off-by: Ja

Re: [PATCH v6 19/25] iommu/mtk_iommu: Add an IOMMU_IDENTITIY_DOMAIN

2023-08-13 Thread Baolu Lu
On 2023/8/3 8:08, Jason Gunthorpe wrote: This brings back the ops->detach_dev() code that commit 1b932ceddd19 ("iommu: Remove detach_dev callbacks") deleted and turns it into an IDENTITY domain. Signed-off-by: Jason Gunthorpe --- drivers/iommu/mtk_iommu.c | 23 +++ 1 file

Re: [PATCH v6 20/25] iommu/sun50i: Add an IOMMU_IDENTITIY_DOMAIN

2023-08-13 Thread Baolu Lu
On 2023/8/3 8:08, Jason Gunthorpe wrote: Prior to commit 1b932ceddd19 ("iommu: Remove detach_dev callbacks") the sun50i_iommu_detach_device() function was being called by ops->detach_dev(). This is an IDENTITY domain so convert sun50i_iommu_detach_device() into sun50i_iommu_identity_attach() and

Re: [PATCH v6 24/25] iommu: Convert simple drivers with DOMAIN_DMA to domain_alloc_paging()

2023-08-13 Thread Baolu Lu
On 2023/8/3 8:08, Jason Gunthorpe wrote: These drivers are all trivially converted since the function is only called if the domain type is going to be IOMMU_DOMAIN_UNMANAGED/DMA. Tested-by: Heiko Stuebner Tested-by: Steven Price Tested-by: Marek Szyprowski Tested-by: Nicolin Chen Signed-off-

Re: [PATCH v6 25/25] iommu: Convert remaining simple drivers to domain_alloc_paging()

2023-08-14 Thread Baolu Lu
On 2023/8/3 8:08, Jason Gunthorpe wrote: These drivers don't support IOMMU_DOMAIN_DMA, so this commit effectively allows them to support that mode. The prior work to require default_domains makes this safe because every one of these drivers is either compilation incompatible with dma-iommu.c, or

Re: [PATCH v6 00/25] iommu: Make default_domain's mandatory

2023-08-14 Thread Baolu Lu
On 2023/8/3 8:07, Jason Gunthorpe wrote: [ It would be good to get this in linux-next, we have some good test coverage on the ARM side already, thanks! ] It has been a long time coming, this series completes the default_domain transition and makes it so that the core IOMMU code will always have

Re: [PATCH v6 07/25] iommu/mtk_iommu_v1: Implement an IDENTITY domain

2023-08-14 Thread Baolu Lu
On 2023/8/14 22:34, Jason Gunthorpe wrote: @@ -443,7 +459,7 @@ static int mtk_iommu_v1_create_mapping(struct device *dev, struct of_phandle_arg static int mtk_iommu_v1_def_domain_type(struct device *dev) { - return IOMMU_DOMAIN_UNMANAGED; + return IOMMU_DOMAIN_IDENTITY; def_do

Re: [PATCH v6 17/25] iommu/qcom_iommu: Add an IOMMU_IDENTITIY_DOMAIN

2023-08-14 Thread Baolu Lu
On 2023/8/14 23:36, Jason Gunthorpe wrote: On Mon, Aug 14, 2023 at 02:32:33PM +0800, Baolu Lu wrote: + pm_runtime_get_sync(qcom_iommu->dev); + for (i = 0; i < fwspec->num_ids; i++) { + struct qcom_iommu_ctx *ctx = to_ctx(qcom_domain, fwsp

Re: [PATCH v6 08/25] iommu: Reorganize iommu_get_default_domain_type() to respect def_domain_type()

2023-08-14 Thread Baolu Lu
On 2023/8/15 1:25, Jason Gunthorpe wrote: Ah, I went over all this again and decided to try again, it is too complicated. This patch can do what the commit message says and the following patches are even simpler: Yes. This method is more concise. Some nits below. /* * Combine the driver's

Re: [PATCH v6 00/25] iommu: Make default_domain's mandatory

2023-08-14 Thread Baolu Lu
On 2023/8/15 1:30, Jason Gunthorpe wrote: On Mon, Aug 14, 2023 at 04:43:23PM +0800, Baolu Lu wrote: This is on github:https://github.com/jgunthorpe/linux/commits/iommu_all_defdom It seems that after this series, all ARM iommu drivers are able to support the IDENTITY default domain, hence

Re: [PATCH 08/11] iommu: Always destroy the iommu_group during iommu_release_device()

2023-04-19 Thread Baolu Lu
On 4/20/23 12:11 AM, Jason Gunthorpe wrote: diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c index dbaf3ed9012c45..a82516c8ea87ad 100644 --- a/drivers/iommu/iommu.c +++ b/drivers/iommu/iommu.c @@ -569,7 +569,6 @@ static void __iommu_group_remove_device(struct device *dev)

Re: [PATCH 10/11] iommu: Split iommu_group_add_device()

2023-04-19 Thread Baolu Lu
On 4/20/23 12:11 AM, Jason Gunthorpe wrote: @@ -451,16 +454,17 @@ static int __iommu_probe_device(struct device *dev, struct list_head *group_list goto out_unlock; group = dev->iommu_group; - ret = iommu_group_add_device(group, dev); + gdev = iommu_group_alloc_

Re: [PATCH v3 23/25] iommu: Add ops->domain_alloc_paging()

2023-06-10 Thread Baolu Lu
On 6/10/23 3:56 AM, Jason Gunthorpe wrote: This callback requests the driver to create only a __IOMMU_DOMAIN_PAGING domain, so it saves a few lines in a lot of drivers needlessly checking the type. More critically, this allows us to sweep out all the IOMMU_DOMAIN_UNMANAGED and IOMMU_DOMAIN_DMA c