[PATCH v5 4/4] nvme: support dma-buf registered buffers for passthrough
Anuj Gupta
anuj20.g at samsung.com
Wed Dec 2 00:51:06 PST 2026
Allow registering a dma-buf against an NVMe namespace character device
and using it as the data buffer of fixed uring_cmd passthrough I/O,
by importing fixed buffers with io_uring_cmd_import_fixed_dmabuf().
Complete through io_uring_cmd_hw_done(), so the dma-buf map is released
at hardware completion.
Signed-off-by: Anuj Gupta <anuj20.g at samsung.com>
Reviewed-by: Christoph Hellwig <hch at lst.de>
Reviewed-by: Pavel Begunkov <asml.silence at gmail.com>
---
drivers/nvme/host/core.c | 16 ++++++++++++++++
drivers/nvme/host/ioctl.c | 4 ++--
2 files changed, 18 insertions(+), 2 deletions(-)
diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c
index f43582e5f6c4..f12cea7cbc8a 100644
--- a/drivers/nvme/host/core.c
+++ b/drivers/nvme/host/core.c
@@ -8,6 +8,7 @@
#include <linux/blkdev.h>
#include <linux/blk-mq.h>
#include <linux/blk-integrity.h>
+#include <linux/dma-buf-io.h>
#include <linux/compat.h>
#include <linux/delay.h>
#include <linux/errno.h>
@@ -4028,6 +4029,20 @@ static int nvme_ns_chr_release(struct inode *inode, struct file *file)
return 0;
}
+static int nvme_ns_chr_init_dma_buf_io_ctx(struct file *file,
+ struct dma_buf_io_ctx *ctx)
+{
+ struct nvme_ns *ns =
+ container_of(file_inode(file)->i_cdev, struct nvme_ns, cdev);
+ struct nvme_ctrl *ctrl = ns->ctrl;
+
+ if (ctx->dmabuf->size > UINT_MAX)
+ return -EINVAL;
+ if (!ctrl->ops->init_dma_buf_io_ctx)
+ return -EOPNOTSUPP;
+ return ctrl->ops->init_dma_buf_io_ctx(ctrl, ctx);
+}
+
static const struct file_operations nvme_ns_chr_fops = {
.owner = THIS_MODULE,
.open = nvme_ns_chr_open,
@@ -4036,6 +4051,7 @@ static const struct file_operations nvme_ns_chr_fops = {
.compat_ioctl = compat_ptr_ioctl,
.uring_cmd = nvme_ns_chr_uring_cmd,
.uring_cmd_iopoll = nvme_ns_chr_uring_cmd_iopoll,
+ .init_dma_buf_io_ctx = nvme_ns_chr_init_dma_buf_io_ctx,
};
static void nvme_add_ns_cdev(struct nvme_ns *ns)
diff --git a/drivers/nvme/host/ioctl.c b/drivers/nvme/host/ioctl.c
index a87c9ca9d06c..ffb24b34ce1e 100644
--- a/drivers/nvme/host/ioctl.c
+++ b/drivers/nvme/host/ioctl.c
@@ -472,7 +472,7 @@ static enum rq_end_io_ret nvme_uring_cmd_end_io(struct request *req,
blk_rq_unmap_user(pdu->bio);
__io_uring_cmd_done(ioucmd, 0);
} else {
- io_uring_cmd_do_in_task_lazy(ioucmd, nvme_uring_task_cb);
+ io_uring_cmd_hw_done(ioucmd, nvme_uring_task_cb);
}
return RQ_END_IO_FREE;
}
@@ -532,7 +532,7 @@ static int nvme_uring_cmd_io(struct nvme_ctrl *ctrl, struct nvme_ns *ns,
u64_to_user_ptr(d.addr), d.data_len,
ddir, &iter, issue_flags);
else
- ret = io_uring_cmd_import_fixed(d.addr, d.data_len,
+ ret = io_uring_cmd_import_fixed_dmabuf(d.addr, d.data_len,
ddir, &iter, ioucmd, issue_flags);
if (ret < 0)
return ret;
--
2.25.1
More information about the Linux-nvme
mailing list