[PATCH v2 0/4] KVM: arm64: Fix vcpu->mutex v. kvm->lock inversion
Oliver Upton
oliver.upton at linux.dev
Thu Mar 16 14:14:08 PDT 2023
As it so happens, lock ordering in KVM/arm64 is completely backwards.
There's a significant amount of VM-wide state that needs to be accessed
from the context of a vCPU. Until now, this was accomplished by
acquiring the kvm->lock, but that cannot be nested within vcpu->mutex.
This series fixes the issue with some fine-grained locking for MP state
and a new, dedicated mutex that can nest with both kvm->lock and
vcpu->mutex.
Tested with kvmtool and QEMU scaled up to 64 vCPUs on a kernel w/
lockdep enabled. Applies to kvmarm/next.
v1: http://lore.kernel.org/kvmarm/20230308083947.3760066-1-oliver.upton@linux.dev
v1 -> v2:
- Add a dedicated lock for serializing writes to MP state
- Inform lockdep of acquisition order at time of VM/vCPU creation
- Plug a race with GIC creation (Sean)
- Use the config_lock in GIC ITS flows as well. There is now a single
(valid) use of kvm->lock when enabling MTE.
Oliver Upton (4):
KVM: arm64: Avoid vcpu->mutex v. kvm->lock inversion in CPU_ON
KVM: arm64: Avoid lock inversion when setting the VM register width
KVM: arm64: Use config_lock to protect data ordered against KVM_RUN
KVM: arm64: Use config_lock to protect vgic state
arch/arm64/include/asm/kvm_host.h | 4 ++
arch/arm64/kvm/arm.c | 45 +++++++++++++++++++----
arch/arm64/kvm/guest.c | 2 +
arch/arm64/kvm/hypercalls.c | 4 +-
arch/arm64/kvm/pmu-emul.c | 23 +++---------
arch/arm64/kvm/psci.c | 19 +++++-----
arch/arm64/kvm/reset.c | 16 ++++----
arch/arm64/kvm/vgic/vgic-debug.c | 8 ++--
arch/arm64/kvm/vgic/vgic-init.c | 33 ++++++++++-------
arch/arm64/kvm/vgic/vgic-its.c | 29 ++++++---------
arch/arm64/kvm/vgic/vgic-kvm-device.c | 53 ++++++++++++---------------
arch/arm64/kvm/vgic/vgic-mmio-v3.c | 4 +-
arch/arm64/kvm/vgic/vgic-mmio.c | 12 +++---
arch/arm64/kvm/vgic/vgic-v4.c | 11 +++---
arch/arm64/kvm/vgic/vgic.c | 2 +-
15 files changed, 146 insertions(+), 119 deletions(-)
--
2.40.0.rc1.284.g88254d51c5-goog
More information about the linux-arm-kernel
mailing list