From: Pavel Begunkov <asml.silence@gmail.com>
To: linux-block@vger.kernel.org, io-uring@vger.kernel.org
Cc: "Vishal Verma" <vishal1.verma@intel.com>,
tushar.gohad@intel.com, "Keith Busch" <kbusch@kernel.org>,
"Jens Axboe" <axboe@kernel.dk>, "Christoph Hellwig" <hch@lst.de>,
"Sagi Grimberg" <sagi@grimberg.me>,
"Alexander Viro" <viro@zeniv.linux.org.uk>,
"Christian Brauner" <brauner@kernel.org>,
"Andrew Morton" <akpm@linux-foundation.org>,
"Sumit Semwal" <sumit.semwal@linaro.org>,
"Christian König" <christian.koenig@amd.com>,
"Pavel Begunkov" <asml.silence@gmail.com>,
linux-kernel@vger.kernel.org, linux-nvme@lists.infradead.org,
linux-fsdevel@vger.kernel.org, linux-media@vger.kernel.org,
dri-devel@lists.freedesktop.org, linaro-mm-sig@lists.linaro.org
Subject: [RFC v2 01/11] file: add callback for pre-mapping dmabuf
Date: Sun, 23 Nov 2025 22:51:21 +0000 [thread overview]
Message-ID: <74d689540fa200fe37f1a930165357a92fe9e68c.1763725387.git.asml.silence@gmail.com> (raw)
In-Reply-To: <cover.1763725387.git.asml.silence@gmail.com>
Add a file callback that maps a dmabuf for the given file and returns
an opaque token of type struct dma_token representing the mapping. The
implementation details are hidden from the caller, and the implementors
are normally expected to extend the structure.
The callback callers will be able to pass the token with an IO request,
which implemented in following patches as a new iterator type. The user
should release the token once it's not needed by calling the provided
release callback via appropriate helpers.
Signed-off-by: Pavel Begunkov <asml.silence@gmail.com>
---
include/linux/dma_token.h | 35 +++++++++++++++++++++++++++++++++++
include/linux/fs.h | 4 ++++
2 files changed, 39 insertions(+)
create mode 100644 include/linux/dma_token.h
diff --git a/include/linux/dma_token.h b/include/linux/dma_token.h
new file mode 100644
index 000000000000..9194b34282c2
--- /dev/null
+++ b/include/linux/dma_token.h
@@ -0,0 +1,35 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+#ifndef _LINUX_DMA_TOKEN_H
+#define _LINUX_DMA_TOKEN_H
+
+#include <linux/dma-buf.h>
+
+struct dma_token_params {
+ struct dma_buf *dmabuf;
+ enum dma_data_direction dir;
+};
+
+struct dma_token {
+ void (*release)(struct dma_token *);
+};
+
+static inline void dma_token_release(struct dma_token *token)
+{
+ token->release(token);
+}
+
+static inline struct dma_token *
+dma_token_create(struct file *file, struct dma_token_params *params)
+{
+ struct dma_token *res;
+
+ if (!file->f_op->dma_map)
+ return ERR_PTR(-EOPNOTSUPP);
+ res = file->f_op->dma_map(file, params);
+
+ WARN_ON_ONCE(!IS_ERR(res) && !res->release);
+
+ return res;
+}
+
+#endif
diff --git a/include/linux/fs.h b/include/linux/fs.h
index c895146c1444..0ce9a53fabec 100644
--- a/include/linux/fs.h
+++ b/include/linux/fs.h
@@ -2262,6 +2262,8 @@ struct dir_context {
struct iov_iter;
struct io_uring_cmd;
struct offset_ctx;
+struct dma_token;
+struct dma_token_params;
typedef unsigned int __bitwise fop_flags_t;
@@ -2309,6 +2311,8 @@ struct file_operations {
int (*uring_cmd_iopoll)(struct io_uring_cmd *, struct io_comp_batch *,
unsigned int poll_flags);
int (*mmap_prepare)(struct vm_area_desc *);
+ struct dma_token *(*dma_map)(struct file *,
+ struct dma_token_params *);
} __randomize_layout;
/* Supports async buffered reads */
--
2.52.0
next prev parent reply other threads:[~2025-11-23 22:51 UTC|newest]
Thread overview: 39+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-11-23 22:51 [RFC v2 00/11] Add dmabuf read/write via io_uring Pavel Begunkov
2025-11-23 22:51 ` Pavel Begunkov [this message]
2025-12-04 10:42 ` [RFC v2 01/11] file: add callback for pre-mapping dmabuf Christoph Hellwig
2025-12-12 1:02 ` Pavel Begunkov
2025-12-04 10:46 ` Christian König
2025-12-04 11:07 ` Christoph Hellwig
2025-12-04 11:09 ` Christian König
2025-12-04 13:10 ` Christoph Hellwig
2025-11-23 22:51 ` [RFC v2 02/11] iov_iter: introduce iter type for pre-registered dma Pavel Begunkov
2025-12-04 10:43 ` Christoph Hellwig
2025-12-12 1:06 ` Pavel Begunkov
2025-11-23 22:51 ` [RFC v2 03/11] block: move around bio flagging helpers Pavel Begunkov
2025-12-04 10:43 ` Christoph Hellwig
2025-12-12 1:08 ` Pavel Begunkov
2025-11-23 22:51 ` [RFC v2 04/11] block: introduce dma token backed bio type Pavel Begunkov
2025-12-04 10:48 ` Christoph Hellwig
2025-11-23 22:51 ` [RFC v2 05/11] block: add infra to handle dmabuf tokens Pavel Begunkov
2025-11-24 13:38 ` Anuj gupta
2025-12-04 10:56 ` Christoph Hellwig
2025-12-12 1:56 ` Pavel Begunkov
2025-12-04 13:08 ` Christoph Hellwig
2025-11-23 22:51 ` [RFC v2 06/11] nvme-pci: add support for dmabuf reggistration Pavel Begunkov
2025-11-24 13:40 ` Anuj gupta
2025-12-04 11:00 ` Christoph Hellwig
2025-12-04 19:07 ` Keith Busch
2025-11-23 22:51 ` [RFC v2 07/11] nvme-pci: implement dma_token backed requests Pavel Begunkov
2025-12-04 11:04 ` Christoph Hellwig
2025-11-23 22:51 ` [RFC v2 08/11] io_uring/rsrc: add imu flags Pavel Begunkov
2025-11-23 22:51 ` [RFC v2 09/11] io_uring/rsrc: extended reg buffer registration Pavel Begunkov
2025-11-23 22:51 ` [RFC v2 10/11] io_uring/rsrc: add dmabuf-backed buffer registeration Pavel Begunkov
2025-11-23 22:51 ` [RFC v2 11/11] io_uring/rsrc: implement dmabuf regbuf import Pavel Begunkov
2025-11-24 10:33 ` [RFC v2 00/11] Add dmabuf read/write via io_uring Christian König
2025-11-24 11:30 ` Pavel Begunkov
2025-11-24 14:17 ` Christian König
2025-11-25 13:52 ` Pavel Begunkov
2025-11-25 14:21 ` Christian König
2025-11-25 19:40 ` Pavel Begunkov
2025-11-24 13:35 ` Anuj gupta
2025-11-25 12:35 ` Pavel Begunkov
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=74d689540fa200fe37f1a930165357a92fe9e68c.1763725387.git.asml.silence@gmail.com \
--to=asml.silence@gmail.com \
--cc=akpm@linux-foundation.org \
--cc=axboe@kernel.dk \
--cc=brauner@kernel.org \
--cc=christian.koenig@amd.com \
--cc=dri-devel@lists.freedesktop.org \
--cc=hch@lst.de \
--cc=io-uring@vger.kernel.org \
--cc=kbusch@kernel.org \
--cc=linaro-mm-sig@lists.linaro.org \
--cc=linux-block@vger.kernel.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-media@vger.kernel.org \
--cc=linux-nvme@lists.infradead.org \
--cc=sagi@grimberg.me \
--cc=sumit.semwal@linaro.org \
--cc=tushar.gohad@intel.com \
--cc=viro@zeniv.linux.org.uk \
--cc=vishal1.verma@intel.com \
/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;
as well as URLs for NNTP newsgroup(s).