From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796110090; b=daoJe9IGk78GsY+JZOJ6T2gJ6R+SZu9Ky7Az7taO+GdK+9to/Uh2QYBlBfZnj+o6bAK0 3cjOHp78kEUz7e956b6+Ek/Be1YF8ULyfWe/MFgj20S0Nn9ZSsu0K8sqcspHwSnYEcJmH yBs1QFZE2fc8MQD1FSCWJaggp1vdfdJdokFbZlOAMyNK8kn6BIdCgeBnsJA/M2UhP1gz2 Fa887wvy9JPf0nbqJn5Tdq53u182qhIsL2IIMQnAzDKnrA87vojwmzAwpISaHQmqYDQ4Y RFbTjYXXPTwwaBtvN+F4/dE0QyGlQVAMzxoQR9ctLhkWiE4uTIu5cO3mC+Q2Id566MA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796110090; h=Received:DKIM-Signature:Message-ID:From:Subject:Reply-To:To:Cc: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date; bh=ciQyLBe10orOwiHfjxe5be3Nb3NerMOnH/DElKCNBFk=; b=OgCgYSWUCsha2jNl7Xzs8nQZFtaWrKWEEp1PoA/2ZCbY6Vn4QLecHzEkbuOjZWQQ1Nlg puH3txstOr69mAZXilIJGIP4eKdVtJFA61HtYiIkG9RKn2n7VVV9RdiKgbECwkgdabKYq UE20Y1QQVfhtYbTfAx+Rm/3oly+5RGEoxo5HQuSAyjSkarhQeFF13KHGz8WrX9FJNyiY/ qzzKT+h0k56a6epYT2hRjkwC1WOZJM1YreL/DjSbkeLuLfC8yxEKm2pp/DofyVoE8lF/O JEYkRokxMkt289PM9VK7brGOaiza7F1tphboEmltw6WnTB0BCSeRE0ObTSmY9UUPseA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b="A0M/H1GD"; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BE694606A338; Tue, 1 Dec 2026 07:28:10 +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: 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() Reply-To: sashiko-reviews@lists.linux.dev 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-Mailing-List: kvm@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list 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