Received: by 2002:ad5:4acb:0:0:0:0:0 with SMTP id n11csp2525422imw; Sun, 10 Jul 2022 08:27:32 -0700 (PDT) X-Google-Smtp-Source: AGRyM1vWxB70KMZs6iqkJdB+mHhmj1Q8S6csYfXpzzqdDhSp//aELSH707li2lMyJjH1TcO8ZaJn X-Received: by 2002:a17:90b:1e4f:b0:1ef:aa42:f196 with SMTP id pi15-20020a17090b1e4f00b001efaa42f196mr11949739pjb.228.1657466852543; Sun, 10 Jul 2022 08:27:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1657466852; cv=none; d=google.com; s=arc-20160816; b=kg5493u5HexMjZMeNFt6lyltWfZqPGFW5JnmdfjkyQGitlBmv2rkBSPjQ9QWv0KhVN 9ld2nV7egxkU+ASAyqVWHUKfSAQdKq3iu2f2OdJFdIRYY66Y2qNRiPKp4BgfyhkI6iaY 2CI1X6ShapWyfKm+maEO5txxAlnRgfi+lMod7nZBNLeh6K9TkcXXuvW/SaWmTwPULz4c FJTzR1lu6du9JBxJlp/w7j0gG/GRACmCZWYzC/avRQLzC8ktn3/tscuW8SoyGPj2sGrP N4po3Gr7TpeAgQmX09YiSrvyDfko0+zywMXfTsLOxWlUc8QDj3n8JfjGN0AbrQWV8cM2 Yw9g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=ZiGKAq8E/61V/xfD2osUhAigUxFAGIjOAFkVRU11S5c=; b=ulBJSi3WypkKmJfwfrGPWlJLkuuMc6A80XUIfZQwCneeGeXlaf0cjtnc2S1OSmb2aE oV0SKDTOI7PAIT9XRr5a0d7hr06RrVh0m1q8nTRcfml0B6lZEn4SUw6HXrkaHDPgMD7a 9Pmr0qMs3mv/CnoOFUDob3dPWnGr9kCD7QWfSdgFzNIsGNzLs4jr34eXdtCs4Tzgx1DJ dqvYnk9j9iOHR9CP+V3QR5hcx/xUcEa4yajrlkslGm037f2ijrmSQxLYRsWKMy9RGXrg cziFfyjbQR73RRJm2ceqIGyHM9Z0LMnPoDe1McqObFGeUnMRKKRaucoDq8aT+9kaqQOj al6g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ventanamicro.com header.s=google header.b=SwASqhsq; 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 mh17-20020a17090b4ad100b001f01fcbab18si5515413pjb.20.2022.07.10.08.27.19; Sun, 10 Jul 2022 08:27:32 -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=SwASqhsq; 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 S229598AbiGJPLq (ORCPT + 99 others); Sun, 10 Jul 2022 11:11:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35282 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229492AbiGJPLp (ORCPT ); Sun, 10 Jul 2022 11:11:45 -0400 Received: from mail-pj1-x1030.google.com (mail-pj1-x1030.google.com [IPv6:2607:f8b0:4864:20::1030]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 42962BCA8 for ; Sun, 10 Jul 2022 08:11:44 -0700 (PDT) Received: by mail-pj1-x1030.google.com with SMTP id 89-20020a17090a09e200b001ef7638e536so6107578pjo.3 for ; Sun, 10 Jul 2022 08:11:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=ZiGKAq8E/61V/xfD2osUhAigUxFAGIjOAFkVRU11S5c=; b=SwASqhsqF/uwpbfqLellpCwOiSzS2k5/C73tZViHwi+wlDrtSvqy/CLZnD2QvQx14O 05Hik6bMxgJLrqyo0hAR3hJVC2DjtGviASL9QpxRfJ2Mr7prJ0NLHiUeNc6BuYBZft4X ZTAqYVdhB8j7EjMsADYyuJSDB4RG6atPSLW3MPkjzoKYaSrWiG9MEd4+xUmzJ7pjW7n0 v8/5ZFNEOPxeviRy8dbKLUM+VbcoYbCkWE78lVU+ATrf/m6cHHGj76Xk5hFSN2VmLNRw k84hTH7nPLuk9tK4wybq6iny6+lXDfG8UDKS9AImQNoG7IoP2xyJCGkMNzNNgc+CpBIZ UO2A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=ZiGKAq8E/61V/xfD2osUhAigUxFAGIjOAFkVRU11S5c=; b=C0YZhxt18+E/P3kAvFxrpTCFZ22Zm1J5GVy5+NK9Uatz3VOjQ/AvvUCxwLZEjyBoJX F12n4AEa6U/KZEx2EHze6rBfVO38S+p9MbyFxz6kRqsR/EvPPn1PH0AUMatp1OOXt7ck TWAbDysr75g5aGqiufSufVdxXvEc004QRPRUe20yvVgQgpjKbzu3cXjyH2Kf9PVUqMwM nG10oYx4oNvaRV1cpgL6zJvwxJh4MB1Bl+m7rYQO3Ly3P0/LWwkbplYSRT6r9g24Zr7e HZi55bl0oUJSXNTY6AKTi5BUOp/kwyFZZ3ViHTVyFDDOaQ7d+NEV1pD9xuC04xC5nGwg pHOw== X-Gm-Message-State: AJIora8dvLrIxcP6gx+nBVM85M+d7+1j0KO1eWxqenoExn1SvyhePvMG FmyuiCgmK8lPqrfNRirTxIsTHw== X-Received: by 2002:a17:90b:1c86:b0:1ee:e795:a6a with SMTP id oo6-20020a17090b1c8600b001eee7950a6amr11794505pjb.205.1657465903563; Sun, 10 Jul 2022 08:11:43 -0700 (PDT) Received: from anup-ubuntu64-vm.. ([122.167.98.167]) by smtp.gmail.com with ESMTPSA id a200-20020a621ad1000000b0052ab37ef3absm3014756pfa.116.2022.07.10.08.11.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 10 Jul 2022 08:11:42 -0700 (PDT) From: Anup Patel To: Paolo Bonzini , Atish Patra Cc: Palmer Dabbelt , Paul Walmsley , Alistair Francis , Bin Meng , Heinrich Schuchardt , Anup Patel , kvm@vger.kernel.org, kvm-riscv@lists.infradead.org, linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, Anup Patel Subject: [PATCH] RISC-V: KVM: Fix SRCU deadlock caused by kvm_riscv_check_vcpu_requests() Date: Sun, 10 Jul 2022 20:41:05 +0530 Message-Id: <20220710151105.687193-1-apatel@ventanamicro.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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=unavailable 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 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