Page MenuHomeFreeBSD

vmm: Use an sx lock to protect the memory map.
ClosedPublic

Authored by jhb on Oct 27 2022, 3:05 PM.
Tags
None
Referenced Files
Unknown Object (File)
Wed, May 8, 1:41 PM
Unknown Object (File)
Wed, May 8, 1:41 PM
Unknown Object (File)
Wed, May 8, 1:40 PM
Unknown Object (File)
Wed, May 8, 1:40 PM
Unknown Object (File)
Wed, May 8, 1:40 PM
Unknown Object (File)
Wed, May 8, 12:03 PM
Unknown Object (File)
Tue, May 7, 6:05 AM
Unknown Object (File)
Sun, May 5, 11:10 AM
Subscribers

Details

Summary

Previously bhyve obtained a "read lock" on the memory map for ioctls
needing to read the map by locking the last vCPU. This is now
replaced by a new per-VM sx lock. Modifying the map requires
exclusively locking the sx lock as well as locking all existing vCPUs.
Reading the map requires either locking one vCPU or the sx lock.

This permits safely modifying or querying the memory map while some
vCPUs do not exist which will be true in a future commit.

Diff Detail

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

Event Timeline

jhb requested review of this revision.Oct 27 2022, 3:05 PM

Typo in your commit log, modififying

Maybe you add one in a follow-up revision, but I think it'd be useful to document the locking protocol somewhere.

sys/amd64/vmm/vmm.c
727

Assert that the lock is held here?

782

Assert that the lock is held?

sys/amd64/vmm/vmm_dev.c
1269

This applies to the old code, but it seems a bit dubious that we increase the object refcount after dropping the lock. vmmdev_mmap_single() does not have this problem.

jhb marked 2 inline comments as done.Nov 4 2022, 9:46 PM
jhb added inline comments.
sys/amd64/vmm/vmm.c
782

It's not held by vm_cleanup(). I could add the assert but would need to add (somewhat pointless) locking in vm_cleanup().

sys/amd64/vmm/vmm_dev.c
1269

I'll add a followup.

jhb marked an inline comment as done.

Add assertion and locking key

This revision is now accepted and ready to land.Nov 4 2022, 11:13 PM

Add locking key for rendezvous_mtx

This revision now requires review to proceed.Nov 11 2022, 5:49 PM
This revision is now accepted and ready to land.Nov 14 2022, 6:55 AM
This revision was automatically updated to reflect the committed changes.