Skip to content

KVM: Register cpuhp/syscore callbacks when enabling virt

Sean Christopherson kvm kvm-riscv kvmarm linux-arm-kernel linux-mips linux-riscv lkml loongarch 4 versions – Applied

Status from this message: Queued, thanks.

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v4 Latest10 patches 6 repliesApplied
  2. v38 patches 22 repliesSuperseded
  3. v26 patches 20 repliesSuperseded
Earlier versions · 1
VersionPostedPatchesRepliesStatus
v14 patches18 repliesSuperseded

Changes in v4 from the cover letter

- Collect more reviews.
- Fix documentation for kvm_usage_lock. [Kai]
- Add a blurb in locking.rst to call out that cpus_read_lock() vs kvm_lock is a general problem.
- Add a paragraph in the locking patch to suggest switching vm_list to an (S)RCU-protected list, so that walkers don't need to take kvm_lock.
- Add an example call chain for the other cpus_read_lock() vs kvm_lock issues that are lurking.
- Enable the module param by default from the get-go. [Paolo]
- Rename even more APIs/symbols (all of 'em I could find). [Paolo]
- Clarify that it's the 0=>1 VM creation that's problematic, not simply the creation of the very first VM. [Paolo]
- Document enable_virt_at_load, and call out the (dis)advantages of enabling virtualization when KVM is loaded.
- Drop the WARN on kvm_usage_count being elevated at the end of kvm_uninit_virtualization(), as it's annoyingly difficult to keep the WARN and still allow arch code (i.e. TDX) to enable virtualization during setup.

Patches in v4 Applied

#Subject and filesSizeRepliesApplied
1/10KVM: Use dedicated mutex to protect kvm_usage_count to avoid deadlockDocumentation/virt/kvm/locking.rst virt/kvm/kvm_main.c+39 -243 replies
2/10KVM: Register cpuhp and syscore callbacks when enabling hardwareDocumentation/virt/kvm/locking.rst virt/kvm/kvm_main.c+66 -1170 replies
3/10KVM: Rename symbols related to enabling virtualization hardwarevirt/kvm/kvm_main.c+21 -210 replies
4/10KVM: Rename arch hooks related to per-CPU virtualization enablingarch/arm64/kvm/arm.c arch/loongarch/kvm/main.c arch/mips/kvm/mips.c +4 more+16 -161 reply
5/10KVM: MIPS: Rename virtualization {en,dis}abling APIs to match common KVMarch/mips/include/asm/kvm_host.h arch/mips/kvm/mips.c arch/mips/kvm/vz.c+8 -80 replies
6/10KVM: x86: Rename virtualization {en,dis}abling APIs to match common KVMarch/x86/include/asm/kvm-x86-ops.h arch/x86/include/asm/kvm_host.h arch/x86/kvm/svm/svm.c +4 more+27 -271 reply
7/10KVM: Add a module param to allow enabling virtualization when KVM is loadedDocumentation/admin-guide/kernel-parameters.txt virt/kvm/kvm_main.c+52 -00 replies
8/10KVM: Add arch hooks for enabling/disabling virtualizationinclude/linux/kvm_host.h virt/kvm/kvm_main.c+28 -00 replies
9/10x86/reboot: Unconditionally define cpu_emergency_virt_cb typedefarch/x86/include/asm/reboot.h+1 -10 replies
10/10KVM: x86: Register "emergency disable" callbacks when virt is enabledarch/x86/include/asm/kvm_host.h arch/x86/kvm/svm/svm.c arch/x86/kvm/vmx/main.c +3 more+18 -90 replies

Reviews trailers per patch

9 of 10 patches have a Reviewed-by or Acked-by.

PatchKai HuangFarrah ChenChao Gao
1/10R-b A-b T-b
2/10R-b A-b T-b
3/10R-b A-b T-b R-b
4/10R-b
5/10
6/10R-b
7/10A-b R-b T-b R-b
8/10R-b A-b T-b R-b
9/10A-b R-b T-b R-b
10/10R-b A-b T-b R-b

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes. Scroll the table sideways for all 3 reviewers.

Read the v4 thread

Cover letter [PATCH v4 00/10] KVM: Register cpuhp/syscore callbacks when enabling virt

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.

That said, this is a nice cleanup on its own. 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.

Patch 1 (re)adds a dedicated lock for kvm_usage_count. Hopefully it's a temporary lock, as we can likely fix the cpus_read_lock() vs. kvm_lock mess for good by switching vm_list to an (S)RCU-protected list.

v4:
- Collect more reviews.
- Fix documentation for kvm_usage_lock. [Kai]
- Add a blurb in locking.rst to call out that cpus_read_lock() vs kvm_lock is a general problem.
- Add a paragraph in the locking patch to suggest switching vm_list to an (S)RCU-protected list, so that walkers don't need to take kvm_lock.
- Add an example call chain for the other cpus_read_lock() vs kvm_lock issues that are lurking.
- Enable the module param by default from the get-go. [Paolo]
- Rename even more APIs/symbols (all of 'em I could find). [Paolo]
- Clarify that it's the 0=>1 VM creation that's problematic, not simply the creation of the very first VM. [Paolo]
- Document enable_virt_at_load, and call out the (dis)advantages of enabling virtualization when KVM is loaded.
- Drop the WARN on kvm_usage_count being elevated at the end of kvm_uninit_virtualization(), as it's annoyingly difficult to keep the WARN and still allow arch code (i.e. TDX) to enable virtualization during setup.

v3:
- https://lore.kernel.org/all/20240608000639.3295768-1-seanjc at google.com
- Collect reviews/acks.
- Switch to kvm_usage_lock in a dedicated patch, Cc'd for stable at . [Chao]
- Enable virt at load by default. [Chao]
- Add comments to document how kvm_arch_{en,dis}able_virtualization() fit into the overall flow. [Kai]

v2:
- https://lore.kernel.org/all/20240522022827.1690416-1-seanjc at google.com
- 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 at google.com

Sean Christopherson (10):
KVM: Use dedicated mutex to protect kvm_usage_count to avoid deadlock
KVM: Register cpuhp and syscore callbacks when enabling hardware
KVM: Rename symbols related to enabling virtualization hardware
KVM: Rename arch hooks related to per-CPU virtualization enabling
KVM: MIPS: Rename virtualization {en,dis}abling APIs to match common
KVM
KVM: x86: Rename virtualization {en,dis}abling APIs to match common
KVM
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

 .../admin-guide/kernel-parameters.txt         |  17 ++
 Documentation/virt/kvm/locking.rst            |  31 +-
 arch/arm64/kvm/arm.c                          |   6 +-
 arch/loongarch/kvm/main.c                     |   4 +-
 arch/mips/include/asm/kvm_host.h              |   4 +-
 arch/mips/kvm/mips.c                          |   8 +-
 arch/mips/kvm/vz.c                            |   8 +-
 arch/riscv/kvm/main.c                         |   4 +-
 arch/x86/include/asm/kvm-x86-ops.h            |   4 +-
 arch/x86/include/asm/kvm_host.h               |   7 +-
 arch/x86/include/asm/reboot.h                 |   2 +-
 arch/x86/kvm/svm/svm.c                        |  19 +-
 arch/x86/kvm/vmx/main.c                       |   6 +-
 arch/x86/kvm/vmx/vmx.c                        |  10 +-
 arch/x86/kvm/vmx/x86_ops.h                    |   5 +-
 arch/x86/kvm/x86.c                            |  26 +-
 include/linux/kvm_host.h                      |  18 +-
 virt/kvm/kvm_main.c                           | 270 +++++++++---------
 18 files changed, 251 insertions(+), 198 deletions(-)

base-commit: 15e1c3d65975524c5c792fcd59f7d89f00402261

Signature · 1 line
2.46.0.469.g59c65b2a67-goog