Greg Kroah-Hartman | 6f52b16 | 2017-11-01 15:08:43 +0100 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ |
H. Peter Anvin | 1965aae | 2008-10-22 22:26:29 -0700 | [diff] [blame] | 2 | #ifndef _ASM_X86_KVM_H |
| 3 | #define _ASM_X86_KVM_H |
Jerone Young | f6a40e3 | 2007-11-19 17:06:31 -0600 | [diff] [blame] | 4 | |
| 5 | /* |
| 6 | * KVM x86 specific structures and definitions |
| 7 | * |
| 8 | */ |
| 9 | |
Jaswinder Singh Rajput | cef3767 | 2009-01-30 22:46:08 +0530 | [diff] [blame] | 10 | #include <linux/types.h> |
Jerone Young | f6a40e3 | 2007-11-19 17:06:31 -0600 | [diff] [blame] | 11 | #include <linux/ioctl.h> |
| 12 | |
Paolo Bonzini | 4b4357e | 2017-03-31 13:53:23 +0200 | [diff] [blame] | 13 | #define KVM_PIO_PAGE_OFFSET 1 |
| 14 | #define KVM_COALESCED_MMIO_PAGE_OFFSET 2 |
Peter Xu | fb04a1e | 2020-09-30 21:22:22 -0400 | [diff] [blame] | 15 | #define KVM_DIRTY_LOG_PAGE_OFFSET 64 |
Paolo Bonzini | 4b4357e | 2017-03-31 13:53:23 +0200 | [diff] [blame] | 16 | |
Xiao Guangrong | 26bf264 | 2012-09-17 16:31:13 +0800 | [diff] [blame] | 17 | #define DE_VECTOR 0 |
| 18 | #define DB_VECTOR 1 |
| 19 | #define BP_VECTOR 3 |
| 20 | #define OF_VECTOR 4 |
| 21 | #define BR_VECTOR 5 |
| 22 | #define UD_VECTOR 6 |
| 23 | #define NM_VECTOR 7 |
| 24 | #define DF_VECTOR 8 |
| 25 | #define TS_VECTOR 10 |
| 26 | #define NP_VECTOR 11 |
| 27 | #define SS_VECTOR 12 |
| 28 | #define GP_VECTOR 13 |
| 29 | #define PF_VECTOR 14 |
| 30 | #define MF_VECTOR 16 |
Nadav Amit | c9cdd08 | 2014-07-21 14:37:24 +0300 | [diff] [blame] | 31 | #define AC_VECTOR 17 |
Xiao Guangrong | 26bf264 | 2012-09-17 16:31:13 +0800 | [diff] [blame] | 32 | #define MC_VECTOR 18 |
Nadav Amit | c9cdd08 | 2014-07-21 14:37:24 +0300 | [diff] [blame] | 33 | #define XM_VECTOR 19 |
| 34 | #define VE_VECTOR 20 |
Xiao Guangrong | 26bf264 | 2012-09-17 16:31:13 +0800 | [diff] [blame] | 35 | |
Avi Kivity | 7a0eb19 | 2009-01-19 14:57:52 +0200 | [diff] [blame] | 36 | /* Select x86 specific features in <linux/kvm.h> */ |
| 37 | #define __KVM_HAVE_PIT |
| 38 | #define __KVM_HAVE_IOAPIC |
Christoffer Dall | a1e4ccb | 2012-06-15 15:07:13 -0400 | [diff] [blame] | 39 | #define __KVM_HAVE_IRQ_LINE |
Avi Kivity | 7a0eb19 | 2009-01-19 14:57:52 +0200 | [diff] [blame] | 40 | #define __KVM_HAVE_MSI |
| 41 | #define __KVM_HAVE_USER_NMI |
Avi Kivity | 91b2ae7 | 2009-01-19 14:57:52 +0200 | [diff] [blame] | 42 | #define __KVM_HAVE_GUEST_DEBUG |
Sheng Yang | d510d6c | 2009-02-25 17:22:28 +0800 | [diff] [blame] | 43 | #define __KVM_HAVE_MSIX |
Huang Ying | 890ca9a | 2009-05-11 16:48:15 +0800 | [diff] [blame] | 44 | #define __KVM_HAVE_MCE |
Beth Kon | e9f4275 | 2009-07-07 11:50:38 -0400 | [diff] [blame] | 45 | #define __KVM_HAVE_PIT_STATE2 |
Ed Swierk | ffde22a | 2009-10-15 15:21:43 -0700 | [diff] [blame] | 46 | #define __KVM_HAVE_XEN_HVM |
Jan Kiszka | 3cfc309 | 2009-11-12 01:04:25 +0100 | [diff] [blame] | 47 | #define __KVM_HAVE_VCPU_EVENTS |
Jan Kiszka | a1efbe7 | 2010-02-15 10:45:43 +0100 | [diff] [blame] | 48 | #define __KVM_HAVE_DEBUGREGS |
Sheng Yang | 2d5b5a6 | 2010-06-13 17:29:39 +0800 | [diff] [blame] | 49 | #define __KVM_HAVE_XSAVE |
| 50 | #define __KVM_HAVE_XCRS |
Xiao Guangrong | 4d8b81a | 2012-08-21 11:02:51 +0800 | [diff] [blame] | 51 | #define __KVM_HAVE_READONLY_MEM |
Avi Kivity | 7a0eb19 | 2009-01-19 14:57:52 +0200 | [diff] [blame] | 52 | |
Jerone Young | 244d57e | 2007-11-19 17:06:36 -0600 | [diff] [blame] | 53 | /* Architectural interrupt line count. */ |
| 54 | #define KVM_NR_INTERRUPTS 256 |
| 55 | |
Jerone Young | f6a40e3 | 2007-11-19 17:06:31 -0600 | [diff] [blame] | 56 | struct kvm_memory_alias { |
| 57 | __u32 slot; /* this has a different namespace than memory slots */ |
| 58 | __u32 flags; |
| 59 | __u64 guest_phys_addr; |
| 60 | __u64 memory_size; |
| 61 | __u64 target_phys_addr; |
| 62 | }; |
| 63 | |
Jerone Young | da1386a | 2007-11-19 17:06:32 -0600 | [diff] [blame] | 64 | /* for KVM_GET_IRQCHIP and KVM_SET_IRQCHIP */ |
| 65 | struct kvm_pic_state { |
| 66 | __u8 last_irr; /* edge detection */ |
| 67 | __u8 irr; /* interrupt request register */ |
| 68 | __u8 imr; /* interrupt mask register */ |
| 69 | __u8 isr; /* interrupt service register */ |
| 70 | __u8 priority_add; /* highest irq priority */ |
| 71 | __u8 irq_base; |
| 72 | __u8 read_reg_select; |
| 73 | __u8 poll; |
| 74 | __u8 special_mask; |
| 75 | __u8 init_state; |
| 76 | __u8 auto_eoi; |
| 77 | __u8 rotate_on_auto_eoi; |
| 78 | __u8 special_fully_nested_mode; |
| 79 | __u8 init4; /* true if 4 byte init */ |
| 80 | __u8 elcr; /* PIIX edge/trigger selection */ |
| 81 | __u8 elcr_mask; |
| 82 | }; |
| 83 | |
| 84 | #define KVM_IOAPIC_NUM_PINS 24 |
| 85 | struct kvm_ioapic_state { |
| 86 | __u64 base_address; |
| 87 | __u32 ioregsel; |
| 88 | __u32 id; |
| 89 | __u32 irr; |
| 90 | __u32 pad; |
| 91 | union { |
| 92 | __u64 bits; |
| 93 | struct { |
| 94 | __u8 vector; |
| 95 | __u8 delivery_mode:3; |
| 96 | __u8 dest_mode:1; |
| 97 | __u8 delivery_status:1; |
| 98 | __u8 polarity:1; |
| 99 | __u8 remote_irr:1; |
| 100 | __u8 trig_mode:1; |
| 101 | __u8 mask:1; |
| 102 | __u8 reserve:7; |
| 103 | __u8 reserved[4]; |
| 104 | __u8 dest_id; |
| 105 | } fields; |
| 106 | } redirtbl[KVM_IOAPIC_NUM_PINS]; |
| 107 | }; |
| 108 | |
| 109 | #define KVM_IRQCHIP_PIC_MASTER 0 |
| 110 | #define KVM_IRQCHIP_PIC_SLAVE 1 |
| 111 | #define KVM_IRQCHIP_IOAPIC 2 |
Gleb Natapov | 3e71f88 | 2009-08-24 11:54:21 +0300 | [diff] [blame] | 112 | #define KVM_NR_IRQCHIPS 3 |
Jerone Young | da1386a | 2007-11-19 17:06:32 -0600 | [diff] [blame] | 113 | |
Paolo Bonzini | f077825 | 2015-04-01 15:06:40 +0200 | [diff] [blame] | 114 | #define KVM_RUN_X86_SMM (1 << 0) |
Chenyi Qiang | fe6b6bc | 2020-11-06 17:03:14 +0800 | [diff] [blame] | 115 | #define KVM_RUN_X86_BUS_LOCK (1 << 1) |
Paolo Bonzini | f077825 | 2015-04-01 15:06:40 +0200 | [diff] [blame] | 116 | |
Jerone Young | 19d30b1 | 2007-11-19 17:06:33 -0600 | [diff] [blame] | 117 | /* for KVM_GET_REGS and KVM_SET_REGS */ |
| 118 | struct kvm_regs { |
| 119 | /* out (KVM_GET_REGS) / in (KVM_SET_REGS) */ |
| 120 | __u64 rax, rbx, rcx, rdx; |
| 121 | __u64 rsi, rdi, rsp, rbp; |
| 122 | __u64 r8, r9, r10, r11; |
| 123 | __u64 r12, r13, r14, r15; |
| 124 | __u64 rip, rflags; |
| 125 | }; |
| 126 | |
Jerone Young | d9ecf92 | 2007-11-19 17:06:34 -0600 | [diff] [blame] | 127 | /* for KVM_GET_LAPIC and KVM_SET_LAPIC */ |
| 128 | #define KVM_APIC_REG_SIZE 0x400 |
| 129 | struct kvm_lapic_state { |
| 130 | char regs[KVM_APIC_REG_SIZE]; |
| 131 | }; |
| 132 | |
Jerone Young | 3a56b20 | 2007-11-19 17:06:35 -0600 | [diff] [blame] | 133 | struct kvm_segment { |
| 134 | __u64 base; |
| 135 | __u32 limit; |
| 136 | __u16 selector; |
| 137 | __u8 type; |
| 138 | __u8 present, dpl, db, s, l, g, avl; |
| 139 | __u8 unusable; |
| 140 | __u8 padding; |
| 141 | }; |
| 142 | |
| 143 | struct kvm_dtable { |
| 144 | __u64 base; |
| 145 | __u16 limit; |
| 146 | __u16 padding[3]; |
| 147 | }; |
| 148 | |
| 149 | |
Jerone Young | 244d57e | 2007-11-19 17:06:36 -0600 | [diff] [blame] | 150 | /* for KVM_GET_SREGS and KVM_SET_SREGS */ |
| 151 | struct kvm_sregs { |
| 152 | /* out (KVM_GET_SREGS) / in (KVM_SET_SREGS) */ |
| 153 | struct kvm_segment cs, ds, es, fs, gs, ss; |
| 154 | struct kvm_segment tr, ldt; |
| 155 | struct kvm_dtable gdt, idt; |
| 156 | __u64 cr0, cr2, cr3, cr4, cr8; |
| 157 | __u64 efer; |
| 158 | __u64 apic_base; |
| 159 | __u64 interrupt_bitmap[(KVM_NR_INTERRUPTS + 63) / 64]; |
| 160 | }; |
| 161 | |
Maxim Levitsky | 6dba940 | 2021-06-07 12:02:02 +0300 | [diff] [blame] | 162 | struct kvm_sregs2 { |
| 163 | /* out (KVM_GET_SREGS2) / in (KVM_SET_SREGS2) */ |
| 164 | struct kvm_segment cs, ds, es, fs, gs, ss; |
| 165 | struct kvm_segment tr, ldt; |
| 166 | struct kvm_dtable gdt, idt; |
| 167 | __u64 cr0, cr2, cr3, cr4, cr8; |
| 168 | __u64 efer; |
| 169 | __u64 apic_base; |
| 170 | __u64 flags; |
| 171 | __u64 pdptrs[4]; |
| 172 | }; |
| 173 | #define KVM_SREGS2_FLAGS_PDPTRS_VALID 1 |
| 174 | |
Christian Ehrhardt | 6f723c7 | 2008-01-08 08:04:50 +0100 | [diff] [blame] | 175 | /* for KVM_GET_FPU and KVM_SET_FPU */ |
| 176 | struct kvm_fpu { |
| 177 | __u8 fpr[8][16]; |
| 178 | __u16 fcw; |
| 179 | __u16 fsw; |
| 180 | __u8 ftwx; /* in fxsave format */ |
| 181 | __u8 pad1; |
| 182 | __u16 last_opcode; |
| 183 | __u64 last_ip; |
| 184 | __u64 last_dp; |
| 185 | __u8 xmm[16][16]; |
| 186 | __u32 mxcsr; |
| 187 | __u32 pad2; |
| 188 | }; |
| 189 | |
Jerone Young | 244d57e | 2007-11-19 17:06:36 -0600 | [diff] [blame] | 190 | struct kvm_msr_entry { |
| 191 | __u32 index; |
| 192 | __u32 reserved; |
| 193 | __u64 data; |
| 194 | }; |
| 195 | |
| 196 | /* for KVM_GET_MSRS and KVM_SET_MSRS */ |
| 197 | struct kvm_msrs { |
| 198 | __u32 nmsrs; /* number of msrs in entries */ |
| 199 | __u32 pad; |
| 200 | |
| 201 | struct kvm_msr_entry entries[0]; |
| 202 | }; |
| 203 | |
| 204 | /* for KVM_GET_MSR_INDEX_LIST */ |
| 205 | struct kvm_msr_list { |
| 206 | __u32 nmsrs; /* number of msrs in entries */ |
| 207 | __u32 indices[0]; |
| 208 | }; |
| 209 | |
Alexander Graf | 1a155254 | 2020-09-25 16:34:21 +0200 | [diff] [blame] | 210 | /* Maximum size of any access bitmap in bytes */ |
| 211 | #define KVM_MSR_FILTER_MAX_BITMAP_SIZE 0x600 |
| 212 | |
| 213 | /* for KVM_X86_SET_MSR_FILTER */ |
| 214 | struct kvm_msr_filter_range { |
Alexander Graf | 51de815 | 2020-09-25 16:34:17 +0200 | [diff] [blame] | 215 | #define KVM_MSR_FILTER_READ (1 << 0) |
| 216 | #define KVM_MSR_FILTER_WRITE (1 << 1) |
Alexander Graf | 1a155254 | 2020-09-25 16:34:21 +0200 | [diff] [blame] | 217 | __u32 flags; |
| 218 | __u32 nmsrs; /* number of msrs in bitmap */ |
| 219 | __u32 base; /* MSR index the bitmap starts at */ |
| 220 | __u8 *bitmap; /* a 1 bit allows the operations in flags, 0 denies */ |
| 221 | }; |
| 222 | |
| 223 | #define KVM_MSR_FILTER_MAX_RANGES 16 |
| 224 | struct kvm_msr_filter { |
| 225 | #define KVM_MSR_FILTER_DEFAULT_ALLOW (0 << 0) |
| 226 | #define KVM_MSR_FILTER_DEFAULT_DENY (1 << 0) |
| 227 | __u32 flags; |
| 228 | struct kvm_msr_filter_range ranges[KVM_MSR_FILTER_MAX_RANGES]; |
| 229 | }; |
Jerone Young | 244d57e | 2007-11-19 17:06:36 -0600 | [diff] [blame] | 230 | |
Jerone Young | a162dd5 | 2007-11-19 17:06:37 -0600 | [diff] [blame] | 231 | struct kvm_cpuid_entry { |
| 232 | __u32 function; |
| 233 | __u32 eax; |
| 234 | __u32 ebx; |
| 235 | __u32 ecx; |
| 236 | __u32 edx; |
| 237 | __u32 padding; |
| 238 | }; |
| 239 | |
| 240 | /* for KVM_SET_CPUID */ |
| 241 | struct kvm_cpuid { |
| 242 | __u32 nent; |
| 243 | __u32 padding; |
| 244 | struct kvm_cpuid_entry entries[0]; |
| 245 | }; |
| 246 | |
Dan Kenigsberg | 0771671 | 2007-11-21 17:10:04 +0200 | [diff] [blame] | 247 | struct kvm_cpuid_entry2 { |
| 248 | __u32 function; |
| 249 | __u32 index; |
| 250 | __u32 flags; |
| 251 | __u32 eax; |
| 252 | __u32 ebx; |
| 253 | __u32 ecx; |
| 254 | __u32 edx; |
| 255 | __u32 padding[3]; |
| 256 | }; |
| 257 | |
Borislav Petkov | 3dbe345 | 2016-05-05 10:18:23 +0200 | [diff] [blame] | 258 | #define KVM_CPUID_FLAG_SIGNIFCANT_INDEX (1 << 0) |
| 259 | #define KVM_CPUID_FLAG_STATEFUL_FUNC (1 << 1) |
| 260 | #define KVM_CPUID_FLAG_STATE_READ_NEXT (1 << 2) |
Dan Kenigsberg | 0771671 | 2007-11-21 17:10:04 +0200 | [diff] [blame] | 261 | |
| 262 | /* for KVM_SET_CPUID2 */ |
| 263 | struct kvm_cpuid2 { |
| 264 | __u32 nent; |
| 265 | __u32 padding; |
| 266 | struct kvm_cpuid_entry2 entries[0]; |
| 267 | }; |
Jerone Young | a162dd5 | 2007-11-19 17:06:37 -0600 | [diff] [blame] | 268 | |
Sheng Yang | e0f63cb | 2008-03-04 00:50:59 +0800 | [diff] [blame] | 269 | /* for KVM_GET_PIT and KVM_SET_PIT */ |
| 270 | struct kvm_pit_channel_state { |
| 271 | __u32 count; /* can be 65536 */ |
| 272 | __u16 latched_count; |
| 273 | __u8 count_latched; |
| 274 | __u8 status_latched; |
| 275 | __u8 status; |
| 276 | __u8 read_state; |
| 277 | __u8 write_state; |
| 278 | __u8 write_latch; |
| 279 | __u8 rw_mode; |
| 280 | __u8 mode; |
| 281 | __u8 bcd; |
| 282 | __u8 gate; |
| 283 | __s64 count_load_time; |
| 284 | }; |
| 285 | |
Jan Kiszka | d0bfb94 | 2008-12-15 13:52:10 +0100 | [diff] [blame] | 286 | struct kvm_debug_exit_arch { |
| 287 | __u32 exception; |
| 288 | __u32 pad; |
| 289 | __u64 pc; |
| 290 | __u64 dr6; |
| 291 | __u64 dr7; |
| 292 | }; |
| 293 | |
| 294 | #define KVM_GUESTDBG_USE_SW_BP 0x00010000 |
| 295 | #define KVM_GUESTDBG_USE_HW_BP 0x00020000 |
| 296 | #define KVM_GUESTDBG_INJECT_DB 0x00040000 |
| 297 | #define KVM_GUESTDBG_INJECT_BP 0x00080000 |
Maxim Levitsky | 61e5f69 | 2021-08-11 15:29:26 +0300 | [diff] [blame] | 298 | #define KVM_GUESTDBG_BLOCKIRQ 0x00100000 |
Jan Kiszka | d0bfb94 | 2008-12-15 13:52:10 +0100 | [diff] [blame] | 299 | |
| 300 | /* for KVM_SET_GUEST_DEBUG */ |
| 301 | struct kvm_guest_debug_arch { |
| 302 | __u64 debugreg[8]; |
| 303 | }; |
| 304 | |
Sheng Yang | e0f63cb | 2008-03-04 00:50:59 +0800 | [diff] [blame] | 305 | struct kvm_pit_state { |
| 306 | struct kvm_pit_channel_state channels[3]; |
| 307 | }; |
Marcelo Tosatti | 52d939a | 2008-12-30 15:55:06 -0200 | [diff] [blame] | 308 | |
Beth Kon | e9f4275 | 2009-07-07 11:50:38 -0400 | [diff] [blame] | 309 | #define KVM_PIT_FLAGS_HPET_LEGACY 0x00000001 |
| 310 | |
| 311 | struct kvm_pit_state2 { |
| 312 | struct kvm_pit_channel_state channels[3]; |
| 313 | __u32 flags; |
| 314 | __u32 reserved[9]; |
| 315 | }; |
| 316 | |
Marcelo Tosatti | 52d939a | 2008-12-30 15:55:06 -0200 | [diff] [blame] | 317 | struct kvm_reinject_control { |
| 318 | __u8 pit_reinject; |
| 319 | __u8 reserved[31]; |
| 320 | }; |
Jan Kiszka | 3cfc309 | 2009-11-12 01:04:25 +0100 | [diff] [blame] | 321 | |
Jan Kiszka | dab4b91 | 2009-12-06 18:24:15 +0100 | [diff] [blame] | 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 |
Jan Kiszka | 48005f6 | 2010-02-19 19:38:07 +0100 | [diff] [blame] | 325 | #define KVM_VCPUEVENT_VALID_SHADOW 0x00000004 |
Paolo Bonzini | f077825 | 2015-04-01 15:06:40 +0200 | [diff] [blame] | 326 | #define KVM_VCPUEVENT_VALID_SMM 0x00000008 |
Jim Mattson | 59073aa | 2018-10-16 14:29:20 -0700 | [diff] [blame] | 327 | #define KVM_VCPUEVENT_VALID_PAYLOAD 0x00000010 |
Jan Kiszka | 48005f6 | 2010-02-19 19:38:07 +0100 | [diff] [blame] | 328 | |
| 329 | /* Interrupt shadow states */ |
| 330 | #define KVM_X86_SHADOW_INT_MOV_SS 0x01 |
| 331 | #define KVM_X86_SHADOW_INT_STI 0x02 |
Jan Kiszka | dab4b91 | 2009-12-06 18:24:15 +0100 | [diff] [blame] | 332 | |
Jan Kiszka | 3cfc309 | 2009-11-12 01:04:25 +0100 | [diff] [blame] | 333 | /* for KVM_GET/SET_VCPU_EVENTS */ |
| 334 | struct kvm_vcpu_events { |
| 335 | struct { |
| 336 | __u8 injected; |
| 337 | __u8 nr; |
| 338 | __u8 has_error_code; |
Jim Mattson | 59073aa | 2018-10-16 14:29:20 -0700 | [diff] [blame] | 339 | __u8 pending; |
Jan Kiszka | 3cfc309 | 2009-11-12 01:04:25 +0100 | [diff] [blame] | 340 | __u32 error_code; |
| 341 | } exception; |
| 342 | struct { |
| 343 | __u8 injected; |
| 344 | __u8 nr; |
| 345 | __u8 soft; |
Jan Kiszka | 48005f6 | 2010-02-19 19:38:07 +0100 | [diff] [blame] | 346 | __u8 shadow; |
Jan Kiszka | 3cfc309 | 2009-11-12 01:04:25 +0100 | [diff] [blame] | 347 | } interrupt; |
| 348 | struct { |
| 349 | __u8 injected; |
| 350 | __u8 pending; |
| 351 | __u8 masked; |
| 352 | __u8 pad; |
| 353 | } nmi; |
| 354 | __u32 sipi_vector; |
| 355 | __u32 flags; |
Paolo Bonzini | f077825 | 2015-04-01 15:06:40 +0200 | [diff] [blame] | 356 | struct { |
| 357 | __u8 smm; |
| 358 | __u8 pending; |
| 359 | __u8 smm_inside_nmi; |
| 360 | __u8 latched_init; |
| 361 | } smi; |
Jim Mattson | 59073aa | 2018-10-16 14:29:20 -0700 | [diff] [blame] | 362 | __u8 reserved[27]; |
| 363 | __u8 exception_has_payload; |
| 364 | __u64 exception_payload; |
Jan Kiszka | 3cfc309 | 2009-11-12 01:04:25 +0100 | [diff] [blame] | 365 | }; |
| 366 | |
Jan Kiszka | a1efbe7 | 2010-02-15 10:45:43 +0100 | [diff] [blame] | 367 | /* for KVM_GET/SET_DEBUGREGS */ |
| 368 | struct kvm_debugregs { |
| 369 | __u64 db[4]; |
| 370 | __u64 dr6; |
| 371 | __u64 dr7; |
| 372 | __u64 flags; |
| 373 | __u64 reserved[9]; |
| 374 | }; |
| 375 | |
Guang Zeng | be50b20 | 2022-01-05 04:35:29 -0800 | [diff] [blame] | 376 | /* for KVM_CAP_XSAVE and KVM_CAP_XSAVE2 */ |
Sheng Yang | 2d5b5a6 | 2010-06-13 17:29:39 +0800 | [diff] [blame] | 377 | struct kvm_xsave { |
Guang Zeng | be50b20 | 2022-01-05 04:35:29 -0800 | [diff] [blame] | 378 | /* |
| 379 | * KVM_GET_XSAVE2 and KVM_SET_XSAVE write and read as many bytes |
| 380 | * as are returned by KVM_CHECK_EXTENSION(KVM_CAP_XSAVE2) |
| 381 | * respectively, when invoked on the vm file descriptor. |
| 382 | * |
| 383 | * The size value returned by KVM_CHECK_EXTENSION(KVM_CAP_XSAVE2) |
| 384 | * will always be at least 4096. Currently, it is only greater |
| 385 | * than 4096 if a dynamic feature has been enabled with |
| 386 | * ``arch_prctl()``, but this may change in the future. |
| 387 | * |
| 388 | * The offsets of the state save areas in struct kvm_xsave follow |
| 389 | * the contents of CPUID leaf 0xD on the host. |
| 390 | */ |
Sheng Yang | 2d5b5a6 | 2010-06-13 17:29:39 +0800 | [diff] [blame] | 391 | __u32 region[1024]; |
Guang Zeng | be50b20 | 2022-01-05 04:35:29 -0800 | [diff] [blame] | 392 | __u32 extra[0]; |
Sheng Yang | 2d5b5a6 | 2010-06-13 17:29:39 +0800 | [diff] [blame] | 393 | }; |
| 394 | |
| 395 | #define KVM_MAX_XCRS 16 |
| 396 | |
| 397 | struct kvm_xcr { |
| 398 | __u32 xcr; |
| 399 | __u32 reserved; |
| 400 | __u64 value; |
| 401 | }; |
| 402 | |
| 403 | struct kvm_xcrs { |
| 404 | __u32 nr_xcrs; |
| 405 | __u32 flags; |
| 406 | struct kvm_xcr xcrs[KVM_MAX_XCRS]; |
| 407 | __u64 padding[16]; |
| 408 | }; |
| 409 | |
Ken Hofsass | 01643c5 | 2018-01-31 16:03:36 -0800 | [diff] [blame] | 410 | #define KVM_SYNC_X86_REGS (1UL << 0) |
| 411 | #define KVM_SYNC_X86_SREGS (1UL << 1) |
| 412 | #define KVM_SYNC_X86_EVENTS (1UL << 2) |
| 413 | |
| 414 | #define KVM_SYNC_X86_VALID_FIELDS \ |
| 415 | (KVM_SYNC_X86_REGS| \ |
| 416 | KVM_SYNC_X86_SREGS| \ |
| 417 | KVM_SYNC_X86_EVENTS) |
| 418 | |
| 419 | /* kvm_sync_regs struct included by kvm_run struct */ |
Christian Borntraeger | b9e5dc8 | 2012-01-11 11:20:30 +0100 | [diff] [blame] | 420 | struct kvm_sync_regs { |
Ken Hofsass | 01643c5 | 2018-01-31 16:03:36 -0800 | [diff] [blame] | 421 | /* Members of this structure are potentially malicious. |
| 422 | * Care must be taken by code reading, esp. interpreting, |
| 423 | * data fields from them inside KVM to prevent TOCTOU and |
| 424 | * double-fetch types of vulnerabilities. |
| 425 | */ |
| 426 | struct kvm_regs regs; |
| 427 | struct kvm_sregs sregs; |
| 428 | struct kvm_vcpu_events events; |
Christian Borntraeger | b9e5dc8 | 2012-01-11 11:20:30 +0100 | [diff] [blame] | 429 | }; |
| 430 | |
Wanpeng Li | 511a8556 | 2019-05-21 14:06:54 +0800 | [diff] [blame] | 431 | #define KVM_X86_QUIRK_LINT0_REENABLED (1 << 0) |
| 432 | #define KVM_X86_QUIRK_CD_NW_CLEARED (1 << 1) |
| 433 | #define KVM_X86_QUIRK_LAPIC_MMIO_HOLE (1 << 2) |
| 434 | #define KVM_X86_QUIRK_OUT_7E_INC_RIP (1 << 3) |
| 435 | #define KVM_X86_QUIRK_MISC_ENABLE_NO_MWAIT (1 << 4) |
Nadav Amit | 90de4a1 | 2015-04-13 01:53:41 +0300 | [diff] [blame] | 436 | |
Liran Alon | 6ca00df | 2019-06-16 15:03:10 +0300 | [diff] [blame] | 437 | #define KVM_STATE_NESTED_FORMAT_VMX 0 |
Paolo Bonzini | cc440cd | 2020-05-13 13:36:32 -0400 | [diff] [blame] | 438 | #define KVM_STATE_NESTED_FORMAT_SVM 1 |
Liran Alon | 6ca00df | 2019-06-16 15:03:10 +0300 | [diff] [blame] | 439 | |
Jim Mattson | 8fcc4b5 | 2018-07-10 11:27:20 +0200 | [diff] [blame] | 440 | #define KVM_STATE_NESTED_GUEST_MODE 0x00000001 |
| 441 | #define KVM_STATE_NESTED_RUN_PENDING 0x00000002 |
Vitaly Kuznetsov | 8cab650 | 2018-10-16 18:50:09 +0200 | [diff] [blame] | 442 | #define KVM_STATE_NESTED_EVMCS 0x00000004 |
Oliver Upton | 5ef8acb | 2020-02-07 02:36:07 -0800 | [diff] [blame] | 443 | #define KVM_STATE_NESTED_MTF_PENDING 0x00000008 |
Paolo Bonzini | cc440cd | 2020-05-13 13:36:32 -0400 | [diff] [blame] | 444 | #define KVM_STATE_NESTED_GIF_SET 0x00000100 |
Jim Mattson | 8fcc4b5 | 2018-07-10 11:27:20 +0200 | [diff] [blame] | 445 | |
| 446 | #define KVM_STATE_NESTED_SMM_GUEST_MODE 0x00000001 |
| 447 | #define KVM_STATE_NESTED_SMM_VMXON 0x00000002 |
| 448 | |
Liran Alon | 6ca00df | 2019-06-16 15:03:10 +0300 | [diff] [blame] | 449 | #define KVM_STATE_NESTED_VMX_VMCS_SIZE 0x1000 |
| 450 | |
Paolo Bonzini | cc440cd | 2020-05-13 13:36:32 -0400 | [diff] [blame] | 451 | #define KVM_STATE_NESTED_SVM_VMCB_SIZE 0x1000 |
| 452 | |
Peter Shier | 850448f | 2020-05-26 14:51:06 -0700 | [diff] [blame] | 453 | #define KVM_STATE_VMX_PREEMPTION_TIMER_DEADLINE 0x00000001 |
Paolo Bonzini | cc440cd | 2020-05-13 13:36:32 -0400 | [diff] [blame] | 454 | |
Liran Alon | 6ca00df | 2019-06-16 15:03:10 +0300 | [diff] [blame] | 455 | struct kvm_vmx_nested_state_data { |
| 456 | __u8 vmcs12[KVM_STATE_NESTED_VMX_VMCS_SIZE]; |
| 457 | __u8 shadow_vmcs12[KVM_STATE_NESTED_VMX_VMCS_SIZE]; |
| 458 | }; |
| 459 | |
| 460 | struct kvm_vmx_nested_state_hdr { |
Jim Mattson | 8fcc4b5 | 2018-07-10 11:27:20 +0200 | [diff] [blame] | 461 | __u64 vmxon_pa; |
Liran Alon | 6ca00df | 2019-06-16 15:03:10 +0300 | [diff] [blame] | 462 | __u64 vmcs12_pa; |
Jim Mattson | 8fcc4b5 | 2018-07-10 11:27:20 +0200 | [diff] [blame] | 463 | |
| 464 | struct { |
| 465 | __u16 flags; |
| 466 | } smm; |
Paolo Bonzini | 83d31e5 | 2020-07-09 13:12:09 -0400 | [diff] [blame] | 467 | |
Vitaly Kuznetsov | 70f094f | 2021-05-03 17:08:52 +0200 | [diff] [blame] | 468 | __u16 pad; |
| 469 | |
Paolo Bonzini | 83d31e5 | 2020-07-09 13:12:09 -0400 | [diff] [blame] | 470 | __u32 flags; |
| 471 | __u64 preemption_timer_deadline; |
Jim Mattson | 8fcc4b5 | 2018-07-10 11:27:20 +0200 | [diff] [blame] | 472 | }; |
| 473 | |
Paolo Bonzini | cc440cd | 2020-05-13 13:36:32 -0400 | [diff] [blame] | 474 | struct kvm_svm_nested_state_data { |
| 475 | /* Save area only used if KVM_STATE_NESTED_RUN_PENDING. */ |
| 476 | __u8 vmcb12[KVM_STATE_NESTED_SVM_VMCB_SIZE]; |
| 477 | }; |
| 478 | |
| 479 | struct kvm_svm_nested_state_hdr { |
| 480 | __u64 vmcb_pa; |
| 481 | }; |
| 482 | |
Jim Mattson | 8fcc4b5 | 2018-07-10 11:27:20 +0200 | [diff] [blame] | 483 | /* for KVM_CAP_NESTED_STATE */ |
| 484 | struct kvm_nested_state { |
Jim Mattson | 8fcc4b5 | 2018-07-10 11:27:20 +0200 | [diff] [blame] | 485 | __u16 flags; |
Jim Mattson | 8fcc4b5 | 2018-07-10 11:27:20 +0200 | [diff] [blame] | 486 | __u16 format; |
Jim Mattson | 8fcc4b5 | 2018-07-10 11:27:20 +0200 | [diff] [blame] | 487 | __u32 size; |
| 488 | |
| 489 | union { |
Liran Alon | 6ca00df | 2019-06-16 15:03:10 +0300 | [diff] [blame] | 490 | struct kvm_vmx_nested_state_hdr vmx; |
Paolo Bonzini | cc440cd | 2020-05-13 13:36:32 -0400 | [diff] [blame] | 491 | struct kvm_svm_nested_state_hdr svm; |
Jim Mattson | 8fcc4b5 | 2018-07-10 11:27:20 +0200 | [diff] [blame] | 492 | |
| 493 | /* Pad the header to 128 bytes. */ |
| 494 | __u8 pad[120]; |
Liran Alon | 6ca00df | 2019-06-16 15:03:10 +0300 | [diff] [blame] | 495 | } hdr; |
Jim Mattson | 8fcc4b5 | 2018-07-10 11:27:20 +0200 | [diff] [blame] | 496 | |
Liran Alon | 6ca00df | 2019-06-16 15:03:10 +0300 | [diff] [blame] | 497 | /* |
| 498 | * Define data region as 0 bytes to preserve backwards-compatability |
| 499 | * to old definition of kvm_nested_state in order to avoid changing |
| 500 | * KVM_{GET,PUT}_NESTED_STATE ioctl values. |
| 501 | */ |
| 502 | union { |
| 503 | struct kvm_vmx_nested_state_data vmx[0]; |
Paolo Bonzini | cc440cd | 2020-05-13 13:36:32 -0400 | [diff] [blame] | 504 | struct kvm_svm_nested_state_data svm[0]; |
Liran Alon | 6ca00df | 2019-06-16 15:03:10 +0300 | [diff] [blame] | 505 | } data; |
Jim Mattson | 8fcc4b5 | 2018-07-10 11:27:20 +0200 | [diff] [blame] | 506 | }; |
| 507 | |
Eric Hankland | 66bb8a0 | 2019-07-10 18:25:15 -0700 | [diff] [blame] | 508 | /* for KVM_CAP_PMU_EVENT_FILTER */ |
| 509 | struct kvm_pmu_event_filter { |
Eric Hankland | 30cd860 | 2019-07-18 11:38:18 -0700 | [diff] [blame] | 510 | __u32 action; |
| 511 | __u32 nevents; |
| 512 | __u32 fixed_counter_bitmap; |
| 513 | __u32 flags; |
| 514 | __u32 pad[4]; |
| 515 | __u64 events[0]; |
Eric Hankland | 66bb8a0 | 2019-07-10 18:25:15 -0700 | [diff] [blame] | 516 | }; |
| 517 | |
| 518 | #define KVM_PMU_EVENT_ALLOW 0 |
| 519 | #define KVM_PMU_EVENT_DENY 1 |
| 520 | |
Oliver Upton | 828ca89 | 2021-09-16 18:15:38 +0000 | [diff] [blame] | 521 | /* for KVM_{GET,SET,HAS}_DEVICE_ATTR */ |
| 522 | #define KVM_VCPU_TSC_CTRL 0 /* control group for the timestamp counter (TSC) */ |
| 523 | #define KVM_VCPU_TSC_OFFSET 0 /* attribute for the TSC offset */ |
| 524 | |
H. Peter Anvin | 1965aae | 2008-10-22 22:26:29 -0700 | [diff] [blame] | 525 | #endif /* _ASM_X86_KVM_H */ |