Skip to content

Commit be7052a

Browse files
isilenceaxboe
authored andcommitted
io_uring/net: convert to struct iou_vec
Convert net.c to use struct iou_vec. Signed-off-by: Pavel Begunkov <[email protected]> Link: https://lore.kernel.org/r/6437b57dabed44eca708c02e390529c7ed211c78.1741362889.git.asml.silence@gmail.com Signed-off-by: Jens Axboe <[email protected]>
1 parent 9fcb349 commit be7052a

File tree

3 files changed

+25
-41
lines changed

3 files changed

+25
-41
lines changed

io_uring/alloc_cache.h

-9
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,6 @@ bool io_alloc_cache_init(struct io_alloc_cache *cache,
1616

1717
void *io_cache_alloc_new(struct io_alloc_cache *cache, gfp_t gfp);
1818

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-
2819
static inline bool io_alloc_cache_put(struct io_alloc_cache *cache,
2920
void *entry)
3021
{

io_uring/net.c

+22-29
Original file line numberDiff line numberDiff line change
@@ -136,11 +136,8 @@ static bool io_net_retry(struct socket *sock, int flags)
136136

137137
static void io_netmsg_iovec_free(struct io_async_msghdr *kmsg)
138138
{
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);
144141
}
145142

146143
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)
154151
}
155152

156153
/* Let normal cleanup path reap it if we fail adding to the cache */
157-
io_alloc_cache_kasan(&hdr->free_iov, &hdr->free_iov_nr);
154+
io_alloc_cache_vec_kasan(&hdr->vec);
158155
if (io_alloc_cache_put(&req->ctx->netmsg_cache, hdr)) {
159156
req->async_data = NULL;
160157
req->flags &= ~REQ_F_ASYNC_DATA;
@@ -171,7 +168,7 @@ static struct io_async_msghdr *io_msg_alloc_async(struct io_kiocb *req)
171168
return NULL;
172169

173170
/* If the async data was cached, we might have an iov cached inside. */
174-
if (hdr->free_iov)
171+
if (hdr->vec.iovec)
175172
req->flags |= REQ_F_NEED_CLEANUP;
176173
return hdr;
177174
}
@@ -182,10 +179,7 @@ static void io_net_vec_assign(struct io_kiocb *req, struct io_async_msghdr *kmsg
182179
{
183180
if (iov) {
184181
req->flags |= REQ_F_NEED_CLEANUP;
185-
kmsg->free_iov_nr = kmsg->msg.msg_iter.nr_segs;
186-
if (kmsg->free_iov)
187-
kfree(kmsg->free_iov);
188-
kmsg->free_iov = iov;
182+
io_vec_reset_iovec(&kmsg->vec, iov, kmsg->msg.msg_iter.nr_segs);
189183
}
190184
}
191185

@@ -208,9 +202,9 @@ static int io_net_import_vec(struct io_kiocb *req, struct io_async_msghdr *iomsg
208202
struct iovec *iov;
209203
int ret, nr_segs;
210204

211-
if (iomsg->free_iov) {
212-
nr_segs = iomsg->free_iov_nr;
213-
iov = iomsg->free_iov;
205+
if (iomsg->vec.iovec) {
206+
nr_segs = iomsg->vec.nr;
207+
iov = iomsg->vec.iovec;
214208
} else {
215209
nr_segs = 1;
216210
iov = &iomsg->fast_iov;
@@ -468,7 +462,7 @@ static int io_bundle_nbufs(struct io_async_msghdr *kmsg, int ret)
468462
if (iter_is_ubuf(&kmsg->msg.msg_iter))
469463
return 1;
470464

471-
iov = kmsg->free_iov;
465+
iov = kmsg->vec.iovec;
472466
if (!iov)
473467
iov = &kmsg->fast_iov;
474468

@@ -584,9 +578,9 @@ static int io_send_select_buffer(struct io_kiocb *req, unsigned int issue_flags,
584578
.nr_iovs = 1,
585579
};
586580

587-
if (kmsg->free_iov) {
588-
arg.nr_iovs = kmsg->free_iov_nr;
589-
arg.iovs = kmsg->free_iov;
581+
if (kmsg->vec.iovec) {
582+
arg.nr_iovs = kmsg->vec.nr;
583+
arg.iovs = kmsg->vec.iovec;
590584
arg.mode = KBUF_MODE_FREE;
591585
}
592586

@@ -599,9 +593,9 @@ static int io_send_select_buffer(struct io_kiocb *req, unsigned int issue_flags,
599593
if (unlikely(ret < 0))
600594
return ret;
601595

602-
if (arg.iovs != &kmsg->fast_iov && arg.iovs != kmsg->free_iov) {
603-
kmsg->free_iov_nr = ret;
604-
kmsg->free_iov = arg.iovs;
596+
if (arg.iovs != &kmsg->fast_iov && arg.iovs != kmsg->vec.iovec) {
597+
kmsg->vec.nr = ret;
598+
kmsg->vec.iovec = arg.iovs;
605599
req->flags |= REQ_F_NEED_CLEANUP;
606600
}
607601
sr->len = arg.out_len;
@@ -1085,9 +1079,9 @@ static int io_recv_buf_select(struct io_kiocb *req, struct io_async_msghdr *kmsg
10851079
.mode = KBUF_MODE_EXPAND,
10861080
};
10871081

1088-
if (kmsg->free_iov) {
1089-
arg.nr_iovs = kmsg->free_iov_nr;
1090-
arg.iovs = kmsg->free_iov;
1082+
if (kmsg->vec.iovec) {
1083+
arg.nr_iovs = kmsg->vec.nr;
1084+
arg.iovs = kmsg->vec.iovec;
10911085
arg.mode |= KBUF_MODE_FREE;
10921086
}
10931087

@@ -1106,9 +1100,9 @@ static int io_recv_buf_select(struct io_kiocb *req, struct io_async_msghdr *kmsg
11061100
}
11071101
iov_iter_init(&kmsg->msg.msg_iter, ITER_DEST, arg.iovs, ret,
11081102
arg.out_len);
1109-
if (arg.iovs != &kmsg->fast_iov && arg.iovs != kmsg->free_iov) {
1110-
kmsg->free_iov_nr = ret;
1111-
kmsg->free_iov = arg.iovs;
1103+
if (arg.iovs != &kmsg->fast_iov && arg.iovs != kmsg->vec.iovec) {
1104+
kmsg->vec.nr = ret;
1105+
kmsg->vec.iovec = arg.iovs;
11121106
req->flags |= REQ_F_NEED_CLEANUP;
11131107
}
11141108
} else {
@@ -1874,8 +1868,7 @@ void io_netmsg_cache_free(const void *entry)
18741868
{
18751869
struct io_async_msghdr *kmsg = (struct io_async_msghdr *) entry;
18761870

1877-
if (kmsg->free_iov)
1878-
io_netmsg_iovec_free(kmsg);
1871+
io_vec_free(&kmsg->vec);
18791872
kfree(kmsg);
18801873
}
18811874
#endif

io_uring/net.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22

33
#include <linux/net.h>
44
#include <linux/uio.h>
5+
#include <linux/io_uring_types.h>
56

67
struct io_async_msghdr {
78
#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+
1111
struct_group(clear,
1212
int namelen;
1313
struct iovec fast_iov;

0 commit comments

Comments
 (0)