* [PATCH] io_uring/rw: free potentially allocated iovec on cache put failure
@ 2026-01-19 3:15 ` Jens Axboe
2026-01-19 8:59 ` Nitesh Shetty
0 siblings, 1 reply; 2+ messages in thread
From: Jens Axboe @ 2026-01-19 3:15 UTC (permalink / raw)
To: io-uring
If a read/write request goes through io_req_rw_cleanup() and has an
allocated iovec attached and fails to put to the rw_cache, then it may
end up with an unaccounted iovec pointer. Have io_rw_recycle() return
whether it recycled the request or not, and use that to gauge whether to
free a potential iovec or not.
Signed-off-by: Jens Axboe <axboe@kernel.dk>
---
diff --git a/io_uring/rw.c b/io_uring/rw.c
index 331af6bf4234..2b7521129f8b 100644
--- a/io_uring/rw.c
+++ b/io_uring/rw.c
@@ -144,19 +144,22 @@ static inline int io_import_rw_buffer(int rw, struct io_kiocb *req,
return 0;
}
-static void io_rw_recycle(struct io_kiocb *req, unsigned int issue_flags)
+static bool io_rw_recycle(struct io_kiocb *req, unsigned int issue_flags)
{
struct io_async_rw *rw = req->async_data;
if (unlikely(issue_flags & IO_URING_F_UNLOCKED))
- return;
+ return false;
io_alloc_cache_vec_kasan(&rw->vec);
if (rw->vec.nr > IO_VEC_CACHE_SOFT_CAP)
io_vec_free(&rw->vec);
- if (io_alloc_cache_put(&req->ctx->rw_cache, rw))
+ if (io_alloc_cache_put(&req->ctx->rw_cache, rw)) {
io_req_async_data_clear(req, 0);
+ return true;
+ }
+ return false;
}
static void io_req_rw_cleanup(struct io_kiocb *req, unsigned int issue_flags)
@@ -190,7 +193,11 @@ static void io_req_rw_cleanup(struct io_kiocb *req, unsigned int issue_flags)
*/
if (!(req->flags & (REQ_F_REISSUE | REQ_F_REFCOUNT))) {
req->flags &= ~REQ_F_NEED_CLEANUP;
- io_rw_recycle(req, issue_flags);
+ if (!io_rw_recycle(req, issue_flags)) {
+ struct io_async_rw *rw = req->async_data;
+
+ io_vec_free(&rw->vec);
+ }
}
}
--
Jens Axboe
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] io_uring/rw: free potentially allocated iovec on cache put failure
2026-01-19 3:15 ` [PATCH] io_uring/rw: free potentially allocated iovec on cache put failure Jens Axboe
@ 2026-01-19 8:59 ` Nitesh Shetty
0 siblings, 0 replies; 2+ messages in thread
From: Nitesh Shetty @ 2026-01-19 8:59 UTC (permalink / raw)
To: Jens Axboe; +Cc: io-uring
[-- Attachment #1: Type: text/plain, Size: 457 bytes --]
On 18/01/26 08:15PM, Jens Axboe wrote:
>If a read/write request goes through io_req_rw_cleanup() and has an
>allocated iovec attached and fails to put to the rw_cache, then it may
>end up with an unaccounted iovec pointer. Have io_rw_recycle() return
>whether it recycled the request or not, and use that to gauge whether to
>free a potential iovec or not.
>
>Signed-off-by: Jens Axboe <axboe@kernel.dk>
>
Reviewed-by: Nitesh Shetty <nj.shetty@samsung.com>
[-- Attachment #2: Type: text/plain, Size: 0 bytes --]
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-01-19 9:03 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
[not found] <CGME20260119090328epcas5p3457c9dbb7c69f70a3988e5f8f77c51d7@epcas5p3.samsung.com>
2026-01-19 3:15 ` [PATCH] io_uring/rw: free potentially allocated iovec on cache put failure Jens Axboe
2026-01-19 8:59 ` Nitesh Shetty
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox