* [PATCH net-next] net: __lock_sock() can be static
@ 2026-02-23 9:27 Eric Dumazet
2026-02-23 18:41 ` Kuniyuki Iwashima
2026-02-25 1:00 ` patchwork-bot+netdevbpf
0 siblings, 2 replies; 3+ messages in thread
From: Eric Dumazet @ 2026-02-23 9:27 UTC (permalink / raw)
To: David S . Miller, Jakub Kicinski, Paolo Abeni
Cc: Simon Horman, Kuniyuki Iwashima, netdev, eric.dumazet,
Eric Dumazet
After commit 6511882cdd82 ("mptcp: allocate fwd memory separately
on the rx and tx path") __lock_sock() can be static again.
Make sure __lock_sock() is not inlined, so that lock_sock_nested()
no longer needs a stack canary.
Add a noinline attribute on lock_sock_nested() so that calls
to lock_sock() from net/core/sock.c are not inlined,
none of them are fast path to deserve that:
- sockopt_lock_sock()
- sock_set_reuseport()
- sock_set_reuseaddr()
- sock_set_mark()
- sock_set_keepalive()
- sock_no_linger()
- sock_bindtoindex()
- sk_wait_data()
- sock_set_rcvbuf()
$ scripts/bloat-o-meter -t vmlinux.old vmlinux
add/remove: 0/0 grow/shrink: 0/3 up/down: 0/-312 (-312)
Function old new delta
__lock_sock 192 188 -4
__lock_sock_fast 239 86 -153
lock_sock_nested 227 72 -155
Total: Before=24888707, After=24888395, chg -0.00%
Signed-off-by: Eric Dumazet <edumazet@google.com>
---
include/net/sock.h | 1 -
net/core/sock.c | 8 ++++----
2 files changed, 4 insertions(+), 5 deletions(-)
diff --git a/include/net/sock.h b/include/net/sock.h
index 66b56288c1d3850439b2a0bed00be801d5770efa..55b61e4b0d8318887d527e919fc1103d78ac6d14 100644
--- a/include/net/sock.h
+++ b/include/net/sock.h
@@ -1709,7 +1709,6 @@ static inline void lock_sock(struct sock *sk)
lock_sock_nested(sk, 0);
}
-void __lock_sock(struct sock *sk);
void __release_sock(struct sock *sk);
void release_sock(struct sock *sk);
diff --git a/net/core/sock.c b/net/core/sock.c
index 693e6d80f501ef552aa58928f28b78a578169536..cfb2a6209946089669882cdbd5d1b36c53838989 100644
--- a/net/core/sock.c
+++ b/net/core/sock.c
@@ -3175,7 +3175,7 @@ bool sk_page_frag_refill(struct sock *sk, struct page_frag *pfrag)
}
EXPORT_SYMBOL(sk_page_frag_refill);
-void __lock_sock(struct sock *sk)
+static void __lock_sock(struct sock *sk)
__releases(&sk->sk_lock.slock)
__acquires(&sk->sk_lock.slock)
{
@@ -3774,14 +3774,14 @@ void sock_init_data(struct socket *sock, struct sock *sk)
}
EXPORT_SYMBOL(sock_init_data);
-void lock_sock_nested(struct sock *sk, int subclass)
+void noinline lock_sock_nested(struct sock *sk, int subclass)
{
/* The sk_lock has mutex_lock() semantics here. */
mutex_acquire(&sk->sk_lock.dep_map, subclass, 0, _RET_IP_);
might_sleep();
spin_lock_bh(&sk->sk_lock.slock);
- if (sock_owned_by_user_nocheck(sk))
+ if (unlikely(sock_owned_by_user_nocheck(sk)))
__lock_sock(sk);
sk->sk_lock.owned = 1;
spin_unlock_bh(&sk->sk_lock.slock);
@@ -3810,7 +3810,7 @@ bool __lock_sock_fast(struct sock *sk) __acquires(&sk->sk_lock.slock)
might_sleep();
spin_lock_bh(&sk->sk_lock.slock);
- if (!sock_owned_by_user_nocheck(sk)) {
+ if (likely(!sock_owned_by_user_nocheck(sk))) {
/*
* Fast path return with bottom halves disabled and
* sock::sk_lock.slock held.
--
2.53.0.345.g96ddfc5eaa-goog
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH net-next] net: __lock_sock() can be static
2026-02-23 9:27 [PATCH net-next] net: __lock_sock() can be static Eric Dumazet
@ 2026-02-23 18:41 ` Kuniyuki Iwashima
2026-02-25 1:00 ` patchwork-bot+netdevbpf
1 sibling, 0 replies; 3+ messages in thread
From: Kuniyuki Iwashima @ 2026-02-23 18:41 UTC (permalink / raw)
To: Eric Dumazet
Cc: David S . Miller, Jakub Kicinski, Paolo Abeni, Simon Horman,
netdev, eric.dumazet
On Mon, Feb 23, 2026 at 1:27 AM Eric Dumazet <edumazet@google.com> wrote:
>
> After commit 6511882cdd82 ("mptcp: allocate fwd memory separately
> on the rx and tx path") __lock_sock() can be static again.
>
> Make sure __lock_sock() is not inlined, so that lock_sock_nested()
> no longer needs a stack canary.
>
> Add a noinline attribute on lock_sock_nested() so that calls
> to lock_sock() from net/core/sock.c are not inlined,
> none of them are fast path to deserve that:
>
> - sockopt_lock_sock()
> - sock_set_reuseport()
> - sock_set_reuseaddr()
> - sock_set_mark()
> - sock_set_keepalive()
> - sock_no_linger()
> - sock_bindtoindex()
> - sk_wait_data()
> - sock_set_rcvbuf()
>
> $ scripts/bloat-o-meter -t vmlinux.old vmlinux
> add/remove: 0/0 grow/shrink: 0/3 up/down: 0/-312 (-312)
> Function old new delta
> __lock_sock 192 188 -4
> __lock_sock_fast 239 86 -153
> lock_sock_nested 227 72 -155
> Total: Before=24888707, After=24888395, chg -0.00%
>
> Signed-off-by: Eric Dumazet <edumazet@google.com>
Reviewed-by: Kuniyuki Iwashima <kuniyu@google.com>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH net-next] net: __lock_sock() can be static
2026-02-23 9:27 [PATCH net-next] net: __lock_sock() can be static Eric Dumazet
2026-02-23 18:41 ` Kuniyuki Iwashima
@ 2026-02-25 1:00 ` patchwork-bot+netdevbpf
1 sibling, 0 replies; 3+ messages in thread
From: patchwork-bot+netdevbpf @ 2026-02-25 1:00 UTC (permalink / raw)
To: Eric Dumazet; +Cc: davem, kuba, pabeni, horms, kuniyu, netdev, eric.dumazet
Hello:
This patch was applied to netdev/net-next.git (main)
by Jakub Kicinski <kuba@kernel.org>:
On Mon, 23 Feb 2026 09:27:15 +0000 you wrote:
> After commit 6511882cdd82 ("mptcp: allocate fwd memory separately
> on the rx and tx path") __lock_sock() can be static again.
>
> Make sure __lock_sock() is not inlined, so that lock_sock_nested()
> no longer needs a stack canary.
>
> Add a noinline attribute on lock_sock_nested() so that calls
> to lock_sock() from net/core/sock.c are not inlined,
> none of them are fast path to deserve that:
>
> [...]
Here is the summary with links:
- [net-next] net: __lock_sock() can be static
https://git.kernel.org/netdev/net-next/c/2550def53bbf
You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-02-25 1:00 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-02-23 9:27 [PATCH net-next] net: __lock_sock() can be static Eric Dumazet
2026-02-23 18:41 ` Kuniyuki Iwashima
2026-02-25 1:00 ` patchwork-bot+netdevbpf
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox