]> git.ipfire.org Git - thirdparty/linux.git/blame - include/linux/kvm_host.h
KVM: Initialize irqfd from kvm_init().
[thirdparty/linux.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>
187f1882 16#include <linux/bug.h>
6aa8b732 17#include <linux/mm.h>
b297e672 18#include <linux/mmu_notifier.h>
15ad7146 19#include <linux/preempt.h>
0937c48d 20#include <linux/msi.h>
d89f5eff 21#include <linux/slab.h>
bd2b53b2 22#include <linux/rcupdate.h>
bd80158a 23#include <linux/ratelimit.h>
83f09228 24#include <linux/err.h>
c11f11fc 25#include <linux/irqflags.h>
e8edc6e0 26#include <asm/signal.h>
6aa8b732 27
6aa8b732 28#include <linux/kvm.h>
102d8325 29#include <linux/kvm_para.h>
6aa8b732 30
edf88417 31#include <linux/kvm_types.h>
d77a39d9 32
edf88417 33#include <asm/kvm_host.h>
d657a98e 34
cef4dea0
AK
35#ifndef KVM_MMIO_SIZE
36#define KVM_MMIO_SIZE 8
37#endif
38
67b29204
XG
39/*
40 * The bit 16 ~ bit 31 of kvm_memory_region::flags are internally used
41 * in kvm, other bits are visible for userspace which are defined in
42 * include/linux/kvm_h.
43 */
44#define KVM_MEMSLOT_INVALID (1UL << 16)
45
87da7e66
XG
46/* Two fragments for cross MMIO pages. */
47#define KVM_MAX_MMIO_FRAGMENTS 2
f78146b0 48
9c5b1172
XG
49/*
50 * For the normal pfn, the highest 12 bits should be zero,
81c52c56
XG
51 * so we can mask bit 62 ~ bit 52 to indicate the error pfn,
52 * mask bit 63 to indicate the noslot pfn.
9c5b1172 53 */
81c52c56
XG
54#define KVM_PFN_ERR_MASK (0x7ffULL << 52)
55#define KVM_PFN_ERR_NOSLOT_MASK (0xfffULL << 52)
56#define KVM_PFN_NOSLOT (0x1ULL << 63)
9c5b1172
XG
57
58#define KVM_PFN_ERR_FAULT (KVM_PFN_ERR_MASK)
59#define KVM_PFN_ERR_HWPOISON (KVM_PFN_ERR_MASK + 1)
81c52c56 60#define KVM_PFN_ERR_RO_FAULT (KVM_PFN_ERR_MASK + 2)
6c8ee57b 61
81c52c56
XG
62/*
63 * error pfns indicate that the gfn is in slot but faild to
64 * translate it to pfn on host.
65 */
9c5b1172 66static inline bool is_error_pfn(pfn_t pfn)
83f09228 67{
9c5b1172 68 return !!(pfn & KVM_PFN_ERR_MASK);
83f09228
XG
69}
70
81c52c56
XG
71/*
72 * error_noslot pfns indicate that the gfn can not be
73 * translated to pfn - it is not in slot or failed to
74 * translate it to pfn.
75 */
76static inline bool is_error_noslot_pfn(pfn_t pfn)
83f09228 77{
81c52c56 78 return !!(pfn & KVM_PFN_ERR_NOSLOT_MASK);
83f09228
XG
79}
80
81c52c56
XG
81/* noslot pfn indicates that the gfn is not in slot. */
82static inline bool is_noslot_pfn(pfn_t pfn)
83f09228 83{
81c52c56 84 return pfn == KVM_PFN_NOSLOT;
83f09228
XG
85}
86
7068d097
XG
87#define KVM_HVA_ERR_BAD (PAGE_OFFSET)
88#define KVM_HVA_ERR_RO_BAD (PAGE_OFFSET + PAGE_SIZE)
ca3a490c
XG
89
90static inline bool kvm_is_error_hva(unsigned long addr)
91{
7068d097 92 return addr >= PAGE_OFFSET;
ca3a490c
XG
93}
94
6cede2e6
XG
95#define KVM_ERR_PTR_BAD_PAGE (ERR_PTR(-ENOENT))
96
9c5b1172 97static inline bool is_error_page(struct page *page)
6cede2e6
XG
98{
99 return IS_ERR(page);
100}
101
d9e368d6
AK
102/*
103 * vcpu->requests bit members
104 */
3176bc3e 105#define KVM_REQ_TLB_FLUSH 0
2f52d58c 106#define KVM_REQ_MIGRATE_TIMER 1
b209749f 107#define KVM_REQ_REPORT_TPR_ACCESS 2
2e53d63a 108#define KVM_REQ_MMU_RELOAD 3
71c4dfaf 109#define KVM_REQ_TRIPLE_FAULT 4
06e05645 110#define KVM_REQ_PENDING_TIMER 5
d7690175 111#define KVM_REQ_UNHALT 6
4731d4c7 112#define KVM_REQ_MMU_SYNC 7
34c238a1 113#define KVM_REQ_CLOCK_UPDATE 8
32f88400 114#define KVM_REQ_KICK 9
02daab21 115#define KVM_REQ_DEACTIVATE_FPU 10
3842d135 116#define KVM_REQ_EVENT 11
af585b92 117#define KVM_REQ_APF_HALT 12
c9aaa895 118#define KVM_REQ_STEAL_UPDATE 13
7460fb4a 119#define KVM_REQ_NMI 14
d6185f20 120#define KVM_REQ_IMMEDIATE_EXIT 15
f5132b01
GN
121#define KVM_REQ_PMU 16
122#define KVM_REQ_PMI 17
f61c94bb 123#define KVM_REQ_WATCHDOG 18
d828199e
MT
124#define KVM_REQ_MASTERCLOCK_UPDATE 19
125#define KVM_REQ_MCLOCK_INPROGRESS 20
1c810636 126#define KVM_REQ_EPR_EXIT 21
c7c9c56c 127#define KVM_REQ_EOIBITMAP 22
6aa8b732 128
7a84428a
AW
129#define KVM_USERSPACE_IRQ_SOURCE_ID 0
130#define KVM_IRQFD_RESAMPLE_IRQ_SOURCE_ID 1
5550af4d 131
6c474694 132struct kvm;
6aa8b732 133struct kvm_vcpu;
c16f862d 134extern struct kmem_cache *kvm_vcpu_cache;
6aa8b732 135
743eeb0b
SL
136struct kvm_io_range {
137 gpa_t addr;
138 int len;
139 struct kvm_io_device *dev;
140};
141
786a9f88 142#define NR_IOBUS_DEVS 1000
a1300716 143
2eeb2e94
GH
144struct kvm_io_bus {
145 int dev_count;
a1300716 146 struct kvm_io_range range[];
2eeb2e94
GH
147};
148
e93f8a0f
MT
149enum kvm_bus {
150 KVM_MMIO_BUS,
151 KVM_PIO_BUS,
152 KVM_NR_BUSES
153};
154
155int kvm_io_bus_write(struct kvm *kvm, enum kvm_bus bus_idx, gpa_t addr,
156 int len, const void *val);
157int kvm_io_bus_read(struct kvm *kvm, enum kvm_bus bus_idx, gpa_t addr, int len,
bda9020e 158 void *val);
743eeb0b
SL
159int kvm_io_bus_register_dev(struct kvm *kvm, enum kvm_bus bus_idx, gpa_t addr,
160 int len, struct kvm_io_device *dev);
e93f8a0f
MT
161int kvm_io_bus_unregister_dev(struct kvm *kvm, enum kvm_bus bus_idx,
162 struct kvm_io_device *dev);
2eeb2e94 163
af585b92
GN
164#ifdef CONFIG_KVM_ASYNC_PF
165struct kvm_async_pf {
166 struct work_struct work;
167 struct list_head link;
168 struct list_head queue;
169 struct kvm_vcpu *vcpu;
170 struct mm_struct *mm;
171 gva_t gva;
172 unsigned long addr;
173 struct kvm_arch_async_pf arch;
174 struct page *page;
175 bool done;
176};
177
178void kvm_clear_async_pf_completion_queue(struct kvm_vcpu *vcpu);
179void kvm_check_async_pf_completion(struct kvm_vcpu *vcpu);
180int kvm_setup_async_pf(struct kvm_vcpu *vcpu, gva_t gva, gfn_t gfn,
181 struct kvm_arch_async_pf *arch);
344d9588 182int kvm_async_pf_wakeup_all(struct kvm_vcpu *vcpu);
af585b92
GN
183#endif
184
6b7e2d09
XG
185enum {
186 OUTSIDE_GUEST_MODE,
187 IN_GUEST_MODE,
c142786c
AK
188 EXITING_GUEST_MODE,
189 READING_SHADOW_PAGE_TABLES,
6b7e2d09
XG
190};
191
f78146b0
AK
192/*
193 * Sometimes a large or cross-page mmio needs to be broken up into separate
194 * exits for userspace servicing.
195 */
196struct kvm_mmio_fragment {
197 gpa_t gpa;
198 void *data;
199 unsigned len;
200};
201
d17fbbf7
ZX
202struct kvm_vcpu {
203 struct kvm *kvm;
31bb117e 204#ifdef CONFIG_PREEMPT_NOTIFIERS
d17fbbf7 205 struct preempt_notifier preempt_notifier;
31bb117e 206#endif
6b7e2d09 207 int cpu;
d17fbbf7 208 int vcpu_id;
6b7e2d09
XG
209 int srcu_idx;
210 int mode;
d17fbbf7 211 unsigned long requests;
d0bfb940 212 unsigned long guest_debug;
6b7e2d09
XG
213
214 struct mutex mutex;
215 struct kvm_run *run;
f656ce01 216
d17fbbf7 217 int fpu_active;
2acf923e 218 int guest_fpu_loaded, guest_xcr0_loaded;
d17fbbf7 219 wait_queue_head_t wq;
34bb10b7 220 struct pid *pid;
d17fbbf7
ZX
221 int sigset_active;
222 sigset_t sigset;
223 struct kvm_vcpu_stat stat;
224
34c16eec 225#ifdef CONFIG_HAS_IOMEM
d17fbbf7
ZX
226 int mmio_needed;
227 int mmio_read_completed;
228 int mmio_is_write;
f78146b0
AK
229 int mmio_cur_fragment;
230 int mmio_nr_fragments;
231 struct kvm_mmio_fragment mmio_fragments[KVM_MAX_MMIO_FRAGMENTS];
34c16eec 232#endif
1165f5fe 233
af585b92
GN
234#ifdef CONFIG_KVM_ASYNC_PF
235 struct {
236 u32 queued;
237 struct list_head queue;
238 struct list_head done;
239 spinlock_t lock;
240 } async_pf;
241#endif
242
4c088493
R
243#ifdef CONFIG_HAVE_KVM_CPU_RELAX_INTERCEPT
244 /*
245 * Cpu relax intercept or pause loop exit optimization
246 * in_spin_loop: set when a vcpu does a pause loop exit
247 * or cpu relax intercepted.
248 * dy_eligible: indicates whether vcpu is eligible for directed yield.
249 */
250 struct {
251 bool in_spin_loop;
252 bool dy_eligible;
253 } spin_loop;
254#endif
d657a98e
ZX
255 struct kvm_vcpu_arch arch;
256};
257
6b7e2d09
XG
258static inline int kvm_vcpu_exiting_guest_mode(struct kvm_vcpu *vcpu)
259{
260 return cmpxchg(&vcpu->mode, IN_GUEST_MODE, EXITING_GUEST_MODE);
261}
262
660c22c4
TY
263/*
264 * Some of the bitops functions do not support too long bitmaps.
265 * This number must be determined not to exceed such limits.
266 */
267#define KVM_MEM_MAX_NR_PAGES ((1UL << 31) - 1)
268
6aa8b732
AK
269struct kvm_memory_slot {
270 gfn_t base_gfn;
271 unsigned long npages;
6aa8b732 272 unsigned long *dirty_bitmap;
db3fe4eb 273 struct kvm_arch_memory_slot arch;
8a7ae055 274 unsigned long userspace_addr;
6104f472 275 u32 flags;
1e702d9a 276 short id;
6aa8b732
AK
277};
278
87bf6e7d
TY
279static inline unsigned long kvm_dirty_bitmap_bytes(struct kvm_memory_slot *memslot)
280{
281 return ALIGN(memslot->npages, BITS_PER_LONG) / 8;
282}
283
399ec807
AK
284struct kvm_kernel_irq_routing_entry {
285 u32 gsi;
5116d8f6 286 u32 type;
4925663a 287 int (*set)(struct kvm_kernel_irq_routing_entry *e,
1a6e4a8c 288 struct kvm *kvm, int irq_source_id, int level);
399ec807
AK
289 union {
290 struct {
291 unsigned irqchip;
292 unsigned pin;
293 } irqchip;
79950e10 294 struct msi_msg msi;
399ec807 295 };
46e624b9
GN
296 struct hlist_node link;
297};
298
3e71f88b
GN
299#ifdef __KVM_HAVE_IOAPIC
300
46e624b9 301struct kvm_irq_routing_table {
3e71f88b 302 int chip[KVM_NR_IRQCHIPS][KVM_IOAPIC_NUM_PINS];
46e624b9
GN
303 struct kvm_kernel_irq_routing_entry *rt_entries;
304 u32 nr_rt_entries;
305 /*
306 * Array indexed by gsi. Each entry contains list of irq chips
307 * the gsi is connected to.
308 */
309 struct hlist_head map[0];
399ec807
AK
310};
311
3e71f88b
GN
312#else
313
314struct kvm_irq_routing_table {};
315
316#endif
317
0743247f
AW
318#ifndef KVM_PRIVATE_MEM_SLOTS
319#define KVM_PRIVATE_MEM_SLOTS 0
320#endif
321
93a5cef0 322#ifndef KVM_MEM_SLOTS_NUM
bbacc0c1 323#define KVM_MEM_SLOTS_NUM (KVM_USER_MEM_SLOTS + KVM_PRIVATE_MEM_SLOTS)
93a5cef0
XG
324#endif
325
bf3e05bc
XG
326/*
327 * Note:
328 * memslots are not sorted by id anymore, please use id_to_memslot()
329 * to get the memslot by its id.
330 */
46a26bf5 331struct kvm_memslots {
49c7754c 332 u64 generation;
93a5cef0 333 struct kvm_memory_slot memslots[KVM_MEM_SLOTS_NUM];
f85e2cb5 334 /* The mapping table from slot id to the index in memslots[]. */
1e702d9a 335 short id_to_index[KVM_MEM_SLOTS_NUM];
46a26bf5
MT
336};
337
6aa8b732 338struct kvm {
aaee2c94 339 spinlock_t mmu_lock;
79fac95e 340 struct mutex slots_lock;
6d4e4c4f 341 struct mm_struct *mm; /* userspace tied to this vm */
46a26bf5 342 struct kvm_memslots *memslots;
bc6678a3 343 struct srcu_struct srcu;
73880c80
GN
344#ifdef CONFIG_KVM_APIC_ARCHITECTURE
345 u32 bsp_vcpu_id;
73880c80 346#endif
fb3f0f51 347 struct kvm_vcpu *vcpus[KVM_MAX_VCPUS];
73880c80 348 atomic_t online_vcpus;
217ece61 349 int last_boosted_vcpu;
133de902 350 struct list_head vm_list;
60eead79 351 struct mutex lock;
e93f8a0f 352 struct kvm_io_bus *buses[KVM_NR_BUSES];
721eecbf
GH
353#ifdef CONFIG_HAVE_KVM_EVENTFD
354 struct {
355 spinlock_t lock;
356 struct list_head items;
7a84428a
AW
357 struct list_head resampler_list;
358 struct mutex resampler_lock;
721eecbf 359 } irqfds;
d34e6b17 360 struct list_head ioeventfds;
721eecbf 361#endif
ba1389b7 362 struct kvm_vm_stat stat;
d69fb81f 363 struct kvm_arch arch;
d39f13b0 364 atomic_t users_count;
5f94c174 365#ifdef KVM_COALESCED_MMIO_PAGE_OFFSET
5f94c174 366 struct kvm_coalesced_mmio_ring *coalesced_mmio_ring;
2b3c246a
SL
367 spinlock_t ring_lock;
368 struct list_head coalesced_zones;
5f94c174 369#endif
e930bffe 370
60eead79 371 struct mutex irq_lock;
75858a84 372#ifdef CONFIG_HAVE_KVM_IRQCHIP
bd2b53b2
MT
373 /*
374 * Update side is protected by irq_lock and,
375 * if configured, irqfds.lock.
376 */
4b6a2872 377 struct kvm_irq_routing_table __rcu *irq_routing;
75858a84 378 struct hlist_head mask_notifier_list;
136bdfee 379 struct hlist_head irq_ack_notifier_list;
75858a84
AK
380#endif
381
36c1ed82 382#if defined(CONFIG_MMU_NOTIFIER) && defined(KVM_ARCH_WANT_MMU_NOTIFIER)
e930bffe
AA
383 struct mmu_notifier mmu_notifier;
384 unsigned long mmu_notifier_seq;
385 long mmu_notifier_count;
386#endif
5c663a15 387 long tlbs_dirty;
6aa8b732
AK
388};
389
a737f256
CD
390#define kvm_err(fmt, ...) \
391 pr_err("kvm [%i]: " fmt, task_pid_nr(current), ## __VA_ARGS__)
392#define kvm_info(fmt, ...) \
393 pr_info("kvm [%i]: " fmt, task_pid_nr(current), ## __VA_ARGS__)
394#define kvm_debug(fmt, ...) \
395 pr_debug("kvm [%i]: " fmt, task_pid_nr(current), ## __VA_ARGS__)
396#define kvm_pr_unimpl(fmt, ...) \
397 pr_err_ratelimited("kvm [%i]: " fmt, \
398 task_tgid_nr(current), ## __VA_ARGS__)
f0242478 399
a737f256
CD
400/* The guest did something we don't support. */
401#define vcpu_unimpl(vcpu, fmt, ...) \
402 kvm_pr_unimpl("vcpu%i " fmt, (vcpu)->vcpu_id, ## __VA_ARGS__)
6aa8b732 403
988a2cae
GN
404static inline struct kvm_vcpu *kvm_get_vcpu(struct kvm *kvm, int i)
405{
406 smp_rmb();
407 return kvm->vcpus[i];
408}
409
410#define kvm_for_each_vcpu(idx, vcpup, kvm) \
b42fc3cb
JM
411 for (idx = 0; \
412 idx < atomic_read(&kvm->online_vcpus) && \
413 (vcpup = kvm_get_vcpu(kvm, idx)) != NULL; \
414 idx++)
988a2cae 415
be6ba0f0
XG
416#define kvm_for_each_memslot(memslot, slots) \
417 for (memslot = &slots->memslots[0]; \
bf3e05bc
XG
418 memslot < slots->memslots + KVM_MEM_SLOTS_NUM && memslot->npages;\
419 memslot++)
be6ba0f0 420
fb3f0f51
RR
421int kvm_vcpu_init(struct kvm_vcpu *vcpu, struct kvm *kvm, unsigned id);
422void kvm_vcpu_uninit(struct kvm_vcpu *vcpu);
423
9fc77441 424int __must_check vcpu_load(struct kvm_vcpu *vcpu);
313a3dc7
CO
425void vcpu_put(struct kvm_vcpu *vcpu);
426
a0f155e9
CH
427#ifdef __KVM_HAVE_IOAPIC
428int kvm_irqfd_init(void);
429void kvm_irqfd_exit(void);
430#else
431static inline int kvm_irqfd_init(void)
432{
433 return 0;
434}
435
436static inline void kvm_irqfd_exit(void)
437{
438}
439#endif
0ee75bea 440int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
c16f862d 441 struct module *module);
cb498ea2 442void kvm_exit(void);
6aa8b732 443
d39f13b0
IE
444void kvm_get_kvm(struct kvm *kvm);
445void kvm_put_kvm(struct kvm *kvm);
116c14c0
AW
446void update_memslots(struct kvm_memslots *slots, struct kvm_memory_slot *new,
447 u64 last_generation);
d39f13b0 448
90d83dc3
LJ
449static inline struct kvm_memslots *kvm_memslots(struct kvm *kvm)
450{
451 return rcu_dereference_check(kvm->memslots,
452 srcu_read_lock_held(&kvm->srcu)
453 || lockdep_is_held(&kvm->slots_lock));
454}
455
28a37544
XG
456static inline struct kvm_memory_slot *
457id_to_memslot(struct kvm_memslots *slots, int id)
458{
f85e2cb5
XG
459 int index = slots->id_to_index[id];
460 struct kvm_memory_slot *slot;
bf3e05bc 461
f85e2cb5 462 slot = &slots->memslots[index];
bf3e05bc 463
f85e2cb5
XG
464 WARN_ON(slot->id != id);
465 return slot;
28a37544
XG
466}
467
74d0727c
TY
468/*
469 * KVM_SET_USER_MEMORY_REGION ioctl allows the following operations:
470 * - create a new memory slot
471 * - delete an existing memory slot
472 * - modify an existing memory slot
473 * -- move it in the guest physical memory space
474 * -- just change its flags
475 *
476 * Since flags can be changed by some of these operations, the following
477 * differentiation is the best we can do for __kvm_set_memory_region():
478 */
479enum kvm_mr_change {
480 KVM_MR_CREATE,
481 KVM_MR_DELETE,
482 KVM_MR_MOVE,
483 KVM_MR_FLAGS_ONLY,
484};
485
210c7c4d 486int kvm_set_memory_region(struct kvm *kvm,
47ae31e2 487 struct kvm_userspace_memory_region *mem);
f78e0e2e 488int __kvm_set_memory_region(struct kvm *kvm,
47ae31e2 489 struct kvm_userspace_memory_region *mem);
db3fe4eb
TY
490void kvm_arch_free_memslot(struct kvm_memory_slot *free,
491 struct kvm_memory_slot *dont);
492int kvm_arch_create_memslot(struct kvm_memory_slot *slot, unsigned long npages);
f7784b8e
MT
493int kvm_arch_prepare_memory_region(struct kvm *kvm,
494 struct kvm_memory_slot *memslot,
7b6195a9
TY
495 struct kvm_userspace_memory_region *mem,
496 enum kvm_mr_change change);
f7784b8e 497void kvm_arch_commit_memory_region(struct kvm *kvm,
0de10343 498 struct kvm_userspace_memory_region *mem,
8482644a
TY
499 const struct kvm_memory_slot *old,
500 enum kvm_mr_change change);
db3fe4eb 501bool kvm_largepages_enabled(void);
54dee993 502void kvm_disable_largepages(void);
2df72e9b
MT
503/* flush all memory translations */
504void kvm_arch_flush_shadow_all(struct kvm *kvm);
505/* flush memory translations pointing to 'slot' */
506void kvm_arch_flush_shadow_memslot(struct kvm *kvm,
507 struct kvm_memory_slot *slot);
a983fb23 508
48987781
XG
509int gfn_to_page_many_atomic(struct kvm *kvm, gfn_t gfn, struct page **pages,
510 int nr_pages);
511
954bbbc2 512struct page *gfn_to_page(struct kvm *kvm, gfn_t gfn);
05da4558 513unsigned long gfn_to_hva(struct kvm *kvm, gfn_t gfn);
4d8b81ab 514unsigned long gfn_to_hva_memslot(struct kvm_memory_slot *slot, gfn_t gfn);
b4231d61
IE
515void kvm_release_page_clean(struct page *page);
516void kvm_release_page_dirty(struct page *page);
35149e21
AL
517void kvm_set_page_dirty(struct page *page);
518void kvm_set_page_accessed(struct page *page);
519
365fb3fd 520pfn_t gfn_to_pfn_atomic(struct kvm *kvm, gfn_t gfn);
612819c3
MT
521pfn_t gfn_to_pfn_async(struct kvm *kvm, gfn_t gfn, bool *async,
522 bool write_fault, bool *writable);
35149e21 523pfn_t gfn_to_pfn(struct kvm *kvm, gfn_t gfn);
612819c3
MT
524pfn_t gfn_to_pfn_prot(struct kvm *kvm, gfn_t gfn, bool write_fault,
525 bool *writable);
d5661048 526pfn_t gfn_to_pfn_memslot(struct kvm_memory_slot *slot, gfn_t gfn);
037d92dc
XG
527pfn_t gfn_to_pfn_memslot_atomic(struct kvm_memory_slot *slot, gfn_t gfn);
528
32cad84f 529void kvm_release_pfn_dirty(pfn_t pfn);
35149e21
AL
530void kvm_release_pfn_clean(pfn_t pfn);
531void kvm_set_pfn_dirty(pfn_t pfn);
532void kvm_set_pfn_accessed(pfn_t pfn);
533void kvm_get_pfn(pfn_t pfn);
534
195aefde
IE
535int kvm_read_guest_page(struct kvm *kvm, gfn_t gfn, void *data, int offset,
536 int len);
7ec54588
MT
537int kvm_read_guest_atomic(struct kvm *kvm, gpa_t gpa, void *data,
538 unsigned long len);
195aefde 539int kvm_read_guest(struct kvm *kvm, gpa_t gpa, void *data, unsigned long len);
e03b644f
GN
540int kvm_read_guest_cached(struct kvm *kvm, struct gfn_to_hva_cache *ghc,
541 void *data, unsigned long len);
195aefde
IE
542int kvm_write_guest_page(struct kvm *kvm, gfn_t gfn, const void *data,
543 int offset, int len);
544int kvm_write_guest(struct kvm *kvm, gpa_t gpa, const void *data,
545 unsigned long len);
49c7754c
GN
546int kvm_write_guest_cached(struct kvm *kvm, struct gfn_to_hva_cache *ghc,
547 void *data, unsigned long len);
548int kvm_gfn_to_hva_cache_init(struct kvm *kvm, struct gfn_to_hva_cache *ghc,
549 gpa_t gpa);
195aefde
IE
550int kvm_clear_guest_page(struct kvm *kvm, gfn_t gfn, int offset, int len);
551int kvm_clear_guest(struct kvm *kvm, gpa_t gpa, unsigned long len);
6aa8b732 552struct kvm_memory_slot *gfn_to_memslot(struct kvm *kvm, gfn_t gfn);
e0d62c7f 553int kvm_is_visible_gfn(struct kvm *kvm, gfn_t gfn);
8f0b1ab6 554unsigned long kvm_host_page_size(struct kvm *kvm, gfn_t gfn);
6aa8b732 555void mark_page_dirty(struct kvm *kvm, gfn_t gfn);
49c7754c
GN
556void mark_page_dirty_in_slot(struct kvm *kvm, struct kvm_memory_slot *memslot,
557 gfn_t gfn);
6aa8b732 558
8776e519 559void kvm_vcpu_block(struct kvm_vcpu *vcpu);
b6d33834 560void kvm_vcpu_kick(struct kvm_vcpu *vcpu);
41628d33 561bool kvm_vcpu_yield_to(struct kvm_vcpu *target);
d255f4f2 562void kvm_vcpu_on_spin(struct kvm_vcpu *vcpu);
6aa8b732 563void kvm_resched(struct kvm_vcpu *vcpu);
7702fd1f
AK
564void kvm_load_guest_fpu(struct kvm_vcpu *vcpu);
565void kvm_put_guest_fpu(struct kvm_vcpu *vcpu);
a4ee1ca4 566
d9e368d6 567void kvm_flush_remote_tlbs(struct kvm *kvm);
2e53d63a 568void kvm_reload_remote_mmus(struct kvm *kvm);
d828199e 569void kvm_make_mclock_inprogress_request(struct kvm *kvm);
c7c9c56c 570void kvm_make_update_eoibitmap_request(struct kvm *kvm);
6aa8b732 571
043405e1
CO
572long kvm_arch_dev_ioctl(struct file *filp,
573 unsigned int ioctl, unsigned long arg);
313a3dc7
CO
574long kvm_arch_vcpu_ioctl(struct file *filp,
575 unsigned int ioctl, unsigned long arg);
5b1c1493 576int kvm_arch_vcpu_fault(struct kvm_vcpu *vcpu, struct vm_fault *vmf);
018d00d2
ZX
577
578int kvm_dev_ioctl_check_extension(long ext);
579
5bb064dc
ZX
580int kvm_get_dirty_log(struct kvm *kvm,
581 struct kvm_dirty_log *log, int *is_dirty);
582int kvm_vm_ioctl_get_dirty_log(struct kvm *kvm,
583 struct kvm_dirty_log *log);
584
1fe779f8 585int kvm_vm_ioctl_set_memory_region(struct kvm *kvm,
47ae31e2 586 struct kvm_userspace_memory_region *mem);
23d43cf9 587int kvm_vm_ioctl_irq_line(struct kvm *kvm, struct kvm_irq_level *irq_level);
1fe779f8
CO
588long kvm_arch_vm_ioctl(struct file *filp,
589 unsigned int ioctl, unsigned long arg);
313a3dc7 590
d0752060
HB
591int kvm_arch_vcpu_ioctl_get_fpu(struct kvm_vcpu *vcpu, struct kvm_fpu *fpu);
592int kvm_arch_vcpu_ioctl_set_fpu(struct kvm_vcpu *vcpu, struct kvm_fpu *fpu);
593
8b006791
ZX
594int kvm_arch_vcpu_ioctl_translate(struct kvm_vcpu *vcpu,
595 struct kvm_translation *tr);
596
b6c7a5dc
HB
597int kvm_arch_vcpu_ioctl_get_regs(struct kvm_vcpu *vcpu, struct kvm_regs *regs);
598int kvm_arch_vcpu_ioctl_set_regs(struct kvm_vcpu *vcpu, struct kvm_regs *regs);
599int kvm_arch_vcpu_ioctl_get_sregs(struct kvm_vcpu *vcpu,
600 struct kvm_sregs *sregs);
601int kvm_arch_vcpu_ioctl_set_sregs(struct kvm_vcpu *vcpu,
602 struct kvm_sregs *sregs);
62d9f0db
MT
603int kvm_arch_vcpu_ioctl_get_mpstate(struct kvm_vcpu *vcpu,
604 struct kvm_mp_state *mp_state);
605int kvm_arch_vcpu_ioctl_set_mpstate(struct kvm_vcpu *vcpu,
606 struct kvm_mp_state *mp_state);
d0bfb940
JK
607int kvm_arch_vcpu_ioctl_set_guest_debug(struct kvm_vcpu *vcpu,
608 struct kvm_guest_debug *dbg);
b6c7a5dc
HB
609int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run);
610
f8c16bba
ZX
611int kvm_arch_init(void *opaque);
612void kvm_arch_exit(void);
043405e1 613
e9b11c17
ZX
614int kvm_arch_vcpu_init(struct kvm_vcpu *vcpu);
615void kvm_arch_vcpu_uninit(struct kvm_vcpu *vcpu);
616
617void kvm_arch_vcpu_free(struct kvm_vcpu *vcpu);
618void kvm_arch_vcpu_load(struct kvm_vcpu *vcpu, int cpu);
619void kvm_arch_vcpu_put(struct kvm_vcpu *vcpu);
620struct kvm_vcpu *kvm_arch_vcpu_create(struct kvm *kvm, unsigned int id);
26e5215f 621int kvm_arch_vcpu_setup(struct kvm_vcpu *vcpu);
42897d86 622int kvm_arch_vcpu_postcreate(struct kvm_vcpu *vcpu);
d40ccc62 623void kvm_arch_vcpu_destroy(struct kvm_vcpu *vcpu);
e9b11c17 624
10474ae8 625int kvm_arch_hardware_enable(void *garbage);
e9b11c17
ZX
626void kvm_arch_hardware_disable(void *garbage);
627int kvm_arch_hardware_setup(void);
628void kvm_arch_hardware_unsetup(void);
629void kvm_arch_check_processor_compat(void *rtn);
1d737c8a 630int kvm_arch_vcpu_runnable(struct kvm_vcpu *vcpu);
b6d33834 631int kvm_arch_vcpu_should_kick(struct kvm_vcpu *vcpu);
e9b11c17 632
d19a9cd2
ZX
633void kvm_free_physmem(struct kvm *kvm);
634
c1a7b32a
TY
635void *kvm_kvzalloc(unsigned long size);
636void kvm_kvfree(const void *addr);
637
d89f5eff
JK
638#ifndef __KVM_HAVE_ARCH_VM_ALLOC
639static inline struct kvm *kvm_arch_alloc_vm(void)
640{
641 return kzalloc(sizeof(struct kvm), GFP_KERNEL);
642}
643
644static inline void kvm_arch_free_vm(struct kvm *kvm)
645{
646 kfree(kvm);
647}
648#endif
649
b6d33834
CD
650static inline wait_queue_head_t *kvm_arch_vcpu_wq(struct kvm_vcpu *vcpu)
651{
2246f8b5
AG
652#ifdef __KVM_HAVE_ARCH_WQP
653 return vcpu->arch.wqp;
654#else
b6d33834 655 return &vcpu->wq;
b6d33834 656#endif
2246f8b5 657}
b6d33834 658
e08b9637 659int kvm_arch_init_vm(struct kvm *kvm, unsigned long type);
d19a9cd2 660void kvm_arch_destroy_vm(struct kvm *kvm);
8a98f664 661void kvm_free_all_assigned_devices(struct kvm *kvm);
ad8ba2cd 662void kvm_arch_sync_events(struct kvm *kvm);
e9b11c17 663
3d80840d 664int kvm_cpu_has_pending_timer(struct kvm_vcpu *vcpu);
5736199a 665void kvm_vcpu_kick(struct kvm_vcpu *vcpu);
682c59a3 666
a2766325 667bool kvm_is_mmio_pfn(pfn_t pfn);
c77fb9dc 668
62c476c7
BAY
669struct kvm_irq_ack_notifier {
670 struct hlist_node link;
671 unsigned gsi;
672 void (*irq_acked)(struct kvm_irq_ack_notifier *kian);
673};
674
675struct kvm_assigned_dev_kernel {
676 struct kvm_irq_ack_notifier ack_notifier;
62c476c7
BAY
677 struct list_head list;
678 int assigned_dev_id;
ab9f4ecb 679 int host_segnr;
62c476c7
BAY
680 int host_busnr;
681 int host_devfn;
c1e01514 682 unsigned int entries_nr;
62c476c7 683 int host_irq;
defaf158 684 bool host_irq_disabled;
07700a94 685 bool pci_2_3;
c1e01514 686 struct msix_entry *host_msix_entries;
62c476c7 687 int guest_irq;
0645211c 688 struct msix_entry *guest_msix_entries;
4f906c19 689 unsigned long irq_requested_type;
5550af4d 690 int irq_source_id;
b653574a 691 int flags;
62c476c7
BAY
692 struct pci_dev *dev;
693 struct kvm *kvm;
0645211c 694 spinlock_t intx_lock;
cf9eeac4 695 spinlock_t intx_mask_lock;
1e001d49 696 char irq_name[32];
f8fcfd77 697 struct pci_saved_state *pci_saved_state;
62c476c7 698};
75858a84
AK
699
700struct kvm_irq_mask_notifier {
701 void (*func)(struct kvm_irq_mask_notifier *kimn, bool masked);
702 int irq;
703 struct hlist_node link;
704};
705
706void kvm_register_irq_mask_notifier(struct kvm *kvm, int irq,
707 struct kvm_irq_mask_notifier *kimn);
708void kvm_unregister_irq_mask_notifier(struct kvm *kvm, int irq,
709 struct kvm_irq_mask_notifier *kimn);
4a994358
GN
710void kvm_fire_mask_notifiers(struct kvm *kvm, unsigned irqchip, unsigned pin,
711 bool mask);
75858a84 712
46e624b9
GN
713#ifdef __KVM_HAVE_IOAPIC
714void kvm_get_intr_delivery_bitmask(struct kvm_ioapic *ioapic,
715 union kvm_ioapic_redirect_entry *entry,
716 unsigned long *deliver_bitmask);
717#endif
718int kvm_set_irq(struct kvm *kvm, int irq_source_id, u32 irq, int level);
01f21880 719int kvm_set_irq_inatomic(struct kvm *kvm, int irq_source_id, u32 irq, int level);
bd2b53b2
MT
720int kvm_set_msi(struct kvm_kernel_irq_routing_entry *irq_entry, struct kvm *kvm,
721 int irq_source_id, int level);
c7c9c56c 722bool kvm_irq_has_notifier(struct kvm *kvm, unsigned irqchip, unsigned pin);
44882eed 723void kvm_notify_acked_irq(struct kvm *kvm, unsigned irqchip, unsigned pin);
3de42dc0
XZ
724void kvm_register_irq_ack_notifier(struct kvm *kvm,
725 struct kvm_irq_ack_notifier *kian);
fa40a821
MT
726void kvm_unregister_irq_ack_notifier(struct kvm *kvm,
727 struct kvm_irq_ack_notifier *kian);
5550af4d
SY
728int kvm_request_irq_source_id(struct kvm *kvm);
729void kvm_free_irq_source_id(struct kvm *kvm, int irq_source_id);
62c476c7 730
522c68c4
SY
731/* For vcpu->arch.iommu_flags */
732#define KVM_IOMMU_CACHE_COHERENCY 0x1
733
19de40a8 734#ifdef CONFIG_IOMMU_API
3ad26d81 735int kvm_iommu_map_pages(struct kvm *kvm, struct kvm_memory_slot *slot);
32f6daad 736void kvm_iommu_unmap_pages(struct kvm *kvm, struct kvm_memory_slot *slot);
260782bc 737int kvm_iommu_map_guest(struct kvm *kvm);
62c476c7 738int kvm_iommu_unmap_guest(struct kvm *kvm);
260782bc
WH
739int kvm_assign_device(struct kvm *kvm,
740 struct kvm_assigned_dev_kernel *assigned_dev);
0a920356
WH
741int kvm_deassign_device(struct kvm *kvm,
742 struct kvm_assigned_dev_kernel *assigned_dev);
19de40a8 743#else /* CONFIG_IOMMU_API */
62c476c7 744static inline int kvm_iommu_map_pages(struct kvm *kvm,
d7a79b6c 745 struct kvm_memory_slot *slot)
62c476c7
BAY
746{
747 return 0;
748}
749
32f6daad
AW
750static inline void kvm_iommu_unmap_pages(struct kvm *kvm,
751 struct kvm_memory_slot *slot)
752{
753}
754
260782bc 755static inline int kvm_iommu_map_guest(struct kvm *kvm)
62c476c7
BAY
756{
757 return -ENODEV;
758}
759
760static inline int kvm_iommu_unmap_guest(struct kvm *kvm)
761{
762 return 0;
763}
260782bc
WH
764
765static inline int kvm_assign_device(struct kvm *kvm,
766 struct kvm_assigned_dev_kernel *assigned_dev)
767{
768 return 0;
769}
0a920356
WH
770
771static inline int kvm_deassign_device(struct kvm *kvm,
772 struct kvm_assigned_dev_kernel *assigned_dev)
773{
774 return 0;
775}
19de40a8 776#endif /* CONFIG_IOMMU_API */
62c476c7 777
6a61671b 778static inline void __guest_enter(void)
d172fcd3 779{
b080935c
FW
780 /*
781 * This is running in ioctl context so we can avoid
782 * the call to vtime_account() with its unnecessary idle check.
783 */
c11f11fc 784 vtime_account_system(current);
d172fcd3 785 current->flags |= PF_VCPU;
c11f11fc
FW
786}
787
6a61671b 788static inline void __guest_exit(void)
c11f11fc
FW
789{
790 /*
791 * This is running in ioctl context so we can avoid
792 * the call to vtime_account() with its unnecessary idle check.
793 */
794 vtime_account_system(current);
795 current->flags &= ~PF_VCPU;
796}
797
6a61671b
FW
798#ifdef CONFIG_CONTEXT_TRACKING
799extern void guest_enter(void);
800extern void guest_exit(void);
801
802#else /* !CONFIG_CONTEXT_TRACKING */
803static inline void guest_enter(void)
804{
805 __guest_enter();
806}
807
808static inline void guest_exit(void)
809{
810 __guest_exit();
811}
812#endif /* !CONFIG_CONTEXT_TRACKING */
813
c11f11fc
FW
814static inline void kvm_guest_enter(void)
815{
816 unsigned long flags;
817
818 BUG_ON(preemptible());
819
820 local_irq_save(flags);
821 guest_enter();
822 local_irq_restore(flags);
823
8fa22068
GN
824 /* KVM does not hold any references to rcu protected data when it
825 * switches CPU into a guest mode. In fact switching to a guest mode
826 * is very similar to exiting to userspase from rcu point of view. In
827 * addition CPU may stay in a guest mode for quite a long time (up to
828 * one time slice). Lets treat guest mode as quiescent state, just like
829 * we do with user-mode execution.
830 */
831 rcu_virt_note_context_switch(smp_processor_id());
d172fcd3
LV
832}
833
834static inline void kvm_guest_exit(void)
835{
c11f11fc
FW
836 unsigned long flags;
837
838 local_irq_save(flags);
839 guest_exit();
840 local_irq_restore(flags);
d172fcd3
LV
841}
842
9d4cba7f
PM
843/*
844 * search_memslots() and __gfn_to_memslot() are here because they are
845 * used in non-modular code in arch/powerpc/kvm/book3s_hv_rm_mmu.c.
846 * gfn_to_memslot() itself isn't here as an inline because that would
847 * bloat other code too much.
848 */
849static inline struct kvm_memory_slot *
850search_memslots(struct kvm_memslots *slots, gfn_t gfn)
851{
852 struct kvm_memory_slot *memslot;
853
854 kvm_for_each_memslot(memslot, slots)
855 if (gfn >= memslot->base_gfn &&
856 gfn < memslot->base_gfn + memslot->npages)
857 return memslot;
858
859 return NULL;
860}
861
862static inline struct kvm_memory_slot *
863__gfn_to_memslot(struct kvm_memslots *slots, gfn_t gfn)
864{
865 return search_memslots(slots, gfn);
866}
867
66a03505
GS
868static inline unsigned long
869__gfn_to_hva_memslot(struct kvm_memory_slot *slot, gfn_t gfn)
870{
871 return slot->userspace_addr + (gfn - slot->base_gfn) * PAGE_SIZE;
872}
873
0ee8dcb8
XG
874static inline int memslot_id(struct kvm *kvm, gfn_t gfn)
875{
876 return gfn_to_memslot(kvm, gfn)->id;
877}
878
fb03cb6f
TY
879static inline gfn_t gfn_to_index(gfn_t gfn, gfn_t base_gfn, int level)
880{
881 /* KVM_HPAGE_GFN_SHIFT(PT_PAGE_TABLE_LEVEL) must be 0. */
882 return (gfn >> KVM_HPAGE_GFN_SHIFT(level)) -
883 (base_gfn >> KVM_HPAGE_GFN_SHIFT(level));
884}
885
d19a748b
TY
886static inline gfn_t
887hva_to_gfn_memslot(unsigned long hva, struct kvm_memory_slot *slot)
887c08ac 888{
d19a748b
TY
889 gfn_t gfn_offset = (hva - slot->userspace_addr) >> PAGE_SHIFT;
890
891 return slot->base_gfn + gfn_offset;
887c08ac
XG
892}
893
1755fbcc
AK
894static inline gpa_t gfn_to_gpa(gfn_t gfn)
895{
896 return (gpa_t)gfn << PAGE_SHIFT;
897}
6aa8b732 898
c30a358d
JR
899static inline gfn_t gpa_to_gfn(gpa_t gpa)
900{
901 return (gfn_t)(gpa >> PAGE_SHIFT);
902}
903
62c476c7
BAY
904static inline hpa_t pfn_to_hpa(pfn_t pfn)
905{
906 return (hpa_t)pfn << PAGE_SHIFT;
907}
908
2f599714 909static inline void kvm_migrate_timers(struct kvm_vcpu *vcpu)
2f52d58c
AK
910{
911 set_bit(KVM_REQ_MIGRATE_TIMER, &vcpu->requests);
912}
913
ba1389b7
AK
914enum kvm_stat_kind {
915 KVM_STAT_VM,
916 KVM_STAT_VCPU,
917};
918
417bc304
HB
919struct kvm_stats_debugfs_item {
920 const char *name;
921 int offset;
ba1389b7 922 enum kvm_stat_kind kind;
417bc304
HB
923 struct dentry *dentry;
924};
925extern struct kvm_stats_debugfs_item debugfs_entries[];
76f7c879 926extern struct dentry *kvm_debugfs_dir;
d4c9ff2d 927
36c1ed82 928#if defined(CONFIG_MMU_NOTIFIER) && defined(KVM_ARCH_WANT_MMU_NOTIFIER)
8ca40a70 929static inline int mmu_notifier_retry(struct kvm *kvm, unsigned long mmu_seq)
e930bffe 930{
8ca40a70 931 if (unlikely(kvm->mmu_notifier_count))
e930bffe
AA
932 return 1;
933 /*
a355aa54
PM
934 * Ensure the read of mmu_notifier_count happens before the read
935 * of mmu_notifier_seq. This interacts with the smp_wmb() in
936 * mmu_notifier_invalidate_range_end to make sure that the caller
937 * either sees the old (non-zero) value of mmu_notifier_count or
938 * the new (incremented) value of mmu_notifier_seq.
939 * PowerPC Book3s HV KVM calls this under a per-page lock
940 * rather than under kvm->mmu_lock, for scalability, so
941 * can't rely on kvm->mmu_lock to keep things ordered.
e930bffe 942 */
a355aa54 943 smp_rmb();
8ca40a70 944 if (kvm->mmu_notifier_seq != mmu_seq)
e930bffe
AA
945 return 1;
946 return 0;
947}
948#endif
949
9900b4b4 950#ifdef KVM_CAP_IRQ_ROUTING
399ec807
AK
951
952#define KVM_MAX_IRQ_ROUTES 1024
953
954int kvm_setup_default_irq_routing(struct kvm *kvm);
955int kvm_set_irq_routing(struct kvm *kvm,
956 const struct kvm_irq_routing_entry *entries,
957 unsigned nr,
958 unsigned flags);
959void kvm_free_irq_routing(struct kvm *kvm);
960
07975ad3
JK
961int kvm_send_userspace_msi(struct kvm *kvm, struct kvm_msi *msi);
962
399ec807
AK
963#else
964
965static inline void kvm_free_irq_routing(struct kvm *kvm) {}
966
967#endif
968
721eecbf
GH
969#ifdef CONFIG_HAVE_KVM_EVENTFD
970
d34e6b17 971void kvm_eventfd_init(struct kvm *kvm);
914daba8
AG
972int kvm_ioeventfd(struct kvm *kvm, struct kvm_ioeventfd *args);
973
974#ifdef CONFIG_HAVE_KVM_IRQCHIP
d4db2935 975int kvm_irqfd(struct kvm *kvm, struct kvm_irqfd *args);
721eecbf 976void kvm_irqfd_release(struct kvm *kvm);
bd2b53b2 977void kvm_irq_routing_update(struct kvm *, struct kvm_irq_routing_table *);
914daba8
AG
978#else
979static inline int kvm_irqfd(struct kvm *kvm, struct kvm_irqfd *args)
980{
981 return -EINVAL;
982}
983
984static inline void kvm_irqfd_release(struct kvm *kvm) {}
985#endif
721eecbf
GH
986
987#else
988
d34e6b17 989static inline void kvm_eventfd_init(struct kvm *kvm) {}
bd2b53b2 990
d4db2935 991static inline int kvm_irqfd(struct kvm *kvm, struct kvm_irqfd *args)
721eecbf
GH
992{
993 return -EINVAL;
994}
995
996static inline void kvm_irqfd_release(struct kvm *kvm) {}
bd2b53b2 997
27923eb1 998#ifdef CONFIG_HAVE_KVM_IRQCHIP
bd2b53b2
MT
999static inline void kvm_irq_routing_update(struct kvm *kvm,
1000 struct kvm_irq_routing_table *irq_rt)
1001{
1002 rcu_assign_pointer(kvm->irq_routing, irq_rt);
1003}
27923eb1 1004#endif
bd2b53b2 1005
d34e6b17
GH
1006static inline int kvm_ioeventfd(struct kvm *kvm, struct kvm_ioeventfd *args)
1007{
1008 return -ENOSYS;
1009}
721eecbf
GH
1010
1011#endif /* CONFIG_HAVE_KVM_EVENTFD */
1012
73880c80 1013#ifdef CONFIG_KVM_APIC_ARCHITECTURE
c5af89b6
GN
1014static inline bool kvm_vcpu_is_bsp(struct kvm_vcpu *vcpu)
1015{
d3efc8ef 1016 return vcpu->kvm->bsp_vcpu_id == vcpu->vcpu_id;
c5af89b6 1017}
3e515705
AK
1018
1019bool kvm_vcpu_compatible(struct kvm_vcpu *vcpu);
1020
1021#else
1022
1023static inline bool kvm_vcpu_compatible(struct kvm_vcpu *vcpu) { return true; }
1024
6aa8b732 1025#endif
bfd99ff5
AK
1026
1027#ifdef __KVM_HAVE_DEVICE_ASSIGNMENT
1028
1029long kvm_vm_ioctl_assigned_device(struct kvm *kvm, unsigned ioctl,
1030 unsigned long arg);
1031
1032#else
1033
1034static inline long kvm_vm_ioctl_assigned_device(struct kvm *kvm, unsigned ioctl,
1035 unsigned long arg)
1036{
1037 return -ENOTTY;
1038}
1039
73880c80 1040#endif
bfd99ff5 1041
a8eeb04a
AK
1042static inline void kvm_make_request(int req, struct kvm_vcpu *vcpu)
1043{
1044 set_bit(req, &vcpu->requests);
1045}
1046
a8eeb04a
AK
1047static inline bool kvm_check_request(int req, struct kvm_vcpu *vcpu)
1048{
0719837c
AK
1049 if (test_bit(req, &vcpu->requests)) {
1050 clear_bit(req, &vcpu->requests);
1051 return true;
1052 } else {
1053 return false;
1054 }
a8eeb04a
AK
1055}
1056
4c088493
R
1057#ifdef CONFIG_HAVE_KVM_CPU_RELAX_INTERCEPT
1058
1059static inline void kvm_vcpu_set_in_spin_loop(struct kvm_vcpu *vcpu, bool val)
1060{
1061 vcpu->spin_loop.in_spin_loop = val;
1062}
1063static inline void kvm_vcpu_set_dy_eligible(struct kvm_vcpu *vcpu, bool val)
1064{
1065 vcpu->spin_loop.dy_eligible = val;
1066}
1067
1068#else /* !CONFIG_HAVE_KVM_CPU_RELAX_INTERCEPT */
1069
1070static inline void kvm_vcpu_set_in_spin_loop(struct kvm_vcpu *vcpu, bool val)
1071{
1072}
1073
1074static inline void kvm_vcpu_set_dy_eligible(struct kvm_vcpu *vcpu, bool val)
1075{
1076}
1077
06e48c51
R
1078static inline bool kvm_vcpu_eligible_for_directed_yield(struct kvm_vcpu *vcpu)
1079{
1080 return true;
1081}
1082
4c088493 1083#endif /* CONFIG_HAVE_KVM_CPU_RELAX_INTERCEPT */
bfd99ff5
AK
1084#endif
1085