All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH net] net: avoid an indirect call in ____sys_recvmsg()
@ 2019-12-06 17:38 Eric Dumazet
  2019-12-06 18:22 ` Paolo Abeni
  2019-12-06 20:06 ` David Miller
  0 siblings, 2 replies; 4+ messages in thread
From: Eric Dumazet @ 2019-12-06 17:38 UTC (permalink / raw)
  To: David S . Miller
  Cc: netdev, Eric Dumazet, Eric Dumazet, Paolo Abeni, David Laight

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.

Signed-off-by: Eric Dumazet <edumazet@google.com>
Cc: Paolo Abeni <pabeni@redhat.com>
Cc: David Laight <David.Laight@aculab.com>
---
 net/socket.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/net/socket.c b/net/socket.c
index ea28cbb9e2e7a7180ee63de2d09a81aacb001ab7..5af84d71cbc2f731def460b70aa7f68533a90b16 100644
--- a/net/socket.c
+++ b/net/socket.c
@@ -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;
-- 
2.24.0.393.g34dc348eaf-goog


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH net] net: avoid an indirect call in ____sys_recvmsg()
  2019-12-06 17:38 [PATCH net] net: avoid an indirect call in ____sys_recvmsg() Eric Dumazet
@ 2019-12-06 18:22 ` Paolo Abeni
  2019-12-06 18:27   ` Eric Dumazet
  2019-12-06 20:06 ` David Miller
  1 sibling, 1 reply; 4+ messages in thread
From: Paolo Abeni @ 2019-12-06 18:22 UTC (permalink / raw)
  To: Eric Dumazet, David S . Miller; +Cc: netdev, Eric Dumazet, David Laight

On Fri, 2019-12-06 at 09:38 -0800, Eric Dumazet wrote:
> 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.
> 
> Signed-off-by: Eric Dumazet <edumazet@google.com>
> Cc: Paolo Abeni <pabeni@redhat.com>
> Cc: David Laight <David.Laight@aculab.com>

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

Acked-by: Paolo Abeni <pabeni@redhat.com>


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH net] net: avoid an indirect call in ____sys_recvmsg()
  2019-12-06 18:22 ` Paolo Abeni
@ 2019-12-06 18:27   ` Eric Dumazet
  0 siblings, 0 replies; 4+ messages in thread
From: Eric Dumazet @ 2019-12-06 18:27 UTC (permalink / raw)
  To: Paolo Abeni; +Cc: David S . Miller, netdev, Eric Dumazet, David Laight

On Fri, Dec 6, 2019 at 10:22 AM Paolo Abeni <pabeni@redhat.com> wrote:
>
>
> 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.

>
> Acked-by: Paolo Abeni <pabeni@redhat.com>

Thanks.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH net] net: avoid an indirect call in ____sys_recvmsg()
  2019-12-06 17:38 [PATCH net] net: avoid an indirect call in ____sys_recvmsg() Eric Dumazet
  2019-12-06 18:22 ` Paolo Abeni
@ 2019-12-06 20:06 ` David Miller
  1 sibling, 0 replies; 4+ messages in thread
From: David Miller @ 2019-12-06 20:06 UTC (permalink / raw)
  To: edumazet; +Cc: netdev, eric.dumazet, pabeni, David.Laight

From: Eric Dumazet <edumazet@google.com>
Date: Fri,  6 Dec 2019 09:38:36 -0800

> 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.
> 
> Signed-off-by: Eric Dumazet <edumazet@google.com>

Applied, thanks Eric.

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2019-12-06 20:07 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-12-06 17:38 [PATCH net] net: avoid an indirect call in ____sys_recvmsg() Eric Dumazet
2019-12-06 18:22 ` Paolo Abeni
2019-12-06 18:27   ` Eric Dumazet
2019-12-06 20:06 ` David Miller

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.