blob: e6edca81ab847f54ff920b2b4b346e3ec60400c1 [file] [log] [blame]
Avi Kivity6aa8b732006-12-10 02:21:36 -08001#ifndef __LINUX_KVM_H
2#define __LINUX_KVM_H
3
4/*
5 * Userspace interface for /dev/kvm - kernel based virtual machine
6 *
7 * Note: this interface is considered experimental and may change without
8 * notice.
9 */
10
11#include <asm/types.h>
12#include <linux/ioctl.h>
13
Avi Kivity2ff81f72007-04-29 16:25:49 +030014#define KVM_API_VERSION 12
Avi Kivity0b76e202006-12-22 01:06:02 -080015
Avi Kivity6aa8b732006-12-10 02:21:36 -080016/*
17 * Architectural interrupt line count, and the size of the bitmap needed
18 * to hold them.
19 */
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))
23
24
25/* for KVM_CREATE_MEMORY_REGION */
26struct kvm_memory_region {
27 __u32 slot;
28 __u32 flags;
29 __u64 guest_phys_addr;
30 __u64 memory_size; /* bytes */
31};
32
33/* for kvm_memory_region::flags */
34#define KVM_MEM_LOG_DIRTY_PAGES 1UL
35
Avi Kivitye8207542007-03-30 16:54:30 +030036struct kvm_memory_alias {
37 __u32 slot; /* this has a different namespace than memory slots */
38 __u32 flags;
39 __u64 guest_phys_addr;
40 __u64 memory_size;
41 __u64 target_phys_addr;
42};
Avi Kivity6aa8b732006-12-10 02:21:36 -080043
Avi Kivity6aa8b732006-12-10 02:21:36 -080044enum kvm_exit_reason {
45 KVM_EXIT_UNKNOWN = 0,
46 KVM_EXIT_EXCEPTION = 1,
47 KVM_EXIT_IO = 2,
Avi Kivityb4e63f52007-03-04 13:59:30 +020048 KVM_EXIT_HYPERCALL = 3,
Avi Kivity6aa8b732006-12-10 02:21:36 -080049 KVM_EXIT_DEBUG = 4,
50 KVM_EXIT_HLT = 5,
51 KVM_EXIT_MMIO = 6,
Dor Laorc1150d82007-01-05 16:36:24 -080052 KVM_EXIT_IRQ_WINDOW_OPEN = 7,
Joerg Roedel46fe4dd2007-01-26 00:56:42 -080053 KVM_EXIT_SHUTDOWN = 8,
Avi Kivity8eb7d332007-03-04 14:17:08 +020054 KVM_EXIT_FAIL_ENTRY = 9,
Avi Kivity1b19f3e2007-03-04 14:24:03 +020055 KVM_EXIT_INTR = 10,
Avi Kivity6aa8b732006-12-10 02:21:36 -080056};
57
Avi Kivity9a2bb7f2007-02-22 12:58:31 +020058/* for KVM_RUN, returned by mmap(vcpu_fd, offset=0) */
Avi Kivity6aa8b732006-12-10 02:21:36 -080059struct kvm_run {
60 /* in */
Dor Laorc1150d82007-01-05 16:36:24 -080061 __u8 request_interrupt_window;
Avi Kivity02c83202007-04-29 15:02:17 +030062 __u8 padding1[7];
Avi Kivity6aa8b732006-12-10 02:21:36 -080063
64 /* out */
Avi Kivity6aa8b732006-12-10 02:21:36 -080065 __u32 exit_reason;
Dor Laorc1150d82007-01-05 16:36:24 -080066 __u8 ready_for_interrupt_injection;
67 __u8 if_flag;
Avi Kivity2ff81f72007-04-29 16:25:49 +030068 __u8 padding2[2];
Dor Laor54810342007-02-12 00:54:39 -080069
70 /* in (pre_kvm_run), out (post_kvm_run) */
Dor Laorc1150d82007-01-05 16:36:24 -080071 __u64 cr8;
72 __u64 apic_base;
73
Avi Kivity6aa8b732006-12-10 02:21:36 -080074 union {
75 /* KVM_EXIT_UNKNOWN */
76 struct {
Avi Kivity8eb7d332007-03-04 14:17:08 +020077 __u64 hardware_exit_reason;
Avi Kivity6aa8b732006-12-10 02:21:36 -080078 } hw;
Avi Kivity8eb7d332007-03-04 14:17:08 +020079 /* KVM_EXIT_FAIL_ENTRY */
80 struct {
81 __u64 hardware_entry_failure_reason;
82 } fail_entry;
Avi Kivity6aa8b732006-12-10 02:21:36 -080083 /* KVM_EXIT_EXCEPTION */
84 struct {
85 __u32 exception;
86 __u32 error_code;
87 } ex;
88 /* KVM_EXIT_IO */
Avi Kivity46fc1472007-02-22 19:39:30 +020089 struct kvm_io {
Avi Kivity6aa8b732006-12-10 02:21:36 -080090#define KVM_EXIT_IO_IN 0
91#define KVM_EXIT_IO_OUT 1
92 __u8 direction;
93 __u8 size; /* bytes */
Avi Kivity6aa8b732006-12-10 02:21:36 -080094 __u16 port;
Avi Kivity039576c2007-03-20 12:46:50 +020095 __u32 count;
96 __u64 data_offset; /* relative to kvm_run start */
Avi Kivity6aa8b732006-12-10 02:21:36 -080097 } io;
98 struct {
99 } debug;
100 /* KVM_EXIT_MMIO */
101 struct {
102 __u64 phys_addr;
103 __u8 data[8];
104 __u32 len;
105 __u8 is_write;
106 } mmio;
Avi Kivityb4e63f52007-03-04 13:59:30 +0200107 /* KVM_EXIT_HYPERCALL */
108 struct {
109 __u64 args[6];
110 __u64 ret;
111 __u32 longmode;
112 __u32 pad;
113 } hypercall;
Avi Kivity6aa8b732006-12-10 02:21:36 -0800114 };
115};
116
117/* for KVM_GET_REGS and KVM_SET_REGS */
118struct kvm_regs {
Avi Kivity6aa8b732006-12-10 02:21:36 -0800119 /* 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;
124 __u64 rip, rflags;
125};
126
Avi Kivityb8836732007-04-01 16:34:31 +0300127/* for KVM_GET_FPU and KVM_SET_FPU */
128struct kvm_fpu {
129 __u8 fpr[8][16];
130 __u16 fcw;
131 __u16 fsw;
132 __u8 ftwx; /* in fxsave format */
133 __u8 pad1;
134 __u16 last_opcode;
135 __u64 last_ip;
136 __u64 last_dp;
137 __u8 xmm[16][16];
138 __u32 mxcsr;
139 __u32 pad2;
140};
141
Avi Kivity6aa8b732006-12-10 02:21:36 -0800142struct kvm_segment {
143 __u64 base;
144 __u32 limit;
145 __u16 selector;
146 __u8 type;
147 __u8 present, dpl, db, s, l, g, avl;
148 __u8 unusable;
149 __u8 padding;
150};
151
152struct kvm_dtable {
153 __u64 base;
154 __u16 limit;
155 __u16 padding[3];
156};
157
158/* for KVM_GET_SREGS and KVM_SET_SREGS */
159struct kvm_sregs {
Avi Kivity6aa8b732006-12-10 02:21:36 -0800160 /* 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;
165 __u64 efer;
166 __u64 apic_base;
167 __u64 interrupt_bitmap[KVM_IRQ_BITMAP_SIZE(__u64)];
168};
169
170struct kvm_msr_entry {
171 __u32 index;
172 __u32 reserved;
173 __u64 data;
174};
175
176/* for KVM_GET_MSRS and KVM_SET_MSRS */
177struct kvm_msrs {
Avi Kivity6aa8b732006-12-10 02:21:36 -0800178 __u32 nmsrs; /* number of msrs in entries */
Avi Kivitybccf2152007-02-21 18:04:26 +0200179 __u32 pad;
Avi Kivity6aa8b732006-12-10 02:21:36 -0800180
181 struct kvm_msr_entry entries[0];
182};
183
184/* for KVM_GET_MSR_INDEX_LIST */
185struct kvm_msr_list {
186 __u32 nmsrs; /* number of msrs in entries */
187 __u32 indices[0];
188};
189
190/* for KVM_TRANSLATE */
191struct kvm_translation {
192 /* in */
193 __u64 linear_address;
Avi Kivity6aa8b732006-12-10 02:21:36 -0800194
195 /* out */
196 __u64 physical_address;
197 __u8 valid;
198 __u8 writeable;
199 __u8 usermode;
Avi Kivity8cd13302007-02-12 00:54:41 -0800200 __u8 pad[5];
Avi Kivity6aa8b732006-12-10 02:21:36 -0800201};
202
203/* for KVM_INTERRUPT */
204struct kvm_interrupt {
205 /* in */
Avi Kivity6aa8b732006-12-10 02:21:36 -0800206 __u32 irq;
207};
208
209struct kvm_breakpoint {
210 __u32 enabled;
211 __u32 padding;
212 __u64 address;
213};
214
215/* for KVM_DEBUG_GUEST */
216struct kvm_debug_guest {
217 /* int */
Avi Kivity6aa8b732006-12-10 02:21:36 -0800218 __u32 enabled;
Avi Kivitybccf2152007-02-21 18:04:26 +0200219 __u32 pad;
Avi Kivity6aa8b732006-12-10 02:21:36 -0800220 struct kvm_breakpoint breakpoints[4];
221 __u32 singlestep;
222};
223
224/* for KVM_GET_DIRTY_LOG */
225struct kvm_dirty_log {
226 __u32 slot;
227 __u32 padding;
228 union {
229 void __user *dirty_bitmap; /* one bit per page */
230 __u64 padding;
231 };
232};
233
Avi Kivity06465c52007-02-28 20:46:53 +0200234struct kvm_cpuid_entry {
235 __u32 function;
236 __u32 eax;
237 __u32 ebx;
238 __u32 ecx;
239 __u32 edx;
240 __u32 padding;
241};
242
243/* for KVM_SET_CPUID */
244struct kvm_cpuid {
245 __u32 nent;
246 __u32 padding;
247 struct kvm_cpuid_entry entries[0];
248};
249
Avi Kivity1961d272007-03-05 19:46:05 +0200250/* for KVM_SET_SIGNAL_MASK */
251struct kvm_signal_mask {
252 __u32 len;
253 __u8 sigset[0];
254};
255
Avi Kivity6aa8b732006-12-10 02:21:36 -0800256#define KVMIO 0xAE
257
Avi Kivityf17abe92007-02-21 19:28:04 +0200258/*
259 * ioctls for /dev/kvm fds:
260 */
Avi Kivity739872c2007-03-01 17:20:13 +0200261#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)
Avi Kivity5d308f42007-03-01 17:56:20 +0200264/*
265 * Check if a kvm extension is available. Argument is extension number,
266 * return is 1 (yes) or 0 (no, sorry).
267 */
268#define KVM_CHECK_EXTENSION _IO(KVMIO, 0x03)
Avi Kivity07c45a32007-03-07 13:05:38 +0200269/*
270 * Get size for mmap(vcpu_fd)
271 */
272#define KVM_GET_VCPU_MMAP_SIZE _IO(KVMIO, 0x04) /* in bytes */
Avi Kivityf17abe92007-02-21 19:28:04 +0200273
274/*
275 * ioctls for VM fds
276 */
Avi Kivity739872c2007-03-01 17:20:13 +0200277#define KVM_SET_MEMORY_REGION _IOW(KVMIO, 0x40, struct kvm_memory_region)
Avi Kivitybccf2152007-02-21 18:04:26 +0200278/*
279 * KVM_CREATE_VCPU receives as a parameter the vcpu slot, and returns
280 * a vcpu fd.
281 */
Avi Kivity739872c2007-03-01 17:20:13 +0200282#define KVM_CREATE_VCPU _IO(KVMIO, 0x41)
283#define KVM_GET_DIRTY_LOG _IOW(KVMIO, 0x42, struct kvm_dirty_log)
Avi Kivitye8207542007-03-30 16:54:30 +0300284#define KVM_SET_MEMORY_ALIAS _IOW(KVMIO, 0x43, struct kvm_memory_alias)
Avi Kivitybccf2152007-02-21 18:04:26 +0200285
286/*
287 * ioctls for vcpu fds
288 */
Avi Kivity739872c2007-03-01 17:20:13 +0200289#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)
Avi Kivity1961d272007-03-05 19:46:05 +0200300#define KVM_SET_SIGNAL_MASK _IOW(KVMIO, 0x8b, struct kvm_signal_mask)
Avi Kivityb8836732007-04-01 16:34:31 +0300301#define KVM_GET_FPU _IOR(KVMIO, 0x8c, struct kvm_fpu)
302#define KVM_SET_FPU _IOW(KVMIO, 0x8d, struct kvm_fpu)
Avi Kivity6aa8b732006-12-10 02:21:36 -0800303
304#endif