mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Yichong Chen <chenyichong@uniontech.com>
To: Jens Axboe <axboe@kernel.dk>, io-uring@vger.kernel.org
Cc: Pavel Begunkov <asml.silence@gmail.com>, linux-kernel@vger.kernel.org
Subject: [PATCH] io_uring/kbuf: only drop an old buffer list on success
Date: Thu, 19 Nov 2026 12:10:17 +0800	[thread overview]
Message-ID: <20261119041017.1118227-1-chenyichong@uniontech.com> (raw)

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


                 reply	other threads:[~2026-11-19  4:10 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261119041017.1118227-1-chenyichong@uniontech.com \
    --to=chenyichong@uniontech.com \
    --cc=asml.silence@gmail.com \
    --cc=axboe@kernel.dk \
    --cc=io-uring@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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®