Received: by 2002:ad5:4acb:0:0:0:0:0 with SMTP id n11csp2982551imw; Sun, 10 Jul 2022 21:48:56 -0700 (PDT) X-Google-Smtp-Source: AGRyM1tYCoFw44MaIHjm0LWqsGZLBJDZXCEsnNNLCKow5pI3Bi/eMuLir+2lJsrmLkH5LajJM524 X-Received: by 2002:a17:902:f542:b0:16b:dbf1:2179 with SMTP id h2-20020a170902f54200b0016bdbf12179mr16871637plf.18.1657514935909; Sun, 10 Jul 2022 21:48:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1657514935; cv=none; d=google.com; s=arc-20160816; b=OUG5dRz0Ke+boH0rprmkm82ozMa0+3cXKJL5C7uSqugMHqshNYYgdXN45nly/P8KSC SwInshe5CPf2YG6zl2Zs+kqyoiVmbjzqwMl8ejlceQtZZH8dswwouPvALvOK9dK3ptLF jXUshU7d4uL33NOwJw8VNfkFHxiQ9a1Gek5IH7b2CwWjN3u7fgjIxxky9oJRvXRicdpt fxEwqe/EPPHd/azYmNuEmsnc5Fw0Bj12i8NWVQwz18t2hyF8rkM+HkYpM/k/ba3MjM/K 1xmGXyS0p1IURMwP6RVEgqN7lcSC2tUkLP5juD9rEUx8oTNTUSv2CHAzaK8XmWd4qO03 EjdA== 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=yokId+kL1XsUAJzXfOxjC7q00UnhVLg0heLq8/CzKNw=; b=slQi9D/Ebd6ICwKB2HJradUyNOTyFoWOsmBz9FBQzFGHSAMakULDEhjgKCfXIb6Yr3 CRV9nY3iU4MzLkX5O/Cvn1zm6pJpxSxVdewgzUvI3JJzj3RNLTkx68grB4HdtHBPIN0r 2+wJlO+cFdLhgk1N9R6Ou1irpfuXQXIrw9NFdkIkgdx0AHyEZMIZWn5QbUdhLPkXjgvo jQQqx8zLih/tV0trtPeCe+VFkHaBLWC1QABardgFJqtxqj0xlp+EX65959lGfslX90D8 GuX8D/rNhcPH1Aonz3gucLyc8CkIIMZwHbVtqTECcPaqRtx7gaQb3+P0AB3sC6X5DId1 UtWA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ventanamicro.com header.s=google header.b=ZY8Gy+sH; 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 o6-20020a635d46000000b004115b38e8e9si10628782pgm.705.2022.07.10.21.48.44; Sun, 10 Jul 2022 21:48:55 -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=@ventanamicro.com header.s=google header.b=ZY8Gy+sH; 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 S229634AbiGKEQi (ORCPT + 99 others); Mon, 11 Jul 2022 00:16:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57150 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229570AbiGKEQh (ORCPT ); Mon, 11 Jul 2022 00:16:37 -0400 Received: from mail-lj1-x22b.google.com (mail-lj1-x22b.google.com [IPv6:2a00:1450:4864:20::22b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 574C1186D2 for ; Sun, 10 Jul 2022 21:16:36 -0700 (PDT) Received: by mail-lj1-x22b.google.com with SMTP id u14so4825218ljh.2 for ; Sun, 10 Jul 2022 21:16:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=yokId+kL1XsUAJzXfOxjC7q00UnhVLg0heLq8/CzKNw=; b=ZY8Gy+sHLWu8VAYvzEiXRTHT9tuRT7ejaosM1Xw4V3DhLlBw2Af9kiToQwGhgSSWL6 KuXNkb0i3epNJ4ykkbpocsM2Tan54xsOLECsVy2OIHB0MDmQHKuyDj4aNVG50X/8xmKQ 4000H37gmgWprf0OeYatZ3qFHZy2hCNnwnbgrE3CgKaSoVtEfndEHG8fCC89B+ZYZ6a+ n+7N82T0k1KIxO5Jf2nqYhS60Dvv08dfX1qs5sGDQU/HCLb48UqkPYxTkhG2IYioaaBf R04SIhoyxkSEoa+ocCn+6DXlkhYEpailJNgOLnS+Vi9bm+K4Bxz9aN8chbL6rkgeH9zz mV1Q== 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=yokId+kL1XsUAJzXfOxjC7q00UnhVLg0heLq8/CzKNw=; b=ESTgdSbSMV8r9eOE67ptk2w8Hl+vn5rb5kwBFbixhj2n9yFOlpON8UOZ3WyNgpBNhe 4WtlAvtTrKRdvcB5aX4DlDPFoN7nQH9uVFVEyYCIYA3edPb2WSdmRvoaTk+g4U04UBR4 +5CMv/Y48Dcq75VbMQq4vxurPUzuKXWlcl0Osi6Wr6MXVltTY2bIb2SQaKEiNqQ0fDiE c8Bqqt89euhWhxYcmD60YSCM3nXdShifNtpdJRutz1pCNOZlQ38LPoWak2o6iSGiNx9w qK8bQDSNfsnUtjrQcplPMgslb5Oqup1IaPQcjekiYZesVTtPAda8bUntbpmc9KqLAc9z +WqA== X-Gm-Message-State: AJIora+lFsxwlsY7Md/fPgcukxSShjlSZG0hNhtjsHwKvU48EOp5XCpl Fba7734KkiC16mVVUUpTwdlnCuGRBAIUOIhK55pbZw== X-Received: by 2002:a2e:9dd3:0:b0:25d:4ee0:f55d with SMTP id x19-20020a2e9dd3000000b0025d4ee0f55dmr8524188ljj.266.1657512994653; Sun, 10 Jul 2022 21:16:34 -0700 (PDT) MIME-Version: 1.0 References: <20220710151105.687193-1-apatel@ventanamicro.com> In-Reply-To: <20220710151105.687193-1-apatel@ventanamicro.com> From: Anup Patel Date: Mon, 11 Jul 2022 09:46:19 +0530 Message-ID: Subject: Re: [PATCH] RISC-V: KVM: Fix SRCU deadlock caused by kvm_riscv_check_vcpu_requests() To: Paolo Bonzini , Atish Patra Cc: 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:41 PM 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 Thanks everyone for providing Tested-by and Reviewed-by. I have queued this patch for 5.19-rcX fixes. Regards, Anup > --- > 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 >