Skip to contentSkip to conversation

RISC-V: KVM: lock the correct mp_state during reset

PATCH Applied Radim Krčmář 3 participants 3 messages May 23, 2025 – Jun 10, 2025

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 RISC-V: KVM: lock the correct mp_state during reset

We're writing to *tmp, but locking *vcpu.

Fixes 2121cadec45a ("RISCV: KVM: Introduce mp_state_lock to avoid lock inversion")
---
 arch/riscv/kvm/vcpu_sbi.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
arch/riscv/kvm/vcpu_sbi.c +2 -2
index 31fd3cc98d66..6e09b518a5d1 100644
@@ -143,9 +143,9 @@ void kvm_riscv_vcpu_sbi_system_reset(struct kvm_vcpu *vcpu,
 	struct kvm_vcpu *tmp;
 
 	kvm_for_each_vcpu(i, tmp, vcpu->kvm) {
-		spin_lock(&vcpu->arch.mp_state_lock);
+		spin_lock(&tmp->arch.mp_state_lock);
 		WRITE_ONCE(tmp->arch.mp_state.mp_state, KVM_MP_STATE_STOPPED);
-		spin_unlock(&vcpu->arch.mp_state_lock);
+		spin_unlock(&tmp->arch.mp_state_lock);
 	}
 	kvm_make_all_cpus_request(vcpu->kvm, KVM_REQ_SLEEP);
 
Signature · 1 line
2.49.0
maintainer Reviewed-by on v1 1/1
#1 lore raw
Quoted 5 lines · Radim Krčmář

We're writing to *tmp, but locking *vcpu.

Fixes 2121cadec45a ("RISCV: KVM: Introduce mp_state_lock to avoid lock inversion")

LGTM.

Improved commit description at the time of queuing.

Queued this patch for Linux-6.16

Thanks,
Anup

Quoted 23 lines
---
 arch/riscv/kvm/vcpu_sbi.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
arch/riscv/kvm/vcpu_sbi.c +2 -3
index 31fd3cc98d66..6e09b518a5d1 100644
@@ -143,9 +143,9 @@ void kvm_riscv_vcpu_sbi_system_reset(struct kvm_vcpu *vcpu,
        struct kvm_vcpu *tmp;
 
        kvm_for_each_vcpu(i, tmp, vcpu->kvm) {
-               spin_lock(&vcpu->arch.mp_state_lock);
+               spin_lock(&tmp->arch.mp_state_lock);
                WRITE_ONCE(tmp->arch.mp_state.mp_state, KVM_MP_STATE_STOPPED);
-               spin_unlock(&vcpu->arch.mp_state_lock);
+               spin_unlock(&tmp->arch.mp_state_lock);
        }
        kvm_make_all_cpus_request(vcpu->kvm, KVM_REQ_SLEEP);
 
--

2.49.0

#2 lore raw
In reply to Radim Krčmář
This patch was applied to riscv/linux.git (fixes) by Anup Patel <[email protected]>:

Hello:

This patch was applied to riscv/linux.git (fixes)
by Anup Patel <[email protected]>:

Quoted 7 lines · On Fri, 23 May 2025 12:47:28 +0200 you wrote:

We're writing to *tmp, but locking *vcpu.

Fixes 2121cadec45a ("RISCV: KVM: Introduce mp_state_lock to avoid lock inversion")
---
 arch/riscv/kvm/vcpu_sbi.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

Here is the summary with links:
- RISC-V: KVM: lock the correct mp_state during reset

    https://git.kernel.org/riscv/c/7917be170928

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html