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 7C89DC77B73 for ; Wed, 19 Apr 2023 07:14:07 +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: Subject:Cc:To:From:Message-ID:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=UdYH5rQarraX36mbKMEp9QUcm9VO8u02xHsrIVHgcyo=; b=R8sqThTvRXn0Wb ETHPW884x5xDPmGuTO+eri14OYJh4AShuOIpG7OgzHqFnnP4v/GG/HsGD6YOciShVCpSv3MQ595m2 FKLt2/x6c4Ej2R17ae9lMvf9zvT5tnKuhIjZTHk23ho02cuhjb80x0usheY6IdMrLNgBHE5MXxuaa OhWO7lwE2VNjR5rZH2TM32YyguQaegMkFHH1ReZQBAhVlhAuUc2lenZ/sZUKiSBZ2qryCtZkH91+z l043nlYVTdC/KKki5NVhWODxWtdm8elcTE33p5I09XhuAjRNKwtzj2hIICGkK5qZtNMCeLuiBCQQW hZ9DsCidy2WAKDMFS+6Q==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1pp206-004NYI-0k; Wed, 19 Apr 2023 07:13:10 +0000 Received: from dfw.source.kernel.org ([2604:1380:4641:c500::1]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1pp202-004NXb-2z for linux-arm-kernel@lists.infradead.org; Wed, 19 Apr 2023 07:13:08 +0000 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 dfw.source.kernel.org (Postfix) with ESMTPS id 4F63761A70; Wed, 19 Apr 2023 07:13:06 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id B15BFC433EF; Wed, 19 Apr 2023 07:13:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1681888385; bh=ZQy39AmqI0x9pdiAQspN9X2fTv8rwKNXrdtD3hdr/FE=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=LIdGeSWngaUyLhCTkPMTslYt5SXo0N42Upa32CilNMbrtmf57rnsDumwTQHKtM1u8 xDeI7VHEiFPuJUx3SyffdWY/9JioRGROaiSajUwyEO80uTIvW6g8oIZGLTs+7/gkm2 QYaJhDPq5y6ql2blk1QyiXPkhBdGCDsySBrH9LMJNf5p1jBFDx6Bxk9MUIJHtZORrd w0YtrJoaJ5UYBhSp3xduZg55tVWKfu4108z7xdvjwfAHZjIATNcOAAHR8bma5ZRFuK vCCF4YfI5o93ZGFKXWQSqoFyueVmaQFNnANCqE0Lr9OYcGLWO491cJBgEQGUnkfSUo KjZCmOtFebcAA== Received: from 82-132-232-246.dab.02.net ([82.132.232.246] helo=wait-a-minute.misterjones.org) by disco-boy.misterjones.org with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.95) (envelope-from ) id 1pp1zz-009UzW-0O; Wed, 19 Apr 2023 08:13:03 +0100 Date: Wed, 19 Apr 2023 08:12:45 +0100 Message-ID: <87cz405or6.wl-maz@kernel.org> From: Marc Zyngier To: Reiji Watanabe Cc: Oliver Upton , kvmarm@lists.linux.dev, kvm@vger.kernel.org, linux-arm-kernel@lists.infradead.org, James Morse , Alexandru Elisei , Zenghui Yu , Suzuki K Poulose , Paolo Bonzini , Ricardo Koller , Jing Zhang , Raghavendra Rao Anata , Will Deacon Subject: Re: [PATCH v1 1/2] KVM: arm64: Acquire mp_state_lock in kvm_arch_vcpu_ioctl_vcpu_init() In-Reply-To: <20230419021852.2981107-2-reijiw@google.com> References: <20230419021852.2981107-1-reijiw@google.com> <20230419021852.2981107-2-reijiw@google.com> User-Agent: Wanderlust/2.15.9 (Almost Unreal) SEMI-EPG/1.14.7 (Harue) FLIM-LB/1.14.9 (=?UTF-8?B?R29qxY0=?=) APEL-LB/10.8 EasyPG/1.0.0 Emacs/27.1 (x86_64-pc-linux-gnu) MULE/6.0 (HANACHIRUSATO) MIME-Version: 1.0 (generated by SEMI-EPG 1.14.7 - "Harue") X-SA-Exim-Connect-IP: 82.132.232.246 X-SA-Exim-Rcpt-To: reijiw@google.com, oliver.upton@linux.dev, kvmarm@lists.linux.dev, kvm@vger.kernel.org, linux-arm-kernel@lists.infradead.org, james.morse@arm.com, alexandru.elisei@arm.com, yuzenghui@huawei.com, suzuki.poulose@arm.com, pbonzini@redhat.com, ricarkol@google.com, jingzhangos@google.com, rananta@google.com, will@kernel.org X-SA-Exim-Mail-From: maz@kernel.org X-SA-Exim-Scanned: No (on disco-boy.misterjones.org); SAEximRunCond expanded to false X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230419_001307_065585_22156BB9 X-CRM114-Status: GOOD ( 26.04 ) X-BeenThere: linux-arm-kernel@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-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On Wed, 19 Apr 2023 03:18:51 +0100, Reiji Watanabe wrote: > > kvm_arch_vcpu_ioctl_vcpu_init() doesn't acquire mp_state_lock > when setting the mp_state to KVM_MP_STATE_RUNNABLE. Fix the > code to acquire the lock. > > Signed-off-by: Reiji Watanabe > --- > arch/arm64/kvm/arm.c | 5 ++++- > 1 file changed, 4 insertions(+), 1 deletion(-) > > diff --git a/arch/arm64/kvm/arm.c b/arch/arm64/kvm/arm.c > index fbafcbbcc463..388aa4f18f21 100644 > --- a/arch/arm64/kvm/arm.c > +++ b/arch/arm64/kvm/arm.c > @@ -1244,8 +1244,11 @@ static int kvm_arch_vcpu_ioctl_vcpu_init(struct kvm_vcpu *vcpu, > */ > if (test_bit(KVM_ARM_VCPU_POWER_OFF, vcpu->arch.features)) > kvm_arm_vcpu_power_off(vcpu); > - else > + else { > + spin_lock(&vcpu->arch.mp_state_lock); > WRITE_ONCE(vcpu->arch.mp_state.mp_state, KVM_MP_STATE_RUNNABLE); > + spin_unlock(&vcpu->arch.mp_state_lock); > + } > > return 0; > } I'm not entirely convinced that this fixes anything. What does the lock hazard against given that the write is atomic? But maybe a slightly more readable of this would be to expand the critical section this way: diff --git a/arch/arm64/kvm/arm.c b/arch/arm64/kvm/arm.c index 4ec888fdd4f7..bb21d0c25de7 100644 --- a/arch/arm64/kvm/arm.c +++ b/arch/arm64/kvm/arm.c @@ -1246,11 +1246,15 @@ static int kvm_arch_vcpu_ioctl_vcpu_init(struct kvm_vcpu *vcpu, /* * Handle the "start in power-off" case. */ + spin_lock(&vcpu->arch.mp_state_lock); + if (test_bit(KVM_ARM_VCPU_POWER_OFF, vcpu->arch.features)) - kvm_arm_vcpu_power_off(vcpu); + __kvm_arm_vcpu_power_off(vcpu); else WRITE_ONCE(vcpu->arch.mp_state.mp_state, KVM_MP_STATE_RUNNABLE); + spin_unlock(&vcpu->arch.mp_state_lock); + return 0; } Thoughts? M. -- Without deviation from the norm, progress is not possible. _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel