From: Robin Murphy <robin.murphy@arm.com>
To: Lu Baolu <baolu.lu@linux.intel.com>,
Joerg Roedel <joro@8bytes.org>, Jason Gunthorpe <jgg@nvidia.com>,
Christoph Hellwig <hch@infradead.org>,
Ben Skeggs <bskeggs@redhat.com>,
Kevin Tian <kevin.tian@intel.com>,
Ashok Raj <ashok.raj@intel.com>, Will Deacon <will@kernel.org>
Cc: David Airlie <airlied@linux.ie>,
linux-kernel@vger.kernel.org, iommu@lists.linux-foundation.org,
Jonathan Hunter <jonathanh@nvidia.com>,
Alex Williamson <alex.williamson@redhat.com>,
Thierry Reding <thierry.reding@gmail.com>,
Jacob jun Pan <jacob.jun.pan@intel.com>,
Daniel Vetter <daniel@ffwll.ch>
Subject: Re: [PATCH 7/7] iommu: Add iommu_domain::domain_ops
Date: Tue, 25 Jan 2022 00:57:49 +0000 [thread overview]
Message-ID: <99023cd7-f037-282f-3f25-629a14a1578b@arm.com> (raw)
In-Reply-To: <20220124071103.2097118-8-baolu.lu@linux.intel.com>
On 2022-01-24 07:11, Lu Baolu wrote:
> Add a domain specific callback set, domain_ops, for vendor iommu driver
> to provide domain specific operations. Move domain-specific callbacks
> from iommu_ops to the domain_ops and hook them when a domain is allocated.
I think it would make a lot of sense for iommu_domain_ops to be a
substructure *within* iommu_ops. That way we can save most of the driver
boilerplate here by not needing extra variables everywhere, and letting
iommu_domain_alloc() still do a default initialisation like "domain->ops
= bus->iommu_ops->domain_ops;"
I do like the future possibility of trying to flatten some of the
io-pgtable indirection by having the SMMU drivers subsequently swizzle
in alternate domain ops once they've picked a format, though. That was a
bit too clunky to achieve at the whole iommu_ops level when I
experimented with it years ago, but now it might well be worth another
try...
One other comment below.
> Signed-off-by: Lu Baolu <baolu.lu@linux.intel.com>
> ---
> include/linux/iommu.h | 93 ++++++++++++---------
> drivers/iommu/amd/iommu.c | 21 +++--
> drivers/iommu/apple-dart.c | 24 ++++--
> drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 22 +++--
> drivers/iommu/arm/arm-smmu/arm-smmu.c | 23 +++--
> drivers/iommu/arm/arm-smmu/qcom_iommu.c | 17 ++--
> drivers/iommu/exynos-iommu.c | 17 ++--
> drivers/iommu/fsl_pamu_domain.c | 13 ++-
> drivers/iommu/intel/iommu.c | 25 ++++--
> drivers/iommu/iommu.c | 15 ++--
> drivers/iommu/ipmmu-vmsa.c | 21 +++--
> drivers/iommu/msm_iommu.c | 17 ++--
> drivers/iommu/mtk_iommu.c | 24 ++++--
> drivers/iommu/mtk_iommu_v1.c | 19 +++--
> drivers/iommu/omap-iommu.c | 15 ++--
> drivers/iommu/rockchip-iommu.c | 17 ++--
> drivers/iommu/s390-iommu.c | 15 ++--
> drivers/iommu/sprd-iommu.c | 19 +++--
> drivers/iommu/sun50i-iommu.c | 18 ++--
> drivers/iommu/tegra-gart.c | 15 ++--
> drivers/iommu/tegra-smmu.c | 16 ++--
> drivers/iommu/virtio-iommu.c | 18 ++--
> 22 files changed, 305 insertions(+), 179 deletions(-)
>
> diff --git a/include/linux/iommu.h b/include/linux/iommu.h
> index 111b3e9c79bb..33c5c0e5c465 100644
> --- a/include/linux/iommu.h
> +++ b/include/linux/iommu.h
> @@ -88,7 +88,7 @@ struct iommu_domain_geometry {
>
> struct iommu_domain {
> unsigned type;
> - const struct iommu_ops *ops;
> + const struct domain_ops *ops;
> unsigned long pgsize_bitmap; /* Bitmap of page sizes in use */
> iommu_fault_handler_t handler;
> void *handler_token;
> @@ -192,26 +192,11 @@ struct iommu_iotlb_gather {
> * struct iommu_ops - iommu ops and capabilities
> * @capable: check capability
> * @domain_alloc: allocate iommu domain
> - * @domain_free: free iommu domain
> - * @attach_dev: attach device to an iommu domain
> - * @detach_dev: detach device from an iommu domain
> - * @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
> - * an iommu domain.
> - * @unmap: unmap a physically contiguous memory region from an iommu domain
> - * @unmap_pages: unmap a number of pages of the same size from an iommu domain
> - * @flush_iotlb_all: Synchronously flush all hardware TLBs for this domain
> - * @iotlb_sync_map: Sync mappings created recently using @map to the hardware
> - * @iotlb_sync: Flush all queued ranges from the hardware TLBs and empty flush
> - * queue
> - * @iova_to_phys: translate iova to physical address
> * @probe_device: Add device to iommu driver handling
> * @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
> * @device_group: find iommu group for a particular device
> - * @enable_nesting: Enable nesting
> - * @set_pgtable_quirks: Set io page table quirks (IO_PGTABLE_QUIRK_*)
> * @get_resv_regions: Request list of reserved regions for a device
> * @put_resv_regions: Free list of reserved regions for a device
> * @apply_resv_region: Temporary helper call-back for iova reserved ranges
> @@ -237,33 +222,11 @@ struct iommu_ops {
>
> /* Domain allocation and freeing by the iommu driver */
> struct iommu_domain *(*domain_alloc)(unsigned iommu_domain_type);
> - void (*domain_free)(struct iommu_domain *);
>
> - int (*attach_dev)(struct iommu_domain *domain, struct device *dev);
> - void (*detach_dev)(struct iommu_domain *domain, struct device *dev);
> - int (*map)(struct iommu_domain *domain, unsigned long iova,
> - phys_addr_t paddr, size_t size, int prot, gfp_t gfp);
> - int (*map_pages)(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);
> - size_t (*unmap)(struct iommu_domain *domain, unsigned long iova,
> - size_t size, struct iommu_iotlb_gather *iotlb_gather);
> - size_t (*unmap_pages)(struct iommu_domain *domain, unsigned long iova,
> - size_t pgsize, size_t pgcount,
> - struct iommu_iotlb_gather *iotlb_gather);
> - void (*flush_iotlb_all)(struct iommu_domain *domain);
> - void (*iotlb_sync_map)(struct iommu_domain *domain, unsigned long iova,
> - size_t size);
> - void (*iotlb_sync)(struct iommu_domain *domain,
> - struct iommu_iotlb_gather *iotlb_gather);
> - phys_addr_t (*iova_to_phys)(struct iommu_domain *domain, dma_addr_t iova);
> struct iommu_device *(*probe_device)(struct device *dev);
> void (*release_device)(struct device *dev);
> void (*probe_finalize)(struct device *dev);
> struct iommu_group *(*device_group)(struct device *dev);
> - int (*enable_nesting)(struct iommu_domain *domain);
> - int (*set_pgtable_quirks)(struct iommu_domain *domain,
> - unsigned long quirks);
>
> /* Request/Free a list of reserved regions for a device */
> void (*get_resv_regions)(struct device *dev, struct list_head *list);
> @@ -296,6 +259,60 @@ struct iommu_ops {
> struct module *owner;
> };
>
> +/**
> + * struct domain_ops - per-domain ops
> + * @attach_dev: attach an iommu domain to a device
> + * @detach_dev: detach an iommu domain from a 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
> + * an iommu domain.
> + * @unmap: unmap a physically contiguous memory region from an iommu domain
> + * @unmap_pages: unmap a number of pages of the same size from an iommu domain
> + * @flush_iotlb_all: Synchronously flush all hardware TLBs for this domain
> + * @iotlb_sync_map: Sync mappings created recently using @map to the hardware
> + * @iotlb_sync: Flush all queued ranges from the hardware TLBs and empty flush
> + * queue
> + * @iova_to_phys: translate iova to physical address
> + * @enable_nesting: Enable nesting
> + * @set_pgtable_quirks: Set io page table quirks (IO_PGTABLE_QUIRK_*)
> + * @release: Release the domain after use.
Not sure about the name change here - it's still logically a "free" that
matches an "alloc", we're not doing anything clever like refcounting or
devres, which is what I'd tend to associate with a "release" function
for an allocated resource.
Robin.
> + */
> +struct domain_ops {
> + int (*attach_dev)(struct iommu_domain *domain, struct device *dev);
> + void (*detach_dev)(struct iommu_domain *domain, struct device *dev);
> +
> + int (*map)(struct iommu_domain *domain, unsigned long iova,
> + phys_addr_t paddr, size_t size, int prot, gfp_t gfp);
> + int (*map_pages)(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);
> + size_t (*unmap)(struct iommu_domain *domain, unsigned long iova,
> + size_t size, struct iommu_iotlb_gather *iotlb_gather);
> + size_t (*unmap_pages)(struct iommu_domain *domain, unsigned long iova,
> + size_t pgsize, size_t pgcount,
> + struct iommu_iotlb_gather *iotlb_gather);
> +
> + void (*flush_iotlb_all)(struct iommu_domain *domain);
> + void (*iotlb_sync_map)(struct iommu_domain *domain, unsigned long iova,
> + size_t size);
> + void (*iotlb_sync)(struct iommu_domain *domain,
> + struct iommu_iotlb_gather *iotlb_gather);
> +
> + phys_addr_t (*iova_to_phys)(struct iommu_domain *domain, dma_addr_t iova);
> +
> + int (*enable_nesting)(struct iommu_domain *domain);
> + int (*set_pgtable_quirks)(struct iommu_domain *domain,
> + unsigned long quirks);
> +
> + void (*release)(struct iommu_domain *domain);
> +};
_______________________________________________
iommu mailing list
iommu@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/iommu
next prev parent reply other threads:[~2022-01-25 0:58 UTC|newest]
Thread overview: 48+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-01-24 7:10 [PATCH 0/7] iommu cleanup and refactoring Lu Baolu
2022-01-24 7:10 ` [PATCH 1/7] iommu/vt-d: Remove guest pasid related callbacks Lu Baolu
2022-01-24 9:25 ` Christoph Hellwig
2022-01-24 7:10 ` [PATCH 2/7] iommu: Remove guest pasid related interfaces and definitions Lu Baolu
2022-01-24 9:26 ` Christoph Hellwig
2022-01-24 7:10 ` [PATCH 3/7] iommu/vt-d: Remove aux-domain related callbacks Lu Baolu
2022-01-24 9:26 ` Christoph Hellwig
2022-01-24 7:10 ` [PATCH 4/7] iommu: Remove aux-domain related interfaces and iommu_ops Lu Baolu
2022-01-24 9:27 ` Christoph Hellwig
2022-01-24 7:11 ` [PATCH 5/7] drm/nouveau/device: Get right pgsize_bitmap of iommu_domain Lu Baolu
2022-01-24 9:29 ` Christoph Hellwig
2022-01-25 2:59 ` Lu Baolu
2022-01-24 7:11 ` [PATCH 6/7] iommu: Use right way to retrieve iommu_ops Lu Baolu
2022-01-24 9:32 ` Christoph Hellwig
2022-01-25 3:01 ` Lu Baolu
2022-01-24 9:48 ` Tian, Kevin
2022-01-25 3:04 ` Lu Baolu
2022-01-24 17:36 ` Jason Gunthorpe via iommu
2022-01-25 3:18 ` Lu Baolu
2022-01-25 0:20 ` Robin Murphy
2022-01-25 3:54 ` Lu Baolu
2022-01-24 7:11 ` [PATCH 7/7] iommu: Add iommu_domain::domain_ops Lu Baolu
2022-01-24 9:37 ` Christoph Hellwig
2022-01-24 17:24 ` Jason Gunthorpe via iommu
2022-01-25 4:43 ` Lu Baolu
2022-01-25 4:42 ` Lu Baolu
2022-01-24 9:58 ` Tian, Kevin
2022-01-24 10:16 ` Jean-Philippe Brucker
2022-01-24 16:33 ` Jason Gunthorpe via iommu
2022-01-26 9:41 ` Jean-Philippe Brucker
2022-01-24 17:17 ` Jason Gunthorpe via iommu
2022-01-25 4:59 ` Lu Baolu
2022-01-25 12:37 ` Jason Gunthorpe via iommu
2022-01-24 17:55 ` Jason Gunthorpe via iommu
2022-01-25 5:04 ` Lu Baolu
2022-01-25 0:57 ` Robin Murphy [this message]
2022-01-25 6:27 ` Lu Baolu
2022-01-25 14:23 ` Robin Murphy
2022-01-25 15:00 ` Jason Gunthorpe via iommu
2022-01-24 9:46 ` [PATCH 0/7] iommu cleanup and refactoring Tian, Kevin
2022-01-24 17:44 ` Jason Gunthorpe via iommu
2022-01-25 1:11 ` Tian, Kevin
2022-01-25 14:48 ` Robin Murphy
2022-01-25 15:16 ` Jason Gunthorpe via iommu
2022-01-26 1:51 ` Lu Baolu
2022-01-26 13:27 ` Jason Gunthorpe via iommu
2022-01-26 14:00 ` Robin Murphy
2022-02-08 1:32 ` Lu Baolu
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=99023cd7-f037-282f-3f25-629a14a1578b@arm.com \
--to=robin.murphy@arm.com \
--cc=airlied@linux.ie \
--cc=alex.williamson@redhat.com \
--cc=ashok.raj@intel.com \
--cc=baolu.lu@linux.intel.com \
--cc=bskeggs@redhat.com \
--cc=daniel@ffwll.ch \
--cc=hch@infradead.org \
--cc=iommu@lists.linux-foundation.org \
--cc=jacob.jun.pan@intel.com \
--cc=jgg@nvidia.com \
--cc=jonathanh@nvidia.com \
--cc=joro@8bytes.org \
--cc=kevin.tian@intel.com \
--cc=linux-kernel@vger.kernel.org \
--cc=thierry.reding@gmail.com \
--cc=will@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).