packet: allow MSG_NOSIGNAL in recvmsg
Subsystems (4)
PATCH 1/1 packet: allow MSG_NOSIGNAL in recvmsg
packet_recvmsg() whitelists a bunch of MSG_* flags, which notably does not include MSG_NOSIGNAL. Unfortunately, io_uring always sets MSG_NOSIGNAL, meaning AF_PACKET sockets can't be used in io_uring recvmsg().
As AF_PACKET sockets never generate SIGPIPE to begin with, MSG_NOSIGNAL is a no-op and can simply be ignored.
--- net/packet/af_packet.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
net/packet/af_packet.c +1 -1
@@ -3410,7 +3410,7 @@ static int packet_recvmsg(struct socket *sock, struct msghdr *msg, size_t len,unsigned int origlen =0 ; err = -EINVAL ; -if (flags & ~(MSG_PEEK |MSG_DONTWAIT |MSG_TRUNC |MSG_CMSG_COMPAT |MSG_ERRQUEUE )) +if (flags & ~(MSG_PEEK |MSG_DONTWAIT |MSG_TRUNC |MSG_CMSG_COMPAT |MSG_ERRQUEUE |MSG_NOSIGNAL )) goto out;#if 0
Signature · 1 line
2.39.2
Quoted 6 lines · David Lamparter
packet_recvmsg()whitelists a bunch of MSG_* flags, which notably does not includeMSG_NOSIGNAL. Unfortunately,io_uringalways setsMSG_NOSIGNAL, meaningAF_PACKETsockets can't be used inio_uringrecvmsg().
Quoted 9 lines
As
AF_PACKETsockets never generate SIGPIPE to begin with,MSG_NOSIGNALis a no-op and can simply be ignored.Signed-off-by David Lamparter <[email protected]>Cc Willem de Bruijn <[email protected]>--- net/packet/af_packet.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
This is odd... I think MSG_NOSIGNAL flag has a meaning for sendmsg() (or write sides in general)
EPIPE is not supposed to be generated at the receiving side ?
So I would rather make io_uring slightly faster :
io_uring/net.c +0 -0
100644
io_uring/net.c +0 -0
@@ -567,7 +567,7 @@ int io_recvmsg_prep(struct io_kiocb *req, const
struct io_uring_sqe *sqe)
sr->flags = READ_ONCE(sqe->ioprio);
if (sr->flags & ~(RECVMSG_FLAGS))
return -EINVAL;
- sr->msg_flags = READ_ONCE(sqe->msg_flags) | MSG_NOSIGNAL;
+ sr->msg_flags = READ_ONCE(sqe->msg_flags);
if (sr->msg_flags & MSG_DONTWAIT)
req->flags |= REQ_F_NOWAIT;
if (sr->msg_flags & MSG_ERRQUEUE)Quoted 1 line · Eric Dumazet
On Fri, Feb 24, 2023 at 8:18 AM David Lamparter <[email protected]> wrote:
[...]
Quoted 9 lines
Quoted 4 lines
packet_recvmsg()whitelists a bunch of MSG_* flags, which notably does not includeMSG_NOSIGNAL. Unfortunately,io_uringalways setsMSG_NOSIGNAL, meaningAF_PACKETsockets can't be used inio_uringrecvmsg().This is odd... I think
MSG_NOSIGNALflag has a meaning forsendmsg()(or write sides in general)EPIPE is not supposed to be generated at the receiving side ?
I would agree, but then again the behavior is inconsistent between socket types. (AF_INET6, SOCK_RAW, ...) works fine with io_uring/MSG_NOSIGNAL, meanwhile setting MSG_NOSIGNAL on (AF_PACKET, SOCK_RAW, ...) gives EINVAL.
Just to get consistency, MSG_NOSIGNAL might be worth ignoring in AF_PACKET recvmsg? Independent of dropping it from io_uring...
Quoted 1 line
So I would rather make
io_uringslightly faster :
[...]
Quoted 2 lines
(quoted diff) +1
-1- sr->msg_flags = READ_ONCE(sqe->msg_flags) | MSG_NOSIGNAL; + sr->msg_flags = READ_ONCE(sqe->msg_flags);
Quoted 14 lines · David Lamparter
Quoted 1 line · Eric Dumazet
On Fri, Feb 24, 2023 at 8:18 AM David Lamparter <[email protected]> wrote:
[...]
Quoted 9 lines
Quoted 4 lines
packet_recvmsg()whitelists a bunch of MSG_* flags, which notably does not includeMSG_NOSIGNAL. Unfortunately,io_uringalways setsMSG_NOSIGNAL, meaningAF_PACKETsockets can't be used inio_uringrecvmsg().This is odd... I think
MSG_NOSIGNALflag has a meaning forsendmsg()(or write sides in general)EPIPE is not supposed to be generated at the receiving side ?
Quoted 8 lines
I would agree, but then again the behavior is inconsistent between socket types. (
AF_INET6,SOCK_RAW, ...) works fine withio_uring/MSG_NOSIGNAL, meanwhile settingMSG_NOSIGNALon (AF_PACKET,SOCK_RAW, ...) gives EINVAL.Just to get consistency,
MSG_NOSIGNALmight be worth ignoring inAF_PACKETrecvmsg? Independent of dropping it fromio_uring...
Probably because rawv6_recvmsg() never bothered to reject unknown flags. (Maybe the reason for that was that RAW sockets were privileged ones back in linux-2.6)
It is too late to add a check there, it might break some applications mistakenly adding MSG_NOSIGNAL (or any currently ignored bits)
Consistency would be to make sure no recvmsg() handler pretends MSG_NOSIGNAL has a meaning.
Your patch would prevent us using this bit for a future purpose in af_packet.
Quoted 4 lines
Quoted 1 line
So I would rather make
io_uringslightly faster :[...]
Quoted 2 lines
(quoted diff) +1
-1- sr->msg_flags = READ_ONCE(sqe->msg_flags) | MSG_NOSIGNAL; + sr->msg_flags = READ_ONCE(sqe->msg_flags);
Jens Axboe
maintainerQuoted 39 lines · Eric Dumazet
Quoted 6 lines · David Lamparter
packet_recvmsg()whitelists a bunch of MSG_* flags, which notably does not includeMSG_NOSIGNAL. Unfortunately,io_uringalways setsMSG_NOSIGNAL, meaningAF_PACKETsockets can't be used inio_uringrecvmsg().Quoted 9 lines
As
AF_PACKETsockets never generate SIGPIPE to begin with,MSG_NOSIGNALis a no-op and can simply be ignored.Signed-off-by David Lamparter <[email protected]>Cc Willem de Bruijn <[email protected]>--- net/packet/af_packet.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)This is odd... I think
MSG_NOSIGNALflag has a meaning forsendmsg()(or write sides in general)EPIPE is not supposed to be generated at the receiving side ?
So I would rather make
io_uringslightly faster :io_uring/net.c +0
-0100644
io_uring/net.c +1
-1@@ -567,7 +567,7 @@ int io_recvmsg_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe) sr->flags = READ_ONCE(sqe->ioprio);if (sr->flags & ~(RECVMSG_FLAGS ))return -EINVAL ; - sr->msg_flags =READ_ONCE (sqe->msg_flags) |MSG_NOSIGNAL ; + sr->msg_flags =READ_ONCE (sqe->msg_flags);if (sr->msg_flags &MSG_DONTWAIT ) req->flags |=REQ_F_NOWAIT ;
Quoted 1 line
if (sr->msg_flags & MSG_ERRQUEUE)
This looks fine to me. Do you want to send a "proper" patch for this?
Signature · 1 line
Jens Axboe
Quoted 3 lines · Jens Axboe
This looks fine to me. Do you want to send a "proper" patch for this?
Sure, or perhaps David wanted to take care of this.
Thanks.
PATCH 1/1 io_uring: remove MSG_NOSIGNAL from recvmsg
MSG_NOSIGNAL is not applicable for the receiving side, SIGPIPE is generated when trying to write to a "broken pipe". AF_PACKET's packet_recvmsg() does enforce this, giving back EINVAL when MSG_NOSIGNAL is set - making it unuseable in io_uring's recvmsg.
Remove MSG_NOSIGNAL from io_recvmsg_prep().
---
Quoted 1 line
Sure, or perhaps David wanted to take care of this.
Here you go. But maybe give me a few hours to test/confirm...
io_uring/net.c +1 -1
@@ -567,7 +567,7 @@ int io_recvmsg_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe) sr->flags =READ_ONCE (sqe->ioprio);if (sr->flags & ~(RECVMSG_FLAGS ))return -EINVAL ; - sr->msg_flags =READ_ONCE (sqe->msg_flags) |MSG_NOSIGNAL ; + sr->msg_flags =READ_ONCE (sqe->msg_flags);if (sr->msg_flags &MSG_DONTWAIT ) req->flags |=REQ_F_NOWAIT ;if (sr->msg_flags &MSG_ERRQUEUE )
Signature · 1 line
2.39.2
Re: [PATCH] io_uring: remove MSG_NOSIGNAL from recvmsg
Quoted 8 lines · David Lamparter
MSG_NOSIGNALis not applicable for the receiving side, SIGPIPE is generated when trying to write to a "broken pipe". AF_PACKET'spacket_recvmsg()does enforce this, giving back EINVAL whenMSG_NOSIGNALis set - making it unuseable in io_uring's recvmsg.
---Quoted 1 line
Sure, or perhaps David wanted to take care of this.
Here you go. But maybe give me a few hours to test/confirm...
Unsurprisingly, it works as expected.
Re: [PATCH] io_uring: remove MSG_NOSIGNAL from recvmsg
In reply to David LamparterQuoted 8 lines · David Lamparter
MSG_NOSIGNALis not applicable for the receiving side, SIGPIPE is generated when trying to write to a "broken pipe". AF_PACKET'spacket_recvmsg()does enforce this, giving back EINVAL whenMSG_NOSIGNALis set - making it unuseable in io_uring's recvmsg.Remove
MSG_NOSIGNALfromio_recvmsg_prep().
Quoted 9 lines
Signed-off-by David Lamparter <[email protected]>Cc Eric Dumazet <[email protected]>Cc Jens Axboe <[email protected]>---
Quoted 1 line
Sure, or perhaps David wanted to take care of this.
Here you go. But maybe give me a few hours to test/confirm...
Thanks !
Re: [PATCH] io_uring: remove MSG_NOSIGNAL from recvmsg
In reply to David LamparterQuoted 8 lines · David Lamparter
MSG_NOSIGNALis not applicable for the receiving side, SIGPIPE is generated when trying to write to a "broken pipe". AF_PACKET'spacket_recvmsg()does enforce this, giving back EINVAL whenMSG_NOSIGNALis set - making it unuseable in io_uring's recvmsg.Remove
MSG_NOSIGNALfromio_recvmsg_prep().[...]
Applied, thanks!
[1/1] io_uring: remove MSG_NOSIGNAL from recvmsg
commit: 4492575406d8592b623987cb36b8234d285cfa17
Best regards,
Signature · 1 line
Jens Axboe