git: ccfc2d91304e - stable/15 - ifnet: vnet_if_return(): Avoid unnecessary recursive acquisition of ifnet_detach_sxlock
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Thu, 30 Apr 2026 09:53:21 UTC
The branch stable/15 has been updated by zlei:
URL: https://cgit.FreeBSD.org/src/commit/?id=ccfc2d91304e88aafc0ca0e13e0f8b5a156d2a01
commit ccfc2d91304e88aafc0ca0e13e0f8b5a156d2a01
Author: Zhenlei Huang <zlei@FreeBSD.org>
AuthorDate: 2026-04-13 04:38:43 +0000
Commit: Zhenlei Huang <zlei@FreeBSD.org>
CommitDate: 2026-04-30 09:52:00 +0000
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
(cherry picked from commit f1fae67afbb13a41d488d0e0ec66b1805925019c)
---
sys/net/if.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/sys/net/if.c b/sys/net/if.c
index 75ef79738010..7424da5ccf6d 100644
--- a/sys/net/if.c
+++ b/sys/net/if.c
@@ -489,6 +489,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
@@ -517,9 +519,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);