diff options
author | Kristof Provost <kp@FreeBSD.org> | 2023-12-05 19:08:11 +0000 |
---|---|---|
committer | Kristof Provost <kp@FreeBSD.org> | 2023-12-14 11:20:25 +0000 |
commit | daaaeb3051bfb9b1a030b7623778c3ec251b2b2b (patch) | |
tree | b58d1e258734f1b6a1ffb1d3422820cfc618429a | |
parent | 35707083c6fb47d28aea5e421ea99b3f0daea0a6 (diff) | |
download | src-daaaeb3051bfb9b1a030b7623778c3ec251b2b2b.tar.gz src-daaaeb3051bfb9b1a030b7623778c3ec251b2b2b.zip |
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)
-rw-r--r-- | sys/net/vnet.c | 4 | ||||
-rw-r--r-- | sys/netinet/ip_reass.c | 2 |
2 files changed, 6 insertions, 0 deletions
diff --git a/sys/net/vnet.c b/sys/net/vnet.c index c4a623698341..5dec0433d31a 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(); } /* diff --git a/sys/netinet/ip_reass.c b/sys/netinet/ip_reass.c index 6f33c7a8a54b..2876e5bfdcdc 100644 --- a/sys/netinet/ip_reass.c +++ b/sys/netinet/ip_reass.c @@ -663,11 +663,13 @@ ipreass_drain(void) { VNET_ITERATOR_DECL(vnet_iter); + VNET_LIST_RLOCK(); VNET_FOREACH(vnet_iter) { CURVNET_SET(vnet_iter); ipreass_drain_vnet(); CURVNET_RESTORE(); } + VNET_LIST_RUNLOCK(); } |