]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
io_uring/rw: move fixed buffer import to issue path
authorKeith Busch <kbusch@kernel.org>
Thu, 27 Feb 2025 22:39:12 +0000 (14:39 -0800)
committerJens Axboe <axboe@kernel.dk>
Fri, 28 Feb 2025 14:05:26 +0000 (07:05 -0700)
Registered buffers may depend on a linked command, which makes the prep
path too early to import. Move to the issue path when the node is
actually needed like all the other users of fixed buffers.

Signed-off-by: Keith Busch <kbusch@kernel.org>
Link: https://lore.kernel.org/r/20250227223916.143006-3-kbusch@meta.com
Reviewed-by: Ming Lei <ming.lei@redhat.com>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
io_uring/opdef.c
io_uring/rw.c
io_uring/rw.h

index e8baef4e51465016b921b327e6da122204504031..306fd9c48b441b6db656c770de5b386c7920c552 100644 (file)
@@ -104,7 +104,7 @@ const struct io_issue_def io_issue_defs[] = {
                .iopoll_queue           = 1,
                .async_size             = sizeof(struct io_async_rw),
                .prep                   = io_prep_read_fixed,
-               .issue                  = io_read,
+               .issue                  = io_read_fixed,
        },
        [IORING_OP_WRITE_FIXED] = {
                .needs_file             = 1,
@@ -118,7 +118,7 @@ const struct io_issue_def io_issue_defs[] = {
                .iopoll_queue           = 1,
                .async_size             = sizeof(struct io_async_rw),
                .prep                   = io_prep_write_fixed,
-               .issue                  = io_write,
+               .issue                  = io_write_fixed,
        },
        [IORING_OP_POLL_ADD] = {
                .needs_file             = 1,
index b21b423b3cf8f7758d1a9ee7405b9a2b67c57c8b..7bc23802a388e07505523af55898ee2ed0af8c9e 100644 (file)
@@ -357,31 +357,30 @@ int io_prep_writev(struct io_kiocb *req, const struct io_uring_sqe *sqe)
        return io_prep_rwv(req, sqe, ITER_SOURCE);
 }
 
-static int io_prep_rw_fixed(struct io_kiocb *req, const struct io_uring_sqe *sqe,
+static int io_init_rw_fixed(struct io_kiocb *req, unsigned int issue_flags,
                            int ddir)
 {
        struct io_rw *rw = io_kiocb_to_cmd(req, struct io_rw);
-       struct io_async_rw *io;
+       struct io_async_rw *io = req->async_data;
        int ret;
 
-       ret = __io_prep_rw(req, sqe, ddir);
-       if (unlikely(ret))
-               return ret;
+       if (io->bytes_done)
+               return 0;
 
-       io = req->async_data;
-       ret = io_import_reg_buf(req, &io->iter, rw->addr, rw->len, ddir, 0);
+       ret = io_import_reg_buf(req, &io->iter, rw->addr, rw->len, ddir,
+                               issue_flags);
        iov_iter_save_state(&io->iter, &io->iter_state);
        return ret;
 }
 
 int io_prep_read_fixed(struct io_kiocb *req, const struct io_uring_sqe *sqe)
 {
-       return io_prep_rw_fixed(req, sqe, ITER_DEST);
+       return __io_prep_rw(req, sqe, ITER_DEST);
 }
 
 int io_prep_write_fixed(struct io_kiocb *req, const struct io_uring_sqe *sqe)
 {
-       return io_prep_rw_fixed(req, sqe, ITER_SOURCE);
+       return __io_prep_rw(req, sqe, ITER_SOURCE);
 }
 
 /*
@@ -1147,6 +1146,28 @@ ret_eagain:
        }
 }
 
+int io_read_fixed(struct io_kiocb *req, unsigned int issue_flags)
+{
+       int ret;
+
+       ret = io_init_rw_fixed(req, issue_flags, ITER_DEST);
+       if (unlikely(ret))
+               return ret;
+
+       return io_read(req, issue_flags);
+}
+
+int io_write_fixed(struct io_kiocb *req, unsigned int issue_flags)
+{
+       int ret;
+
+       ret = io_init_rw_fixed(req, issue_flags, ITER_SOURCE);
+       if (unlikely(ret))
+               return ret;
+
+       return io_write(req, issue_flags);
+}
+
 void io_rw_fail(struct io_kiocb *req)
 {
        int res;
index a45e0c71b59d6e2ac9e2444e7928ff484ec559b0..bf121b81ebe84ed4905a7ca787833e4e66b91b17 100644 (file)
@@ -38,6 +38,8 @@ int io_prep_read(struct io_kiocb *req, const struct io_uring_sqe *sqe);
 int io_prep_write(struct io_kiocb *req, const struct io_uring_sqe *sqe);
 int io_read(struct io_kiocb *req, unsigned int issue_flags);
 int io_write(struct io_kiocb *req, unsigned int issue_flags);
+int io_read_fixed(struct io_kiocb *req, unsigned int issue_flags);
+int io_write_fixed(struct io_kiocb *req, unsigned int issue_flags);
 void io_readv_writev_cleanup(struct io_kiocb *req);
 void io_rw_fail(struct io_kiocb *req);
 void io_req_rw_complete(struct io_kiocb *req, io_tw_token_t tw);