Instead of enforcing that a dma-buf-io ctx is used only with the registered file, allow sharing using tags. Fixes: 62e4bf5b25d44 ("io_uring/rsrc: add dmabuf backed registered buffers") Signed-off-by: Pavel Begunkov --- 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 6f1d21c0f558..f25749f7da22 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 a97412ebbb3f..9bd7c8c64397 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; req->flags |= REQ_F_DMABUF; iov_iter_dmabuf_map(iter, ddir, NULL, offset, len); -- 2.54.0