Skip to contentSkip to conversation

nbd: reclassify the socket lock on reconnect too

PATCH New Nguyen Ngoc Thang 1 participant 1 message Oct 28

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 nbd: reclassify the socket lock on reconnect too

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")

---
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(+)
drivers/block/nbd.c +1 -0
index a567c0bce90e..b24f69a2bd82 100644
@@ -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) {
Signature · 1 line
2.43.0