mbox series

[v2,0/2] RISCV: KVM: Avoid lock inversion in SBI_EXT_HSM_HART_START

Message ID 20240417074528.16506-1-yongxuan.wang@sifive.com (mailing list archive)
Headers show
Series RISCV: KVM: Avoid lock inversion in SBI_EXT_HSM_HART_START | expand

Message

Yong-Xuan Wang April 17, 2024, 7:45 a.m. UTC
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.

The use of kvm->lock over there ensures that only one VCPU can update
the reset context and call SBI_EXT_HSM_HART_START for the target VCPU
simultaneously. This patchset divides it into 2 separate spinlock, and
replace vcpu->power_off with vcpu->mp_state.

---
v2:
- rename the hsm_start_lock to mp_state_lock
- replace vcpu->power_off with vcpu->mp_state in PATCH1
- add vcpu->reset_cntx_lock in PATCH2

Yong-Xuan Wang (2):
  RISCV: KVM: Introduce mp_state_lock to avoid lock inversion in
    SBI_EXT_HSM_HART_START
  RISCV: KVM: Introduce vcpu->reset_cntx_lock

 arch/riscv/include/asm/kvm_host.h |  8 +++-
 arch/riscv/kvm/vcpu.c             | 62 ++++++++++++++++++++++++-------
 arch/riscv/kvm/vcpu_sbi.c         |  7 +++-
 arch/riscv/kvm/vcpu_sbi_hsm.c     | 26 +++++++++----
 4 files changed, 78 insertions(+), 25 deletions(-)

Comments

Anup Patel April 22, 2024, 5:13 a.m. UTC | #1
On Wed, Apr 17, 2024 at 1:15 PM Yong-Xuan Wang <yongxuan.wang@sifive.com> wrote:
>
> 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.
>
> The use of kvm->lock over there ensures that only one VCPU can update
> the reset context and call SBI_EXT_HSM_HART_START for the target VCPU
> simultaneously. This patchset divides it into 2 separate spinlock, and
> replace vcpu->power_off with vcpu->mp_state.
>
> ---
> v2:
> - rename the hsm_start_lock to mp_state_lock
> - replace vcpu->power_off with vcpu->mp_state in PATCH1
> - add vcpu->reset_cntx_lock in PATCH2
>
> Yong-Xuan Wang (2):
>   RISCV: KVM: Introduce mp_state_lock to avoid lock inversion in
>     SBI_EXT_HSM_HART_START
>   RISCV: KVM: Introduce vcpu->reset_cntx_lock

Queued this series for Linux-6.10

Thanks,
Anup

>
>  arch/riscv/include/asm/kvm_host.h |  8 +++-
>  arch/riscv/kvm/vcpu.c             | 62 ++++++++++++++++++++++++-------
>  arch/riscv/kvm/vcpu_sbi.c         |  7 +++-
>  arch/riscv/kvm/vcpu_sbi_hsm.c     | 26 +++++++++----
>  4 files changed, 78 insertions(+), 25 deletions(-)
>
> --
> 2.17.1
>
>
> --
> kvm-riscv mailing list
> kvm-riscv@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/kvm-riscv