Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 04 May 2026 16:51:15 +0000
From:      Zhenlei Huang <zlei@FreeBSD.org>
To:        src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org
Subject:   git: e7063f1d8b5d - stable/14 - ifnet: vnet_if_return(): Avoid unnecessary recursive acquisition of ifnet_detach_sxlock
Message-ID:  <69f8ce83.25b3d.6acee854@gitrepo.freebsd.org>

index | next in thread | raw e-mail

The branch stable/14 has been updated by zlei:

URL: https://cgit.FreeBSD.org/src/commit/?id=e7063f1d8b5db637fdedc6a66abccc0efd76d9c7

commit e7063f1d8b5db637fdedc6a66abccc0efd76d9c7
Author:     Zhenlei Huang <zlei@FreeBSD.org>
AuthorDate: 2026-04-13 04:38:43 +0000
Commit:     Zhenlei Huang <zlei@FreeBSD.org>
CommitDate: 2026-05-04 16:49:41 +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)
    (cherry picked from commit ccfc2d91304e88aafc0ca0e13e0f8b5a156d2a01)
---
 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 1d6b2f7b9461..c4c2df61dd1d 100644
--- a/sys/net/if.c
+++ b/sys/net/if.c
@@ -491,6 +491,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
@@ -519,9 +521,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);


home | help

Want to link to this message? Use this
URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?69f8ce83.25b3d.6acee854>