]> bbs.cooldavid.org Git - net-next-2.6.git/blame - include/linux/kvm_host.h
KVM: convert bus to slots_lock
[net-next-2.6.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>
d4c9ff2d 18#include <linux/marker.h>
0937c48d 19#include <linux/msi.h>
e8edc6e0 20#include <asm/signal.h>
6aa8b732 21
6aa8b732 22#include <linux/kvm.h>
102d8325 23#include <linux/kvm_para.h>
6aa8b732 24
edf88417 25#include <linux/kvm_types.h>
d77a39d9 26
edf88417 27#include <asm/kvm_host.h>
d657a98e 28
d9e368d6
AK
29/*
30 * vcpu->requests bit members
31 */
3176bc3e 32#define KVM_REQ_TLB_FLUSH 0
2f52d58c 33#define KVM_REQ_MIGRATE_TIMER 1
b209749f 34#define KVM_REQ_REPORT_TPR_ACCESS 2
2e53d63a 35#define KVM_REQ_MMU_RELOAD 3
71c4dfaf 36#define KVM_REQ_TRIPLE_FAULT 4
06e05645 37#define KVM_REQ_PENDING_TIMER 5
d7690175 38#define KVM_REQ_UNHALT 6
4731d4c7 39#define KVM_REQ_MMU_SYNC 7
c8076604 40#define KVM_REQ_KVMCLOCK_UPDATE 8
32f88400 41#define KVM_REQ_KICK 9
6aa8b732 42
5550af4d
SY
43#define KVM_USERSPACE_IRQ_SOURCE_ID 0
44
6c474694 45struct kvm;
6aa8b732 46struct kvm_vcpu;
c16f862d 47extern struct kmem_cache *kvm_vcpu_cache;
6aa8b732 48
2eeb2e94
GH
49/*
50 * It would be nice to use something smarter than a linear search, TBD...
51 * Thankfully we dont expect many devices to register (famous last words :),
52 * so until then it will suffice. At least its abstracted so we can change
53 * in one place.
54 */
55struct kvm_io_bus {
56 int dev_count;
57#define NR_IOBUS_DEVS 6
58 struct kvm_io_device *devs[NR_IOBUS_DEVS];
59};
60
61void kvm_io_bus_init(struct kvm_io_bus *bus);
62void kvm_io_bus_destroy(struct kvm_io_bus *bus);
92760499
LV
63struct kvm_io_device *kvm_io_bus_find_dev(struct kvm_io_bus *bus,
64 gpa_t addr, int len, int is_write);
6c474694
MT
65void __kvm_io_bus_register_dev(struct kvm_io_bus *bus,
66 struct kvm_io_device *dev);
67void kvm_io_bus_register_dev(struct kvm *kvm, struct kvm_io_bus *bus,
2eeb2e94
GH
68 struct kvm_io_device *dev);
69
d17fbbf7
ZX
70struct kvm_vcpu {
71 struct kvm *kvm;
31bb117e 72#ifdef CONFIG_PREEMPT_NOTIFIERS
d17fbbf7 73 struct preempt_notifier preempt_notifier;
31bb117e 74#endif
d17fbbf7
ZX
75 int vcpu_id;
76 struct mutex mutex;
77 int cpu;
78 struct kvm_run *run;
d17fbbf7 79 unsigned long requests;
d0bfb940 80 unsigned long guest_debug;
d17fbbf7
ZX
81 int fpu_active;
82 int guest_fpu_loaded;
83 wait_queue_head_t wq;
84 int sigset_active;
85 sigset_t sigset;
86 struct kvm_vcpu_stat stat;
87
34c16eec 88#ifdef CONFIG_HAS_IOMEM
d17fbbf7
ZX
89 int mmio_needed;
90 int mmio_read_completed;
91 int mmio_is_write;
92 int mmio_size;
93 unsigned char mmio_data[8];
6aa8b732 94 gpa_t mmio_phys_addr;
34c16eec 95#endif
1165f5fe 96
d657a98e
ZX
97 struct kvm_vcpu_arch arch;
98};
99
6aa8b732
AK
100struct kvm_memory_slot {
101 gfn_t base_gfn;
102 unsigned long npages;
103 unsigned long flags;
290fc38d 104 unsigned long *rmap;
6aa8b732 105 unsigned long *dirty_bitmap;
05da4558
MT
106 struct {
107 unsigned long rmap_pde;
108 int write_count;
ec04b260 109 } *lpage_info[KVM_NR_PAGE_SIZES - 1];
8a7ae055 110 unsigned long userspace_addr;
80b14b5b 111 int user_alloc;
6aa8b732
AK
112};
113
399ec807
AK
114struct kvm_kernel_irq_routing_entry {
115 u32 gsi;
5116d8f6 116 u32 type;
4925663a 117 int (*set)(struct kvm_kernel_irq_routing_entry *e,
399ec807
AK
118 struct kvm *kvm, int level);
119 union {
120 struct {
121 unsigned irqchip;
122 unsigned pin;
123 } irqchip;
79950e10 124 struct msi_msg msi;
399ec807
AK
125 };
126 struct list_head link;
127};
128
6aa8b732 129struct kvm {
aaee2c94 130 spinlock_t mmu_lock;
84261923 131 spinlock_t requests_lock;
72dc67a6 132 struct rw_semaphore slots_lock;
6d4e4c4f 133 struct mm_struct *mm; /* userspace tied to this vm */
6aa8b732 134 int nmemslots;
e0d62c7f
IE
135 struct kvm_memory_slot memslots[KVM_MEMORY_SLOTS +
136 KVM_PRIVATE_MEM_SLOTS];
73880c80
GN
137#ifdef CONFIG_KVM_APIC_ARCHITECTURE
138 u32 bsp_vcpu_id;
c5af89b6 139 struct kvm_vcpu *bsp_vcpu;
73880c80 140#endif
fb3f0f51 141 struct kvm_vcpu *vcpus[KVM_MAX_VCPUS];
73880c80 142 atomic_t online_vcpus;
133de902 143 struct list_head vm_list;
60eead79 144 struct mutex lock;
2eeb2e94 145 struct kvm_io_bus mmio_bus;
74906345 146 struct kvm_io_bus pio_bus;
721eecbf
GH
147#ifdef CONFIG_HAVE_KVM_EVENTFD
148 struct {
149 spinlock_t lock;
150 struct list_head items;
151 } irqfds;
152#endif
ba1389b7 153 struct kvm_vm_stat stat;
d69fb81f 154 struct kvm_arch arch;
d39f13b0 155 atomic_t users_count;
5f94c174
LV
156#ifdef KVM_COALESCED_MMIO_PAGE_OFFSET
157 struct kvm_coalesced_mmio_dev *coalesced_mmio_dev;
158 struct kvm_coalesced_mmio_ring *coalesced_mmio_ring;
159#endif
e930bffe 160
60eead79 161 struct mutex irq_lock;
75858a84 162#ifdef CONFIG_HAVE_KVM_IRQCHIP
399ec807 163 struct list_head irq_routing; /* of kvm_kernel_irq_routing_entry */
75858a84
AK
164 struct hlist_head mask_notifier_list;
165#endif
166
e930bffe
AA
167#ifdef KVM_ARCH_WANT_MMU_NOTIFIER
168 struct mmu_notifier mmu_notifier;
169 unsigned long mmu_notifier_seq;
170 long mmu_notifier_count;
171#endif
6aa8b732
AK
172};
173
f0242478
RR
174/* The guest did something we don't support. */
175#define pr_unimpl(vcpu, fmt, ...) \
176 do { \
177 if (printk_ratelimit()) \
178 printk(KERN_ERR "kvm: %i: cpu%i " fmt, \
179 current->tgid, (vcpu)->vcpu_id , ## __VA_ARGS__); \
d77c26fc 180 } while (0)
f0242478 181
6aa8b732
AK
182#define kvm_printf(kvm, fmt ...) printk(KERN_DEBUG fmt)
183#define vcpu_printf(vcpu, fmt...) kvm_printf(vcpu->kvm, fmt)
184
988a2cae
GN
185static inline struct kvm_vcpu *kvm_get_vcpu(struct kvm *kvm, int i)
186{
187 smp_rmb();
188 return kvm->vcpus[i];
189}
190
191#define kvm_for_each_vcpu(idx, vcpup, kvm) \
192 for (idx = 0, vcpup = kvm_get_vcpu(kvm, idx); \
193 idx < atomic_read(&kvm->online_vcpus) && vcpup; \
194 vcpup = kvm_get_vcpu(kvm, ++idx))
195
fb3f0f51
RR
196int kvm_vcpu_init(struct kvm_vcpu *vcpu, struct kvm *kvm, unsigned id);
197void kvm_vcpu_uninit(struct kvm_vcpu *vcpu);
198
313a3dc7
CO
199void vcpu_load(struct kvm_vcpu *vcpu);
200void vcpu_put(struct kvm_vcpu *vcpu);
201
f8c16bba 202int kvm_init(void *opaque, unsigned int vcpu_size,
c16f862d 203 struct module *module);
cb498ea2 204void kvm_exit(void);
6aa8b732 205
d39f13b0
IE
206void kvm_get_kvm(struct kvm *kvm);
207void kvm_put_kvm(struct kvm *kvm);
208
6aa8b732
AK
209#define HPA_MSB ((sizeof(hpa_t) * 8) - 1)
210#define HPA_ERR_MASK ((hpa_t)1 << HPA_MSB)
211static inline int is_error_hpa(hpa_t hpa) { return hpa >> HPA_MSB; }
039576c0 212struct page *gva_to_page(struct kvm_vcpu *vcpu, gva_t gva);
6aa8b732 213
cea7bb21 214extern struct page *bad_page;
35149e21 215extern pfn_t bad_pfn;
6aa8b732 216
cea7bb21 217int is_error_page(struct page *page);
35149e21 218int is_error_pfn(pfn_t pfn);
f9d46eb0 219int kvm_is_error_hva(unsigned long addr);
210c7c4d
IE
220int kvm_set_memory_region(struct kvm *kvm,
221 struct kvm_userspace_memory_region *mem,
222 int user_alloc);
f78e0e2e
SY
223int __kvm_set_memory_region(struct kvm *kvm,
224 struct kvm_userspace_memory_region *mem,
225 int user_alloc);
0de10343
ZX
226int kvm_arch_set_memory_region(struct kvm *kvm,
227 struct kvm_userspace_memory_region *mem,
228 struct kvm_memory_slot old,
229 int user_alloc);
54dee993 230void kvm_disable_largepages(void);
34d4cb8f 231void kvm_arch_flush_shadow(struct kvm *kvm);
290fc38d 232gfn_t unalias_gfn(struct kvm *kvm, gfn_t gfn);
954bbbc2 233struct page *gfn_to_page(struct kvm *kvm, gfn_t gfn);
05da4558 234unsigned long gfn_to_hva(struct kvm *kvm, gfn_t gfn);
b4231d61
IE
235void kvm_release_page_clean(struct page *page);
236void kvm_release_page_dirty(struct page *page);
35149e21
AL
237void kvm_set_page_dirty(struct page *page);
238void kvm_set_page_accessed(struct page *page);
239
240pfn_t gfn_to_pfn(struct kvm *kvm, gfn_t gfn);
241void kvm_release_pfn_dirty(pfn_t);
242void kvm_release_pfn_clean(pfn_t pfn);
243void kvm_set_pfn_dirty(pfn_t pfn);
244void kvm_set_pfn_accessed(pfn_t pfn);
245void kvm_get_pfn(pfn_t pfn);
246
195aefde
IE
247int kvm_read_guest_page(struct kvm *kvm, gfn_t gfn, void *data, int offset,
248 int len);
7ec54588
MT
249int kvm_read_guest_atomic(struct kvm *kvm, gpa_t gpa, void *data,
250 unsigned long len);
195aefde
IE
251int kvm_read_guest(struct kvm *kvm, gpa_t gpa, void *data, unsigned long len);
252int kvm_write_guest_page(struct kvm *kvm, gfn_t gfn, const void *data,
253 int offset, int len);
254int kvm_write_guest(struct kvm *kvm, gpa_t gpa, const void *data,
255 unsigned long len);
256int kvm_clear_guest_page(struct kvm *kvm, gfn_t gfn, int offset, int len);
257int kvm_clear_guest(struct kvm *kvm, gpa_t gpa, unsigned long len);
6aa8b732 258struct kvm_memory_slot *gfn_to_memslot(struct kvm *kvm, gfn_t gfn);
e0d62c7f 259int kvm_is_visible_gfn(struct kvm *kvm, gfn_t gfn);
6aa8b732
AK
260void mark_page_dirty(struct kvm *kvm, gfn_t gfn);
261
8776e519 262void kvm_vcpu_block(struct kvm_vcpu *vcpu);
6aa8b732 263void kvm_resched(struct kvm_vcpu *vcpu);
7702fd1f
AK
264void kvm_load_guest_fpu(struct kvm_vcpu *vcpu);
265void kvm_put_guest_fpu(struct kvm_vcpu *vcpu);
d9e368d6 266void kvm_flush_remote_tlbs(struct kvm *kvm);
2e53d63a 267void kvm_reload_remote_mmus(struct kvm *kvm);
6aa8b732 268
043405e1
CO
269long kvm_arch_dev_ioctl(struct file *filp,
270 unsigned int ioctl, unsigned long arg);
313a3dc7
CO
271long kvm_arch_vcpu_ioctl(struct file *filp,
272 unsigned int ioctl, unsigned long arg);
018d00d2
ZX
273
274int kvm_dev_ioctl_check_extension(long ext);
275
5bb064dc
ZX
276int kvm_get_dirty_log(struct kvm *kvm,
277 struct kvm_dirty_log *log, int *is_dirty);
278int kvm_vm_ioctl_get_dirty_log(struct kvm *kvm,
279 struct kvm_dirty_log *log);
280
1fe779f8
CO
281int kvm_vm_ioctl_set_memory_region(struct kvm *kvm,
282 struct
283 kvm_userspace_memory_region *mem,
284 int user_alloc);
285long kvm_arch_vm_ioctl(struct file *filp,
286 unsigned int ioctl, unsigned long arg);
313a3dc7 287
d0752060
HB
288int kvm_arch_vcpu_ioctl_get_fpu(struct kvm_vcpu *vcpu, struct kvm_fpu *fpu);
289int kvm_arch_vcpu_ioctl_set_fpu(struct kvm_vcpu *vcpu, struct kvm_fpu *fpu);
290
8b006791
ZX
291int kvm_arch_vcpu_ioctl_translate(struct kvm_vcpu *vcpu,
292 struct kvm_translation *tr);
293
b6c7a5dc
HB
294int kvm_arch_vcpu_ioctl_get_regs(struct kvm_vcpu *vcpu, struct kvm_regs *regs);
295int kvm_arch_vcpu_ioctl_set_regs(struct kvm_vcpu *vcpu, struct kvm_regs *regs);
296int kvm_arch_vcpu_ioctl_get_sregs(struct kvm_vcpu *vcpu,
297 struct kvm_sregs *sregs);
298int kvm_arch_vcpu_ioctl_set_sregs(struct kvm_vcpu *vcpu,
299 struct kvm_sregs *sregs);
62d9f0db
MT
300int kvm_arch_vcpu_ioctl_get_mpstate(struct kvm_vcpu *vcpu,
301 struct kvm_mp_state *mp_state);
302int kvm_arch_vcpu_ioctl_set_mpstate(struct kvm_vcpu *vcpu,
303 struct kvm_mp_state *mp_state);
d0bfb940
JK
304int kvm_arch_vcpu_ioctl_set_guest_debug(struct kvm_vcpu *vcpu,
305 struct kvm_guest_debug *dbg);
b6c7a5dc
HB
306int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run);
307
f8c16bba
ZX
308int kvm_arch_init(void *opaque);
309void kvm_arch_exit(void);
043405e1 310
e9b11c17
ZX
311int kvm_arch_vcpu_init(struct kvm_vcpu *vcpu);
312void kvm_arch_vcpu_uninit(struct kvm_vcpu *vcpu);
313
314void kvm_arch_vcpu_free(struct kvm_vcpu *vcpu);
315void kvm_arch_vcpu_load(struct kvm_vcpu *vcpu, int cpu);
316void kvm_arch_vcpu_put(struct kvm_vcpu *vcpu);
317struct kvm_vcpu *kvm_arch_vcpu_create(struct kvm *kvm, unsigned int id);
26e5215f 318int kvm_arch_vcpu_setup(struct kvm_vcpu *vcpu);
d40ccc62 319void kvm_arch_vcpu_destroy(struct kvm_vcpu *vcpu);
e9b11c17
ZX
320
321int kvm_arch_vcpu_reset(struct kvm_vcpu *vcpu);
322void kvm_arch_hardware_enable(void *garbage);
323void kvm_arch_hardware_disable(void *garbage);
324int kvm_arch_hardware_setup(void);
325void kvm_arch_hardware_unsetup(void);
326void kvm_arch_check_processor_compat(void *rtn);
1d737c8a 327int kvm_arch_vcpu_runnable(struct kvm_vcpu *vcpu);
78646121 328int kvm_arch_interrupt_allowed(struct kvm_vcpu *vcpu);
e9b11c17 329
d19a9cd2
ZX
330void kvm_free_physmem(struct kvm *kvm);
331
332struct kvm *kvm_arch_create_vm(void);
333void kvm_arch_destroy_vm(struct kvm *kvm);
8a98f664 334void kvm_free_all_assigned_devices(struct kvm *kvm);
ad8ba2cd 335void kvm_arch_sync_events(struct kvm *kvm);
e9b11c17 336
682c59a3
ZX
337int kvm_cpu_get_interrupt(struct kvm_vcpu *v);
338int kvm_cpu_has_interrupt(struct kvm_vcpu *v);
3d80840d 339int kvm_cpu_has_pending_timer(struct kvm_vcpu *vcpu);
5736199a 340void kvm_vcpu_kick(struct kvm_vcpu *vcpu);
682c59a3 341
c77fb9dc
XZ
342int kvm_is_mmio_pfn(pfn_t pfn);
343
62c476c7
BAY
344struct kvm_irq_ack_notifier {
345 struct hlist_node link;
346 unsigned gsi;
347 void (*irq_acked)(struct kvm_irq_ack_notifier *kian);
348};
349
2350bd1f 350#define KVM_ASSIGNED_MSIX_PENDING 0x1
c1e01514
SY
351struct kvm_guest_msix_entry {
352 u32 vector;
353 u16 entry;
354 u16 flags;
355};
356
62c476c7
BAY
357struct kvm_assigned_dev_kernel {
358 struct kvm_irq_ack_notifier ack_notifier;
359 struct work_struct interrupt_work;
360 struct list_head list;
361 int assigned_dev_id;
362 int host_busnr;
363 int host_devfn;
c1e01514 364 unsigned int entries_nr;
62c476c7 365 int host_irq;
defaf158 366 bool host_irq_disabled;
c1e01514 367 struct msix_entry *host_msix_entries;
62c476c7 368 int guest_irq;
c1e01514 369 struct kvm_guest_msix_entry *guest_msix_entries;
4f906c19 370 unsigned long irq_requested_type;
5550af4d 371 int irq_source_id;
b653574a 372 int flags;
62c476c7
BAY
373 struct pci_dev *dev;
374 struct kvm *kvm;
547de29e 375 spinlock_t assigned_dev_lock;
62c476c7 376};
75858a84
AK
377
378struct kvm_irq_mask_notifier {
379 void (*func)(struct kvm_irq_mask_notifier *kimn, bool masked);
380 int irq;
381 struct hlist_node link;
382};
383
384void kvm_register_irq_mask_notifier(struct kvm *kvm, int irq,
385 struct kvm_irq_mask_notifier *kimn);
386void kvm_unregister_irq_mask_notifier(struct kvm *kvm, int irq,
387 struct kvm_irq_mask_notifier *kimn);
388void kvm_fire_mask_notifiers(struct kvm *kvm, int irq, bool mask);
389
4925663a 390int kvm_set_irq(struct kvm *kvm, int irq_source_id, int irq, int level);
44882eed 391void kvm_notify_acked_irq(struct kvm *kvm, unsigned irqchip, unsigned pin);
3de42dc0
XZ
392void kvm_register_irq_ack_notifier(struct kvm *kvm,
393 struct kvm_irq_ack_notifier *kian);
fa40a821
MT
394void kvm_unregister_irq_ack_notifier(struct kvm *kvm,
395 struct kvm_irq_ack_notifier *kian);
5550af4d
SY
396int kvm_request_irq_source_id(struct kvm *kvm);
397void kvm_free_irq_source_id(struct kvm *kvm, int irq_source_id);
62c476c7 398
522c68c4
SY
399/* For vcpu->arch.iommu_flags */
400#define KVM_IOMMU_CACHE_COHERENCY 0x1
401
19de40a8 402#ifdef CONFIG_IOMMU_API
62c476c7
BAY
403int kvm_iommu_map_pages(struct kvm *kvm, gfn_t base_gfn,
404 unsigned long npages);
260782bc 405int kvm_iommu_map_guest(struct kvm *kvm);
62c476c7 406int kvm_iommu_unmap_guest(struct kvm *kvm);
260782bc
WH
407int kvm_assign_device(struct kvm *kvm,
408 struct kvm_assigned_dev_kernel *assigned_dev);
0a920356
WH
409int kvm_deassign_device(struct kvm *kvm,
410 struct kvm_assigned_dev_kernel *assigned_dev);
19de40a8 411#else /* CONFIG_IOMMU_API */
62c476c7
BAY
412static inline int kvm_iommu_map_pages(struct kvm *kvm,
413 gfn_t base_gfn,
414 unsigned long npages)
415{
416 return 0;
417}
418
260782bc 419static inline int kvm_iommu_map_guest(struct kvm *kvm)
62c476c7
BAY
420{
421 return -ENODEV;
422}
423
424static inline int kvm_iommu_unmap_guest(struct kvm *kvm)
425{
426 return 0;
427}
260782bc
WH
428
429static inline int kvm_assign_device(struct kvm *kvm,
430 struct kvm_assigned_dev_kernel *assigned_dev)
431{
432 return 0;
433}
0a920356
WH
434
435static inline int kvm_deassign_device(struct kvm *kvm,
436 struct kvm_assigned_dev_kernel *assigned_dev)
437{
438 return 0;
439}
19de40a8 440#endif /* CONFIG_IOMMU_API */
62c476c7 441
d172fcd3
LV
442static inline void kvm_guest_enter(void)
443{
e56a7a28 444 account_system_vtime(current);
d172fcd3
LV
445 current->flags |= PF_VCPU;
446}
447
448static inline void kvm_guest_exit(void)
449{
e56a7a28 450 account_system_vtime(current);
d172fcd3
LV
451 current->flags &= ~PF_VCPU;
452}
453
6aa8b732
AK
454static inline int memslot_id(struct kvm *kvm, struct kvm_memory_slot *slot)
455{
456 return slot - kvm->memslots;
457}
458
1755fbcc
AK
459static inline gpa_t gfn_to_gpa(gfn_t gfn)
460{
461 return (gpa_t)gfn << PAGE_SHIFT;
462}
6aa8b732 463
62c476c7
BAY
464static inline hpa_t pfn_to_hpa(pfn_t pfn)
465{
466 return (hpa_t)pfn << PAGE_SHIFT;
467}
468
2f599714 469static inline void kvm_migrate_timers(struct kvm_vcpu *vcpu)
2f52d58c
AK
470{
471 set_bit(KVM_REQ_MIGRATE_TIMER, &vcpu->requests);
472}
473
ba1389b7
AK
474enum kvm_stat_kind {
475 KVM_STAT_VM,
476 KVM_STAT_VCPU,
477};
478
417bc304
HB
479struct kvm_stats_debugfs_item {
480 const char *name;
481 int offset;
ba1389b7 482 enum kvm_stat_kind kind;
417bc304
HB
483 struct dentry *dentry;
484};
485extern struct kvm_stats_debugfs_item debugfs_entries[];
76f7c879 486extern struct dentry *kvm_debugfs_dir;
d4c9ff2d 487
e930bffe
AA
488#ifdef KVM_ARCH_WANT_MMU_NOTIFIER
489static inline int mmu_notifier_retry(struct kvm_vcpu *vcpu, unsigned long mmu_seq)
490{
491 if (unlikely(vcpu->kvm->mmu_notifier_count))
492 return 1;
493 /*
494 * Both reads happen under the mmu_lock and both values are
495 * modified under mmu_lock, so there's no need of smb_rmb()
496 * here in between, otherwise mmu_notifier_count should be
497 * read before mmu_notifier_seq, see
498 * mmu_notifier_invalidate_range_end write side.
499 */
500 if (vcpu->kvm->mmu_notifier_seq != mmu_seq)
501 return 1;
502 return 0;
503}
504#endif
505
399ec807
AK
506#ifdef CONFIG_HAVE_KVM_IRQCHIP
507
508#define KVM_MAX_IRQ_ROUTES 1024
509
510int kvm_setup_default_irq_routing(struct kvm *kvm);
511int kvm_set_irq_routing(struct kvm *kvm,
512 const struct kvm_irq_routing_entry *entries,
513 unsigned nr,
514 unsigned flags);
515void kvm_free_irq_routing(struct kvm *kvm);
516
517#else
518
519static inline void kvm_free_irq_routing(struct kvm *kvm) {}
520
521#endif
522
721eecbf
GH
523#ifdef CONFIG_HAVE_KVM_EVENTFD
524
525void kvm_irqfd_init(struct kvm *kvm);
526int kvm_irqfd(struct kvm *kvm, int fd, int gsi, int flags);
527void kvm_irqfd_release(struct kvm *kvm);
528
529#else
530
531static inline void kvm_irqfd_init(struct kvm *kvm) {}
532static inline int kvm_irqfd(struct kvm *kvm, int fd, int gsi, int flags)
533{
534 return -EINVAL;
535}
536
537static inline void kvm_irqfd_release(struct kvm *kvm) {}
538
539#endif /* CONFIG_HAVE_KVM_EVENTFD */
540
73880c80 541#ifdef CONFIG_KVM_APIC_ARCHITECTURE
c5af89b6
GN
542static inline bool kvm_vcpu_is_bsp(struct kvm_vcpu *vcpu)
543{
d3efc8ef 544 return vcpu->kvm->bsp_vcpu_id == vcpu->vcpu_id;
c5af89b6 545}
6aa8b732 546#endif
73880c80 547#endif