Skip to contentSkip to conversation

nbd: reclassify socket lock in nbd_reconnect_socket

PATCH In review Yun Zhou 1 participant 2 messages Jul 6 – Jul 19

Subsystems (2)
lore
Share & tools
lore

Yun Zhou

author
#0 lore raw

PATCH 1/1 nbd: reclassify socket lock in nbd_reconnect_socket

nbd_reconnect_socket() obtains a new socket via nbd_get_socket() but does not call nbd_reclassify_socket(), leaving the socket's sk_lock in the default AF_INET6 lockdep class. This causes false circular lock dependency warnings because lockdep merges the NBD socket's sk_lock with unrelated sockets (e.g., rawv6_sendmsg) that establish a sk_lock -> fs_reclaim dependency in normal operation.

nbd_add_socket() already reclassifies correctly on the initial connect path, but the reconnect path was missed.

Add the missing nbd_reclassify_socket() call after nbd_get_socket() in nbd_reconnect_socket().

Reported-by [email protected]
Fixes d532cddb6c60 ("nbd: Reclassify sockets to avoid lockdep circular dependency")
---
 drivers/block/nbd.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/block/nbd.c +2 -0
index 8c6028e71e83..70a04d541ea4 100644
@@ -1386,6 +1386,8 @@ static int nbd_reconnect_socket(struct nbd_device *nbd, unsigned long arg)
 	if (!sock)
 		return err;
 
+	nbd_reclassify_socket(sock);
+
 	args = kzalloc_obj(*args);
 	if (!args) {
 		sockfd_put(sock);
Signature · 1 line
2.43.0
author
#1 lore raw

Friendly ping.

Quoted 34 lines · Yun Zhou

nbd_reconnect_socket() obtains a new socket via nbd_get_socket() but does not call nbd_reclassify_socket(), leaving the socket's sk_lock in the default AF_INET6 lockdep class. This causes false circular lock dependency warnings because lockdep merges the NBD socket's sk_lock with unrelated sockets (e.g., rawv6_sendmsg) that establish a sk_lock -> fs_reclaim dependency in normal operation.

nbd_add_socket() already reclassifies correctly on the initial connect path, but the reconnect path was missed.

Add the missing nbd_reclassify_socket() call after nbd_get_socket() in nbd_reconnect_socket().

Reported-by [email protected]
Fixes d532cddb6c60 ("nbd: Reclassify sockets to avoid lockdep circular dependency")
---
  drivers/block/nbd.c | 2 ++
  1 file changed, 2 insertions(+)
drivers/block/nbd.c +2 -0
index 8c6028e71e83..70a04d541ea4 100644
@@ -1386,6 +1386,8 @@ static int nbd_reconnect_socket(struct nbd_device *nbd, unsigned long arg)
  	if (!sock)
  		return err;
 
+	nbd_reclassify_socket(sock);
+
  	args = kzalloc_obj(*args);
  	if (!args) {
  		sockfd_put(sock);