]> www.infradead.org Git - users/jedix/linux-maple.git/commit
KVM: Grab vcpu->mutex across installing the vCPU's fd and bumping online_vcpus
authorSean Christopherson <seanjc@google.com>
Wed, 9 Oct 2024 15:04:52 +0000 (08:04 -0700)
committerSean Christopherson <seanjc@google.com>
Mon, 16 Dec 2024 22:37:30 +0000 (14:37 -0800)
commit6e2b2358b3ef870d24109083d2e314d04fc72de4
tree98c689e4e3c33fbc70e36db603e23c487dd63408
parent0664dc74e9d004c36b4400081811df795169809a
KVM: Grab vcpu->mutex across installing the vCPU's fd and bumping online_vcpus

During vCPU creation, acquire vcpu->mutex prior to exposing the vCPU to
userspace, and hold the mutex until online_vcpus is bumped, i.e. until the
vCPU is fully online from KVM's perspective.

To ensure asynchronous vCPU ioctls also wait for the vCPU to come online,
explicitly check online_vcpus at the start of kvm_vcpu_ioctl(), and take
the vCPU's mutex to wait if necessary (having to wait for any ioctl should
be exceedingly rare, i.e. not worth optimizing).

Reported-by: Will Deacon <will@kernel.org>
Reported-by: Michal Luczaj <mhal@rbox.co>
Link: https://lore.kernel.org/all/20240730155646.1687-1-will@kernel.org
Acked-by: Will Deacon <will@kernel.org>
Link: https://lore.kernel.org/r/20241009150455.1057573-4-seanjc@google.com
Signed-off-by: Sean Christopherson <seanjc@google.com>
virt/kvm/kvm_main.c