aboutsummaryrefslogtreecommitdiffstats
path: root/include/linux/kvm.h
diff options
context:
space:
mode:
authorAvi Kivity <avi@qumranet.com>2006-12-10 05:21:36 -0500
committerLinus Torvalds <torvalds@woody.osdl.org>2006-12-10 12:57:22 -0500
commit6aa8b732ca01c3d7a54e93f4d701b8aabbe60fb7 (patch)
tree23fcbe6f4918cacdae26d513a2bd13e91d8b4c38 /include/linux/kvm.h
parentf5f1a24a2caa299bb7d294aee92d7dd3410d9ed7 (diff)
[PATCH] kvm: userspace interface
web site: http://kvm.sourceforge.net mailing list: kvm-devel@lists.sourceforge.net (http://lists.sourceforge.net/lists/listinfo/kvm-devel) The following patchset adds a driver for Intel's hardware virtualization extensions to the x86 architecture. The driver adds a character device (/dev/kvm) that exposes the virtualization capabilities to userspace. Using this driver, a process can run a virtual machine (a "guest") in a fully virtualized PC containing its own virtual hard disks, network adapters, and display. Using this driver, one can start multiple virtual machines on a host. Each virtual machine is a process on the host; a virtual cpu is a thread in that process. kill(1), nice(1), top(1) work as expected. In effect, the driver adds a third execution mode to the existing two: we now have kernel mode, user mode, and guest mode. Guest mode has its own address space mapping guest physical memory (which is accessible to user mode by mmap()ing /dev/kvm). Guest mode has no access to any I/O devices; any such access is intercepted and directed to user mode for emulation. The driver supports i386 and x86_64 hosts and guests. All combinations are allowed except x86_64 guest on i386 host. For i386 guests and hosts, both pae and non-pae paging modes are supported. SMP hosts and UP guests are supported. At the moment only Intel hardware is supported, but AMD virtualization support is being worked on. Performance currently is non-stellar due to the naive implementation of the mmu virtualization, which throws away most of the shadow page table entries every context switch. We plan to address this in two ways: - cache shadow page tables across tlb flushes - wait until AMD and Intel release processors with nested page tables Currently a virtual desktop is responsive but consumes a lot of CPU. Under Windows I tried playing pinball and watching a few flash movies; with a recent CPU one can hardly feel the virtualization. Linux/X is slower, probably due to X being in a separate process. In addition to the driver, you need a slightly modified qemu to provide I/O device emulation and the BIOS. Caveats (akpm: might no longer be true): - The Windows install currently bluescreens due to a problem with the virtual APIC. We are working on a fix. A temporary workaround is to use an existing image or install through qemu - Windows 64-bit does not work. That's also true for qemu, so it's probably a problem with the device model. [bero@arklinux.org: build fix] [simon.kagstrom@bth.se: build fix, other fixes] [uril@qumranet.com: KVM: Expose interrupt bitmap] [akpm@osdl.org: i386 build fix] [mingo@elte.hu: i386 fixes] [rdreier@cisco.com: add log levels to all printks] [randy.dunlap@oracle.com: Fix sparse NULL and C99 struct init warnings] [anthony@codemonkey.ws: KVM: AMD SVM: 32-bit host support] Signed-off-by: Yaniv Kamay <yaniv@qumranet.com> Signed-off-by: Avi Kivity <avi@qumranet.com> Cc: Simon Kagstrom <simon.kagstrom@bth.se> Cc: Bernhard Rosenkraenzer <bero@arklinux.org> Signed-off-by: Uri Lublin <uril@qumranet.com> Cc: Ingo Molnar <mingo@elte.hu> Cc: Roland Dreier <rolandd@cisco.com> Signed-off-by: Randy Dunlap <randy.dunlap@oracle.com> Signed-off-by: Anthony Liguori <anthony@codemonkey.ws> Signed-off-by: Andrew Morton <akpm@osdl.org> Signed-off-by: Linus Torvalds <torvalds@osdl.org>
Diffstat (limited to 'include/linux/kvm.h')
-rw-r--r--include/linux/kvm.h227
1 files changed, 227 insertions, 0 deletions
diff --git a/include/linux/kvm.h b/include/linux/kvm.h
new file mode 100644
index 000000000000..5bb2c3c585c1
--- /dev/null
+++ b/include/linux/kvm.h
@@ -0,0 +1,227 @@
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/*
15 * Architectural interrupt line count, and the size of the bitmap needed
16 * to hold them.
17 */
18#define KVM_NR_INTERRUPTS 256
19#define KVM_IRQ_BITMAP_SIZE_BYTES ((KVM_NR_INTERRUPTS + 7) / 8)
20#define KVM_IRQ_BITMAP_SIZE(type) (KVM_IRQ_BITMAP_SIZE_BYTES / sizeof(type))
21
22
23/* for KVM_CREATE_MEMORY_REGION */
24struct kvm_memory_region {
25 __u32 slot;
26 __u32 flags;
27 __u64 guest_phys_addr;
28 __u64 memory_size; /* bytes */
29};
30
31/* for kvm_memory_region::flags */
32#define KVM_MEM_LOG_DIRTY_PAGES 1UL
33
34
35#define KVM_EXIT_TYPE_FAIL_ENTRY 1
36#define KVM_EXIT_TYPE_VM_EXIT 2
37
38enum kvm_exit_reason {
39 KVM_EXIT_UNKNOWN = 0,
40 KVM_EXIT_EXCEPTION = 1,
41 KVM_EXIT_IO = 2,
42 KVM_EXIT_CPUID = 3,
43 KVM_EXIT_DEBUG = 4,
44 KVM_EXIT_HLT = 5,
45 KVM_EXIT_MMIO = 6,
46};
47
48/* for KVM_RUN */
49struct kvm_run {
50 /* in */
51 __u32 vcpu;
52 __u32 emulated; /* skip current instruction */
53 __u32 mmio_completed; /* mmio request completed */
54
55 /* out */
56 __u32 exit_type;
57 __u32 exit_reason;
58 __u32 instruction_length;
59 union {
60 /* KVM_EXIT_UNKNOWN */
61 struct {
62 __u32 hardware_exit_reason;
63 } hw;
64 /* KVM_EXIT_EXCEPTION */
65 struct {
66 __u32 exception;
67 __u32 error_code;
68 } ex;
69 /* KVM_EXIT_IO */
70 struct {
71#define KVM_EXIT_IO_IN 0
72#define KVM_EXIT_IO_OUT 1
73 __u8 direction;
74 __u8 size; /* bytes */
75 __u8 string;
76 __u8 string_down;
77 __u8 rep;
78 __u8 pad;
79 __u16 port;
80 __u64 count;
81 union {
82 __u64 address;
83 __u32 value;
84 };
85 } io;
86 struct {
87 } debug;
88 /* KVM_EXIT_MMIO */
89 struct {
90 __u64 phys_addr;
91 __u8 data[8];
92 __u32 len;
93 __u8 is_write;
94 } mmio;
95 };
96};
97
98/* for KVM_GET_REGS and KVM_SET_REGS */
99struct kvm_regs {
100 /* in */
101 __u32 vcpu;
102 __u32 padding;
103
104 /* out (KVM_GET_REGS) / in (KVM_SET_REGS) */
105 __u64 rax, rbx, rcx, rdx;
106 __u64 rsi, rdi, rsp, rbp;
107 __u64 r8, r9, r10, r11;
108 __u64 r12, r13, r14, r15;
109 __u64 rip, rflags;
110};
111
112struct kvm_segment {
113 __u64 base;
114 __u32 limit;
115 __u16 selector;
116 __u8 type;
117 __u8 present, dpl, db, s, l, g, avl;
118 __u8 unusable;
119 __u8 padding;
120};
121
122struct kvm_dtable {
123 __u64 base;
124 __u16 limit;
125 __u16 padding[3];
126};
127
128/* for KVM_GET_SREGS and KVM_SET_SREGS */
129struct kvm_sregs {
130 /* in */
131 __u32 vcpu;
132 __u32 padding;
133
134 /* out (KVM_GET_SREGS) / in (KVM_SET_SREGS) */
135 struct kvm_segment cs, ds, es, fs, gs, ss;
136 struct kvm_segment tr, ldt;
137 struct kvm_dtable gdt, idt;
138 __u64 cr0, cr2, cr3, cr4, cr8;
139 __u64 efer;
140 __u64 apic_base;
141 __u64 interrupt_bitmap[KVM_IRQ_BITMAP_SIZE(__u64)];
142};
143
144struct kvm_msr_entry {
145 __u32 index;
146 __u32 reserved;
147 __u64 data;
148};
149
150/* for KVM_GET_MSRS and KVM_SET_MSRS */
151struct kvm_msrs {
152 __u32 vcpu;
153 __u32 nmsrs; /* number of msrs in entries */
154
155 struct kvm_msr_entry entries[0];
156};
157
158/* for KVM_GET_MSR_INDEX_LIST */
159struct kvm_msr_list {
160 __u32 nmsrs; /* number of msrs in entries */
161 __u32 indices[0];
162};
163
164/* for KVM_TRANSLATE */
165struct kvm_translation {
166 /* in */
167 __u64 linear_address;
168 __u32 vcpu;
169 __u32 padding;
170
171 /* out */
172 __u64 physical_address;
173 __u8 valid;
174 __u8 writeable;
175 __u8 usermode;
176};
177
178/* for KVM_INTERRUPT */
179struct kvm_interrupt {
180 /* in */
181 __u32 vcpu;
182 __u32 irq;
183};
184
185struct kvm_breakpoint {
186 __u32 enabled;
187 __u32 padding;
188 __u64 address;
189};
190
191/* for KVM_DEBUG_GUEST */
192struct kvm_debug_guest {
193 /* int */
194 __u32 vcpu;
195 __u32 enabled;
196 struct kvm_breakpoint breakpoints[4];
197 __u32 singlestep;
198};
199
200/* for KVM_GET_DIRTY_LOG */
201struct kvm_dirty_log {
202 __u32 slot;
203 __u32 padding;
204 union {
205 void __user *dirty_bitmap; /* one bit per page */
206 __u64 padding;
207 };
208};
209
210#define KVMIO 0xAE
211
212#define KVM_RUN _IOWR(KVMIO, 2, struct kvm_run)
213#define KVM_GET_REGS _IOWR(KVMIO, 3, struct kvm_regs)
214#define KVM_SET_REGS _IOW(KVMIO, 4, struct kvm_regs)
215#define KVM_GET_SREGS _IOWR(KVMIO, 5, struct kvm_sregs)
216#define KVM_SET_SREGS _IOW(KVMIO, 6, struct kvm_sregs)
217#define KVM_TRANSLATE _IOWR(KVMIO, 7, struct kvm_translation)
218#define KVM_INTERRUPT _IOW(KVMIO, 8, struct kvm_interrupt)
219#define KVM_DEBUG_GUEST _IOW(KVMIO, 9, struct kvm_debug_guest)
220#define KVM_SET_MEMORY_REGION _IOW(KVMIO, 10, struct kvm_memory_region)
221#define KVM_CREATE_VCPU _IOW(KVMIO, 11, int /* vcpu_slot */)
222#define KVM_GET_DIRTY_LOG _IOW(KVMIO, 12, struct kvm_dirty_log)
223#define KVM_GET_MSRS _IOWR(KVMIO, 13, struct kvm_msrs)
224#define KVM_SET_MSRS _IOWR(KVMIO, 14, struct kvm_msrs)
225#define KVM_GET_MSR_INDEX_LIST _IOWR(KVMIO, 15, struct kvm_msr_list)
226
227#endif