Avi Kivity | 6aa8b73 | 2006-12-10 02:21:36 -0800 | [diff] [blame] | 1 | #ifndef __LINUX_KVM_H |
| 2 | #define __LINUX_KVM_H |
| 3 | |
| 4 | /* |
| 5 | * Userspace interface for /dev/kvm - kernel based virtual machine |
| 6 | * |
| 7 | * Note: this interface is considered experimental and may change without |
| 8 | * notice. |
| 9 | */ |
| 10 | |
| 11 | #include <asm/types.h> |
| 12 | #include <linux/ioctl.h> |
| 13 | |
Avi Kivity | 2ff81f7 | 2007-04-29 16:25:49 +0300 | [diff] [blame] | 14 | #define KVM_API_VERSION 12 |
Avi Kivity | 0b76e20 | 2006-12-22 01:06:02 -0800 | [diff] [blame] | 15 | |
Avi Kivity | 6aa8b73 | 2006-12-10 02:21:36 -0800 | [diff] [blame] | 16 | /* |
| 17 | * Architectural interrupt line count, and the size of the bitmap needed |
| 18 | * to hold them. |
| 19 | */ |
| 20 | #define KVM_NR_INTERRUPTS 256 |
| 21 | #define KVM_IRQ_BITMAP_SIZE_BYTES ((KVM_NR_INTERRUPTS + 7) / 8) |
| 22 | #define KVM_IRQ_BITMAP_SIZE(type) (KVM_IRQ_BITMAP_SIZE_BYTES / sizeof(type)) |
| 23 | |
| 24 | |
| 25 | /* for KVM_CREATE_MEMORY_REGION */ |
| 26 | struct kvm_memory_region { |
| 27 | __u32 slot; |
| 28 | __u32 flags; |
| 29 | __u64 guest_phys_addr; |
| 30 | __u64 memory_size; /* bytes */ |
| 31 | }; |
| 32 | |
| 33 | /* for kvm_memory_region::flags */ |
| 34 | #define KVM_MEM_LOG_DIRTY_PAGES 1UL |
| 35 | |
Avi Kivity | e820754 | 2007-03-30 16:54:30 +0300 | [diff] [blame] | 36 | struct kvm_memory_alias { |
| 37 | __u32 slot; /* this has a different namespace than memory slots */ |
| 38 | __u32 flags; |
| 39 | __u64 guest_phys_addr; |
| 40 | __u64 memory_size; |
| 41 | __u64 target_phys_addr; |
| 42 | }; |
Avi Kivity | 6aa8b73 | 2006-12-10 02:21:36 -0800 | [diff] [blame] | 43 | |
Avi Kivity | 6aa8b73 | 2006-12-10 02:21:36 -0800 | [diff] [blame] | 44 | enum kvm_exit_reason { |
| 45 | KVM_EXIT_UNKNOWN = 0, |
| 46 | KVM_EXIT_EXCEPTION = 1, |
| 47 | KVM_EXIT_IO = 2, |
Avi Kivity | b4e63f5 | 2007-03-04 13:59:30 +0200 | [diff] [blame] | 48 | KVM_EXIT_HYPERCALL = 3, |
Avi Kivity | 6aa8b73 | 2006-12-10 02:21:36 -0800 | [diff] [blame] | 49 | KVM_EXIT_DEBUG = 4, |
| 50 | KVM_EXIT_HLT = 5, |
| 51 | KVM_EXIT_MMIO = 6, |
Dor Laor | c1150d8 | 2007-01-05 16:36:24 -0800 | [diff] [blame] | 52 | KVM_EXIT_IRQ_WINDOW_OPEN = 7, |
Joerg Roedel | 46fe4dd | 2007-01-26 00:56:42 -0800 | [diff] [blame] | 53 | KVM_EXIT_SHUTDOWN = 8, |
Avi Kivity | 8eb7d33 | 2007-03-04 14:17:08 +0200 | [diff] [blame] | 54 | KVM_EXIT_FAIL_ENTRY = 9, |
Avi Kivity | 1b19f3e | 2007-03-04 14:24:03 +0200 | [diff] [blame] | 55 | KVM_EXIT_INTR = 10, |
Avi Kivity | 6aa8b73 | 2006-12-10 02:21:36 -0800 | [diff] [blame] | 56 | }; |
| 57 | |
Avi Kivity | 9a2bb7f | 2007-02-22 12:58:31 +0200 | [diff] [blame] | 58 | /* for KVM_RUN, returned by mmap(vcpu_fd, offset=0) */ |
Avi Kivity | 6aa8b73 | 2006-12-10 02:21:36 -0800 | [diff] [blame] | 59 | struct kvm_run { |
| 60 | /* in */ |
Dor Laor | c1150d8 | 2007-01-05 16:36:24 -0800 | [diff] [blame] | 61 | __u8 request_interrupt_window; |
Avi Kivity | 02c8320 | 2007-04-29 15:02:17 +0300 | [diff] [blame] | 62 | __u8 padding1[7]; |
Avi Kivity | 6aa8b73 | 2006-12-10 02:21:36 -0800 | [diff] [blame] | 63 | |
| 64 | /* out */ |
Avi Kivity | 6aa8b73 | 2006-12-10 02:21:36 -0800 | [diff] [blame] | 65 | __u32 exit_reason; |
Dor Laor | c1150d8 | 2007-01-05 16:36:24 -0800 | [diff] [blame] | 66 | __u8 ready_for_interrupt_injection; |
| 67 | __u8 if_flag; |
Avi Kivity | 2ff81f7 | 2007-04-29 16:25:49 +0300 | [diff] [blame] | 68 | __u8 padding2[2]; |
Dor Laor | 5481034 | 2007-02-12 00:54:39 -0800 | [diff] [blame] | 69 | |
| 70 | /* in (pre_kvm_run), out (post_kvm_run) */ |
Dor Laor | c1150d8 | 2007-01-05 16:36:24 -0800 | [diff] [blame] | 71 | __u64 cr8; |
| 72 | __u64 apic_base; |
| 73 | |
Avi Kivity | 6aa8b73 | 2006-12-10 02:21:36 -0800 | [diff] [blame] | 74 | union { |
| 75 | /* KVM_EXIT_UNKNOWN */ |
| 76 | struct { |
Avi Kivity | 8eb7d33 | 2007-03-04 14:17:08 +0200 | [diff] [blame] | 77 | __u64 hardware_exit_reason; |
Avi Kivity | 6aa8b73 | 2006-12-10 02:21:36 -0800 | [diff] [blame] | 78 | } hw; |
Avi Kivity | 8eb7d33 | 2007-03-04 14:17:08 +0200 | [diff] [blame] | 79 | /* KVM_EXIT_FAIL_ENTRY */ |
| 80 | struct { |
| 81 | __u64 hardware_entry_failure_reason; |
| 82 | } fail_entry; |
Avi Kivity | 6aa8b73 | 2006-12-10 02:21:36 -0800 | [diff] [blame] | 83 | /* KVM_EXIT_EXCEPTION */ |
| 84 | struct { |
| 85 | __u32 exception; |
| 86 | __u32 error_code; |
| 87 | } ex; |
| 88 | /* KVM_EXIT_IO */ |
Avi Kivity | 46fc147 | 2007-02-22 19:39:30 +0200 | [diff] [blame] | 89 | struct kvm_io { |
Avi Kivity | 6aa8b73 | 2006-12-10 02:21:36 -0800 | [diff] [blame] | 90 | #define KVM_EXIT_IO_IN 0 |
| 91 | #define KVM_EXIT_IO_OUT 1 |
| 92 | __u8 direction; |
| 93 | __u8 size; /* bytes */ |
Avi Kivity | 6aa8b73 | 2006-12-10 02:21:36 -0800 | [diff] [blame] | 94 | __u16 port; |
Avi Kivity | 039576c | 2007-03-20 12:46:50 +0200 | [diff] [blame] | 95 | __u32 count; |
| 96 | __u64 data_offset; /* relative to kvm_run start */ |
Avi Kivity | 6aa8b73 | 2006-12-10 02:21:36 -0800 | [diff] [blame] | 97 | } io; |
| 98 | struct { |
| 99 | } debug; |
| 100 | /* KVM_EXIT_MMIO */ |
| 101 | struct { |
| 102 | __u64 phys_addr; |
| 103 | __u8 data[8]; |
| 104 | __u32 len; |
| 105 | __u8 is_write; |
| 106 | } mmio; |
Avi Kivity | b4e63f5 | 2007-03-04 13:59:30 +0200 | [diff] [blame] | 107 | /* KVM_EXIT_HYPERCALL */ |
| 108 | struct { |
| 109 | __u64 args[6]; |
| 110 | __u64 ret; |
| 111 | __u32 longmode; |
| 112 | __u32 pad; |
| 113 | } hypercall; |
Avi Kivity | 6aa8b73 | 2006-12-10 02:21:36 -0800 | [diff] [blame] | 114 | }; |
| 115 | }; |
| 116 | |
| 117 | /* for KVM_GET_REGS and KVM_SET_REGS */ |
| 118 | struct kvm_regs { |
Avi Kivity | 6aa8b73 | 2006-12-10 02:21:36 -0800 | [diff] [blame] | 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 | |
Avi Kivity | b883673 | 2007-04-01 16:34:31 +0300 | [diff] [blame] | 127 | /* for KVM_GET_FPU and KVM_SET_FPU */ |
| 128 | struct kvm_fpu { |
| 129 | __u8 fpr[8][16]; |
| 130 | __u16 fcw; |
| 131 | __u16 fsw; |
| 132 | __u8 ftwx; /* in fxsave format */ |
| 133 | __u8 pad1; |
| 134 | __u16 last_opcode; |
| 135 | __u64 last_ip; |
| 136 | __u64 last_dp; |
| 137 | __u8 xmm[16][16]; |
| 138 | __u32 mxcsr; |
| 139 | __u32 pad2; |
| 140 | }; |
| 141 | |
Avi Kivity | 6aa8b73 | 2006-12-10 02:21:36 -0800 | [diff] [blame] | 142 | struct kvm_segment { |
| 143 | __u64 base; |
| 144 | __u32 limit; |
| 145 | __u16 selector; |
| 146 | __u8 type; |
| 147 | __u8 present, dpl, db, s, l, g, avl; |
| 148 | __u8 unusable; |
| 149 | __u8 padding; |
| 150 | }; |
| 151 | |
| 152 | struct kvm_dtable { |
| 153 | __u64 base; |
| 154 | __u16 limit; |
| 155 | __u16 padding[3]; |
| 156 | }; |
| 157 | |
| 158 | /* for KVM_GET_SREGS and KVM_SET_SREGS */ |
| 159 | struct kvm_sregs { |
Avi Kivity | 6aa8b73 | 2006-12-10 02:21:36 -0800 | [diff] [blame] | 160 | /* out (KVM_GET_SREGS) / in (KVM_SET_SREGS) */ |
| 161 | struct kvm_segment cs, ds, es, fs, gs, ss; |
| 162 | struct kvm_segment tr, ldt; |
| 163 | struct kvm_dtable gdt, idt; |
| 164 | __u64 cr0, cr2, cr3, cr4, cr8; |
| 165 | __u64 efer; |
| 166 | __u64 apic_base; |
| 167 | __u64 interrupt_bitmap[KVM_IRQ_BITMAP_SIZE(__u64)]; |
| 168 | }; |
| 169 | |
| 170 | struct kvm_msr_entry { |
| 171 | __u32 index; |
| 172 | __u32 reserved; |
| 173 | __u64 data; |
| 174 | }; |
| 175 | |
| 176 | /* for KVM_GET_MSRS and KVM_SET_MSRS */ |
| 177 | struct kvm_msrs { |
Avi Kivity | 6aa8b73 | 2006-12-10 02:21:36 -0800 | [diff] [blame] | 178 | __u32 nmsrs; /* number of msrs in entries */ |
Avi Kivity | bccf215 | 2007-02-21 18:04:26 +0200 | [diff] [blame] | 179 | __u32 pad; |
Avi Kivity | 6aa8b73 | 2006-12-10 02:21:36 -0800 | [diff] [blame] | 180 | |
| 181 | struct kvm_msr_entry entries[0]; |
| 182 | }; |
| 183 | |
| 184 | /* for KVM_GET_MSR_INDEX_LIST */ |
| 185 | struct kvm_msr_list { |
| 186 | __u32 nmsrs; /* number of msrs in entries */ |
| 187 | __u32 indices[0]; |
| 188 | }; |
| 189 | |
| 190 | /* for KVM_TRANSLATE */ |
| 191 | struct kvm_translation { |
| 192 | /* in */ |
| 193 | __u64 linear_address; |
Avi Kivity | 6aa8b73 | 2006-12-10 02:21:36 -0800 | [diff] [blame] | 194 | |
| 195 | /* out */ |
| 196 | __u64 physical_address; |
| 197 | __u8 valid; |
| 198 | __u8 writeable; |
| 199 | __u8 usermode; |
Avi Kivity | 8cd1330 | 2007-02-12 00:54:41 -0800 | [diff] [blame] | 200 | __u8 pad[5]; |
Avi Kivity | 6aa8b73 | 2006-12-10 02:21:36 -0800 | [diff] [blame] | 201 | }; |
| 202 | |
| 203 | /* for KVM_INTERRUPT */ |
| 204 | struct kvm_interrupt { |
| 205 | /* in */ |
Avi Kivity | 6aa8b73 | 2006-12-10 02:21:36 -0800 | [diff] [blame] | 206 | __u32 irq; |
| 207 | }; |
| 208 | |
| 209 | struct kvm_breakpoint { |
| 210 | __u32 enabled; |
| 211 | __u32 padding; |
| 212 | __u64 address; |
| 213 | }; |
| 214 | |
| 215 | /* for KVM_DEBUG_GUEST */ |
| 216 | struct kvm_debug_guest { |
| 217 | /* int */ |
Avi Kivity | 6aa8b73 | 2006-12-10 02:21:36 -0800 | [diff] [blame] | 218 | __u32 enabled; |
Avi Kivity | bccf215 | 2007-02-21 18:04:26 +0200 | [diff] [blame] | 219 | __u32 pad; |
Avi Kivity | 6aa8b73 | 2006-12-10 02:21:36 -0800 | [diff] [blame] | 220 | struct kvm_breakpoint breakpoints[4]; |
| 221 | __u32 singlestep; |
| 222 | }; |
| 223 | |
| 224 | /* for KVM_GET_DIRTY_LOG */ |
| 225 | struct kvm_dirty_log { |
| 226 | __u32 slot; |
| 227 | __u32 padding; |
| 228 | union { |
| 229 | void __user *dirty_bitmap; /* one bit per page */ |
| 230 | __u64 padding; |
| 231 | }; |
| 232 | }; |
| 233 | |
Avi Kivity | 06465c5 | 2007-02-28 20:46:53 +0200 | [diff] [blame] | 234 | struct kvm_cpuid_entry { |
| 235 | __u32 function; |
| 236 | __u32 eax; |
| 237 | __u32 ebx; |
| 238 | __u32 ecx; |
| 239 | __u32 edx; |
| 240 | __u32 padding; |
| 241 | }; |
| 242 | |
| 243 | /* for KVM_SET_CPUID */ |
| 244 | struct kvm_cpuid { |
| 245 | __u32 nent; |
| 246 | __u32 padding; |
| 247 | struct kvm_cpuid_entry entries[0]; |
| 248 | }; |
| 249 | |
Avi Kivity | 1961d27 | 2007-03-05 19:46:05 +0200 | [diff] [blame] | 250 | /* for KVM_SET_SIGNAL_MASK */ |
| 251 | struct kvm_signal_mask { |
| 252 | __u32 len; |
| 253 | __u8 sigset[0]; |
| 254 | }; |
| 255 | |
Avi Kivity | 6aa8b73 | 2006-12-10 02:21:36 -0800 | [diff] [blame] | 256 | #define KVMIO 0xAE |
| 257 | |
Avi Kivity | f17abe9 | 2007-02-21 19:28:04 +0200 | [diff] [blame] | 258 | /* |
| 259 | * ioctls for /dev/kvm fds: |
| 260 | */ |
Avi Kivity | 739872c | 2007-03-01 17:20:13 +0200 | [diff] [blame] | 261 | #define KVM_GET_API_VERSION _IO(KVMIO, 0x00) |
| 262 | #define KVM_CREATE_VM _IO(KVMIO, 0x01) /* returns a VM fd */ |
| 263 | #define KVM_GET_MSR_INDEX_LIST _IOWR(KVMIO, 0x02, struct kvm_msr_list) |
Avi Kivity | 5d308f4 | 2007-03-01 17:56:20 +0200 | [diff] [blame] | 264 | /* |
| 265 | * Check if a kvm extension is available. Argument is extension number, |
| 266 | * return is 1 (yes) or 0 (no, sorry). |
| 267 | */ |
| 268 | #define KVM_CHECK_EXTENSION _IO(KVMIO, 0x03) |
Avi Kivity | 07c45a3 | 2007-03-07 13:05:38 +0200 | [diff] [blame] | 269 | /* |
| 270 | * Get size for mmap(vcpu_fd) |
| 271 | */ |
| 272 | #define KVM_GET_VCPU_MMAP_SIZE _IO(KVMIO, 0x04) /* in bytes */ |
Avi Kivity | f17abe9 | 2007-02-21 19:28:04 +0200 | [diff] [blame] | 273 | |
| 274 | /* |
| 275 | * ioctls for VM fds |
| 276 | */ |
Avi Kivity | 739872c | 2007-03-01 17:20:13 +0200 | [diff] [blame] | 277 | #define KVM_SET_MEMORY_REGION _IOW(KVMIO, 0x40, struct kvm_memory_region) |
Avi Kivity | bccf215 | 2007-02-21 18:04:26 +0200 | [diff] [blame] | 278 | /* |
| 279 | * KVM_CREATE_VCPU receives as a parameter the vcpu slot, and returns |
| 280 | * a vcpu fd. |
| 281 | */ |
Avi Kivity | 739872c | 2007-03-01 17:20:13 +0200 | [diff] [blame] | 282 | #define KVM_CREATE_VCPU _IO(KVMIO, 0x41) |
| 283 | #define KVM_GET_DIRTY_LOG _IOW(KVMIO, 0x42, struct kvm_dirty_log) |
Avi Kivity | e820754 | 2007-03-30 16:54:30 +0300 | [diff] [blame] | 284 | #define KVM_SET_MEMORY_ALIAS _IOW(KVMIO, 0x43, struct kvm_memory_alias) |
Avi Kivity | bccf215 | 2007-02-21 18:04:26 +0200 | [diff] [blame] | 285 | |
| 286 | /* |
| 287 | * ioctls for vcpu fds |
| 288 | */ |
Avi Kivity | 739872c | 2007-03-01 17:20:13 +0200 | [diff] [blame] | 289 | #define KVM_RUN _IO(KVMIO, 0x80) |
| 290 | #define KVM_GET_REGS _IOR(KVMIO, 0x81, struct kvm_regs) |
| 291 | #define KVM_SET_REGS _IOW(KVMIO, 0x82, struct kvm_regs) |
| 292 | #define KVM_GET_SREGS _IOR(KVMIO, 0x83, struct kvm_sregs) |
| 293 | #define KVM_SET_SREGS _IOW(KVMIO, 0x84, struct kvm_sregs) |
| 294 | #define KVM_TRANSLATE _IOWR(KVMIO, 0x85, struct kvm_translation) |
| 295 | #define KVM_INTERRUPT _IOW(KVMIO, 0x86, struct kvm_interrupt) |
| 296 | #define KVM_DEBUG_GUEST _IOW(KVMIO, 0x87, struct kvm_debug_guest) |
| 297 | #define KVM_GET_MSRS _IOWR(KVMIO, 0x88, struct kvm_msrs) |
| 298 | #define KVM_SET_MSRS _IOW(KVMIO, 0x89, struct kvm_msrs) |
| 299 | #define KVM_SET_CPUID _IOW(KVMIO, 0x8a, struct kvm_cpuid) |
Avi Kivity | 1961d27 | 2007-03-05 19:46:05 +0200 | [diff] [blame] | 300 | #define KVM_SET_SIGNAL_MASK _IOW(KVMIO, 0x8b, struct kvm_signal_mask) |
Avi Kivity | b883673 | 2007-04-01 16:34:31 +0300 | [diff] [blame] | 301 | #define KVM_GET_FPU _IOR(KVMIO, 0x8c, struct kvm_fpu) |
| 302 | #define KVM_SET_FPU _IOW(KVMIO, 0x8d, struct kvm_fpu) |
Avi Kivity | 6aa8b73 | 2006-12-10 02:21:36 -0800 | [diff] [blame] | 303 | |
| 304 | #endif |