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 C09BAC4332F for ; Tue, 11 Jan 2022 18:54:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1350242AbiAKSyS (ORCPT ); Tue, 11 Jan 2022 13:54:18 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34918 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1350127AbiAKSyR (ORCPT ); Tue, 11 Jan 2022 13:54:17 -0500 Received: from mail-yb1-xb31.google.com (mail-yb1-xb31.google.com [IPv6:2607:f8b0:4864:20::b31]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8E676C061748 for ; Tue, 11 Jan 2022 10:54:16 -0800 (PST) Received: by mail-yb1-xb31.google.com with SMTP id g81so22816252ybg.10 for ; Tue, 11 Jan 2022 10:54:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=dL+btzQ+xCxXspDJaZJGykFcK855V7Nc4qMk1w8Krog=; b=do5RkxEiTvBJKwP8Dwceb93LhoaiHtrVK3rpQLZL6591RN7aCxg+6wrPkIfrG+3vx2 HZkeIHoe4AJ6wOHohpMrkiWbIOacLU6s2IyUsIXNJNiIK0g0t+oib5q4qKKfEC3MhWj2 GQZUli8+aMDP731VX5OnkTNhIACQdB3JbOekC2lsqiITasdmocNW3gVj5WGQSo03IVpZ KGevY2wEgZdHPI7Dut+Y6Br/2su6UD48i9VKEk0Nfz81VvW8+YOPRnlaz8bGElKfazWR zD7scaBip1NPm0RwZdW9zkGduOghl2GO3aPzMVIKp12HHtga1ELUBnND7Rus/2DHk/Rp YTOA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=dL+btzQ+xCxXspDJaZJGykFcK855V7Nc4qMk1w8Krog=; b=I5TOKcgUG1jwsjynW3QiDAxJ9uqsQvQuLYocc9ILyVteSWObnx9jLJBkkiAxQ1FZSF b2W8DFbLGwgHAehVmybBYGPXvpz1kP3s0UuuMUXTOBy83CmpZ18wRMmf/YzJR5omE0OL K0GbPjaBeLPyyM9adczfxnwKFTYg1P8yDXdAAx/zew+/5kQSvOsgTBjzbukLlvokkFpW 4uX3B4lwD0vPxGRKEDT4CggyIzkKy7zBgrgxZcHqVqTc7eTRSoZ0y7E9xjl7OW+vwSlw g0S9D8FjEIP9Bpv+nFwRBuiHMl72YcFKXk9wf0FH53C8ddpuD50cjbQF/jG3SVLApDMF 3QkA== X-Gm-Message-State: AOAM5301Rds3Vb9K5BVSEYzLxja7OUvmsZBjpEpTQsFlIr6I/1+mcy/I fWdY2Rsk2y36hsE9WCIg7p+RcZ1lrhpxaT6xlvCBjw== X-Google-Smtp-Source: ABdhPJzdKh4TYtVP9wJaIC9WtAXx8WjDTCq5KBT609w0WccuH6YBlrmVHkTjxZ89JzWrJ3ZhBf1h0/HOXcQQkM4gZ+8= X-Received: by 2002:a25:c841:: with SMTP id y62mr8493349ybf.196.1641927255567; Tue, 11 Jan 2022 10:54:15 -0800 (PST) MIME-Version: 1.0 References: <20220104194918.373612-1-rananta@google.com> <20220104194918.373612-2-rananta@google.com> In-Reply-To: From: Raghavendra Rao Ananta Date: Tue, 11 Jan 2022 10:54:05 -0800 Message-ID: Subject: Re: [RFC PATCH v3 01/11] KVM: Capture VM start To: Reiji Watanabe Cc: Marc Zyngier , Andrew Jones , James Morse , Alexandru Elisei , Suzuki K Poulose , Paolo Bonzini , Catalin Marinas , Will Deacon , Peter Shier , Ricardo Koller , Oliver Upton , Jing Zhang , Linux ARM , kvmarm@lists.cs.columbia.edu, linux-kernel@vger.kernel.org, kvm@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Jan 10, 2022 at 4:04 PM Reiji Watanabe wrote: > > On Fri, Jan 7, 2022 at 3:43 PM Raghavendra Rao Ananta > wrote: > > > > Hi Reiji, > > > > On Thu, Jan 6, 2022 at 10:07 PM Reiji Watanabe wrote: > > > > > > Hi Raghu, > > > > > > On Tue, Jan 4, 2022 at 11:49 AM Raghavendra Rao Ananta > > > wrote: > > > > > > > > Capture the start of the KVM VM, which is basically the > > > > 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. > > > > > > > > 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; > > > > > > Since KVM_RUN on any vCPUs doesn't necessarily mean that the VM > > > started yet, the name might be a bit misleading IMHO. I would > > > think 'has_run_once' or 'ran_once' might be more clear (?). > > > > > I always struggle with the names; but if you feel that 'ran_once' > > makes more sense for a reader, I can change it. > > I would prefer 'ran_once'. > Yes, that makes sense. I think the name created a lot of confusion for the patch. Thanks, Raghavendra > > > > > }; > > > > > > > > #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) > > > > + > > > > 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 (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. > > > > + */ > > > > > > It might be nicer to add a comment why the code below gets kvm->lock. > > > > > I've been going back and forth on this one. Initially I considered > > simply going with atomic_t, but the patch 4/11 (KVM: arm64: Setup a > > framework for hypercall bitmap firmware registers) > > kvm_arm_set_fw_reg_bmap()'s implementation felt like we need a lock to > > have the whole 'is the register busy?' operation atomic. But, that's > > just one of the applications. > > I understand why you need the code to get the lock here with the > current implementation. > But, since the code just set the one field (vm_started) with the lock, > I thought the intention of getting the lock might not be so obvious. > (But, maybe clear enough looking at the code in the patch-4) > > Thanks, > Reiji > > > > > Anyway, the patch generally looks good to me, and thank you > > > for making this change (it works for my purpose as well). > > > > > > Reviewed-by: Reiji Watanabe > > > > > Glad that it's helping you as well and thanks for the review. > > > > Regards, > > Raghavendra > > > > > Thanks, > > > Reiji > > > > > > > > > > + mutex_lock(&kvm->lock); > > > > + kvm->vm_started = true; > > > > + mutex_unlock(&kvm->lock); > > > > } > > > > r = kvm_arch_vcpu_ioctl_run(vcpu); > > > > trace_kvm_userspace_exit(vcpu->run->exit_reason, r); > > > > -- > > > > 2.34.1.448.ga2b2bfdf31-goog > > > >