x86/reboot: KVM: Clean up "emergency" virt code
Status from this message: Applied to kvm-x86 misc, thanks!
Get series with b4
b4 am [email protected]Versions newest first · linked by author and title
- v4 Latest19 patches 16 repliesApplied
- v318 patches 19 repliesSuperseded
- v218 patches 16 repliesSuperseded
Earlier versions · 1
| Version | Posted | Patches | Replies | Status |
|---|---|---|---|---|
| v1 | 16 patches | 0 replies | Superseded |
Changes in v4 from the cover letter
- Collect reviews. [Kai]
- Skip VMCLEAR during reboot if CR4.VMXE=0. [Kai]
- Call out that disabling virtualization iff there's a callback also avoids an unnecessary NMI shootdown. [Kai]
- Move "Disable virtualization during reboot iff callback is registered" patch after "Hoist "disable virt" helpers above \"emergency reboot\"" patch to fix an intermediate build error.
Patches in v4 Applied
| # | Subject and files | Size | Replies | Applied |
|---|---|---|---|---|
| 1/19 | x86/reboot: VMCLEAR active VMCSes before emergency rebootarch/ arch/ arch/ +2 more | +27 | 0 replies | |
| 2/19 | x86/reboot: Harden virtualization hooks for emergency rebootarch/ arch/ arch/ | +29 | 0 replies | |
| 3/19 | x86/reboot: KVM: Handle VMXOFF in KVM's reboot callbackarch/ arch/ arch/ | +14 | 1 reply | |
| 4/19 | x86/reboot: KVM: Disable SVM during reboot via virt/KVM reboot callbackarch/ arch/ arch/ | +17 | 0 replies | |
| 5/19 | x86/reboot: Assert that IRQs are disabled when turning off virtualizationarch/ | +7 | 2 replies | |
| 6/19 | x86/reboot: Hoist "disable virt" helpers above "emergency reboot" patharch/ | +45 | 0 replies | |
| 7/19 | x86/reboot: Disable virtualization during reboot iff callback is registeredarch/ | +1 | 1 reply | |
| 8/19 | x86/reboot: Expose VMCS crash hooks if and only if KVM_{INTEL,AMD} is enabledarch/ arch/ | +8 | 0 replies | |
| 9/19 | x86/virt: KVM: Open code cpu_has_vmx() in KVM VMXarch/ arch/ | +1 | 0 replies | |
| 10/19 | x86/virt: KVM: Move VMXOFF helpers into KVM VMXarch/ arch/ | +26 | 2 replies | |
| 11/19 | KVM: SVM: Make KVM_AMD depend on CPU_SUP_AMD or CPU_SUP_HYGONarch/ | +1 | 0 replies | |
| 12/19 | x86/virt: Drop unnecessary check on extended CPUID level in cpu_has_svm()arch/ | +0 | 0 replies | |
| 13/19 | x86/virt: KVM: Open code cpu_has_svm() into kvm_is_svm_supported()arch/ arch/ | +8 | 0 replies | |
| 14/19 | KVM: SVM: Check that the current CPU supports SVM in kvm_is_svm_supported()arch/ | +19 | 6 replies | |
| 15/19 | KVM: VMX: Ensure CPU is stable when probing basic VMX supportarch/ | +14 | 0 replies | |
| 16/19 | x86/virt: KVM: Move "disable SVM" helper into KVM SVMarch/ arch/ | +25 | 0 replies | |
| 17/19 | KVM: x86: Force kvm_rebooting=true during emergency reboot/crasharch/ arch/ | +4 | 0 replies | |
| 18/19 | KVM: SVM: Use "standard" stgi() helper when disabling SVMarch/ | +3 | 0 replies | |
| 19/19 | KVM: VMX: Skip VMCLEAR logic during emergency reboots if CR4.VMXE=0arch/ | +10 | 3 replies |
Reviews trailers per patch
15 of 19 patches have a Reviewed-by or Acked-by.
| Patch | Kai Huang |
|---|---|
| 1/19 | |
| 2/19 | R-b |
| 3/19 | R-b |
| 4/19 | A-b |
| 5/19 | R-b |
| 6/19 | R-b |
| 7/19 | R-b |
| 8/19 | R-b |
| 9/19 | R-b |
| 10/19 | R-b |
| 11/19 | |
| 12/19 | |
| 13/19 | R-b |
| 14/19 | R-b |
| 15/19 | R-b |
| 16/19 | R-b |
| 17/19 | R-b |
| 18/19 | |
| 19/19 | R-b |
Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes.
Cover letter [PATCH v4 00/19] x86/reboot: KVM: Clean up "emergency" virt code
If there are no objections, my plan is to take this through the KVM tree for 6.6.
Instead of having the reboot code blindly try to disable virtualization during an emergency, use the existing callback into KVM to disable virt as "needed". In quotes because KVM still somewhat blindly attempts to disable virt, e.g. if KVM is loaded but doesn't have active VMs and thus hasn't enabled hardware. That could theoretically be "fixed", but due to the callback being invoked from NMI context, I'm not convinced it would be worth the complexity. E.g. false positives would still be possible, and KVM would have to play games with the per-CPU hardware_enabled flag to ensure there are no false negatives.
The callback is currently used only to VMCLEAR the per-CPU list of VMCSes, but not using the callback to disable virt isn't intentional. Arguably, a callback should have been used in the initial "disable virt" code added by commit d176720d34c7 ("x86: disable VMX on all CPUs on reboot"). And the kexec logic added (much later) by commit f23d1f4a1160 ("x86/kexec: VMCLEAR VMCSs loaded on all cpus if necessary") simply missed the opportunity to use the callback for all virtualization needs.
Once KVM handles disabling virt, move all of the helpers provided by virtext.h into KVM proper.
There's one outlier patch, "Make KVM_AMD depend on CPU_SUP_AMD or CPU_SUP_HYGON", that I included here because it felt weird to pull in the "must be AMD or Hygon" check without KVM demanding that at build time.
v4:
- Collect reviews. [Kai]
- Skip VMCLEAR during reboot if CR4.VMXE=0. [Kai]
- Call out that disabling virtualization iff there's a callback also avoids an unnecessary NMI shootdown. [Kai]
- Move "Disable virtualization during reboot iff callback is registered" patch after "Hoist "disable virt" helpers above \"emergency reboot\"" patch to fix an intermediate build error.
v3:
- https://lore.kernel.org/all/[email protected]
- Massage changelogs to avoid talking about out-of-tree hypervisors. [Kai]
- Move #ifdef "KVM" addition later. [Kai]
v2:
- https://lore.kernel.org/all/[email protected]
- Disable task migration when probing basic SVM and VMX support to avoid logging misleading info (wrong CPU) if probing fails.
v1: https://lore.kernel.org/all/[email protected]
Sean Christopherson (19):
x86/reboot: VMCLEAR active VMCSes before emergency reboot x86/reboot: Harden virtualization hooks for emergency reboot x86/reboot: KVM: Handle VMXOFF in KVM's reboot callback x86/reboot: KVM: Disable SVM during reboot via virt/KVM reboot
callback
x86/reboot: Assert that IRQs are disabled when turning off
virtualization
x86/reboot: Hoist "disable virt" helpers above "emergency reboot" path x86/reboot: Disable virtualization during reboot iff callback is
registered
x86/reboot: Expose VMCS crash hooks if and only if KVM_{INTEL,AMD} is
enabled
x86/virt: KVM: Open code cpu_has_vmx() in KVM VMX x86/virt: KVM: Move VMXOFF helpers into KVM VMX
KVM: SVM: Make KVM_AMD depend on CPU_SUP_AMD or CPU_SUP_HYGON x86/virt: Drop unnecessary check on extended CPUID level in
cpu_has_svm()
x86/virt: KVM: Open code cpu_has_svm() into kvm_is_svm_supported()
KVM: SVM: Check that the current CPU supports SVM in
kvm_is_svm_supported()
KVM: VMX: Ensure CPU is stable when probing basic VMX support x86/virt: KVM: Move "disable SVM" helper into KVM SVM
KVM: x86: Force kvm_rebooting=true during emergency reboot/crash
KVM: SVM: Use "standard" stgi() helper when disabling SVM
KVM: VMX: Skip VMCLEAR logic during emergency reboots if CR4.VMXE=0
arch/x86/include/asm/kexec.h | 2 - arch/x86/include/asm/reboot.h | 7 ++ arch/x86/include/asm/virtext.h | 154 --------------------------------- arch/x86/kernel/crash.c | 31 ------- arch/x86/kernel/reboot.c | 66 ++++++++++---- arch/x86/kvm/Kconfig | 2 +- arch/x86/kvm/svm/svm.c | 71 ++++++++++++--- arch/x86/kvm/vmx/vmx.c | 76 ++++++++++++---- 8 files changed, 176 insertions(+), 233 deletions(-) delete mode 100644 arch/x86/include/asm/virtext.h
base-commit: fdf0eaf11452d72945af31804e2a1048ee1b574c
Signature · 1 line
2.41.0.487.g6d72f3e995-goog