* [PATCH] nbd: Reclassify sockets to avoid lockdep circular dependency
@ 2026-06-13 4:26 Eric Dumazet
2026-06-13 10:12 ` Hillf Danton
2026-06-13 12:34 ` Jens Axboe
0 siblings, 2 replies; 3+ messages in thread
From: Eric Dumazet @ 2026-06-13 4:26 UTC (permalink / raw)
To: Josef Bacik, Jens Axboe
Cc: linux-kernel, linux-block, nbd, Eric Dumazet, Jakub Kicinski,
Paolo Abeni, Kuniyuki Iwashima, netdev, Eric Dumazet,
syzbot+607cdcf978b3e79da878
syzbot reported a possible circular locking dependency in udp_sendmsg()
where fs_reclaim can be triggered while holding sk_lock, and fs_reclaim
can eventually depend on another sk_lock (e.g., if NBD is used for swap
or writeback and NBD uses TLS/TCP which acquires sk_lock).
Since the UDP socket and the NBD TCP/TLS socket are different, this is a
false positive. Fix this by reclassifying NBD sockets to a separate lock
class when they are added to the NBD device.
This is similar to what nvme-tcp and other network block devices do.
Fixes: ffa1e7ada456 ("block: Make request_queue lockdep splats show up earlier")
Reported-by: syzbot+607cdcf978b3e79da878@syzkaller.appspotmail.com
Closes: https://lore.kernel.org/netdev/6a2cdafe.428ffe26.258b27.0161.GAE@google.com/T/#u
Signed-off-by: Eric Dumazet <edumazet@google.com>
---
drivers/block/nbd.c | 37 +++++++++++++++++++++++++++++++++++++
1 file changed, 37 insertions(+)
diff --git a/drivers/block/nbd.c b/drivers/block/nbd.c
index fe63f3c55d0d960a1a4bbb2c60738cbbece10719..0e2180e910c4eaaa58556a0c75c1b9c3fdc1930d 100644
--- a/drivers/block/nbd.c
+++ b/drivers/block/nbd.c
@@ -1238,6 +1238,42 @@ static struct socket *nbd_get_socket(struct nbd_device *nbd, unsigned long fd,
return sock;
}
+#ifdef CONFIG_DEBUG_LOCK_ALLOC
+static struct lock_class_key nbd_key[3];
+static struct lock_class_key nbd_slock_key[3];
+
+static void nbd_reclassify_socket(struct socket *sock)
+{
+ struct sock *sk = sock->sk;
+
+ if (WARN_ON_ONCE(!sock_allow_reclassification(sk)))
+ return;
+
+ switch (sk->sk_family) {
+ case AF_INET:
+ sock_lock_init_class_and_name(sk, "slock-AF_INET-NBD",
+ &nbd_slock_key[0],
+ "sk_lock-AF_INET-NBD",
+ &nbd_key[0]);
+ break;
+ case AF_INET6:
+ sock_lock_init_class_and_name(sk, "slock-AF_INET6-NBD",
+ &nbd_slock_key[1],
+ "sk_lock-AF_INET6-NBD",
+ &nbd_key[1]);
+ break;
+ case AF_UNIX:
+ sock_lock_init_class_and_name(sk, "slock-AF_UNIX-NBD",
+ &nbd_slock_key[2],
+ "sk_lock-AF_UNIX-NBD",
+ &nbd_key[2]);
+ break;
+ }
+}
+#else
+static inline void nbd_reclassify_socket(struct socket *sock) {}
+#endif
+
static int nbd_add_socket(struct nbd_device *nbd, unsigned long arg,
bool netlink)
{
@@ -1254,6 +1290,7 @@ static int nbd_add_socket(struct nbd_device *nbd, unsigned long arg,
sock = nbd_get_socket(nbd, arg, &err);
if (!sock)
return err;
+ nbd_reclassify_socket(sock);
/*
* We need to make sure we don't get any errant requests while we're
--
2.54.0.1136.gdb2ca164c4-goog
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] nbd: Reclassify sockets to avoid lockdep circular dependency
2026-06-13 4:26 [PATCH] nbd: Reclassify sockets to avoid lockdep circular dependency Eric Dumazet
@ 2026-06-13 10:12 ` Hillf Danton
2026-06-13 12:34 ` Jens Axboe
1 sibling, 0 replies; 3+ messages in thread
From: Hillf Danton @ 2026-06-13 10:12 UTC (permalink / raw)
To: Eric Dumazet
Cc: linux-kernel, Jens Axboe, linux-block, nbd, Kuniyuki Iwashima,
netdev, syzbot+607cdcf978b3e79da878
On Sat, 13 Jun 2026 04:26:19 +0000 Eric Dumazet wrote:
> syzbot reported a possible circular locking dependency in udp_sendmsg()
> where fs_reclaim can be triggered while holding sk_lock, and fs_reclaim
> can eventually depend on another sk_lock (e.g., if NBD is used for swap
> or writeback and NBD uses TLS/TCP which acquires sk_lock).
>
> Since the UDP socket and the NBD TCP/TLS socket are different, this is a
> false positive. Fix this by reclassifying NBD sockets to a separate lock
> class when they are added to the NBD device.
>
> This is similar to what nvme-tcp and other network block devices do.
>
> Fixes: ffa1e7ada456 ("block: Make request_queue lockdep splats show up earlier")
Given the Fixes tag, can you specify anything wrong that commit added?
> Reported-by: syzbot+607cdcf978b3e79da878@syzkaller.appspotmail.com
> Closes: https://lore.kernel.org/netdev/6a2cdafe.428ffe26.258b27.0161.GAE@google.com/T/#u
> Signed-off-by: Eric Dumazet <edumazet@google.com>
> ---
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] nbd: Reclassify sockets to avoid lockdep circular dependency
2026-06-13 4:26 [PATCH] nbd: Reclassify sockets to avoid lockdep circular dependency Eric Dumazet
2026-06-13 10:12 ` Hillf Danton
@ 2026-06-13 12:34 ` Jens Axboe
1 sibling, 0 replies; 3+ messages in thread
From: Jens Axboe @ 2026-06-13 12:34 UTC (permalink / raw)
To: Josef Bacik, Eric Dumazet
Cc: linux-kernel, linux-block, nbd, Eric Dumazet, Jakub Kicinski,
Paolo Abeni, Kuniyuki Iwashima, netdev,
syzbot+607cdcf978b3e79da878
On Sat, 13 Jun 2026 04:26:19 +0000, Eric Dumazet wrote:
> syzbot reported a possible circular locking dependency in udp_sendmsg()
> where fs_reclaim can be triggered while holding sk_lock, and fs_reclaim
> can eventually depend on another sk_lock (e.g., if NBD is used for swap
> or writeback and NBD uses TLS/TCP which acquires sk_lock).
>
> Since the UDP socket and the NBD TCP/TLS socket are different, this is a
> false positive. Fix this by reclassifying NBD sockets to a separate lock
> class when they are added to the NBD device.
>
> [...]
Applied, thanks!
[1/1] nbd: Reclassify sockets to avoid lockdep circular dependency
commit: d532cddb6c6049ced414d64d83c6ce7149a6421a
Best regards,
--
Jens Axboe
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-06-13 12:34 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-06-13 4:26 [PATCH] nbd: Reclassify sockets to avoid lockdep circular dependency Eric Dumazet
2026-06-13 10:12 ` Hillf Danton
2026-06-13 12:34 ` Jens Axboe
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox