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, Apr 24, 2:12 PM
Unknown Object (File)
Wed, Apr 24, 2:12 PM
Unknown Object (File)
Wed, Apr 24, 2:12 PM
Unknown Object (File)
Wed, Apr 24, 2:12 PM
Unknown Object (File)
Wed, Apr 24, 2:12 PM
Unknown Object (File)
Sun, Apr 21, 8:17 PM
Unknown Object (File)
Feb 15 2024, 6:02 AM
Unknown Object (File)
Feb 15 2024, 6:02 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.