]> git.proxmox.com Git - mirror_ubuntu-zesty-kernel.git/blob - include/linux/kvm.h
KVM: Fold kvm_run::exit_type into kvm_run::exit_reason
[mirror_ubuntu-zesty-kernel.git] / include / linux / kvm.h
1 #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
14 #define KVM_API_VERSION 8
15
16 /*
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 */
26 struct 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
36
37 enum kvm_exit_reason {
38 KVM_EXIT_UNKNOWN = 0,
39 KVM_EXIT_EXCEPTION = 1,
40 KVM_EXIT_IO = 2,
41 KVM_EXIT_HYPERCALL = 3,
42 KVM_EXIT_DEBUG = 4,
43 KVM_EXIT_HLT = 5,
44 KVM_EXIT_MMIO = 6,
45 KVM_EXIT_IRQ_WINDOW_OPEN = 7,
46 KVM_EXIT_SHUTDOWN = 8,
47 KVM_EXIT_FAIL_ENTRY = 9,
48 };
49
50 /* for KVM_RUN, returned by mmap(vcpu_fd, offset=0) */
51 struct kvm_run {
52 /* in */
53 __u32 io_completed; /* mmio/pio request completed */
54 __u8 request_interrupt_window;
55 __u8 padding1[3];
56
57 /* out */
58 __u32 exit_reason;
59 __u32 instruction_length;
60 __u8 ready_for_interrupt_injection;
61 __u8 if_flag;
62 __u8 padding2[6];
63
64 /* in (pre_kvm_run), out (post_kvm_run) */
65 __u64 cr8;
66 __u64 apic_base;
67
68 union {
69 /* KVM_EXIT_UNKNOWN */
70 struct {
71 __u64 hardware_exit_reason;
72 } hw;
73 /* KVM_EXIT_FAIL_ENTRY */
74 struct {
75 __u64 hardware_entry_failure_reason;
76 } fail_entry;
77 /* KVM_EXIT_EXCEPTION */
78 struct {
79 __u32 exception;
80 __u32 error_code;
81 } ex;
82 /* KVM_EXIT_IO */
83 struct kvm_io {
84 #define KVM_EXIT_IO_IN 0
85 #define KVM_EXIT_IO_OUT 1
86 __u8 direction;
87 __u8 size; /* bytes */
88 __u8 string;
89 __u8 string_down;
90 __u8 rep;
91 __u8 pad;
92 __u16 port;
93 __u64 count;
94 union {
95 __u64 address;
96 __u32 value;
97 };
98 } io;
99 struct {
100 } debug;
101 /* KVM_EXIT_MMIO */
102 struct {
103 __u64 phys_addr;
104 __u8 data[8];
105 __u32 len;
106 __u8 is_write;
107 } mmio;
108 /* KVM_EXIT_HYPERCALL */
109 struct {
110 __u64 args[6];
111 __u64 ret;
112 __u32 longmode;
113 __u32 pad;
114 } hypercall;
115 };
116 };
117
118 /* for KVM_GET_REGS and KVM_SET_REGS */
119 struct kvm_regs {
120 /* out (KVM_GET_REGS) / in (KVM_SET_REGS) */
121 __u64 rax, rbx, rcx, rdx;
122 __u64 rsi, rdi, rsp, rbp;
123 __u64 r8, r9, r10, r11;
124 __u64 r12, r13, r14, r15;
125 __u64 rip, rflags;
126 };
127
128 struct kvm_segment {
129 __u64 base;
130 __u32 limit;
131 __u16 selector;
132 __u8 type;
133 __u8 present, dpl, db, s, l, g, avl;
134 __u8 unusable;
135 __u8 padding;
136 };
137
138 struct kvm_dtable {
139 __u64 base;
140 __u16 limit;
141 __u16 padding[3];
142 };
143
144 /* for KVM_GET_SREGS and KVM_SET_SREGS */
145 struct kvm_sregs {
146 /* out (KVM_GET_SREGS) / in (KVM_SET_SREGS) */
147 struct kvm_segment cs, ds, es, fs, gs, ss;
148 struct kvm_segment tr, ldt;
149 struct kvm_dtable gdt, idt;
150 __u64 cr0, cr2, cr3, cr4, cr8;
151 __u64 efer;
152 __u64 apic_base;
153 __u64 interrupt_bitmap[KVM_IRQ_BITMAP_SIZE(__u64)];
154 };
155
156 struct kvm_msr_entry {
157 __u32 index;
158 __u32 reserved;
159 __u64 data;
160 };
161
162 /* for KVM_GET_MSRS and KVM_SET_MSRS */
163 struct kvm_msrs {
164 __u32 nmsrs; /* number of msrs in entries */
165 __u32 pad;
166
167 struct kvm_msr_entry entries[0];
168 };
169
170 /* for KVM_GET_MSR_INDEX_LIST */
171 struct kvm_msr_list {
172 __u32 nmsrs; /* number of msrs in entries */
173 __u32 indices[0];
174 };
175
176 /* for KVM_TRANSLATE */
177 struct kvm_translation {
178 /* in */
179 __u64 linear_address;
180
181 /* out */
182 __u64 physical_address;
183 __u8 valid;
184 __u8 writeable;
185 __u8 usermode;
186 __u8 pad[5];
187 };
188
189 /* for KVM_INTERRUPT */
190 struct kvm_interrupt {
191 /* in */
192 __u32 irq;
193 };
194
195 struct kvm_breakpoint {
196 __u32 enabled;
197 __u32 padding;
198 __u64 address;
199 };
200
201 /* for KVM_DEBUG_GUEST */
202 struct kvm_debug_guest {
203 /* int */
204 __u32 enabled;
205 __u32 pad;
206 struct kvm_breakpoint breakpoints[4];
207 __u32 singlestep;
208 };
209
210 /* for KVM_GET_DIRTY_LOG */
211 struct kvm_dirty_log {
212 __u32 slot;
213 __u32 padding;
214 union {
215 void __user *dirty_bitmap; /* one bit per page */
216 __u64 padding;
217 };
218 };
219
220 struct kvm_cpuid_entry {
221 __u32 function;
222 __u32 eax;
223 __u32 ebx;
224 __u32 ecx;
225 __u32 edx;
226 __u32 padding;
227 };
228
229 /* for KVM_SET_CPUID */
230 struct kvm_cpuid {
231 __u32 nent;
232 __u32 padding;
233 struct kvm_cpuid_entry entries[0];
234 };
235
236 #define KVMIO 0xAE
237
238 /*
239 * ioctls for /dev/kvm fds:
240 */
241 #define KVM_GET_API_VERSION _IO(KVMIO, 0x00)
242 #define KVM_CREATE_VM _IO(KVMIO, 0x01) /* returns a VM fd */
243 #define KVM_GET_MSR_INDEX_LIST _IOWR(KVMIO, 0x02, struct kvm_msr_list)
244 /*
245 * Check if a kvm extension is available. Argument is extension number,
246 * return is 1 (yes) or 0 (no, sorry).
247 */
248 #define KVM_CHECK_EXTENSION _IO(KVMIO, 0x03)
249
250 /*
251 * ioctls for VM fds
252 */
253 #define KVM_SET_MEMORY_REGION _IOW(KVMIO, 0x40, struct kvm_memory_region)
254 /*
255 * KVM_CREATE_VCPU receives as a parameter the vcpu slot, and returns
256 * a vcpu fd.
257 */
258 #define KVM_CREATE_VCPU _IO(KVMIO, 0x41)
259 #define KVM_GET_DIRTY_LOG _IOW(KVMIO, 0x42, struct kvm_dirty_log)
260
261 /*
262 * ioctls for vcpu fds
263 */
264 #define KVM_RUN _IO(KVMIO, 0x80)
265 #define KVM_GET_REGS _IOR(KVMIO, 0x81, struct kvm_regs)
266 #define KVM_SET_REGS _IOW(KVMIO, 0x82, struct kvm_regs)
267 #define KVM_GET_SREGS _IOR(KVMIO, 0x83, struct kvm_sregs)
268 #define KVM_SET_SREGS _IOW(KVMIO, 0x84, struct kvm_sregs)
269 #define KVM_TRANSLATE _IOWR(KVMIO, 0x85, struct kvm_translation)
270 #define KVM_INTERRUPT _IOW(KVMIO, 0x86, struct kvm_interrupt)
271 #define KVM_DEBUG_GUEST _IOW(KVMIO, 0x87, struct kvm_debug_guest)
272 #define KVM_GET_MSRS _IOWR(KVMIO, 0x88, struct kvm_msrs)
273 #define KVM_SET_MSRS _IOW(KVMIO, 0x89, struct kvm_msrs)
274 #define KVM_SET_CPUID _IOW(KVMIO, 0x8a, struct kvm_cpuid)
275
276 #endif