]> git.ipfire.org Git - thirdparty/kernel/linux.git/commit
dma-buf: Add dma_buf_attach_revocable()
authorLeon Romanovsky <leonro@nvidia.com>
Sat, 31 Jan 2026 05:34:16 +0000 (07:34 +0200)
committerChristian König <christian.koenig@amd.com>
Mon, 23 Feb 2026 18:51:40 +0000 (19:51 +0100)
commitbe6d4c9e9d714ebbf358be41332726a0f94b9ffa
tree825268be3e530d145672b1daa0744af48c7e0ac7
parent575157b1b5fcfcdd0f9c42d635dcf8219f8c86dc
dma-buf: Add dma_buf_attach_revocable()

Some exporters need a flow to synchronously revoke access to the DMA-buf
by importers. Once revoke is completed the importer is not permitted to
touch the memory otherwise they may get IOMMU faults, AERs, or worse.

DMA-buf today defines a revoke flow, for both pinned and dynamic
importers, which is broadly:

dma_resv_lock(dmabuf->resv, NULL);
// Prevent new mappings from being established
priv->revoked = true;

// Tell all importers to eventually unmap
dma_buf_invalidate_mappings(dmabuf);

// Wait for any inprogress fences on the old mapping
dma_resv_wait_timeout(dmabuf->resv,
      DMA_RESV_USAGE_BOOKKEEP, false,
      MAX_SCHEDULE_TIMEOUT);
dma_resv_unlock(dmabuf->resv, NULL);

// Wait for all importers to complete unmap
wait_for_completion(&priv->unmapped_comp);

This works well, and an importer that continues to access the DMA-buf
after unmapping it is very buggy.

However, the final wait for unmap is effectively unbounded. Several
importers do not support invalidate_mappings() at all and won't unmap
until userspace triggers it.

This unbounded wait is not suitable for exporters like VFIO and RDMA tha
need to issue revoke as part of their normal operations.

Add dma_buf_attach_revocable() to allow exporters to determine the
difference between importers that can complete the above in bounded time,
and those that can't. It can be called inside the exporter's attach op to
reject incompatible importers.

Document these details about how dma_buf_invalidate_mappings() works and
what the required sequence is to achieve a full revocation.

Signed-off-by: Leon Romanovsky <leonro@nvidia.com>
Reviewed-by: Christian König <christian.koenig@amd.com>
Signed-off-by: Christian König <christian.koenig@amd.com>
Link: https://lore.kernel.org/r/20260131-dmabuf-revoke-v7-6-463d956bd527@nvidia.com
drivers/dma-buf/dma-buf.c
include/linux/dma-buf.h