x86_64: lock IA32_FEATURE_CONTROL with VMXON enabled at boot#438
Open
CMGS wants to merge 1 commit into
Open
Conversation
Guest hypervisors (Windows Hyper-V, WSL2) check IA32_FEATURE_CONTROL at boot and refuse VMXON unless firmware has set the lock bit with VMXON-outside-SMX enabled -- otherwise they report "virtualization not enabled in firmware". rust-hypervisor-firmware never touched this MSR, so a Windows guest saw VMX in CPUID (VMMonitorModeExtensions=True) but VirtualizationFirmwareEnabled=False, and Hyper-V launch failed with Event 41 "Either VMX not present or not enabled in BIOS". Nested virtualization was therefore unusable. Set the MSR the way real firmware does: when CPUID reports VMX, lock IA32_FEATURE_CONTROL with VMXON-outside-SMX enabled, before handing control to the OS. Skipped when the lock bit is already set (idempotent) and when VMX is absent (AMD / nested off), so AMD and non-nested guests are unaffected. Verified on a Cloud Hypervisor Windows 11 guest: VirtualizationFirmwareEnabled flips False to True and the guest boots normally. Signed-off-by: tonic <tonicbupt@gmail.com>
0c6a309 to
5eda674
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Guest hypervisors (Windows Hyper-V, WSL2) check
IA32_FEATURE_CONTROL(MSR0x3A) at boot and refuseVMXONunless the firmware has set the lock bitwith VMXON-outside-SMX enabled — otherwise they report "virtualization not
enabled in firmware". rust-hypervisor-firmware never touched this MSR, so a
Windows guest saw VMX in CPUID (
VMMonitorModeExtensions=True) butVirtualizationFirmwareEnabled=False, and Hyper-V launch failed with Event 41"Either VMX not present or not enabled in BIOS". Nested virtualization was
therefore unusable.
Set the MSR the way real firmware does: in
rust64_start, whenCPUID.1:ECX.VMXreports VMX support, lock
IA32_FEATURE_CONTROLwith bit 0 (LOCKED) and bit 2(VMXON-outside-SMX), before handing control to the OS. The write is skipped when
the lock bit is already set (idempotent) and when VMX is absent (AMD / nested
off), so AMD and non-nested guests are unaffected. Other architectures
(aarch64, riscv64) are not touched.
Verified on a Cloud Hypervisor Windows 11 guest:
VirtualizationFirmwareEnabledflips False to True and the guest boots normally.
Signed-off-by: tonic tonicbupt@gmail.com