From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id B29FCC433EF for ; Tue, 19 Apr 2022 08:55:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1350204AbiDSI6O (ORCPT ); Tue, 19 Apr 2022 04:58:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55772 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237640AbiDSI6L (ORCPT ); Tue, 19 Apr 2022 04:58:11 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id C2F9F25E86 for ; Tue, 19 Apr 2022 01:55:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1650358528; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=sAp+F+npHVI/LvkJesk2bVKFg1Wa6g6pN0S+Js80XoI=; b=Aw71b+3zqHHKd4FVZYq1L0a274qEGVML2saaD11UiuUz85rL/gTxz2E9e4NIQcMtTHqFqK vFE42w1zeJ6yzBvNJeEGTO/UKP4r5W/dSxUojNDhkGuOKCsnLzViigrM8FGpssN11v8Lqs kfjyFVYYUbSaTBmVLxsRu9WLwYaLPQQ= Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-121-cvwRzkmxM9Szm0_kiSLc0w-1; Tue, 19 Apr 2022 04:55:24 -0400 X-MC-Unique: cvwRzkmxM9Szm0_kiSLc0w-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id C56EF3811F2D; Tue, 19 Apr 2022 08:55:23 +0000 (UTC) Received: from starship (unknown [10.40.194.231]) by smtp.corp.redhat.com (Postfix) with ESMTP id 465364087D60; Tue, 19 Apr 2022 08:55:19 +0000 (UTC) Message-ID: <204c7265de2d69ed240d18e30c7595702277cdbb.camel@redhat.com> Subject: Re: [PATCH 1/3] KVM: x86: Don't re-acquire SRCU lock in complete_emulated_io() From: Maxim Levitsky To: Sean Christopherson , Anup Patel , Paul Walmsley , Palmer Dabbelt , Albert Ou , Christian Borntraeger , Janosch Frank , Claudio Imbrenda , Paolo Bonzini Cc: Atish Patra , David Hildenbrand , Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Joerg Roedel , linuxppc-dev@lists.ozlabs.org, kvm@vger.kernel.org, kvm-riscv@lists.infradead.org, linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org Date: Tue, 19 Apr 2022 11:55:18 +0300 In-Reply-To: <20220415004343.2203171-2-seanjc@google.com> References: <20220415004343.2203171-1-seanjc@google.com> <20220415004343.2203171-2-seanjc@google.com> Content-Type: text/plain; charset="UTF-8" User-Agent: Evolution 3.36.5 (3.36.5-2.fc32) MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Scanned-By: MIMEDefang 2.84 on 10.11.54.1 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, 2022-04-15 at 00:43 +0000, Sean Christopherson wrote: > Don't re-acquire SRCU in complete_emulated_io() now that KVM acquires the > lock in kvm_arch_vcpu_ioctl_run(). More importantly, don't overwrite > vcpu->srcu_idx. If the index acquired by complete_emulated_io() differs > from the one acquired by kvm_arch_vcpu_ioctl_run(), KVM will effectively > leak a lock and hang if/when synchronize_srcu() is invoked for the > relevant grace period. > > Fixes: 8d25b7beca7e ("KVM: x86: pull kvm->srcu read-side to kvm_arch_vcpu_ioctl_run") > Cc: stable@vger.kernel.org > Signed-off-by: Sean Christopherson > --- > arch/x86/kvm/x86.c | 7 +------ > 1 file changed, 1 insertion(+), 6 deletions(-) > > diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c > index ab336f7c82e4..f35fe09de59d 100644 > --- a/arch/x86/kvm/x86.c > +++ b/arch/x86/kvm/x86.c > @@ -10450,12 +10450,7 @@ static int vcpu_run(struct kvm_vcpu *vcpu) > > static inline int complete_emulated_io(struct kvm_vcpu *vcpu) > { > - int r; > - > - vcpu->srcu_idx = srcu_read_lock(&vcpu->kvm->srcu); > - r = kvm_emulate_instruction(vcpu, EMULTYPE_NO_DECODE); > - srcu_read_unlock(&vcpu->kvm->srcu, vcpu->srcu_idx); > - return r; > + return kvm_emulate_instruction(vcpu, EMULTYPE_NO_DECODE); > } > > static int complete_emulated_pio(struct kvm_vcpu *vcpu) I wonder how this did work.... Reviewed-by: Maxim Levitsky Best regards, Maxim Levitsky From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 9222AC433EF for ; Tue, 19 Apr 2022 08:56:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Date:Cc:To:From:Subject:Message-ID:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=eqRaLBCPWt3npuarEOc+CPylrZ71Phf04hd8fhWuTWg=; b=hkPziES2/gTgJn 0JdbdDc4agmhhfJfsE1bBZ3P0FJoM7I3Hv6PbiJHWvB37IuPgab74/iwWVb27OaciH2uQUfbIhGq5 Ye36Cnq4GAradhngO1H5UCMQyH59E+xXSQIUXvsm49PH7o7uoH+g4FTEshqyo7ZZDppeHk4UwDk+o MhWrP50EOmIHO8ZedddxFI92j4S2JVEzH5zsShPpJLgZc81t8e24oC7BMmEZWNb2huQoBqHMCTb6L v8zjFeKTOM7L2bR5bAcj9jBzUd+ul+SIPDI2nVYb02NP0yJEIBSl0bzC9lhv7/EsOlawJ5RmbKhy0 puzYNPvL7UUjRnUICZ3Q==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1ngjed-002R91-NZ; Tue, 19 Apr 2022 08:56:11 +0000 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1ngjdx-002QnQ-UH for linux-riscv@lists.infradead.org; Tue, 19 Apr 2022 08:55:31 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1650358526; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=sAp+F+npHVI/LvkJesk2bVKFg1Wa6g6pN0S+Js80XoI=; b=d4VkmmEv1jRIZOHM2aCUREWUUQ5E0ITtDTcmHLBYr3tYrofzWLnlHFlVjlupJKd9qkSPse KgzF/tjFlrpEPEwTlZjLi7IMEsQMAGErNi67HE5kRcGiEYMWFAjoswSPfH3iWALIxr42fi 9LN3HUP2WjGwm0OIK9aJNhGkLE8TPnY= Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-121-cvwRzkmxM9Szm0_kiSLc0w-1; Tue, 19 Apr 2022 04:55:24 -0400 X-MC-Unique: cvwRzkmxM9Szm0_kiSLc0w-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id C56EF3811F2D; Tue, 19 Apr 2022 08:55:23 +0000 (UTC) Received: from starship (unknown [10.40.194.231]) by smtp.corp.redhat.com (Postfix) with ESMTP id 465364087D60; Tue, 19 Apr 2022 08:55:19 +0000 (UTC) Message-ID: <204c7265de2d69ed240d18e30c7595702277cdbb.camel@redhat.com> Subject: Re: [PATCH 1/3] KVM: x86: Don't re-acquire SRCU lock in complete_emulated_io() From: Maxim Levitsky To: Sean Christopherson , Anup Patel , Paul Walmsley , Palmer Dabbelt , Albert Ou , Christian Borntraeger , Janosch Frank , Claudio Imbrenda , Paolo Bonzini Cc: Atish Patra , David Hildenbrand , Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Joerg Roedel , linuxppc-dev@lists.ozlabs.org, kvm@vger.kernel.org, kvm-riscv@lists.infradead.org, linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org Date: Tue, 19 Apr 2022 11:55:18 +0300 In-Reply-To: <20220415004343.2203171-2-seanjc@google.com> References: <20220415004343.2203171-1-seanjc@google.com> <20220415004343.2203171-2-seanjc@google.com> User-Agent: Evolution 3.36.5 (3.36.5-2.fc32) MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.11.54.1 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220419_015530_163331_41EA7FA0 X-CRM114-Status: GOOD ( 17.64 ) X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org On Fri, 2022-04-15 at 00:43 +0000, Sean Christopherson wrote: > Don't re-acquire SRCU in complete_emulated_io() now that KVM acquires the > lock in kvm_arch_vcpu_ioctl_run(). More importantly, don't overwrite > vcpu->srcu_idx. If the index acquired by complete_emulated_io() differs > from the one acquired by kvm_arch_vcpu_ioctl_run(), KVM will effectively > leak a lock and hang if/when synchronize_srcu() is invoked for the > relevant grace period. > > Fixes: 8d25b7beca7e ("KVM: x86: pull kvm->srcu read-side to kvm_arch_vcpu_ioctl_run") > Cc: stable@vger.kernel.org > Signed-off-by: Sean Christopherson > --- > arch/x86/kvm/x86.c | 7 +------ > 1 file changed, 1 insertion(+), 6 deletions(-) > > diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c > index ab336f7c82e4..f35fe09de59d 100644 > --- a/arch/x86/kvm/x86.c > +++ b/arch/x86/kvm/x86.c > @@ -10450,12 +10450,7 @@ static int vcpu_run(struct kvm_vcpu *vcpu) > > static inline int complete_emulated_io(struct kvm_vcpu *vcpu) > { > - int r; > - > - vcpu->srcu_idx = srcu_read_lock(&vcpu->kvm->srcu); > - r = kvm_emulate_instruction(vcpu, EMULTYPE_NO_DECODE); > - srcu_read_unlock(&vcpu->kvm->srcu, vcpu->srcu_idx); > - return r; > + return kvm_emulate_instruction(vcpu, EMULTYPE_NO_DECODE); > } > > static int complete_emulated_pio(struct kvm_vcpu *vcpu) I wonder how this did work.... Reviewed-by: Maxim Levitsky Best regards, Maxim Levitsky _______________________________________________ linux-riscv mailing list linux-riscv@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-riscv From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.ozlabs.org (lists.ozlabs.org [112.213.38.117]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 12505C433EF for ; Tue, 19 Apr 2022 10:57:42 +0000 (UTC) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4KjLP04Dxvz3brv for ; Tue, 19 Apr 2022 20:57:40 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=Aw71b+3z; dkim=fail reason="signature verification failed" (1024-bit key) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=hixjpFQx; dkim-atps=neutral Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=redhat.com (client-ip=170.10.129.124; helo=us-smtp-delivery-124.mimecast.com; envelope-from=mlevitsk@redhat.com; receiver=) Authentication-Results: lists.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=Aw71b+3z; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=hixjpFQx; dkim-atps=neutral Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 4KjHh63qJ8z2y8R for ; Tue, 19 Apr 2022 18:55:31 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1650358528; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=sAp+F+npHVI/LvkJesk2bVKFg1Wa6g6pN0S+Js80XoI=; b=Aw71b+3zqHHKd4FVZYq1L0a274qEGVML2saaD11UiuUz85rL/gTxz2E9e4NIQcMtTHqFqK vFE42w1zeJ6yzBvNJeEGTO/UKP4r5W/dSxUojNDhkGuOKCsnLzViigrM8FGpssN11v8Lqs kfjyFVYYUbSaTBmVLxsRu9WLwYaLPQQ= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1650358529; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=sAp+F+npHVI/LvkJesk2bVKFg1Wa6g6pN0S+Js80XoI=; b=hixjpFQx5ywOZnMBuC/Q/KLk7b8NKp+aYryc3+qNs9HNYF4/WTCpgthlpUBv1xY9rvUmqY uwknRI7yfG3t3DqRF27Qm/BxR31EwVlIcdJHwyOfUDBlb/cotqFYve5AbAq+XDoDC+QCt5 sbQPSuAFfX64DgUacnSCJBYfVuW3is8= Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-121-cvwRzkmxM9Szm0_kiSLc0w-1; Tue, 19 Apr 2022 04:55:24 -0400 X-MC-Unique: cvwRzkmxM9Szm0_kiSLc0w-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id C56EF3811F2D; Tue, 19 Apr 2022 08:55:23 +0000 (UTC) Received: from starship (unknown [10.40.194.231]) by smtp.corp.redhat.com (Postfix) with ESMTP id 465364087D60; Tue, 19 Apr 2022 08:55:19 +0000 (UTC) Message-ID: <204c7265de2d69ed240d18e30c7595702277cdbb.camel@redhat.com> Subject: Re: [PATCH 1/3] KVM: x86: Don't re-acquire SRCU lock in complete_emulated_io() From: Maxim Levitsky To: Sean Christopherson , Anup Patel , Paul Walmsley , Palmer Dabbelt , Albert Ou , Christian Borntraeger , Janosch Frank , Claudio Imbrenda , Paolo Bonzini Date: Tue, 19 Apr 2022 11:55:18 +0300 In-Reply-To: <20220415004343.2203171-2-seanjc@google.com> References: <20220415004343.2203171-1-seanjc@google.com> <20220415004343.2203171-2-seanjc@google.com> Content-Type: text/plain; charset="UTF-8" User-Agent: Evolution 3.36.5 (3.36.5-2.fc32) MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Scanned-By: MIMEDefang 2.84 on 10.11.54.1 X-Mailman-Approved-At: Tue, 19 Apr 2022 20:56:27 +1000 X-BeenThere: linuxppc-dev@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Wanpeng Li , kvm@vger.kernel.org, David Hildenbrand , Joerg Roedel , linux-kernel@vger.kernel.org, kvm-riscv@lists.infradead.org, Atish Patra , Vitaly Kuznetsov , linuxppc-dev@lists.ozlabs.org, linux-riscv@lists.infradead.org, Jim Mattson Errors-To: linuxppc-dev-bounces+linuxppc-dev=archiver.kernel.org@lists.ozlabs.org Sender: "Linuxppc-dev" On Fri, 2022-04-15 at 00:43 +0000, Sean Christopherson wrote: > Don't re-acquire SRCU in complete_emulated_io() now that KVM acquires the > lock in kvm_arch_vcpu_ioctl_run(). More importantly, don't overwrite > vcpu->srcu_idx. If the index acquired by complete_emulated_io() differs > from the one acquired by kvm_arch_vcpu_ioctl_run(), KVM will effectively > leak a lock and hang if/when synchronize_srcu() is invoked for the > relevant grace period. > > Fixes: 8d25b7beca7e ("KVM: x86: pull kvm->srcu read-side to kvm_arch_vcpu_ioctl_run") > Cc: stable@vger.kernel.org > Signed-off-by: Sean Christopherson > --- > arch/x86/kvm/x86.c | 7 +------ > 1 file changed, 1 insertion(+), 6 deletions(-) > > diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c > index ab336f7c82e4..f35fe09de59d 100644 > --- a/arch/x86/kvm/x86.c > +++ b/arch/x86/kvm/x86.c > @@ -10450,12 +10450,7 @@ static int vcpu_run(struct kvm_vcpu *vcpu) > > static inline int complete_emulated_io(struct kvm_vcpu *vcpu) > { > - int r; > - > - vcpu->srcu_idx = srcu_read_lock(&vcpu->kvm->srcu); > - r = kvm_emulate_instruction(vcpu, EMULTYPE_NO_DECODE); > - srcu_read_unlock(&vcpu->kvm->srcu, vcpu->srcu_idx); > - return r; > + return kvm_emulate_instruction(vcpu, EMULTYPE_NO_DECODE); > } > > static int complete_emulated_pio(struct kvm_vcpu *vcpu) I wonder how this did work.... Reviewed-by: Maxim Levitsky Best regards, Maxim Levitsky