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 X-Spam-Level: X-Spam-Status: No, score=-14.0 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id B6B47C433E0 for ; Sun, 27 Dec 2020 14:38:19 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 7135220867 for ; Sun, 27 Dec 2020 14:38:19 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 7135220867 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To:Subject: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=ElcBIw5seNMgiGFHokg+O/XK0GEoSYEkOYhbz1xoMWs=; b=DX2mRaV64g2SsEUFM2R7q5zhg iLpMe34PnJk/Di+64WjwTh75yXmalph3oKLRXDudu1QDqAXlPxw+MwUYRhefePhDFzZwjDDjt7LqJ mGsiaV1RKUrWuwaNj+tHsEgmBAbYmdwDTekM91KsIo66a0eh2NglpIgq7vb5HLacgSa65n/Rp+6rd gBftKZKtAwsQ2V8BSMshta9las53cK/gRwXpsZMaeQsLWqEBByOC7Fv3kdTgS6fcdtQf9aQpMwr2Y +C4tuKrsnudGFa8JFHPyOwn0KJpebjdJNHT1tcMANs7jn2gLHmfUpcGa+3sY+NL4fHPTkgpWWkUv1 5H1FO80NA==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1ktX9c-00032N-NK; Sun, 27 Dec 2020 14:36:16 +0000 Received: from mail.kernel.org ([198.145.29.99]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1ktX9Z-000323-Be for linux-arm-kernel@lists.infradead.org; Sun, 27 Dec 2020 14:36:14 +0000 Received: from disco-boy.misterjones.org (disco-boy.misterjones.org [51.254.78.96]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 61259217A0; Sun, 27 Dec 2020 14:36:10 +0000 (UTC) Received: from 78.163-31-62.static.virginmediabusiness.co.uk ([62.31.163.78] 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.94) (envelope-from ) id 1ktX9U-0042mB-1g; Sun, 27 Dec 2020 14:36:08 +0000 Date: Sun, 27 Dec 2020 14:36:06 +0000 Message-ID: <87czyvpb8p.wl-maz@kernel.org> From: Marc Zyngier To: Auger Eric Subject: Re: [PATCH 3/5] KVM: arm64: Move double-checked lock to kvm_vgic_map_resources() In-Reply-To: References: <20201201150157.223625-1-alexandru.elisei@arm.com> <20201201150157.223625-4-alexandru.elisei@arm.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 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: 62.31.163.78 X-SA-Exim-Rcpt-To: eric.auger@redhat.com, alexandru.elisei@arm.com, linux-arm-kernel@lists.infradead.org, kvmarm@lists.cs.columbia.edu, james.morse@arm.com, julien.thierry.kdev@gmail.com, suzuki.poulose@arm.com 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-20201227_093613_547626_D1274090 X-CRM114-Status: GOOD ( 32.34 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: suzuki.poulose@arm.com, james.morse@arm.com, linux-arm-kernel@lists.infradead.org, Alexandru Elisei , kvmarm@lists.cs.columbia.edu, julien.thierry.kdev@gmail.com 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 Mon, 14 Dec 2020 12:55:51 +0000, Auger Eric wrote: > > Hi Alexandru, > > On 12/1/20 4:01 PM, Alexandru Elisei wrote: > > kvm_vgic_map_resources() is called when a VCPU if first run and it maps all > > the VGIC MMIO regions. To prevent double-initialization, the VGIC uses the > > ready variable to keep track of the state of resources and the global KVM > > mutex to protect against concurrent accesses. After the lock is taken, the > > variable is checked again in case another VCPU took the lock between the > > current VCPU reading ready equals false and taking the lock. > > > > The double-checked lock pattern is spread across four different functions: > > in kvm_vcpu_first_run_init(), in kvm_vgic_map_resource() and in > > vgic_{v2,v3}_map_resources(), which makes it hard to reason about and > > introduces minor code duplication. Consolidate the checks in > > kvm_vgic_map_resources(), where the lock is taken. > > > > No functional change intended. > > > > Signed-off-by: Alexandru Elisei > > --- > > arch/arm64/kvm/arm.c | 8 +++----- > > arch/arm64/kvm/vgic/vgic-init.c | 6 ++++++ > > arch/arm64/kvm/vgic/vgic-v2.c | 3 --- > > arch/arm64/kvm/vgic/vgic-v3.c | 3 --- > > 4 files changed, 9 insertions(+), 11 deletions(-) > > > > diff --git a/arch/arm64/kvm/arm.c b/arch/arm64/kvm/arm.c > > index 9d69d2bf6943..65a5e89f5133 100644 > > --- a/arch/arm64/kvm/arm.c > > +++ b/arch/arm64/kvm/arm.c > > @@ -530,11 +530,9 @@ static int kvm_vcpu_first_run_init(struct kvm_vcpu *vcpu) > > * Map the VGIC hardware resources before running a vcpu the > > * first time on this VM. > > */ > > - if (unlikely(!vgic_ready(kvm))) { > > - ret = kvm_vgic_map_resources(kvm); > > - if (ret) > > - return ret; > > - } > > + ret = kvm_vgic_map_resources(kvm); > > + if (ret) > > + return ret; > > } else { > > /* > > * Tell the rest of the code that there are userspace irqchip > > diff --git a/arch/arm64/kvm/vgic/vgic-init.c b/arch/arm64/kvm/vgic/vgic-init.c > > index 32e32d67a127..a2f4d1c85f00 100644 > > --- a/arch/arm64/kvm/vgic/vgic-init.c > > +++ b/arch/arm64/kvm/vgic/vgic-init.c > > @@ -428,7 +428,13 @@ int kvm_vgic_map_resources(struct kvm *kvm) > > struct vgic_dist *dist = &kvm->arch.vgic; > > int ret = 0; > > > > + if (likely(vgic_ready(kvm))) > > + return 0; > > + > > mutex_lock(&kvm->lock); > > + if (vgic_ready(kvm)) > > + goto out; > > + > While we are at it, the setting of dist->ready may be moved in > kvm_vgic_map_resources() too. Good point. FWIW, I have added an extra patch on top to that effect. Thanks, 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