summaryrefslogtreecommitdiff
path: root/io_uring/net.c
diff options
context:
space:
mode:
authorGabriel Krisman Bertazi <krisman@suse.de>2024-12-16 15:46:12 -0500
committerJens Axboe <axboe@kernel.dk>2024-12-27 10:07:48 -0700
commitf49a85371d8c1b44650ce660652a2fe305d3ddf6 (patch)
tree31a6a29c6665a7a2d327e408d6a6dadd0349c034 /io_uring/net.c
parente9447dc0b18db40f7c9807f8d0a218f0fa07517f (diff)
io_uring/net: Allocate msghdr async data through helper
This abstracts away the cache details. Signed-off-by: Gabriel Krisman Bertazi <krisman@suse.de> Link: https://lore.kernel.org/r/20241216204615.759089-7-krisman@suse.de Signed-off-by: Jens Axboe <axboe@kernel.dk>
Diffstat (limited to 'io_uring/net.c')
-rw-r--r--io_uring/net.c35
1 files changed, 18 insertions, 17 deletions
diff --git a/io_uring/net.c b/io_uring/net.c
index df1f7dc6f1c8..8457408194e7 100644
--- a/io_uring/net.c
+++ b/io_uring/net.c
@@ -155,30 +155,31 @@ static void io_netmsg_recycle(struct io_kiocb *req, unsigned int issue_flags)
}
}
+static void io_msg_async_data_init(void *obj)
+{
+ struct io_async_msghdr *hdr = (struct io_async_msghdr *)obj;
+
+ hdr->free_iov = NULL;
+ hdr->free_iov_nr = 0;
+}
+
static struct io_async_msghdr *io_msg_alloc_async(struct io_kiocb *req)
{
struct io_ring_ctx *ctx = req->ctx;
struct io_async_msghdr *hdr;
- hdr = io_alloc_cache_get(&ctx->netmsg_cache);
- if (hdr) {
- if (hdr->free_iov) {
- kasan_mempool_unpoison_object(hdr->free_iov,
- hdr->free_iov_nr * sizeof(struct iovec));
- req->flags |= REQ_F_NEED_CLEANUP;
- }
- req->flags |= REQ_F_ASYNC_DATA;
- req->async_data = hdr;
- return hdr;
- }
+ hdr = io_uring_alloc_async_data(&ctx->netmsg_cache, req,
+ io_msg_async_data_init);
+ if (!hdr)
+ return NULL;
- if (!io_alloc_async_data(req)) {
- hdr = req->async_data;
- hdr->free_iov_nr = 0;
- hdr->free_iov = NULL;
- return hdr;
+ /* If the async data was cached, we might have an iov cached inside. */
+ if (hdr->free_iov) {
+ kasan_mempool_unpoison_object(hdr->free_iov,
+ hdr->free_iov_nr * sizeof(struct iovec));
+ req->flags |= REQ_F_NEED_CLEANUP;
}
- return NULL;
+ return hdr;
}
/* assign new iovec to kmsg, if we need to */