From: "Clément Léger" <cleger@meta.com>
To: Jens Axboe <axboe@kernel.dk>
Cc: "Clément Léger" <cleger@meta.com>,
io-uring@vger.kernel.org, linux-kernel@vger.kernel.org,
"Juanlu Herrero" <jlhe0197@meta.com>
Subject: [PATCH v2 2/3] io_uring/net: Add bundle support for recvmsg
Date: Mon, 23 Nov 2026 13:39:19 -0800 [thread overview]
Message-ID: <20261123213952.824008-3-cleger@meta.com> (raw)
In-Reply-To: <20261123213952.824008-1-cleger@meta.com>
Implement IORING_RECVSEND_BUNDLE support for IORING_OP_RECVMSG. Single
shot requests return the name and control data through the user msghdr,
so only the payload is stored in the provided buffers and is bundled as
for recv. Most of the code for bundle support is already there, just
wire the call to io_recv_bundle_peek() and modify the check to allow for
bundles with non-multishot.
Signed-off-by: Clément Léger <cleger@meta.com>
---
io_uring/net.c | 62 ++++++++++++++++++++++++++++++++++++++++----------
1 file changed, 50 insertions(+), 12 deletions(-)
diff --git a/io_uring/net.c b/io_uring/net.c
index 6c9cfef7ed5c..4c9d21db1409 100644
--- a/io_uring/net.c
+++ b/io_uring/net.c
@@ -848,7 +848,8 @@ int io_recvmsg_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe)
}
if (sr->flags & IORING_RECVSEND_BUNDLE) {
- if (req->opcode == IORING_OP_RECVMSG)
+ if (req->opcode == IORING_OP_RECVMSG &&
+ sr->flags & IORING_RECV_MULTISHOT)
return -EINVAL;
}
@@ -917,7 +918,8 @@ static inline bool io_recv_finish(struct io_kiocb *req,
* If more is available AND it was a full transfer, retry and
* append to this one
*/
- if (!(sr->flags & IORING_RECV_NO_RETRY) &&
+ if (req->opcode != IORING_OP_RECVMSG &&
+ !(sr->flags & IORING_RECV_NO_RETRY) &&
kmsg->msg.msg_inq > 1 && this_ret > 0 &&
!iov_iter_count(&kmsg->msg.msg_iter)) {
req->cqe.flags = cflags & ~CQE_F_MASK;
@@ -1079,29 +1081,65 @@ static int io_recv_bundle_peek(struct io_kiocb *req,
return nr_iovs;
}
+static int io_recvmsg_bundle_select(struct io_kiocb *req,
+ struct io_async_msghdr *kmsg,
+ struct io_br_sel *sel)
+{
+ struct io_sr_msg *sr = io_kiocb_to_cmd(req, struct io_sr_msg);
+ struct buf_sel_arg arg;
+ int nr_iovs;
+
+ nr_iovs = io_recv_bundle_peek(req, kmsg, sel, &arg, sr->len);
+ if (unlikely(nr_iovs <= 0))
+ return !nr_iovs ? -ENOBUFS : nr_iovs;
+
+ if (!sel->buf_list)
+ arg.out_len = arg.iovs[0].iov_len;
+
+ if (nr_iovs == 1)
+ iov_iter_ubuf(&kmsg->msg.msg_iter, ITER_DEST,
+ arg.iovs[0].iov_base, arg.out_len);
+ else
+ iov_iter_init(&kmsg->msg.msg_iter, ITER_DEST, arg.iovs,
+ nr_iovs, arg.out_len);
+ return 0;
+}
+
static int io_recvmsg_buf_select(struct io_kiocb *req,
struct io_async_msghdr *kmsg,
struct io_br_sel *sel,
unsigned int issue_flags)
{
struct io_sr_msg *sr = io_kiocb_to_cmd(req, struct io_sr_msg);
- size_t len = sr->len;
int ret;
- *sel = io_buffer_select(req, &len, sr->buf_group, issue_flags);
- if (!sel->addr)
- return -ENOBUFS;
- len = min_t(size_t, len, MAX_RW_COUNT);
-
- if (req->flags & REQ_F_APOLL_MULTISHOT) {
- ret = io_recvmsg_prep_multishot(kmsg, sr, &sel->addr, &len);
- if (ret) {
+ if (!(issue_flags & IO_URING_F_UNLOCKED) &&
+ sr->flags & IORING_RECVSEND_BUNDLE) {
+ ret = io_recvmsg_bundle_select(req, kmsg, sel);
+ if (unlikely(ret < 0)) {
io_kbuf_recycle(req, sel->buf_list, issue_flags);
return ret;
}
+ } else {
+ size_t len = sr->len;
+
+ *sel = io_buffer_select(req, &len, sr->buf_group, issue_flags);
+ if (!sel->addr)
+ return -ENOBUFS;
+ len = min_t(size_t, len, MAX_RW_COUNT);
+
+ if (req->flags & REQ_F_APOLL_MULTISHOT) {
+ ret = io_recvmsg_prep_multishot(kmsg, sr, &sel->addr,
+ &len);
+ if (ret) {
+ io_kbuf_recycle(req, sel->buf_list, issue_flags);
+ return ret;
+ }
+ }
+
+ iov_iter_ubuf(&kmsg->msg.msg_iter, ITER_DEST, sel->addr, len);
}
- iov_iter_ubuf(&kmsg->msg.msg_iter, ITER_DEST, sel->addr, len);
return 0;
}
--
2.53.1-Meta
next prev parent reply other threads:[~2026-11-23 21:40 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-23 21:39 [PATCH v2 0/3] " Clément Léger
2026-11-23 21:39 ` [PATCH v2 1/3] io_uring/net: Factor out receive buffer selection Clément Léger
2026-11-23 21:39 ` Clément Léger [this message]
2026-11-23 21:39 ` [PATCH v2 3/3] io_uring/net: Add bundle support for multishot recvmsg Clément Léger
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=20261123213952.824008-3-cleger@meta.com \
--to=cleger@meta.com \
--cc=axboe@kernel.dk \
--cc=io-uring@vger.kernel.org \
--cc=jlhe0197@meta.com \
--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®