HomeFreeBSD

vmm: Allocate vCPUs on first use of a vCPU.

Description

vmm: Allocate vCPUs on first use of a vCPU.

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 allocate a new vCPU, these ioctls also lock the sx lock that
protects vCPU creation.

Reviewed by: corvink, markj
Differential Revision: https://reviews.freebsd.org/D37174

(cherry picked from commit 98568a005a193ce2c37702a8377ddd10c570e452)

Details

Provenance
jhbAuthored on Nov 18 2022, 6:05 PM
Reviewer
corvink
Differential Revision
D37174: vmm: Allocate vCPUs on first use of a vCPU.
Parents
rG5d3ee23b91f3: vmm: don't lock a mtx in the icr_low write handler
Branches
Unknown
Tags
Unknown