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 6A685C433EF for ; Mon, 22 Nov 2021 16:31:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240294AbhKVQe4 (ORCPT ); Mon, 22 Nov 2021 11:34:56 -0500 Received: from mail.kernel.org ([198.145.29.99]:43820 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232912AbhKVQeu (ORCPT ); Mon, 22 Nov 2021 11:34:50 -0500 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") Content-Type: text/plain; charset=US-ASCII 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 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.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.