From: Nicolin Chen <nicolinc@nvidia.com>
To: Jason Gunthorpe <jgg@nvidia.com>
Cc: <robin.murphy@arm.com>, <joro@8bytes.org>, <bhelgaas@google.com>,
<will@kernel.org>, <robin.clark@oss.qualcomm.com>,
<yong.wu@mediatek.com>, <matthias.bgg@gmail.com>,
<angelogioacchino.delregno@collabora.com>,
<thierry.reding@gmail.com>, <vdumpa@nvidia.com>,
<jonathanh@nvidia.com>, <rafael@kernel.org>, <lenb@kernel.org>,
<kevin.tian@intel.com>, <yi.l.liu@intel.com>,
<baolu.lu@linux.intel.com>,
<linux-arm-kernel@lists.infradead.org>, <iommu@lists.linux.dev>,
<linux-kernel@vger.kernel.org>, <linux-arm-msm@vger.kernel.org>,
<linux-mediatek@lists.infradead.org>,
<linux-tegra@vger.kernel.org>, <linux-acpi@vger.kernel.org>,
<linux-pci@vger.kernel.org>, <patches@lists.linux.dev>,
<pjaroszynski@nvidia.com>, <vsethi@nvidia.com>,
<helgaas@kernel.org>, <etzhao1900@gmail.com>
Subject: Re: [PATCH v3 3/5] iommu: Add iommu_get_domain_for_dev_locked() helper
Date: Tue, 19 Aug 2025 10:22:20 -0700 [thread overview]
Message-ID: <aKSyzI9Xz3J0nhfk@Asurada-Nvidia> (raw)
In-Reply-To: <20250819125249.GG802098@nvidia.com>
On Tue, Aug 19, 2025 at 09:52:49AM -0300, Jason Gunthorpe wrote:
> On Mon, Aug 18, 2025 at 10:09:11PM -0700, Nicolin Chen wrote:
> > Yes, I've thought about that. The concern is that some other place
> > someday may want to use iommu_get_domain_for_dev() in similar cases
> > but would find that it doesn't work. So it would have to duplicate
> > the domain pointer in its "master" structure.
> >
> > Overall, having a _locked version feels cleaner to me.
>
> We probably need the locked version, but it just shouldn't be called very
> much..
OK. Let's have one patch upgrading the attach_dev to pass in the
old domain pointer (aligning with the SVA version of attach_dev),
and another patch adding the _locked version that then will have
very limited callers.
> > > With sensible internal locking
> >
> > Hmm, I feel this iommu_get_translation_mode() is somewhat the same
> > as the current iommu_get_domain_for_dev(). It would just return the
> > group->domain->type v.s. group->domain, right?
> >
> > This doesn't have any UAF concern though.
>
> Yes, no UAF concern is the point
I see.
> > > So that is another bunch. Not sure what will be left after.
> >
> > I recall that some of the drivers manages their own domains, e.g.
> > drivers/gpu/drm/tegra/drm.c
> >
> > So, they would want more out of the domain pointer than just type.
>
> This looks like it wants an 'is currently attached' operation
That's certainly one of the wide use cases. And I think we could
have an IOMMU_DOMAIN_NONE to fit that into the type helper.
Yet, I also see some other cases that cannot be helped with the
type function. Just listing a few:
1) domain matching (and type)
drivers/gpu/drm/tegra/drm.c:965: if (domain && domain->type != IOMMU_DOMAIN_IDENTITY &&
drivers/gpu/drm/tegra/drm.c:966: domain != tegra->domain)
drivers/gpu/drm/tegra/drm.c-967- return 0;
2) page size
drivers/gpu/drm/arm/malidp_planes.c:307: mmu_dom = iommu_get_domain_for_dev(mp->base.dev->dev);
drivers/gpu/drm/arm/malidp_planes.c-308- if (mmu_dom)
drivers/gpu/drm/arm/malidp_planes.c-309- return mmu_dom->pgsize_bitmap;
3) iommu_iova_to_phys
drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c:2597: dom = iommu_get_domain_for_dev(adev->dev);
drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c-2598-
drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c-2599- while (size) {
drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c-2600- phys_addr_t addr = *pos & PAGE_MASK;
drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c-2601- loff_t off = *pos & ~PAGE_MASK;
drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c-2602- size_t bytes = PAGE_SIZE - off;
drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c-2603- unsigned long pfn;
drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c-2604- struct page *p;
drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c-2605- void *ptr;
drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c-2606-
drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c-2607- bytes = min(bytes, size);
drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c-2608-
drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c:2609: addr = dom ? iommu_iova_to_phys(dom, addr) : addr;
4) map/unmap
drivers/net/ipa/ipa_mem.c:465: domain = iommu_get_domain_for_dev(dev);
drivers/net/ipa/ipa_mem.c-466- if (!domain) {
drivers/net/ipa/ipa_mem.c-467- dev_err(dev, "no IOMMU domain found for IMEM\n");
drivers/net/ipa/ipa_mem.c-468- return -EINVAL;
drivers/net/ipa/ipa_mem.c-469- }
drivers/net/ipa/ipa_mem.c-470-
drivers/net/ipa/ipa_mem.c-471- /* Align the address down and the size up to page boundaries */
drivers/net/ipa/ipa_mem.c-472- phys = addr & PAGE_MASK;
drivers/net/ipa/ipa_mem.c-473- size = PAGE_ALIGN(size + addr - phys);
drivers/net/ipa/ipa_mem.c-474- iova = phys; /* We just want a direct mapping */
drivers/net/ipa/ipa_mem.c-475-
drivers/net/ipa/ipa_mem.c-476- ret = iommu_map(domain, iova, phys, size, IOMMU_READ | IOMMU_WRITE,
...
drivers/net/ipa/ipa_mem.c:495: domain = iommu_get_domain_for_dev(dev);
drivers/net/ipa/ipa_mem.c-496- if (domain) {
drivers/net/ipa/ipa_mem.c-497- size_t size;
drivers/net/ipa/ipa_mem.c-498-
drivers/net/ipa/ipa_mem.c-499- size = iommu_unmap(domain, ipa->imem_iova, ipa->imem_size);
We could probably invent something for case 1-3. But for case 4,
it feels that iommu_get_domain_for_dev() is the only helper..
Thanks
Nicolin
next prev parent reply other threads:[~2025-08-19 17:22 UTC|newest]
Thread overview: 55+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-08-11 22:59 [PATCH v3 0/5] Disable ATS via iommu during PCI resets Nicolin Chen
2025-08-11 22:59 ` [PATCH v3 1/5] iommu: Lock group->mutex in iommu_deferred_attach Nicolin Chen
2025-08-15 5:09 ` Baolu Lu
2025-08-15 8:27 ` Tian, Kevin
2025-08-15 8:24 ` Tian, Kevin
2025-08-15 19:26 ` Nicolin Chen
2025-08-18 14:17 ` Jason Gunthorpe
2025-08-18 17:45 ` Nicolin Chen
2025-08-18 18:09 ` Jason Gunthorpe
2025-08-18 18:29 ` Nicolin Chen
2025-08-11 22:59 ` [PATCH v3 2/5] iommu: Pass in gdev to __iommu_device_set_domain Nicolin Chen
2025-08-15 5:18 ` Baolu Lu
2025-08-15 8:29 ` Tian, Kevin
2025-08-11 22:59 ` [PATCH v3 3/5] iommu: Add iommu_get_domain_for_dev_locked() helper Nicolin Chen
2025-08-15 5:28 ` Baolu Lu
2025-08-15 18:48 ` Nicolin Chen
2025-08-18 14:40 ` Jason Gunthorpe
2025-08-19 2:09 ` Baolu Lu
2025-08-15 8:55 ` Tian, Kevin
2025-08-15 18:45 ` Nicolin Chen
2025-08-21 8:07 ` Tian, Kevin
2025-08-21 14:41 ` Nicolin Chen
2025-08-31 23:24 ` Nicolin Chen
2025-08-18 14:39 ` Jason Gunthorpe
2025-08-18 17:22 ` Nicolin Chen
2025-08-18 23:42 ` Jason Gunthorpe
2025-08-19 5:09 ` Nicolin Chen
2025-08-19 12:52 ` Jason Gunthorpe
2025-08-19 17:22 ` Nicolin Chen [this message]
2025-08-21 13:13 ` Jason Gunthorpe
2025-08-21 15:22 ` Nicolin Chen
2025-08-21 18:37 ` Jason Gunthorpe
2025-08-22 5:11 ` Nicolin Chen
2025-08-21 8:11 ` Tian, Kevin
2025-08-21 13:14 ` Jason Gunthorpe
2025-08-22 9:45 ` Tian, Kevin
2025-08-22 13:21 ` Jason Gunthorpe
2025-08-11 22:59 ` [PATCH v3 4/5] iommu: Introduce iommu_dev_reset_prepare() and iommu_dev_reset_done() Nicolin Chen
2025-08-15 5:49 ` Baolu Lu
2025-08-15 20:10 ` Nicolin Chen
2025-08-15 9:14 ` Tian, Kevin
2025-08-15 19:45 ` Nicolin Chen
2025-08-11 22:59 ` [PATCH v3 5/5] pci: Suspend iommu function prior to resetting a device Nicolin Chen
2025-08-19 14:12 ` Ethan Zhao
2025-08-19 21:59 ` Nicolin Chen
2025-08-20 3:18 ` Ethan Zhao
2025-08-22 6:14 ` Nicolin Chen
2025-08-21 13:07 ` Jason Gunthorpe
2025-08-22 6:35 ` Nicolin Chen
2025-08-22 14:08 ` Jason Gunthorpe
2025-08-22 18:50 ` Nicolin Chen
2025-08-28 12:51 ` Jason Gunthorpe
2025-08-28 15:08 ` Nicolin Chen
2025-08-28 18:46 ` Jason Gunthorpe
2025-08-28 19:35 ` Nicolin Chen
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=aKSyzI9Xz3J0nhfk@Asurada-Nvidia \
--to=nicolinc@nvidia.com \
--cc=angelogioacchino.delregno@collabora.com \
--cc=baolu.lu@linux.intel.com \
--cc=bhelgaas@google.com \
--cc=etzhao1900@gmail.com \
--cc=helgaas@kernel.org \
--cc=iommu@lists.linux.dev \
--cc=jgg@nvidia.com \
--cc=jonathanh@nvidia.com \
--cc=joro@8bytes.org \
--cc=kevin.tian@intel.com \
--cc=lenb@kernel.org \
--cc=linux-acpi@vger.kernel.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-arm-msm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mediatek@lists.infradead.org \
--cc=linux-pci@vger.kernel.org \
--cc=linux-tegra@vger.kernel.org \
--cc=matthias.bgg@gmail.com \
--cc=patches@lists.linux.dev \
--cc=pjaroszynski@nvidia.com \
--cc=rafael@kernel.org \
--cc=robin.clark@oss.qualcomm.com \
--cc=robin.murphy@arm.com \
--cc=thierry.reding@gmail.com \
--cc=vdumpa@nvidia.com \
--cc=vsethi@nvidia.com \
--cc=will@kernel.org \
--cc=yi.l.liu@intel.com \
--cc=yong.wu@mediatek.com \
/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).