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 0A318C433EF for ; Sat, 8 Jan 2022 01:07:43 +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:In-Reply-To:MIME-Version:References: Message-ID:Subject:Cc:To:From:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=vDWmsJwWGPLXd/yHoCndlHRxIzXa79vLlO9CAlyix14=; b=lnNHTXOrSi741J argIHKWvoD1dSbOtCcbu6luYDTls0HpyonRQ5lhmxRDXr1x0V/5wuTEwW5e5UshsxzEswUR/rB/is ehACqU8v4jyX/E0U3Sf+cSNXQo5EchWyFVMJWGMkEY0ey/PvpM4tr/QkpreiaCNgOMjXpZ+4IUtK3 J2xykRSMahoXAiMjddIJbLvCVmGJ+aTiraD/YBB9+rIrb9KGv6+bDxarKSDLV2kI2W2ZQ7reeDRP+ lktx8e9TdxdCOu3GflPRDcTVd/g9aQHfRZz3CriOLArsGzsj+6EnKemrK30sLPijTwWQCxyCoH1CY PKO6lDRJph1mnZTS9csw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1n60BR-005iqV-AX; Sat, 08 Jan 2022 01:06:13 +0000 Received: from mail-pg1-x532.google.com ([2607:f8b0:4864:20::532]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1n60BM-005ips-Ap for linux-arm-kernel@lists.infradead.org; Sat, 08 Jan 2022 01:06:11 +0000 Received: by mail-pg1-x532.google.com with SMTP id i8so7117861pgt.13 for ; Fri, 07 Jan 2022 17:06:07 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=P/JdDvFQ/rU7zLe6irNqXlDeNuS6rYc6yuVZLjuKGyc=; b=Gg5eWfiQzwLIDi3YoPnouPv9dHbr42UFFA0692cmMc7iSKB3cfJ5APAG23uGy/zbsp oya7+4PV908NfHJWxCkXmdBerdH+HzKm70zC7wBiD7lEiagilEozr/p5HxVIv0JMB9vt xfp8BL/sZlkI5ZvY1XM8Jj4+ooVgNxixfzOcEOuiWvDD1VZTA79hUIEOzDnjgqtGr6hZ hFxCBC2uNj4kC8Q3E5BaaaOPYm0J39TVtvw/a4HH6csoTDS1yZK43b7wD9i7v81Y1H47 sYePq+D7zHxdjOge2j+M+0YN2yDtjEwxUZGKuxBuCJB1Gir0mUYamaCWzpw3NzO3l2yx d6aw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=P/JdDvFQ/rU7zLe6irNqXlDeNuS6rYc6yuVZLjuKGyc=; b=fFuWK80PAg7KaDduKtX8A+aCM3rCuTc9tSWRKtpz/XVNI0Noym8OfjAmGcPEBPTpbC 3Yu4tKFRcjFDBvyFvFJTo3Sx/cqexvVkAGvRgVvHeO6VPzQ2JkrFQIkFueUiNo3R65WY DG3+38rO4CTyPYLiWQSTSRASF/0Ms0eer+2rA1Fz3gUfZl7bnUaTLkH1S/dYwF56t2Ce VXXXuBc7uBCkhND5Fe7NIauKqHvB7Yb7vzRA9Y0q5GIBt5nnzaTRqRGAFkEuz/Y+8xz3 JUcQAXdg2FslQNYp0bHJf2vQCEwXdyExdr+krAEvhxYaBhy4pdz4Fl8bwILwaAA2FgPU 2ycA== X-Gm-Message-State: AOAM530rqOzV2bs0xDnfauWFRb9WmJBe89OBTy2F6QCrmGdMCyT9IOSE pkcJJKyd93EdTuig1uaD4Lw7dw== X-Google-Smtp-Source: ABdhPJxZQQtD46lRS+IB/vTcxBt5snfvk4QQYFbDeXg0NYPG6jAhHnl2lRG1C3Wa5MqAPv4pOwoSvQ== X-Received: by 2002:a63:44a:: with SMTP id 71mr57292354pge.453.1641603967292; Fri, 07 Jan 2022 17:06:07 -0800 (PST) Received: from google.com (157.214.185.35.bc.googleusercontent.com. [35.185.214.157]) by smtp.gmail.com with ESMTPSA id c124sm121598pfb.139.2022.01.07.17.06.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 07 Jan 2022 17:06:06 -0800 (PST) Date: Sat, 8 Jan 2022 01:06:03 +0000 From: Sean Christopherson To: Raghavendra Rao Ananta Cc: Marc Zyngier , Andrew Jones , James Morse , Alexandru Elisei , Suzuki K Poulose , kvm@vger.kernel.org, Catalin Marinas , Peter Shier , linux-kernel@vger.kernel.org, Paolo Bonzini , Will Deacon , kvmarm@lists.cs.columbia.edu, linux-arm-kernel@lists.infradead.org Subject: Re: [RFC PATCH v3 01/11] KVM: Capture VM start Message-ID: References: <20220104194918.373612-1-rananta@google.com> <20220104194918.373612-2-rananta@google.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20220104194918.373612-2-rananta@google.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220107_170608_428954_69BEBD9B X-CRM114-Status: GOOD ( 25.19 ) 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 Tue, Jan 04, 2022, Raghavendra Rao Ananta wrote: > Capture the start of the KVM VM, which is basically the Please wrap at ~75 chars. > start of any vCPU run. This state of the VM is helpful > in the upcoming patches to prevent user-space from > configuring certain VM features after the VM has started > running. Please provide context of how the flag will be used. I glanced at the future patches, and knowing very little about arm, I was unable to glean useful info about exactly who is being prevented from doing what. > > Signed-off-by: Raghavendra Rao Ananta > --- > include/linux/kvm_host.h | 3 +++ > virt/kvm/kvm_main.c | 9 +++++++++ > 2 files changed, 12 insertions(+) > > diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h > index c310648cc8f1..d0bd8f7a026c 100644 > --- a/include/linux/kvm_host.h > +++ b/include/linux/kvm_host.h > @@ -623,6 +623,7 @@ struct kvm { > struct notifier_block pm_notifier; > #endif > char stats_id[KVM_STATS_NAME_SIZE]; > + bool vm_started; > }; > > #define kvm_err(fmt, ...) \ > @@ -1666,6 +1667,8 @@ static inline bool kvm_check_request(int req, struct kvm_vcpu *vcpu) > } > } > > +#define kvm_vm_has_started(kvm) (kvm->vm_started) Needs parantheses around (kvm), but why bother with a macro? This is the same header that defines struct kvm. > + > extern bool kvm_rebooting; > > extern unsigned int halt_poll_ns; > diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c > index 72c4e6b39389..962b91ac2064 100644 > --- a/virt/kvm/kvm_main.c > +++ b/virt/kvm/kvm_main.c > @@ -3686,6 +3686,7 @@ static long kvm_vcpu_ioctl(struct file *filp, > int r; > struct kvm_fpu *fpu = NULL; > struct kvm_sregs *kvm_sregs = NULL; > + struct kvm *kvm = vcpu->kvm; If you're going to bother grabbing kvm, replace the instances below that also do vcpu->kvm. > > if (vcpu->kvm->mm != current->mm || vcpu->kvm->vm_dead) > return -EIO; > @@ -3723,6 +3724,14 @@ static long kvm_vcpu_ioctl(struct file *filp, > if (oldpid) > synchronize_rcu(); > put_pid(oldpid); > + > + /* > + * Since we land here even on the first vCPU run, > + * we can mark that the VM has started running. Please avoid "we", "us", etc.. "vm_started" is also ambiguous. If we end up with a flag, then I would prefer a much more literal name, a la created_vcpus, e.g. ran_vcpus or something. > + */ > + mutex_lock(&kvm->lock); This adds unnecessary lock contention when running vCPUs. The naive solution would be: if (!kvm->vm_started) { ... } > + kvm->vm_started = true; > + mutex_unlock(&kvm->lock); Lastly, why is this in generic KVM? > } > r = kvm_arch_vcpu_ioctl_run(vcpu); > trace_kvm_userspace_exit(vcpu->run->exit_reason, r); > -- > 2.34.1.448.ga2b2bfdf31-goog > > _______________________________________________ > kvmarm mailing list > kvmarm@lists.cs.columbia.edu > https://lists.cs.columbia.edu/mailman/listinfo/kvmarm _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel