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>
15 * Architectural interrupt line count, and the size of the bitmap needed
18 #define KVM_NR_INTERRUPTS 256
19 #define KVM_IRQ_BITMAP_SIZE_BYTES ((KVM_NR_INTERRUPTS + 7) / 8)
20 #define KVM_IRQ_BITMAP_SIZE(type) (KVM_IRQ_BITMAP_SIZE_BYTES / sizeof(type))
23 /* for KVM_CREATE_MEMORY_REGION */
24 struct kvm_memory_region
{
27 __u64 guest_phys_addr
;
28 __u64 memory_size
; /* bytes */
31 /* for kvm_memory_region::flags */
32 #define KVM_MEM_LOG_DIRTY_PAGES 1UL
35 #define KVM_EXIT_TYPE_FAIL_ENTRY 1
36 #define KVM_EXIT_TYPE_VM_EXIT 2
38 enum kvm_exit_reason
{
40 KVM_EXIT_EXCEPTION
= 1,
52 __u32 emulated
; /* skip current instruction */
53 __u32 mmio_completed
; /* mmio request completed */
58 __u32 instruction_length
;
60 /* KVM_EXIT_UNKNOWN */
62 __u32 hardware_exit_reason
;
64 /* KVM_EXIT_EXCEPTION */
71 #define KVM_EXIT_IO_IN 0
72 #define KVM_EXIT_IO_OUT 1
74 __u8 size
; /* bytes */
98 /* for KVM_GET_REGS and KVM_SET_REGS */
104 /* out (KVM_GET_REGS) / in (KVM_SET_REGS) */
105 __u64 rax
, rbx
, rcx
, rdx
;
106 __u64 rsi
, rdi
, rsp
, rbp
;
107 __u64 r8
, r9
, r10
, r11
;
108 __u64 r12
, r13
, r14
, r15
;
117 __u8 present
, dpl
, db
, s
, l
, g
, avl
;
128 /* for KVM_GET_SREGS and KVM_SET_SREGS */
134 /* out (KVM_GET_SREGS) / in (KVM_SET_SREGS) */
135 struct kvm_segment cs
, ds
, es
, fs
, gs
, ss
;
136 struct kvm_segment tr
, ldt
;
137 struct kvm_dtable gdt
, idt
;
138 __u64 cr0
, cr2
, cr3
, cr4
, cr8
;
141 __u64 interrupt_bitmap
[KVM_IRQ_BITMAP_SIZE(__u64
)];
144 struct kvm_msr_entry
{
150 /* for KVM_GET_MSRS and KVM_SET_MSRS */
153 __u32 nmsrs
; /* number of msrs in entries */
155 struct kvm_msr_entry entries
[0];
158 /* for KVM_GET_MSR_INDEX_LIST */
159 struct kvm_msr_list
{
160 __u32 nmsrs
; /* number of msrs in entries */
164 /* for KVM_TRANSLATE */
165 struct kvm_translation
{
167 __u64 linear_address
;
172 __u64 physical_address
;
178 /* for KVM_INTERRUPT */
179 struct kvm_interrupt
{
185 struct kvm_breakpoint
{
191 /* for KVM_DEBUG_GUEST */
192 struct kvm_debug_guest
{
196 struct kvm_breakpoint breakpoints
[4];
200 /* for KVM_GET_DIRTY_LOG */
201 struct kvm_dirty_log
{
205 void __user
*dirty_bitmap
; /* one bit per page */
212 #define KVM_RUN _IOWR(KVMIO, 2, struct kvm_run)
213 #define KVM_GET_REGS _IOWR(KVMIO, 3, struct kvm_regs)
214 #define KVM_SET_REGS _IOW(KVMIO, 4, struct kvm_regs)
215 #define KVM_GET_SREGS _IOWR(KVMIO, 5, struct kvm_sregs)
216 #define KVM_SET_SREGS _IOW(KVMIO, 6, struct kvm_sregs)
217 #define KVM_TRANSLATE _IOWR(KVMIO, 7, struct kvm_translation)
218 #define KVM_INTERRUPT _IOW(KVMIO, 8, struct kvm_interrupt)
219 #define KVM_DEBUG_GUEST _IOW(KVMIO, 9, struct kvm_debug_guest)
220 #define KVM_SET_MEMORY_REGION _IOW(KVMIO, 10, struct kvm_memory_region)
221 #define KVM_CREATE_VCPU _IOW(KVMIO, 11, int /* vcpu_slot */)
222 #define KVM_GET_DIRTY_LOG _IOW(KVMIO, 12, struct kvm_dirty_log)
223 #define KVM_GET_MSRS _IOWR(KVMIO, 13, struct kvm_msrs)
224 #define KVM_SET_MSRS _IOWR(KVMIO, 14, struct kvm_msrs)
225 #define KVM_GET_MSR_INDEX_LIST _IOWR(KVMIO, 15, struct kvm_msr_list)