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>
This commit is contained in:
parent
9fcb349f5a
commit
be7052a4b5
|
@ -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)
|
||||
{
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in New Issue