Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

RDMA/rxe: let rxe_reclassify_recv_socket() call sk_owner_put()

On kernels build with CONFIG_PROVE_LOCKING, CONFIG_MODULES
and CONFIG_DEBUG_LOCK_ALLOC 'rmmod rdma_rxe' is no longer
possible.

For the global recv sockets rxe_net_exit() is where we
call rxe_release_udp_tunnel-> udp_tunnel_sock_release(),
which means the sockets are destroyed before 'rmmod rdma_rxe'
finishes, so there's no need to protect against
rxe_recv_slock_key and rxe_recv_sk_key disappearing
while the sockets are still alive.

Fixes: 80a85a771deb ("RDMA/rxe: reclassify sockets in order to avoid false positives from lockdep")
Cc: Zhu Yanjun <zyjzyj2000@gmail.com>
Cc: Jason Gunthorpe <jgg@ziepe.ca>
Cc: Leon Romanovsky <leon@kernel.org>
Cc: Shinichiro Kawasaki <shinichiro.kawasaki@wdc.com>
Cc: linux-rdma@vger.kernel.org
Cc: netdev@vger.kernel.org
Cc: linux-cifs@vger.kernel.org
Signed-off-by: Stefan Metzmacher <metze@samba.org>
Link: https://patch.msgid.link/20251219140408.2300163-1-metze@samba.org
Reviewed-by: Zhu Yanjun <yanjun.zhu@linux.dev>
Tested-by: Shin'ichiro Kawasaki <shinichiro.kawasaki@wdc.com>
Signed-off-by: Leon Romanovsky <leon@kernel.org>

authored by

Stefan Metzmacher and committed by
Leon Romanovsky
de41cbc6 145a417a

+32
+32
drivers/infiniband/sw/rxe/rxe_net.c
··· 64 64 break; 65 65 default: 66 66 WARN_ON_ONCE(1); 67 + return; 67 68 } 69 + /* 70 + * sock_lock_init_class_and_name() calls 71 + * sk_owner_set(sk, THIS_MODULE); in order 72 + * to make sure the referenced global 73 + * variables rxe_recv_slock_key and 74 + * rxe_recv_sk_key are not removed 75 + * before the socket is closed. 76 + * 77 + * However this prevents rxe_net_exit() 78 + * from being called and 'rmmod rdma_rxe' 79 + * is refused because of the references. 80 + * 81 + * For the global sockets in recv_sockets, 82 + * we are sure that rxe_net_exit() will call 83 + * rxe_release_udp_tunnel -> udp_tunnel_sock_release. 84 + * 85 + * So we don't need the additional reference to 86 + * our own (THIS_MODULE). 87 + */ 88 + sk_owner_put(sk); 89 + /* 90 + * We also call sk_owner_clear() otherwise 91 + * sk_owner_put(sk) in sk_prot_free will 92 + * fail, which is called via 93 + * sk_free -> __sk_free -> sk_destruct 94 + * and sk_destruct calls __sk_destruct 95 + * directly or via call_rcu() 96 + * so sk_prot_free() might be called 97 + * after rxe_net_exit(). 98 + */ 99 + sk_owner_clear(sk); 68 100 #endif /* CONFIG_DEBUG_LOCK_ALLOC */ 69 101 } 70 102