]> www.infradead.org Git - users/jedix/linux-maple.git/commitdiff
io_uring/net: convert to struct iou_vec
authorPavel Begunkov <asml.silence@gmail.com>
Fri, 7 Mar 2025 16:00:35 +0000 (16:00 +0000)
committerJens Axboe <axboe@kernel.dk>
Fri, 7 Mar 2025 20:41:08 +0000 (13:41 -0700)
Convert net.c to use struct iou_vec.

Signed-off-by: Pavel Begunkov <asml.silence@gmail.com>
Link: https://lore.kernel.org/r/6437b57dabed44eca708c02e390529c7ed211c78.1741362889.git.asml.silence@gmail.com
Signed-off-by: Jens Axboe <axboe@kernel.dk>
io_uring/alloc_cache.h
io_uring/net.c
io_uring/net.h

index 7f68eff2e7f3250f11eba7a732064575e31518a3..d33ce159ef33921319a442ab16be9a8e7ee015e5 100644 (file)
@@ -16,15 +16,6 @@ bool io_alloc_cache_init(struct io_alloc_cache *cache,
 
 void *io_cache_alloc_new(struct io_alloc_cache *cache, gfp_t gfp);
 
-static inline void io_alloc_cache_kasan(struct iovec **iov, int *nr)
-{
-       if (IS_ENABLED(CONFIG_KASAN)) {
-               kfree(*iov);
-               *iov = NULL;
-               *nr = 0;
-       }
-}
-
 static inline bool io_alloc_cache_put(struct io_alloc_cache *cache,
                                      void *entry)
 {
index 0c46e631528909752c6960f0e7355452ac99ead1..4825111185c306632e99f53efcd78b444047b9eb 100644 (file)
@@ -136,11 +136,8 @@ static bool io_net_retry(struct socket *sock, int flags)
 
 static void io_netmsg_iovec_free(struct io_async_msghdr *kmsg)
 {
-       if (kmsg->free_iov) {
-               kfree(kmsg->free_iov);
-               kmsg->free_iov_nr = 0;
-               kmsg->free_iov = NULL;
-       }
+       if (kmsg->vec.iovec)
+               io_vec_free(&kmsg->vec);
 }
 
 static void io_netmsg_recycle(struct io_kiocb *req, unsigned int issue_flags)
@@ -154,7 +151,7 @@ static void io_netmsg_recycle(struct io_kiocb *req, unsigned int issue_flags)
        }
 
        /* Let normal cleanup path reap it if we fail adding to the cache */
-       io_alloc_cache_kasan(&hdr->free_iov, &hdr->free_iov_nr);
+       io_alloc_cache_vec_kasan(&hdr->vec);
        if (io_alloc_cache_put(&req->ctx->netmsg_cache, hdr)) {
                req->async_data = NULL;
                req->flags &= ~REQ_F_ASYNC_DATA;
@@ -171,7 +168,7 @@ static struct io_async_msghdr *io_msg_alloc_async(struct io_kiocb *req)
                return NULL;
 
        /* If the async data was cached, we might have an iov cached inside. */
-       if (hdr->free_iov)
+       if (hdr->vec.iovec)
                req->flags |= REQ_F_NEED_CLEANUP;
        return hdr;
 }
@@ -182,10 +179,7 @@ static void io_net_vec_assign(struct io_kiocb *req, struct io_async_msghdr *kmsg
 {
        if (iov) {
                req->flags |= REQ_F_NEED_CLEANUP;
-               kmsg->free_iov_nr = kmsg->msg.msg_iter.nr_segs;
-               if (kmsg->free_iov)
-                       kfree(kmsg->free_iov);
-               kmsg->free_iov = iov;
+               io_vec_reset_iovec(&kmsg->vec, iov, kmsg->msg.msg_iter.nr_segs);
        }
 }
 
@@ -208,9 +202,9 @@ static int io_net_import_vec(struct io_kiocb *req, struct io_async_msghdr *iomsg
        struct iovec *iov;
        int ret, nr_segs;
 
-       if (iomsg->free_iov) {
-               nr_segs = iomsg->free_iov_nr;
-               iov = iomsg->free_iov;
+       if (iomsg->vec.iovec) {
+               nr_segs = iomsg->vec.nr;
+               iov = iomsg->vec.iovec;
        } else {
                nr_segs = 1;
                iov = &iomsg->fast_iov;
@@ -468,7 +462,7 @@ static int io_bundle_nbufs(struct io_async_msghdr *kmsg, int ret)
        if (iter_is_ubuf(&kmsg->msg.msg_iter))
                return 1;
 
-       iov = kmsg->free_iov;
+       iov = kmsg->vec.iovec;
        if (!iov)
                iov = &kmsg->fast_iov;
 
@@ -584,9 +578,9 @@ static int io_send_select_buffer(struct io_kiocb *req, unsigned int issue_flags,
                .nr_iovs = 1,
        };
 
-       if (kmsg->free_iov) {
-               arg.nr_iovs = kmsg->free_iov_nr;
-               arg.iovs = kmsg->free_iov;
+       if (kmsg->vec.iovec) {
+               arg.nr_iovs = kmsg->vec.nr;
+               arg.iovs = kmsg->vec.iovec;
                arg.mode = KBUF_MODE_FREE;
        }
 
@@ -599,9 +593,9 @@ static int io_send_select_buffer(struct io_kiocb *req, unsigned int issue_flags,
        if (unlikely(ret < 0))
                return ret;
 
-       if (arg.iovs != &kmsg->fast_iov && arg.iovs != kmsg->free_iov) {
-               kmsg->free_iov_nr = ret;
-               kmsg->free_iov = arg.iovs;
+       if (arg.iovs != &kmsg->fast_iov && arg.iovs != kmsg->vec.iovec) {
+               kmsg->vec.nr = ret;
+               kmsg->vec.iovec = arg.iovs;
                req->flags |= REQ_F_NEED_CLEANUP;
        }
        sr->len = arg.out_len;
@@ -1085,9 +1079,9 @@ static int io_recv_buf_select(struct io_kiocb *req, struct io_async_msghdr *kmsg
                        .mode = KBUF_MODE_EXPAND,
                };
 
-               if (kmsg->free_iov) {
-                       arg.nr_iovs = kmsg->free_iov_nr;
-                       arg.iovs = kmsg->free_iov;
+               if (kmsg->vec.iovec) {
+                       arg.nr_iovs = kmsg->vec.nr;
+                       arg.iovs = kmsg->vec.iovec;
                        arg.mode |= KBUF_MODE_FREE;
                }
 
@@ -1106,9 +1100,9 @@ static int io_recv_buf_select(struct io_kiocb *req, struct io_async_msghdr *kmsg
                }
                iov_iter_init(&kmsg->msg.msg_iter, ITER_DEST, arg.iovs, ret,
                                arg.out_len);
-               if (arg.iovs != &kmsg->fast_iov && arg.iovs != kmsg->free_iov) {
-                       kmsg->free_iov_nr = ret;
-                       kmsg->free_iov = arg.iovs;
+               if (arg.iovs != &kmsg->fast_iov && arg.iovs != kmsg->vec.iovec) {
+                       kmsg->vec.nr = ret;
+                       kmsg->vec.iovec = arg.iovs;
                        req->flags |= REQ_F_NEED_CLEANUP;
                }
        } else {
@@ -1874,8 +1868,7 @@ void io_netmsg_cache_free(const void *entry)
 {
        struct io_async_msghdr *kmsg = (struct io_async_msghdr *) entry;
 
-       if (kmsg->free_iov)
-               io_netmsg_iovec_free(kmsg);
+       io_vec_free(&kmsg->vec);
        kfree(kmsg);
 }
 #endif
index b804c2b36e605ccd026bdd4075190077822e3549..43e5ce5416b7ec68c6523f7f59462a6c126f9b19 100644 (file)
@@ -2,12 +2,12 @@
 
 #include <linux/net.h>
 #include <linux/uio.h>
+#include <linux/io_uring_types.h>
 
 struct io_async_msghdr {
 #if defined(CONFIG_NET)
-       struct iovec                    *free_iov;
-       /* points to an allocated iov, if NULL we use fast_iov instead */
-       int                             free_iov_nr;
+       struct iou_vec                          vec;
+
        struct_group(clear,
                int                             namelen;
                struct iovec                    fast_iov;