Skip to contentSkip to conversation

net: avoid an indirect call in ____sys_recvmsg()

PATCH Applied Eric Dumazet 3 participants 4 messages Dec 6, 2019

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

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.

Cc Paolo Abeni <[email protected]>
Cc David Laight <[email protected]>
---
 net/socket.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
net/socket.c +6 -1
index ea28cbb9e2e7a7180ee63de2d09a81aacb001ab7..5af84d71cbc2f731def460b70aa7f68533a90b16 100644
@@ -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
maintainer Acked-by on v1 1/1
#1 lore raw
Quoted 6 lines · Eric Dumazet

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.

Quoted 7 lines

Alternative would be to not call sock_recvmsg() and instead use security_socket_recvmsg() and sock_recvmsg_nosec(), but this is less readable IMO.

Cc Paolo Abeni <[email protected]>
Cc David Laight <[email protected]>

I'm not sure this is -net material, but the code LGTM.

#2 lore raw
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

Thanks.

maintainer Applied
#3 lore raw
In reply to Eric Dumazet

From: Eric Dumazet <[email protected]>
Date: Fri, 6 Dec 2019 09:38:36 -0800

Quoted 11 lines

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.

Applied, thanks Eric.