net: avoid an indirect call in ____sys_recvmsg()
Subsystems (3)
PATCH 1/1 net: avoid an indirect call in ____sys_recvmsg()
CONFIG_RETPOLINE=y made indirect calls expensive.
gcc seems to add an indirect call in ____sys_recvmsg().
Rewriting the code slightly makes sure to avoid this indirection.
Alternative would be to not call sock_recvmsg() and instead use security_socket_recvmsg() and sock_recvmsg_nosec(), but this is less readable IMO.
--- net/socket.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
net/socket.c +6 -1
@@ -2559,7 +2559,12 @@ static int ____sys_recvmsg(struct socket *sock, struct msghdr *msg_sys,if (sock->file->f_flags &O_NONBLOCK ) flags |=MSG_DONTWAIT ; - err = (nosec ? sock_recvmsg_nosec : sock_recvmsg)(sock, msg_sys, flags); + +if (unlikely (nosec)) + err =sock_recvmsg_nosec (sock, msg_sys, flags); +else + err =sock_recvmsg (sock, msg_sys, flags); +if (err <0 ) goto out; len = err;
Signature · 1 line
2.24.0.393.g34dc348eaf-goog
Quoted 6 lines · Eric Dumazet
CONFIG_RETPOLINE=ymade indirect calls expensive.gcc seems to add an indirect call in
____sys_recvmsg().Rewriting the code slightly makes sure to avoid this indirection.
Quoted 7 lines
Alternative would be to not call
sock_recvmsg()and instead usesecurity_socket_recvmsg()andsock_recvmsg_nosec(), but this is less readable IMO.Signed-off-by Eric Dumazet <[email protected]>Cc Paolo Abeni <[email protected]>Cc David Laight <[email protected]>
I'm not sure this is -net material, but the code LGTM.
Quoted 3 lines · Paolo Abeni
I'm not sure this is -net material, but the code LGTM.
Well, performance matters (otherwise David Laight would not have investigated so much),
and patch is kind-of-trivial, I am pretty sure David Miller will not mind.
Quoted 2 lines
Acked-by Paolo Abeni <[email protected]>
Thanks.
From: Eric Dumazet <[email protected]>
Date: Fri, 6 Dec 2019 09:38:36 -0800
Quoted 11 lines
CONFIG_RETPOLINE=ymade indirect calls expensive.gcc seems to add an indirect call in
____sys_recvmsg().Rewriting the code slightly makes sure to avoid this indirection.
Alternative would be to not call
sock_recvmsg()and instead usesecurity_socket_recvmsg()andsock_recvmsg_nosec(), but this is less readable IMO.Signed-off-by Eric Dumazet <[email protected]>
Applied, thanks Eric.