From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5565F606A33B for ; Tue, 1 Dec 2026 07:28:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=A0M/H1GD Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id A39C010F107; Tue, 1 Dec 2026 07:28:17 +0000 (UTC) Received: from sea.source.kernel.org (sea.source.kernel.org [172.234.252.31]) by gabe.freedesktop.org (Postfix) with ESMTPS id AA7D810F0B1; Tue, 1 Dec 2026 07:28:10 +0000 (UTC) Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) by sea.source.kernel.org (Postfix) with ESMTP id 8965741B2E; Tue, 1 Dec 2026 07:28:10 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3021B1F00893; Tue, 1 Dec 2026 07:28:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796110090; bh=ciQyLBe10orOwiHfjxe5be3Nb3NerMOnH/DElKCNBFk=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=A0M/H1GDm78kA4u2au7O26PfzMq05Z4TR4b37CMKFmCQJhl9mb9J1b9nhC86jlTEV JYJeM/aZkvywaLWHmzvZ1+2/XKNQgHUpU7wtj6bqt4smkMqoLNAYcYrDtb3Fib8Pdq nkzLz389GPx/0IgtmA1RBOFGoCGJZWLy+hdkPSyEgzUNNLpEol2q1+uDipKf5Uopup d3IaPWE+gySax3YZtXhSJgyNu4li6A8Jbqsxya1ViqVRmJWunC++bzkkcKyv0AQrNf DuNTbD/fXVv3+v5/71SS+4KPT50Stg7KjdMPCvTa2bjGWV2kqYkYTdX5Ole1nSRauJ QOFBA4S1sB37g== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH RFC 13/16] iommufd: Map DMA-bufs through dma_buf_iommu_map() To: "Alistair Popple" Cc: dri-devel@lists.freedesktop.org, intel-xe@lists.freedesktop.org, linux-rdma@vger.kernel.org, kvm@vger.kernel.org, media-ci@linuxtv.org In-Reply-To: <20261201-dmabuf_shared_buf_v1_xe_rc5-v1-13-b672717c7fc9@nvidia.com> References: <20261201-dmabuf_shared_buf_v1_xe_rc5-v1-0-b672717c7fc9@nvidia.com> <20261201-dmabuf_shared_buf_v1_xe_rc5-v1-13-b672717c7fc9@nvidia.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Tue, 01 Dec 2026 07:28:09 +0000 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: sashiko-reviews@lists.linux.dev Sender: "dri-devel" X-Spam-Status: No, score=-10.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=4.0.1 X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on aws-us-west-2-korg-listserv-alma10-1 X-Archived-By: 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 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_dmabu= f_attach_revoke_ops =3D { > .invalidate_mappings =3D iopt_revoke_notify, > }; > =20 > -/* > - * 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 =3D iommufd_test_dma_buf_iommufd_map(attachment, phys); > - if (rc !=3D -EOPNOTSUPP) > - return rc; > - > - if (!IS_ENABLED(CONFIG_VFIO_PCI_DMABUF)) > - return -EOPNOTSUPP; > - > - fn =3D symbol_get(vfio_pci_dma_buf_iommufd_map); > - if (!fn) > - return -EOPNOTSUPP; > - rc =3D 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; > =20 > + /* Fail at import rather than when a domain is first filled */ > + if (!dma_buf_iommu_mappable(dmabuf)) > + return -EOPNOTSUPP; > + > attach =3D 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 *ic= tx, struct iopt_pages *pages, > if (rc) > goto err_detach; > =20 > - rc =3D sym_vfio_pci_dma_buf_iommufd_map(attach, &pages->dmabuf.phys); > - if (rc) > - goto err_unpin; > - > dma_resv_unlock(dmabuf->resv); > =20 > /* On success iopt_release_pages() will detach and put the dmabuf. */ > pages->dmabuf.attach =3D 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 =3D 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 =3D=3D 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() =3D=3D 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_a= rea *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 =3D=3D 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)); } ... } --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261201-dmabuf_sha= red_buf_v1_xe_rc5-v1-0-b672717c7fc9@nvidia.com?part=3D13