Page MenuHomeFreeBSD

vmm: Allocate vCPUs on first use of a vCPU.
ClosedPublic

Authored by jhb on Oct 27 2022, 3:06 PM.
Tags
None
Referenced Files
Unknown Object (File)
Wed, Nov 13, 10:02 PM
Unknown Object (File)
Tue, Nov 12, 12:28 AM
Unknown Object (File)
Sun, Nov 10, 4:37 AM
Unknown Object (File)
Sat, Nov 9, 11:29 AM
Unknown Object (File)
Sat, Nov 9, 9:13 AM
Unknown Object (File)
Sat, Nov 9, 8:12 AM
Unknown Object (File)
Sat, Nov 9, 6:05 AM
Unknown Object (File)
Sat, Nov 9, 4:14 AM

Details

Summary

Convert the vcpu[] array in struct vm to an array of pointers and
allocate vCPUs on first use. This avoids always allocating VM_MAXCPU
vCPUs for each VM, but instead only allocates the vCPUs in use. A new
per-VM sx lock is added to serialize attempts to allocate vCPUs on
first use. However, a given vCPU is never freed while the VM is
active, so the pointer is read via an unlocked read first to avoid the
need for the lock in the common case once the vCPU has been created.

Some ioctls need to lock all vCPUs. To prevent races with ioctls that
want to allocata a new vCPU, these ioctls also lock the sx lock that
protects vCPU creation.

Diff Detail

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

Event Timeline

corvink added inline comments.
sys/amd64/vmm/vmm_dev.c
168–169

Just a suggestion.

187–188

Just a suggestion.

jhb marked 2 inline comments as done.Nov 4 2022, 9:51 PM
This revision is now accepted and ready to land.Nov 7 2022, 7:26 AM
markj added inline comments.
sys/amd64/vmm/vmm.c
516

I'd make this an atomic_load_ptr().

614

Add __unused then?

jhb marked 2 inline comments as done.Nov 11 2022, 5:51 PM
This revision now requires review to proceed.Nov 11 2022, 5:52 PM
This revision is now accepted and ready to land.Nov 14 2022, 7:01 AM
This revision was automatically updated to reflect the committed changes.