diff mbox series

[netdev] ipv6: Make sure tcp accept_queue's spinlocks are initialized

Message ID 20240122102322.1131826-1-wenst@chromium.org (mailing list archive)
State Not Applicable
Delegated to: Netdev Maintainers
Headers show
Series [netdev] ipv6: Make sure tcp accept_queue's spinlocks are initialized | expand

Checks

Context Check Description
netdev/series_format success Single patches do not need cover letters
netdev/tree_selection success Clearly marked for net
netdev/ynl success SINGLE THREAD; Generated files up to date; no warnings/errors; no diff in generated;
netdev/fixes_present success Fixes tag present in non-next series
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 1077 this patch: 1077
netdev/build_tools success No tools touched, skip
netdev/cc_maintainers success CCed 0 of 0 maintainers
netdev/build_clang success Errors and warnings before: 1095 this patch: 1095
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/deprecated_api success None detected
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success Fixes tag looks correct
netdev/build_allmodconfig_warn success Errors and warnings before: 1095 this patch: 1095
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 9 lines checked
netdev/build_clang_rust success No Rust files in patch. Skipping build
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0

Commit Message

Chen-Yu Tsai Jan. 22, 2024, 10:23 a.m. UTC
Commit 198bc90e0e73 ("tcp: make sure init the accept_queue's spinlocks
once") moved the TCP accept_queue spinlock initialization from a common
core function to two places for two cases: the common accept callback,
and the socket create callback.

For the second case, only AF_INET (IPv4) was considered. This results
in a lockdep error when accepting an incoming IPv6 TCP connection.

    INFO: trying to register non-static key.
    The code is fine but needs lockdep annotation, or maybe
    you didn't initialize this object before use?
    turning off the locking correctness validator.
    Call trace:
    ... <stack dump> ...
    register_lock_class (kernel/locking/lockdep.c:977 kernel/locking/lockdep.c:1289)
    __lock_acquire (kernel/locking/lockdep.c:5014)
    lock_acquire (./arch/arm64/include/asm/percpu.h:40 kernel/locking/lockdep.c:467 kernel/locking/lockdep.c:5756 kernel/locking/lockdep.c:5719)
    _raw_spin_lock (./include/linux/spinlock_api_smp.h:134 kernel/locking/spinlock.c:154)
    inet_csk_complete_hashdance (net/ipv4/inet_connection_sock.c:1303 net/ipv4/inet_connection_sock.c:1355)
    tcp_check_req (net/ipv4/tcp_minisocks.c:653)
    tcp_v6_rcv (net/ipv6/tcp_ipv6.c:1837)
    ip6_protocol_deliver_rcu (net/ipv6/ip6_input.c:438)
    ip6_input_finish (./include/linux/rcupdate.h:779 net/ipv6/ip6_input.c:484)
    ip6_input (./include/linux/netfilter.h:314 ./include/linux/netfilter.h:308 net/ipv6/ip6_input.c:492)
    ip6_sublist_rcv_finish (net/ipv6/ip6_input.c:86 (discriminator 3))
    ip6_sublist_rcv (net/ipv6/ip6_input.c:317)
    ipv6_list_rcv (net/ipv6/ip6_input.c:326)
    __netif_receive_skb_list_core (net/core/dev.c:5577 net/core/dev.c:5625)
    netif_receive_skb_list_internal (net/core/dev.c:5679 net/core/dev.c:5768)
    napi_complete_done (./include/linux/list.h:37 (discriminator 2) ./include/net/gro.h:440 (discriminator 2) ./include/net/gro.h:435 (discriminator 2) net/core/dev.c:6108 (discriminator 2))
    ... <device callback> ...

Fix this by adding the appropriate code to AF_INET6 (IPv6) socket create
callback, mirroring what was added for AF_INET.

Fixes: 198bc90e0e73 ("tcp: make sure init the accept_queue's spinlocks once")
Signed-off-by: Chen-Yu Tsai <wenst@chromium.org>
---
 net/ipv6/af_inet6.c | 3 +++
 1 file changed, 3 insertions(+)

Comments

shaozhengchao Jan. 22, 2024, 11:12 a.m. UTC | #1
Hi Chen-Yu Tsai:
	I have send the fixed patch.
https://lore.kernel.org/all/20240122102001.2851701-1-shaozhengchao@huawei.com/
Thank you

Zhengchao Shao

On 2024/1/22 18:23, Chen-Yu Tsai wrote:
> Commit 198bc90e0e73 ("tcp: make sure init the accept_queue's spinlocks
> once") moved the TCP accept_queue spinlock initialization from a common
> core function to two places for two cases: the common accept callback,
> and the socket create callback.
> 
> For the second case, only AF_INET (IPv4) was considered. This results
> in a lockdep error when accepting an incoming IPv6 TCP connection.
> 
>      INFO: trying to register non-static key.
>      The code is fine but needs lockdep annotation, or maybe
>      you didn't initialize this object before use?
>      turning off the locking correctness validator.
>      Call trace:
>      ... <stack dump> ...
>      register_lock_class (kernel/locking/lockdep.c:977 kernel/locking/lockdep.c:1289)
>      __lock_acquire (kernel/locking/lockdep.c:5014)
>      lock_acquire (./arch/arm64/include/asm/percpu.h:40 kernel/locking/lockdep.c:467 kernel/locking/lockdep.c:5756 kernel/locking/lockdep.c:5719)
>      _raw_spin_lock (./include/linux/spinlock_api_smp.h:134 kernel/locking/spinlock.c:154)
>      inet_csk_complete_hashdance (net/ipv4/inet_connection_sock.c:1303 net/ipv4/inet_connection_sock.c:1355)
>      tcp_check_req (net/ipv4/tcp_minisocks.c:653)
>      tcp_v6_rcv (net/ipv6/tcp_ipv6.c:1837)
>      ip6_protocol_deliver_rcu (net/ipv6/ip6_input.c:438)
>      ip6_input_finish (./include/linux/rcupdate.h:779 net/ipv6/ip6_input.c:484)
>      ip6_input (./include/linux/netfilter.h:314 ./include/linux/netfilter.h:308 net/ipv6/ip6_input.c:492)
>      ip6_sublist_rcv_finish (net/ipv6/ip6_input.c:86 (discriminator 3))
>      ip6_sublist_rcv (net/ipv6/ip6_input.c:317)
>      ipv6_list_rcv (net/ipv6/ip6_input.c:326)
>      __netif_receive_skb_list_core (net/core/dev.c:5577 net/core/dev.c:5625)
>      netif_receive_skb_list_internal (net/core/dev.c:5679 net/core/dev.c:5768)
>      napi_complete_done (./include/linux/list.h:37 (discriminator 2) ./include/net/gro.h:440 (discriminator 2) ./include/net/gro.h:435 (discriminator 2) net/core/dev.c:6108 (discriminator 2))
>      ... <device callback> ...
> 
> Fix this by adding the appropriate code to AF_INET6 (IPv6) socket create
> callback, mirroring what was added for AF_INET.
> 
> Fixes: 198bc90e0e73 ("tcp: make sure init the accept_queue's spinlocks once")
> Signed-off-by: Chen-Yu Tsai <wenst@chromium.org>
> ---
>   net/ipv6/af_inet6.c | 3 +++
>   1 file changed, 3 insertions(+)
> 
> diff --git a/net/ipv6/af_inet6.c b/net/ipv6/af_inet6.c
> index 13a1833a4df5..959bfd9f6344 100644
> --- a/net/ipv6/af_inet6.c
> +++ b/net/ipv6/af_inet6.c
> @@ -199,6 +199,9 @@ static int inet6_create(struct net *net, struct socket *sock, int protocol,
>   	if (INET_PROTOSW_REUSE & answer_flags)
>   		sk->sk_reuse = SK_CAN_REUSE;
>   
> +	if (INET_PROTOSW_ICSK & answer_flags)
> +		inet_init_csk_locks(sk);
> +
>   	inet = inet_sk(sk);
>   	inet_assign_bit(IS_ICSK, sk, INET_PROTOSW_ICSK & answer_flags);
>
diff mbox series

Patch

diff --git a/net/ipv6/af_inet6.c b/net/ipv6/af_inet6.c
index 13a1833a4df5..959bfd9f6344 100644
--- a/net/ipv6/af_inet6.c
+++ b/net/ipv6/af_inet6.c
@@ -199,6 +199,9 @@  static int inet6_create(struct net *net, struct socket *sock, int protocol,
 	if (INET_PROTOSW_REUSE & answer_flags)
 		sk->sk_reuse = SK_CAN_REUSE;
 
+	if (INET_PROTOSW_ICSK & answer_flags)
+		inet_init_csk_locks(sk);
+
 	inet = inet_sk(sk);
 	inet_assign_bit(IS_ICSK, sk, INET_PROTOSW_ICSK & answer_flags);