Page MenuHomeFreeBSD

vnet: (read) lock the vnet list while iterating it
ClosedPublic

Authored by kp on Dec 6 2023, 2:48 PM.
Tags
None
Referenced Files
Unknown Object (File)
Fri, Apr 26, 1:52 AM
Unknown Object (File)
Wed, Apr 24, 7:19 PM
Unknown Object (File)
Mar 31 2024, 6:04 PM
Unknown Object (File)
Mar 5 2024, 9:04 AM
Unknown Object (File)
Feb 20 2024, 9:50 AM
Unknown Object (File)
Jan 11 2024, 2:46 AM
Unknown Object (File)
Dec 23 2023, 4:54 AM

Details

Summary

Ensure that the vnet list cannot be modified while we're running through
it.

MFC after: 1 week
Sponsored by: Rubicon Communications, LLC ("Netgate")

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

kp requested review of this revision.Dec 6 2023, 2:48 PM
mjg added inline comments.
sys/net/vnet.c
607

you should unlock in the same order for consistency

the VNET_FOREACH macro should presumably assert on the lock?

sys/net/vnet.c
607

It should, but the locking for the vnet list uses two different locks for reasons I do not currently understand.
So we'd have to MPASS(sx_locked(&vnet_sxlock) || rw_rowned(&vnet_rwlock));. Which is doubly annoying because rw_rowned() doesn't exist.

sys/net/vnet.c
607

that is a gap i'm going to plug

This revision is now accepted and ready to land.Dec 6 2023, 3:04 PM
zlei added a subscriber: zlei.
zlei added inline comments.
sys/net/vnet.c
596

In vnet_register_sysinit() we have lock order

VNET_SYSINIT_WLOCK();
VNET_LIST_RLOCK;

I think it is best to make lock order consistent with that in vnet_register_sysinit(), although dead lock is not possible.

607

you should unlock in the same order for consistency

I'd prefer to unlock in the reverse order. That is more natural for me.
Anyway unlock order does not matter much.

the VNET_FOREACH macro should presumably assert on the lock?

ipreass_drain() in sys/netinet/ip_reass.c also miss read lock.
I think it is good to have read lock assert in macro VNET_FOREACH .