aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZhenlei Huang <zlei@FreeBSD.org>2026-04-13 04:38:43 +0000
committerZhenlei Huang <zlei@FreeBSD.org>2026-04-13 04:38:43 +0000
commitf1fae67afbb13a41d488d0e0ec66b1805925019c (patch)
tree90554e6b9b4fc27f1da420fa178947e10c7c8973
parent8085c5a5c1e50eb478fb7b59fae201d9ab4207f0 (diff)
ifnet: vnet_if_return(): Avoid unnecessary recursive acquisition of ifnet_detach_sxlock
vnet_if_return() will be invocked by vnet_sysuninit() on vnet destructing, while the lock ifnet_detach_sxlock has been acquired in vnet_destroy() already. With this change the order of locking is more clear. There should be no functional change. Reviewed by: pouria Fixes: 868bf82153e8 if: avoid interface destroy race MFC after: 1 week Differential Revision: https://reviews.freebsd.org/D56288
-rw-r--r--sys/net/if.c4
1 files changed, 2 insertions, 2 deletions
diff --git a/sys/net/if.c b/sys/net/if.c
index 519b23750b52..73138716cf46 100644
--- a/sys/net/if.c
+++ b/sys/net/if.c
@@ -479,6 +479,8 @@ vnet_if_return(const void *unused __unused)
i = 0;
+ /* The lock has already been aquired in vnet_destroy() */
+ sx_assert(&ifnet_detach_sxlock, SX_XLOCKED);
/*
* We need to protect our access to the V_ifnet tailq. Ordinarily we'd
* enter NET_EPOCH, but that's not possible, because if_vmove() calls
@@ -507,9 +509,7 @@ vnet_if_return(const void *unused __unused)
IFNET_WUNLOCK();
for (int j = 0; j < i; j++) {
- sx_xlock(&ifnet_detach_sxlock);
if_vmove(pending[j], pending[j]->if_home_vnet);
- sx_xunlock(&ifnet_detach_sxlock);
}
free(pending, M_IFNET);