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 85B25C433FE for ; Tue, 4 Jan 2022 19:49:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231450AbiADTta (ORCPT ); Tue, 4 Jan 2022 14:49:30 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44090 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231409AbiADTt3 (ORCPT ); Tue, 4 Jan 2022 14:49:29 -0500 Received: from mail-pj1-x104a.google.com (mail-pj1-x104a.google.com [IPv6:2607:f8b0:4864:20::104a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6E5DEC061785 for ; Tue, 4 Jan 2022 11:49:29 -0800 (PST) Received: by mail-pj1-x104a.google.com with SMTP id d3-20020a17090a2a4300b001b22191073dso368114pjg.4 for ; Tue, 04 Jan 2022 11:49:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=A6x6Pw7kLwqSVAYV5QWuRkaeBaCvukF54j0t8jOjIWo=; b=ptX0vg9YdIJXEIv+bPi9miN6Phs8Gqz7sBU2QWQsUtqw2kQGQwiABtW992ywk4hZ+W 0Yjxd+YrHiAZDx5j9yYFCFkPbsVaZ0Me2jeZ8/Yp1nLtpTRU3glZ/AFWrivJ3Ne9PxOZ wEEkRcAX+0GHmJL3/IL+wNt/VFmeQ8X8mW6bJyPiNxpnLVbR0aLEbdEA2Ze9gi6qqQ3C poU1KuO3mU1pkPlTHi2tto1rMBI3uHO8ySMfK3Luj4uIlnnCmLez6qNGPpgKaKGbE9tx WkPLsVqsmNEpEEThs9CKJ8Tw+DYsrLXtA1p0adzY5K5eZnk7V3wXfESrD7ST2e9CTHW1 RFAA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=A6x6Pw7kLwqSVAYV5QWuRkaeBaCvukF54j0t8jOjIWo=; b=l2/SEkQStjmEcZoRmbkqDxRPOpeCvU7eUDM3uPualfu56nV1/wSdjebKj1ahMZ90Es XFFP3qkJs7IFqBFkLNHwV0DcLMAN+rnjXCqxUC47ddlYMctO9g/SEUGQhrEbhrJSY9Jg eMO41XGqVNxKzcLDl3qSk/uoH43P+UgQR/BVs9zlNGgu8UH5idrg4YgunnpIKWMICa9p a/ycsumJ7mJm6oQ2OA3m8mNHMCFxskFJoooUqRz0vnAXdsTqd7aOMCQkdEnBjeNDpW8f KCj1/5NKiW0z2Z2sLrluPONclBoLpu+0ftUOLcqitcMY++7eJHNM2f0PpPev9HfqfNQe u0MA== X-Gm-Message-State: AOAM531AtndSlPURb6JtTaA9tp+akP457bmL+xUrdqx+lP0r8Y+AWQp3 LCCvGFOT4cvu3dyAVIfuuq87jq8Hsu71 X-Google-Smtp-Source: ABdhPJwl3NnGF1TfkZRlci6WjMWULIHIZ/BPa4U45UMKx/oZHTzTtRdYJEOxN/Xl1feLxe+jPtf4xNYvI4PH X-Received: from rananta-virt.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:1bcc]) (user=rananta job=sendgmr) by 2002:a17:90b:3809:: with SMTP id mq9mr62274740pjb.245.1641325768929; Tue, 04 Jan 2022 11:49:28 -0800 (PST) Date: Tue, 4 Jan 2022 19:49:08 +0000 In-Reply-To: <20220104194918.373612-1-rananta@google.com> Message-Id: <20220104194918.373612-2-rananta@google.com> Mime-Version: 1.0 References: <20220104194918.373612-1-rananta@google.com> X-Mailer: git-send-email 2.34.1.448.ga2b2bfdf31-goog Subject: [RFC PATCH v3 01/11] KVM: Capture VM start From: Raghavendra Rao Ananta To: Marc Zyngier , Andrew Jones , James Morse , Alexandru Elisei , Suzuki K Poulose Cc: Paolo Bonzini , Catalin Marinas , Will Deacon , Peter Shier , Ricardo Koller , Oliver Upton , Reiji Watanabe , Jing Zhang , Raghavendra Rao Anata , linux-arm-kernel@lists.infradead.org, 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 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; }; #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. + */ + 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