5 * Userspace interface for /dev/kvm - kernel based virtual machine
7 * Note: this interface is considered experimental and may change without
11 #include <asm/types.h>
12 #include <linux/ioctl.h>
14 #define KVM_API_VERSION 1
17 * Architectural interrupt line count, and the size of the bitmap needed
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))
25 /* for KVM_CREATE_MEMORY_REGION */
26 struct kvm_memory_region {
29 __u64 guest_phys_addr;
30 __u64 memory_size; /* bytes */
33 /* for kvm_memory_region::flags */
34 #define KVM_MEM_LOG_DIRTY_PAGES 1UL
37 #define KVM_EXIT_TYPE_FAIL_ENTRY 1
38 #define KVM_EXIT_TYPE_VM_EXIT 2
40 enum kvm_exit_reason {
42 KVM_EXIT_EXCEPTION = 1,
54 __u32 emulated; /* skip current instruction */
55 __u32 mmio_completed; /* mmio request completed */
60 __u32 instruction_length;
62 /* KVM_EXIT_UNKNOWN */
64 __u32 hardware_exit_reason;
66 /* KVM_EXIT_EXCEPTION */
73 #define KVM_EXIT_IO_IN 0
74 #define KVM_EXIT_IO_OUT 1
76 __u8 size; /* bytes */
100 /* for KVM_GET_REGS and KVM_SET_REGS */
106 /* out (KVM_GET_REGS) / in (KVM_SET_REGS) */
107 __u64 rax, rbx, rcx, rdx;
108 __u64 rsi, rdi, rsp, rbp;
109 __u64 r8, r9, r10, r11;
110 __u64 r12, r13, r14, r15;
119 __u8 present, dpl, db, s, l, g, avl;
130 /* for KVM_GET_SREGS and KVM_SET_SREGS */
136 /* out (KVM_GET_SREGS) / in (KVM_SET_SREGS) */
137 struct kvm_segment cs, ds, es, fs, gs, ss;
138 struct kvm_segment tr, ldt;
139 struct kvm_dtable gdt, idt;
140 __u64 cr0, cr2, cr3, cr4, cr8;
143 __u64 interrupt_bitmap[KVM_IRQ_BITMAP_SIZE(__u64)];
146 struct kvm_msr_entry {
152 /* for KVM_GET_MSRS and KVM_SET_MSRS */
155 __u32 nmsrs; /* number of msrs in entries */
157 struct kvm_msr_entry entries[0];
160 /* for KVM_GET_MSR_INDEX_LIST */
161 struct kvm_msr_list {
162 __u32 nmsrs; /* number of msrs in entries */
166 /* for KVM_TRANSLATE */
167 struct kvm_translation {
169 __u64 linear_address;
174 __u64 physical_address;
180 /* for KVM_INTERRUPT */
181 struct kvm_interrupt {
187 struct kvm_breakpoint {
193 /* for KVM_DEBUG_GUEST */
194 struct kvm_debug_guest {
198 struct kvm_breakpoint breakpoints[4];
202 /* for KVM_GET_DIRTY_LOG */
203 struct kvm_dirty_log {
207 void __user *dirty_bitmap; /* one bit per page */
214 #define KVM_GET_API_VERSION _IO(KVMIO, 1)
215 #define KVM_RUN _IOWR(KVMIO, 2, struct kvm_run)
216 #define KVM_GET_REGS _IOWR(KVMIO, 3, struct kvm_regs)
217 #define KVM_SET_REGS _IOW(KVMIO, 4, struct kvm_regs)
218 #define KVM_GET_SREGS _IOWR(KVMIO, 5, struct kvm_sregs)
219 #define KVM_SET_SREGS _IOW(KVMIO, 6, struct kvm_sregs)
220 #define KVM_TRANSLATE _IOWR(KVMIO, 7, struct kvm_translation)
221 #define KVM_INTERRUPT _IOW(KVMIO, 8, struct kvm_interrupt)
222 #define KVM_DEBUG_GUEST _IOW(KVMIO, 9, struct kvm_debug_guest)
223 #define KVM_SET_MEMORY_REGION _IOW(KVMIO, 10, struct kvm_memory_region)
224 #define KVM_CREATE_VCPU _IOW(KVMIO, 11, int /* vcpu_slot */)
225 #define KVM_GET_DIRTY_LOG _IOW(KVMIO, 12, struct kvm_dirty_log)
226 #define KVM_GET_MSRS _IOWR(KVMIO, 13, struct kvm_msrs)
227 #define KVM_SET_MSRS _IOWR(KVMIO, 14, struct kvm_msrs)
228 #define KVM_GET_MSR_INDEX_LIST _IOWR(KVMIO, 15, struct kvm_msr_list)