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/compiler.h>
12 #include <linux/ioctl.h>
15 #define KVM_API_VERSION 12
17 /* for KVM_CREATE_MEMORY_REGION */
18 struct kvm_memory_region
{
21 __u64 guest_phys_addr
;
22 __u64 memory_size
; /* bytes */
25 /* for KVM_SET_USER_MEMORY_REGION */
26 struct kvm_userspace_memory_region
{
29 __u64 guest_phys_addr
;
30 __u64 memory_size
; /* bytes */
31 __u64 userspace_addr
; /* start of the userspace allocated memory */
34 /* for kvm_memory_region::flags */
35 #define KVM_MEM_LOG_DIRTY_PAGES 1UL
38 /* for KVM_IRQ_LINE */
39 struct kvm_irq_level
{
41 * ACPI gsi notion of irq.
42 * For IA-64 (APIC model) IOAPIC0: irq 0-23; IOAPIC1: irq 24-47..
43 * For X86 (standard AT mode) PIC0/1: irq 0-15. IOAPIC0: 0-23..
54 char dummy
[512]; /* reserving space */
56 struct kvm_pic_state pic
;
58 #if defined(CONFIG_X86) || defined(CONFIG_IA64)
59 struct kvm_ioapic_state ioapic
;
64 #define KVM_EXIT_UNKNOWN 0
65 #define KVM_EXIT_EXCEPTION 1
67 #define KVM_EXIT_HYPERCALL 3
68 #define KVM_EXIT_DEBUG 4
69 #define KVM_EXIT_HLT 5
70 #define KVM_EXIT_MMIO 6
71 #define KVM_EXIT_IRQ_WINDOW_OPEN 7
72 #define KVM_EXIT_SHUTDOWN 8
73 #define KVM_EXIT_FAIL_ENTRY 9
74 #define KVM_EXIT_INTR 10
75 #define KVM_EXIT_SET_TPR 11
76 #define KVM_EXIT_TPR_ACCESS 12
77 #define KVM_EXIT_S390_SIEIC 13
79 /* for KVM_RUN, returned by mmap(vcpu_fd, offset=0) */
82 __u8 request_interrupt_window
;
87 __u8 ready_for_interrupt_injection
;
91 /* in (pre_kvm_run), out (post_kvm_run) */
96 /* KVM_EXIT_UNKNOWN */
98 __u64 hardware_exit_reason
;
100 /* KVM_EXIT_FAIL_ENTRY */
102 __u64 hardware_entry_failure_reason
;
104 /* KVM_EXIT_EXCEPTION */
111 #define KVM_EXIT_IO_IN 0
112 #define KVM_EXIT_IO_OUT 1
114 __u8 size
; /* bytes */
117 __u64 data_offset
; /* relative to kvm_run start */
128 /* KVM_EXIT_HYPERCALL */
136 /* KVM_EXIT_TPR_ACCESS */
142 /* KVM_EXIT_S390_SIEIC */
145 __u64 mask
; /* psw upper half */
146 __u64 addr
; /* psw lower half */
150 /* Fix the size of the union. */
155 /* for KVM_TRANSLATE */
156 struct kvm_translation
{
158 __u64 linear_address
;
161 __u64 physical_address
;
168 /* for KVM_INTERRUPT */
169 struct kvm_interrupt
{
174 struct kvm_breakpoint
{
180 /* for KVM_DEBUG_GUEST */
181 struct kvm_debug_guest
{
185 struct kvm_breakpoint breakpoints
[4];
189 /* for KVM_GET_DIRTY_LOG */
190 struct kvm_dirty_log
{
194 void __user
*dirty_bitmap
; /* one bit per page */
199 /* for KVM_SET_SIGNAL_MASK */
200 struct kvm_signal_mask
{
205 /* for KVM_TPR_ACCESS_REPORTING */
206 struct kvm_tpr_access_ctl
{
212 /* for KVM_SET_VAPIC_ADDR */
213 struct kvm_vapic_addr
{
217 struct kvm_s390_psw
{
225 * ioctls for /dev/kvm fds:
227 #define KVM_GET_API_VERSION _IO(KVMIO, 0x00)
228 #define KVM_CREATE_VM _IO(KVMIO, 0x01) /* returns a VM fd */
229 #define KVM_GET_MSR_INDEX_LIST _IOWR(KVMIO, 0x02, struct kvm_msr_list)
231 #define KVM_S390_ENABLE_SIE _IO(KVMIO, 0x06)
233 * Check if a kvm extension is available. Argument is extension number,
234 * return is 1 (yes) or 0 (no, sorry).
236 #define KVM_CHECK_EXTENSION _IO(KVMIO, 0x03)
238 * Get size for mmap(vcpu_fd)
240 #define KVM_GET_VCPU_MMAP_SIZE _IO(KVMIO, 0x04) /* in bytes */
241 #define KVM_GET_SUPPORTED_CPUID _IOWR(KVMIO, 0x05, struct kvm_cpuid2)
244 * Extension capability list.
246 #define KVM_CAP_IRQCHIP 0
247 #define KVM_CAP_HLT 1
248 #define KVM_CAP_MMU_SHADOW_CACHE_CONTROL 2
249 #define KVM_CAP_USER_MEMORY 3
250 #define KVM_CAP_SET_TSS_ADDR 4
251 #define KVM_CAP_VAPIC 6
252 #define KVM_CAP_EXT_CPUID 7
253 #define KVM_CAP_CLOCKSOURCE 8
254 #define KVM_CAP_NR_VCPUS 9 /* returns max vcpus per vm */
255 #define KVM_CAP_NR_MEMSLOTS 10 /* returns max memory slots per vm */
256 #define KVM_CAP_PIT 11
257 #define KVM_CAP_NOP_IO_DELAY 12
258 #define KVM_CAP_PV_MMU 13
263 #define KVM_SET_MEMORY_REGION _IOW(KVMIO, 0x40, struct kvm_memory_region)
264 #define KVM_SET_NR_MMU_PAGES _IO(KVMIO, 0x44)
265 #define KVM_GET_NR_MMU_PAGES _IO(KVMIO, 0x45)
266 #define KVM_SET_USER_MEMORY_REGION _IOW(KVMIO, 0x46,\
267 struct kvm_userspace_memory_region)
268 #define KVM_SET_TSS_ADDR _IO(KVMIO, 0x47)
270 * KVM_CREATE_VCPU receives as a parameter the vcpu slot, and returns
273 #define KVM_CREATE_VCPU _IO(KVMIO, 0x41)
274 #define KVM_GET_DIRTY_LOG _IOW(KVMIO, 0x42, struct kvm_dirty_log)
275 #define KVM_SET_MEMORY_ALIAS _IOW(KVMIO, 0x43, struct kvm_memory_alias)
276 /* Device model IOC */
277 #define KVM_CREATE_IRQCHIP _IO(KVMIO, 0x60)
278 #define KVM_IRQ_LINE _IOW(KVMIO, 0x61, struct kvm_irq_level)
279 #define KVM_GET_IRQCHIP _IOWR(KVMIO, 0x62, struct kvm_irqchip)
280 #define KVM_SET_IRQCHIP _IOR(KVMIO, 0x63, struct kvm_irqchip)
281 #define KVM_CREATE_PIT _IO(KVMIO, 0x64)
282 #define KVM_GET_PIT _IOWR(KVMIO, 0x65, struct kvm_pit_state)
283 #define KVM_SET_PIT _IOR(KVMIO, 0x66, struct kvm_pit_state)
286 * ioctls for vcpu fds
288 #define KVM_RUN _IO(KVMIO, 0x80)
289 #define KVM_GET_REGS _IOR(KVMIO, 0x81, struct kvm_regs)
290 #define KVM_SET_REGS _IOW(KVMIO, 0x82, struct kvm_regs)
291 #define KVM_GET_SREGS _IOR(KVMIO, 0x83, struct kvm_sregs)
292 #define KVM_SET_SREGS _IOW(KVMIO, 0x84, struct kvm_sregs)
293 #define KVM_TRANSLATE _IOWR(KVMIO, 0x85, struct kvm_translation)
294 #define KVM_INTERRUPT _IOW(KVMIO, 0x86, struct kvm_interrupt)
295 #define KVM_DEBUG_GUEST _IOW(KVMIO, 0x87, struct kvm_debug_guest)
296 #define KVM_GET_MSRS _IOWR(KVMIO, 0x88, struct kvm_msrs)
297 #define KVM_SET_MSRS _IOW(KVMIO, 0x89, struct kvm_msrs)
298 #define KVM_SET_CPUID _IOW(KVMIO, 0x8a, struct kvm_cpuid)
299 #define KVM_SET_SIGNAL_MASK _IOW(KVMIO, 0x8b, struct kvm_signal_mask)
300 #define KVM_GET_FPU _IOR(KVMIO, 0x8c, struct kvm_fpu)
301 #define KVM_SET_FPU _IOW(KVMIO, 0x8d, struct kvm_fpu)
302 #define KVM_GET_LAPIC _IOR(KVMIO, 0x8e, struct kvm_lapic_state)
303 #define KVM_SET_LAPIC _IOW(KVMIO, 0x8f, struct kvm_lapic_state)
304 #define KVM_SET_CPUID2 _IOW(KVMIO, 0x90, struct kvm_cpuid2)
305 #define KVM_GET_CPUID2 _IOWR(KVMIO, 0x91, struct kvm_cpuid2)
306 /* Available with KVM_CAP_VAPIC */
307 #define KVM_TPR_ACCESS_REPORTING _IOWR(KVMIO, 0x92, struct kvm_tpr_access_ctl)
308 /* Available with KVM_CAP_VAPIC */
309 #define KVM_SET_VAPIC_ADDR _IOW(KVMIO, 0x93, struct kvm_vapic_addr)
310 /* store status for s390 */
311 #define KVM_S390_STORE_STATUS_NOADDR (-1ul)
312 #define KVM_S390_STORE_STATUS_PREFIXED (-2ul)
313 #define KVM_S390_STORE_STATUS _IOW(KVMIO, 0x95, unsigned long)
314 /* initial ipl psw for s390 */
315 #define KVM_S390_SET_INITIAL_PSW _IOW(KVMIO, 0x96, struct kvm_s390_psw)
316 /* initial reset for s390 */
317 #define KVM_S390_INITIAL_RESET _IO(KVMIO, 0x97)