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 5/8] KVM: Add arch hooks for enabling/disabling virtualization
Date: Wed, 14 Aug 2024 20:15:33 +0200 [thread overview]
Message-ID: <ef4053c9-6bc8-4b08-af8b-6a4a51100283@redhat.com> (raw)
In-Reply-To: <20240608000639.3295768-6-seanjc@google.com>
On 6/8/24 02:06, Sean Christopherson wrote:
> Add arch hooks that are invoked when KVM enables/disable virtualization.
> x86 will use the hooks to register an "emergency disable" callback, which
> is essentially an x86-specific shutdown notifier that is used when the
> kernel is doing an emergency reboot/shutdown/kexec.
>
> Add comments for the declarations to help arch code understand exactly
> when the callbacks are invoked. Alternatively, the APIs themselves could
> communicate most of the same info, but kvm_arch_pre_enable_virtualization()
> and kvm_arch_post_disable_virtualization() are a bit cumbersome, and make
> it a bit less obvious that they are intended to be implemented as a pair.
>
> Reviewed-by: Chao Gao <chao.gao@intel.com>
> Reviewed-by: Kai Huang <kai.huang@intel.com>
> Signed-off-by: Sean Christopherson <seanjc@google.com>
> ---
> include/linux/kvm_host.h | 14 ++++++++++++++
> virt/kvm/kvm_main.c | 14 ++++++++++++++
> 2 files changed, 28 insertions(+)
>
> diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h
> index 96ad3e8b9ddb..12ef3beb4e47 100644
> --- a/include/linux/kvm_host.h
> +++ b/include/linux/kvm_host.h
> @@ -1514,6 +1514,20 @@ static inline void kvm_create_vcpu_debugfs(struct kvm_vcpu *vcpu) {}
> #endif
>
> #ifdef CONFIG_KVM_GENERIC_HARDWARE_ENABLING
> +/*
> + * kvm_arch_{enable,disable}_virtualization() are called on one CPU, under
> + * kvm_usage_lock, immediately after/before 0=>1 and 1=>0 transitions of
> + * kvm_usage_count, i.e. at the beginning of the generic hardware enabling
> + * sequence, and at the end of the generic hardware disabling sequence.
> + */
> +void kvm_arch_enable_virtualization(void);
> +void kvm_arch_disable_virtualization(void);
> +/*
> + * kvm_arch_hardware_{enable,disable}() are called on "every" CPU to do the
> + * actual twiddling of hardware bits. The hooks are called all online CPUs
> + * when KVM enables/disabled virtualization. Enabling/disabling is also done
> + * when a CPU is onlined/offlined (or Resumed/Suspended).
> + */
> int kvm_arch_hardware_enable(void);
> void kvm_arch_hardware_disable(void);
Since you are at it, rename these to
kvm_arch_{enable,disable}_virtualization_cpu()?
Paolo
> #endif
> diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
> index 7bdd744e4821..e20189a89a64 100644
> --- a/virt/kvm/kvm_main.c
> +++ b/virt/kvm/kvm_main.c
> @@ -5505,6 +5505,16 @@ static DEFINE_PER_CPU(bool, hardware_enabled);
> static DEFINE_MUTEX(kvm_usage_lock);
> static int kvm_usage_count;
>
> +__weak void kvm_arch_enable_virtualization(void)
> +{
> +
> +}
> +
> +__weak void kvm_arch_disable_virtualization(void)
> +{
> +
> +}
> +
> static int __kvm_enable_virtualization(void)
> {
> if (__this_cpu_read(hardware_enabled))
> @@ -5604,6 +5614,8 @@ static int kvm_enable_virtualization(void)
> if (kvm_usage_count++)
> return 0;
>
> + kvm_arch_enable_virtualization();
> +
> r = cpuhp_setup_state(CPUHP_AP_KVM_ONLINE, "kvm/cpu:online",
> kvm_online_cpu, kvm_offline_cpu);
> if (r)
> @@ -5634,6 +5646,7 @@ static int kvm_enable_virtualization(void)
> unregister_syscore_ops(&kvm_syscore_ops);
> cpuhp_remove_state(CPUHP_AP_KVM_ONLINE);
> err_cpuhp:
> + kvm_arch_disable_virtualization();
> --kvm_usage_count;
> return r;
> }
> @@ -5647,6 +5660,7 @@ static void kvm_disable_virtualization(void)
>
> unregister_syscore_ops(&kvm_syscore_ops);
> cpuhp_remove_state(CPUHP_AP_KVM_ONLINE);
> + kvm_arch_disable_virtualization();
> }
>
> static int kvm_init_virtualization(void)
next prev parent reply other threads:[~2024-08-14 18:15 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
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 [this message]
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=ef4053c9-6bc8-4b08-af8b-6a4a51100283@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®