RISCV: KVM: Introduce mp_state_lock to avoid lock inversion
authorYong-Xuan Wang <yongxuan.wang@sifive.com>
Wed, 17 Apr 2024 07:45:25 +0000 (15:45 +0800)
committerAnup Patel <anup@brainfault.org>
Mon, 22 Apr 2024 05:07:11 +0000 (10:37 +0530)
commit2121cadec45aaf61fa45b3aa3d99723ed4e6683a
tree4e2988e18b8011af58bca07e987a3c48d73bea6b
parentf1c48c1ec73538a8e49695445a0fbc52156aac42
RISCV: KVM: Introduce mp_state_lock to avoid lock inversion

Documentation/virt/kvm/locking.rst advises that kvm->lock should be
acquired outside vcpu->mutex and kvm->srcu. However, when KVM/RISC-V
handling SBI_EXT_HSM_HART_START, the lock ordering is vcpu->mutex,
kvm->srcu then kvm->lock.

Although the lockdep checking no longer complains about this after commit
f0f44752f5f6 ("rcu: Annotate SRCU's update-side lockdep dependencies"),
it's necessary to replace kvm->lock with a new dedicated lock to ensure
only one hart can execute the SBI_EXT_HSM_HART_START call for the target
hart simultaneously.

Additionally, this patch also rename "power_off" to "mp_state" with two
possible values. The vcpu->mp_state_lock also protects the access of
vcpu->mp_state.

Signed-off-by: Yong-Xuan Wang <yongxuan.wang@sifive.com>
Reviewed-by: Anup Patel <anup@brainfault.org>
Link: https://lore.kernel.org/r/20240417074528.16506-2-yongxuan.wang@sifive.com
Signed-off-by: Anup Patel <anup@brainfault.org>
arch/riscv/include/asm/kvm_host.h
arch/riscv/kvm/vcpu.c
arch/riscv/kvm/vcpu_sbi.c
arch/riscv/kvm/vcpu_sbi_hsm.c