]> git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/blame - include/linux/kvm_host.h
KVM: function declaration parameter name cleanup
[mirror_ubuntu-artful-kernel.git] / include / linux / kvm_host.h
CommitLineData
edf88417
AK
1#ifndef __KVM_HOST_H
2#define __KVM_HOST_H
6aa8b732
AK
3
4/*
5 * This work is licensed under the terms of the GNU GPL, version 2. See
6 * the COPYING file in the top-level directory.
7 */
8
9#include <linux/types.h>
e56a7a28 10#include <linux/hardirq.h>
6aa8b732
AK
11#include <linux/list.h>
12#include <linux/mutex.h>
13#include <linux/spinlock.h>
06ff0d37
MR
14#include <linux/signal.h>
15#include <linux/sched.h>
6aa8b732 16#include <linux/mm.h>
15ad7146 17#include <linux/preempt.h>
e8edc6e0 18#include <asm/signal.h>
6aa8b732 19
6aa8b732 20#include <linux/kvm.h>
102d8325 21#include <linux/kvm_para.h>
6aa8b732 22
edf88417 23#include <linux/kvm_types.h>
d77a39d9 24
edf88417 25#include <asm/kvm_host.h>
d657a98e 26
d9e368d6
AK
27/*
28 * vcpu->requests bit members
29 */
3176bc3e 30#define KVM_REQ_TLB_FLUSH 0
2f52d58c 31#define KVM_REQ_MIGRATE_TIMER 1
b209749f 32#define KVM_REQ_REPORT_TPR_ACCESS 2
2e53d63a 33#define KVM_REQ_MMU_RELOAD 3
71c4dfaf 34#define KVM_REQ_TRIPLE_FAULT 4
6aa8b732 35
6aa8b732 36struct kvm_vcpu;
c16f862d 37extern struct kmem_cache *kvm_vcpu_cache;
6aa8b732 38
2eeb2e94
GH
39/*
40 * It would be nice to use something smarter than a linear search, TBD...
41 * Thankfully we dont expect many devices to register (famous last words :),
42 * so until then it will suffice. At least its abstracted so we can change
43 * in one place.
44 */
45struct kvm_io_bus {
46 int dev_count;
47#define NR_IOBUS_DEVS 6
48 struct kvm_io_device *devs[NR_IOBUS_DEVS];
49};
50
51void kvm_io_bus_init(struct kvm_io_bus *bus);
52void kvm_io_bus_destroy(struct kvm_io_bus *bus);
53struct kvm_io_device *kvm_io_bus_find_dev(struct kvm_io_bus *bus, gpa_t addr);
54void kvm_io_bus_register_dev(struct kvm_io_bus *bus,
55 struct kvm_io_device *dev);
56
d17fbbf7
ZX
57struct kvm_vcpu {
58 struct kvm *kvm;
31bb117e 59#ifdef CONFIG_PREEMPT_NOTIFIERS
d17fbbf7 60 struct preempt_notifier preempt_notifier;
31bb117e 61#endif
d17fbbf7
ZX
62 int vcpu_id;
63 struct mutex mutex;
64 int cpu;
65 struct kvm_run *run;
66 int guest_mode;
67 unsigned long requests;
68 struct kvm_guest_debug guest_debug;
69 int fpu_active;
70 int guest_fpu_loaded;
71 wait_queue_head_t wq;
72 int sigset_active;
73 sigset_t sigset;
74 struct kvm_vcpu_stat stat;
75
34c16eec 76#ifdef CONFIG_HAS_IOMEM
d17fbbf7
ZX
77 int mmio_needed;
78 int mmio_read_completed;
79 int mmio_is_write;
80 int mmio_size;
81 unsigned char mmio_data[8];
6aa8b732 82 gpa_t mmio_phys_addr;
34c16eec 83#endif
1165f5fe 84
d657a98e
ZX
85 struct kvm_vcpu_arch arch;
86};
87
6aa8b732
AK
88struct kvm_memory_slot {
89 gfn_t base_gfn;
90 unsigned long npages;
91 unsigned long flags;
290fc38d 92 unsigned long *rmap;
6aa8b732 93 unsigned long *dirty_bitmap;
05da4558
MT
94 struct {
95 unsigned long rmap_pde;
96 int write_count;
97 } *lpage_info;
8a7ae055 98 unsigned long userspace_addr;
80b14b5b 99 int user_alloc;
6aa8b732
AK
100};
101
102struct kvm {
aaee2c94
MT
103 struct mutex lock; /* protects the vcpus array and APIC accesses */
104 spinlock_t mmu_lock;
72dc67a6 105 struct rw_semaphore slots_lock;
6d4e4c4f 106 struct mm_struct *mm; /* userspace tied to this vm */
6aa8b732 107 int nmemslots;
e0d62c7f
IE
108 struct kvm_memory_slot memslots[KVM_MEMORY_SLOTS +
109 KVM_PRIVATE_MEM_SLOTS];
fb3f0f51 110 struct kvm_vcpu *vcpus[KVM_MAX_VCPUS];
133de902 111 struct list_head vm_list;
bccf2150 112 struct file *filp;
2eeb2e94 113 struct kvm_io_bus mmio_bus;
74906345 114 struct kvm_io_bus pio_bus;
ba1389b7 115 struct kvm_vm_stat stat;
d69fb81f 116 struct kvm_arch arch;
6aa8b732
AK
117};
118
f0242478
RR
119/* The guest did something we don't support. */
120#define pr_unimpl(vcpu, fmt, ...) \
121 do { \
122 if (printk_ratelimit()) \
123 printk(KERN_ERR "kvm: %i: cpu%i " fmt, \
124 current->tgid, (vcpu)->vcpu_id , ## __VA_ARGS__); \
d77c26fc 125 } while (0)
f0242478 126
6aa8b732
AK
127#define kvm_printf(kvm, fmt ...) printk(KERN_DEBUG fmt)
128#define vcpu_printf(vcpu, fmt...) kvm_printf(vcpu->kvm, fmt)
129
fb3f0f51
RR
130int kvm_vcpu_init(struct kvm_vcpu *vcpu, struct kvm *kvm, unsigned id);
131void kvm_vcpu_uninit(struct kvm_vcpu *vcpu);
132
313a3dc7
CO
133void vcpu_load(struct kvm_vcpu *vcpu);
134void vcpu_put(struct kvm_vcpu *vcpu);
135
e9b11c17
ZX
136void decache_vcpus_on_cpu(int cpu);
137
313a3dc7 138
f8c16bba 139int kvm_init(void *opaque, unsigned int vcpu_size,
c16f862d 140 struct module *module);
cb498ea2 141void kvm_exit(void);
6aa8b732 142
6aa8b732
AK
143#define HPA_MSB ((sizeof(hpa_t) * 8) - 1)
144#define HPA_ERR_MASK ((hpa_t)1 << HPA_MSB)
145static inline int is_error_hpa(hpa_t hpa) { return hpa >> HPA_MSB; }
039576c0 146struct page *gva_to_page(struct kvm_vcpu *vcpu, gva_t gva);
6aa8b732 147
cea7bb21 148extern struct page *bad_page;
6aa8b732 149
cea7bb21 150int is_error_page(struct page *page);
f9d46eb0 151int kvm_is_error_hva(unsigned long addr);
210c7c4d
IE
152int kvm_set_memory_region(struct kvm *kvm,
153 struct kvm_userspace_memory_region *mem,
154 int user_alloc);
f78e0e2e
SY
155int __kvm_set_memory_region(struct kvm *kvm,
156 struct kvm_userspace_memory_region *mem,
157 int user_alloc);
0de10343
ZX
158int kvm_arch_set_memory_region(struct kvm *kvm,
159 struct kvm_userspace_memory_region *mem,
160 struct kvm_memory_slot old,
161 int user_alloc);
290fc38d 162gfn_t unalias_gfn(struct kvm *kvm, gfn_t gfn);
954bbbc2 163struct page *gfn_to_page(struct kvm *kvm, gfn_t gfn);
05da4558 164unsigned long gfn_to_hva(struct kvm *kvm, gfn_t gfn);
b4231d61
IE
165void kvm_release_page_clean(struct page *page);
166void kvm_release_page_dirty(struct page *page);
195aefde
IE
167int kvm_read_guest_page(struct kvm *kvm, gfn_t gfn, void *data, int offset,
168 int len);
7ec54588
MT
169int kvm_read_guest_atomic(struct kvm *kvm, gpa_t gpa, void *data,
170 unsigned long len);
195aefde
IE
171int kvm_read_guest(struct kvm *kvm, gpa_t gpa, void *data, unsigned long len);
172int kvm_write_guest_page(struct kvm *kvm, gfn_t gfn, const void *data,
173 int offset, int len);
174int kvm_write_guest(struct kvm *kvm, gpa_t gpa, const void *data,
175 unsigned long len);
176int kvm_clear_guest_page(struct kvm *kvm, gfn_t gfn, int offset, int len);
177int kvm_clear_guest(struct kvm *kvm, gpa_t gpa, unsigned long len);
6aa8b732 178struct kvm_memory_slot *gfn_to_memslot(struct kvm *kvm, gfn_t gfn);
e0d62c7f 179int kvm_is_visible_gfn(struct kvm *kvm, gfn_t gfn);
6aa8b732
AK
180void mark_page_dirty(struct kvm *kvm, gfn_t gfn);
181
8776e519 182void kvm_vcpu_block(struct kvm_vcpu *vcpu);
6aa8b732 183void kvm_resched(struct kvm_vcpu *vcpu);
7702fd1f
AK
184void kvm_load_guest_fpu(struct kvm_vcpu *vcpu);
185void kvm_put_guest_fpu(struct kvm_vcpu *vcpu);
d9e368d6 186void kvm_flush_remote_tlbs(struct kvm *kvm);
2e53d63a 187void kvm_reload_remote_mmus(struct kvm *kvm);
6aa8b732 188
043405e1
CO
189long kvm_arch_dev_ioctl(struct file *filp,
190 unsigned int ioctl, unsigned long arg);
313a3dc7
CO
191long kvm_arch_vcpu_ioctl(struct file *filp,
192 unsigned int ioctl, unsigned long arg);
193void kvm_arch_vcpu_load(struct kvm_vcpu *vcpu, int cpu);
194void kvm_arch_vcpu_put(struct kvm_vcpu *vcpu);
018d00d2
ZX
195
196int kvm_dev_ioctl_check_extension(long ext);
197
5bb064dc
ZX
198int kvm_get_dirty_log(struct kvm *kvm,
199 struct kvm_dirty_log *log, int *is_dirty);
200int kvm_vm_ioctl_get_dirty_log(struct kvm *kvm,
201 struct kvm_dirty_log *log);
202
1fe779f8
CO
203int kvm_vm_ioctl_set_memory_region(struct kvm *kvm,
204 struct
205 kvm_userspace_memory_region *mem,
206 int user_alloc);
207long kvm_arch_vm_ioctl(struct file *filp,
208 unsigned int ioctl, unsigned long arg);
209void kvm_arch_destroy_vm(struct kvm *kvm);
313a3dc7 210
d0752060
HB
211int kvm_arch_vcpu_ioctl_get_fpu(struct kvm_vcpu *vcpu, struct kvm_fpu *fpu);
212int kvm_arch_vcpu_ioctl_set_fpu(struct kvm_vcpu *vcpu, struct kvm_fpu *fpu);
213
8b006791
ZX
214int kvm_arch_vcpu_ioctl_translate(struct kvm_vcpu *vcpu,
215 struct kvm_translation *tr);
216
b6c7a5dc
HB
217int kvm_arch_vcpu_ioctl_get_regs(struct kvm_vcpu *vcpu, struct kvm_regs *regs);
218int kvm_arch_vcpu_ioctl_set_regs(struct kvm_vcpu *vcpu, struct kvm_regs *regs);
219int kvm_arch_vcpu_ioctl_get_sregs(struct kvm_vcpu *vcpu,
220 struct kvm_sregs *sregs);
221int kvm_arch_vcpu_ioctl_set_sregs(struct kvm_vcpu *vcpu,
222 struct kvm_sregs *sregs);
223int kvm_arch_vcpu_ioctl_debug_guest(struct kvm_vcpu *vcpu,
224 struct kvm_debug_guest *dbg);
225int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run);
226
f8c16bba
ZX
227int kvm_arch_init(void *opaque);
228void kvm_arch_exit(void);
043405e1 229
e9b11c17
ZX
230int kvm_arch_vcpu_init(struct kvm_vcpu *vcpu);
231void kvm_arch_vcpu_uninit(struct kvm_vcpu *vcpu);
232
233void kvm_arch_vcpu_free(struct kvm_vcpu *vcpu);
234void kvm_arch_vcpu_load(struct kvm_vcpu *vcpu, int cpu);
235void kvm_arch_vcpu_put(struct kvm_vcpu *vcpu);
236struct kvm_vcpu *kvm_arch_vcpu_create(struct kvm *kvm, unsigned int id);
26e5215f 237int kvm_arch_vcpu_setup(struct kvm_vcpu *vcpu);
d40ccc62 238void kvm_arch_vcpu_destroy(struct kvm_vcpu *vcpu);
e9b11c17
ZX
239
240int kvm_arch_vcpu_reset(struct kvm_vcpu *vcpu);
241void kvm_arch_hardware_enable(void *garbage);
242void kvm_arch_hardware_disable(void *garbage);
243int kvm_arch_hardware_setup(void);
244void kvm_arch_hardware_unsetup(void);
245void kvm_arch_check_processor_compat(void *rtn);
1d737c8a 246int kvm_arch_vcpu_runnable(struct kvm_vcpu *vcpu);
e9b11c17 247
d19a9cd2
ZX
248void kvm_free_physmem(struct kvm *kvm);
249
250struct kvm *kvm_arch_create_vm(void);
251void kvm_arch_destroy_vm(struct kvm *kvm);
e9b11c17 252
682c59a3
ZX
253int kvm_cpu_get_interrupt(struct kvm_vcpu *v);
254int kvm_cpu_has_interrupt(struct kvm_vcpu *v);
5736199a 255void kvm_vcpu_kick(struct kvm_vcpu *vcpu);
682c59a3 256
d172fcd3
LV
257static inline void kvm_guest_enter(void)
258{
e56a7a28 259 account_system_vtime(current);
d172fcd3
LV
260 current->flags |= PF_VCPU;
261}
262
263static inline void kvm_guest_exit(void)
264{
e56a7a28 265 account_system_vtime(current);
d172fcd3
LV
266 current->flags &= ~PF_VCPU;
267}
268
6aa8b732
AK
269static inline int memslot_id(struct kvm *kvm, struct kvm_memory_slot *slot)
270{
271 return slot - kvm->memslots;
272}
273
1755fbcc
AK
274static inline gpa_t gfn_to_gpa(gfn_t gfn)
275{
276 return (gpa_t)gfn << PAGE_SHIFT;
277}
6aa8b732 278
2f52d58c
AK
279static inline void kvm_migrate_apic_timer(struct kvm_vcpu *vcpu)
280{
281 set_bit(KVM_REQ_MIGRATE_TIMER, &vcpu->requests);
282}
283
ba1389b7
AK
284enum kvm_stat_kind {
285 KVM_STAT_VM,
286 KVM_STAT_VCPU,
287};
288
417bc304
HB
289struct kvm_stats_debugfs_item {
290 const char *name;
291 int offset;
ba1389b7 292 enum kvm_stat_kind kind;
417bc304
HB
293 struct dentry *dentry;
294};
295extern struct kvm_stats_debugfs_item debugfs_entries[];
296
6aa8b732 297#endif