mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Paolo Bonzini <pbonzini@redhat.com>
To: Sean Christopherson <seanjc@google.com>
Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org,
	Chao Gao <chao.gao@intel.com>, Kai Huang <kai.huang@intel.com>
Subject: Re: [PATCH v3 4/8] KVM: Add a module param to allow enabling virtualization when KVM is loaded
Date: Wed, 14 Aug 2024 20:14:46 +0200	[thread overview]
Message-ID: <c4f7cb72-c0af-433d-ab52-e68728af1446@redhat.com> (raw)
In-Reply-To: <20240608000639.3295768-5-seanjc@google.com>

On 6/8/24 02:06, Sean Christopherson wrote:
> Add an off-by-default module param, enable_virt_at_load, to let userspace
> force virtualization to be enabled in hardware when KVM is initialized,
> i.e. just before /dev/kvm is exposed to userspace.  Enabling virtualization
> during KVM initialization allows userspace to avoid the additional latency
> when creating/destroying the first/last VM.  Now that KVM uses the cpuhp
> framework to do per-CPU enabling, the latency could be non-trivial as the
> cpuhup bringup/teardown is serialized across CPUs, e.g. the latency could
> be problematic for use case that need to spin up VMs quickly.
> 
> Enabling virtualizaton during initialization will also allow KVM to setup
> the Intel TDX Module, which requires VMX to be fully enabled, without
> needing additional APIs to temporarily enable virtualization.
> 
> Signed-off-by: Sean Christopherson <seanjc@google.com>

I think we should enable it by default and wait for someone to complain. 
  Or notice, even.

Paolo

