Received: by 2002:ad5:4acb:0:0:0:0:0 with SMTP id n11csp2688662imw; Sun, 10 Jul 2022 12:41:28 -0700 (PDT) X-Google-Smtp-Source: AGRyM1ulgdP0XUQ4TFmvhdTXl+on4i8xO7m2mpMSiGoycpQyRn0Utmnz+ytYNqlWhuQ9jwMWinJT X-Received: by 2002:a17:903:11d0:b0:16b:80cf:5d9 with SMTP id q16-20020a17090311d000b0016b80cf05d9mr15208150plh.91.1657482088206; Sun, 10 Jul 2022 12:41:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1657482088; cv=none; d=google.com; s=arc-20160816; b=RdmPSLO8OqoywuM23q2OQAYAfLtyuMXOyd9/eySsWYB347xRmIjYhoKP9iKJtHUBP+ dKjM34zgByPehx7sgJb6Z8VqUnboKNKiq6fvlFNO5obHNu2yFJvmsR1qYK0GS32eTovl /6nHqknWm76QrWyr88zzim9ndyvkrZgdnE2iDKLnUPOW73RZ6DiB9CpHwLir14xy0vss FVTbBfnXlXcfULaKoXxjzz69A2CBUljtzZmHIR8WIezMxMi69OuERcgo4eoFYsQICkJO +mDePSnwFCYMJW7tcG7aWqSuLeInIQomr5lhbLud75at0nYhSa27T61ha1/qTMY0sF03 3WSA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=tkZ9euRFpN6RPFPNbwsacD82kKvLsZ80aQxI2epTktI=; b=D1gm5PFg/XskxT397GwTPMHVFSdQZFZWpa++lU9tYHTcHhJJgJVZ21nFPBnt666CiH CnAvAn9nt3cw4UKBNHunmvZAAbQTWYE16t1SekJ6UhsH9SvjS0gg4DGD/6wWYjqGICpo X/0wOQPsAOZxdqLbdfyqF346jcV324q2JXQiSM29N7lWrSqXW9F+W1IKOzlC4/LMOhF8 voIRfw2lg7lpKKG9ADQqypvw/+0n0+yAxgdvdxZ0DMTKsJyVek3M7a3qO7YJm/CuEKBd z56Vlx+qogh+vszT/ta3g5gAGfiNpgdkKRR5UwcIcnp0hlNpaAOPnOay9vHlptzpkaWS gGPw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@atishpatra.org header.s=google header.b=L+RFTeLR; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id i127-20020a626d85000000b005252ffbda2esi6472805pfc.36.2022.07.10.12.41.08; Sun, 10 Jul 2022 12:41:28 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@atishpatra.org header.s=google header.b=L+RFTeLR; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229572AbiGJTFp (ORCPT + 99 others); Sun, 10 Jul 2022 15:05:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51470 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229456AbiGJTFl (ORCPT ); Sun, 10 Jul 2022 15:05:41 -0400 Received: from mail-yw1-x1133.google.com (mail-yw1-x1133.google.com [IPv6:2607:f8b0:4864:20::1133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9B90D11C07 for ; Sun, 10 Jul 2022 12:05:40 -0700 (PDT) Received: by mail-yw1-x1133.google.com with SMTP id 00721157ae682-31c8bb90d09so30519627b3.8 for ; Sun, 10 Jul 2022 12:05:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=atishpatra.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=tkZ9euRFpN6RPFPNbwsacD82kKvLsZ80aQxI2epTktI=; b=L+RFTeLRQS0mezNdJHzI7btiFmANc6Tyji1uh+iIfM2RQA568qOWxJLcPkB/geHXey LYEiB/wcmktqV95Fmt2nxRwshkuSHKiY1rOB0rKj6dMVyVI5tWtGqq6uQKuZ/s3SbwDX vCEs8dEfgL3PtT+azgXyVO7NCPKhC5j2HYfzs= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=tkZ9euRFpN6RPFPNbwsacD82kKvLsZ80aQxI2epTktI=; b=4GCLC0APxzseKJwQu3as/ltPCyI+eiSkiIRVXXE/9whFYGqOWgN8THBN/K8SJ3CvJV TQd13qRoch8Gr1NO3pHIZyWGVfDnNO+HqBWPpSG8sNWXROx1tbgBvmTkw/5XmHqD6z9l Os6juiD1zwP55whBeVaAslR40sOS3dZHVgBP/CJ7rVdJNhOUPY2YOQyRe/1neqjCI+To oF7QzXuEJHpEzEbsbhlYS7X7+AMs4rXh+CgHeCkl2y3S7AZV+DbBE14xGZqQliba35ic Q10AdZZYBT3ciebkpmmTao7j/sJPcobw8W83ZsgNodpHsePiBj0QvVjs/3zr7bMMRH3u 4qeQ== X-Gm-Message-State: AJIora+op52okG2mADlsuHG6ksktUmRD2IXRpsUQrage8740fdNjAwuv hYCNjMjoKxXXat9xX1HI4BKUDpdyEZSq6HpnubFw X-Received: by 2002:a81:1514:0:b0:31c:a84b:350a with SMTP id 20-20020a811514000000b0031ca84b350amr16064656ywv.400.1657479939850; Sun, 10 Jul 2022 12:05:39 -0700 (PDT) MIME-Version: 1.0 References: <20220710151105.687193-1-apatel@ventanamicro.com> In-Reply-To: <20220710151105.687193-1-apatel@ventanamicro.com> From: Atish Patra Date: Sun, 10 Jul 2022 12:05:29 -0700 Message-ID: Subject: Re: [PATCH] RISC-V: KVM: Fix SRCU deadlock caused by kvm_riscv_check_vcpu_requests() To: Anup Patel Cc: Paolo Bonzini , Palmer Dabbelt , Paul Walmsley , Alistair Francis , Bin Meng , Heinrich Schuchardt , Anup Patel , KVM General , "open list:KERNEL VIRTUAL MACHINE FOR RISC-V (KVM/riscv)" , linux-riscv , "linux-kernel@vger.kernel.org List" Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sun, Jul 10, 2022 at 8:11 AM Anup Patel wrote: > > 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: cce69aff689e ("RISC-V: KVM: Implement VCPU interrupts and > requests handling") > Reported-by: Bin Meng > Signed-off-by: Anup Patel > --- > arch/riscv/kvm/vcpu.c | 2 ++ > 1 file changed, 2 insertions(+) > > diff --git a/arch/riscv/kvm/vcpu.c b/arch/riscv/kvm/vcpu.c > index b7a433c54d0f..5d271b597613 100644 > --- a/arch/riscv/kvm/vcpu.c > +++ b/arch/riscv/kvm/vcpu.c > @@ -845,9 +845,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) { > /* > -- > 2.34.1 > Reviewed-by: Atish Patra -- Regards, Atish