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