public inbox for io-uring@vger.kernel.org
 help / color / mirror / Atom feed
From: Jens Axboe <axboe@kernel.dk>
To: io-uring <io-uring@vger.kernel.org>
Subject: [PATCH] io_uring/kbuf: don't early commit provided ring buffers if locked
Date: Mon, 26 Jan 2026 11:09:57 -0700	[thread overview]
Message-ID: <8d8921ff-4fdb-4927-ac72-e48a96c274e9@kernel.dk> (raw)

If multiple buffers are peeked, they need not get committed upfront if
the caller has the uring_lock held - for that case, rely on the caller
recycling or committing before dropping the lock. This can happen if the
operation fails and needs to punt to polling, for example.

Link: https://github.com/axboe/liburing/discussions/1528
Cc: stable@vger.kernel.org
Fixes: 35c8711c8fc4 ("io_uring/kbuf: add helpers for getting/peeking multiple buffers")
Signed-off-by: Jens Axboe <axboe@kernel.dk>

---

diff --git a/io_uring/kbuf.c b/io_uring/kbuf.c
index 796d131107dd..427e80748580 100644
--- a/io_uring/kbuf.c
+++ b/io_uring/kbuf.c
@@ -328,14 +328,15 @@ int io_buffers_select(struct io_kiocb *req, struct buf_sel_arg *arg,
 	if (sel->buf_list->flags & IOBL_BUF_RING) {
 		ret = io_ring_buffers_peek(req, arg, sel->buf_list);
 		/*
-		 * Don't recycle these buffers if we need to go through poll.
-		 * Nobody else can use them anyway, and holding on to provided
-		 * buffers for a send/write operation would happen on the app
-		 * side anyway with normal buffers. Besides, we already
-		 * committed them, they cannot be put back in the queue.
+		 * Allow recyling of these buffers only if we arrived here
+		 * in a locked state. That relies on the caller doing the
+		 * proper recycling under the lock, if it doesn't commit under
+		 * the lock.
 		 */
 		if (ret > 0) {
-			req->flags |= REQ_F_BUFFERS_COMMIT | REQ_F_BL_NO_RECYCLE;
+			req->flags |= REQ_F_BUFFERS_COMMIT;
+			if (issue_flags & IO_URING_F_UNLOCKED)
+				req->flags |= REQ_F_BL_NO_RECYCLE;
 			io_kbuf_commit(req, sel->buf_list, arg->out_len, ret);
 		}
 	} else {

-- 
Jens Axboe


                 reply	other threads:[~2026-01-26 18: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=8d8921ff-4fdb-4927-ac72-e48a96c274e9@kernel.dk \
    --to=axboe@kernel.dk \
    --cc=io-uring@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