diff mbox series

[v3,1/2,RESEND] resolve gtp possible deadlock warning

Message ID a226d1132aa6f7e1e5d9b9054bbf5c291fcfa664.1729031472.git.danielyangkang@gmail.com (mailing list archive)
State Changes Requested
Delegated to: Netdev Maintainers
Headers show
Series [v3,1/2,RESEND] resolve gtp possible deadlock warning | expand

Checks

Context Check Description
netdev/tree_selection success Guessing tree name failed - patch did not apply

Commit Message

Daniel Yang Oct. 15, 2024, 10:48 p.m. UTC
From: D. Wythe <alibuda@linux.alibaba.com>

Adds lockdep annotations on smc inet socket creation

Tested-by: Daniel Yang <danielyangkang@gmail.com>
Signed-off-by: Daniel Yang <danielyangkang@gmail.com>
Reported-by: syzbot+e953a8f3071f5c0a28fd@syzkaller.appspotmail.com
---
 net/smc/smc_inet.c | 27 ++++++++++++++++++++++++++-
 1 file changed, 26 insertions(+), 1 deletion(-)
diff mbox series

Patch

diff --git a/net/smc/smc_inet.c b/net/smc/smc_inet.c
index a5b204160..7ae49ffd2 100644
--- a/net/smc/smc_inet.c
+++ b/net/smc/smc_inet.c
@@ -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)