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 12
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
36 struct kvm_memory_alias
{
37 __u32 slot
; /* this has a different namespace than memory slots */
39 __u64 guest_phys_addr
;
41 __u64 target_phys_addr
;
44 enum kvm_exit_reason
{
46 KVM_EXIT_EXCEPTION
= 1,
48 KVM_EXIT_HYPERCALL
= 3,
52 KVM_EXIT_IRQ_WINDOW_OPEN
= 7,
53 KVM_EXIT_SHUTDOWN
= 8,
54 KVM_EXIT_FAIL_ENTRY
= 9,
58 /* for KVM_RUN, returned by mmap(vcpu_fd, offset=0) */
61 __u8 request_interrupt_window
;
66 __u8 ready_for_interrupt_injection
;
70 /* in (pre_kvm_run), out (post_kvm_run) */
75 /* KVM_EXIT_UNKNOWN */
77 __u64 hardware_exit_reason
;
79 /* KVM_EXIT_FAIL_ENTRY */
81 __u64 hardware_entry_failure_reason
;
83 /* KVM_EXIT_EXCEPTION */
90 #define KVM_EXIT_IO_IN 0
91 #define KVM_EXIT_IO_OUT 1
93 __u8 size
; /* bytes */
96 __u64 data_offset
; /* relative to kvm_run start */
107 /* KVM_EXIT_HYPERCALL */
117 /* for KVM_GET_REGS and KVM_SET_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
;
127 /* for KVM_GET_FPU and KVM_SET_FPU */
132 __u8 ftwx
; /* in fxsave format */
147 __u8 present
, dpl
, db
, s
, l
, g
, avl
;
158 /* for KVM_GET_SREGS and KVM_SET_SREGS */
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
;
167 __u64 interrupt_bitmap
[KVM_IRQ_BITMAP_SIZE(__u64
)];
170 struct kvm_msr_entry
{
176 /* for KVM_GET_MSRS and KVM_SET_MSRS */
178 __u32 nmsrs
; /* number of msrs in entries */
181 struct kvm_msr_entry entries
[0];
184 /* for KVM_GET_MSR_INDEX_LIST */
185 struct kvm_msr_list
{
186 __u32 nmsrs
; /* number of msrs in entries */
190 /* for KVM_TRANSLATE */
191 struct kvm_translation
{
193 __u64 linear_address
;
196 __u64 physical_address
;
203 /* for KVM_INTERRUPT */
204 struct kvm_interrupt
{
209 struct kvm_breakpoint
{
215 /* for KVM_DEBUG_GUEST */
216 struct kvm_debug_guest
{
220 struct kvm_breakpoint breakpoints
[4];
224 /* for KVM_GET_DIRTY_LOG */
225 struct kvm_dirty_log
{
229 void __user
*dirty_bitmap
; /* one bit per page */
234 struct kvm_cpuid_entry
{
243 /* for KVM_SET_CPUID */
247 struct kvm_cpuid_entry entries
[0];
250 /* for KVM_SET_SIGNAL_MASK */
251 struct kvm_signal_mask
{
259 * ioctls for /dev/kvm fds:
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)
265 * Check if a kvm extension is available. Argument is extension number,
266 * return is 1 (yes) or 0 (no, sorry).
268 #define KVM_CHECK_EXTENSION _IO(KVMIO, 0x03)
270 * Get size for mmap(vcpu_fd)
272 #define KVM_GET_VCPU_MMAP_SIZE _IO(KVMIO, 0x04) /* in bytes */
277 #define KVM_SET_MEMORY_REGION _IOW(KVMIO, 0x40, struct kvm_memory_region)
279 * KVM_CREATE_VCPU receives as a parameter the vcpu slot, and returns
282 #define KVM_CREATE_VCPU _IO(KVMIO, 0x41)
283 #define KVM_GET_DIRTY_LOG _IOW(KVMIO, 0x42, struct kvm_dirty_log)
284 #define KVM_SET_MEMORY_ALIAS _IOW(KVMIO, 0x43, struct kvm_memory_alias)
287 * ioctls for vcpu fds
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)
300 #define KVM_SET_SIGNAL_MASK _IOW(KVMIO, 0x8b, struct kvm_signal_mask)
301 #define KVM_GET_FPU _IOR(KVMIO, 0x8c, struct kvm_fpu)
302 #define KVM_SET_FPU _IOW(KVMIO, 0x8d, struct kvm_fpu)