From: sashiko-bot@kernel.org
To: "Alistair Popple" <apopple@nvidia.com>
Cc: dri-devel@lists.freedesktop.org, intel-xe@lists.freedesktop.org,
linux-rdma@vger.kernel.org, kvm@vger.kernel.org,
media-ci@linuxtv.org
Subject: Re: [PATCH RFC 13/16] iommufd: Map DMA-bufs through dma_buf_iommu_map()
Date: Tue, 01 Dec 2026 07:28:09 +0000 [thread overview]
Message-ID: <sashiko-outbox-242770@kernel.org> (raw)
In-Reply-To: <20261201-dmabuf_shared_buf_v1_xe_rc5-v1-13-b672717c7fc9@nvidia.com>
Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [Medium] iommufd: missed revoke race during attach in
iopt_map_dmabuf()
- [Low] iommufd: multi-domain unfill paths bypass dma_buf_iommu_unmap()
--
commit e899ecc3d9089496a227965c5bb36a21b049566a
Author: Alistair Popple <apopple@nvidia.com>
iommufd: Map DMA-bufs through dma_buf_iommu_map()
This commit switches iommufd to map and unmap DMA-bufs in IOMMU domains
through dma_buf_iommu_map() and dma_buf_iommu_unmap() instead of reading
physical addresses through the PFN reader.
> diff --git a/drivers/iommu/iommufd/pages.c b/drivers/iommu/iommufd/pages.c
> index fcdbde007a9ab..aeac509e574fe 100644
> --- a/drivers/iommu/iommufd/pages.c
> +++ b/drivers/iommu/iommufd/pages.c
[ ... ]
> @@ -1467,38 +1461,16 @@ static const struct dma_buf_attach_ops iopt_dmabuf_attach_revoke_ops = {
> .invalidate_mappings = iopt_revoke_notify,
> };
>
> -/*
> - * iommufd and vfio have a circular dependency. Future work for a phys
> - * based private interconnect will remove this.
> - */
> -static int
> -sym_vfio_pci_dma_buf_iommufd_map(struct dma_buf_attachment *attachment,
> - struct phys_vec *phys)
> -{
> - typeof(&vfio_pci_dma_buf_iommufd_map) fn;
> - int rc;
> -
> - rc = iommufd_test_dma_buf_iommufd_map(attachment, phys);
> - if (rc != -EOPNOTSUPP)
> - return rc;
> -
> - if (!IS_ENABLED(CONFIG_VFIO_PCI_DMABUF))
> - return -EOPNOTSUPP;
> -
> - fn = symbol_get(vfio_pci_dma_buf_iommufd_map);
> - if (!fn)
> - return -EOPNOTSUPP;
> - rc = fn(attachment, phys);
> - symbol_put(vfio_pci_dma_buf_iommufd_map);
> - return rc;
> -}
> -
> static int iopt_map_dmabuf(struct iommufd_ctx *ictx, struct iopt_pages *pages,
> struct dma_buf *dmabuf)
> {
> struct dma_buf_attachment *attach;
> int rc;
>
> + /* Fail at import rather than when a domain is first filled */
> + if (!dma_buf_iommu_mappable(dmabuf))
> + return -EOPNOTSUPP;
> +
> attach = dma_buf_dynamic_attach(dmabuf, iommufd_global_device(),
> &iopt_dmabuf_attach_revoke_ops, pages);
> if (IS_ERR(attach))
> @@ -1518,18 +1490,12 @@ static int iopt_map_dmabuf(struct iommufd_ctx *ictx, struct iopt_pages *pages,
> if (rc)
> goto err_detach;
>
> - rc = sym_vfio_pci_dma_buf_iommufd_map(attach, &pages->dmabuf.phys);
> - if (rc)
> - goto err_unpin;
> -
> dma_resv_unlock(dmabuf->resv);
>
> /* On success iopt_release_pages() will detach and put the dmabuf. */
> pages->dmabuf.attach = attach;
> return 0;
[Severity: Medium]
Can iopt_map_dmabuf() miss a concurrent revoke and leave
pages->dmabuf.revoked as false on a revoked buffer?
Previously, sym_vfio_pci_dma_buf_iommufd_map() checked priv->revoked under
dmabuf->resv after dma_buf_dynamic_attach() had added attach to
dmabuf->attachments. Now the only check during import is in
dmabuf->ops->attach(), which dma_buf_dynamic_attach() calls before taking
dmabuf->resv and adding attach to dmabuf->attachments, while dma_buf_pin()
is a no-op for exporters without .pin (such as vfio_pci_dmabuf_ops and
iommufd_test_dmabuf_ops):
CPU0 CPU1
iopt_map_dmabuf()
dma_buf_dynamic_attach()
ops->attach()
if (priv->revoked) // false
vfio_pci_dma_buf_move() /
iommufd_test_dmabuf_revoke()
dma_resv_lock(dmabuf->resv, ...)
priv->revoked = true;
dma_buf_invalidate_mappings()
// attach not in attachments yet
dma_resv_unlock(dmabuf->resv)
dma_resv_lock(dmabuf->resv, ...)
list_add(&attach->node,
&dmabuf->attachments)
dma_resv_unlock(dmabuf->resv)
...
// succeeds with pages->dmabuf.revoked == false
If the IOAS has no domains attached yet, iopt_area_fill_domains() returns 0
early when xa_empty(&area->iopt->domains) is true, so IOMMU_IOAS_MAP_FILE
succeeds with pages->dmabuf.revoked left as false. When a domain is later
attached via iopt_table_add_domain() -> iopt_fill_domain(),
iopt_area_fill_domain() sees iopt_dmabuf_revoked() == false and calls
dma_buf_iommu_map(), failing the domain attach with -ENODEV instead of
skipping the revoked DMA-buf (or allowing a later mapping if the exporter
re-enables access after a revoke that should have been permanent).
> @@ -1764,8 +1730,8 @@ static void __iopt_area_unfill_domain(struct iopt_area *area,
> if (iopt_is_dmabuf(pages)) {
> if (WARN_ON(iopt_dmabuf_revoked(pages)))
> return;
> - iopt_area_unmap_domain_range(area, domain, start_index,
> - last_index);
> + iopt_dmabuf_unmap_domain_range(area, pages, domain, start_index,
> + last_index);
> return;
> }
[Severity: Low]
Should the multi-domain unfill paths in iopt_unfill_domain() and
iopt_area_unfill_domains() also unmap DMA-bufs through
iopt_dmabuf_unmap_domain_range() (or iopt_area_unfill_domain()) instead of
iopt_area_unmap_domain() and iopt_area_unmap_domain_range()?
When more than one domain is attached to the IOAS, those two paths still
unmap DMA-buf areas directly via iommu_unmap_nofail() rather than
dma_buf_iommu_unmap():
drivers/iommu/iommufd/io_pagetable.c:iopt_unfill_domain() {
...
if (iopt_is_dmabuf(pages)) {
if (!iopt_dmabuf_revoked(pages))
iopt_area_unmap_domain(area, domain);
iopt_dmabuf_untrack_domain(pages, area, domain);
}
...
}
drivers/iommu/iommufd/pages.c:iopt_area_unfill_domains() {
...
xa_for_each(&iopt->domains, index, domain) {
if (domain == area->storage_domain)
continue;
if (!iopt_dmabuf_revoked(pages))
iopt_area_unmap_domain_range(
area, domain, iopt_area_index(area),
iopt_area_last_index(area));
}
...
}
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261201-dmabuf_shared_buf_v1_xe_rc5-v1-0-b672717c7fc9@nvidia.com?part=13
next prev parent reply other threads:[~2026-12-01 7:28 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-01 7:06 [PATCH RFC 00/16] dma-buf: Introduce dma_shared_buf and dma_addr_list to replace sg_table Alistair Popple
2026-12-01 7:06 ` [PATCH RFC 01/16] treewide: Rename dma_buf_(un)map_attachment() to dma_buf_(un)map_sgt() Alistair Popple
2026-12-01 7:06 ` [PATCH RFC 02/16] dma-shared-buf: Add struct dma_shared_buf Alistair Popple
2026-12-01 7:06 ` [PATCH RFC 03/16] dma-shared-buf: Add dma_shared_buf_iommu_map() Alistair Popple
2026-12-01 7:06 ` [PATCH RFC 04/16] dma-shared-buf: Add dma_addr_list_to_sgt() Alistair Popple
2026-12-01 7:19 ` sashiko-bot
2026-12-01 7:06 ` [PATCH RFC 05/16] dma-shared-buf: Add dma_shared_buf_from_pages() Alistair Popple
2026-12-01 7:06 ` [PATCH RFC 06/16] dma-buf: Allow exporters to hand out a dma_shared_buf Alistair Popple
2026-12-01 7:06 ` [PATCH RFC 07/16] dma-buf: Add dma_buf_iommu_map() for IOMMU domain importers Alistair Popple
2026-12-01 7:06 ` [PATCH RFC 08/16] dma-buf: Factor out the pin and fence wait around the exporter's map Alistair Popple
2026-12-01 7:06 ` [PATCH RFC 09/16] dma-buf: Add dma_buf_map_dma_list() for DMA address only importers Alistair Popple
2026-12-01 7:06 ` [PATCH RFC 10/16] vfio/pci: Export a dma_shared_buf instead of mapping the buffer Alistair Popple
2026-12-01 7:06 ` [PATCH RFC 11/16] RDMA/uverbs: " Alistair Popple
2026-12-01 7:06 ` [PATCH RFC 12/16] dma-buf: Remove dma_buf_phys_vec_to_sgt() and dma_buf_free_sgt() Alistair Popple
2026-12-01 7:06 ` [PATCH RFC 13/16] iommufd: Map DMA-bufs through dma_buf_iommu_map() Alistair Popple
2026-12-01 7:28 ` sashiko-bot [this message]
2026-12-01 7:06 ` [PATCH RFC 14/16] vfio/pci: Remove vfio_pci_dma_buf_iommufd_map() Alistair Popple
2026-12-01 7:06 ` [PATCH RFC 15/16] drm/xe/dma-buf: Export a dma_shared_buf instead of mapping the buffer Alistair Popple
2026-12-01 7:26 ` sashiko-bot
2026-12-01 7:06 ` [PATCH RFC 16/16] drm/xe: Import DMA-bufs as a DMA address list Alistair Popple
2026-12-01 7:28 ` [PATCH RFC 00/16] dma-buf: Introduce dma_shared_buf and dma_addr_list to replace sg_table sashiko-bot
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=sashiko-outbox-242770@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=apopple@nvidia.com \
--cc=dri-devel@lists.freedesktop.org \
--cc=intel-xe@lists.freedesktop.org \
--cc=kvm@vger.kernel.org \
--cc=linux-rdma@vger.kernel.org \
--cc=media-ci@linuxtv.org \
--cc=sashiko-reviews@lists.linux.dev \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.