]> www.infradead.org Git - users/jedix/linux-maple.git/commitdiff
io_uring: introduce struct iou_vec
authorPavel Begunkov <asml.silence@gmail.com>
Fri, 7 Mar 2025 16:00:29 +0000 (16:00 +0000)
committerJens Axboe <axboe@kernel.dk>
Fri, 7 Mar 2025 16:07:29 +0000 (09:07 -0700)
I need a convenient way to pass around and work with iovec+size pair,
put them into a structure and makes use of it in rw.c

Signed-off-by: Pavel Begunkov <asml.silence@gmail.com>
Link: https://lore.kernel.org/r/d39fadafc9e9047b0a292e5be6db3cf2f48bb1f7.1741362889.git.asml.silence@gmail.com
Signed-off-by: Jens Axboe <axboe@kernel.dk>
include/linux/io_uring_types.h
io_uring/rsrc.c
io_uring/rsrc.h
io_uring/rw.c
io_uring/rw.h

index 35fc241c46726be3147f848b8d34fd7c796cc7c4..9101f12d21efbc209cb6362c540aac0c66b9209b 100644 (file)
@@ -110,6 +110,11 @@ struct io_uring_task {
        } ____cacheline_aligned_in_smp;
 };
 
+struct iou_vec {
+       struct iovec            *iovec;
+       unsigned                nr;
+};
+
 struct io_uring {
        u32 head;
        u32 tail;
index 28783f1dde00197ac21be0260c843c26c8bcd58e..bac509f85c806e5befc85ffff1f0343c9114e5a5 100644 (file)
@@ -1260,3 +1260,12 @@ int io_register_clone_buffers(struct io_ring_ctx *ctx, void __user *arg)
        fput(file);
        return ret;
 }
+
+void io_vec_free(struct iou_vec *iv)
+{
+       if (!iv->iovec)
+               return;
+       kfree(iv->iovec);
+       iv->iovec = NULL;
+       iv->nr = 0;
+}
index 284e300e63fb82e9b37ee40b319ce4b1ff54c609..f35e1a07619ab7ba620eb0d04aed306675a2cb15 100644 (file)
@@ -145,4 +145,20 @@ static inline void __io_unaccount_mem(struct user_struct *user,
        atomic_long_sub(nr_pages, &user->locked_vm);
 }
 
+void io_vec_free(struct iou_vec *iv);
+
+static inline void io_vec_reset_iovec(struct iou_vec *iv,
+                                     struct iovec *iovec, unsigned nr)
+{
+       io_vec_free(iv);
+       iv->iovec = iovec;
+       iv->nr = nr;
+}
+
+static inline void io_alloc_cache_vec_kasan(struct iou_vec *iv)
+{
+       if (IS_ENABLED(CONFIG_KASAN))
+               io_vec_free(iv);
+}
+
 #endif
index 5ee9f8949e8baa62f632064352c1399a66f9b85e..ad7f647d48e9c6a5c5e437e0ddf364beacb84f74 100644 (file)
@@ -87,9 +87,9 @@ static int io_import_vec(int ddir, struct io_kiocb *req,
        int ret, nr_segs;
        struct iovec *iov;
 
-       if (io->free_iovec) {
-               nr_segs = io->free_iov_nr;
-               iov = io->free_iovec;
+       if (io->vec.iovec) {
+               nr_segs = io->vec.nr;
+               iov = io->vec.iovec;
        } else {
                nr_segs = 1;
                iov = &io->fast_iov;
@@ -101,9 +101,7 @@ static int io_import_vec(int ddir, struct io_kiocb *req,
                return ret;
        if (iov) {
                req->flags |= REQ_F_NEED_CLEANUP;
-               io->free_iov_nr = io->iter.nr_segs;
-               kfree(io->free_iovec);
-               io->free_iovec = iov;
+               io_vec_reset_iovec(&io->vec, iov, io->iter.nr_segs);
        }
        return 0;
 }
@@ -151,7 +149,7 @@ static void io_rw_recycle(struct io_kiocb *req, unsigned int issue_flags)
        if (unlikely(issue_flags & IO_URING_F_UNLOCKED))
                return;
 
-       io_alloc_cache_kasan(&rw->free_iovec, &rw->free_iov_nr);
+       io_alloc_cache_vec_kasan(&rw->vec);
        if (io_alloc_cache_put(&req->ctx->rw_cache, rw)) {
                req->async_data = NULL;
                req->flags &= ~REQ_F_ASYNC_DATA;
@@ -201,7 +199,7 @@ static int io_rw_alloc_async(struct io_kiocb *req)
        rw = io_uring_alloc_async_data(&ctx->rw_cache, req);
        if (!rw)
                return -ENOMEM;
-       if (rw->free_iovec)
+       if (rw->vec.iovec)
                req->flags |= REQ_F_NEED_CLEANUP;
        rw->bytes_done = 0;
        return 0;
@@ -1327,7 +1325,6 @@ void io_rw_cache_free(const void *entry)
 {
        struct io_async_rw *rw = (struct io_async_rw *) entry;
 
-       if (rw->free_iovec)
-               kfree(rw->free_iovec);
+       io_vec_free(&rw->vec);
        kfree(rw);
 }
index bf121b81ebe84ed4905a7ca787833e4e66b91b17..529fd2f96a7fb123506f233efd0d9047bc49e176 100644 (file)
@@ -9,13 +9,13 @@ struct io_meta_state {
 };
 
 struct io_async_rw {
+       struct iou_vec                  vec;
        size_t                          bytes_done;
-       struct iovec                    *free_iovec;
+
        struct_group(clear,
                struct iov_iter                 iter;
                struct iov_iter_state           iter_state;
                struct iovec                    fast_iov;
-               int                             free_iov_nr;
                /*
                 * wpq is for buffered io, while meta fields are used with
                 * direct io