From: Anuj Gupta <anuj1072538@gmail.com>
To: axboe@kernel.dk, asml.silence@gmail.com, kbusch@kernel.org,
hch@lst.de, sagi@grimberg.me,
James.Bottomley@HansenPartnership.com, mkp@kernel.org,
bernd@bsbernd.com, joannelkoong@gmail.com, miklos@szeredi.hu
Cc: io-uring@vger.kernel.org, linux-nvme@lists.infradead.org,
linux-block@vger.kernel.org, linux-scsi@vger.kernel.org,
fuse-devel@lists.linux.dev, joshi.k@samsung.com,
anuj20.g@samsung.com
Subject: [PATCH v2 5/5] nvme: support dma-buf registered buffers for passthrough
Date: Thu, 22 Oct 2026 20:14:56 +0530 [thread overview]
Message-ID: <20261022144501.2478417-6-anuj1072538@gmail.com> (raw)
In-Reply-To: <20261022144501.2478417-1-anuj1072538@gmail.com>
From: Anuj Gupta <anuj20.g@samsung.com>
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.
Complete through io_uring_cmd_hw_done(), so the dma-buf map is released
at hardware completion.
Signed-off-by: Anuj Gupta <anuj20.g@samsung.com>
---
drivers/nvme/host/core.c | 16 ++++++++++++++++
drivers/nvme/host/ioctl.c | 5 +++--
2 files changed, 19 insertions(+), 2 deletions(-)
diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c
index d81462e864a4..6157ff839929 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>
@@ -3982,6 +3983,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 -EINVAL;
+ 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,
@@ -3990,6 +4005,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 612d3009dd29..645446acc10a 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;
}
@@ -533,7 +533,8 @@ static int nvme_uring_cmd_io(struct nvme_ctrl *ctrl, struct nvme_ns *ns,
ddir, &iter, issue_flags);
else
ret = io_uring_cmd_import_fixed(d.addr, d.data_len,
- ddir, &iter, ioucmd, issue_flags, 0);
+ ddir, &iter, ioucmd, issue_flags,
+ IO_URING_CMD_IMPORT_DMABUF);
if (ret < 0)
return ret;
--
2.43.0
next prev parent reply other threads:[~2026-10-22 14:46 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-22 14:44 [PATCH v2 0/5] dma-buf backed NVMe passthrough I/O Anuj Gupta
2026-10-22 14:44 ` [PATCH v2 1/5] io_uring/rsrc: pass import flags to io_import_reg_buf() Anuj Gupta
2026-10-22 14:44 ` [PATCH v2 2/5] io_uring/uring_cmd: add import flags to io_uring_cmd_import_fixed() Anuj Gupta
2026-10-22 14:44 ` [PATCH v2 3/5] io_uring/uring_cmd: support dma-buf registered buffers Anuj Gupta
2026-10-22 14:44 ` [PATCH v2 4/5] block: map dma-buf iterators in blk_rq_map_user_iov() Anuj Gupta
2026-10-28 16:30 ` Christoph Hellwig
2026-10-22 14:44 ` Anuj Gupta [this message]
2026-10-28 16:31 ` [PATCH v2 5/5] nvme: support dma-buf registered buffers for passthrough Christoph Hellwig
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261022144501.2478417-6-anuj1072538@gmail.com \
--to=anuj1072538@gmail.com \
--cc=James.Bottomley@HansenPartnership.com \
--cc=anuj20.g@samsung.com \
--cc=asml.silence@gmail.com \
--cc=axboe@kernel.dk \
--cc=bernd@bsbernd.com \
--cc=fuse-devel@lists.linux.dev \
--cc=hch@lst.de \
--cc=io-uring@vger.kernel.org \
--cc=joannelkoong@gmail.com \
--cc=joshi.k@samsung.com \
--cc=kbusch@kernel.org \
--cc=linux-block@vger.kernel.org \
--cc=linux-nvme@lists.infradead.org \
--cc=linux-scsi@vger.kernel.org \
--cc=miklos@szeredi.hu \
--cc=mkp@kernel.org \
--cc=sagi@grimberg.me \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox