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 3/5] io_uring/uring_cmd: support dma-buf registered buffers
Date: Thu, 22 Oct 2026 20:14:54 +0530 [thread overview]
Message-ID: <20261022144501.2478417-4-anuj1072538@gmail.com> (raw)
In-Reply-To: <20261022144501.2478417-1-anuj1072538@gmail.com>
From: Anuj Gupta <anuj20.g@samsung.com>
Let callers of io_uring_cmd_import_fixed() opt in to dma-buf registered
buffers with IO_URING_CMD_IMPORT_DMABUF, and attach the current map on
import.
The map has to be dropped at hardware completion rather than from
task_work. Add io_uring_cmd_hw_done() for drivers to call from end_io,
which drops the map and queues task_work, and warn if task_work is
queued with a map still attached.
Signed-off-by: Anuj Gupta <anuj20.g@samsung.com>
---
include/linux/io_uring/cmd.h | 9 +++++++++
io_uring/uring_cmd.c | 28 ++++++++++++++++++++++++++--
2 files changed, 35 insertions(+), 2 deletions(-)
diff --git a/include/linux/io_uring/cmd.h b/include/linux/io_uring/cmd.h
index 23fb66a1e2c1..d4e17c2f59fd 100644
--- a/include/linux/io_uring/cmd.h
+++ b/include/linux/io_uring/cmd.h
@@ -12,6 +12,9 @@
/* io_uring_cmd is being issued again */
#define IORING_URING_CMD_REISSUE (1U << 31)
+/* io_uring_cmd_import_fixed() flags */
+#define IO_URING_CMD_IMPORT_DMABUF (1U << 0)
+
struct io_uring_cmd {
struct file *file;
const struct io_uring_sqe *sqe;
@@ -86,6 +89,8 @@ void __io_uring_cmd_done(struct io_uring_cmd *, unsigned issue_flags);
void __io_uring_cmd_do_in_task(struct io_uring_cmd *ioucmd,
io_req_tw_func_t task_work_cb,
unsigned flags);
+void io_uring_cmd_hw_done(struct io_uring_cmd *ioucmd,
+ io_req_tw_func_t task_work_cb);
/*
* Note: the caller should never hard code @issue_flags and only use the
@@ -145,6 +150,10 @@ static inline void __io_uring_cmd_do_in_task(struct io_uring_cmd *ioucmd,
io_req_tw_func_t task_work_cb, unsigned flags)
{
}
+static inline void io_uring_cmd_hw_done(struct io_uring_cmd *ioucmd,
+ io_req_tw_func_t task_work_cb)
+{
+}
static inline void io_uring_cmd_mark_cancelable(struct io_uring_cmd *cmd,
unsigned int issue_flags)
{
diff --git a/io_uring/uring_cmd.c b/io_uring/uring_cmd.c
index c2bc9dd242ec..c89f154190b1 100644
--- a/io_uring/uring_cmd.c
+++ b/io_uring/uring_cmd.c
@@ -10,6 +10,7 @@
#include "io_uring.h"
#include "alloc_cache.h"
+#include "dma-buf.h"
#include "rsrc.h"
#include "kbuf.h"
#include "uring_cmd.h"
@@ -28,6 +29,7 @@ static void io_req_uring_cleanup(struct io_kiocb *req, unsigned int issue_flags)
struct io_uring_cmd *ioucmd = io_kiocb_to_cmd(req, struct io_uring_cmd);
struct io_async_cmd *ac = req->async_data;
+ io_detach_dmabuf_map(req);
if (issue_flags & IO_URING_F_UNLOCKED)
return;
@@ -132,12 +134,26 @@ void __io_uring_cmd_do_in_task(struct io_uring_cmd *ioucmd,
if (WARN_ON_ONCE(req->flags & REQ_F_APOLL_MULTISHOT))
return;
+ /* the dma-buf map must be dropped first, see io_uring_cmd_hw_done() */
+ WARN_ON_ONCE(req->dmabuf_map);
req->io_task_work.func = task_work_cb;
__io_req_task_work_add(req, flags);
}
EXPORT_SYMBOL_GPL(__io_uring_cmd_do_in_task);
+/*
+ * Queue completion in task context after dropping references that must be
+ * released at hardware completion rather than from task_work.
+ */
+void io_uring_cmd_hw_done(struct io_uring_cmd *ioucmd,
+ io_req_tw_func_t task_work_cb)
+{
+ io_detach_dmabuf_map(cmd_to_io_kiocb(ioucmd));
+ __io_uring_cmd_do_in_task(ioucmd, task_work_cb, IOU_F_TWQ_LAZY_WAKE);
+}
+EXPORT_SYMBOL_GPL(io_uring_cmd_hw_done);
+
/*
* Called by consumers of io_uring_cmd, if they originally returned
* -EIOCBQUEUED upon receiving the command.
@@ -257,6 +273,7 @@ int io_uring_cmd(struct io_kiocb *req, unsigned int issue_flags)
ret = file->f_op->uring_cmd(ioucmd, issue_flags);
if (ret == -EAGAIN) {
+ io_detach_dmabuf_map(req);
ioucmd->flags |= IORING_URING_CMD_REISSUE;
return ret;
}
@@ -276,13 +293,20 @@ int io_uring_cmd_import_fixed(u64 ubuf, unsigned long len, int rw,
unsigned int import_flags)
{
struct io_kiocb *req = cmd_to_io_kiocb(ioucmd);
+ unsigned int flags = 0;
+ int ret;
if (WARN_ON_ONCE(!(ioucmd->flags & IORING_URING_CMD_FIXED)))
return -EINVAL;
- if (WARN_ON_ONCE(import_flags))
+ if (WARN_ON_ONCE(import_flags & ~IO_URING_CMD_IMPORT_DMABUF))
return -EINVAL;
+ if (import_flags & IO_URING_CMD_IMPORT_DMABUF)
+ flags |= IO_REGBUF_IMPORT_ALLOW_DMABUF;
- return io_import_reg_buf(req, iter, ubuf, len, rw, issue_flags, 0);
+ ret = io_import_reg_buf(req, iter, ubuf, len, rw, issue_flags, flags);
+ if (ret)
+ return ret;
+ return io_attach_dmabuf_map(req, iter, issue_flags);
}
EXPORT_SYMBOL_GPL(io_uring_cmd_import_fixed);
--
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 ` Anuj Gupta [this message]
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 ` [PATCH v2 5/5] nvme: support dma-buf registered buffers for passthrough Anuj Gupta
2026-10-28 16:31 ` 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-4-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