Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

io_uring/net: convert to struct iou_vec

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>

authored by

Pavel Begunkov and committed by
Jens Axboe
be7052a4 9fcb349f

+25 -41
-9
io_uring/alloc_cache.h
··· 16 16 17 17 void *io_cache_alloc_new(struct io_alloc_cache *cache, gfp_t gfp); 18 18 19 - static inline void io_alloc_cache_kasan(struct iovec **iov, int *nr) 20 - { 21 - if (IS_ENABLED(CONFIG_KASAN)) { 22 - kfree(*iov); 23 - *iov = NULL; 24 - *nr = 0; 25 - } 26 - } 27 - 28 19 static inline bool io_alloc_cache_put(struct io_alloc_cache *cache, 29 20 void *entry) 30 21 {
+22 -29
io_uring/net.c
··· 136 136 137 137 static void io_netmsg_iovec_free(struct io_async_msghdr *kmsg) 138 138 { 139 - if (kmsg->free_iov) { 140 - kfree(kmsg->free_iov); 141 - kmsg->free_iov_nr = 0; 142 - kmsg->free_iov = NULL; 143 - } 139 + if (kmsg->vec.iovec) 140 + io_vec_free(&kmsg->vec); 144 141 } 145 142 146 143 static void io_netmsg_recycle(struct io_kiocb *req, unsigned int issue_flags) ··· 151 154 } 152 155 153 156 /* Let normal cleanup path reap it if we fail adding to the cache */ 154 - io_alloc_cache_kasan(&hdr->free_iov, &hdr->free_iov_nr); 157 + io_alloc_cache_vec_kasan(&hdr->vec); 155 158 if (io_alloc_cache_put(&req->ctx->netmsg_cache, hdr)) { 156 159 req->async_data = NULL; 157 160 req->flags &= ~REQ_F_ASYNC_DATA; ··· 168 171 return NULL; 169 172 170 173 /* If the async data was cached, we might have an iov cached inside. */ 171 - if (hdr->free_iov) 174 + if (hdr->vec.iovec) 172 175 req->flags |= REQ_F_NEED_CLEANUP; 173 176 return hdr; 174 177 } ··· 179 182 { 180 183 if (iov) { 181 184 req->flags |= REQ_F_NEED_CLEANUP; 182 - kmsg->free_iov_nr = kmsg->msg.msg_iter.nr_segs; 183 - if (kmsg->free_iov) 184 - kfree(kmsg->free_iov); 185 - kmsg->free_iov = iov; 185 + io_vec_reset_iovec(&kmsg->vec, iov, kmsg->msg.msg_iter.nr_segs); 186 186 } 187 187 } 188 188 ··· 202 208 struct iovec *iov; 203 209 int ret, nr_segs; 204 210 205 - if (iomsg->free_iov) { 206 - nr_segs = iomsg->free_iov_nr; 207 - iov = iomsg->free_iov; 211 + if (iomsg->vec.iovec) { 212 + nr_segs = iomsg->vec.nr; 213 + iov = iomsg->vec.iovec; 208 214 } else { 209 215 nr_segs = 1; 210 216 iov = &iomsg->fast_iov; ··· 462 468 if (iter_is_ubuf(&kmsg->msg.msg_iter)) 463 469 return 1; 464 470 465 - iov = kmsg->free_iov; 471 + iov = kmsg->vec.iovec; 466 472 if (!iov) 467 473 iov = &kmsg->fast_iov; 468 474 ··· 578 584 .nr_iovs = 1, 579 585 }; 580 586 581 - if (kmsg->free_iov) { 582 - arg.nr_iovs = kmsg->free_iov_nr; 583 - arg.iovs = kmsg->free_iov; 587 + if (kmsg->vec.iovec) { 588 + arg.nr_iovs = kmsg->vec.nr; 589 + arg.iovs = kmsg->vec.iovec; 584 590 arg.mode = KBUF_MODE_FREE; 585 591 } 586 592 ··· 593 599 if (unlikely(ret < 0)) 594 600 return ret; 595 601 596 - if (arg.iovs != &kmsg->fast_iov && arg.iovs != kmsg->free_iov) { 597 - kmsg->free_iov_nr = ret; 598 - kmsg->free_iov = arg.iovs; 602 + if (arg.iovs != &kmsg->fast_iov && arg.iovs != kmsg->vec.iovec) { 603 + kmsg->vec.nr = ret; 604 + kmsg->vec.iovec = arg.iovs; 599 605 req->flags |= REQ_F_NEED_CLEANUP; 600 606 } 601 607 sr->len = arg.out_len; ··· 1079 1085 .mode = KBUF_MODE_EXPAND, 1080 1086 }; 1081 1087 1082 - if (kmsg->free_iov) { 1083 - arg.nr_iovs = kmsg->free_iov_nr; 1084 - arg.iovs = kmsg->free_iov; 1088 + if (kmsg->vec.iovec) { 1089 + arg.nr_iovs = kmsg->vec.nr; 1090 + arg.iovs = kmsg->vec.iovec; 1085 1091 arg.mode |= KBUF_MODE_FREE; 1086 1092 } 1087 1093 ··· 1100 1106 } 1101 1107 iov_iter_init(&kmsg->msg.msg_iter, ITER_DEST, arg.iovs, ret, 1102 1108 arg.out_len); 1103 - if (arg.iovs != &kmsg->fast_iov && arg.iovs != kmsg->free_iov) { 1104 - kmsg->free_iov_nr = ret; 1105 - kmsg->free_iov = arg.iovs; 1109 + if (arg.iovs != &kmsg->fast_iov && arg.iovs != kmsg->vec.iovec) { 1110 + kmsg->vec.nr = ret; 1111 + kmsg->vec.iovec = arg.iovs; 1106 1112 req->flags |= REQ_F_NEED_CLEANUP; 1107 1113 } 1108 1114 } else { ··· 1868 1874 { 1869 1875 struct io_async_msghdr *kmsg = (struct io_async_msghdr *) entry; 1870 1876 1871 - if (kmsg->free_iov) 1872 - io_netmsg_iovec_free(kmsg); 1877 + io_vec_free(&kmsg->vec); 1873 1878 kfree(kmsg); 1874 1879 } 1875 1880 #endif
+3 -3
io_uring/net.h
··· 2 2 3 3 #include <linux/net.h> 4 4 #include <linux/uio.h> 5 + #include <linux/io_uring_types.h> 5 6 6 7 struct io_async_msghdr { 7 8 #if defined(CONFIG_NET) 8 - struct iovec *free_iov; 9 - /* points to an allocated iov, if NULL we use fast_iov instead */ 10 - int free_iov_nr; 9 + struct iou_vec vec; 10 + 11 11 struct_group(clear, 12 12 int namelen; 13 13 struct iovec fast_iov;