From nobody Sun Feb 8 17:55:11 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 640E043C048; Tue, 20 Jan 2026 14:07:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768918054; cv=none; b=NjabP5z57UjaH+qJOdCAEqbT8drQyObFC7LOuxbdJFWptdnokye/d673d/ojRO1N4t3Nb3j+P9zSe5npmyFEK+GPQlcZBsgwZJMucthTO73Quhh9ID+IPXXwjXaztA0FixyUA9R26OWKUZ1zKFkFpOIYljPUECwD2mX7NoqEIcE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768918054; c=relaxed/simple; bh=OGYKw47EaUqM/lWyK5JqNggda0T3gP3mV7IvIl6ZhwE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=UXza6PNpp5DCs9uFPS4rgnFc1wB5tpOZZ+EWseihp0SqiQTSaUk0Irprw55BYWdVgfYVsKNDcoijodWZoM6ZLsBQDfarnxEEPHkrDW6mA99wwOfN3sJ/29NyJCVVs4pWNIq8BfHWWPpRmxk8Z7gdxjj4dB4FcpsUCHRxfOYs3oI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=tYUeMXTY; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="tYUeMXTY" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 561F9C16AAE; Tue, 20 Jan 2026 14:07:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1768918053; bh=OGYKw47EaUqM/lWyK5JqNggda0T3gP3mV7IvIl6ZhwE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=tYUeMXTYft4GtVy4nltWw2eo7loX0iq5KSPd4tbFPKJ8TCxoPRxPdvjpoGw2OoDBY SWmASS2V8hQJkkbZHFlSFISOLy9ok6Xm46EcCeCy9RAP8sIacs0r4rD9gaJNpKW2Cn 4o3Vm6BGbT7uiGIMPCGWwMYgI9paEvtL32cMHECFVIEKa6/5rmUS6mbliAmbH6h7QR PW8K6Amsao0YSlCtgN5zAh3iEfY7GNmDuydcJQ2HQJz0oP8X1heqiOImOpxlky44zB FpZmoS4zOv69VH85sSs2CUSjJoHA/PYmXIcIiLOyOFlEQ69qa32KUfkeBMKgZfGy7j HszFLQEQAwjqg== From: Leon Romanovsky To: Sumit Semwal , =?utf-8?q?Christian_K=C3=B6nig?= , Alex Deucher , David Airlie , Simona Vetter , Gerd Hoffmann , Dmitry Osipenko , Gurchetan Singh , Chia-I Wu , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , Lucas De Marchi , =?utf-8?q?Thomas_Hellstr=C3=B6m?= , Rodrigo Vivi , Jason Gunthorpe , Leon Romanovsky , Kevin Tian , Joerg Roedel , Will Deacon , Robin Murphy , Felix Kuehling , Alex Williamson , Ankit Agrawal , Vivek Kasireddy Cc: linux-media@vger.kernel.org, dri-devel@lists.freedesktop.org, linaro-mm-sig@lists.linaro.org, linux-kernel@vger.kernel.org, amd-gfx@lists.freedesktop.org, virtualization@lists.linux.dev, intel-xe@lists.freedesktop.org, linux-rdma@vger.kernel.org, iommu@lists.linux.dev, kvm@vger.kernel.org Subject: [PATCH v3 1/7] dma-buf: Rename .move_notify() callback to a clearer identifier Date: Tue, 20 Jan 2026 16:07:01 +0200 Message-ID: <20260120-dmabuf-revoke-v3-1-b7e0b07b8214@nvidia.com> X-Mailer: git-send-email 2.52.0 In-Reply-To: <20260120-dmabuf-revoke-v3-0-b7e0b07b8214@nvidia.com> References: <20260120-dmabuf-revoke-v3-0-b7e0b07b8214@nvidia.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" X-Mailer: b4 0.15-dev-a6db3 Content-Transfer-Encoding: quoted-printable From: Leon Romanovsky Rename the .move_notify() callback to .invalidate_mappings() to make its purpose explicit and highlight that it is responsible for invalidating existing mappings. Suggested-by: Christian K=C3=B6nig Reviewed-by: Christian K=C3=B6nig Signed-off-by: Leon Romanovsky --- drivers/dma-buf/dma-buf.c | 6 +++--- drivers/gpu/drm/amd/amdgpu/amdgpu_dma_buf.c | 4 ++-- drivers/gpu/drm/virtio/virtgpu_prime.c | 2 +- drivers/gpu/drm/xe/tests/xe_dma_buf.c | 6 +++--- drivers/gpu/drm/xe/xe_dma_buf.c | 2 +- drivers/infiniband/core/umem_dmabuf.c | 4 ++-- drivers/infiniband/hw/mlx5/mr.c | 2 +- drivers/iommu/iommufd/pages.c | 2 +- include/linux/dma-buf.h | 6 +++--- 9 files changed, 17 insertions(+), 17 deletions(-) diff --git a/drivers/dma-buf/dma-buf.c b/drivers/dma-buf/dma-buf.c index edaa9e4ee4ae..59cc647bf40e 100644 --- a/drivers/dma-buf/dma-buf.c +++ b/drivers/dma-buf/dma-buf.c @@ -948,7 +948,7 @@ dma_buf_dynamic_attach(struct dma_buf *dmabuf, struct d= evice *dev, if (WARN_ON(!dmabuf || !dev)) return ERR_PTR(-EINVAL); =20 - if (WARN_ON(importer_ops && !importer_ops->move_notify)) + if (WARN_ON(importer_ops && !importer_ops->invalidate_mappings)) return ERR_PTR(-EINVAL); =20 attach =3D kzalloc(sizeof(*attach), GFP_KERNEL); @@ -1055,7 +1055,7 @@ EXPORT_SYMBOL_NS_GPL(dma_buf_pin, "DMA_BUF"); * * This unpins a buffer pinned by dma_buf_pin() and allows the exporter to= move * any mapping of @attach again and inform the importer through - * &dma_buf_attach_ops.move_notify. + * &dma_buf_attach_ops.invalidate_mappings. */ void dma_buf_unpin(struct dma_buf_attachment *attach) { @@ -1262,7 +1262,7 @@ void dma_buf_move_notify(struct dma_buf *dmabuf) =20 list_for_each_entry(attach, &dmabuf->attachments, node) if (attach->importer_ops) - attach->importer_ops->move_notify(attach); + attach->importer_ops->invalidate_mappings(attach); } EXPORT_SYMBOL_NS_GPL(dma_buf_move_notify, "DMA_BUF"); =20 diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_dma_buf.c b/drivers/gpu/drm/= amd/amdgpu/amdgpu_dma_buf.c index e22cfa7c6d32..863454148b28 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_dma_buf.c +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_dma_buf.c @@ -450,7 +450,7 @@ amdgpu_dma_buf_create_obj(struct drm_device *dev, struc= t dma_buf *dma_buf) } =20 /** - * amdgpu_dma_buf_move_notify - &attach.move_notify implementation + * amdgpu_dma_buf_move_notify - &attach.invalidate_mappings implementation * * @attach: the DMA-buf attachment * @@ -521,7 +521,7 @@ amdgpu_dma_buf_move_notify(struct dma_buf_attachment *a= ttach) =20 static const struct dma_buf_attach_ops amdgpu_dma_buf_attach_ops =3D { .allow_peer2peer =3D true, - .move_notify =3D amdgpu_dma_buf_move_notify + .invalidate_mappings =3D amdgpu_dma_buf_move_notify }; =20 /** diff --git a/drivers/gpu/drm/virtio/virtgpu_prime.c b/drivers/gpu/drm/virti= o/virtgpu_prime.c index ce49282198cb..19c78dd2ca77 100644 --- a/drivers/gpu/drm/virtio/virtgpu_prime.c +++ b/drivers/gpu/drm/virtio/virtgpu_prime.c @@ -288,7 +288,7 @@ static void virtgpu_dma_buf_move_notify(struct dma_buf_= attachment *attach) =20 static const struct dma_buf_attach_ops virtgpu_dma_buf_attach_ops =3D { .allow_peer2peer =3D true, - .move_notify =3D virtgpu_dma_buf_move_notify + .invalidate_mappings =3D virtgpu_dma_buf_move_notify }; =20 struct drm_gem_object *virtgpu_gem_prime_import(struct drm_device *dev, diff --git a/drivers/gpu/drm/xe/tests/xe_dma_buf.c b/drivers/gpu/drm/xe/tes= ts/xe_dma_buf.c index 5df98de5ba3c..1f2cca5c2f81 100644 --- a/drivers/gpu/drm/xe/tests/xe_dma_buf.c +++ b/drivers/gpu/drm/xe/tests/xe_dma_buf.c @@ -23,7 +23,7 @@ static bool p2p_enabled(struct dma_buf_test_params *param= s) static bool is_dynamic(struct dma_buf_test_params *params) { return IS_ENABLED(CONFIG_DMABUF_MOVE_NOTIFY) && params->attach_ops && - params->attach_ops->move_notify; + params->attach_ops->invalidate_mappings; } =20 static void check_residency(struct kunit *test, struct xe_bo *exported, @@ -60,7 +60,7 @@ static void check_residency(struct kunit *test, struct xe= _bo *exported, =20 /* * Evict exporter. Evicting the exported bo will - * evict also the imported bo through the move_notify() functionality if + * evict also the imported bo through the invalidate_mappings() functiona= lity if * importer is on a different device. If they're on the same device, * the exporter and the importer should be the same bo. */ @@ -198,7 +198,7 @@ static void xe_test_dmabuf_import_same_driver(struct xe= _device *xe) =20 static const struct dma_buf_attach_ops nop2p_attach_ops =3D { .allow_peer2peer =3D false, - .move_notify =3D xe_dma_buf_move_notify + .invalidate_mappings =3D xe_dma_buf_move_notify }; =20 /* diff --git a/drivers/gpu/drm/xe/xe_dma_buf.c b/drivers/gpu/drm/xe/xe_dma_bu= f.c index 7c74a31d4486..1b9cd043e517 100644 --- a/drivers/gpu/drm/xe/xe_dma_buf.c +++ b/drivers/gpu/drm/xe/xe_dma_buf.c @@ -287,7 +287,7 @@ static void xe_dma_buf_move_notify(struct dma_buf_attac= hment *attach) =20 static const struct dma_buf_attach_ops xe_dma_buf_attach_ops =3D { .allow_peer2peer =3D true, - .move_notify =3D xe_dma_buf_move_notify + .invalidate_mappings =3D xe_dma_buf_move_notify }; =20 #if IS_ENABLED(CONFIG_DRM_XE_KUNIT_TEST) diff --git a/drivers/infiniband/core/umem_dmabuf.c b/drivers/infiniband/cor= e/umem_dmabuf.c index 0ec2e4120cc9..d77a739cfe7a 100644 --- a/drivers/infiniband/core/umem_dmabuf.c +++ b/drivers/infiniband/core/umem_dmabuf.c @@ -129,7 +129,7 @@ ib_umem_dmabuf_get_with_dma_device(struct ib_device *de= vice, if (check_add_overflow(offset, (unsigned long)size, &end)) return ret; =20 - if (unlikely(!ops || !ops->move_notify)) + if (unlikely(!ops || !ops->invalidate_mappings)) return ret; =20 dmabuf =3D dma_buf_get(fd); @@ -195,7 +195,7 @@ ib_umem_dmabuf_unsupported_move_notify(struct dma_buf_a= ttachment *attach) =20 static struct dma_buf_attach_ops ib_umem_dmabuf_attach_pinned_ops =3D { .allow_peer2peer =3D true, - .move_notify =3D ib_umem_dmabuf_unsupported_move_notify, + .invalidate_mappings =3D ib_umem_dmabuf_unsupported_move_notify, }; =20 struct ib_umem_dmabuf * diff --git a/drivers/infiniband/hw/mlx5/mr.c b/drivers/infiniband/hw/mlx5/m= r.c index 325fa04cbe8a..97099d3b1688 100644 --- a/drivers/infiniband/hw/mlx5/mr.c +++ b/drivers/infiniband/hw/mlx5/mr.c @@ -1620,7 +1620,7 @@ static void mlx5_ib_dmabuf_invalidate_cb(struct dma_b= uf_attachment *attach) =20 static struct dma_buf_attach_ops mlx5_ib_dmabuf_attach_ops =3D { .allow_peer2peer =3D 1, - .move_notify =3D mlx5_ib_dmabuf_invalidate_cb, + .invalidate_mappings =3D mlx5_ib_dmabuf_invalidate_cb, }; =20 static struct ib_mr * diff --git a/drivers/iommu/iommufd/pages.c b/drivers/iommu/iommufd/pages.c index dbe51ecb9a20..76f900fa1687 100644 --- a/drivers/iommu/iommufd/pages.c +++ b/drivers/iommu/iommufd/pages.c @@ -1451,7 +1451,7 @@ static void iopt_revoke_notify(struct dma_buf_attachm= ent *attach) =20 static struct dma_buf_attach_ops iopt_dmabuf_attach_revoke_ops =3D { .allow_peer2peer =3D true, - .move_notify =3D iopt_revoke_notify, + .invalidate_mappings =3D iopt_revoke_notify, }; =20 /* diff --git a/include/linux/dma-buf.h b/include/linux/dma-buf.h index 0bc492090237..1b397635c793 100644 --- a/include/linux/dma-buf.h +++ b/include/linux/dma-buf.h @@ -407,7 +407,7 @@ struct dma_buf { * through the device. * * - Dynamic importers should set fences for any access that they can't - * disable immediately from their &dma_buf_attach_ops.move_notify + * disable immediately from their &dma_buf_attach_ops.invalidate_mappin= gs * callback. * * IMPORTANT: @@ -458,7 +458,7 @@ struct dma_buf_attach_ops { bool allow_peer2peer; =20 /** - * @move_notify: [optional] notification that the DMA-buf is moving + * @invalidate_mappings: [optional] notification that the DMA-buf is movi= ng * * If this callback is provided the framework can avoid pinning the * backing store while mappings exists. @@ -475,7 +475,7 @@ struct dma_buf_attach_ops { * New mappings can be created after this callback returns, and will * point to the new location of the DMA-buf. */ - void (*move_notify)(struct dma_buf_attachment *attach); + void (*invalidate_mappings)(struct dma_buf_attachment *attach); }; =20 /** --=20 2.52.0 From nobody Sun Feb 8 17:55:11 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1964A43E9F7; Tue, 20 Jan 2026 14:07:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768918042; cv=none; b=BBHqB3fI3D/KiyrGw4IU8zJYELM7IPBcsYCY6AlTmLabXmTaUBC7SW6NQVe4MNKgDhBNYDxqZqBe9CJ6EYrUoDaMbdr8AD+dFRQHH50WlvIfY9cpQF00dJK8EouR6sGnUCrFF5QfbiUHW9sBOm6Q5z85YkqfW2razqcO1vRU4D0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768918042; c=relaxed/simple; bh=1hYHYQMvghzNsWmwvxu8DztgpWMwQVcDwD8L4qNzSFs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=NSBH4ltsCXKtOlm5JBnIQFqt46NiQpIFrK70Itd0YgKAhXhXhvNC9Ax6VsPtXfTGUjKRfWiK5olV4KEwOaUNX37pn6jevORjIcIQ3z3+FlLyQimif6T3zdjtXkJJ/Q58MM7gc2/vJ3wZutQaByUNrZg8XfOu5ogLW5fwwGNwLIc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=QRlTBMJh; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="QRlTBMJh" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0A9D2C16AAE; Tue, 20 Jan 2026 14:07:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1768918041; bh=1hYHYQMvghzNsWmwvxu8DztgpWMwQVcDwD8L4qNzSFs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=QRlTBMJhHmgjJfRLZFugcge3ItgdIDWL7IepDxcq9jS7Pmnp9SZe/HWs+cDKDZB+i nUuCzOMeJsQabH0oG1eBHIfmwy8tJG8zd24hjV2hNiliRYS6FxL7SYQPI7x1u1pNr5 8b6JRNtS+TuokQxelcA/64PVpwWACS1LR1/bVtpwCRop0qeh1af5mf3HH/L5MrOkuU bFvU+NmThWYFuWapDRNns9vD/Y9C7Je8c45M3BkGXWJDMuFNJOlIIEupIvm2wVMJL9 b8KmKjJBBFnQTnREVzTzXg4iSZjjRf/LJq3Mbcvh2ZOG6w0gdKBicov3TKvpb497a+ oevri4eLFs6HQ== From: Leon Romanovsky To: Sumit Semwal , =?utf-8?q?Christian_K=C3=B6nig?= , Alex Deucher , David Airlie , Simona Vetter , Gerd Hoffmann , Dmitry Osipenko , Gurchetan Singh , Chia-I Wu , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , Lucas De Marchi , =?utf-8?q?Thomas_Hellstr=C3=B6m?= , Rodrigo Vivi , Jason Gunthorpe , Leon Romanovsky , Kevin Tian , Joerg Roedel , Will Deacon , Robin Murphy , Felix Kuehling , Alex Williamson , Ankit Agrawal , Vivek Kasireddy Cc: linux-media@vger.kernel.org, dri-devel@lists.freedesktop.org, linaro-mm-sig@lists.linaro.org, linux-kernel@vger.kernel.org, amd-gfx@lists.freedesktop.org, virtualization@lists.linux.dev, intel-xe@lists.freedesktop.org, linux-rdma@vger.kernel.org, iommu@lists.linux.dev, kvm@vger.kernel.org Subject: [PATCH v3 2/7] dma-buf: Always build with DMABUF_MOVE_NOTIFY Date: Tue, 20 Jan 2026 16:07:02 +0200 Message-ID: <20260120-dmabuf-revoke-v3-2-b7e0b07b8214@nvidia.com> X-Mailer: git-send-email 2.52.0 In-Reply-To: <20260120-dmabuf-revoke-v3-0-b7e0b07b8214@nvidia.com> References: <20260120-dmabuf-revoke-v3-0-b7e0b07b8214@nvidia.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" X-Mailer: b4 0.15-dev-a6db3 Content-Transfer-Encoding: quoted-printable From: Leon Romanovsky DMABUF_MOVE_NOTIFY was introduced in 2018 and has been marked as experimental and disabled by default ever since. Six years later, all new importers implement this callback. It is therefore reasonable to drop CONFIG_DMABUF_MOVE_NOTIFY and always build DMABUF with support for it enabled. Suggested-by: Christian K=C3=B6nig Signed-off-by: Leon Romanovsky --- drivers/dma-buf/Kconfig | 12 ------------ drivers/dma-buf/dma-buf.c | 12 ++---------- drivers/gpu/drm/amd/amdgpu/amdgpu_dma_buf.c | 10 +++------- drivers/gpu/drm/amd/amdkfd/Kconfig | 2 +- drivers/gpu/drm/xe/tests/xe_dma_buf.c | 3 +-- drivers/gpu/drm/xe/xe_dma_buf.c | 12 ++++-------- 6 files changed, 11 insertions(+), 40 deletions(-) diff --git a/drivers/dma-buf/Kconfig b/drivers/dma-buf/Kconfig index b46eb8a552d7..84d5e9b24e20 100644 --- a/drivers/dma-buf/Kconfig +++ b/drivers/dma-buf/Kconfig @@ -40,18 +40,6 @@ config UDMABUF A driver to let userspace turn memfd regions into dma-bufs. Qemu can use this to create host dmabufs for guest framebuffers. =20 -config DMABUF_MOVE_NOTIFY - bool "Move notify between drivers (EXPERIMENTAL)" - default n - depends on DMA_SHARED_BUFFER - help - Don't pin buffers if the dynamic DMA-buf interface is available on - both the exporter as well as the importer. This fixes a security - problem where userspace is able to pin unrestricted amounts of memory - through DMA-buf. - This is marked experimental because we don't yet have a consistent - execution context and memory management between drivers. - config DMABUF_DEBUG bool "DMA-BUF debug checks" depends on DMA_SHARED_BUFFER diff --git a/drivers/dma-buf/dma-buf.c b/drivers/dma-buf/dma-buf.c index 59cc647bf40e..cd3b60ce4863 100644 --- a/drivers/dma-buf/dma-buf.c +++ b/drivers/dma-buf/dma-buf.c @@ -837,18 +837,10 @@ static void mangle_sg_table(struct sg_table *sg_table) =20 } =20 -static inline bool -dma_buf_attachment_is_dynamic(struct dma_buf_attachment *attach) -{ - return !!attach->importer_ops; -} - static bool dma_buf_pin_on_map(struct dma_buf_attachment *attach) { - return attach->dmabuf->ops->pin && - (!dma_buf_attachment_is_dynamic(attach) || - !IS_ENABLED(CONFIG_DMABUF_MOVE_NOTIFY)); + return attach->dmabuf->ops->pin && !attach->importer_ops; } =20 /** @@ -1124,7 +1116,7 @@ struct sg_table *dma_buf_map_attachment(struct dma_bu= f_attachment *attach, /* * Importers with static attachments don't wait for fences. */ - if (!dma_buf_attachment_is_dynamic(attach)) { + if (!attach->importer_ops) { ret =3D dma_resv_wait_timeout(attach->dmabuf->resv, DMA_RESV_USAGE_KERNEL, true, MAX_SCHEDULE_TIMEOUT); diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_dma_buf.c b/drivers/gpu/drm/= amd/amdgpu/amdgpu_dma_buf.c index 863454148b28..349215549e8f 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_dma_buf.c +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_dma_buf.c @@ -145,13 +145,9 @@ static int amdgpu_dma_buf_pin(struct dma_buf_attachmen= t *attach) * notifiers are disabled, only allow pinning in VRAM when move * notiers are enabled. */ - if (!IS_ENABLED(CONFIG_DMABUF_MOVE_NOTIFY)) { - domains &=3D ~AMDGPU_GEM_DOMAIN_VRAM; - } else { - list_for_each_entry(attach, &dmabuf->attachments, node) - if (!attach->peer2peer) - domains &=3D ~AMDGPU_GEM_DOMAIN_VRAM; - } + list_for_each_entry(attach, &dmabuf->attachments, node) + if (!attach->peer2peer) + domains &=3D ~AMDGPU_GEM_DOMAIN_VRAM; =20 if (domains & AMDGPU_GEM_DOMAIN_VRAM) bo->flags |=3D AMDGPU_GEM_CREATE_CPU_ACCESS_REQUIRED; diff --git a/drivers/gpu/drm/amd/amdkfd/Kconfig b/drivers/gpu/drm/amd/amdkf= d/Kconfig index 16e12c9913f9..a5d7467c2f34 100644 --- a/drivers/gpu/drm/amd/amdkfd/Kconfig +++ b/drivers/gpu/drm/amd/amdkfd/Kconfig @@ -27,7 +27,7 @@ config HSA_AMD_SVM =20 config HSA_AMD_P2P bool "HSA kernel driver support for peer-to-peer for AMD GPU devices" - depends on HSA_AMD && PCI_P2PDMA && DMABUF_MOVE_NOTIFY + depends on HSA_AMD && PCI_P2PDMA help Enable peer-to-peer (P2P) communication between AMD GPUs over the PCIe bus. This can improve performance of multi-GPU compute diff --git a/drivers/gpu/drm/xe/tests/xe_dma_buf.c b/drivers/gpu/drm/xe/tes= ts/xe_dma_buf.c index 1f2cca5c2f81..c107687ef3c0 100644 --- a/drivers/gpu/drm/xe/tests/xe_dma_buf.c +++ b/drivers/gpu/drm/xe/tests/xe_dma_buf.c @@ -22,8 +22,7 @@ static bool p2p_enabled(struct dma_buf_test_params *param= s) =20 static bool is_dynamic(struct dma_buf_test_params *params) { - return IS_ENABLED(CONFIG_DMABUF_MOVE_NOTIFY) && params->attach_ops && - params->attach_ops->invalidate_mappings; + return params->attach_ops && params->attach_ops->invalidate_mappings; } =20 static void check_residency(struct kunit *test, struct xe_bo *exported, diff --git a/drivers/gpu/drm/xe/xe_dma_buf.c b/drivers/gpu/drm/xe/xe_dma_bu= f.c index 1b9cd043e517..ea370cd373e9 100644 --- a/drivers/gpu/drm/xe/xe_dma_buf.c +++ b/drivers/gpu/drm/xe/xe_dma_buf.c @@ -56,14 +56,10 @@ static int xe_dma_buf_pin(struct dma_buf_attachment *at= tach) bool allow_vram =3D true; int ret; =20 - if (!IS_ENABLED(CONFIG_DMABUF_MOVE_NOTIFY)) { - allow_vram =3D false; - } else { - list_for_each_entry(attach, &dmabuf->attachments, node) { - if (!attach->peer2peer) { - allow_vram =3D false; - break; - } + list_for_each_entry(attach, &dmabuf->attachments, node) { + if (!attach->peer2peer) { + allow_vram =3D false; + break; } } =20 --=20 2.52.0 From nobody Sun Feb 8 17:55:11 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BB7C9439015; Tue, 20 Jan 2026 14:07:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768918045; cv=none; b=fTpw8bmTNYtgVBF8RHtlE7FHocA54mCUi3yQZDaLkBuqPe3ehTQuVVnTNtksr99xVjW0pAQjpYwujmcVovf4rzAe1X7BBEjQXcgW1pR+/BN1pFaq2iryxUc/TBkl1QFBLYvufHeDO2T+gQJrsyxm5SJGd90XsoI9Dn6JaCZrZnU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768918045; c=relaxed/simple; bh=3eb1V4Rv6TEPo/iUbHVsGnBY7mv0aXK8Ke6NEm2PaJk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=jqnFlA/XeqzI+OSCs8gwb2jp+Hz7bR9x43QJx6ehDGphiRcOYMmPKV/3jvqrTq7S1Be8QBUvOn+rRXHV69Xxf9kBFlILHASm8CeQJHzlIT4Cm2npePYU3CnhUnrDzSjL7DrfaGG/G6GM8aWxUspxVEuE7/udeCvFPMNHSMFmC8Y= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=HSnGk9XF; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="HSnGk9XF" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 81CDFC19423; Tue, 20 Jan 2026 14:07:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1768918045; bh=3eb1V4Rv6TEPo/iUbHVsGnBY7mv0aXK8Ke6NEm2PaJk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=HSnGk9XFDR4LcBjJZ3PdWo/nLxtHrZYRrbNJIbATZmIMl/oIgDp7Zv3+Iv2FgU217 XVf93XW9pO75mbYU7+mCrG3kSK0it+Br0MlfELbZ31oz+qTMUvDB5n3yGI2SnV3Qrp D1WvGs3G3WGDLykWT09F9nPjulEAfUuV/7wykEKRBV2yJ7E0cEX5M0sYZgxlnc8sNd /ouz/Bj0hGmYAAt2OyWdPAEJ9C/gT46X3HvhPjEKYLZSKETXF88S2ATjiB1BsX/IX8 3NXeM8d2pcUK4R9/jjKU8NFqyvNjGSef59Q10YMOdntmwc0NzsTIIUYhhfhlHlaozG g5RqxzB/E0aRw== From: Leon Romanovsky To: Sumit Semwal , =?utf-8?q?Christian_K=C3=B6nig?= , Alex Deucher , David Airlie , Simona Vetter , Gerd Hoffmann , Dmitry Osipenko , Gurchetan Singh , Chia-I Wu , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , Lucas De Marchi , =?utf-8?q?Thomas_Hellstr=C3=B6m?= , Rodrigo Vivi , Jason Gunthorpe , Leon Romanovsky , Kevin Tian , Joerg Roedel , Will Deacon , Robin Murphy , Felix Kuehling , Alex Williamson , Ankit Agrawal , Vivek Kasireddy Cc: linux-media@vger.kernel.org, dri-devel@lists.freedesktop.org, linaro-mm-sig@lists.linaro.org, linux-kernel@vger.kernel.org, amd-gfx@lists.freedesktop.org, virtualization@lists.linux.dev, intel-xe@lists.freedesktop.org, linux-rdma@vger.kernel.org, iommu@lists.linux.dev, kvm@vger.kernel.org Subject: [PATCH v3 3/7] dma-buf: Document RDMA non-ODP invalidate_mapping() special case Date: Tue, 20 Jan 2026 16:07:03 +0200 Message-ID: <20260120-dmabuf-revoke-v3-3-b7e0b07b8214@nvidia.com> X-Mailer: git-send-email 2.52.0 In-Reply-To: <20260120-dmabuf-revoke-v3-0-b7e0b07b8214@nvidia.com> References: <20260120-dmabuf-revoke-v3-0-b7e0b07b8214@nvidia.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" X-Mailer: b4 0.15-dev-a6db3 Content-Transfer-Encoding: quoted-printable From: Leon Romanovsky The .invalidate_mapping() callback is documented as optional, yet it effectively became mandatory whenever importer_ops were provided. This led to cases where RDMA non-ODP code had to supply an empty stub just to provide allow_peer2peer. Document this behavior by creating a dedicated export for the dma_buf_unsupported_invalidate_mappings() function. This function is intended solely for the RDMA non-ODP case and must not be used by any other dma-buf importer. This makes it possible to rely on a valid .invalidate_mappings() callback to determine whether an importer supports revocation. Signed-off-by: Leon Romanovsky --- drivers/dma-buf/dma-buf.c | 14 ++++++++++++++ drivers/infiniband/core/umem_dmabuf.c | 11 +---------- include/linux/dma-buf.h | 4 +++- 3 files changed, 18 insertions(+), 11 deletions(-) diff --git a/drivers/dma-buf/dma-buf.c b/drivers/dma-buf/dma-buf.c index cd3b60ce4863..c4fa35034b92 100644 --- a/drivers/dma-buf/dma-buf.c +++ b/drivers/dma-buf/dma-buf.c @@ -1238,6 +1238,20 @@ void dma_buf_unmap_attachment_unlocked(struct dma_bu= f_attachment *attach, } EXPORT_SYMBOL_NS_GPL(dma_buf_unmap_attachment_unlocked, "DMA_BUF"); =20 +/* + * This function shouldn't be used by anyone except RDMA non-ODP case. + * The reason to it is UAPI mistake where dma-buf was exported to the + * userspace without knowing that .invalidate_mappings() can be called + * for pinned memory too. + * + * This warning shouldn't be seen in real production scenario. + */ +void dma_buf_unsupported_invalidate_mappings(struct dma_buf_attachment *at= tach) +{ + pr_warn("Invalidate callback should not be called when memory is pinned\n= "); +} +EXPORT_SYMBOL_FOR_MODULES(dma_buf_unsupported_invalidate_mappings, "ib_uve= rbs"); + /** * dma_buf_move_notify - notify attachments that DMA-buf is moving * diff --git a/drivers/infiniband/core/umem_dmabuf.c b/drivers/infiniband/cor= e/umem_dmabuf.c index d77a739cfe7a..81442a887b48 100644 --- a/drivers/infiniband/core/umem_dmabuf.c +++ b/drivers/infiniband/core/umem_dmabuf.c @@ -184,18 +184,9 @@ struct ib_umem_dmabuf *ib_umem_dmabuf_get(struct ib_de= vice *device, } EXPORT_SYMBOL(ib_umem_dmabuf_get); =20 -static void -ib_umem_dmabuf_unsupported_move_notify(struct dma_buf_attachment *attach) -{ - struct ib_umem_dmabuf *umem_dmabuf =3D attach->importer_priv; - - ibdev_warn_ratelimited(umem_dmabuf->umem.ibdev, - "Invalidate callback should not be called when memory is pinned\= n"); -} - static struct dma_buf_attach_ops ib_umem_dmabuf_attach_pinned_ops =3D { .allow_peer2peer =3D true, - .invalidate_mappings =3D ib_umem_dmabuf_unsupported_move_notify, + .invalidate_mappings =3D dma_buf_unsupported_invalidate_mappings, }; =20 struct ib_umem_dmabuf * diff --git a/include/linux/dma-buf.h b/include/linux/dma-buf.h index 1b397635c793..7d7d0a4fb762 100644 --- a/include/linux/dma-buf.h +++ b/include/linux/dma-buf.h @@ -458,7 +458,7 @@ struct dma_buf_attach_ops { bool allow_peer2peer; =20 /** - * @invalidate_mappings: [optional] notification that the DMA-buf is movi= ng + * @invalidate_mappings: notification that the DMA-buf is moving * * If this callback is provided the framework can avoid pinning the * backing store while mappings exists. @@ -601,6 +601,8 @@ struct sg_table *dma_buf_map_attachment(struct dma_buf_= attachment *, void dma_buf_unmap_attachment(struct dma_buf_attachment *, struct sg_table= *, enum dma_data_direction); void dma_buf_move_notify(struct dma_buf *dma_buf); +void dma_buf_unsupported_invalidate_mappings(struct dma_buf_attachment *at= tach); + int dma_buf_begin_cpu_access(struct dma_buf *dma_buf, enum dma_data_direction dir); int dma_buf_end_cpu_access(struct dma_buf *dma_buf, --=20 2.52.0 From nobody Sun Feb 8 17:55:11 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4D2AD439015; Tue, 20 Jan 2026 14:07:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768918049; cv=none; b=ifW3Ma7PWnmJR7KXUlGe8Fty0Ap/K6Fz2HJFDBgeeVcQ0cQFzenrIkoXI8wKxIiK0cZ9NS2ey0L5+Duj9DmlJkYtJKwaPZIPkh+mPCbFk5v9USrx23rh/kuxrDWSbMkY5SkjnSF/bUdvbIudB+u+u5fkc/hyRFtuPOGja1t9yVc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768918049; c=relaxed/simple; bh=MryhAftyHxYTop+mnKinqTb8eFJW20BmygrDTfbPY2w=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=sYzjNqj4dXSOMfZ/U4f+nn5VN8uPuEpzrKtAXE48PtR1KITgZiZOCiWPPORllX9NSKiUhAM7cRjh1juFrNIBp2pKpeFWvuOB1gztIqzfMwbgyx3cfudA7OrL8xqe7FIcN41Rkn1I0Ie2B6CMvET67QG4usyVB6fqVbbwXLQVhHY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=HRchcWPp; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="HRchcWPp" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2DB10C16AAE; Tue, 20 Jan 2026 14:07:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1768918049; bh=MryhAftyHxYTop+mnKinqTb8eFJW20BmygrDTfbPY2w=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=HRchcWPpsUvcK+Crk3OAOK761eYKGCH0fgOBvesqeEQQlf1bYaTkU5/cAIoZz24Xg QZOa8k69UfgH0yHQAxr/k5AFdCcArO4JpyQS0ALF7IOK7+5MXk+zQaXz/gMMgMYxTE oN/OiCYRgZMn7+HHLVC8ZS7zvMFhxFJKTXEohcy6HZiZ6em6nCJZ4V8msli3NFxDPo ULsfYeHN5PJhqPiDXsOQsfLXaqDydvqEYPJGjBmI323H0aNfpgB/Gkg/XAf2FMSE0t NXBeQanufm7+6AtVifiTmQhurpZw8xuWsfKDlKQKi/x2zRXK6HWmQL9ZaTNupRUW8w BferpMeWKFc9A== From: Leon Romanovsky To: Sumit Semwal , =?utf-8?q?Christian_K=C3=B6nig?= , Alex Deucher , David Airlie , Simona Vetter , Gerd Hoffmann , Dmitry Osipenko , Gurchetan Singh , Chia-I Wu , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , Lucas De Marchi , =?utf-8?q?Thomas_Hellstr=C3=B6m?= , Rodrigo Vivi , Jason Gunthorpe , Leon Romanovsky , Kevin Tian , Joerg Roedel , Will Deacon , Robin Murphy , Felix Kuehling , Alex Williamson , Ankit Agrawal , Vivek Kasireddy Cc: linux-media@vger.kernel.org, dri-devel@lists.freedesktop.org, linaro-mm-sig@lists.linaro.org, linux-kernel@vger.kernel.org, amd-gfx@lists.freedesktop.org, virtualization@lists.linux.dev, intel-xe@lists.freedesktop.org, linux-rdma@vger.kernel.org, iommu@lists.linux.dev, kvm@vger.kernel.org Subject: [PATCH v3 4/7] dma-buf: Add check function for revoke semantics Date: Tue, 20 Jan 2026 16:07:04 +0200 Message-ID: <20260120-dmabuf-revoke-v3-4-b7e0b07b8214@nvidia.com> X-Mailer: git-send-email 2.52.0 In-Reply-To: <20260120-dmabuf-revoke-v3-0-b7e0b07b8214@nvidia.com> References: <20260120-dmabuf-revoke-v3-0-b7e0b07b8214@nvidia.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" X-Mailer: b4 0.15-dev-a6db3 Content-Transfer-Encoding: quoted-printable From: Leon Romanovsky A DMA-buf revoke mechanism that allows an exporter to explicitly invalidate ("kill") a shared buffer after it has been handed out to importers. Once revoked, all further CPU and device access is blocked, and importers consistently observe failure. This requires both importers and exporters to honor the revoke contract. For importers, this means implementing .invalidate_mappings(). For exporter= s, this means implementing the .pin() and/or .attach() callback, which check t= he dma=E2=80=91buf attachment for a valid revoke implementation. Signed-off-by: Leon Romanovsky --- drivers/dma-buf/dma-buf.c | 37 ++++++++++++++++++++++++++++++++++++- include/linux/dma-buf.h | 1 + 2 files changed, 37 insertions(+), 1 deletion(-) diff --git a/drivers/dma-buf/dma-buf.c b/drivers/dma-buf/dma-buf.c index c4fa35034b92..c048c822c3e9 100644 --- a/drivers/dma-buf/dma-buf.c +++ b/drivers/dma-buf/dma-buf.c @@ -1252,13 +1252,48 @@ void dma_buf_unsupported_invalidate_mappings(struct= dma_buf_attachment *attach) } EXPORT_SYMBOL_FOR_MODULES(dma_buf_unsupported_invalidate_mappings, "ib_uve= rbs"); =20 +/** + * dma_buf_attach_revocable - check if a DMA-buf importer implements + * revoke semantics. + * @attach: the DMA-buf attachment to check + * + * Returns true if the DMA-buf importer can handle invalidating it's mappi= ngs + * at any time, even after pinning a buffer. + */ +bool dma_buf_attach_revocable(struct dma_buf_attachment *attach) +{ + /* + * There is no need to check existence of .invalidate_mappings() as + * it always exists when importer_ops is set in dma_buf_dynamic_attach(). + */ + return attach->importer_ops && + (attach->importer_ops->invalidate_mappings !=3D + &dma_buf_unsupported_invalidate_mappings); +} +EXPORT_SYMBOL_NS_GPL(dma_buf_attach_revocable, "DMA_BUF"); + /** * dma_buf_move_notify - notify attachments that DMA-buf is moving * * @dmabuf: [in] buffer which is moving * * Informs all attachments that they need to destroy and recreate all their - * mappings. + * mappings. If the attachment is dynamic then the dynamic importer is exp= ected + * to invalidate any caches it has of the mapping result and perform a new + * mapping request before allowing HW to do any further DMA. + * + * If the attachment is pinned then this informs the pinned importer that + * the underlying mapping is no longer available. Pinned importers may take + * this is as a permanent revocation so exporters should not trigger it + * lightly. + * + * For legacy pinned importers that cannot support invalidation this is a = NOP. + * Drivers can call dma_buf_attach_revocable() to determine if the importer + * supports this. + * + * NOTE: The invalidation triggers asynchronous HW operation and the calle= rs + * need to wait for this operation to complete by calling + * to dma_resv_wait_timeout(). */ void dma_buf_move_notify(struct dma_buf *dmabuf) { diff --git a/include/linux/dma-buf.h b/include/linux/dma-buf.h index 7d7d0a4fb762..ac2ce1273b4c 100644 --- a/include/linux/dma-buf.h +++ b/include/linux/dma-buf.h @@ -602,6 +602,7 @@ void dma_buf_unmap_attachment(struct dma_buf_attachment= *, struct sg_table *, enum dma_data_direction); void dma_buf_move_notify(struct dma_buf *dma_buf); void dma_buf_unsupported_invalidate_mappings(struct dma_buf_attachment *at= tach); +bool dma_buf_attach_revocable(struct dma_buf_attachment *attach); =20 int dma_buf_begin_cpu_access(struct dma_buf *dma_buf, enum dma_data_direction dir); --=20 2.52.0 From nobody Sun Feb 8 17:55:11 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 06A6A449EDA; Tue, 20 Jan 2026 14:07:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768918061; cv=none; b=VgEwPiyBGbHYxeTHBHi40xTOsBJWQBOTNUGf/j2LtBABtscuAz3+0JupRgGbzfdf0pMG97KIaTIjgTRixZ4q7lOHfIBMPyWChdvSGU2w1ur5nm3IMm4vEmWNkzu5liPxqjbtyWDx1hMDn6xWhptL8ivO+NX5zZpxI7AOYFmehRY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768918061; c=relaxed/simple; bh=L6OTT3mPtqYVA8mPyQyKoyFwZdirdGqFu8l/X01cJfo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=KB/a1wZ7RU+BOSKIPGFEa1jG9LI4q2D7pYmygVn8GE8YoqXWStJ5DVoJJcYsYtMdCiDd/GMT/ng9O2K2V2DYrMGzZkjkRjnDP5e6zDWnSg0m9fzm57Fl1KDX99qz2bfz/lp6CTCBOV6gpXXGAKr1dVJIki+t4LWIwW3+H0d5v78= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=M3RmBw8O; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="M3RmBw8O" Received: by smtp.kernel.org (Postfix) with ESMTPSA id A481BC16AAE; Tue, 20 Jan 2026 14:07:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1768918060; bh=L6OTT3mPtqYVA8mPyQyKoyFwZdirdGqFu8l/X01cJfo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=M3RmBw8Oc4lRgNdb/8GwB0L3CvMNnEvnPKDMWTWvUfIVq6JI4nZJ6uIuLq/vhnaiQ ITyA88tLQNKl69RqtoPneRB3Z8JQ5mFdAcCfs2O4oLJbm1gsAjG6HHHpIRoGIUzCdd 5MiAcqiZRKbIFwfZBFd+4BAXxfbshgLgVNY6MBojSn78gFZwEKUcTk0qr5cEqlociP +CiKD2i78akTx548vLZI6+GvlBIfIwdQ7oVKd/NcxyCMHCnwgnsZU0V41p2KdNnT/3 I45GmWSMqRkJH/nVlz1o4avGTI4hjGoVJdHM5p7nTi3LKkMYl8G0FGFznibFGnL6B6 tisqgYNfrTwBQ== From: Leon Romanovsky To: Sumit Semwal , =?utf-8?q?Christian_K=C3=B6nig?= , Alex Deucher , David Airlie , Simona Vetter , Gerd Hoffmann , Dmitry Osipenko , Gurchetan Singh , Chia-I Wu , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , Lucas De Marchi , =?utf-8?q?Thomas_Hellstr=C3=B6m?= , Rodrigo Vivi , Jason Gunthorpe , Leon Romanovsky , Kevin Tian , Joerg Roedel , Will Deacon , Robin Murphy , Felix Kuehling , Alex Williamson , Ankit Agrawal , Vivek Kasireddy Cc: linux-media@vger.kernel.org, dri-devel@lists.freedesktop.org, linaro-mm-sig@lists.linaro.org, linux-kernel@vger.kernel.org, amd-gfx@lists.freedesktop.org, virtualization@lists.linux.dev, intel-xe@lists.freedesktop.org, linux-rdma@vger.kernel.org, iommu@lists.linux.dev, kvm@vger.kernel.org Subject: [PATCH v3 5/7] iommufd: Pin dma-buf importer for revoke semantics Date: Tue, 20 Jan 2026 16:07:05 +0200 Message-ID: <20260120-dmabuf-revoke-v3-5-b7e0b07b8214@nvidia.com> X-Mailer: git-send-email 2.52.0 In-Reply-To: <20260120-dmabuf-revoke-v3-0-b7e0b07b8214@nvidia.com> References: <20260120-dmabuf-revoke-v3-0-b7e0b07b8214@nvidia.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" X-Mailer: b4 0.15-dev-a6db3 Content-Transfer-Encoding: quoted-printable From: Leon Romanovsky IOMMUFD does not support page fault handling, and after a call to .invalidate_mappings() all mappings become invalid. Ensure that the IOMMUFD dma-buf importer is bound to a revoke=E2=80=91aware dma-buf exporter (for example, VFIO). Signed-off-by: Leon Romanovsky Acked-by: Christian K=C3=B6nig --- drivers/iommu/iommufd/pages.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/drivers/iommu/iommufd/pages.c b/drivers/iommu/iommufd/pages.c index 76f900fa1687..a5eb2bc4ef48 100644 --- a/drivers/iommu/iommufd/pages.c +++ b/drivers/iommu/iommufd/pages.c @@ -1501,16 +1501,22 @@ static int iopt_map_dmabuf(struct iommufd_ctx *ictx= , struct iopt_pages *pages, mutex_unlock(&pages->mutex); } =20 - rc =3D sym_vfio_pci_dma_buf_iommufd_map(attach, &pages->dmabuf.phys); + rc =3D dma_buf_pin(attach); 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; =20 +err_unpin: + dma_buf_unpin(attach); err_detach: dma_resv_unlock(dmabuf->resv); dma_buf_detach(dmabuf, attach); @@ -1656,6 +1662,7 @@ void iopt_release_pages(struct kref *kref) if (iopt_is_dmabuf(pages) && pages->dmabuf.attach) { struct dma_buf *dmabuf =3D pages->dmabuf.attach->dmabuf; =20 + dma_buf_unpin(pages->dmabuf.attach); dma_buf_detach(dmabuf, pages->dmabuf.attach); dma_buf_put(dmabuf); WARN_ON(!list_empty(&pages->dmabuf.tracker)); --=20 2.52.0 From nobody Sun Feb 8 17:55:11 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DED9E449EDA; Tue, 20 Jan 2026 14:07:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768918057; cv=none; b=RduSmPULgCt1Kz1jVNjVpYBRBkYk0FjEcZEnsAMJB/HPATD1R9F4GrCFjs8oJP/rFxwzlUO2JCVrdwnCuT7b/GAi48LYp6A+tTAKuRhJ3BPDgdi9f8QSz148tjmcpehi340ySyh+3h5AF0bAvGhE+UuhqAAnoeFtk7AfghH72qM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768918057; c=relaxed/simple; bh=bf1696+c5PaSfpBeHHGzA+vmhqIVB4390cXN7pOou2E=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=Y7sxCMDG8IpheVII0D/4t+R0oXHiQknz/tJH+FmeWqrSStUW46Zy5GB8C3KN7GlYmADxzNHRMhyXgRbhdKrnyAjq6OJluwyVywgf2PjQoTGuVVb3rQHj2zcKbGkKRO666oOPd0OWSas0dNbfFfCJfGClW5RpckGQkqUht5wdVGo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=NBjWhUFV; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="NBjWhUFV" Received: by smtp.kernel.org (Postfix) with ESMTPSA id B29C7C2BC86; Tue, 20 Jan 2026 14:07:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1768918056; bh=bf1696+c5PaSfpBeHHGzA+vmhqIVB4390cXN7pOou2E=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=NBjWhUFVYnRzWBwslbwnf3YkcH1nikmzNYEw/PthA0UmL0zyOrClkJko7UTwOtT8v +4VBltLl7uM7PsMb7uiam/Xlx8gM8HDQ0Obb2wlKT4rWiUMa43+tbff3bXupMyeJdx wDxL36aBPCKbdDA4Qb32vtAkYyS48v4pyulCvKBVUiIvLy2k5uZ24Vztos9slrw8H0 iSkU4nGBDZZA9AsTpBEVBFMSylMfN1Vu4UliXAOwjpA735qtqBFEb1JOWHBOkDK9cq +5TQCt8uFqHSC+68xraxCpD7BjZyd+Vwtdp3IkygP2CS0ghFagzaiIted2cqXXfZnB 4HpjhwEhU/B4Q== From: Leon Romanovsky To: Sumit Semwal , =?utf-8?q?Christian_K=C3=B6nig?= , Alex Deucher , David Airlie , Simona Vetter , Gerd Hoffmann , Dmitry Osipenko , Gurchetan Singh , Chia-I Wu , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , Lucas De Marchi , =?utf-8?q?Thomas_Hellstr=C3=B6m?= , Rodrigo Vivi , Jason Gunthorpe , Leon Romanovsky , Kevin Tian , Joerg Roedel , Will Deacon , Robin Murphy , Felix Kuehling , Alex Williamson , Ankit Agrawal , Vivek Kasireddy Cc: linux-media@vger.kernel.org, dri-devel@lists.freedesktop.org, linaro-mm-sig@lists.linaro.org, linux-kernel@vger.kernel.org, amd-gfx@lists.freedesktop.org, virtualization@lists.linux.dev, intel-xe@lists.freedesktop.org, linux-rdma@vger.kernel.org, iommu@lists.linux.dev, kvm@vger.kernel.org Subject: [PATCH v3 6/7] vfio: Wait for dma-buf invalidation to complete Date: Tue, 20 Jan 2026 16:07:06 +0200 Message-ID: <20260120-dmabuf-revoke-v3-6-b7e0b07b8214@nvidia.com> X-Mailer: git-send-email 2.52.0 In-Reply-To: <20260120-dmabuf-revoke-v3-0-b7e0b07b8214@nvidia.com> References: <20260120-dmabuf-revoke-v3-0-b7e0b07b8214@nvidia.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" X-Mailer: b4 0.15-dev-a6db3 Content-Transfer-Encoding: quoted-printable From: Leon Romanovsky dma-buf invalidation is performed asynchronously by hardware, so VFIO must wait until all affected objects have been fully invalidated. Fixes: 5d74781ebc86 ("vfio/pci: Add dma-buf export support for MMIO regions= ") Signed-off-by: Leon Romanovsky Reviewed-by: Christian K=C3=B6nig --- drivers/vfio/pci/vfio_pci_dmabuf.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/drivers/vfio/pci/vfio_pci_dmabuf.c b/drivers/vfio/pci/vfio_pci= _dmabuf.c index d4d0f7d08c53..33bc6a1909dd 100644 --- a/drivers/vfio/pci/vfio_pci_dmabuf.c +++ b/drivers/vfio/pci/vfio_pci_dmabuf.c @@ -321,6 +321,9 @@ void vfio_pci_dma_buf_move(struct vfio_pci_core_device = *vdev, bool revoked) dma_resv_lock(priv->dmabuf->resv, NULL); priv->revoked =3D revoked; dma_buf_move_notify(priv->dmabuf); + dma_resv_wait_timeout(priv->dmabuf->resv, + DMA_RESV_USAGE_KERNEL, false, + MAX_SCHEDULE_TIMEOUT); dma_resv_unlock(priv->dmabuf->resv); } fput(priv->dmabuf->file); @@ -342,6 +345,8 @@ void vfio_pci_dma_buf_cleanup(struct vfio_pci_core_devi= ce *vdev) priv->vdev =3D NULL; priv->revoked =3D true; dma_buf_move_notify(priv->dmabuf); + dma_resv_wait_timeout(priv->dmabuf->resv, DMA_RESV_USAGE_KERNEL, + false, MAX_SCHEDULE_TIMEOUT); dma_resv_unlock(priv->dmabuf->resv); vfio_device_put_registration(&vdev->vdev); fput(priv->dmabuf->file); --=20 2.52.0 From nobody Sun Feb 8 17:55:11 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B106344BC8F; Tue, 20 Jan 2026 14:07:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768918064; cv=none; b=Gv5P1wgIT73jG2ny/lW5O+4cuGnZVmejezEYP/ph9oQbG4eV4Pbs21ULU4t1zNSwccQhuaAGX2IwRA+fNq8oBYJTySY85mV46hPLLtJAW8j7yYDbGpgDTSWApdbM//65rS/nzuJlze1O0sMtMGpNGS5kWCpNMu2PeUqAI6hFhQI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768918064; c=relaxed/simple; bh=+j0ekknPQd/d3gRAxiqnNNnfw0hqFAwwAjsZYhI192Y=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=n9IuiPqazEo4QYwDyoPvwMdwEs0KDvUm54u6F38pHnZ4aiIO/PU/VvDeM9NzIz3HUDAx4qw+MBWDG+FsYmeP9ryuFH/Uay7Uf3FWD2JTRVX8VdF6IZMRYISxjCnaaxYrXFTZK8++K81//XqUreY/NEplZulDCXdyE80ATrUVsa8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=ijj/wO77; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="ijj/wO77" Received: by smtp.kernel.org (Postfix) with ESMTPSA id A92D6C16AAE; Tue, 20 Jan 2026 14:07:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1768918064; bh=+j0ekknPQd/d3gRAxiqnNNnfw0hqFAwwAjsZYhI192Y=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ijj/wO771lycS6FKxtpygkeK/BYUHKt2nUSEqMQc/fe3SpJqqJcZ/BWCkpIQHgiev S+Mf1rPln8yu+F+l0oxZG17ZYhJVhUmOOaXGRiQiIBKGtLNc0IgMJWG2CRJYDmkieP 5a/VPKZauZJfX0w5M94s+0B+uQ1I4TbxB1ftUo/dLav7fV9nfxwwD7OdKnSh9ZF6iI /6dB5AHN3tBpnq0H+i2vDN0zwB0+7FapFUTpuAq/16it37Dv+DIWjBTSnV+vXDMZEJ wa4KiwHpfHeh/NIPj1cnYuRyh73tj+UYbl1afb2guZsXGQRwLqiccEkTVLl9YVBg3w 6Da43ktVUa1LQ== From: Leon Romanovsky To: Sumit Semwal , =?utf-8?q?Christian_K=C3=B6nig?= , Alex Deucher , David Airlie , Simona Vetter , Gerd Hoffmann , Dmitry Osipenko , Gurchetan Singh , Chia-I Wu , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , Lucas De Marchi , =?utf-8?q?Thomas_Hellstr=C3=B6m?= , Rodrigo Vivi , Jason Gunthorpe , Leon Romanovsky , Kevin Tian , Joerg Roedel , Will Deacon , Robin Murphy , Felix Kuehling , Alex Williamson , Ankit Agrawal , Vivek Kasireddy Cc: linux-media@vger.kernel.org, dri-devel@lists.freedesktop.org, linaro-mm-sig@lists.linaro.org, linux-kernel@vger.kernel.org, amd-gfx@lists.freedesktop.org, virtualization@lists.linux.dev, intel-xe@lists.freedesktop.org, linux-rdma@vger.kernel.org, iommu@lists.linux.dev, kvm@vger.kernel.org Subject: [PATCH v3 7/7] vfio: Validate dma-buf revocation semantics Date: Tue, 20 Jan 2026 16:07:07 +0200 Message-ID: <20260120-dmabuf-revoke-v3-7-b7e0b07b8214@nvidia.com> X-Mailer: git-send-email 2.52.0 In-Reply-To: <20260120-dmabuf-revoke-v3-0-b7e0b07b8214@nvidia.com> References: <20260120-dmabuf-revoke-v3-0-b7e0b07b8214@nvidia.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" X-Mailer: b4 0.15-dev-a6db3 Content-Transfer-Encoding: quoted-printable From: Leon Romanovsky Use the new dma_buf_attach_revocable() helper to restrict attachments to importers that support mapping invalidation. Signed-off-by: Leon Romanovsky --- drivers/vfio/pci/vfio_pci_dmabuf.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/drivers/vfio/pci/vfio_pci_dmabuf.c b/drivers/vfio/pci/vfio_pci= _dmabuf.c index 33bc6a1909dd..0c7782a51912 100644 --- a/drivers/vfio/pci/vfio_pci_dmabuf.c +++ b/drivers/vfio/pci/vfio_pci_dmabuf.c @@ -31,6 +31,9 @@ static int vfio_pci_dma_buf_attach(struct dma_buf *dmabuf, if (priv->revoked) return -ENODEV; =20 + if (!dma_buf_attach_revocable(attachment)) + return -EOPNOTSUPP; + return 0; } =20 --=20 2.52.0