Commit fd36a31
committed
hypervisor: kvm: enable Enlightened VMCS for nested Hyper-V guests
A Windows guest that itself runs Hyper-V (nested Hyper-V, or WSL2 which
is built on it) acts as an L1 hypervisor on top of KVM. On Intel, Hyper-V
does not drive KVM through the architectural VMCS — it uses Microsoft's
Enlightened VMCS (eVMCS) layout, a paravirtualized L0(KVM)<->L1(Hyper-V)
protocol. Cloud Hypervisor never negotiated eVMCS: it enabled only
KVM_CAP_HYPERV_SYNIC and left the Hyper-V nested-features CPUID leaf
(0x4000000A) zeroed. The guest's hvix64 therefore reaches VMXON with no
eVMCS contract in place and the nested launch path stalls.
Wire up the missing piece:
- Add Vcpu::enable_hyperv_enlightened_vmcs(), a no-op by default (so MSHV,
which handles nesting natively, and non-x86 backends are unaffected) and
implemented on the KVM backend as KVM_ENABLE_CAP(KVM_CAP_HYPERV_ENLIGHTENED_VMCS).
- In configure_vcpu(), when Hyper-V enlightenments + nested are both on and
the vCPU is Intel, enable the eVMCS capability before set_cpuid2 (KVM only
accepts leaf 0x4000000A after the cap is enabled) and then advertise:
* 0x40000004.EAX bit 14 HV_ENLIGHTENED_VMCS_RECOMMENDED
* 0x4000000A.EAX low 16 supported eVMCS version range (v1: 0x0101)
bit 17 HV_NESTED_DIRECT_FLUSH
bit 19 HV_NESTED_MSR_BITMAP
Gated Intel-only because eVMCS is a VMX construct; AMD/SVM is untouched.
Gated on `nested` so non-nested Windows guests are unchanged.
Scope note: this is necessary but, in a deeply-nested environment (e.g. a
cloud instance that is itself an L1 guest, making the Windows guest L2 and
its WSL2/Hyper-V workload L3), may not be sufficient on its own — the host's
own nesting depth can still be the limiting factor. On a bare-metal Intel
KVM host this provides the eVMCS contract Hyper-V requires.
Sources:
Linux Documentation/virt/kvm/api.rst (KVM_CAP_HYPERV_ENLIGHTENED_VMCS;
HYPERV_CPUID_NESTED_FEATURES exposed only after the cap is enabled)
Microsoft Hypervisor Top-Level Functional Specification (eVMCS,
HV_CPUID_NESTED_FEATURES)
qemu/qemu docs/system/i386/hyperv.rst (hv-evmcs: Intel-only, nested-only)1 parent a769777 commit fd36a31
3 files changed
Lines changed: 77 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
51 | 51 | | |
52 | 52 | | |
53 | 53 | | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
54 | 64 | | |
55 | 65 | | |
56 | 66 | | |
| |||
1000 | 1010 | | |
1001 | 1011 | | |
1002 | 1012 | | |
| 1013 | + | |
| 1014 | + | |
| 1015 | + | |
| 1016 | + | |
| 1017 | + | |
| 1018 | + | |
| 1019 | + | |
| 1020 | + | |
| 1021 | + | |
| 1022 | + | |
| 1023 | + | |
| 1024 | + | |
| 1025 | + | |
| 1026 | + | |
| 1027 | + | |
| 1028 | + | |
| 1029 | + | |
| 1030 | + | |
| 1031 | + | |
| 1032 | + | |
| 1033 | + | |
| 1034 | + | |
| 1035 | + | |
| 1036 | + | |
| 1037 | + | |
| 1038 | + | |
| 1039 | + | |
1003 | 1040 | | |
1004 | 1041 | | |
1005 | 1042 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
212 | 212 | | |
213 | 213 | | |
214 | 214 | | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
215 | 219 | | |
216 | 220 | | |
217 | 221 | | |
| |||
417 | 421 | | |
418 | 422 | | |
419 | 423 | | |
| 424 | + | |
| 425 | + | |
| 426 | + | |
| 427 | + | |
| 428 | + | |
| 429 | + | |
| 430 | + | |
| 431 | + | |
| 432 | + | |
| 433 | + | |
| 434 | + | |
| 435 | + | |
| 436 | + | |
420 | 437 | | |
421 | 438 | | |
422 | 439 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
68 | 68 | | |
69 | 69 | | |
70 | 70 | | |
71 | | - | |
72 | | - | |
73 | | - | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
74 | 75 | | |
75 | 76 | | |
76 | 77 | | |
| |||
2247 | 2248 | | |
2248 | 2249 | | |
2249 | 2250 | | |
| 2251 | + | |
| 2252 | + | |
| 2253 | + | |
| 2254 | + | |
| 2255 | + | |
| 2256 | + | |
| 2257 | + | |
| 2258 | + | |
| 2259 | + | |
| 2260 | + | |
| 2261 | + | |
| 2262 | + | |
| 2263 | + | |
| 2264 | + | |
| 2265 | + | |
| 2266 | + | |
| 2267 | + | |
| 2268 | + | |
| 2269 | + | |
2250 | 2270 | | |
2251 | 2271 | | |
2252 | 2272 | | |
| |||
0 commit comments