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 /* for KVM_IRQ_LINE */
38 struct kvm_irq_level
{
40 * ACPI gsi notion of irq.
41 * For IA-64 (APIC model) IOAPIC0: irq 0-23; IOAPIC1: irq 24-47..
42 * For X86 (standard AT mode) PIC0/1: irq 0-15. IOAPIC0: 0-23..
48 /* for KVM_GET_IRQCHIP and KVM_SET_IRQCHIP */
49 struct kvm_pic_state
{
50 __u8 last_irr
; /* edge detection */
51 __u8 irr
; /* interrupt request register */
52 __u8 imr
; /* interrupt mask register */
53 __u8 isr
; /* interrupt service register */
54 __u8 priority_add
; /* highest irq priority */
61 __u8 rotate_on_auto_eoi
;
62 __u8 special_fully_nested_mode
;
63 __u8 init4
; /* true if 4 byte init */
64 __u8 elcr
; /* PIIX edge/trigger selection */
68 #define KVM_IOAPIC_NUM_PINS 24
69 struct kvm_ioapic_state
{
81 __u8 delivery_status
:1;
90 } redirtbl
[KVM_IOAPIC_NUM_PINS
];
93 #define KVM_IRQCHIP_PIC_MASTER 0
94 #define KVM_IRQCHIP_PIC_SLAVE 1
95 #define KVM_IRQCHIP_IOAPIC 2
101 char dummy
[512]; /* reserving space */
102 struct kvm_pic_state pic
;
103 struct kvm_ioapic_state ioapic
;
107 #define KVM_EXIT_UNKNOWN 0
108 #define KVM_EXIT_EXCEPTION 1
109 #define KVM_EXIT_IO 2
110 #define KVM_EXIT_HYPERCALL 3
111 #define KVM_EXIT_DEBUG 4
112 #define KVM_EXIT_HLT 5
113 #define KVM_EXIT_MMIO 6
114 #define KVM_EXIT_IRQ_WINDOW_OPEN 7
115 #define KVM_EXIT_SHUTDOWN 8
116 #define KVM_EXIT_FAIL_ENTRY 9
117 #define KVM_EXIT_INTR 10
118 #define KVM_EXIT_SET_TPR 11
120 /* for KVM_RUN, returned by mmap(vcpu_fd, offset=0) */
123 __u8 request_interrupt_window
;
128 __u8 ready_for_interrupt_injection
;
132 /* in (pre_kvm_run), out (post_kvm_run) */
137 /* KVM_EXIT_UNKNOWN */
139 __u64 hardware_exit_reason
;
141 /* KVM_EXIT_FAIL_ENTRY */
143 __u64 hardware_entry_failure_reason
;
145 /* KVM_EXIT_EXCEPTION */
152 #define KVM_EXIT_IO_IN 0
153 #define KVM_EXIT_IO_OUT 1
155 __u8 size
; /* bytes */
158 __u64 data_offset
; /* relative to kvm_run start */
169 /* KVM_EXIT_HYPERCALL */
177 /* Fix the size of the union. */
182 /* for KVM_GET_REGS and KVM_SET_REGS */
184 /* out (KVM_GET_REGS) / in (KVM_SET_REGS) */
185 __u64 rax
, rbx
, rcx
, rdx
;
186 __u64 rsi
, rdi
, rsp
, rbp
;
187 __u64 r8
, r9
, r10
, r11
;
188 __u64 r12
, r13
, r14
, r15
;
192 /* for KVM_GET_FPU and KVM_SET_FPU */
197 __u8 ftwx
; /* in fxsave format */
207 /* for KVM_GET_LAPIC and KVM_SET_LAPIC */
208 #define KVM_APIC_REG_SIZE 0x400
209 struct kvm_lapic_state
{
210 char regs
[KVM_APIC_REG_SIZE
];
218 __u8 present
, dpl
, db
, s
, l
, g
, avl
;
229 /* for KVM_GET_SREGS and KVM_SET_SREGS */
231 /* out (KVM_GET_SREGS) / in (KVM_SET_SREGS) */
232 struct kvm_segment cs
, ds
, es
, fs
, gs
, ss
;
233 struct kvm_segment tr
, ldt
;
234 struct kvm_dtable gdt
, idt
;
235 __u64 cr0
, cr2
, cr3
, cr4
, cr8
;
238 __u64 interrupt_bitmap
[(KVM_NR_INTERRUPTS
+ 63) / 64];
241 struct kvm_msr_entry
{
247 /* for KVM_GET_MSRS and KVM_SET_MSRS */
249 __u32 nmsrs
; /* number of msrs in entries */
252 struct kvm_msr_entry entries
[0];
255 /* for KVM_GET_MSR_INDEX_LIST */
256 struct kvm_msr_list
{
257 __u32 nmsrs
; /* number of msrs in entries */
261 /* for KVM_TRANSLATE */
262 struct kvm_translation
{
264 __u64 linear_address
;
267 __u64 physical_address
;
274 /* for KVM_INTERRUPT */
275 struct kvm_interrupt
{
280 struct kvm_breakpoint
{
286 /* for KVM_DEBUG_GUEST */
287 struct kvm_debug_guest
{
291 struct kvm_breakpoint breakpoints
[4];
295 /* for KVM_GET_DIRTY_LOG */
296 struct kvm_dirty_log
{
300 void __user
*dirty_bitmap
; /* one bit per page */
305 struct kvm_cpuid_entry
{
314 /* for KVM_SET_CPUID */
318 struct kvm_cpuid_entry entries
[0];
321 /* for KVM_SET_SIGNAL_MASK */
322 struct kvm_signal_mask
{
330 * ioctls for /dev/kvm fds:
332 #define KVM_GET_API_VERSION _IO(KVMIO, 0x00)
333 #define KVM_CREATE_VM _IO(KVMIO, 0x01) /* returns a VM fd */
334 #define KVM_GET_MSR_INDEX_LIST _IOWR(KVMIO, 0x02, struct kvm_msr_list)
336 * Check if a kvm extension is available. Argument is extension number,
337 * return is 1 (yes) or 0 (no, sorry).
339 #define KVM_CHECK_EXTENSION _IO(KVMIO, 0x03)
341 * Get size for mmap(vcpu_fd)
343 #define KVM_GET_VCPU_MMAP_SIZE _IO(KVMIO, 0x04) /* in bytes */
346 * Extension capability list.
348 #define KVM_CAP_IRQCHIP 0
349 #define KVM_CAP_HLT 1
354 #define KVM_SET_MEMORY_REGION _IOW(KVMIO, 0x40, struct kvm_memory_region)
356 * KVM_CREATE_VCPU receives as a parameter the vcpu slot, and returns
359 #define KVM_CREATE_VCPU _IO(KVMIO, 0x41)
360 #define KVM_GET_DIRTY_LOG _IOW(KVMIO, 0x42, struct kvm_dirty_log)
361 #define KVM_SET_MEMORY_ALIAS _IOW(KVMIO, 0x43, struct kvm_memory_alias)
362 /* Device model IOC */
363 #define KVM_CREATE_IRQCHIP _IO(KVMIO, 0x60)
364 #define KVM_IRQ_LINE _IOW(KVMIO, 0x61, struct kvm_irq_level)
365 #define KVM_GET_IRQCHIP _IOWR(KVMIO, 0x62, struct kvm_irqchip)
366 #define KVM_SET_IRQCHIP _IOR(KVMIO, 0x63, struct kvm_irqchip)
369 * ioctls for vcpu fds
371 #define KVM_RUN _IO(KVMIO, 0x80)
372 #define KVM_GET_REGS _IOR(KVMIO, 0x81, struct kvm_regs)
373 #define KVM_SET_REGS _IOW(KVMIO, 0x82, struct kvm_regs)
374 #define KVM_GET_SREGS _IOR(KVMIO, 0x83, struct kvm_sregs)
375 #define KVM_SET_SREGS _IOW(KVMIO, 0x84, struct kvm_sregs)
376 #define KVM_TRANSLATE _IOWR(KVMIO, 0x85, struct kvm_translation)
377 #define KVM_INTERRUPT _IOW(KVMIO, 0x86, struct kvm_interrupt)
378 #define KVM_DEBUG_GUEST _IOW(KVMIO, 0x87, struct kvm_debug_guest)
379 #define KVM_GET_MSRS _IOWR(KVMIO, 0x88, struct kvm_msrs)
380 #define KVM_SET_MSRS _IOW(KVMIO, 0x89, struct kvm_msrs)
381 #define KVM_SET_CPUID _IOW(KVMIO, 0x8a, struct kvm_cpuid)
382 #define KVM_SET_SIGNAL_MASK _IOW(KVMIO, 0x8b, struct kvm_signal_mask)
383 #define KVM_GET_FPU _IOR(KVMIO, 0x8c, struct kvm_fpu)
384 #define KVM_SET_FPU _IOW(KVMIO, 0x8d, struct kvm_fpu)
385 #define KVM_GET_LAPIC _IOR(KVMIO, 0x8e, struct kvm_lapic_state)
386 #define KVM_SET_LAPIC _IOW(KVMIO, 0x8f, struct kvm_lapic_state)