Skip to contentSkip to conversation

io_uring/kbuf: only drop an old buffer list on success

PATCH New Yichong Chen 1 participant 1 message Nov 19 io_uring

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 io_uring/kbuf: only drop an old buffer list on success

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")
---
 io_uring/kbuf.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
io_uring/kbuf.c +4 -2
index abf44f5..e785ca8 100644
@@ -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;
Signature · 1 line
2.51.0