xref: /linux/tools/arch/x86/include/uapi/asm/kvm.h (revision 01abac26dccd77eddffec6b032e51f501714dee3)
1 /* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
2 #ifndef _ASM_X86_KVM_H
3 #define _ASM_X86_KVM_H
4 
5 /*
6  * KVM x86 specific structures and definitions
7  *
8  */
9 
10 #include <linux/const.h>
11 #include <linux/bits.h>
12 #include <linux/types.h>
13 #include <linux/ioctl.h>
14 #include <linux/stddef.h>
15 
16 #define KVM_PIO_PAGE_OFFSET 1
17 #define KVM_COALESCED_MMIO_PAGE_OFFSET 2
18 #define KVM_DIRTY_LOG_PAGE_OFFSET 64
19 
20 #define DE_VECTOR 0
21 #define DB_VECTOR 1
22 #define BP_VECTOR 3
23 #define OF_VECTOR 4
24 #define BR_VECTOR 5
25 #define UD_VECTOR 6
26 #define NM_VECTOR 7
27 #define DF_VECTOR 8
28 #define TS_VECTOR 10
29 #define NP_VECTOR 11
30 #define SS_VECTOR 12
31 #define GP_VECTOR 13
32 #define PF_VECTOR 14
33 #define MF_VECTOR 16
34 #define AC_VECTOR 17
35 #define MC_VECTOR 18
36 #define XM_VECTOR 19
37 #define VE_VECTOR 20
38 
39 /* Select x86 specific features in <linux/kvm.h> */
40 #define __KVM_HAVE_PIT
41 #define __KVM_HAVE_IOAPIC
42 #define __KVM_HAVE_IRQ_LINE
43 #define __KVM_HAVE_MSI
44 #define __KVM_HAVE_USER_NMI
45 #define __KVM_HAVE_MSIX
46 #define __KVM_HAVE_MCE
47 #define __KVM_HAVE_PIT_STATE2
48 #define __KVM_HAVE_XEN_HVM
49 #define __KVM_HAVE_VCPU_EVENTS
50 #define __KVM_HAVE_DEBUGREGS
51 #define __KVM_HAVE_XSAVE
52 #define __KVM_HAVE_XCRS
53 
54 /* Architectural interrupt line count. */
55 #define KVM_NR_INTERRUPTS 256
56 
57 /* for KVM_GET_IRQCHIP and KVM_SET_IRQCHIP */
58 struct kvm_pic_state {
59 	__u8 last_irr;	/* edge detection */
60 	__u8 irr;		/* interrupt request register */
61 	__u8 imr;		/* interrupt mask register */
62 	__u8 isr;		/* interrupt service register */
63 	__u8 priority_add;	/* highest irq priority */
64 	__u8 irq_base;
65 	__u8 read_reg_select;
66 	__u8 poll;
67 	__u8 special_mask;
68 	__u8 init_state;
69 	__u8 auto_eoi;
70 	__u8 rotate_on_auto_eoi;
71 	__u8 special_fully_nested_mode;
72 	__u8 init4;		/* true if 4 byte init */
73 	__u8 elcr;		/* PIIX edge/trigger selection */
74 	__u8 elcr_mask;
75 };
76 
77 #define KVM_IOAPIC_NUM_PINS  24
78 struct kvm_ioapic_state {
79 	__u64 base_address;
80 	__u32 ioregsel;
81 	__u32 id;
82 	__u32 irr;
83 	__u32 pad;
84 	union {
85 		__u64 bits;
86 		struct {
87 			__u8 vector;
88 			__u8 delivery_mode:3;
89 			__u8 dest_mode:1;
90 			__u8 delivery_status:1;
91 			__u8 polarity:1;
92 			__u8 remote_irr:1;
93 			__u8 trig_mode:1;
94 			__u8 mask:1;
95 			__u8 reserve:7;
96 			__u8 reserved[4];
97 			__u8 dest_id;
98 		} fields;
99 	} redirtbl[KVM_IOAPIC_NUM_PINS];
100 };
101 
102 #define KVM_IRQCHIP_PIC_MASTER   0
103 #define KVM_IRQCHIP_PIC_SLAVE    1
104 #define KVM_IRQCHIP_IOAPIC       2
105 #define KVM_NR_IRQCHIPS          3
106 
107 #define KVM_RUN_X86_SMM		 (1 << 0)
108 #define KVM_RUN_X86_BUS_LOCK     (1 << 1)
109 #define KVM_RUN_X86_GUEST_MODE   (1 << 2)
110 
111 /* for KVM_GET_REGS and KVM_SET_REGS */
112 struct kvm_regs {
113 	/* out (KVM_GET_REGS) / in (KVM_SET_REGS) */
114 	__u64 rax, rbx, rcx, rdx;
115 	__u64 rsi, rdi, rsp, rbp;
116 	__u64 r8,  r9,  r10, r11;
117 	__u64 r12, r13, r14, r15;
118 	__u64 rip, rflags;
119 };
120 
121 /* for KVM_GET_LAPIC and KVM_SET_LAPIC */
122 #define KVM_APIC_REG_SIZE 0x400
123 struct kvm_lapic_state {
124 	char regs[KVM_APIC_REG_SIZE];
125 };
126 
127 struct kvm_segment {
128 	__u64 base;
129 	__u32 limit;
130 	__u16 selector;
131 	__u8  type;
132 	__u8  present, dpl, db, s, l, g, avl;
133 	__u8  unusable;
134 	__u8  padding;
135 };
136 
137 struct kvm_dtable {
138 	__u64 base;
139 	__u16 limit;
140 	__u16 padding[3];
141 };
142 
143 
144 /* for KVM_GET_SREGS and KVM_SET_SREGS */
145 struct kvm_sregs {
146 	/* out (KVM_GET_SREGS) / in (KVM_SET_SREGS) */
147 	struct kvm_segment cs, ds, es, fs, gs, ss;
148 	struct kvm_segment tr, ldt;
149 	struct kvm_dtable gdt, idt;
150 	__u64 cr0, cr2, cr3, cr4, cr8;
151 	__u64 efer;
152 	__u64 apic_base;
153 	__u64 interrupt_bitmap[(KVM_NR_INTERRUPTS + 63) / 64];
154 };
155 
156 struct kvm_sregs2 {
157 	/* out (KVM_GET_SREGS2) / in (KVM_SET_SREGS2) */
158 	struct kvm_segment cs, ds, es, fs, gs, ss;
159 	struct kvm_segment tr, ldt;
160 	struct kvm_dtable gdt, idt;
161 	__u64 cr0, cr2, cr3, cr4, cr8;
162 	__u64 efer;
163 	__u64 apic_base;
164 	__u64 flags;
165 	__u64 pdptrs[4];
166 };
167 #define KVM_SREGS2_FLAGS_PDPTRS_VALID 1
168 
169 /* for KVM_GET_FPU and KVM_SET_FPU */
170 struct kvm_fpu {
171 	__u8  fpr[8][16];
172 	__u16 fcw;
173 	__u16 fsw;
174 	__u8  ftwx;  /* in fxsave format */
175 	__u8  pad1;
176 	__u16 last_opcode;
177 	__u64 last_ip;
178 	__u64 last_dp;
179 	__u8  xmm[16][16];
180 	__u32 mxcsr;
181 	__u32 pad2;
182 };
183 
184 struct kvm_msr_entry {
185 	__u32 index;
186 	__u32 reserved;
187 	__u64 data;
188 };
189 
190 /* for KVM_GET_MSRS and KVM_SET_MSRS */
191 struct kvm_msrs {
192 	__u32 nmsrs; /* number of msrs in entries */
193 	__u32 pad;
194 
195 	struct kvm_msr_entry entries[];
196 };
197 
198 /* for KVM_GET_MSR_INDEX_LIST */
199 struct kvm_msr_list {
200 	__u32 nmsrs; /* number of msrs in entries */
201 	__u32 indices[];
202 };
203 
204 /* Maximum size of any access bitmap in bytes */
205 #define KVM_MSR_FILTER_MAX_BITMAP_SIZE 0x600
206 
207 /* for KVM_X86_SET_MSR_FILTER */
208 struct kvm_msr_filter_range {
209 #define KVM_MSR_FILTER_READ  (1 << 0)
210 #define KVM_MSR_FILTER_WRITE (1 << 1)
211 #define KVM_MSR_FILTER_RANGE_VALID_MASK (KVM_MSR_FILTER_READ | \
212 					 KVM_MSR_FILTER_WRITE)
213 	__u32 flags;
214 	__u32 nmsrs; /* number of msrs in bitmap */
215 	__u32 base;  /* MSR index the bitmap starts at */
216 	__u8 *bitmap; /* a 1 bit allows the operations in flags, 0 denies */
217 };
218 
219 #define KVM_MSR_FILTER_MAX_RANGES 16
220 struct kvm_msr_filter {
221 #ifndef __KERNEL__
222 #define KVM_MSR_FILTER_DEFAULT_ALLOW (0 << 0)
223 #endif
224 #define KVM_MSR_FILTER_DEFAULT_DENY  (1 << 0)
225 #define KVM_MSR_FILTER_VALID_MASK (KVM_MSR_FILTER_DEFAULT_DENY)
226 	__u32 flags;
227 	struct kvm_msr_filter_range ranges[KVM_MSR_FILTER_MAX_RANGES];
228 };
229 
230 struct kvm_cpuid_entry {
231 	__u32 function;
232 	__u32 eax;
233 	__u32 ebx;
234 	__u32 ecx;
235 	__u32 edx;
236 	__u32 padding;
237 };
238 
239 /* for KVM_SET_CPUID */
240 struct kvm_cpuid {
241 	__u32 nent;
242 	__u32 padding;
243 	struct kvm_cpuid_entry entries[];
244 };
245 
246 struct kvm_cpuid_entry2 {
247 	__u32 function;
248 	__u32 index;
249 	__u32 flags;
250 	__u32 eax;
251 	__u32 ebx;
252 	__u32 ecx;
253 	__u32 edx;
254 	__u32 padding[3];
255 };
256 
257 #define KVM_CPUID_FLAG_SIGNIFCANT_INDEX		(1 << 0)
258 #define KVM_CPUID_FLAG_STATEFUL_FUNC		(1 << 1)
259 #define KVM_CPUID_FLAG_STATE_READ_NEXT		(1 << 2)
260 
261 /* for KVM_SET_CPUID2 */
262 struct kvm_cpuid2 {
263 	__u32 nent;
264 	__u32 padding;
265 	struct kvm_cpuid_entry2 entries[];
266 };
267 
268 /* for KVM_GET_PIT and KVM_SET_PIT */
269 struct kvm_pit_channel_state {
270 	__u32 count; /* can be 65536 */
271 	__u16 latched_count;
272 	__u8 count_latched;
273 	__u8 status_latched;
274 	__u8 status;
275 	__u8 read_state;
276 	__u8 write_state;
277 	__u8 write_latch;
278 	__u8 rw_mode;
279 	__u8 mode;
280 	__u8 bcd;
281 	__u8 gate;
282 	__s64 count_load_time;
283 };
284 
285 struct kvm_debug_exit_arch {
286 	__u32 exception;
287 	__u32 pad;
288 	__u64 pc;
289 	__u64 dr6;
290 	__u64 dr7;
291 };
292 
293 #define KVM_GUESTDBG_USE_SW_BP		0x00010000
294 #define KVM_GUESTDBG_USE_HW_BP		0x00020000
295 #define KVM_GUESTDBG_INJECT_DB		0x00040000
296 #define KVM_GUESTDBG_INJECT_BP		0x00080000
297 #define KVM_GUESTDBG_BLOCKIRQ		0x00100000
298 
299 /* for KVM_SET_GUEST_DEBUG */
300 struct kvm_guest_debug_arch {
301 	__u64 debugreg[8];
302 };
303 
304 struct kvm_pit_state {
305 	struct kvm_pit_channel_state channels[3];
306 };
307 
308 #define KVM_PIT_FLAGS_HPET_LEGACY     0x00000001
309 #define KVM_PIT_FLAGS_SPEAKER_DATA_ON 0x00000002
310 
311 struct kvm_pit_state2 {
312 	struct kvm_pit_channel_state channels[3];
313 	__u32 flags;
314 	__u32 reserved[9];
315 };
316 
317 struct kvm_reinject_control {
318 	__u8 pit_reinject;
319 	__u8 reserved[31];
320 };
321 
322 /* When set in flags, include corresponding fields on KVM_SET_VCPU_EVENTS */
323 #define KVM_VCPUEVENT_VALID_NMI_PENDING	0x00000001
324 #define KVM_VCPUEVENT_VALID_SIPI_VECTOR	0x00000002
325 #define KVM_VCPUEVENT_VALID_SHADOW	0x00000004
326 #define KVM_VCPUEVENT_VALID_SMM		0x00000008
327 #define KVM_VCPUEVENT_VALID_PAYLOAD	0x00000010
328 #define KVM_VCPUEVENT_VALID_TRIPLE_FAULT	0x00000020
329 
330 /* Interrupt shadow states */
331 #define KVM_X86_SHADOW_INT_MOV_SS	0x01
332 #define KVM_X86_SHADOW_INT_STI		0x02
333 
334 /* for KVM_GET/SET_VCPU_EVENTS */
335 struct kvm_vcpu_events {
336 	struct {
337 		__u8 injected;
338 		__u8 nr;
339 		__u8 has_error_code;
340 		__u8 pending;
341 		__u32 error_code;
342 	} exception;
343 	struct {
344 		__u8 injected;
345 		__u8 nr;
346 		__u8 soft;
347 		__u8 shadow;
348 	} interrupt;
349 	struct {
350 		__u8 injected;
351 		__u8 pending;
352 		__u8 masked;
353 		__u8 pad;
354 	} nmi;
355 	__u32 sipi_vector;
356 	__u32 flags;
357 	struct {
358 		__u8 smm;
359 		__u8 pending;
360 		__u8 smm_inside_nmi;
361 		__u8 latched_init;
362 	} smi;
363 	struct {
364 		__u8 pending;
365 	} triple_fault;
366 	__u8 reserved[26];
367 	__u8 exception_has_payload;
368 	__u64 exception_payload;
369 };
370 
371 /* for KVM_GET/SET_DEBUGREGS */
372 struct kvm_debugregs {
373 	__u64 db[4];
374 	__u64 dr6;
375 	__u64 dr7;
376 	__u64 flags;
377 	__u64 reserved[9];
378 };
379 
380 /* for KVM_CAP_XSAVE and KVM_CAP_XSAVE2 */
381 struct kvm_xsave {
382 	/*
383 	 * KVM_GET_XSAVE2 and KVM_SET_XSAVE write and read as many bytes
384 	 * as are returned by KVM_CHECK_EXTENSION(KVM_CAP_XSAVE2)
385 	 * respectively, when invoked on the vm file descriptor.
386 	 *
387 	 * The size value returned by KVM_CHECK_EXTENSION(KVM_CAP_XSAVE2)
388 	 * will always be at least 4096. Currently, it is only greater
389 	 * than 4096 if a dynamic feature has been enabled with
390 	 * ``arch_prctl()``, but this may change in the future.
391 	 *
392 	 * The offsets of the state save areas in struct kvm_xsave follow
393 	 * the contents of CPUID leaf 0xD on the host.
394 	 */
395 	__u32 region[1024];
396 	__u32 extra[];
397 };
398 
399 #define KVM_MAX_XCRS	16
400 
401 struct kvm_xcr {
402 	__u32 xcr;
403 	__u32 reserved;
404 	__u64 value;
405 };
406 
407 struct kvm_xcrs {
408 	__u32 nr_xcrs;
409 	__u32 flags;
410 	struct kvm_xcr xcrs[KVM_MAX_XCRS];
411 	__u64 padding[16];
412 };
413 
414 #define KVM_SYNC_X86_REGS      (1UL << 0)
415 #define KVM_SYNC_X86_SREGS     (1UL << 1)
416 #define KVM_SYNC_X86_EVENTS    (1UL << 2)
417 
418 #define KVM_SYNC_X86_VALID_FIELDS \
419 	(KVM_SYNC_X86_REGS| \
420 	 KVM_SYNC_X86_SREGS| \
421 	 KVM_SYNC_X86_EVENTS)
422 
423 /* kvm_sync_regs struct included by kvm_run struct */
424 struct kvm_sync_regs {
425 	/* Members of this structure are potentially malicious.
426 	 * Care must be taken by code reading, esp. interpreting,
427 	 * data fields from them inside KVM to prevent TOCTOU and
428 	 * double-fetch types of vulnerabilities.
429 	 */
430 	struct kvm_regs regs;
431 	struct kvm_sregs sregs;
432 	struct kvm_vcpu_events events;
433 };
434 
435 #define KVM_X86_QUIRK_LINT0_REENABLED		(1 << 0)
436 #define KVM_X86_QUIRK_CD_NW_CLEARED		(1 << 1)
437 #define KVM_X86_QUIRK_LAPIC_MMIO_HOLE		(1 << 2)
438 #define KVM_X86_QUIRK_OUT_7E_INC_RIP		(1 << 3)
439 #define KVM_X86_QUIRK_MISC_ENABLE_NO_MWAIT	(1 << 4)
440 #define KVM_X86_QUIRK_FIX_HYPERCALL_INSN	(1 << 5)
441 #define KVM_X86_QUIRK_MWAIT_NEVER_UD_FAULTS	(1 << 6)
442 #define KVM_X86_QUIRK_SLOT_ZAP_ALL		(1 << 7)
443 #define KVM_X86_QUIRK_STUFF_FEATURE_MSRS	(1 << 8)
444 
445 #define KVM_STATE_NESTED_FORMAT_VMX	0
446 #define KVM_STATE_NESTED_FORMAT_SVM	1
447 
448 #define KVM_STATE_NESTED_GUEST_MODE	0x00000001
449 #define KVM_STATE_NESTED_RUN_PENDING	0x00000002
450 #define KVM_STATE_NESTED_EVMCS		0x00000004
451 #define KVM_STATE_NESTED_MTF_PENDING	0x00000008
452 #define KVM_STATE_NESTED_GIF_SET	0x00000100
453 
454 #define KVM_STATE_NESTED_SMM_GUEST_MODE	0x00000001
455 #define KVM_STATE_NESTED_SMM_VMXON	0x00000002
456 
457 #define KVM_STATE_NESTED_VMX_VMCS_SIZE	0x1000
458 
459 #define KVM_STATE_NESTED_SVM_VMCB_SIZE	0x1000
460 
461 #define KVM_STATE_VMX_PREEMPTION_TIMER_DEADLINE	0x00000001
462 
463 /* vendor-independent attributes for system fd (group 0) */
464 #define KVM_X86_GRP_SYSTEM		0
465 #  define KVM_X86_XCOMP_GUEST_SUPP	0
466 
467 /* vendor-specific groups and attributes for system fd */
468 #define KVM_X86_GRP_SEV			1
469 #  define KVM_X86_SEV_VMSA_FEATURES	0
470 
471 struct kvm_vmx_nested_state_data {
472 	__u8 vmcs12[KVM_STATE_NESTED_VMX_VMCS_SIZE];
473 	__u8 shadow_vmcs12[KVM_STATE_NESTED_VMX_VMCS_SIZE];
474 };
475 
476 struct kvm_vmx_nested_state_hdr {
477 	__u64 vmxon_pa;
478 	__u64 vmcs12_pa;
479 
480 	struct {
481 		__u16 flags;
482 	} smm;
483 
484 	__u16 pad;
485 
486 	__u32 flags;
487 	__u64 preemption_timer_deadline;
488 };
489 
490 struct kvm_svm_nested_state_data {
491 	/* Save area only used if KVM_STATE_NESTED_RUN_PENDING.  */
492 	__u8 vmcb12[KVM_STATE_NESTED_SVM_VMCB_SIZE];
493 };
494 
495 struct kvm_svm_nested_state_hdr {
496 	__u64 vmcb_pa;
497 };
498 
499 /* for KVM_CAP_NESTED_STATE */
500 struct kvm_nested_state {
501 	__u16 flags;
502 	__u16 format;
503 	__u32 size;
504 
505 	union {
506 		struct kvm_vmx_nested_state_hdr vmx;
507 		struct kvm_svm_nested_state_hdr svm;
508 
509 		/* Pad the header to 128 bytes.  */
510 		__u8 pad[120];
511 	} hdr;
512 
513 	/*
514 	 * Define data region as 0 bytes to preserve backwards-compatability
515 	 * to old definition of kvm_nested_state in order to avoid changing
516 	 * KVM_{GET,PUT}_NESTED_STATE ioctl values.
517 	 */
518 	union {
519 		__DECLARE_FLEX_ARRAY(struct kvm_vmx_nested_state_data, vmx);
520 		__DECLARE_FLEX_ARRAY(struct kvm_svm_nested_state_data, svm);
521 	} data;
522 };
523 
524 /* for KVM_CAP_PMU_EVENT_FILTER */
525 struct kvm_pmu_event_filter {
526 	__u32 action;
527 	__u32 nevents;
528 	__u32 fixed_counter_bitmap;
529 	__u32 flags;
530 	__u32 pad[4];
531 	__u64 events[];
532 };
533 
534 #define KVM_PMU_EVENT_ALLOW 0
535 #define KVM_PMU_EVENT_DENY 1
536 
537 #define KVM_PMU_EVENT_FLAG_MASKED_EVENTS _BITUL(0)
538 #define KVM_PMU_EVENT_FLAGS_VALID_MASK (KVM_PMU_EVENT_FLAG_MASKED_EVENTS)
539 
540 /* for KVM_CAP_MCE */
541 struct kvm_x86_mce {
542 	__u64 status;
543 	__u64 addr;
544 	__u64 misc;
545 	__u64 mcg_status;
546 	__u8 bank;
547 	__u8 pad1[7];
548 	__u64 pad2[3];
549 };
550 
551 /* for KVM_CAP_XEN_HVM */
552 #define KVM_XEN_HVM_CONFIG_HYPERCALL_MSR	(1 << 0)
553 #define KVM_XEN_HVM_CONFIG_INTERCEPT_HCALL	(1 << 1)
554 #define KVM_XEN_HVM_CONFIG_SHARED_INFO		(1 << 2)
555 #define KVM_XEN_HVM_CONFIG_RUNSTATE		(1 << 3)
556 #define KVM_XEN_HVM_CONFIG_EVTCHN_2LEVEL	(1 << 4)
557 #define KVM_XEN_HVM_CONFIG_EVTCHN_SEND		(1 << 5)
558 #define KVM_XEN_HVM_CONFIG_RUNSTATE_UPDATE_FLAG	(1 << 6)
559 #define KVM_XEN_HVM_CONFIG_PVCLOCK_TSC_UNSTABLE	(1 << 7)
560 #define KVM_XEN_HVM_CONFIG_SHARED_INFO_HVA	(1 << 8)
561 
562 struct kvm_xen_hvm_config {
563 	__u32 flags;
564 	__u32 msr;
565 	__u64 blob_addr_32;
566 	__u64 blob_addr_64;
567 	__u8 blob_size_32;
568 	__u8 blob_size_64;
569 	__u8 pad2[30];
570 };
571 
572 struct kvm_xen_hvm_attr {
573 	__u16 type;
574 	__u16 pad[3];
575 	union {
576 		__u8 long_mode;
577 		__u8 vector;
578 		__u8 runstate_update_flag;
579 		union {
580 			__u64 gfn;
581 #define KVM_XEN_INVALID_GFN ((__u64)-1)
582 			__u64 hva;
583 		} shared_info;
584 		struct {
585 			__u32 send_port;
586 			__u32 type; /* EVTCHNSTAT_ipi / EVTCHNSTAT_interdomain */
587 			__u32 flags;
588 #define KVM_XEN_EVTCHN_DEASSIGN		(1 << 0)
589 #define KVM_XEN_EVTCHN_UPDATE		(1 << 1)
590 #define KVM_XEN_EVTCHN_RESET		(1 << 2)
591 			/*
592 			 * Events sent by the guest are either looped back to
593 			 * the guest itself (potentially on a different port#)
594 			 * or signalled via an eventfd.
595 			 */
596 			union {
597 				struct {
598 					__u32 port;
599 					__u32 vcpu;
600 					__u32 priority;
601 				} port;
602 				struct {
603 					__u32 port; /* Zero for eventfd */
604 					__s32 fd;
605 				} eventfd;
606 				__u32 padding[4];
607 			} deliver;
608 		} evtchn;
609 		__u32 xen_version;
610 		__u64 pad[8];
611 	} u;
612 };
613 
614 
615 /* Available with KVM_CAP_XEN_HVM / KVM_XEN_HVM_CONFIG_SHARED_INFO */
616 #define KVM_XEN_ATTR_TYPE_LONG_MODE		0x0
617 #define KVM_XEN_ATTR_TYPE_SHARED_INFO		0x1
618 #define KVM_XEN_ATTR_TYPE_UPCALL_VECTOR		0x2
619 /* Available with KVM_CAP_XEN_HVM / KVM_XEN_HVM_CONFIG_EVTCHN_SEND */
620 #define KVM_XEN_ATTR_TYPE_EVTCHN		0x3
621 #define KVM_XEN_ATTR_TYPE_XEN_VERSION		0x4
622 /* Available with KVM_CAP_XEN_HVM / KVM_XEN_HVM_CONFIG_RUNSTATE_UPDATE_FLAG */
623 #define KVM_XEN_ATTR_TYPE_RUNSTATE_UPDATE_FLAG	0x5
624 /* Available with KVM_CAP_XEN_HVM / KVM_XEN_HVM_CONFIG_SHARED_INFO_HVA */
625 #define KVM_XEN_ATTR_TYPE_SHARED_INFO_HVA	0x6
626 
627 struct kvm_xen_vcpu_attr {
628 	__u16 type;
629 	__u16 pad[3];
630 	union {
631 		__u64 gpa;
632 #define KVM_XEN_INVALID_GPA ((__u64)-1)
633 		__u64 hva;
634 		__u64 pad[8];
635 		struct {
636 			__u64 state;
637 			__u64 state_entry_time;
638 			__u64 time_running;
639 			__u64 time_runnable;
640 			__u64 time_blocked;
641 			__u64 time_offline;
642 		} runstate;
643 		__u32 vcpu_id;
644 		struct {
645 			__u32 port;
646 			__u32 priority;
647 			__u64 expires_ns;
648 		} timer;
649 		__u8 vector;
650 	} u;
651 };
652 
653 /* Available with KVM_CAP_XEN_HVM / KVM_XEN_HVM_CONFIG_SHARED_INFO */
654 #define KVM_XEN_VCPU_ATTR_TYPE_VCPU_INFO	0x0
655 #define KVM_XEN_VCPU_ATTR_TYPE_VCPU_TIME_INFO	0x1
656 #define KVM_XEN_VCPU_ATTR_TYPE_RUNSTATE_ADDR	0x2
657 #define KVM_XEN_VCPU_ATTR_TYPE_RUNSTATE_CURRENT	0x3
658 #define KVM_XEN_VCPU_ATTR_TYPE_RUNSTATE_DATA	0x4
659 #define KVM_XEN_VCPU_ATTR_TYPE_RUNSTATE_ADJUST	0x5
660 /* Available with KVM_CAP_XEN_HVM / KVM_XEN_HVM_CONFIG_EVTCHN_SEND */
661 #define KVM_XEN_VCPU_ATTR_TYPE_VCPU_ID		0x6
662 #define KVM_XEN_VCPU_ATTR_TYPE_TIMER		0x7
663 #define KVM_XEN_VCPU_ATTR_TYPE_UPCALL_VECTOR	0x8
664 /* Available with KVM_CAP_XEN_HVM / KVM_XEN_HVM_CONFIG_SHARED_INFO_HVA */
665 #define KVM_XEN_VCPU_ATTR_TYPE_VCPU_INFO_HVA	0x9
666 
667 /* Secure Encrypted Virtualization command */
668 enum sev_cmd_id {
669 	/* Guest initialization commands */
670 	KVM_SEV_INIT = 0,
671 	KVM_SEV_ES_INIT,
672 	/* Guest launch commands */
673 	KVM_SEV_LAUNCH_START,
674 	KVM_SEV_LAUNCH_UPDATE_DATA,
675 	KVM_SEV_LAUNCH_UPDATE_VMSA,
676 	KVM_SEV_LAUNCH_SECRET,
677 	KVM_SEV_LAUNCH_MEASURE,
678 	KVM_SEV_LAUNCH_FINISH,
679 	/* Guest migration commands (outgoing) */
680 	KVM_SEV_SEND_START,
681 	KVM_SEV_SEND_UPDATE_DATA,
682 	KVM_SEV_SEND_UPDATE_VMSA,
683 	KVM_SEV_SEND_FINISH,
684 	/* Guest migration commands (incoming) */
685 	KVM_SEV_RECEIVE_START,
686 	KVM_SEV_RECEIVE_UPDATE_DATA,
687 	KVM_SEV_RECEIVE_UPDATE_VMSA,
688 	KVM_SEV_RECEIVE_FINISH,
689 	/* Guest status and debug commands */
690 	KVM_SEV_GUEST_STATUS,
691 	KVM_SEV_DBG_DECRYPT,
692 	KVM_SEV_DBG_ENCRYPT,
693 	/* Guest certificates commands */
694 	KVM_SEV_CERT_EXPORT,
695 	/* Attestation report */
696 	KVM_SEV_GET_ATTESTATION_REPORT,
697 	/* Guest Migration Extension */
698 	KVM_SEV_SEND_CANCEL,
699 
700 	/* Second time is the charm; improved versions of the above ioctls.  */
701 	KVM_SEV_INIT2,
702 
703 	/* SNP-specific commands */
704 	KVM_SEV_SNP_LAUNCH_START = 100,
705 	KVM_SEV_SNP_LAUNCH_UPDATE,
706 	KVM_SEV_SNP_LAUNCH_FINISH,
707 
708 	KVM_SEV_NR_MAX,
709 };
710 
711 struct kvm_sev_cmd {
712 	__u32 id;
713 	__u32 pad0;
714 	__u64 data;
715 	__u32 error;
716 	__u32 sev_fd;
717 };
718 
719 struct kvm_sev_init {
720 	__u64 vmsa_features;
721 	__u32 flags;
722 	__u16 ghcb_version;
723 	__u16 pad1;
724 	__u32 pad2[8];
725 };
726 
727 struct kvm_sev_launch_start {
728 	__u32 handle;
729 	__u32 policy;
730 	__u64 dh_uaddr;
731 	__u32 dh_len;
732 	__u32 pad0;
733 	__u64 session_uaddr;
734 	__u32 session_len;
735 	__u32 pad1;
736 };
737 
738 struct kvm_sev_launch_update_data {
739 	__u64 uaddr;
740 	__u32 len;
741 	__u32 pad0;
742 };
743 
744 
745 struct kvm_sev_launch_secret {
746 	__u64 hdr_uaddr;
747 	__u32 hdr_len;
748 	__u32 pad0;
749 	__u64 guest_uaddr;
750 	__u32 guest_len;
751 	__u32 pad1;
752 	__u64 trans_uaddr;
753 	__u32 trans_len;
754 	__u32 pad2;
755 };
756 
757 struct kvm_sev_launch_measure {
758 	__u64 uaddr;
759 	__u32 len;
760 	__u32 pad0;
761 };
762 
763 struct kvm_sev_guest_status {
764 	__u32 handle;
765 	__u32 policy;
766 	__u32 state;
767 };
768 
769 struct kvm_sev_dbg {
770 	__u64 src_uaddr;
771 	__u64 dst_uaddr;
772 	__u32 len;
773 	__u32 pad0;
774 };
775 
776 struct kvm_sev_attestation_report {
777 	__u8 mnonce[16];
778 	__u64 uaddr;
779 	__u32 len;
780 	__u32 pad0;
781 };
782 
783 struct kvm_sev_send_start {
784 	__u32 policy;
785 	__u32 pad0;
786 	__u64 pdh_cert_uaddr;
787 	__u32 pdh_cert_len;
788 	__u32 pad1;
789 	__u64 plat_certs_uaddr;
790 	__u32 plat_certs_len;
791 	__u32 pad2;
792 	__u64 amd_certs_uaddr;
793 	__u32 amd_certs_len;
794 	__u32 pad3;
795 	__u64 session_uaddr;
796 	__u32 session_len;
797 	__u32 pad4;
798 };
799 
800 struct kvm_sev_send_update_data {
801 	__u64 hdr_uaddr;
802 	__u32 hdr_len;
803 	__u32 pad0;
804 	__u64 guest_uaddr;
805 	__u32 guest_len;
806 	__u32 pad1;
807 	__u64 trans_uaddr;
808 	__u32 trans_len;
809 	__u32 pad2;
810 };
811 
812 struct kvm_sev_receive_start {
813 	__u32 handle;
814 	__u32 policy;
815 	__u64 pdh_uaddr;
816 	__u32 pdh_len;
817 	__u32 pad0;
818 	__u64 session_uaddr;
819 	__u32 session_len;
820 	__u32 pad1;
821 };
822 
823 struct kvm_sev_receive_update_data {
824 	__u64 hdr_uaddr;
825 	__u32 hdr_len;
826 	__u32 pad0;
827 	__u64 guest_uaddr;
828 	__u32 guest_len;
829 	__u32 pad1;
830 	__u64 trans_uaddr;
831 	__u32 trans_len;
832 	__u32 pad2;
833 };
834 
835 struct kvm_sev_snp_launch_start {
836 	__u64 policy;
837 	__u8 gosvw[16];
838 	__u16 flags;
839 	__u8 pad0[6];
840 	__u64 pad1[4];
841 };
842 
843 /* Kept in sync with firmware values for simplicity. */
844 #define KVM_SEV_SNP_PAGE_TYPE_NORMAL		0x1
845 #define KVM_SEV_SNP_PAGE_TYPE_ZERO		0x3
846 #define KVM_SEV_SNP_PAGE_TYPE_UNMEASURED	0x4
847 #define KVM_SEV_SNP_PAGE_TYPE_SECRETS		0x5
848 #define KVM_SEV_SNP_PAGE_TYPE_CPUID		0x6
849 
850 struct kvm_sev_snp_launch_update {
851 	__u64 gfn_start;
852 	__u64 uaddr;
853 	__u64 len;
854 	__u8 type;
855 	__u8 pad0;
856 	__u16 flags;
857 	__u32 pad1;
858 	__u64 pad2[4];
859 };
860 
861 #define KVM_SEV_SNP_ID_BLOCK_SIZE	96
862 #define KVM_SEV_SNP_ID_AUTH_SIZE	4096
863 #define KVM_SEV_SNP_FINISH_DATA_SIZE	32
864 
865 struct kvm_sev_snp_launch_finish {
866 	__u64 id_block_uaddr;
867 	__u64 id_auth_uaddr;
868 	__u8 id_block_en;
869 	__u8 auth_key_en;
870 	__u8 vcek_disabled;
871 	__u8 host_data[KVM_SEV_SNP_FINISH_DATA_SIZE];
872 	__u8 pad0[3];
873 	__u16 flags;
874 	__u64 pad1[4];
875 };
876 
877 #define KVM_X2APIC_API_USE_32BIT_IDS            (1ULL << 0)
878 #define KVM_X2APIC_API_DISABLE_BROADCAST_QUIRK  (1ULL << 1)
879 
880 struct kvm_hyperv_eventfd {
881 	__u32 conn_id;
882 	__s32 fd;
883 	__u32 flags;
884 	__u32 padding[3];
885 };
886 
887 #define KVM_HYPERV_CONN_ID_MASK		0x00ffffff
888 #define KVM_HYPERV_EVENTFD_DEASSIGN	(1 << 0)
889 
890 /*
891  * Masked event layout.
892  * Bits   Description
893  * ----   -----------
894  * 7:0    event select (low bits)
895  * 15:8   umask match
896  * 31:16  unused
897  * 35:32  event select (high bits)
898  * 36:54  unused
899  * 55     exclude bit
900  * 63:56  umask mask
901  */
902 
903 #define KVM_PMU_ENCODE_MASKED_ENTRY(event_select, mask, match, exclude) \
904 	(((event_select) & 0xFFULL) | (((event_select) & 0XF00ULL) << 24) | \
905 	(((mask) & 0xFFULL) << 56) | \
906 	(((match) & 0xFFULL) << 8) | \
907 	((__u64)(!!(exclude)) << 55))
908 
909 #define KVM_PMU_MASKED_ENTRY_EVENT_SELECT \
910 	(__GENMASK_ULL(7, 0) | __GENMASK_ULL(35, 32))
911 #define KVM_PMU_MASKED_ENTRY_UMASK_MASK		(__GENMASK_ULL(63, 56))
912 #define KVM_PMU_MASKED_ENTRY_UMASK_MATCH	(__GENMASK_ULL(15, 8))
913 #define KVM_PMU_MASKED_ENTRY_EXCLUDE		(_BITULL(55))
914 #define KVM_PMU_MASKED_ENTRY_UMASK_MASK_SHIFT	(56)
915 
916 /* for KVM_{GET,SET,HAS}_DEVICE_ATTR */
917 #define KVM_VCPU_TSC_CTRL 0 /* control group for the timestamp counter (TSC) */
918 #define   KVM_VCPU_TSC_OFFSET 0 /* attribute for the TSC offset */
919 
920 /* x86-specific KVM_EXIT_HYPERCALL flags. */
921 #define KVM_EXIT_HYPERCALL_LONG_MODE	_BITULL(0)
922 
923 #define KVM_X86_DEFAULT_VM	0
924 #define KVM_X86_SW_PROTECTED_VM	1
925 #define KVM_X86_SEV_VM		2
926 #define KVM_X86_SEV_ES_VM	3
927 #define KVM_X86_SNP_VM		4
928 
929 #endif /* _ASM_X86_KVM_H */
930