[PATCH] nbd: reclassify the socket lock on reconnect too

From: Nguyen Ngoc Thang

Date: Wed Oct 28 2026 - 10:29:43 EST


Commit d532cddb6c60 ("nbd: Reclassify sockets to avoid lockdep circular
dependency") moves nbd sockets to their own lockdep class, but only in
nbd_add_socket(). A socket installed by NBD_CMD_RECONFIGURE keeps the
generic sk_lock-AF_INET class, so the false positive comes back as soon
as recv_work() shuts it down under tx_lock:

WARNING: possible circular locking dependency detected
kworker/u20:0/67 is trying to acquire lock:
(sk_lock-AF_INET){+.+.}-{0:0}, at: inet_shutdown+0x67/0x410
but task is already holding lock:
(&nsock->tx_lock){+.+.}-{4:4}, at: recv_work+0x657/0xa70
...
Chain exists of:
sk_lock-AF_INET --> &cmd->lock --> &nsock->tx_lock

Reclassify the socket in the reconnect path as well.

Fixes: d532cddb6c60 ("nbd: Reclassify sockets to avoid lockdep circular dependency")
Signed-off-by: Nguyen Ngoc Thang <ngocthang2710.1999@xxxxxxxxx>
---
Found while testing the fix for
https://syzkaller.appspot.com/bug?extid=a246ab421a728c78b4ad
("nbd: don't take cpu_hotplug_lock under tx_lock on reconnect", sent
separately): once that splat is gone, the same reproducer reports this
one. Independent of that patch; applies on its own.

Tested in x86_64 QEMU (KASAN + PROVE_LOCKING): with both fixes the
reproducer runs clean 5/5.

drivers/block/nbd.c | 1 +
1 file changed, 1 insertion(+)

diff --git a/drivers/block/nbd.c b/drivers/block/nbd.c
index a567c0bce90e..b24f69a2bd82 100644
--- a/drivers/block/nbd.c
+++ b/drivers/block/nbd.c
@@ -1357,6 +1357,7 @@ static int nbd_genl_reconnect_sock_cb(struct nbd_device *nbd, unsigned long arg)
sock = nbd_get_socket(nbd, arg, &err);
if (!sock)
return err;
+ nbd_reclassify_socket(sock);

args = kzalloc_obj(*args);
if (!args) {
--
2.43.0