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)
Oct 8 2024, 4:08 AM
Unknown Object (File)
Sep 9 2024, 5:57 PM
Unknown Object (File)
Sep 7 2024, 6:19 PM
Unknown Object (File)
Sep 6 2024, 1:22 AM
Unknown Object (File)
Sep 4 2024, 4:12 AM
Unknown Object (File)
Sep 2 2024, 6:19 PM
Unknown Object (File)
Aug 31 2024, 5:49 PM
Unknown Object (File)
Aug 7 2024, 2:48 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 Skipped
Unit
Tests Skipped
Build Status
Buildable 48310
Build 45196: arc lint + arc unit

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.