Skip to content

Commit be82abe

Browse files
committed
RISC-V: KVM: Fix SRCU deadlock caused by kvm_riscv_check_vcpu_requests()
The kvm_riscv_check_vcpu_requests() is called with SRCU read lock held and for KVM_REQ_SLEEP request it will block the VCPU without releasing SRCU read lock. This causes KVM ioctls (such as KVM_IOEVENTFD) from other VCPUs of the same Guest/VM to hang/deadlock if there is any synchronize_srcu() or synchronize_srcu_expedited() in the path. To fix the above in kvm_riscv_check_vcpu_requests(), we should do SRCU read unlock before blocking the VCPU and do SRCU read lock after VCPU wakeup. Fixes: cce69af ("RISC-V: KVM: Implement VCPU interrupts and requests handling") Reported-by: Bin Meng <bmeng.cn@gmail.com> Signed-off-by: Anup Patel <apatel@ventanamicro.com> Reviewed-by: Atish Patra <atishp@rivosinc.com> Tested-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com> Tested-by: Bin Meng <bmeng.cn@gmail.com> Signed-off-by: Anup Patel <anup@brainfault.org>
1 parent 8857338 commit be82abe

1 file changed

Lines changed: 2 additions & 0 deletions

File tree

arch/riscv/kvm/vcpu.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -781,9 +781,11 @@ static void kvm_riscv_check_vcpu_requests(struct kvm_vcpu *vcpu)
781781

782782
if (kvm_request_pending(vcpu)) {
783783
if (kvm_check_request(KVM_REQ_SLEEP, vcpu)) {
784+
kvm_vcpu_srcu_read_unlock(vcpu);
784785
rcuwait_wait_event(wait,
785786
(!vcpu->arch.power_off) && (!vcpu->arch.pause),
786787
TASK_INTERRUPTIBLE);
788+
kvm_vcpu_srcu_read_lock(vcpu);
787789

788790
if (vcpu->arch.power_off || vcpu->arch.pause) {
789791
/*

0 commit comments

Comments
 (0)