blob: 1c602ad4bda89097cdfa1f7368cb777caa838111 [file] [log] [blame]
Greg Kroah-Hartman6f52b162017-11-01 15:08:43 +01001/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
Vitaly Kuznetsov5a485802018-03-20 15:02:05 +01002
3/*
4 * This file contains definitions from Hyper-V Hypervisor Top-Level Functional
5 * Specification (TLFS):
6 * https://docs.microsoft.com/en-us/virtualization/hyper-v-on-windows/reference/tlfs
7 */
8
9#ifndef _ASM_X86_HYPERV_TLFS_H
10#define _ASM_X86_HYPERV_TLFS_H
Gleb Natapov1d5103c2010-01-17 15:51:21 +020011
12#include <linux/types.h>
13
14/*
15 * The below CPUID leaves are present if VersionAndFeatures.HypervisorPresent
16 * is set by CPUID(HvCpuIdFunctionVersionAndFeatures).
17 */
18#define HYPERV_CPUID_VENDOR_AND_MAX_FUNCTIONS 0x40000000
19#define HYPERV_CPUID_INTERFACE 0x40000001
20#define HYPERV_CPUID_VERSION 0x40000002
21#define HYPERV_CPUID_FEATURES 0x40000003
22#define HYPERV_CPUID_ENLIGHTMENT_INFO 0x40000004
23#define HYPERV_CPUID_IMPLEMENT_LIMITS 0x40000005
Vitaly Kuznetsov5431390b2018-03-20 15:02:10 +010024#define HYPERV_CPUID_NESTED_FEATURES 0x4000000A
Gleb Natapov1d5103c2010-01-17 15:51:21 +020025
Ky Srinivasana2a47c62010-05-06 12:08:41 -070026#define HYPERV_HYPERVISOR_PRESENT_BIT 0x80000000
27#define HYPERV_CPUID_MIN 0x40000005
H. Peter Anvine08cae42010-05-07 16:57:28 -070028#define HYPERV_CPUID_MAX 0x4000ffff
Ky Srinivasana2a47c62010-05-06 12:08:41 -070029
Gleb Natapov1d5103c2010-01-17 15:51:21 +020030/*
31 * Feature identification. EAX indicates which features are available
32 * to the partition based upon the current partition privileges.
33 */
34
35/* VP Runtime (HV_X64_MSR_VP_RUNTIME) available */
36#define HV_X64_MSR_VP_RUNTIME_AVAILABLE (1 << 0)
37/* Partition Reference Counter (HV_X64_MSR_TIME_REF_COUNT) available*/
38#define HV_X64_MSR_TIME_REF_COUNT_AVAILABLE (1 << 1)
K. Y. Srinivasanca9357b2015-08-05 00:52:42 -070039/* Partition reference TSC MSR is available */
40#define HV_X64_MSR_REFERENCE_TSC_AVAILABLE (1 << 9)
K. Y. Srinivasan9e7827b2013-09-30 17:28:52 +020041
Vadim Rozenfelde9840972014-01-16 20:18:37 +110042/* A partition's reference time stamp counter (TSC) page */
43#define HV_X64_MSR_REFERENCE_TSC 0x40000021
44
K. Y. Srinivasan9e7827b2013-09-30 17:28:52 +020045/*
Vitaly Kuznetsov2cf02842017-06-22 18:07:29 +080046 * There is a single feature flag that signifies if the partition has access
47 * to MSRs with local APIC and TSC frequencies.
K. Y. Srinivasan9e7827b2013-09-30 17:28:52 +020048 */
Vitaly Kuznetsov2cf02842017-06-22 18:07:29 +080049#define HV_X64_ACCESS_FREQUENCY_MSRS (1 << 11)
K. Y. Srinivasan9e7827b2013-09-30 17:28:52 +020050
Vitaly Kuznetsov93286262018-01-24 14:23:33 +010051/* AccessReenlightenmentControls privilege */
52#define HV_X64_ACCESS_REENLIGHTENMENT BIT(13)
53
Gleb Natapov1d5103c2010-01-17 15:51:21 +020054/*
55 * Basic SynIC MSRs (HV_X64_MSR_SCONTROL through HV_X64_MSR_EOM
56 * and HV_X64_MSR_SINT0 through HV_X64_MSR_SINT15) available
57 */
58#define HV_X64_MSR_SYNIC_AVAILABLE (1 << 2)
59/*
60 * Synthetic Timer MSRs (HV_X64_MSR_STIMER0_CONFIG through
61 * HV_X64_MSR_STIMER3_COUNT) available
62 */
63#define HV_X64_MSR_SYNTIMER_AVAILABLE (1 << 3)
64/*
65 * APIC access MSRs (HV_X64_MSR_EOI, HV_X64_MSR_ICR and HV_X64_MSR_TPR)
66 * are available
67 */
68#define HV_X64_MSR_APIC_ACCESS_AVAILABLE (1 << 4)
69/* Hypercall MSRs (HV_X64_MSR_GUEST_OS_ID and HV_X64_MSR_HYPERCALL) available*/
70#define HV_X64_MSR_HYPERCALL_AVAILABLE (1 << 5)
71/* Access virtual processor index MSR (HV_X64_MSR_VP_INDEX) available*/
72#define HV_X64_MSR_VP_INDEX_AVAILABLE (1 << 6)
73/* Virtual system reset MSR (HV_X64_MSR_RESET) is available*/
74#define HV_X64_MSR_RESET_AVAILABLE (1 << 7)
75 /*
76 * Access statistics pages MSRs (HV_X64_MSR_STATS_PARTITION_RETAIL_PAGE,
77 * HV_X64_MSR_STATS_PARTITION_INTERNAL_PAGE, HV_X64_MSR_STATS_VP_RETAIL_PAGE,
78 * HV_X64_MSR_STATS_VP_INTERNAL_PAGE) available
79 */
80#define HV_X64_MSR_STAT_PAGES_AVAILABLE (1 << 8)
81
Vitaly Kuznetsov2cf02842017-06-22 18:07:29 +080082/* Frequency MSRs available */
83#define HV_FEATURE_FREQUENCY_MSRS_AVAILABLE (1 << 8)
84
K. Y. Srinivasand058fa72017-01-19 11:51:48 -070085/* Crash MSR available */
86#define HV_FEATURE_GUEST_CRASH_MSR_AVAILABLE (1 << 10)
87
Gleb Natapov1d5103c2010-01-17 15:51:21 +020088/*
89 * Feature identification: EBX indicates which flags were specified at
90 * partition creation. The format is the same as the partition creation
91 * flag structure defined in section Partition Creation Flags.
92 */
93#define HV_X64_CREATE_PARTITIONS (1 << 0)
94#define HV_X64_ACCESS_PARTITION_ID (1 << 1)
95#define HV_X64_ACCESS_MEMORY_POOL (1 << 2)
96#define HV_X64_ADJUST_MESSAGE_BUFFERS (1 << 3)
97#define HV_X64_POST_MESSAGES (1 << 4)
98#define HV_X64_SIGNAL_EVENTS (1 << 5)
99#define HV_X64_CREATE_PORT (1 << 6)
100#define HV_X64_CONNECT_PORT (1 << 7)
101#define HV_X64_ACCESS_STATS (1 << 8)
102#define HV_X64_DEBUGGING (1 << 11)
103#define HV_X64_CPU_POWER_MANAGEMENT (1 << 12)
104#define HV_X64_CONFIGURE_PROFILER (1 << 13)
105
106/*
107 * Feature identification. EDX indicates which miscellaneous features
108 * are available to the partition.
109 */
110/* The MWAIT instruction is available (per section MONITOR / MWAIT) */
111#define HV_X64_MWAIT_AVAILABLE (1 << 0)
112/* Guest debugging support is available */
113#define HV_X64_GUEST_DEBUGGING_AVAILABLE (1 << 1)
114/* Performance Monitor support is available*/
115#define HV_X64_PERF_MONITOR_AVAILABLE (1 << 2)
116/* Support for physical CPU dynamic partitioning events is available*/
117#define HV_X64_CPU_DYNAMIC_PARTITIONING_AVAILABLE (1 << 3)
118/*
119 * Support for passing hypercall input parameter block via XMM
120 * registers is available
121 */
122#define HV_X64_HYPERCALL_PARAMS_XMM_AVAILABLE (1 << 4)
123/* Support for a virtual guest idle state is available */
124#define HV_X64_GUEST_IDLE_STATE_AVAILABLE (1 << 5)
Paolo Bonzini5d75a742015-07-07 12:17:36 +0200125/* Guest crash data handler available */
126#define HV_X64_GUEST_CRASH_MSR_AVAILABLE (1 << 10)
Gleb Natapov1d5103c2010-01-17 15:51:21 +0200127
128/*
129 * Implementation recommendations. Indicates which behaviors the hypervisor
130 * recommends the OS implement for optimal performance.
131 */
132 /*
133 * Recommend using hypercall for address space switches rather
134 * than MOV to CR3 instruction
135 */
K. Y. Srinivasan45396732017-03-14 18:01:38 -0700136#define HV_X64_AS_SWITCH_RECOMMENDED (1 << 0)
Gleb Natapov1d5103c2010-01-17 15:51:21 +0200137/* Recommend using hypercall for local TLB flushes rather
138 * than INVLPG or MOV to CR3 instructions */
139#define HV_X64_LOCAL_TLB_FLUSH_RECOMMENDED (1 << 1)
140/*
141 * Recommend using hypercall for remote TLB flushes rather
142 * than inter-processor interrupts
143 */
144#define HV_X64_REMOTE_TLB_FLUSH_RECOMMENDED (1 << 2)
145/*
146 * Recommend using MSRs for accessing APIC registers
147 * EOI, ICR and TPR rather than their memory-mapped counterparts
148 */
149#define HV_X64_APIC_ACCESS_RECOMMENDED (1 << 3)
150/* Recommend using the hypervisor-provided MSR to initiate a system RESET */
151#define HV_X64_SYSTEM_RESET_RECOMMENDED (1 << 4)
152/*
153 * Recommend using relaxed timing for this partition. If used,
154 * the VM should disable any watchdog timeouts that rely on the
155 * timely delivery of external interrupts
156 */
157#define HV_X64_RELAXED_TIMING_RECOMMENDED (1 << 5)
158
K. Y. Srinivasand058fa72017-01-19 11:51:48 -0700159/*
K. Y. Srinivasan6c248aa2017-03-14 18:01:39 -0700160 * Virtual APIC support
161 */
162#define HV_X64_DEPRECATING_AEOI_RECOMMENDED (1 << 9)
163
Vitaly Kuznetsov628f54c2017-08-02 18:09:20 +0200164/* Recommend using the newer ExProcessorMasks interface */
165#define HV_X64_EX_PROCESSOR_MASKS_RECOMMENDED (1 << 11)
166
Vitaly Kuznetsova46d15c2018-03-20 15:02:08 +0100167/* Recommend using enlightened VMCS */
168#define HV_X64_ENLIGHTENED_VMCS_RECOMMENDED (1 << 14)
169
K. Y. Srinivasan6c248aa2017-03-14 18:01:39 -0700170/*
K. Y. Srinivasand058fa72017-01-19 11:51:48 -0700171 * Crash notification flag.
172 */
173#define HV_CRASH_CTL_CRASH_NOTIFY (1ULL << 63)
174
Gleb Natapov1d5103c2010-01-17 15:51:21 +0200175/* MSR used to identify the guest OS. */
176#define HV_X64_MSR_GUEST_OS_ID 0x40000000
177
178/* MSR used to setup pages used to communicate with the hypervisor. */
179#define HV_X64_MSR_HYPERCALL 0x40000001
180
181/* MSR used to provide vcpu index */
182#define HV_X64_MSR_VP_INDEX 0x40000002
183
Andrey Smetanine516ceb2015-09-16 12:29:48 +0300184/* MSR used to reset the guest OS. */
185#define HV_X64_MSR_RESET 0x40000003
186
Andrey Smetanin9eec50b2015-09-16 12:29:50 +0300187/* MSR used to provide vcpu runtime in 100ns units */
188#define HV_X64_MSR_VP_RUNTIME 0x40000010
189
Ky Srinivasana2a47c62010-05-06 12:08:41 -0700190/* MSR used to read the per-partition time reference counter */
191#define HV_X64_MSR_TIME_REF_COUNT 0x40000020
192
K. Y. Srinivasan9e7827b2013-09-30 17:28:52 +0200193/* MSR used to retrieve the TSC frequency */
194#define HV_X64_MSR_TSC_FREQUENCY 0x40000022
195
196/* MSR used to retrieve the local APIC timer frequency */
197#define HV_X64_MSR_APIC_FREQUENCY 0x40000023
198
Gleb Natapov1d5103c2010-01-17 15:51:21 +0200199/* Define the virtual APIC registers */
200#define HV_X64_MSR_EOI 0x40000070
201#define HV_X64_MSR_ICR 0x40000071
202#define HV_X64_MSR_TPR 0x40000072
Ladi Prosekd4abc572018-03-20 15:02:07 +0100203#define HV_X64_MSR_VP_ASSIST_PAGE 0x40000073
Gleb Natapov1d5103c2010-01-17 15:51:21 +0200204
205/* Define synthetic interrupt controller model specific registers. */
206#define HV_X64_MSR_SCONTROL 0x40000080
207#define HV_X64_MSR_SVERSION 0x40000081
208#define HV_X64_MSR_SIEFP 0x40000082
209#define HV_X64_MSR_SIMP 0x40000083
210#define HV_X64_MSR_EOM 0x40000084
211#define HV_X64_MSR_SINT0 0x40000090
212#define HV_X64_MSR_SINT1 0x40000091
213#define HV_X64_MSR_SINT2 0x40000092
214#define HV_X64_MSR_SINT3 0x40000093
215#define HV_X64_MSR_SINT4 0x40000094
216#define HV_X64_MSR_SINT5 0x40000095
217#define HV_X64_MSR_SINT6 0x40000096
218#define HV_X64_MSR_SINT7 0x40000097
219#define HV_X64_MSR_SINT8 0x40000098
220#define HV_X64_MSR_SINT9 0x40000099
221#define HV_X64_MSR_SINT10 0x4000009A
222#define HV_X64_MSR_SINT11 0x4000009B
223#define HV_X64_MSR_SINT12 0x4000009C
224#define HV_X64_MSR_SINT13 0x4000009D
225#define HV_X64_MSR_SINT14 0x4000009E
226#define HV_X64_MSR_SINT15 0x4000009F
227
K. Y. Srinivasan4061ed92015-01-09 23:54:32 -0800228/*
229 * Synthetic Timer MSRs. Four timers per vcpu.
230 */
231#define HV_X64_MSR_STIMER0_CONFIG 0x400000B0
232#define HV_X64_MSR_STIMER0_COUNT 0x400000B1
233#define HV_X64_MSR_STIMER1_CONFIG 0x400000B2
234#define HV_X64_MSR_STIMER1_COUNT 0x400000B3
235#define HV_X64_MSR_STIMER2_CONFIG 0x400000B4
236#define HV_X64_MSR_STIMER2_COUNT 0x400000B5
237#define HV_X64_MSR_STIMER3_CONFIG 0x400000B6
238#define HV_X64_MSR_STIMER3_COUNT 0x400000B7
Gleb Natapov1d5103c2010-01-17 15:51:21 +0200239
Andrey Smetanina88464a2015-07-02 19:07:46 +0300240/* Hyper-V guest crash notification MSR's */
241#define HV_X64_MSR_CRASH_P0 0x40000100
242#define HV_X64_MSR_CRASH_P1 0x40000101
243#define HV_X64_MSR_CRASH_P2 0x40000102
244#define HV_X64_MSR_CRASH_P3 0x40000103
245#define HV_X64_MSR_CRASH_P4 0x40000104
246#define HV_X64_MSR_CRASH_CTL 0x40000105
247#define HV_X64_MSR_CRASH_CTL_NOTIFY (1ULL << 63)
248#define HV_X64_MSR_CRASH_PARAMS \
249 (1 + (HV_X64_MSR_CRASH_P4 - HV_X64_MSR_CRASH_P0))
250
Vitaly Kuznetsov415bd1c2018-03-20 15:02:06 +0100251/*
252 * Declare the MSR used to setup pages used to communicate with the hypervisor.
253 */
254union hv_x64_msr_hypercall_contents {
255 u64 as_uint64;
256 struct {
257 u64 enable:1;
258 u64 reserved:11;
259 u64 guest_physical_address:52;
260 };
261};
262
263/*
264 * TSC page layout.
265 */
266struct ms_hyperv_tsc_page {
267 volatile u32 tsc_sequence;
268 u32 reserved1;
269 volatile u64 tsc_scale;
270 volatile s64 tsc_offset;
271 u64 reserved2[509];
272};
273
274/*
275 * The guest OS needs to register the guest ID with the hypervisor.
276 * The guest ID is a 64 bit entity and the structure of this ID is
277 * specified in the Hyper-V specification:
278 *
279 * msdn.microsoft.com/en-us/library/windows/hardware/ff542653%28v=vs.85%29.aspx
280 *
281 * While the current guideline does not specify how Linux guest ID(s)
282 * need to be generated, our plan is to publish the guidelines for
283 * Linux and other guest operating systems that currently are hosted
284 * on Hyper-V. The implementation here conforms to this yet
285 * unpublished guidelines.
286 *
287 *
288 * Bit(s)
289 * 63 - Indicates if the OS is Open Source or not; 1 is Open Source
290 * 62:56 - Os Type; Linux is 0x100
291 * 55:48 - Distro specific identification
292 * 47:16 - Linux kernel version number
293 * 15:0 - Distro specific identification
294 *
295 *
296 */
297
298#define HV_LINUX_VENDOR_ID 0x8100
299
Vitaly Kuznetsov93286262018-01-24 14:23:33 +0100300/* TSC emulation after migration */
301#define HV_X64_MSR_REENLIGHTENMENT_CONTROL 0x40000106
302
303struct hv_reenlightenment_control {
KarimAllah Ahmed89426642018-02-20 08:39:51 +0100304 __u64 vector:8;
305 __u64 reserved1:8;
306 __u64 enabled:1;
307 __u64 reserved2:15;
308 __u64 target_vp:32;
Vitaly Kuznetsov93286262018-01-24 14:23:33 +0100309};
310
311#define HV_X64_MSR_TSC_EMULATION_CONTROL 0x40000107
312#define HV_X64_MSR_TSC_EMULATION_STATUS 0x40000108
313
314struct hv_tsc_emulation_control {
KarimAllah Ahmed89426642018-02-20 08:39:51 +0100315 __u64 enabled:1;
316 __u64 reserved:63;
Vitaly Kuznetsov93286262018-01-24 14:23:33 +0100317};
318
319struct hv_tsc_emulation_status {
KarimAllah Ahmed89426642018-02-20 08:39:51 +0100320 __u64 inprogress:1;
321 __u64 reserved:63;
Vitaly Kuznetsov93286262018-01-24 14:23:33 +0100322};
323
Gleb Natapov1d5103c2010-01-17 15:51:21 +0200324#define HV_X64_MSR_HYPERCALL_ENABLE 0x00000001
325#define HV_X64_MSR_HYPERCALL_PAGE_ADDRESS_SHIFT 12
326#define HV_X64_MSR_HYPERCALL_PAGE_ADDRESS_MASK \
327 (~((1ull << HV_X64_MSR_HYPERCALL_PAGE_ADDRESS_SHIFT) - 1))
328
329/* Declare the various hypercall operations. */
Vitaly Kuznetsov2ffd9e32017-08-02 18:09:19 +0200330#define HVCALL_FLUSH_VIRTUAL_ADDRESS_SPACE 0x0002
331#define HVCALL_FLUSH_VIRTUAL_ADDRESS_LIST 0x0003
Andrey Smetanin8ed6d762016-02-11 16:44:57 +0300332#define HVCALL_NOTIFY_LONG_SPIN_WAIT 0x0008
Vitaly Kuznetsov628f54c2017-08-02 18:09:20 +0200333#define HVCALL_FLUSH_VIRTUAL_ADDRESS_SPACE_EX 0x0013
334#define HVCALL_FLUSH_VIRTUAL_ADDRESS_LIST_EX 0x0014
Andrey Smetanin18f09862016-02-11 16:44:58 +0300335#define HVCALL_POST_MESSAGE 0x005c
336#define HVCALL_SIGNAL_EVENT 0x005d
Gleb Natapov1d5103c2010-01-17 15:51:21 +0200337
Ladi Prosekd4abc572018-03-20 15:02:07 +0100338#define HV_X64_MSR_VP_ASSIST_PAGE_ENABLE 0x00000001
339#define HV_X64_MSR_VP_ASSIST_PAGE_ADDRESS_SHIFT 12
340#define HV_X64_MSR_VP_ASSIST_PAGE_ADDRESS_MASK \
341 (~((1ull << HV_X64_MSR_VP_ASSIST_PAGE_ADDRESS_SHIFT) - 1))
Gleb Natapov1d5103c2010-01-17 15:51:21 +0200342
Vitaly Kuznetsov5431390b2018-03-20 15:02:10 +0100343/* Hyper-V Enlightened VMCS version mask in nested features CPUID */
344#define HV_X64_ENLIGHTENED_VMCS_VERSION 0xff
345
Vadim Rozenfelde9840972014-01-16 20:18:37 +1100346#define HV_X64_MSR_TSC_REFERENCE_ENABLE 0x00000001
347#define HV_X64_MSR_TSC_REFERENCE_ADDRESS_SHIFT 12
348
Gleb Natapov1d5103c2010-01-17 15:51:21 +0200349#define HV_PROCESSOR_POWER_STATE_C0 0
350#define HV_PROCESSOR_POWER_STATE_C1 1
351#define HV_PROCESSOR_POWER_STATE_C2 2
352#define HV_PROCESSOR_POWER_STATE_C3 3
353
Vitaly Kuznetsov2ffd9e32017-08-02 18:09:19 +0200354#define HV_FLUSH_ALL_PROCESSORS BIT(0)
355#define HV_FLUSH_ALL_VIRTUAL_ADDRESS_SPACES BIT(1)
356#define HV_FLUSH_NON_GLOBAL_MAPPINGS_ONLY BIT(2)
357#define HV_FLUSH_USE_EXTENDED_RANGE_FORMAT BIT(3)
358
Vitaly Kuznetsov628f54c2017-08-02 18:09:20 +0200359enum HV_GENERIC_SET_FORMAT {
360 HV_GENERIC_SET_SPARCE_4K,
361 HV_GENERIC_SET_ALL,
362};
363
Vitaly Kuznetsov415bd1c2018-03-20 15:02:06 +0100364#define HV_HYPERCALL_RESULT_MASK GENMASK_ULL(15, 0)
365#define HV_HYPERCALL_FAST_BIT BIT(16)
366#define HV_HYPERCALL_VARHEAD_OFFSET 17
367#define HV_HYPERCALL_REP_COMP_OFFSET 32
368#define HV_HYPERCALL_REP_COMP_MASK GENMASK_ULL(43, 32)
369#define HV_HYPERCALL_REP_START_OFFSET 48
370#define HV_HYPERCALL_REP_START_MASK GENMASK_ULL(59, 48)
371
Gleb Natapov1d5103c2010-01-17 15:51:21 +0200372/* hypercall status code */
373#define HV_STATUS_SUCCESS 0
374#define HV_STATUS_INVALID_HYPERCALL_CODE 2
375#define HV_STATUS_INVALID_HYPERCALL_INPUT 3
376#define HV_STATUS_INVALID_ALIGNMENT 4
Roman Kaganfaeb7832018-02-01 16:48:32 +0300377#define HV_STATUS_INVALID_PARAMETER 5
Dexuan Cui89f9f672015-02-27 11:25:59 -0800378#define HV_STATUS_INSUFFICIENT_MEMORY 11
Roman Kaganfaeb7832018-02-01 16:48:32 +0300379#define HV_STATUS_INVALID_PORT_ID 17
Dexuan Cui89f9f672015-02-27 11:25:59 -0800380#define HV_STATUS_INVALID_CONNECTION_ID 18
K. Y. Srinivasan5289d3d2011-08-25 09:49:01 -0700381#define HV_STATUS_INSUFFICIENT_BUFFERS 19
Gleb Natapov1d5103c2010-01-17 15:51:21 +0200382
Vadim Rozenfelde9840972014-01-16 20:18:37 +1100383typedef struct _HV_REFERENCE_TSC_PAGE {
384 __u32 tsc_sequence;
385 __u32 res1;
386 __u64 tsc_scale;
387 __s64 tsc_offset;
388} HV_REFERENCE_TSC_PAGE, *PHV_REFERENCE_TSC_PAGE;
389
Andrey Smetaninc75efa92015-10-16 10:07:50 +0300390/* Define the number of synthetic interrupt sources. */
391#define HV_SYNIC_SINT_COUNT (16)
392/* Define the expected SynIC version. */
393#define HV_SYNIC_VERSION_1 (0x1)
Vitaly Kuznetsov98f65ad2018-03-01 15:15:13 +0100394/* Valid SynIC vectors are 16-255. */
395#define HV_SYNIC_FIRST_VALID_VECTOR (16)
Andrey Smetaninc75efa92015-10-16 10:07:50 +0300396
397#define HV_SYNIC_CONTROL_ENABLE (1ULL << 0)
398#define HV_SYNIC_SIMP_ENABLE (1ULL << 0)
399#define HV_SYNIC_SIEFP_ENABLE (1ULL << 0)
400#define HV_SYNIC_SINT_MASKED (1ULL << 16)
401#define HV_SYNIC_SINT_AUTO_EOI (1ULL << 17)
402#define HV_SYNIC_SINT_VECTOR_MASK (0xFF)
403
Andrey Smetanin4f39bcf2015-11-30 19:22:14 +0300404#define HV_SYNIC_STIMER_COUNT (4)
405
Andrey Smetanin5b423ef2015-11-30 19:22:15 +0300406/* Define synthetic interrupt controller message constants. */
407#define HV_MESSAGE_SIZE (256)
408#define HV_MESSAGE_PAYLOAD_BYTE_COUNT (240)
409#define HV_MESSAGE_PAYLOAD_QWORD_COUNT (30)
410
411/* Define hypervisor message types. */
412enum hv_message_type {
413 HVMSG_NONE = 0x00000000,
414
415 /* Memory access messages. */
416 HVMSG_UNMAPPED_GPA = 0x80000000,
417 HVMSG_GPA_INTERCEPT = 0x80000001,
418
419 /* Timer notification messages. */
420 HVMSG_TIMER_EXPIRED = 0x80000010,
421
422 /* Error messages. */
423 HVMSG_INVALID_VP_REGISTER_VALUE = 0x80000020,
424 HVMSG_UNRECOVERABLE_EXCEPTION = 0x80000021,
425 HVMSG_UNSUPPORTED_FEATURE = 0x80000022,
426
427 /* Trace buffer complete messages. */
428 HVMSG_EVENTLOG_BUFFERCOMPLETE = 0x80000040,
429
430 /* Platform-specific processor intercept messages. */
431 HVMSG_X64_IOPORT_INTERCEPT = 0x80010000,
432 HVMSG_X64_MSR_INTERCEPT = 0x80010001,
433 HVMSG_X64_CPUID_INTERCEPT = 0x80010002,
434 HVMSG_X64_EXCEPTION_INTERCEPT = 0x80010003,
435 HVMSG_X64_APIC_EOI = 0x80010004,
436 HVMSG_X64_LEGACY_FP_ERROR = 0x80010005
437};
438
439/* Define synthetic interrupt controller message flags. */
440union hv_message_flags {
441 __u8 asu8;
442 struct {
443 __u8 msg_pending:1;
444 __u8 reserved:7;
445 };
446};
447
448/* Define port identifier type. */
449union hv_port_id {
450 __u32 asu32;
451 struct {
452 __u32 id:24;
453 __u32 reserved:8;
454 } u;
455};
456
457/* Define synthetic interrupt controller message header. */
458struct hv_message_header {
459 __u32 message_type;
460 __u8 payload_size;
461 union hv_message_flags message_flags;
462 __u8 reserved[2];
463 union {
464 __u64 sender;
465 union hv_port_id port;
466 };
467};
468
469/* Define synthetic interrupt controller message format. */
470struct hv_message {
471 struct hv_message_header header;
472 union {
473 __u64 payload[HV_MESSAGE_PAYLOAD_QWORD_COUNT];
474 } u;
475};
476
477/* Define the synthetic interrupt message page layout. */
478struct hv_message_page {
479 struct hv_message sint_message[HV_SYNIC_SINT_COUNT];
480};
481
Andrey Smetaninc71acc42015-11-30 19:22:16 +0300482/* Define timer message payload structure. */
483struct hv_timer_message_payload {
484 __u32 timer_index;
485 __u32 reserved;
486 __u64 expiration_time; /* When the timer expired */
487 __u64 delivery_time; /* When the message was delivered */
488};
489
Vitaly Kuznetsova46d15c2018-03-20 15:02:08 +0100490/* Define virtual processor assist page structure. */
491struct hv_vp_assist_page {
492 __u32 apic_assist;
493 __u32 reserved;
494 __u64 vtl_control[2];
495 __u64 nested_enlightenments_control[2];
496 __u32 enlighten_vmentry;
497 __u64 current_nested_vmcs;
498};
499
Vitaly Kuznetsov68d1eb72018-03-20 15:02:09 +0100500struct hv_enlightened_vmcs {
501 u32 revision_id;
502 u32 abort;
503
504 u16 host_es_selector;
505 u16 host_cs_selector;
506 u16 host_ss_selector;
507 u16 host_ds_selector;
508 u16 host_fs_selector;
509 u16 host_gs_selector;
510 u16 host_tr_selector;
511
512 u64 host_ia32_pat;
513 u64 host_ia32_efer;
514
515 u64 host_cr0;
516 u64 host_cr3;
517 u64 host_cr4;
518
519 u64 host_ia32_sysenter_esp;
520 u64 host_ia32_sysenter_eip;
521 u64 host_rip;
522 u32 host_ia32_sysenter_cs;
523
524 u32 pin_based_vm_exec_control;
525 u32 vm_exit_controls;
526 u32 secondary_vm_exec_control;
527
528 u64 io_bitmap_a;
529 u64 io_bitmap_b;
530 u64 msr_bitmap;
531
532 u16 guest_es_selector;
533 u16 guest_cs_selector;
534 u16 guest_ss_selector;
535 u16 guest_ds_selector;
536 u16 guest_fs_selector;
537 u16 guest_gs_selector;
538 u16 guest_ldtr_selector;
539 u16 guest_tr_selector;
540
541 u32 guest_es_limit;
542 u32 guest_cs_limit;
543 u32 guest_ss_limit;
544 u32 guest_ds_limit;
545 u32 guest_fs_limit;
546 u32 guest_gs_limit;
547 u32 guest_ldtr_limit;
548 u32 guest_tr_limit;
549 u32 guest_gdtr_limit;
550 u32 guest_idtr_limit;
551
552 u32 guest_es_ar_bytes;
553 u32 guest_cs_ar_bytes;
554 u32 guest_ss_ar_bytes;
555 u32 guest_ds_ar_bytes;
556 u32 guest_fs_ar_bytes;
557 u32 guest_gs_ar_bytes;
558 u32 guest_ldtr_ar_bytes;
559 u32 guest_tr_ar_bytes;
560
561 u64 guest_es_base;
562 u64 guest_cs_base;
563 u64 guest_ss_base;
564 u64 guest_ds_base;
565 u64 guest_fs_base;
566 u64 guest_gs_base;
567 u64 guest_ldtr_base;
568 u64 guest_tr_base;
569 u64 guest_gdtr_base;
570 u64 guest_idtr_base;
571
572 u64 padding64_1[3];
573
574 u64 vm_exit_msr_store_addr;
575 u64 vm_exit_msr_load_addr;
576 u64 vm_entry_msr_load_addr;
577
578 u64 cr3_target_value0;
579 u64 cr3_target_value1;
580 u64 cr3_target_value2;
581 u64 cr3_target_value3;
582
583 u32 page_fault_error_code_mask;
584 u32 page_fault_error_code_match;
585
586 u32 cr3_target_count;
587 u32 vm_exit_msr_store_count;
588 u32 vm_exit_msr_load_count;
589 u32 vm_entry_msr_load_count;
590
591 u64 tsc_offset;
592 u64 virtual_apic_page_addr;
593 u64 vmcs_link_pointer;
594
595 u64 guest_ia32_debugctl;
596 u64 guest_ia32_pat;
597 u64 guest_ia32_efer;
598
599 u64 guest_pdptr0;
600 u64 guest_pdptr1;
601 u64 guest_pdptr2;
602 u64 guest_pdptr3;
603
604 u64 guest_pending_dbg_exceptions;
605 u64 guest_sysenter_esp;
606 u64 guest_sysenter_eip;
607
608 u32 guest_activity_state;
609 u32 guest_sysenter_cs;
610
611 u64 cr0_guest_host_mask;
612 u64 cr4_guest_host_mask;
613 u64 cr0_read_shadow;
614 u64 cr4_read_shadow;
615 u64 guest_cr0;
616 u64 guest_cr3;
617 u64 guest_cr4;
618 u64 guest_dr7;
619
620 u64 host_fs_base;
621 u64 host_gs_base;
622 u64 host_tr_base;
623 u64 host_gdtr_base;
624 u64 host_idtr_base;
625 u64 host_rsp;
626
627 u64 ept_pointer;
628
629 u16 virtual_processor_id;
630 u16 padding16[3];
631
632 u64 padding64_2[5];
633 u64 guest_physical_address;
634
635 u32 vm_instruction_error;
636 u32 vm_exit_reason;
637 u32 vm_exit_intr_info;
638 u32 vm_exit_intr_error_code;
639 u32 idt_vectoring_info_field;
640 u32 idt_vectoring_error_code;
641 u32 vm_exit_instruction_len;
642 u32 vmx_instruction_info;
643
644 u64 exit_qualification;
645 u64 exit_io_instruction_ecx;
646 u64 exit_io_instruction_esi;
647 u64 exit_io_instruction_edi;
648 u64 exit_io_instruction_eip;
649
650 u64 guest_linear_address;
651 u64 guest_rsp;
652 u64 guest_rflags;
653
654 u32 guest_interruptibility_info;
655 u32 cpu_based_vm_exec_control;
656 u32 exception_bitmap;
657 u32 vm_entry_controls;
658 u32 vm_entry_intr_info_field;
659 u32 vm_entry_exception_error_code;
660 u32 vm_entry_instruction_len;
661 u32 tpr_threshold;
662
663 u64 guest_rip;
664
665 u32 hv_clean_fields;
666 u32 hv_padding_32;
667 u32 hv_synthetic_controls;
668 u32 hv_enlightenments_control;
669 u32 hv_vp_id;
670
671 u64 hv_vm_id;
672 u64 partition_assist_page;
673 u64 padding64_4[4];
674 u64 guest_bndcfgs;
675 u64 padding64_5[7];
676 u64 xss_exit_bitmap;
677 u64 padding64_6[7];
678};
679
680#define HV_VMX_ENLIGHTENED_CLEAN_FIELD_NONE 0
681#define HV_VMX_ENLIGHTENED_CLEAN_FIELD_IO_BITMAP BIT(0)
682#define HV_VMX_ENLIGHTENED_CLEAN_FIELD_MSR_BITMAP BIT(1)
683#define HV_VMX_ENLIGHTENED_CLEAN_FIELD_CONTROL_GRP2 BIT(2)
684#define HV_VMX_ENLIGHTENED_CLEAN_FIELD_CONTROL_GRP1 BIT(3)
685#define HV_VMX_ENLIGHTENED_CLEAN_FIELD_CONTROL_PROC BIT(4)
686#define HV_VMX_ENLIGHTENED_CLEAN_FIELD_CONTROL_EVENT BIT(5)
687#define HV_VMX_ENLIGHTENED_CLEAN_FIELD_CONTROL_ENTRY BIT(6)
688#define HV_VMX_ENLIGHTENED_CLEAN_FIELD_CONTROL_EXCPN BIT(7)
689#define HV_VMX_ENLIGHTENED_CLEAN_FIELD_CRDR BIT(8)
690#define HV_VMX_ENLIGHTENED_CLEAN_FIELD_CONTROL_XLAT BIT(9)
691#define HV_VMX_ENLIGHTENED_CLEAN_FIELD_GUEST_BASIC BIT(10)
692#define HV_VMX_ENLIGHTENED_CLEAN_FIELD_GUEST_GRP1 BIT(11)
693#define HV_VMX_ENLIGHTENED_CLEAN_FIELD_GUEST_GRP2 BIT(12)
694#define HV_VMX_ENLIGHTENED_CLEAN_FIELD_HOST_POINTER BIT(13)
695#define HV_VMX_ENLIGHTENED_CLEAN_FIELD_HOST_GRP1 BIT(14)
696#define HV_VMX_ENLIGHTENED_CLEAN_FIELD_ENLIGHTENMENTSCONTROL BIT(15)
697
698#define HV_VMX_ENLIGHTENED_CLEAN_FIELD_ALL 0xFFFF
699
Andrey Smetanin1f4b34f2015-11-30 19:22:21 +0300700#define HV_STIMER_ENABLE (1ULL << 0)
701#define HV_STIMER_PERIODIC (1ULL << 1)
702#define HV_STIMER_LAZY (1ULL << 2)
703#define HV_STIMER_AUTOENABLE (1ULL << 3)
704#define HV_STIMER_SINT(config) (__u8)(((config) >> 16) & 0x0F)
705
Gleb Natapov1d5103c2010-01-17 15:51:21 +0200706#endif