From: Daniel Yang <danielyangkang@gmail.com>
To: Wenjia Zhang <wenjia@linux.ibm.com>,
Jan Karcher <jaka@linux.ibm.com>,
"D. Wythe" <alibuda@linux.alibaba.com>,
Tony Lu <tonylu@linux.alibaba.com>,
Wen Gu <guwen@linux.alibaba.com>,
"David S. Miller" <davem@davemloft.net>,
Eric Dumazet <edumazet@google.com>,
Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
linux-s390@vger.kernel.org, netdev@vger.kernel.org,
linux-kernel@vger.kernel.org
Cc: danielyangkang@gmail.com,
syzbot+e953a8f3071f5c0a28fd@syzkaller.appspotmail.com
Subject: [PATCH v2] resolve gtp possible deadlock warning
Date: Fri, 4 Oct 2024 21:54:11 -0700 [thread overview]
Message-ID: <20241005045411.118720-1-danielyangkang@gmail.com> (raw)
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 a function that initializes lockdep
labels for smc socks resolved the false positives in lockdep upon
testing. Since smc uses AF_SMC and SOCKSTREAM, two labels are created to
distinguish between proper smc socks and non smc socks incorrectly
input into the function.
Signed-off-by: Daniel Yang <danielyangkang@gmail.com>
Reported-by: syzbot+e953a8f3071f5c0a28fd@syzkaller.appspotmail.com
---
v1->v2: Add lockdep annotations instead of changing locking order
net/smc/af_smc.c | 21 +++++++++++++++++++++
1 file changed, 21 insertions(+)
diff --git a/net/smc/af_smc.c b/net/smc/af_smc.c
index 0316217b7..4de70bfd5 100644
--- a/net/smc/af_smc.c
+++ b/net/smc/af_smc.c
@@ -16,6 +16,8 @@
* based on prototype from Frank Blaschka
*/
+#include "linux/lockdep_types.h"
+#include "linux/socket.h"
#define KMSG_COMPONENT "smc"
#define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
@@ -2755,6 +2757,24 @@ int smc_getname(struct socket *sock, struct sockaddr *addr,
return smc->clcsock->ops->getname(smc->clcsock, addr, peer);
}
+static struct lock_class_key smc_slock_key[2];
+static struct lock_class_key smc_key[2];
+
+static inline void smc_sock_lock_init(struct sock *sk)
+{
+ bool is_smc = (sk->sk_family == AF_SMC) && sk_is_tcp(sk);
+
+ sock_lock_init_class_and_name(sk,
+ is_smc ?
+ "smc_lock-AF_SMC_SOCKSTREAM" :
+ "smc_lock-INVALID",
+ &smc_slock_key[is_smc],
+ is_smc ?
+ "smc_sk_lock-AF_SMC_SOCKSTREAM" :
+ "smc_sk_lock-INVALID",
+ &smc_key[is_smc]);
+}
+
int smc_sendmsg(struct socket *sock, struct msghdr *msg, size_t len)
{
struct sock *sk = sock->sk;
@@ -2762,6 +2782,7 @@ int smc_sendmsg(struct socket *sock, struct msghdr *msg, size_t len)
int rc;
smc = smc_sk(sk);
+ smc_sock_lock_init(sk);
lock_sock(sk);
/* SMC does not support connect with fastopen */
--
2.39.2
next reply other threads:[~2024-10-05 4:54 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-10-05 4:54 Daniel Yang [this message]
2024-10-05 7:24 ` [PATCH v2] resolve gtp possible deadlock warning Eric Dumazet
2024-10-07 6:54 ` Daniel Yang
2024-10-09 7:20 ` D. Wythe
2024-10-14 6:30 ` Daniel Yang
2024-10-07 11:55 ` kernel test robot
2024-10-07 12:48 ` kernel test robot
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20241005045411.118720-1-danielyangkang@gmail.com \
--to=danielyangkang@gmail.com \
--cc=alibuda@linux.alibaba.com \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=guwen@linux.alibaba.com \
--cc=jaka@linux.ibm.com \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-s390@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=syzbot+e953a8f3071f5c0a28fd@syzkaller.appspotmail.com \
--cc=tonylu@linux.alibaba.com \
--cc=wenjia@linux.ibm.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox