resolve gtp possible deadlock warning
v3 cover resolve gtp possible deadlock warning
Fixes deadlock described in this bug:
https://syzkaller.appspot.com/bug?extid=e953a8f3071f5c0a28fd.
Specific crash report here:
https://syzkaller.appspot.com/text?tag=CrashReport&x=14670e07980000.
This bug is a false positive lockdep warning since gtp and smc use completely different socket protocols.
Lockdep thinks that lock_sock() in smc will deadlock with gtp's lock_sock() acquisition.
Adding lockdep annotations on smc socket creation prevents these false positives.
Daniel Yang (2):
Patch from D. Wythe <[email protected]> Move lockdep annotation to separate function for readability.
net/smc/smc_inet.c | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-)
Signature · 1 line
2.39.2
PATCH v3 1/2 Patch from
From: D. Wythe <[email protected]>
Adds lockdep annotations on smc inet socket creation
--- net/smc/smc_inet.c | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-)
net/smc/smc_inet.c +26 -1
@@ -108,14 +108,39 @@ static struct inet_protosw smc_inet6_protosw = { };#endif /* CONFIG_IPV6 */ +static struct lock_class_key smc_slock_keys[2 ]; +static struct lock_class_key smc_keys[2 ]; +static int smc_inet_init_sock (struct sock *sk) {struct net *net =sock_net (sk); +int rc;/* init common smc sock */ smc_sk_init (net, sk,IPPROTO_SMC );/* create clcsock */ -return smc_create_clcsk (net, sk, sk->sk_family); + rc =smc_create_clcsk (net, sk, sk->sk_family); +if (rc) +return rc; + +switch (sk->sk_family) { +case AF_INET : +sock_lock_init_class_and_name (sk,"slock-AF_INET-SMC" , + &smc_slock_keys[0 ], +"sk_lock-AF_INET-SMC" , + &smc_keys[0 ]); +break ; +case AF_INET6 : +sock_lock_init_class_and_name (sk,"slock-AF_INET6-SMC" , + &smc_slock_keys[1 ], +"sk_lock-AF_INET6-SMC" , + &smc_keys[1 ]); +break ; +default : +WARN_ON_ONCE (1 ); + } + +return 0 ; }int __init smc_inet_init (void )
Signature · 1 line
2.39.2
PATCH v3 2/2 Move lockdep annotation to separate function for readability.
In reply to Daniel YangFrom: Daniel Yang <[email protected]>
Moved lockdep annotation to separate function for readability.
--- net/smc/smc_inet.c | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-)
net/smc/smc_inet.c +2 -12
@@ -111,18 +111,7 @@ static struct inet_protosw smc_inet6_protosw = {static struct lock_class_key smc_slock_keys[2 ];static struct lock_class_key smc_keys[2 ]; -static int smc_inet_init_sock (struct sock *sk) -{ -struct net *net =sock_net (sk); -int rc; - -/* init common smc sock */ -smc_sk_init (net, sk,IPPROTO_SMC ); -/* create clcsock */ - rc =smc_create_clcsk (net, sk, sk->sk_family); -if (rc) -return rc; - +static inline void smc_inet_lockdep_annotate (struct sock *sk) +{switch (sk->sk_family) {case AF_INET :
sock_lock_init_class_and_name(sk, "slock-AF_INET-SMC",
@@ -139,8 +128,21 @@ static int smc_inet_init_sock(struct sock *sk)
default:
WARN_ON_ONCE(1);
}
+}
- return 0;
+static int smc_inet_init_sock(struct sock *sk)
+{
+ struct net *net = sock_net(sk);
+ int rc;
+
+ /* init common smc sock */
+ smc_sk_init(net, sk, IPPROTO_SMC);
+ /* create clcsock */
+ rc = smc_create_clcsk(net, sk, sk->sk_family);
+ if (!rc)
+ smc_inet_lockdep_annotate(sk);
+
+ return rc;
}
int __init smc_inet_init(void)
Signature · 1 line
2.39.2
Jakub Kicinski
maintainerQuoted 5 lines · On Mon, 14 Oct 2024 00:30:36 -0700 Daniel Yang wrote:
Fixes deadlock described in this bug:
https://syzkaller.appspot.com/bug?extid=e953a8f3071f5c0a28fd.
Specific crash report here:
https://syzkaller.appspot.com/text?tag=CrashReport&x=14670e07980000.
Quoted 8 lines
This bug is a false positive lockdep warning since gtp and smc use completely different socket protocols.
Lockdep thinks that
lock_sock()in smc will deadlock with gtp'slock_sock()acquisition.Adding lockdep annotations on smc socket creation prevents these false positives.
This posting looks corrupted, please fix and repost, if it's not accidental.