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 5698FC433EF for ; Mon, 22 Nov 2021 16:33:02 +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=L2ZGGOzOAiwSWB+teSdNPGHlVpE59N4Fomqqtrw+4iU=; b=abAbX8tjmPIzen NDH4LDBNugN6ND/0BTXPUc91yOHwLk9fB4HU3ar03NE4pdgxw2JrJevRGAZaGT57TM81zsVSGcbgV qfZcHZPSUC3Am51osj6+Y+QtBgI/IpLZJJw829HRwvfrl1o5WFLu2/xaFc702rrBFoXgTAxG5OXni o5yobrbhAgJA4xCI+d4gJ/pcVshHadNMqiZggNZ//qJMIxd2Kdu7HIy2yU5p9qaA2Gw4gAvSlZAmy qRqZyVhZFsLf7oPJUK+/7jT0LtfOPbtO3BZDg6wUAposMNouQDmvp+SsimBsMJl0SMJKzapJVZBJ3 m6IiL4A+OBdHNNTVTJ4A==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mpCEL-00H9en-Io; Mon, 22 Nov 2021 16:31:45 +0000 Received: from mail.kernel.org ([198.145.29.99]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1mpCEH-00H9dF-2a for linux-arm-kernel@lists.infradead.org; Mon, 22 Nov 2021 16:31:42 +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 8EFB460F90; Mon, 22 Nov 2021 16:31:40 +0000 (UTC) Received: from sofa.misterjones.org ([185.219.108.64] helo=why.misterjones.org) by disco-boy.misterjones.org with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1mpCEE-0075vS-8n; Mon, 22 Nov 2021 16:31:38 +0000 Date: Mon, 22 Nov 2021 16:31:37 +0000 Message-ID: <87y25gcfti.wl-maz@kernel.org> From: Marc Zyngier To: Raghavendra Rao Ananta Cc: Andrew Jones , James Morse , Alexandru Elisei , Suzuki K Poulose , Paolo Bonzini , Catalin Marinas , Will Deacon , Peter Shier , Ricardo Koller , Oliver Upton , Reiji Watanabe , Jing Zhang , linux-arm-kernel@lists.infradead.org, kvmarm@lists.cs.columbia.edu, linux-kernel@vger.kernel.org, kvm@vger.kernel.org Subject: Re: [RFC PATCH v2 03/11] KVM: Introduce kvm_vm_has_run_once In-Reply-To: <20211113012234.1443009-4-rananta@google.com> References: <20211113012234.1443009-1-rananta@google.com> <20211113012234.1443009-4-rananta@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: 185.219.108.64 X-SA-Exim-Rcpt-To: rananta@google.com, drjones@redhat.com, james.morse@arm.com, alexandru.elisei@arm.com, suzuki.poulose@arm.com, pbonzini@redhat.com, catalin.marinas@arm.com, will@kernel.org, pshier@google.com, ricarkol@google.com, oupton@google.com, reijiw@google.com, jingzhangos@google.com, linux-arm-kernel@lists.infradead.org, kvmarm@lists.cs.columbia.edu, linux-kernel@vger.kernel.org, kvm@vger.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-20211122_083141_184274_90979E15 X-CRM114-Status: GOOD ( 22.72 ) 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 Sat, 13 Nov 2021 01:22:26 +0000, Raghavendra Rao Ananta wrote: > > The upcoming patches need a way to detect if the VM, as > a whole, has started. Hence, unionize kvm_vcpu_has_run_once() > of all the vcpus of the VM and build kvm_vm_has_run_once() > to achieve the functionality. > > No functional change intended. > > Signed-off-by: Raghavendra Rao Ananta > --- > include/linux/kvm_host.h | 2 ++ > virt/kvm/kvm_main.c | 17 +++++++++++++++++ > 2 files changed, 19 insertions(+) > > diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h > index b373929c71eb..102e00c0e21c 100644 > --- a/include/linux/kvm_host.h > +++ b/include/linux/kvm_host.h > @@ -1854,4 +1854,6 @@ static inline bool kvm_vcpu_has_run_once(struct kvm_vcpu *vcpu) > return vcpu->has_run_once; > } > > +bool kvm_vm_has_run_once(struct kvm *kvm); > + > #endif > diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c > index 1ec8a8e959b2..3d8d96e8f61d 100644 > --- a/virt/kvm/kvm_main.c > +++ b/virt/kvm/kvm_main.c > @@ -4339,6 +4339,23 @@ static int kvm_vm_ioctl_get_stats_fd(struct kvm *kvm) > return fd; > } > > +bool kvm_vm_has_run_once(struct kvm *kvm) > +{ > + int i, ret = false; > + struct kvm_vcpu *vcpu; > + > + mutex_lock(&kvm->lock); > + > + kvm_for_each_vcpu(i, vcpu, kvm) { > + ret = kvm_vcpu_has_run_once(vcpu); > + if (ret) > + break; > + } > + > + mutex_unlock(&kvm->lock); > + return ret; > +} This is horribly racy. Nothing prevents a vcpu from running behind your back. If you want any sort of guarantee, look at what we do in kvm_vgic_create(). Alexandru has patches that extract it to make it generally available (at least for arm64). 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