master
rst 327 lines 15.5 KB
Raw
1 Hyper-V Enlightenments
2 ======================
3
4
5 Description
6 -----------
7
8 In some cases when implementing a hardware interface in software is slow, KVM
9 implements its own paravirtualized interfaces. This works well for Linux as
10 guest support for such features is added simultaneously with the feature itself.
11 It may, however, be hard-to-impossible to add support for these interfaces to
12 proprietary OSes, namely, Microsoft Windows.
13
14 KVM on x86 implements Hyper-V Enlightenments for Windows guests. These features
15 make Windows and Hyper-V guests think they're running on top of a Hyper-V
16 compatible hypervisor and use Hyper-V specific features.
17
18
19 Setup
20 -----
21
22 No Hyper-V enlightenments are enabled by default by either KVM or QEMU. In
23 QEMU, individual enlightenments can be enabled through CPU flags, e.g:
24
25 .. parsed-literal::
26
27 |qemu_system| --enable-kvm --cpu host,hv_relaxed,hv_vpindex,hv_time, ...
28
29 Sometimes there are dependencies between enlightenments, QEMU is supposed to
30 check that the supplied configuration is sane.
31
32 When any set of the Hyper-V enlightenments is enabled, QEMU changes hypervisor
33 identification (CPUID 0x40000000..0x4000000A) to Hyper-V. KVM identification
34 and features are kept in leaves 0x40000100..0x40000101.
35
36
37 Existing enlightenments
38 -----------------------
39
40 ``hv-relaxed``
41 This feature tells guest OS to disable watchdog timeouts as it is running on a
42 hypervisor. It is known that some Windows versions will do this even when they
43 see 'hypervisor' CPU flag.
44
45 ``hv-vapic``
46 Provides so-called VP Assist page MSR to guest allowing it to work with APIC
47 more efficiently. In particular, this enlightenment allows paravirtualized
48 (exit-less) EOI processing.
49
50 ``hv-spinlocks`` = xxx
51 Enables paravirtualized spinlocks. The parameter indicates how many times
52 spinlock acquisition should be attempted before indicating the situation to the
53 hypervisor. A special value 0xffffffff indicates "never notify".
54
55 ``hv-vpindex``
56 Provides HV_X64_MSR_VP_INDEX (0x40000002) MSR to the guest which has Virtual
57 processor index information. This enlightenment makes sense in conjunction with
58 hv-synic, hv-stimer and other enlightenments which require the guest to know its
59 Virtual Processor indices (e.g. when VP index needs to be passed in a
60 hypercall).
61
62 ``hv-runtime``
63 Provides HV_X64_MSR_VP_RUNTIME (0x40000010) MSR to the guest. The MSR keeps the
64 virtual processor run time in 100ns units. This gives guest operating system an
65 idea of how much time was 'stolen' from it (when the virtual CPU was preempted
66 to perform some other work).
67
68 ``hv-crash``
69 Provides HV_X64_MSR_CRASH_P0..HV_X64_MSR_CRASH_P5 (0x40000100..0x40000105) and
70 HV_X64_MSR_CRASH_CTL (0x40000105) MSRs to the guest. These MSRs are written to
71 by the guest when it crashes, HV_X64_MSR_CRASH_P0..HV_X64_MSR_CRASH_P5 MSRs
72 contain additional crash information. This information is outputted in QEMU log
73 and through QAPI.
74 Note: unlike under genuine Hyper-V, write to HV_X64_MSR_CRASH_CTL triggers
75 ``qemu_system_guest_panicked()`` via ``KVM_SYSTEM_EVENT_CRASH`` and the
76 resulting action depends on the ``-action panic=...`` policy (default:
77 ``shutdown``). With the default action, this effectively blocks crash dump
78 generation by Windows.
79
80 ``hv-time``
81 Enables two Hyper-V-specific clocksources available to the guest: MSR-based
82 Hyper-V clocksource (HV_X64_MSR_TIME_REF_COUNT, 0x40000020) and Reference TSC
83 page (enabled via MSR HV_X64_MSR_REFERENCE_TSC, 0x40000021). Both clocksources
84 are per-guest, Reference TSC page clocksource allows for exit-less time stamp
85 readings. Using this enlightenment leads to significant speedup of all timestamp
86 related operations.
87
88 ``hv-synic``
89 Enables Hyper-V Synthetic interrupt controller - an extension of a local APIC.
90 When enabled, this enlightenment provides additional communication facilities
91 to the guest: SynIC messages and Events. This is a pre-requisite for
92 implementing VMBus devices (not yet in QEMU). Additionally, this enlightenment
93 is needed to enable Hyper-V synthetic timers. SynIC is controlled through MSRs
94 HV_X64_MSR_SCONTROL..HV_X64_MSR_EOM (0x40000080..0x40000084) and
95 HV_X64_MSR_SINT0..HV_X64_MSR_SINT15 (0x40000090..0x4000009F)
96
97 Requires: ``hv-vpindex``
98
99 ``hv-stimer``
100 Enables Hyper-V synthetic timers. There are four synthetic timers per virtual
101 CPU controlled through HV_X64_MSR_STIMER0_CONFIG..HV_X64_MSR_STIMER3_COUNT
102 (0x400000B0..0x400000B7) MSRs. These timers can work either in single-shot or
103 periodic mode. It is known that certain Windows versions revert to using HPET
104 (or even RTC when HPET is unavailable) extensively when this enlightenment is
105 not provided; this can lead to significant CPU consumption, even when virtual
106 CPU is idle.
107
108 Requires: ``hv-vpindex``, ``hv-synic``, ``hv-time``
109
110 ``hv-tlbflush``
111 Enables paravirtualized TLB shoot-down mechanism. On x86 architecture, remote
112 TLB flush procedure requires sending IPIs and waiting for other CPUs to perform
113 local TLB flush. In virtualized environment some virtual CPUs may not even be
114 scheduled at the time of the call and may not require flushing (or, flushing
115 may be postponed until the virtual CPU is scheduled). hv-tlbflush enlightenment
116 implements TLB shoot-down through hypervisor enabling the optimization.
117
118 Requires: ``hv-vpindex``
119
120 ``hv-ipi``
121 Enables paravirtualized IPI send mechanism. HvCallSendSyntheticClusterIpi
122 hypercall may target more than 64 virtual CPUs simultaneously, doing the same
123 through APIC requires more than one access (and thus exit to the hypervisor).
124
125 Requires: ``hv-vpindex``
126
127 ``hv-vendor-id`` = xxx
128 This changes Hyper-V identification in CPUID 0x40000000.EBX-EDX from the default
129 "Microsoft Hv". The parameter should be no longer than 12 characters. According
130 to the specification, guests shouldn't use this information and it is unknown
131 if there is a Windows version which acts differently.
132 Note: hv-vendor-id is not an enlightenment and thus doesn't enable Hyper-V
133 identification when specified without some other enlightenment.
134
135 ``hv-reset``
136 Provides HV_X64_MSR_RESET (0x40000003) MSR to the guest allowing it to reset
137 itself by writing to it. Even when this MSR is enabled, it is not a recommended
138 way for Windows to perform system reboot and thus it may not be used.
139
140 ``hv-frequencies``
141 Provides HV_X64_MSR_TSC_FREQUENCY (0x40000022) and HV_X64_MSR_APIC_FREQUENCY
142 (0x40000023) allowing the guest to get its TSC/APIC frequencies without doing
143 measurements.
144
145 ``hv-reenlightenment``
146 The enlightenment is nested specific, it targets Hyper-V on KVM guests. When
147 enabled, it provides HV_X64_MSR_REENLIGHTENMENT_CONTROL (0x40000106),
148 HV_X64_MSR_TSC_EMULATION_CONTROL (0x40000107)and HV_X64_MSR_TSC_EMULATION_STATUS
149 (0x40000108) MSRs allowing the guest to get notified when TSC frequency changes
150 (only happens on migration) and keep using old frequency (through emulation in
151 the hypervisor) until it is ready to switch to the new one. This, in conjunction
152 with ``hv-frequencies``, allows Hyper-V on KVM to pass stable clocksource
153 (Reference TSC page) to its own guests.
154
155 Note, KVM doesn't fully support re-enlightenment notifications and doesn't
156 emulate TSC accesses after migration so 'tsc-frequency=' CPU option also has to
157 be specified to make migration succeed. The destination host has to either have
158 the same TSC frequency or support TSC scaling CPU feature.
159
160 Recommended: ``hv-frequencies``
161
162 ``hv-evmcs``
163 The enlightenment is nested specific, it targets Hyper-V on KVM guests. When
164 enabled, it provides Enlightened VMCS version 1 feature to the guest. The feature
165 implements paravirtualized protocol between L0 (KVM) and L1 (Hyper-V)
166 hypervisors making L2 exits to the hypervisor faster. The feature is Intel-only.
167
168 Note: some virtualization features (e.g. Posted Interrupts) are disabled when
169 hv-evmcs is enabled. It may make sense to measure your nested workload with and
170 without the feature to find out if enabling it is beneficial.
171
172 Requires: ``hv-vapic``
173
174 ``hv-stimer-direct``
175 Hyper-V specification allows synthetic timer operation in two modes: "classic",
176 when expiration event is delivered as SynIC message and "direct", when the event
177 is delivered via normal interrupt. It is known that nested Hyper-V can only
178 use synthetic timers in direct mode and thus ``hv-stimer-direct`` needs to be
179 enabled.
180
181 Requires: ``hv-vpindex``, ``hv-synic``, ``hv-time``, ``hv-stimer``
182
183 ``hv-avic`` (``hv-apicv``)
184 The enlightenment allows to use Hyper-V SynIC with hardware APICv/AVIC enabled.
185 Normally, Hyper-V SynIC disables these hardware feature and suggests the guest
186 to use paravirtualized AutoEOI feature.
187 Note: enabling this feature on old hardware (without APICv/AVIC support) may
188 have negative effect on guest's performance.
189
190 ``hv-no-nonarch-coresharing`` = on/off/auto
191 This enlightenment tells guest OS that virtual processors will never share a
192 physical core unless they are reported as sibling SMT threads. This information
193 is required by Windows and Hyper-V guests to properly mitigate SMT related CPU
194 vulnerabilities.
195
196 When the option is set to 'auto' QEMU will enable the feature only when KVM
197 reports that non-architectural coresharing is impossible, this means that
198 hyper-threading is not supported or completely disabled on the host. This
199 setting also prevents migration as SMT settings on the destination may differ.
200 When the option is set to 'on' QEMU will always enable the feature, regardless
201 of host setup. To keep guests secure, this can only be used in conjunction with
202 exposing correct vCPU topology and vCPU pinning.
203
204 ``hv-version-id-build``, ``hv-version-id-major``, ``hv-version-id-minor``, ``hv-version-id-spack``, ``hv-version-id-sbranch``, ``hv-version-id-snumber``
205 This changes Hyper-V version identification in CPUID 0x40000002.EAX-EDX from the
206 default (WS2016).
207
208 - ``hv-version-id-build`` sets 'Build Number' (32 bits)
209 - ``hv-version-id-major`` sets 'Major Version' (16 bits)
210 - ``hv-version-id-minor`` sets 'Minor Version' (16 bits)
211 - ``hv-version-id-spack`` sets 'Service Pack' (32 bits)
212 - ``hv-version-id-sbranch`` sets 'Service Branch' (8 bits)
213 - ``hv-version-id-snumber`` sets 'Service Number' (24 bits)
214
215 Note: hv-version-id-* are not enlightenments and thus don't enable Hyper-V
216 identification when specified without any other enlightenments.
217
218 ``hv-syndbg``
219 Enables Hyper-V synthetic debugger interface, this is a special interface used
220 by Windows Kernel debugger to send the packets through, rather than sending
221 them via serial/network .
222 When enabled, this enlightenment provides additional communication facilities
223 to the guest: SynDbg messages.
224 This new communication is used by Windows Kernel debugger rather than sending
225 packets via serial/network, adding significant performance boost over the other
226 comm channels.
227 This enlightenment requires a VMBus device (-device vmbus-bridge,irq=15).
228
229 Requires: ``hv-relaxed``, ``hv_time``, ``hv-vapic``, ``hv-vpindex``, ``hv-synic``, ``hv-runtime``, ``hv-stimer``
230
231 ``hv-emsr-bitmap``
232 The enlightenment is nested specific, it targets Hyper-V on KVM guests. When
233 enabled, it allows L0 (KVM) and L1 (Hyper-V) hypervisors to collaborate to
234 avoid unnecessary updates to L2 MSR-Bitmap upon vmexits. While the protocol is
235 supported for both VMX (Intel) and SVM (AMD), the VMX implementation requires
236 Enlightened VMCS (``hv-evmcs``) feature to also be enabled.
237
238 Recommended: ``hv-evmcs`` (Intel)
239
240 ``hv-xmm-input``
241 Hyper-V specification allows to pass parameters for certain hypercalls using XMM
242 registers ("XMM Fast Hypercall Input"). When the feature is in use, it allows
243 for faster hypercalls processing as KVM can avoid reading guest's memory.
244
245 ``hv-tlbflush-ext``
246 Allow for extended GVA ranges to be passed to Hyper-V TLB flush hypercalls
247 (HvFlushVirtualAddressList/HvFlushVirtualAddressListEx).
248
249 Requires: ``hv-tlbflush``
250
251 ``hv-tlbflush-direct``
252 The enlightenment is nested specific, it targets Hyper-V on KVM guests. When
253 enabled, it allows L0 (KVM) to directly handle TLB flush hypercalls from L2
254 guest without the need to exit to L1 (Hyper-V) hypervisor. While the feature is
255 supported for both VMX (Intel) and SVM (AMD), the VMX implementation requires
256 Enlightened VMCS (``hv-evmcs``) feature to also be enabled.
257
258 Requires: ``hv-vapic``
259
260 Recommended: ``hv-evmcs`` (Intel)
261
262 Supplementary features
263 ----------------------
264
265 ``hv-passthrough``
266 In some cases (e.g. during development) it may make sense to use QEMU in
267 'pass-through' mode and give Windows guests all enlightenments currently
268 supported by KVM.
269
270 Note: ``hv-passthrough`` flag only enables enlightenments which are known to QEMU
271 (have corresponding 'hv-' flag) and copies ``hv-spinlocks`` and ``hv-vendor-id``
272 values from KVM to QEMU. ``hv-passthrough`` overrides all other 'hv-' settings on
273 the command line.
274
275 Note: ``hv-passthrough`` does not enable ``hv-syndbg`` which can prevent certain
276 Windows guests from booting when used without proper configuration. If needed,
277 ``hv-syndbg`` can be enabled additionally.
278
279 Note: ``hv-passthrough`` effectively prevents migration as the list of enabled
280 enlightenments may differ between target and destination hosts.
281
282 ``hv-enforce-cpuid``
283 By default, KVM allows the guest to use all currently supported Hyper-V
284 enlightenments when Hyper-V CPUID interface was exposed, regardless of if
285 some features were not announced in guest visible CPUIDs. ``hv-enforce-cpuid``
286 feature alters this behavior and only allows the guest to use exposed Hyper-V
287 enlightenments.
288
289 Recommendations
290 ---------------
291
292 To achieve the best performance of Windows and Hyper-V guests and unless there
293 are any specific requirements (e.g. migration to older QEMU/KVM versions,
294 emulating specific Hyper-V version, ...), it is recommended to enable all
295 currently implemented Hyper-V enlightenments with the following exceptions:
296
297 - ``hv-syndbg``, ``hv-passthrough``, ``hv-enforce-cpuid`` should not be enabled
298 in production configurations as these are debugging/development features.
299 - ``hv-reset`` can be avoided as modern Hyper-V versions don't expose it.
300 - ``hv-evmcs`` can (and should) be enabled on Intel CPUs only. While the feature
301 is only used in nested configurations (Hyper-V, WSL2), enabling it for regular
302 Windows guests should not have any negative effects.
303 - ``hv-no-nonarch-coresharing`` must only be enabled if vCPUs are properly pinned
304 so no non-architectural core sharing is possible.
305 - ``hv-vendor-id``, ``hv-version-id-build``, ``hv-version-id-major``,
306 ``hv-version-id-minor``, ``hv-version-id-spack``, ``hv-version-id-sbranch``,
307 ``hv-version-id-snumber`` can be left unchanged, guests are not supposed to
308 behave differently when different Hyper-V version is presented to them.
309 - ``hv-crash`` must only be enabled if the crash information is consumed via
310 QAPI by higher levels of the virtualization stack. With the default
311 ``-action panic=shutdown`` policy, enabling this feature effectively
312 prevents Windows from creating dumps upon crashes.
313 - ``hv-reenlightenment`` can only be used on hardware which supports TSC
314 scaling or when guest migration is not needed.
315 - ``hv-spinlocks`` should be set to e.g. 0xfff when host CPUs are overcommited
316 (meaning there are other scheduled tasks or guests) and can be left unchanged
317 from the default value (0xffffffff) otherwise.
318 - ``hv-avic``/``hv-apicv`` should not be enabled if the hardware does not
319 support APIC virtualization (Intel APICv, AMD AVIC).
320
321 Useful links
322 ------------
323 Hyper-V Top Level Functional specification and other information:
324
325 - https://github.com/MicrosoftDocs/Virtualization-Documentation
326 - https://docs.microsoft.com/en-us/virtualization/hyper-v-on-windows/tlfs/tlfs
327