mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] io_uring/kbuf: only drop an old buffer list on success
@ 2026-11-19  4:10 Yichong Chen
  0 siblings, 0 replies; only message in thread
From: Yichong Chen @ 2026-11-19  4:10 UTC (permalink / raw)
  To: Jens Axboe, io-uring; +Cc: Pavel Begunkov, linux-kernel

A buffer list for the bgid is dropped before the new list is allocated and
before its region is set up, so any failure after that point (-ENOMEM, a
region that cannot be created, or the SHM_COLOUR alignment check) leaves
the caller without the empty legacy group it had. Keep the old list until
the new one is fully set up.

Fixes: 8802766324e1 ("io_uring/kbuf: reallocate buf lists on upgrade")
Signed-off-by: Yichong Chen <chenyichong@uniontech.com>
---
 io_uring/kbuf.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/io_uring/kbuf.c b/io_uring/kbuf.c
index abf44f5..e785ca8 100644
--- a/io_uring/kbuf.c
+++ b/io_uring/kbuf.c
@@ -632,7 +632,7 @@ int io_manage_buffers_legacy(struct io_kiocb *req, unsigned int issue_flags)
 int io_register_pbuf_ring(struct io_ring_ctx *ctx, void __user *arg)
 {
 	struct io_uring_buf_reg reg;
-	struct io_buffer_list *bl;
+	struct io_buffer_list *bl, *old_bl = NULL;
 	struct io_uring_region_desc rd;
 	struct io_uring_buf_ring *br;
 	unsigned long mmap_offset;
@@ -662,7 +662,7 @@ int io_register_pbuf_ring(struct io_ring_ctx *ctx, void __user *arg)
 		/* if mapped buffer ring OR classic exists, don't allow */
 		if (bl->flags & IOBL_BUF_RING || !list_empty(&bl->buf_list))
 			return -EEXIST;
-		io_destroy_bl(ctx, bl);
+		old_bl = bl;
 	}
 
 	bl = kzalloc_obj(*bl, GFP_KERNEL_ACCOUNT);
@@ -707,6 +707,8 @@ int io_register_pbuf_ring(struct io_ring_ctx *ctx, void __user *arg)
 		bl->min_left_sub_one = reg.min_left - 1;
 	if (reg.flags & IOU_PBUF_RING_INC)
 		bl->flags |= IOBL_INC;
+	if (old_bl)
+		io_destroy_bl(ctx, old_bl);
 	ret = io_buffer_add_list(ctx, bl, reg.bgid);
 	if (!ret)
 		return 0;
-- 
2.51.0


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2026-11-19  4:10 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-19  4:10 [PATCH] io_uring/kbuf: only drop an old buffer list on success Yichong Chen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®