public inbox for io-uring@vger.kernel.org
 help / color / mirror / Atom feed
From: "Clément Léger" <cleger@meta.com>
To: <io-uring@vger.kernel.org>, Jens Axboe <axboe@kernel.dk>
Cc: "Clément Léger" <cleger@meta.com>
Subject: [PATCH] io_uring/net: inherit IORING_CQE_F_BUF_MORE across bundle recv retries
Date: Thu, 4 Jun 2026 09:07:13 -0700	[thread overview]
Message-ID: <20260604160715.2482972-1-cleger@meta.com> (raw)

When a bundle recv retries inside io_recv_finish(), the merge logic
OR the saved cflags from the previous iteration with the cflags
returned by the new iteration:
  cflags = req->cqe.flags | (cflags & CQE_F_MASK);

Bits listed in CQE_F_MASK are inherited from the new iteration, and
all other bits (notably IORING_CQE_F_BUFFER and the buffer ID) come
from the saved cflags. Before this change CQE_F_MASK covered only
IORING_CQE_F_SOCK_NONEMPTY and IORING_CQE_F_MORE.

When using provided buffer rings (IOU_PBUF_RING_INC) with incremental
mode, and bundle recv, io_kbuf_inc_commit() can leave the head ring
entry partially consumed, __io_put_kbufs() then sets
IORING_CQE_F_BUF_MORE on the returned cflags so userspace knows the
buffer ID will be reused for subsequent completions.

Because IORING_CQE_F_BUF_MORE was not in CQE_F_MASK, the merge above
silently dropped it whenever the final retry iteration partially consumed
the buffer, and the subsequent req->cqe.flags = cflags & ~CQE_F_MASK
save would have left a stale IORING_CQE_F_BUF_MORE in the carried-over
cflags had one been present. Userspace would then wrongfully advance it
ring head past an entry the kernel still uses.

Add IORING_CQE_F_BUF_MORE to CQE_F_MASK so it is both inherited from
the new iteration into the user-visible CQE and stripped from the
saved cflags between iterations.

A test available in https://github.com/clementleger/liburing/tree/bug_f_buf_more
allows to validate this fix.

Signed-off-by: Clément Léger <cleger@meta.com>
Assisted-by: Claude:claude-opus-4.6
---
 io_uring/net.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/io_uring/net.c b/io_uring/net.c
index 8df15b639358..ee848eb65ec9 100644
--- a/io_uring/net.c
+++ b/io_uring/net.c
@@ -842,7 +842,8 @@ int io_recvmsg_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe)
 }

 /* bits to clear in old and inherit in new cflags on bundle retry */
-#define CQE_F_MASK	(IORING_CQE_F_SOCK_NONEMPTY|IORING_CQE_F_MORE)
+#define CQE_F_MASK	(IORING_CQE_F_SOCK_NONEMPTY|IORING_CQE_F_MORE|\
+			 IORING_CQE_F_BUF_MORE)

 /*
  * Finishes io_recv and io_recvmsg.
--
2.53.0-Meta

             reply	other threads:[~2026-06-04 16:07 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-06-04 16:07 Clément Léger [this message]
2026-06-04 19:43 ` [PATCH] io_uring/net: inherit IORING_CQE_F_BUF_MORE across bundle recv retries Jens Axboe
2026-06-05 11:21 ` Jens Axboe

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=20260604160715.2482972-1-cleger@meta.com \
    --to=cleger@meta.com \
    --cc=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