All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jens Axboe <axboe@kernel.dk>
To: io-uring@vger.kernel.org
Cc: Jens Axboe <axboe@kernel.dk>
Subject: [PATCH 04/14] io_uring/splice: open code 2nd direct file assignment
Date: Tue, 29 Oct 2024 09:16:33 -0600	[thread overview]
Message-ID: <20241029152249.667290-5-axboe@kernel.dk> (raw)
In-Reply-To: <20241029152249.667290-1-axboe@kernel.dk>

In preparation for not pinning the whole registered file table, open
code the second potential direct file assignment. This will be handled
by appropriate helpers in the future, for now just do it manually.

Signed-off-by: Jens Axboe <axboe@kernel.dk>
---
 io_uring/opdef.c  |  2 ++
 io_uring/splice.c | 44 ++++++++++++++++++++++++++++++++++++--------
 io_uring/splice.h |  1 +
 3 files changed, 39 insertions(+), 8 deletions(-)

diff --git a/io_uring/opdef.c b/io_uring/opdef.c
index a2be3bbca5ff..3de75eca1c92 100644
--- a/io_uring/opdef.c
+++ b/io_uring/opdef.c
@@ -641,6 +641,7 @@ const struct io_cold_def io_cold_defs[] = {
 	},
 	[IORING_OP_SPLICE] = {
 		.name			= "SPLICE",
+		.cleanup		= io_splice_cleanup,
 	},
 	[IORING_OP_PROVIDE_BUFFERS] = {
 		.name			= "PROVIDE_BUFFERS",
@@ -650,6 +651,7 @@ const struct io_cold_def io_cold_defs[] = {
 	},
 	[IORING_OP_TEE] = {
 		.name			= "TEE",
+		.cleanup		= io_splice_cleanup,
 	},
 	[IORING_OP_SHUTDOWN] = {
 		.name			= "SHUTDOWN",
diff --git a/io_uring/splice.c b/io_uring/splice.c
index 3b659cd23e9d..e62bc6497a94 100644
--- a/io_uring/splice.c
+++ b/io_uring/splice.c
@@ -21,6 +21,7 @@ struct io_splice {
 	u64				len;
 	int				splice_fd_in;
 	unsigned int			flags;
+	struct io_rsrc_node		*rsrc_node;
 };
 
 static int __io_splice_prep(struct io_kiocb *req,
@@ -34,6 +35,7 @@ static int __io_splice_prep(struct io_kiocb *req,
 	if (unlikely(sp->flags & ~valid_flags))
 		return -EINVAL;
 	sp->splice_fd_in = READ_ONCE(sqe->splice_fd_in);
+	sp->rsrc_node = NULL;
 	req->flags |= REQ_F_FORCE_ASYNC;
 	return 0;
 }
@@ -45,6 +47,38 @@ int io_tee_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe)
 	return __io_splice_prep(req, sqe);
 }
 
+void io_splice_cleanup(struct io_kiocb *req)
+{
+	struct io_splice *sp = io_kiocb_to_cmd(req, struct io_splice);
+
+	io_put_rsrc_node(req->ctx, sp->rsrc_node);
+}
+
+static struct file *io_splice_get_file(struct io_kiocb *req,
+				       unsigned int issue_flags)
+{
+	struct io_splice *sp = io_kiocb_to_cmd(req, struct io_splice);
+	struct io_ring_ctx *ctx = req->ctx;
+	struct io_fixed_file *slot;
+	struct file *file = NULL;
+
+	if (!(sp->flags & SPLICE_F_FD_IN_FIXED))
+		return io_file_get_normal(req, sp->splice_fd_in);
+
+	io_ring_submit_lock(ctx, issue_flags);
+	if (unlikely(sp->splice_fd_in >= ctx->nr_user_files))
+		goto out;
+	sp->splice_fd_in = array_index_nospec(sp->splice_fd_in, ctx->nr_user_files);
+	slot = &ctx->file_table.files[sp->splice_fd_in];
+	if (!req->rsrc_node)
+		__io_req_set_rsrc_node(req, ctx);
+	file = io_slot_file(slot);
+	req->flags |= REQ_F_NEED_CLEANUP;
+out:
+	io_ring_submit_unlock(ctx, issue_flags);
+	return file;
+}
+
 int io_tee(struct io_kiocb *req, unsigned int issue_flags)
 {
 	struct io_splice *sp = io_kiocb_to_cmd(req, struct io_splice);
@@ -55,10 +89,7 @@ int io_tee(struct io_kiocb *req, unsigned int issue_flags)
 
 	WARN_ON_ONCE(issue_flags & IO_URING_F_NONBLOCK);
 
-	if (sp->flags & SPLICE_F_FD_IN_FIXED)
-		in = io_file_get_fixed(req, sp->splice_fd_in, issue_flags);
-	else
-		in = io_file_get_normal(req, sp->splice_fd_in);
+	in = io_splice_get_file(req, issue_flags);
 	if (!in) {
 		ret = -EBADF;
 		goto done;
@@ -96,10 +127,7 @@ int io_splice(struct io_kiocb *req, unsigned int issue_flags)
 
 	WARN_ON_ONCE(issue_flags & IO_URING_F_NONBLOCK);
 
-	if (sp->flags & SPLICE_F_FD_IN_FIXED)
-		in = io_file_get_fixed(req, sp->splice_fd_in, issue_flags);
-	else
-		in = io_file_get_normal(req, sp->splice_fd_in);
+	in = io_splice_get_file(req, issue_flags);
 	if (!in) {
 		ret = -EBADF;
 		goto done;
diff --git a/io_uring/splice.h b/io_uring/splice.h
index 542f94168ad3..b9b2848327fb 100644
--- a/io_uring/splice.h
+++ b/io_uring/splice.h
@@ -3,5 +3,6 @@
 int io_tee_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe);
 int io_tee(struct io_kiocb *req, unsigned int issue_flags);
 
+void io_splice_cleanup(struct io_kiocb *req);
 int io_splice_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe);
 int io_splice(struct io_kiocb *req, unsigned int issue_flags);
-- 
2.45.2


  parent reply	other threads:[~2024-10-29 15:23 UTC|newest]

Thread overview: 37+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-10-29 15:16 [PATCHSET v3 0/14] Rewrite rsrc node handling Jens Axboe
2024-10-29 15:16 ` [PATCH 01/14] io_uring/nop: add support for testing registered files and buffers Jens Axboe
2024-10-29 15:16 ` [PATCH 02/14] io_uring/rsrc: move struct io_fixed_file to rsrc.h header Jens Axboe
2024-10-29 15:16 ` [PATCH 03/14] io_uring: specify freeptr usage for SLAB_TYPESAFE_BY_RCU io_kiocb cache Jens Axboe
2024-11-19 15:36   ` Guenter Roeck
2024-11-19 16:02     ` Jens Axboe
2024-11-19 16:21       ` Guenter Roeck
2024-11-19 17:49         ` Geert Uytterhoeven
2024-11-19 19:00           ` Jens Axboe
2024-11-19 19:02             ` Geert Uytterhoeven
2024-11-19 19:10               ` Jens Axboe
2024-11-19 19:25                 ` Geert Uytterhoeven
2024-11-19 19:30                   ` Jens Axboe
2024-11-19 19:41                     ` Geert Uytterhoeven
2024-11-19 19:44                       ` Jens Axboe
2024-11-19 19:49                         ` Jens Axboe
2024-11-19 21:46                           ` Guenter Roeck
2024-11-19 22:30                             ` Jens Axboe
2024-11-20  0:08                               ` Guenter Roeck
2024-11-20  1:58                                 ` Jens Axboe
2024-11-20  8:19                               ` Geert Uytterhoeven
2024-11-20  8:47                                 ` Vlastimil Babka
2024-11-20  9:07                                   ` Geert Uytterhoeven
2024-11-20  9:37                                     ` Vlastimil Babka
2024-11-20 12:48                                       ` Geert Uytterhoeven
2024-11-21 23:04             ` Finn Thain
2024-10-29 15:16 ` Jens Axboe [this message]
2024-10-29 15:16 ` [PATCH 05/14] io_uring/rsrc: kill io_charge_rsrc_node() Jens Axboe
2024-10-29 15:16 ` [PATCH 06/14] io_uring/rsrc: get rid of per-ring io_rsrc_node list Jens Axboe
2024-10-29 15:16 ` [PATCH 07/14] io_uring/rsrc: get rid of io_rsrc_node allocation cache Jens Axboe
2024-10-29 15:16 ` [PATCH 08/14] io_uring/rsrc: add an empty io_rsrc_node for sparse buffer entries Jens Axboe
2024-10-29 15:16 ` [PATCH 09/14] io_uring: only initialize io_kiocb rsrc_nodes when needed Jens Axboe
2024-10-29 15:16 ` [PATCH 10/14] io_uring/rsrc: unify file and buffer resource tables Jens Axboe
2024-10-29 15:16 ` [PATCH 11/14] io_uring/rsrc: add io_rsrc_node_lookup() helper Jens Axboe
2024-10-29 15:16 ` [PATCH 12/14] io_uring/filetable: remove io_file_from_index() helper Jens Axboe
2024-10-29 15:16 ` [PATCH 13/14] io_uring/filetable: kill io_reset_alloc_hint() helper Jens Axboe
2024-10-29 15:16 ` [PATCH 14/14] io_uring/rsrc: add io_reset_rsrc_node() helper 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 \
    --in-reply-to=20241029152249.667290-5-axboe@kernel.dk \
    --to=axboe@kernel.dk \
    --cc=io-uring@vger.kernel.org \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.