public inbox for io-uring@vger.kernel.org
 help / color / mirror / Atom feed
From: Jens Axboe <axboe@kernel.dk>
To: io-uring@vger.kernel.org
Cc: Jens Axboe <axboe@kernel.dk>
Subject: [PATCH 2/2] io_uring/net: add IORING_CQE_F_SOCK_FULL if a send needed to poll arm
Date: Wed,  5 Nov 2025 12:30:59 -0700	[thread overview]
Message-ID: <20251105193639.235441-3-axboe@kernel.dk> (raw)
In-Reply-To: <20251105193639.235441-1-axboe@kernel.dk>

If a send/sendmsg/sendzc/sendmsgzc needed to wait for space in the
socket to complete, add IORING_CQE_F_SOCK_FULL to the cqe->flags to tell
the application about it. This meant that the socket was full when the
operation was attempted.

This adds IORING_CQE_F_SOCK_FULL as a new CQE flag. It borrows the value
of IORING_CQE_F_SOCK_NONEMPTY, which is a flag only used on the receive
side. Hence there can be no confusion on which of the two meanings is
included in a given CQE, as the application must know which kind of
operation the completion refers to.

Signed-off-by: Jens Axboe <axboe@kernel.dk>
---
 include/uapi/linux/io_uring.h |  4 ++++
 io_uring/net.c                | 19 +++++++++++++------
 2 files changed, 17 insertions(+), 6 deletions(-)

diff --git a/include/uapi/linux/io_uring.h b/include/uapi/linux/io_uring.h
index e96080db3e4d..3d921cbb84f8 100644
--- a/include/uapi/linux/io_uring.h
+++ b/include/uapi/linux/io_uring.h
@@ -495,6 +495,9 @@ struct io_uring_cqe {
  * IORING_CQE_F_BUFFER	If set, the upper 16 bits are the buffer ID
  * IORING_CQE_F_MORE	If set, parent SQE will generate more CQE entries
  * IORING_CQE_F_SOCK_NONEMPTY	If set, more data to read after socket recv
+ * IORING_CQE_F_SOCK_FULL	If set, the socket was full when this send or
+ *			sendmsg was attempted. Hence it had to wait for POLLOUT
+ *			before being able to complete.
  * IORING_CQE_F_NOTIF	Set for notification CQEs. Can be used to distinct
  * 			them from sends.
  * IORING_CQE_F_BUF_MORE If set, the buffer ID set in the completion will get
@@ -518,6 +521,7 @@ struct io_uring_cqe {
 #define IORING_CQE_F_BUFFER		(1U << 0)
 #define IORING_CQE_F_MORE		(1U << 1)
 #define IORING_CQE_F_SOCK_NONEMPTY	(1U << 2)
+#define IORING_CQE_F_SOCK_FULL		IORING_CQE_F_SOCK_NONEMPTY
 #define IORING_CQE_F_NOTIF		(1U << 3)
 #define IORING_CQE_F_BUF_MORE		(1U << 4)
 #define IORING_CQE_F_SKIP		(1U << 5)
diff --git a/io_uring/net.c b/io_uring/net.c
index a95cc9ca2a4d..6a834237fd5c 100644
--- a/io_uring/net.c
+++ b/io_uring/net.c
@@ -530,11 +530,21 @@ static inline bool io_send_finish(struct io_kiocb *req,
 
 	/* Otherwise stop bundle and use the current result. */
 finish:
+	if (req->flags & REQ_F_POLL_TRIGGERED)
+		cflags |= IORING_CQE_F_SOCK_FULL;
 	io_req_set_res(req, sel->val, cflags);
 	sel->val = IOU_COMPLETE;
 	return true;
 }
 
+static int io_send_complete(struct io_kiocb *req, int ret, unsigned cflags)
+{
+	if (req->flags & REQ_F_POLL_TRIGGERED)
+		cflags |= IORING_CQE_F_SOCK_FULL;
+	io_req_set_res(req, ret, cflags);
+	return IOU_COMPLETE;
+}
+
 int io_sendmsg(struct io_kiocb *req, unsigned int issue_flags)
 {
 	struct io_sr_msg *sr = io_kiocb_to_cmd(req, struct io_sr_msg);
@@ -580,8 +590,7 @@ int io_sendmsg(struct io_kiocb *req, unsigned int issue_flags)
 		ret += sr->done_io;
 	else if (sr->done_io)
 		ret = sr->done_io;
-	io_req_set_res(req, ret, 0);
-	return IOU_COMPLETE;
+	return io_send_complete(req, ret, 0);
 }
 
 static int io_send_select_buffer(struct io_kiocb *req, unsigned int issue_flags,
@@ -1516,8 +1525,7 @@ int io_send_zc(struct io_kiocb *req, unsigned int issue_flags)
 		zc->notif = NULL;
 		io_req_msg_cleanup(req, 0);
 	}
-	io_req_set_res(req, ret, IORING_CQE_F_MORE);
-	return IOU_COMPLETE;
+	return io_send_complete(req, ret, IORING_CQE_F_MORE);
 }
 
 int io_sendmsg_zc(struct io_kiocb *req, unsigned int issue_flags)
@@ -1586,8 +1594,7 @@ int io_sendmsg_zc(struct io_kiocb *req, unsigned int issue_flags)
 		sr->notif = NULL;
 		io_req_msg_cleanup(req, 0);
 	}
-	io_req_set_res(req, ret, IORING_CQE_F_MORE);
-	return IOU_COMPLETE;
+	return io_send_complete(req, ret, IORING_CQE_F_MORE);
 }
 
 void io_sendrecv_fail(struct io_kiocb *req)
-- 
2.51.0


  parent reply	other threads:[~2025-11-05 19:37 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-11-05 19:30 [PATCHSET 0/2] Add support for IORING_CQE_F_SOCK_FULL Jens Axboe
2025-11-05 19:30 ` [PATCH 1/2] io_uring/poll: flag request with REQ_F_POLL_TRIGGERED if it went through poll Jens Axboe
2025-11-05 19:30 ` Jens Axboe [this message]
2025-11-06 12:19 ` [PATCHSET 0/2] Add support for IORING_CQE_F_SOCK_FULL Pavel Begunkov
2025-11-06 23:24   ` 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=20251105193639.235441-3-axboe@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