Received: by 2002:ad5:4acb:0:0:0:0:0 with SMTP id n11csp2900191imw; Sun, 10 Jul 2022 18:53:23 -0700 (PDT) X-Google-Smtp-Source: AGRyM1vBH1xZUvm4WikRBis9aThAduJ9SfxEXq8aCdBHE0dUufBNtvOHfucSUFWhTcpi4MXO1SV0 X-Received: by 2002:a17:902:8211:b0:16a:43ad:b832 with SMTP id x17-20020a170902821100b0016a43adb832mr15833096pln.165.1657504402812; Sun, 10 Jul 2022 18:53:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1657504402; cv=none; d=google.com; s=arc-20160816; b=tF4XNgpOVw+esgob2ieOnmXO/tQ1J4RpsqQibqX55YFCqax56wTomV+xC224TsdC1X x9cGyyCSm8MIdHHqC4vjVSijhwlw88B6biaLEFwJm6ZtZhYC1ySBnpkd8a39ltn6mEzi PzkvmNvueYNbmxFHLPxsjY7znLBlnB5vvBtJRNmTSTBFj4aYKieaJGrksPjmqwnBz9p1 l39pnPom2MMaN1lRBcv8GyKj9Cxd5lfizOa8vF9jR3/Mdt5dkixrUbaDaGoKAuRkczq8 iZDtZHE8A/WmN9yb/SiZrLnMPhdPeeT+rbAwjrdyRn+6DgQ33qfvOonLy7xW/XYTBKrB 4KiQ== 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=xureSuw2V9E7tzVjUzBjylXpgFwjrDdPqi99TNgwo2k=; b=HP59cNhsu8GFh/6oEPkUok3t8J5k3eTJ+yUFp6KuUK1b6d4ZzXLtdth9E1KtcsNHAq xSw8oQ6bE5zWESTZIZeVREdMaZyAeToR80FP84j24uBiupkVA5JXn8lB8xKKFBLWkNgz 9RrYLiTh0YV5288fZVtM5plLuQj4drdFfJ8lc3H/4QE88PpyG9l/GSWfXB7FZsBBRWxQ a2mbIFkb18KXVe6K6lcfwv2VuO7pJnkMxhtSe98QJNH/hrsl8C+t4ez5tO6yNo8ks/67 GD1KiqzYDyoyklw2A2SblUMAH80YKQhMYTs0v/SfcWHMj5catQyuz0b3w+IIZphvcC0u SVSw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=GlElJxs6; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id m8-20020a637d48000000b004121688026asi8216259pgn.217.2022.07.10.18.53.11; Sun, 10 Jul 2022 18:53:22 -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=@gmail.com header.s=20210112 header.b=GlElJxs6; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229717AbiGKBiP (ORCPT + 99 others); Sun, 10 Jul 2022 21:38:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40834 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229548AbiGKBiN (ORCPT ); Sun, 10 Jul 2022 21:38:13 -0400 Received: from mail-qk1-x72f.google.com (mail-qk1-x72f.google.com [IPv6:2607:f8b0:4864:20::72f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 14C6713DCB; Sun, 10 Jul 2022 18:38:13 -0700 (PDT) Received: by mail-qk1-x72f.google.com with SMTP id b25so2433340qkl.1; Sun, 10 Jul 2022 18:38:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=xureSuw2V9E7tzVjUzBjylXpgFwjrDdPqi99TNgwo2k=; b=GlElJxs6r9uyx/SQSYXULuTbs82yeDXXiSIJtB2p4ltiJUAxG9ZiGA77JLrro7RlQX 0kY2uWkVTgoPyTQhbejFres652JV82MmsmKKBoW3lGZVjXUzs+12F4Ds3sk8Hj8h2gqZ TKthuvDMbemYVTKyLKl9gtMEOcu1gE2GYBXWlJRP5kRRR08sHNwobRml2McKgUfTpkBm Stp0xir9M5UC+LyL8+nWyupiuK8UQalEUuKhWtpjANVl4t1qkAU7NxHjPigfxquc/ExS 0GQE90k2A3wgZURr1hM9eBXsn12M8PbjuTXwMkeWaDVvYrXYJf/5PfX2OzzSpjuD7XA7 BOQQ== 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=xureSuw2V9E7tzVjUzBjylXpgFwjrDdPqi99TNgwo2k=; b=jBYoH+2/c4BcryNjmyukl9s4jQEIiKm47pTnbdO5v03FIg8Z6ygxq31T6Rm0WBH8iv Rt+0yyuIVDIUynnls6CjKgP79qFJB4HTGvLjlw+zHT36nMGnjow/AKJQlNC4PYFT09Ui ZkgeD/bglC0zm/UnyoBlKDLTYZK521WQvP6nj/aSfHXIFST7M7ybeowUBEehRhrlFZyx FazAtFvnBKwKCim82Rh1f4jkm0rnD9ekBLCjsplXniqA8nILiBOPFOLG/XrEKO789agH HNiOe31RdSebZMGMuffExZwpzmDTRJ6NplUE+fC31N0p5qX2/MBnWU+uFwgFVbnj4AK6 AMeQ== X-Gm-Message-State: AJIora+pWFUDiTlLMjbGN/goXtB9L+/OjGYBVISw9EL/XqXAe4qtsSn9 aO6Lhn3QApmP+z26fQ7Ej9YT84o03D95VH1/TwU= X-Received: by 2002:a05:620a:430f:b0:6a7:9f9d:20cd with SMTP id u15-20020a05620a430f00b006a79f9d20cdmr9909341qko.389.1657503492197; Sun, 10 Jul 2022 18:38:12 -0700 (PDT) MIME-Version: 1.0 References: <20220710151105.687193-1-apatel@ventanamicro.com> In-Reply-To: <20220710151105.687193-1-apatel@ventanamicro.com> From: Bin Meng Date: Mon, 11 Jul 2022 09:37:59 +0800 Message-ID: Subject: Re: [PATCH] RISC-V: KVM: Fix SRCU deadlock caused by kvm_riscv_check_vcpu_requests() To: Anup Patel Cc: Paolo Bonzini , Atish Patra , Palmer Dabbelt , Paul Walmsley , Alistair Francis , Heinrich Schuchardt , Anup Patel , KVM General , kvm-riscv@lists.infradead.org, linux-riscv , linux-kernel 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,FREEMAIL_FROM, 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 11:11 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") nites: the "Fixes" tag should be put in a single line to avoid breaking scripts that parse the "Fixes" tag > 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) { > /* > -- Tested-by: Bin Meng