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
This commit is contained in:
Kristof Provost 2023-12-05 20:08:11 +01:00
parent 3878bbf1bb
commit bd7b2f9501
2 changed files with 6 additions and 0 deletions

View file

@ -536,11 +536,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();
}
@ -592,6 +594,7 @@ vnet_deregister_sysuninit(void *arg)
* deregistered.
*/
VNET_SYSINIT_WLOCK();
VNET_LIST_RLOCK();
VNET_FOREACH(vnet) {
CURVNET_SET_QUIET(vnet);
vs->func(vs->arg);
@ -601,6 +604,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();
}
/*

View file

@ -661,11 +661,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();
}