[RFC PATCH v3 05/13] io_uring/dma-buf: switch to tag file filtering
From: Nitesh Shetty
Date: Tue Dec 01 2026 - 11:54:49 EST
From: Pavel Begunkov <asml.silence@xxxxxxxxx>
Instead of enforcing that a dma-buf-io context is used only with the
registered file, allow sharing it between files with the same tag.
Drop the reference to that file, so it can be closed while the buffer
stays registered.
Signed-off-by: Pavel Begunkov <asml.silence@xxxxxxxxx>
Signed-off-by: Anuj Gupta <anuj20.g@xxxxxxxxxxx>
Signed-off-by: Nitesh Shetty <nj.shetty@xxxxxxxxxxx>
---
io_uring/dma-buf.c | 3 +--
io_uring/dma-buf.h | 6 ++----
2 files changed, 3 insertions(+), 6 deletions(-)
diff --git a/io_uring/dma-buf.c b/io_uring/dma-buf.c
index fd9b8769818a..fe735a8773b7 100644
--- a/io_uring/dma-buf.c
+++ b/io_uring/dma-buf.c
@@ -4,7 +4,6 @@ static inline void io_release_dmabuf(void *priv)
{
struct io_buf_dma *bd = io_priv_to_dmabuf(priv);
- fput(bd->target_file);
dma_buf_io_ctx_release(bd->ctx);
kfree(bd);
}
@@ -52,13 +51,13 @@ int __io_register_dmabuf(struct io_ring_ctx *ctx,
if (ret)
goto err;
- bd->target_file = target_file;
imu->len = dmabuf->size;
imu->release = io_release_dmabuf;
imu->priv = bd;
imu->flags = IO_REGBUF_F_DMABUF;
imu->dir = IO_BUF_DEST | IO_BUF_SOURCE;
dma_buf_put(dmabuf);
+ fput(target_file);
return 0;
err:
kfree(bd);
diff --git a/io_uring/dma-buf.h b/io_uring/dma-buf.h
index 051483991090..eb4ce2348be2 100644
--- a/io_uring/dma-buf.h
+++ b/io_uring/dma-buf.h
@@ -9,7 +9,6 @@
struct io_buf_dma {
struct dma_buf_io_ctx *ctx;
- struct file *target_file;
};
static inline struct io_buf_dma *io_priv_to_dmabuf(void *data)
@@ -63,11 +62,10 @@ static inline int io_import_dmabuf_map(struct io_kiocb *req,
struct io_mapped_ubuf *imu,
size_t len, size_t offset)
{
- struct io_buf_dma *bd = io_buf_to_dmabuf(imu);
-
if (!IS_ENABLED(CONFIG_DMA_SHARED_BUFFER))
return -EOPNOTSUPP;
- if (req->file != bd->target_file)
+ if (unlikely(!dma_buf_io_file_compatible(io_buf_to_dmabuf(imu)->ctx,
+ req->file)))
return -EBADF;
io_req_set_flags(req, REQ_F_DMABUF);
iov_iter_dmabuf_map(iter, ddir, NULL, offset, len);
--
2.47.3