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
F102646855: D42927.diff
Fri, Nov 15, 7:26 AM
Unknown Object (File)
Sep 30 2024, 12:14 AM
Unknown Object (File)
Sep 28 2024, 7:19 AM
Unknown Object (File)
Sep 27 2024, 4:54 PM
Unknown Object (File)
Sep 27 2024, 9:00 AM
Unknown Object (File)
Sep 22 2024, 12:30 AM
Unknown Object (File)
Sep 6 2024, 1:37 AM
Unknown Object (File)
Sep 2 2024, 5:00 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 Skipped
Unit
Tests Skipped
Build Status
Buildable 54818
Build 51707: arc lint + arc unit

Event Timeline

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

you should unlock in the same order for consistency

the VNET_FOREACH macro should presumably assert on the lock?

sys/net/vnet.c
608

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
608

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.

608

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 .