5 * Userspace interface for /dev/kvm - kernel based virtual machine
7 * Note: you must update KVM_API_VERSION if you change this interface.
10 #include <asm/types.h>
11 #include <linux/ioctl.h>
13 #define KVM_API_VERSION 12
15 /* Architectural interrupt line count. */
16 #define KVM_NR_INTERRUPTS 256
18 /* for KVM_CREATE_MEMORY_REGION */
19 struct kvm_memory_region {
22 __u64 guest_phys_addr;
23 __u64 memory_size; /* bytes */
26 /* for kvm_memory_region::flags */
27 #define KVM_MEM_LOG_DIRTY_PAGES 1UL
29 struct kvm_memory_alias {
30 __u32 slot; /* this has a different namespace than memory slots */
32 __u64 guest_phys_addr;
34 __u64 target_phys_addr;
37 enum kvm_exit_reason {
39 KVM_EXIT_EXCEPTION = 1,
41 KVM_EXIT_HYPERCALL = 3,
45 KVM_EXIT_IRQ_WINDOW_OPEN = 7,
46 KVM_EXIT_SHUTDOWN = 8,
47 KVM_EXIT_FAIL_ENTRY = 9,
52 /* for KVM_RUN, returned by mmap(vcpu_fd, offset=0) */
55 __u8 request_interrupt_window;
60 __u8 ready_for_interrupt_injection;
64 /* in (pre_kvm_run), out (post_kvm_run) */
69 /* KVM_EXIT_UNKNOWN */
71 __u64 hardware_exit_reason;
73 /* KVM_EXIT_FAIL_ENTRY */
75 __u64 hardware_entry_failure_reason;
77 /* KVM_EXIT_EXCEPTION */
84 #define KVM_EXIT_IO_IN 0
85 #define KVM_EXIT_IO_OUT 1
87 __u8 size; /* bytes */
90 __u64 data_offset; /* relative to kvm_run start */
101 /* KVM_EXIT_HYPERCALL */
109 /* Fix the size of the union. */
114 /* for KVM_GET_REGS and KVM_SET_REGS */
116 /* out (KVM_GET_REGS) / in (KVM_SET_REGS) */
117 __u64 rax, rbx, rcx, rdx;
118 __u64 rsi, rdi, rsp, rbp;
119 __u64 r8, r9, r10, r11;
120 __u64 r12, r13, r14, r15;
124 /* for KVM_GET_FPU and KVM_SET_FPU */
129 __u8 ftwx; /* in fxsave format */
144 __u8 present, dpl, db, s, l, g, avl;
155 /* for KVM_GET_SREGS and KVM_SET_SREGS */
157 /* out (KVM_GET_SREGS) / in (KVM_SET_SREGS) */
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;
164 __u64 interrupt_bitmap[(KVM_NR_INTERRUPTS + 63) / 64];
167 struct kvm_msr_entry {
173 /* for KVM_GET_MSRS and KVM_SET_MSRS */
175 __u32 nmsrs; /* number of msrs in entries */
178 struct kvm_msr_entry entries[0];
181 /* for KVM_GET_MSR_INDEX_LIST */
182 struct kvm_msr_list {
183 __u32 nmsrs; /* number of msrs in entries */
187 /* for KVM_TRANSLATE */
188 struct kvm_translation {
190 __u64 linear_address;
193 __u64 physical_address;
200 /* for KVM_INTERRUPT */
201 struct kvm_interrupt {
206 struct kvm_breakpoint {
212 /* for KVM_DEBUG_GUEST */
213 struct kvm_debug_guest {
217 struct kvm_breakpoint breakpoints[4];
221 /* for KVM_GET_DIRTY_LOG */
222 struct kvm_dirty_log {
226 void __user *dirty_bitmap; /* one bit per page */
231 struct kvm_cpuid_entry {
240 /* for KVM_SET_CPUID */
244 struct kvm_cpuid_entry entries[0];
247 /* for KVM_SET_SIGNAL_MASK */
248 struct kvm_signal_mask {
256 * ioctls for /dev/kvm fds:
258 #define KVM_GET_API_VERSION _IO(KVMIO, 0x00)
259 #define KVM_CREATE_VM _IO(KVMIO, 0x01) /* returns a VM fd */
260 #define KVM_GET_MSR_INDEX_LIST _IOWR(KVMIO, 0x02, struct kvm_msr_list)
262 * Check if a kvm extension is available. Argument is extension number,
263 * return is 1 (yes) or 0 (no, sorry).
265 #define KVM_CHECK_EXTENSION _IO(KVMIO, 0x03)
267 * Get size for mmap(vcpu_fd)
269 #define KVM_GET_VCPU_MMAP_SIZE _IO(KVMIO, 0x04) /* in bytes */
274 #define KVM_SET_MEMORY_REGION _IOW(KVMIO, 0x40, struct kvm_memory_region)
276 * KVM_CREATE_VCPU receives as a parameter the vcpu slot, and returns
279 #define KVM_CREATE_VCPU _IO(KVMIO, 0x41)
280 #define KVM_GET_DIRTY_LOG _IOW(KVMIO, 0x42, struct kvm_dirty_log)
281 #define KVM_SET_MEMORY_ALIAS _IOW(KVMIO, 0x43, struct kvm_memory_alias)
284 * ioctls for vcpu fds
286 #define KVM_RUN _IO(KVMIO, 0x80)
287 #define KVM_GET_REGS _IOR(KVMIO, 0x81, struct kvm_regs)
288 #define KVM_SET_REGS _IOW(KVMIO, 0x82, struct kvm_regs)
289 #define KVM_GET_SREGS _IOR(KVMIO, 0x83, struct kvm_sregs)
290 #define KVM_SET_SREGS _IOW(KVMIO, 0x84, struct kvm_sregs)
291 #define KVM_TRANSLATE _IOWR(KVMIO, 0x85, struct kvm_translation)
292 #define KVM_INTERRUPT _IOW(KVMIO, 0x86, struct kvm_interrupt)
293 #define KVM_DEBUG_GUEST _IOW(KVMIO, 0x87, struct kvm_debug_guest)
294 #define KVM_GET_MSRS _IOWR(KVMIO, 0x88, struct kvm_msrs)
295 #define KVM_SET_MSRS _IOW(KVMIO, 0x89, struct kvm_msrs)
296 #define KVM_SET_CPUID _IOW(KVMIO, 0x8a, struct kvm_cpuid)
297 #define KVM_SET_SIGNAL_MASK _IOW(KVMIO, 0x8b, struct kvm_signal_mask)
298 #define KVM_GET_FPU _IOR(KVMIO, 0x8c, struct kvm_fpu)
299 #define KVM_SET_FPU _IOW(KVMIO, 0x8d, struct kvm_fpu)