From: Ming Lei <[email protected]>
To: Jens Axboe <[email protected]>,
[email protected], Pavel Begunkov <[email protected]>
Cc: [email protected],
Uday Shankar <[email protected]>,
Akilesh Kailash <[email protected]>,
Ming Lei <[email protected]>
Subject: [PATCH V10 09/12] io_uring: add callback to 'io_mapped_buffer' for giving back kernel buffer
Date: Thu, 7 Nov 2024 19:01:42 +0800 [thread overview]
Message-ID: <[email protected]> (raw)
In-Reply-To: <[email protected]>
Add one callback to 'io_mapped_buffer' for giving back kernel buffer
after the buffer is used.
Meantime move 'io_rsrc_node' into public header, and it will become
part of kernel buffer API.
Signed-off-by: Ming Lei <[email protected]>
---
include/linux/io_uring_types.h | 20 +++++++++++++++++++-
io_uring/rsrc.c | 14 +++++++++++++-
io_uring/rsrc.h | 13 +------------
3 files changed, 33 insertions(+), 14 deletions(-)
diff --git a/include/linux/io_uring_types.h b/include/linux/io_uring_types.h
index 03abaeef4a67..7de0d4c0ed6b 100644
--- a/include/linux/io_uring_types.h
+++ b/include/linux/io_uring_types.h
@@ -40,8 +40,26 @@ enum io_uring_cmd_flags {
IO_URING_F_COMPAT = (1 << 12),
};
+struct io_rsrc_node {
+ unsigned char type;
+ unsigned char flags;
+ int refs;
+
+ u64 tag;
+ union {
+ unsigned long file_ptr;
+ struct io_mapped_buf *buf;
+ };
+};
+
+typedef void (io_uring_kbuf_ack_t) (struct io_rsrc_node *);
+
struct io_mapped_buf {
- u64 addr;
+ /* 'addr' is always 0 for kernel buffer */
+ union {
+ u64 addr;
+ io_uring_kbuf_ack_t *kbuf_ack;
+ };
unsigned int len;
unsigned int nr_bvecs;
refcount_t refs;
diff --git a/io_uring/rsrc.c b/io_uring/rsrc.c
index b0b60ae0456a..327bc1a83e4b 100644
--- a/io_uring/rsrc.c
+++ b/io_uring/rsrc.c
@@ -441,6 +441,18 @@ int io_files_update(struct io_kiocb *req, unsigned int issue_flags)
return IOU_OK;
}
+static void __io_free_buf_node(struct io_ring_ctx *ctx, struct io_rsrc_node *node)
+{
+ struct io_mapped_buf *buf = node->buf;
+
+ if (node->flags & IORING_RSRC_F_BUF_KERNEL) {
+ if (buf->kbuf_ack)
+ buf->kbuf_ack(node);
+ } else {
+ io_buffer_unmap(ctx, node);
+ }
+}
+
void io_free_rsrc_node(struct io_ring_ctx *ctx, struct io_rsrc_node *node)
{
bool need_free = node->flags & IORING_RSRC_F_NEED_FREE;
@@ -457,7 +469,7 @@ void io_free_rsrc_node(struct io_ring_ctx *ctx, struct io_rsrc_node *node)
break;
case IORING_RSRC_BUFFER:
if (node->buf)
- io_buffer_unmap(ctx, node);
+ __io_free_buf_node(ctx, node);
break;
default:
WARN_ON_ONCE(1);
diff --git a/io_uring/rsrc.h b/io_uring/rsrc.h
index 3bc3a484fbba..f45a26c3b79d 100644
--- a/io_uring/rsrc.h
+++ b/io_uring/rsrc.h
@@ -14,18 +14,7 @@ enum {
__IORING_RSRC_LAST_TYPE,
IORING_RSRC_F_NEED_FREE = 1 << 0,
-};
-
-struct io_rsrc_node {
- unsigned char type;
- unsigned char flags;
- int refs;
-
- u64 tag;
- union {
- unsigned long file_ptr;
- struct io_mapped_buf *buf;
- };
+ IORING_RSRC_F_BUF_KERNEL = 1 << 1,
};
struct io_imu_folio_data {
--
2.47.0
next prev parent reply other threads:[~2024-11-07 11:02 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-11-07 11:01 [PATCH V10 0/12] io_uring: support group buffer & ublk zc Ming Lei
2024-11-07 11:01 ` [PATCH V10 01/12] io_uring/rsrc: pass 'struct io_ring_ctx' reference to rsrc helpers Ming Lei
2024-11-07 11:01 ` [PATCH V10 02/12] io_uring/rsrc: remove '->ctx_ptr' of 'struct io_rsrc_node' Ming Lei
2024-11-07 11:01 ` [PATCH V10 03/12] io_uring/rsrc: add & apply io_req_assign_buf_node() Ming Lei
2024-11-07 11:01 ` [PATCH V10 04/12] io_uring/rsrc: prepare for supporting external 'io_rsrc_node' Ming Lei
2024-11-07 11:01 ` [PATCH V10 05/12] io_uring: rename io_mapped_ubuf as io_mapped_buf Ming Lei
2024-11-07 11:01 ` [PATCH V10 06/12] io_uring: rename io_mapped_buf->ubuf as io_mapped_buf->addr Ming Lei
2024-11-07 11:01 ` [PATCH V10 07/12] io_uring: shrink io_mapped_buf Ming Lei
2024-11-07 11:01 ` [PATCH V10 08/12] io_uring: reuse io_mapped_buf for kernel buffer Ming Lei
2024-11-07 11:01 ` Ming Lei [this message]
2024-11-07 11:01 ` [PATCH V10 10/12] io_uring: support leased group buffer with REQ_F_GROUP_BUF Ming Lei
2024-11-07 11:01 ` [PATCH V10 11/12] io_uring/uring_cmd: support leasing device kernel buffer to io_uring Ming Lei
2024-11-07 18:27 ` kernel test robot
2024-11-07 19:30 ` kernel test robot
2024-11-08 0:59 ` Ming Lei
2024-11-07 11:01 ` [PATCH V10 12/12] ublk: support leasing io " Ming Lei
2024-11-07 22:25 ` (subset) [PATCH V10 0/12] io_uring: support group buffer & ublk zc Jens Axboe
2024-11-07 22:25 ` Jens Axboe
2024-11-12 0:53 ` Ming Lei
2024-11-13 13:43 ` Pavel Begunkov
2024-11-13 14:56 ` Jens Axboe
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 \
[email protected] \
[email protected] \
[email protected] \
[email protected] \
[email protected] \
[email protected] \
[email protected] \
[email protected] \
/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