Skip to content

Commit

Permalink
RISC-V: KVM: Fix SRCU deadlock caused by kvm_riscv_check_vcpu_requests()
Browse files Browse the repository at this point in the history
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 <[email protected]>
Signed-off-by: Anup Patel <[email protected]>
Reviewed-by: Atish Patra <[email protected]>
Tested-by: Heinrich Schuchardt <[email protected]>
Tested-by: Bin Meng <[email protected]>
Signed-off-by: Anup Patel <[email protected]>
  • Loading branch information
avpatel committed Jul 11, 2022
1 parent 8857338 commit be82abe
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions arch/riscv/kvm/vcpu.c
Original file line number Diff line number Diff line change
Expand Up @@ -781,9 +781,11 @@ static void kvm_riscv_check_vcpu_requests(struct kvm_vcpu *vcpu)

if (kvm_request_pending(vcpu)) {
if (kvm_check_request(KVM_REQ_SLEEP, vcpu)) {
kvm_vcpu_srcu_read_unlock(vcpu);
rcuwait_wait_event(wait,
(!vcpu->arch.power_off) && (!vcpu->arch.pause),
TASK_INTERRUPTIBLE);
kvm_vcpu_srcu_read_lock(vcpu);

if (vcpu->arch.power_off || vcpu->arch.pause) {
/*
Expand Down

0 comments on commit be82abe

Please sign in to comment.