Received: by 2002:ad5:4acb:0:0:0:0:0 with SMTP id n11csp4451626imw; Tue, 19 Jul 2022 06:55:20 -0700 (PDT) X-Google-Smtp-Source: AGRyM1tJmF+/CY6TIC0bUNBFhuJf/3+gZZtFWMzmewC+n8aEAZ0zdIXMOWFxi6hvTTijm1lEuN5B X-Received: by 2002:a05:6402:3311:b0:43a:8714:d486 with SMTP id e17-20020a056402331100b0043a8714d486mr44264100eda.136.1658238920326; Tue, 19 Jul 2022 06:55:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1658238920; cv=none; d=google.com; s=arc-20160816; b=D0s0ToCKbGuegB3kboQ7vnRoLIOQVfnaOQ0ktK++1xhNJ9Mo2j8HvmZICgEQNIXQv6 QEydv5zP6GXx1+5FP9m5TJRXg1j+Jn5GBvkQHOai1EUdmUYV1XkWKwOfHiiWMBGUmRkj 9+duG3Ovifgi2vhkOfNvdcprfpcdGw1pIZLxQc8YKPFDhHqPA3LTE9kF3cR3r8FK+pF1 9+eax7jmO/x257VI/pkcbtx5ri9icRX+Pus2Ndo7Jde/SvoWhNl4dFI5EJzANTI8h8Wp lsVdEup6t98DNCv23EbxpuEog4o3aELJKfn+o4AEpgwUzVTCIHV3K6TjRJy2WR6qWX+0 9EjQ== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=T1GCplpBONWrShE0qBFCCRAAWEaNEKiFiQN6Dx5nWyo=; b=qvy38zulv39w20UEzLKQsDm5T9Rg5PJCGmQm8v2RLSnNk3Y/XANhGddkJzukE82lz8 cNMrV8NA0xlyG6kAzoy4WrmBF+x1OnIphenJiCRkbLnCzZEfRzzCbkRtLY7VQHiAvseU MB2+N9DRqMx80RRD7qDaW+OLd33VQ0Alef4vWPh05+8SHr8Z3p3NfFWOphBemKdx21/K HivDetH4L5WrX+UJf0TTC/uXZ4pO2oZJ7zfQ7TikNTnW+qD70QLYcYHXm8D122iQPFBU cGk1YBKJ+i83lBiNAxDYpzGfOpsVYm9p1ApFrFtBqVMNTCtyAVyr0s9fVjVD3/PizpOn ywxw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=OM6IzAe9; 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=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id ji3-20020a170907980300b006fe9e9ed643si22645275ejc.48.2022.07.19.06.54.54; Tue, 19 Jul 2022 06:55:20 -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=@linuxfoundation.org header.s=korg header.b=OM6IzAe9; 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=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242349AbiGSM6e (ORCPT + 99 others); Tue, 19 Jul 2022 08:58:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40402 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242477AbiGSM5p (ORCPT ); Tue, 19 Jul 2022 08:57:45 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B1A085C9FB; Tue, 19 Jul 2022 05:23:13 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 5A0C3B81B1A; Tue, 19 Jul 2022 12:23:12 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8B988C341CA; Tue, 19 Jul 2022 12:23:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1658233391; bh=ZEvhBsiFb0MsBA5AbLVJ+Wg+sCQobeZjz46lu0goM20=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=OM6IzAe9YMNOQ8rekMkme+F6QeinKrR6und3ni8dTBDKWytaMQAnxVenlqWqkbL70 9LVgsdTyxItzUiJn3+q481LINzYFDXKCowOM1Dx9agkxl/ujXT3c2/yi2UJcepamds /sqWT+7NdES3Uy55PQpZQQBOZzE79ALE9ujIDdj8= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Bin Meng , Anup Patel , Atish Patra , Heinrich Schuchardt , Anup Patel , Sasha Levin Subject: [PATCH 5.18 089/231] RISC-V: KVM: Fix SRCU deadlock caused by kvm_riscv_check_vcpu_requests() Date: Tue, 19 Jul 2022 13:52:54 +0200 Message-Id: <20220719114722.253629343@linuxfoundation.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220719114714.247441733@linuxfoundation.org> References: <20220719114714.247441733@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.8 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS 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 From: Anup Patel [ Upstream commit be82abe6a76ba8e76f25312566182b0f13c4fbf9 ] 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 Reviewed-by: Atish Patra Tested-by: Heinrich Schuchardt Tested-by: Bin Meng Signed-off-by: Anup Patel Signed-off-by: Sasha Levin --- 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 7461f964d20a..3894777bfa87 100644 --- a/arch/riscv/kvm/vcpu.c +++ b/arch/riscv/kvm/vcpu.c @@ -673,9 +673,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.35.1