net: leave O_NONBLOCK to the sendmsg and recvmsg syscalls
Subsystems (3)
PATCH v2 1/1 net: leave O_NONBLOCK to the sendmsg and recvmsg syscalls
____sys_sendmsg() and ____sys_recvmsg() turn O_NONBLOCK on the socket into MSG_DONTWAIT. That is right for the system calls, but io_uring uses __sys_sendmsg_sock() and __sys_recvmsg_sock() for a blocking attempt from io-wq as well, after the non-blocking attempts with MSG_DONTWAIT have failed. On an O_NONBLOCK socket that attempt can't block either and the request completes with -EAGAIN, unlike IORING_OP_SEND and RECV, which call sock_sendmsg() and sock_recvmsg() directly and don't look at O_NONBLOCK at all.
Move the O_NONBLOCK handling to ___sys_sendmsg() and ___sys_recvmsg(), which the sendmsg, sendmmsg, recvmsg and recvmmsg system calls go through. The io_uring helpers then pass the flags the caller asked for.
---
v2: add fixes, CC stable, add link, correct Lukáš, correct subject
net/socket.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-)
net/socket.c +6 -5
@@ -2697,8 +2697,6 @@ static int ____sys_sendmsg(struct socket *sock, struct msghdr *msg_sys, flags &= ~MSG_INTERNAL_SENDMSG_FLAGS ; msg_sys->msg_flags = flags; -if (sock->file->f_flags &O_NONBLOCK ) - msg_sys->msg_flags |=MSG_DONTWAIT ;/* * If this is sendmmsg() and current destination address is same as * previously succeeded address, omit asking LSM's decision.
@@ -2762,6 +2760,9 @@ static int ___sys_sendmsg(struct socket *sock, struct user_msghdr __user *msg, msg_sys->msg_name = &address; +if (sock->file->f_flags &O_NONBLOCK ) + flags |=MSG_DONTWAIT ; + err =sendmsg_copy_msghdr (msg_sys, msg, flags, &iov);if (err <0 )return err;
@@ -2926,9 +2927,6 @@ static int ____sys_recvmsg(struct socket *sock, struct msghdr *msg_sys,/* We assume all kernel code knows the size of sockaddr_storage */ msg_sys->msg_namelen =0 ; -if (sock->file->f_flags &O_NONBLOCK ) - flags |=MSG_DONTWAIT ; -if (unlikely (nosec)) err =sock_recvmsg_nosec (sock, msg_sys, flags);else
@@ -2970,6 +2968,9 @@ static int ___sys_recvmsg(struct socket *sock, struct user_msghdr __user *msg,struct sockaddr __user *uaddr;ssize_t err; +if (sock->file->f_flags &O_NONBLOCK ) + flags |=MSG_DONTWAIT ; + err =recvmsg_copy_msghdr (msg_sys, msg, flags, &uaddr, &iov);if (err <0 )return err;
Signature · 1 line
2.56.0
This patch was applied to netdev/net.git (main) by Dave Miller <[email protected]>:
Hello:
This patch was applied to netdev/net.git (main) by Dave Miller <[email protected]>:
Quoted 10 lines · On Fri, 6 Nov 2026 16:50:46 -0700 you wrote:
____sys_sendmsg()and____sys_recvmsg()turnO_NONBLOCKon the socket intoMSG_DONTWAIT. That is right for the system calls, butio_uringuses__sys_sendmsg_sock()and__sys_recvmsg_sock()for a blocking attempt from io-wq as well, after the non-blocking attempts withMSG_DONTWAIThave failed. On anO_NONBLOCKsocket that attempt can't block either and the request completes with-EAGAIN, unlikeIORING_OP_SENDand RECV, which callsock_sendmsg()andsock_recvmsg()directly and don't look atO_NONBLOCKat all.[...]
Here is the summary with links:
- [net,v2] net: leave O_NONBLOCK to the sendmsg and recvmsg syscalls
https://git.kernel.org/netdev/net/c/bdc350ddbcbe
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html