Skip to contentSkip to conversation

io_uring/net: disable partial retries for recvmsg with cmsg

PATCH Superseded Jens Axboe 2 participants 3 messages Jun 19, 2023 – Jun 20, 2023 io_uring

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Jens Axboe

author maintainer
#0 lore raw

PATCH 1/1 io_uring/net: disable partial retries for recvmsg with cmsg

We cannot sanely handle partial retries for recvmsg if we have cmsg attached. If we don't, then we'd just be overwriting the initial cmsg header on retries. Alternatively we could increment and handle this appropriately, but it doesn't seem worth the complication.

---

io_uring/net.c +2 -1
index fe1c478c7dec..6674a0759390 100644
@@ -788,7 +788,8 @@ int io_recvmsg(struct io_kiocb *req, unsigned int issue_flags)
 	flags = sr->msg_flags;
 	if (force_nonblock)
 		flags |= MSG_DONTWAIT;
-	if (flags & MSG_WAITALL)
+	/* disable partial retry for recvmsg with cmsg attached */
+	if (flags & MSG_WAITALL && !kmsg->controllen)
 		min_ret = iov_iter_count(&kmsg->msg.msg_iter);
 
 	kmsg->msg.msg_get_inq = 1;
Signature · 1 line
Jens Axboe
#1 lore raw

Hi Jens,

Quoted 17 lines

We cannot sanely handle partial retries for recvmsg if we have cmsg attached. If we don't, then we'd just be overwriting the initial cmsg header on retries. Alternatively we could increment and handle this appropriately, but it doesn't seem worth the complication.

---

io_uring/net.c +0 -0
index fe1c478c7dec..6674a0759390 100644

io_uring/net.c int io_recvmsg(struct io_kiocb *req, unsigned int issue_flags) · line 793

Quoted 7 lines
io_uring/net.c +2 -1
@@ -788,7 +788,8 @@ int io_recvmsg(struct io_kiocb *req, unsigned int issue_flags)
  	flags = sr->msg_flags;
  	if (force_nonblock)
  		flags |= MSG_DONTWAIT;
-	if (flags & MSG_WAITALL)
+	/* disable partial retry for recvmsg with cmsg attached */
+	if (flags & MSG_WAITALL && !kmsg->controllen)
  		min_ret = iov_iter_count(&kmsg->msg.msg_iter);

Isn't kmsg->controllen only used for REQ_F_APOLL_MULTISHOT?

I guess the correct value would be kmsg->msg.msg_controllen?

Maybe the safest change would be something like this (completely untested!):

io_uring/net.c +2 -2
index 89e839013837..1dd5322fb732 100644
@@ -781,14 +781,14 @@ int io_recvmsg(struct io_kiocb *req, unsigned int issue_flags)
 	flags = sr->msg_flags;
 	if (force_nonblock)
 		flags |= MSG_DONTWAIT;
-	if (flags & MSG_WAITALL)
-		min_ret = iov_iter_count(&kmsg->msg.msg_iter);
 
 	kmsg->msg.msg_get_inq = 1;
 	if (req->flags & REQ_F_APOLL_MULTISHOT)
 		ret = io_recvmsg_multishot(sock, sr, kmsg, flags,
 					   &mshot_finished);
 	else
+		if (flags & MSG_WAITALL && !kmsg->msg.msg_controllen)
+			min_ret = iov_iter_count(&kmsg->msg.msg_iter);
 		ret = __sys_recvmsg_sock(sock, &kmsg->msg, sr->umsg,
 					 kmsg->uaddr, flags);
 

metze

author maintainer
#2 lore raw
Quoted 29 lines · Stefan Metzmacher

Hi Jens,

Quoted 17 lines

We cannot sanely handle partial retries for recvmsg if we have cmsg attached. If we don't, then we'd just be overwriting the initial cmsg header on retries. Alternatively we could increment and handle this appropriately, but it doesn't seem worth the complication.

---

io_uring/net.c +0 -0
index fe1c478c7dec..6674a0759390 100644

io_uring/net.c int io_recvmsg(struct io_kiocb *req, unsigned int issue_flags) · line 793

Quoted 7 lines
io_uring/net.c +2 -1
@@ -788,7 +788,8 @@ int io_recvmsg(struct io_kiocb *req, unsigned int issue_flags)
      flags = sr->msg_flags;
      if (force_nonblock)
          flags |= MSG_DONTWAIT;
-    if (flags & MSG_WAITALL)
+    /* disable partial retry for recvmsg with cmsg attached */
+    if (flags & MSG_WAITALL && !kmsg->controllen)
          min_ret = iov_iter_count(&kmsg->msg.msg_iter);

Isn't kmsg->controllen only used for REQ_F_APOLL_MULTISHOT?

Quoted 1 line

I guess the correct value would be kmsg->msg.msg_controllen?

Gah, yes indeed it should!

Quoted 12 lines

Maybe the safest change would be something like this (completely untested!):

io_uring/net.c +0 -2
index 89e839013837..1dd5322fb732 100644
@@ -781,14 +781,14 @@ int io_recvmsg(struct io_kiocb *req, unsigned int issue_flags)
     flags = sr->msg_flags;
     if (force_nonblock)
         flags |= MSG_DONTWAIT;
-    if (flags & MSG_WAITALL)
-        min_ret = iov_iter_count(&kmsg->msg.msg_iter);

io_uring/net.c int io_recvmsg(struct io_kiocb *req, unsigned int issue_flags) · line 793

Quoted 10 lines
io_uring/net.c +2 -0
 
     kmsg->msg.msg_get_inq = 1;
     if (req->flags & REQ_F_APOLL_MULTISHOT)
         ret = io_recvmsg_multishot(sock, sr, kmsg, flags,
                        &mshot_finished);
     else
+        if (flags & MSG_WAITALL && !kmsg->msg.msg_controllen)
+            min_ret = iov_iter_count(&kmsg->msg.msg_iter);
         ret = __sys_recvmsg_sock(sock, &kmsg->msg, sr->umsg,
                      kmsg->uaddr, flags);

I like putting it there, as MSG_WAITALL is explicitly disallowed for multishot anyway. The check belongs in that branch rather than as a whole.

Signature · 1 line
Jens Axboe