KVM: Communicate cr8 changes to userspace
[deliverable/linux.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: you must update KVM_API_VERSION if you change this interface.
8 */
9
10 #include <asm/types.h>
11 #include <linux/ioctl.h>
12
13 #define KVM_API_VERSION 12
14
15 /* Architectural interrupt line count. */
16 #define KVM_NR_INTERRUPTS 256
17
18 /* for KVM_CREATE_MEMORY_REGION */
19 struct kvm_memory_region {
20 __u32 slot;
21 __u32 flags;
22 __u64 guest_phys_addr;
23 __u64 memory_size; /* bytes */
24 };
25
26 /* for kvm_memory_region::flags */
27 #define KVM_MEM_LOG_DIRTY_PAGES 1UL
28
29 struct kvm_memory_alias {
30 __u32 slot; /* this has a different namespace than memory slots */
31 __u32 flags;
32 __u64 guest_phys_addr;
33 __u64 memory_size;
34 __u64 target_phys_addr;
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 KVM_EXIT_INTR = 10,
49 KVM_EXIT_SET_TPR = 11
50 };
51
52 /* for KVM_RUN, returned by mmap(vcpu_fd, offset=0) */
53 struct kvm_run {
54 /* in */
55 __u8 request_interrupt_window;
56 __u8 padding1[7];
57
58 /* out */
59 __u32 exit_reason;
60 __u8 ready_for_interrupt_injection;
61 __u8 if_flag;
62 __u8 padding2[2];
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 __u16 port;
89 __u32 count;
90 __u64 data_offset; /* relative to kvm_run start */
91 } io;
92 struct {
93 } debug;
94 /* KVM_EXIT_MMIO */
95 struct {
96 __u64 phys_addr;
97 __u8 data[8];
98 __u32 len;
99 __u8 is_write;
100 } mmio;
101 /* KVM_EXIT_HYPERCALL */
102 struct {
103 __u64 nr;
104 __u64 args[6];
105 __u64 ret;
106 __u32 longmode;
107 __u32 pad;
108 } hypercall;
109 /* Fix the size of the union. */
110 char padding[256];
111 };
112 };
113
114 /* for KVM_GET_REGS and KVM_SET_REGS */
115 struct kvm_regs {
116 /* out (KVM_GET_REGS) / in (KVM_SET_REGS) */
117 __u64 rax, rbx, rcx, rdx;
118 __u64 rsi, rdi, rsp, rbp;
119 __u64 r8, r9, r10, r11;
120 __u64 r12, r13, r14, r15;
121 __u64 rip, rflags;
122 };
123
124 /* for KVM_GET_FPU and KVM_SET_FPU */
125 struct kvm_fpu {
126 __u8 fpr[8][16];
127 __u16 fcw;
128 __u16 fsw;
129 __u8 ftwx; /* in fxsave format */
130 __u8 pad1;
131 __u16 last_opcode;
132 __u64 last_ip;
133 __u64 last_dp;
134 __u8 xmm[16][16];
135 __u32 mxcsr;
136 __u32 pad2;
137 };
138
139 struct kvm_segment {
140 __u64 base;
141 __u32 limit;
142 __u16 selector;
143 __u8 type;
144 __u8 present, dpl, db, s, l, g, avl;
145 __u8 unusable;
146 __u8 padding;
147 };
148
149 struct kvm_dtable {
150 __u64 base;
151 __u16 limit;
152 __u16 padding[3];
153 };
154
155 /* for KVM_GET_SREGS and KVM_SET_SREGS */
156 struct kvm_sregs {
157 /* out (KVM_GET_SREGS) / in (KVM_SET_SREGS) */
158 struct kvm_segment cs, ds, es, fs, gs, ss;
159 struct kvm_segment tr, ldt;
160 struct kvm_dtable gdt, idt;
161 __u64 cr0, cr2, cr3, cr4, cr8;
162 __u64 efer;
163 __u64 apic_base;
164 __u64 interrupt_bitmap[(KVM_NR_INTERRUPTS + 63) / 64];
165 };
166
167 struct kvm_msr_entry {
168 __u32 index;
169 __u32 reserved;
170 __u64 data;
171 };
172
173 /* for KVM_GET_MSRS and KVM_SET_MSRS */
174 struct kvm_msrs {
175 __u32 nmsrs; /* number of msrs in entries */
176 __u32 pad;
177
178 struct kvm_msr_entry entries[0];
179 };
180
181 /* for KVM_GET_MSR_INDEX_LIST */
182 struct kvm_msr_list {
183 __u32 nmsrs; /* number of msrs in entries */
184 __u32 indices[0];
185 };
186
187 /* for KVM_TRANSLATE */
188 struct kvm_translation {
189 /* in */
190 __u64 linear_address;
191
192 /* out */
193 __u64 physical_address;
194 __u8 valid;
195 __u8 writeable;
196 __u8 usermode;
197 __u8 pad[5];
198 };
199
200 /* for KVM_INTERRUPT */
201 struct kvm_interrupt {
202 /* in */
203 __u32 irq;
204 };
205
206 struct kvm_breakpoint {
207 __u32 enabled;
208 __u32 padding;
209 __u64 address;
210 };
211
212 /* for KVM_DEBUG_GUEST */
213 struct kvm_debug_guest {
214 /* int */
215 __u32 enabled;
216 __u32 pad;
217 struct kvm_breakpoint breakpoints[4];
218 __u32 singlestep;
219 };
220
221 /* for KVM_GET_DIRTY_LOG */
222 struct kvm_dirty_log {
223 __u32 slot;
224 __u32 padding;
225 union {
226 void __user *dirty_bitmap; /* one bit per page */
227 __u64 padding;
228 };
229 };
230
231 struct kvm_cpuid_entry {
232 __u32 function;
233 __u32 eax;
234 __u32 ebx;
235 __u32 ecx;
236 __u32 edx;
237 __u32 padding;
238 };
239
240 /* for KVM_SET_CPUID */
241 struct kvm_cpuid {
242 __u32 nent;
243 __u32 padding;
244 struct kvm_cpuid_entry entries[0];
245 };
246
247 /* for KVM_SET_SIGNAL_MASK */
248 struct kvm_signal_mask {
249 __u32 len;
250 __u8 sigset[0];
251 };
252
253 #define KVMIO 0xAE
254
255 /*
256 * ioctls for /dev/kvm fds:
257 */
258 #define KVM_GET_API_VERSION _IO(KVMIO, 0x00)
259 #define KVM_CREATE_VM _IO(KVMIO, 0x01) /* returns a VM fd */
260 #define KVM_GET_MSR_INDEX_LIST _IOWR(KVMIO, 0x02, struct kvm_msr_list)
261 /*
262 * Check if a kvm extension is available. Argument is extension number,
263 * return is 1 (yes) or 0 (no, sorry).
264 */
265 #define KVM_CHECK_EXTENSION _IO(KVMIO, 0x03)
266 /*
267 * Get size for mmap(vcpu_fd)
268 */
269 #define KVM_GET_VCPU_MMAP_SIZE _IO(KVMIO, 0x04) /* in bytes */
270
271 /*
272 * ioctls for VM fds
273 */
274 #define KVM_SET_MEMORY_REGION _IOW(KVMIO, 0x40, struct kvm_memory_region)
275 /*
276 * KVM_CREATE_VCPU receives as a parameter the vcpu slot, and returns
277 * a vcpu fd.
278 */
279 #define KVM_CREATE_VCPU _IO(KVMIO, 0x41)
280 #define KVM_GET_DIRTY_LOG _IOW(KVMIO, 0x42, struct kvm_dirty_log)
281 #define KVM_SET_MEMORY_ALIAS _IOW(KVMIO, 0x43, struct kvm_memory_alias)
282
283 /*
284 * ioctls for vcpu fds
285 */
286 #define KVM_RUN _IO(KVMIO, 0x80)
287 #define KVM_GET_REGS _IOR(KVMIO, 0x81, struct kvm_regs)
288 #define KVM_SET_REGS _IOW(KVMIO, 0x82, struct kvm_regs)
289 #define KVM_GET_SREGS _IOR(KVMIO, 0x83, struct kvm_sregs)
290 #define KVM_SET_SREGS _IOW(KVMIO, 0x84, struct kvm_sregs)
291 #define KVM_TRANSLATE _IOWR(KVMIO, 0x85, struct kvm_translation)
292 #define KVM_INTERRUPT _IOW(KVMIO, 0x86, struct kvm_interrupt)
293 #define KVM_DEBUG_GUEST _IOW(KVMIO, 0x87, struct kvm_debug_guest)
294 #define KVM_GET_MSRS _IOWR(KVMIO, 0x88, struct kvm_msrs)
295 #define KVM_SET_MSRS _IOW(KVMIO, 0x89, struct kvm_msrs)
296 #define KVM_SET_CPUID _IOW(KVMIO, 0x8a, struct kvm_cpuid)
297 #define KVM_SET_SIGNAL_MASK _IOW(KVMIO, 0x8b, struct kvm_signal_mask)
298 #define KVM_GET_FPU _IOR(KVMIO, 0x8c, struct kvm_fpu)
299 #define KVM_SET_FPU _IOW(KVMIO, 0x8d, struct kvm_fpu)
300
301 #endif
This page took 0.070095 seconds and 5 git commands to generate.