[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <aRwaHMcgQNqV/cCG@Asurada-Nvidia>
Date: Mon, 17 Nov 2025 23:02:52 -0800
From: Nicolin Chen <nicolinc@...dia.com>
To: Baolu Lu <baolu.lu@...ux.intel.com>
CC: <joro@...tes.org>, <afael@...nel.org>, <bhelgaas@...gle.com>,
<alex@...zbot.org>, <jgg@...dia.com>, <kevin.tian@...el.com>,
<will@...nel.org>, <robin.murphy@....com>, <lenb@...nel.org>,
<linux-arm-kernel@...ts.infradead.org>, <iommu@...ts.linux.dev>,
<linux-kernel@...r.kernel.org>, <linux-acpi@...r.kernel.org>,
<linux-pci@...r.kernel.org>, <kvm@...r.kernel.org>,
<patches@...ts.linux.dev>, <pjaroszynski@...dia.com>, <vsethi@...dia.com>,
<helgaas@...nel.org>, <etzhao1900@...il.com>
Subject: Re: [PATCH v5 3/5] iommu: Add iommu_driver_get_domain_for_dev()
helper
On Wed, Nov 12, 2025 at 09:41:25AM -0800, Nicolin Chen wrote:
> Hi Baolu,
>
> On Wed, Nov 12, 2025 at 01:58:51PM +0800, Baolu Lu wrote:
> > On 11/11/25 13:12, Nicolin Chen wrote:
> > > +/**
> > > + * iommu_get_domain_for_dev() - Return the DMA API domain pointer
> > > + * @dev - Device to query
> > > + *
> > > + * This function can be called within a driver bound to dev. The returned
> > > + * pointer is valid for the lifetime of the bound driver.
> > > + *
> > > + * It should not be called by drivers with driver_managed_dma = true.
> >
> > "driver_managed_dma != true" means the driver will use the default
> > domain allocated by the iommu core during iommu probe.
>
> Hmm, I am not very sure. Jason's remarks pointed out that There
> is an exception in host1x_client_iommu_detach():
> https://lore.kernel.org/all/20250924191055.GJ2617119@nvidia.com/
>
> Where the group->domain could be NULL, i.e. not attached to the
> default domain?
>
> > The iommu core
> > ensures that this domain stored at group->domain will not be changed
> > during the driver's whole lifecycle. That's reasonable.
> >
> > How about making some code to enforce this requirement? Something like
> > below ...
> >
> > > + */
> > > struct iommu_domain *iommu_get_domain_for_dev(struct device *dev)
> > > {
> > > /* Caller must be a probed driver on dev */
> > > @@ -2225,10 +2234,29 @@ struct iommu_domain *iommu_get_domain_for_dev(struct device *dev)
> > > if (!group)
> > > return NULL;
> > > + lockdep_assert_not_held(&group->mutex);
> >
> > ...
> > if (WARN_ON(!dev->driver || !group->owner_cnt || group->owner))
> > return NULL;
>
> With that, could host1x_client_iommu_detach() trigger WARN_ON?
Hi Baolu,
For v6, I tend to keep this API as-is, trying not to give troubles
to existing callers. Jason suggested a potential followup series:
https://lore.kernel.org/linux-iommu/20250821131304.GM802098@nvidia.com/
That would replace this function, so maybe we can think about that.
If you have a strong feeling about the WARN_ON, please let me know.
Thanks
Nicolin
Powered by blists - more mailing lists