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: 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>

authored by

Gabriel Krisman Bertazi and committed by
Jens Axboe
f49a8537 e9447dc0

+18 -17
+18 -17
io_uring/net.c
··· 155 155 } 156 156 } 157 157 158 + static void io_msg_async_data_init(void *obj) 159 + { 160 + struct io_async_msghdr *hdr = (struct io_async_msghdr *)obj; 161 + 162 + hdr->free_iov = NULL; 163 + hdr->free_iov_nr = 0; 164 + } 165 + 158 166 static struct io_async_msghdr *io_msg_alloc_async(struct io_kiocb *req) 159 167 { 160 168 struct io_ring_ctx *ctx = req->ctx; 161 169 struct io_async_msghdr *hdr; 162 170 163 - hdr = io_alloc_cache_get(&ctx->netmsg_cache); 164 - if (hdr) { 165 - if (hdr->free_iov) { 166 - kasan_mempool_unpoison_object(hdr->free_iov, 167 - hdr->free_iov_nr * sizeof(struct iovec)); 168 - req->flags |= REQ_F_NEED_CLEANUP; 169 - } 170 - req->flags |= REQ_F_ASYNC_DATA; 171 - req->async_data = hdr; 172 - return hdr; 173 - } 171 + hdr = io_uring_alloc_async_data(&ctx->netmsg_cache, req, 172 + io_msg_async_data_init); 173 + if (!hdr) 174 + return NULL; 174 175 175 - if (!io_alloc_async_data(req)) { 176 - hdr = req->async_data; 177 - hdr->free_iov_nr = 0; 178 - hdr->free_iov = NULL; 179 - return hdr; 176 + /* If the async data was cached, we might have an iov cached inside. */ 177 + if (hdr->free_iov) { 178 + kasan_mempool_unpoison_object(hdr->free_iov, 179 + hdr->free_iov_nr * sizeof(struct iovec)); 180 + req->flags |= REQ_F_NEED_CLEANUP; 180 181 } 181 - return NULL; 182 + return hdr; 182 183 } 183 184 184 185 /* assign new iovec to kmsg, if we need to */