> ---
>   virt/kvm/kvm_main.c | 37 +++++++++++++++++++++++++++++++++++++
>   1 file changed, 37 insertions(+)
> 
> diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
> index 98e52d12f137..7bdd744e4821 100644
> --- a/virt/kvm/kvm_main.c
> +++ b/virt/kvm/kvm_main.c
> @@ -5495,6 +5495,9 @@ static struct miscdevice kvm_dev = {
>   };
>   
>   #ifdef CONFIG_KVM_GENERIC_HARDWARE_ENABLING
> +static bool enable_virt_at_load;
> +module_param(enable_virt_at_load, bool, 0444);
> +
>   __visible bool kvm_rebooting;
>   EXPORT_SYMBOL_GPL(kvm_rebooting);
>   
> @@ -5645,15 +5648,41 @@ static void kvm_disable_virtualization(void)
>   	unregister_syscore_ops(&kvm_syscore_ops);
>   	cpuhp_remove_state(CPUHP_AP_KVM_ONLINE);
>   }
> +
> +static int kvm_init_virtualization(void)
> +{
> +	if (enable_virt_at_load)
> +		return kvm_enable_virtualization();
> +
> +	return 0;
> +}
> +
> +static void kvm_uninit_virtualization(void)
> +{
> +	if (enable_virt_at_load)
> +		kvm_disable_virtualization();
> +
> +	WARN_ON(kvm_usage_count);
> +}
>   #else /* CONFIG_KVM_GENERIC_HARDWARE_ENABLING */
>   static int kvm_enable_virtualization(void)
>   {
>   	return 0;
>   }
>   
> +static int kvm_init_virtualization(void)
> +{
> +	return 0;
> +}
> +
>   static void kvm_disable_virtualization(void)
>   {
>   
> +}
> +
> +static void kvm_uninit_virtualization(void)
> +{
> +
>   }
>   #endif /* CONFIG_KVM_GENERIC_HARDWARE_ENABLING */
>   
> @@ -6395,6 +6424,10 @@ int kvm_init(unsigned vcpu_size, unsigned vcpu_align, struct module *module)
>   
>   	kvm_gmem_init(module);
>   
> +	r = kvm_init_virtualization();
> +	if (r)
> +		goto err_virt;
> +
>   	/*
>   	 * Registration _must_ be the very last thing done, as this exposes
>   	 * /dev/kvm to userspace, i.e. all infrastructure must be setup!
> @@ -6408,6 +6441,8 @@ int kvm_init(unsigned vcpu_size, unsigned vcpu_align, struct module *module)
>   	return 0;
>   
>   err_register:
> +	kvm_uninit_virtualization();
> +err_virt:
>   	kvm_vfio_ops_exit();
>   err_vfio:
>   	kvm_async_pf_deinit();
> @@ -6433,6 +6468,8 @@ void kvm_exit(void)
>   	 */
>   	misc_deregister(&kvm_dev);
>   
> +	kvm_uninit_virtualization();
> +
>   	debugfs_remove_recursive(kvm_debugfs_dir);
>   	for_each_possible_cpu(cpu)
>   		free_cpumask_var(per_cpu(cpu_kick_mask, cpu));


  parent reply	other threads:[~2024-08-14 18:14 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-06-08  0:06 [PATCH v3 0/8] KVM: Register cpuhp/syscore callbacks when enabling virt Sean Christopherson
2024-06-08  0:06 ` [PATCH v3 1/8] KVM: Use dedicated mutex to protect kvm_usage_count to avoid deadlock Sean Christopherson
2024-06-10  0:26   ` Huang, Kai
2024-08-14 18:06   ` Paolo Bonzini
2024-08-15 14:39     ` Sean Christopherson
2024-08-15 16:10       ` Paolo Bonzini
2024-08-30 23:45         ` Sean Christopherson
2024-09-02 13:03           ` Paolo Bonzini
2024-06-08  0:06 ` [PATCH v3 2/8] KVM: Register cpuhp and syscore callbacks when enabling hardware Sean Christopherson
2024-06-10  0:55   ` Huang, Kai
2024-08-14 18:12   ` Paolo Bonzini
2024-08-14 20:55     ` Sean Christopherson
2024-06-08  0:06 ` [PATCH v3 3/8] KVM: Rename functions related to enabling virtualization hardware Sean Christopherson
2024-06-08  0:06 ` [PATCH v3 4/8] KVM: Add a module param to allow enabling virtualization when KVM is loaded Sean Christopherson
2024-08-02 12:02   ` Huang, Kai
2024-08-02 12:06     ` Huang, Kai
2024-08-13  2:31     ` Sean Christopherson
2024-08-13  5:22       ` Huang, Kai
2024-08-13 23:47         ` Huang, Kai
2024-08-14 18:14   ` Paolo Bonzini [this message]
2024-06-08  0:06 ` [PATCH v3 5/8] KVM: Add arch hooks for enabling/disabling virtualization Sean Christopherson
2024-08-14 18:15   ` Paolo Bonzini
2024-06-08  0:06 ` [PATCH v3 6/8] x86/reboot: Unconditionally define cpu_emergency_virt_cb typedef Sean Christopherson
2024-06-08  0:06 ` [PATCH v3 7/8] KVM: x86: Register "emergency disable" callbacks when virt is enabled Sean Christopherson
2024-06-08  0:06 ` [PATCH v3 8/8] KVM: Enable virtualization at load/initialization by default Sean Christopherson
2024-08-14 18:20   ` Paolo Bonzini
2024-06-10  0:59 ` [PATCH v3 0/8] KVM: Register cpuhp/syscore callbacks when enabling virt Huang, Kai
2024-08-14 18:23 ` Paolo Bonzini
2024-08-14 22:17   ` Huang, Kai
2024-08-15 14:41     ` Sean Christopherson
2024-08-20  8:57 ` Paolo Bonzini

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=c4f7cb72-c0af-433d-ab52-e68728af1446@redhat.com \
    --to=pbonzini@redhat.com \
    --cc=chao.gao@intel.com \
    --cc=kai.huang@intel.com \
    --cc=kvm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=seanjc@google.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®