public inbox for kvm@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2 0/6] KVM: Register cpuhp/syscore callbacks when enabling virt
@ 2024-05-22  2:28 Sean Christopherson
  2024-05-22  2:28 ` [PATCH v2 1/6] KVM: Register cpuhp and syscore callbacks when enabling hardware Sean Christopherson
                   ` (5 more replies)
  0 siblings, 6 replies; 27+ messages in thread
From: Sean Christopherson @ 2024-05-22  2:28 UTC (permalink / raw)
  To: Sean Christopherson, Paolo Bonzini; +Cc: kvm, linux-kernel, Chao Gao, Kai Huang

Register KVM's cpuhp and syscore callbacks when enabling virtualization in
hardware, as the sole purpose of said callbacks is to disable and re-enable
virtualization as needed.

The primary motivation for this series is to simplify dealing with enabling
virtualization for Intel's TDX, which needs to enable virtualization
when kvm-intel.ko is loaded, i.e. long before the first VM is created.  TDX
doesn't _need_ to keep virtualization enabled, but doing so is much simpler
for KVM (see patch 3).

That said, this is a nice cleanup on its own, assuming I haven't broken
something.  By registering the callbacks on-demand, the callbacks themselves
don't need to check kvm_usage_count, because their very existence implies a
non-zero count.

The meat is in patch 1.  Patches 2 renames the helpers so that patch 3 is
less awkward.  Patch 3 adds a module param to enable virtualization when KVM
is loaded.  Patches 4-6 are tangentially related x86 cleanups to registers
KVM's "emergency disable" callback on-demand, same as the syscore callbacks.

Moderately well tested on x86, though I haven't (yet) done due dilegence on
the suspend/resume and cphup paths.  Compile tested on other architectures,
but that's all for this version.

v2:
 - Use a dedicated mutex to avoid lock inversion issues between kvm_lock and
   the cpuhp lock.
 - Register emergency disable callbacks on-demand. [Kai]
 - Drop an unintended s/junk/ign rename. [Kai]
 - Decrement kvm_usage_count on failure. [Chao]

v1: https://lore.kernel.org/all/20240425233951.3344485-1-seanjc@google.com

Sean Christopherson (6):
  KVM: Register cpuhp and syscore callbacks when enabling hardware
  KVM: Rename functions related to enabling virtualization hardware
  KVM: Add a module param to allow enabling virtualization when KVM is
    loaded
  KVM: Add arch hooks for enabling/disabling virtualization
  x86/reboot: Unconditionally define cpu_emergency_virt_cb typedef
  KVM: x86: Register "emergency disable" callbacks when virt is enabled

 arch/x86/include/asm/kvm_host.h |   3 +
 arch/x86/include/asm/reboot.h   |   2 +-
 arch/x86/kvm/svm/svm.c          |   5 +-
 arch/x86/kvm/vmx/main.c         |   2 +
 arch/x86/kvm/vmx/vmx.c          |   6 +-
 arch/x86/kvm/vmx/x86_ops.h      |   1 +
 arch/x86/kvm/x86.c              |  10 ++
 include/linux/kvm_host.h        |   2 +
 virt/kvm/kvm_main.c             | 258 ++++++++++++++++----------------
 9 files changed, 150 insertions(+), 139 deletions(-)


base-commit: 4aad0b1893a141f114ba40ed509066f3c9bc24b0
-- 
2.45.0.215.g3402c0e53f-goog


^ permalink raw reply	[flat|nested] 27+ messages in thread

end of thread, other threads:[~2024-05-30  0:07 UTC | newest]

Thread overview: 27+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-05-22  2:28 [PATCH v2 0/6] KVM: Register cpuhp/syscore callbacks when enabling virt Sean Christopherson
2024-05-22  2:28 ` [PATCH v2 1/6] KVM: Register cpuhp and syscore callbacks when enabling hardware Sean Christopherson
2024-05-22  6:10   ` Chao Gao
2024-05-29 14:29     ` Sean Christopherson
2024-05-22  2:28 ` [PATCH v2 2/6] KVM: Rename functions related to enabling virtualization hardware Sean Christopherson
2024-05-22  7:10   ` Chao Gao
2024-05-22 22:34   ` Huang, Kai
2024-05-22  2:28 ` [PATCH v2 3/6] KVM: Add a module param to allow enabling virtualization when KVM is loaded Sean Christopherson
2024-05-22 22:27   ` Huang, Kai
2024-05-23  4:23     ` Chao Gao
2024-05-23 23:11       ` Huang, Kai
2024-05-24  2:39         ` Chao Gao
2024-05-27 22:36           ` Huang, Kai
2024-05-29 15:01             ` Sean Christopherson
2024-05-29 22:45               ` Huang, Kai
2024-05-29 23:07                 ` Sean Christopherson
2024-05-30  0:06                   ` Huang, Kai
2024-05-22  2:28 ` [PATCH v2 4/6] KVM: Add arch hooks for enabling/disabling virtualization Sean Christopherson
2024-05-22 22:33   ` Huang, Kai
2024-05-28 22:50     ` Sean Christopherson
2024-05-23  5:31   ` Chao Gao
2024-05-22  2:28 ` [PATCH v2 5/6] x86/reboot: Unconditionally define cpu_emergency_virt_cb typedef Sean Christopherson
2024-05-22 22:35   ` Huang, Kai
2024-05-23  5:41   ` Chao Gao
2024-05-22  2:28 ` [PATCH v2 6/6] KVM: x86: Register "emergency disable" callbacks when virt is enabled Sean Christopherson
2024-05-22 22:37   ` Huang, Kai
2024-05-23  5:59   ` Chao Gao

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox