git: 4102ee128b9f - stable/13 - vnet: (read) lock the vnet list while iterating it

From: Kristof Provost <kp_at_FreeBSD.org>
Date: Thu, 14 Dec 2023 11:20:40 UTC
The branch stable/13 has been updated by kp:

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

commit 4102ee128b9f0159f00e48c2f00f1b3b80cd0f1a
Author:     Kristof Provost <kp@FreeBSD.org>
AuthorDate: 2023-12-05 19:08:11 +0000
Commit:     Kristof Provost <kp@FreeBSD.org>
CommitDate: 2023-12-14 08:34:32 +0000

    vnet: (read) lock the vnet list while iterating it
    
    Ensure that the vnet list cannot be modified while we're running through
    it.
    
    Reviewed by:    mjg (previous version), zlei (previous version)
    MFC after:      1 week
    Sponsored by:   Rubicon Communications, LLC ("Netgate")
    Differential Revision:  https://reviews.freebsd.org/D42927
    
    (cherry picked from commit bd7b2f95019e9715150c34736279805de0818d09)
---
 sys/net/vnet.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/sys/net/vnet.c b/sys/net/vnet.c
index 4f61061853da..9bcc0a779d59 100644
--- a/sys/net/vnet.c
+++ b/sys/net/vnet.c
@@ -503,11 +503,13 @@ vnet_register_sysinit(void *arg)
 	 * Invoke the constructor on all the existing vnets when it is
 	 * registered.
 	 */
+	VNET_LIST_RLOCK();
 	VNET_FOREACH(vnet) {
 		CURVNET_SET_QUIET(vnet);
 		vs->func(vs->arg);
 		CURVNET_RESTORE();
 	}
+	VNET_LIST_RUNLOCK();
 	VNET_SYSINIT_WUNLOCK();
 }
 
@@ -559,6 +561,7 @@ vnet_deregister_sysuninit(void *arg)
 	 * deregistered.
 	 */
 	VNET_SYSINIT_WLOCK();
+	VNET_LIST_RLOCK();
 	VNET_FOREACH(vnet) {
 		CURVNET_SET_QUIET(vnet);
 		vs->func(vs->arg);
@@ -568,6 +571,7 @@ vnet_deregister_sysuninit(void *arg)
 	/* Remove the destructor from the global list of vnet destructors. */
 	TAILQ_REMOVE(&vnet_destructors, vs, link);
 	VNET_SYSINIT_WUNLOCK();
+	VNET_LIST_RUNLOCK();
 }
 
 /*