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