iommu.lists.linux-foundation.org archive mirror
 help / color / mirror / Atom feed
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 14:23:52 +0000	[thread overview]
Message-ID: <ab09f75c-08cc-1845-9aa7-81fed779d636@arm.com> (raw)
In-Reply-To: <82c5db53-088f-a51f-6fbc-c977ef871d8f@linux.intel.com>

On 2022-01-25 06:27, Lu Baolu wrote:
> On 1/25/22 8:57 AM, Robin Murphy wrote:
>> 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;"
> 
> In the new model, iommu_domain_ops and iommu_ops are not 1:1 mapped.
> For example, a PASID-capable IOMMU could support DMA domain (which
> supports map/unmap), SVA domain (which does not), and others in the
> future. Different type of domain has its own domain_ops.

Sure, it's clear that that's the direction in which this is headed, and 
as I say I'm quite excited about that. However there are a couple of 
points I think are really worth considering:

Where it's just about which operations are valid for which domains, it's 
even simpler for the core interface wrappers to validate the domain 
type, rather than forcing drivers to implement multiple ops structures 
purely for the sake of having different callbacks populated. We already 
have this in places, e.g. where iommu_map() checks for 
__IOMMU_DOMAIN_PAGING.

Paging domains are also effectively the baseline level of IOMMU API 
functionality. All drivers support them, and for the majority of drivers 
it's all they will ever support. Those drivers really don't benefit from 
any of the churn and boilerplate in this patch as-is, and it's so easy 
to compromise with a couple of lines of core code to handle the common 
case by default when the driver *isn't* one of the handful which ever 
actually cares to install their own per-domain ops. Consider how much 
cleaner this patch would look if the typical driver diff could be 
something completely minimal like this:

----->8-----
diff --git a/drivers/iommu/mtk_iommu_v1.c b/drivers/iommu/mtk_iommu_v1.c
index be22fcf988ce..6aff493e37ee 100644
--- a/drivers/iommu/mtk_iommu_v1.c
+++ b/drivers/iommu/mtk_iommu_v1.c
@@ -514,12 +514,14 @@ static int mtk_iommu_hw_init(const struct 
mtk_iommu_data *data)

  static const struct iommu_ops mtk_iommu_ops = {
  	.domain_alloc	= mtk_iommu_domain_alloc,
-	.domain_free	= mtk_iommu_domain_free,
-	.attach_dev	= mtk_iommu_attach_device,
-	.detach_dev	= mtk_iommu_detach_device,
-	.map		= mtk_iommu_map,
-	.unmap		= mtk_iommu_unmap,
-	.iova_to_phys	= mtk_iommu_iova_to_phys,
+	.domain_ops = &(const struct iommu_domain_ops){
+		.domain_free	= mtk_iommu_domain_free,
+		.attach_dev	= mtk_iommu_attach_device,
+		.detach_dev	= mtk_iommu_detach_device,
+		.map		= mtk_iommu_map,
+		.unmap		= mtk_iommu_unmap,
+		.iova_to_phys	= mtk_iommu_iova_to_phys,
+	}
  	.probe_device	= mtk_iommu_probe_device,
  	.probe_finalize = mtk_iommu_probe_finalize,
  	.release_device	= mtk_iommu_release_device,

-----8<-----

And of course I have to shy away from calling it default_domain_ops, 
since although it's logically default ops for domains, it is not 
specifically ops for default domains, sigh... :)

Cheers,
Robin.
_______________________________________________
iommu mailing list
iommu@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/iommu

  reply	other threads:[~2022-01-25 14:24 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
2022-01-25  6:27     ` Lu Baolu
2022-01-25 14:23       ` Robin Murphy [this message]
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=ab09f75c-08cc-1845-9aa7-81fed779d636@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).