Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

net: __lock_sock() can be static

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>
Link: https://patch.msgid.link/20260223092716.3673939-1-edumazet@google.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>

authored by

Eric Dumazet and committed by
Jakub Kicinski
2550def5 8636385b

+4 -5
-1
include/net/sock.h
··· 1709 1709 lock_sock_nested(sk, 0); 1710 1710 } 1711 1711 1712 - void __lock_sock(struct sock *sk); 1713 1712 void __release_sock(struct sock *sk); 1714 1713 void release_sock(struct sock *sk); 1715 1714
+4 -4
net/core/sock.c
··· 3175 3175 } 3176 3176 EXPORT_SYMBOL(sk_page_frag_refill); 3177 3177 3178 - void __lock_sock(struct sock *sk) 3178 + static void __lock_sock(struct sock *sk) 3179 3179 __releases(&sk->sk_lock.slock) 3180 3180 __acquires(&sk->sk_lock.slock) 3181 3181 { ··· 3774 3774 } 3775 3775 EXPORT_SYMBOL(sock_init_data); 3776 3776 3777 - void lock_sock_nested(struct sock *sk, int subclass) 3777 + void noinline lock_sock_nested(struct sock *sk, int subclass) 3778 3778 { 3779 3779 /* The sk_lock has mutex_lock() semantics here. */ 3780 3780 mutex_acquire(&sk->sk_lock.dep_map, subclass, 0, _RET_IP_); 3781 3781 3782 3782 might_sleep(); 3783 3783 spin_lock_bh(&sk->sk_lock.slock); 3784 - if (sock_owned_by_user_nocheck(sk)) 3784 + if (unlikely(sock_owned_by_user_nocheck(sk))) 3785 3785 __lock_sock(sk); 3786 3786 sk->sk_lock.owned = 1; 3787 3787 spin_unlock_bh(&sk->sk_lock.slock); ··· 3810 3810 might_sleep(); 3811 3811 spin_lock_bh(&sk->sk_lock.slock); 3812 3812 3813 - if (!sock_owned_by_user_nocheck(sk)) { 3813 + if (likely(!sock_owned_by_user_nocheck(sk))) { 3814 3814 /* 3815 3815 * Fast path return with bottom halves disabled and 3816 3816 * sock::sk_lock.slock held.