fixes for removing provided buffers
cover fixes for removing provided buffers
Hi,
Two fixes for removing provided buffers. They are in the same area, but otherwise unrelated. I'll send a liburing test for the first one shortly.
Thanks,
Wojciech
Wojciech Lukowicz (2):
io_uring: fix return value when removing provided buffers
io_uring: fix memory leak when removing provided buffers
io_uring/io_uring.c | 2 +- io_uring/kbuf.c | 7 ++++--- 2 files changed, 5 insertions(+), 4 deletions(-)
Signature · 1 line
2.30.2
PATCH 1/2 io_uring: fix return value when removing provided buffers
When a request to remove buffers is submitted, and the given number to be removed is larger than available in the specified buffer group, the resulting CQE result will be the number of removed buffers + 1, which is 1 more than it should be.
Previously, the head was part of the list and it got removed after the loop, so the increment was needed. Now, the head is not an element of the list, so the increment shouldn't be there anymore.
--- io_uring/kbuf.c | 2 -- 1 file changed, 2 deletions(-)
io_uring/kbuf.c +0 -2
@@ -228,7 +228,6 @@ static int __io_remove_buffers(struct io_ring_ctx *ctx,return i; } -/* the head kbuf is the list itself */ while (!list_empty (&bl->buf_list)) {struct io_buffer *nxt;
@@ -238,7 +237,6 @@ static int __io_remove_buffers(struct io_ring_ctx *ctx,return i;cond_resched (); } - i++;return i; }
Signature · 1 line
2.30.2
PATCH 2/2 io_uring: fix memory leak when removing provided buffers
In reply to Wojciech LukowiczWhen removing provided buffers, io_buffer structs are not being disposed of, leading to a memory leak. They can't be freed individually, because they are allocated in page-sized groups. They need to be added to some free list instead, such as io_buffers_cache. All callers already hold the lock protecting it, apart from when destroying buffers, so had to extend the lock there.
--- io_uring/io_uring.c | 2 +- io_uring/kbuf.c | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-)
io_uring/io_uring.c +1 -1
@@ -2789,8 +2789,8 @@ static __cold void io_ring_ctx_free(struct io_ring_ctx *ctx)io_eventfd_unregister (ctx);io_alloc_cache_free (&ctx->apoll_cache, io_apoll_cache_free);io_alloc_cache_free (&ctx->netmsg_cache, io_netmsg_cache_free); -mutex_unlock (&ctx->uring_lock);io_destroy_buffers (ctx); +mutex_unlock (&ctx->uring_lock);if (ctx->sq_creds)put_cred (ctx->sq_creds);if (ctx->submitter_task)
io_uring/kbuf.c +4 -1
@@ -228,11 +228,14 @@ static int __io_remove_buffers(struct io_ring_ctx *ctx,return i; } +/* protects io_buffers_cache */ +lockdep_assert_held (&ctx->uring_lock); +while (!list_empty (&bl->buf_list)) {struct io_buffer *nxt; nxt = list_first_entry(&bl->buf_list, struct io_buffer, list); -list_del (&nxt->list); +list_move (&nxt->list, &ctx->io_buffers_cache);if (++i == nbufs)return i;cond_resched ();
Signature · 1 line
2.30.2
Jens Axboe
maintainerQuoted 5 lines · Wojciech Lukowicz
Hi,
Two fixes for removing provided buffers. They are in the same area, but otherwise unrelated. I'll send a liburing test for the first one shortly.
Looks good, thanks for sending these in!
Signature · 1 line
Jens Axboe
Quoted 8 lines · Wojciech Lukowicz
Two fixes for removing provided buffers. They are in the same area, but otherwise unrelated. I'll send a liburing test for the first one shortly.
Thanks,
Wojciech[...]
Applied, thanks!
[1/2] io_uring: fix return value when removing provided buffers
commit: b4a72c0589fdea6259720375426179888969d6a2
[2/2] io_uring: fix memory leak when removing provided buffers
commit: b4a72c0589fdea6259720375426179888969d6a2Best regards,
Signature · 1 line
Jens Axboe