kvm_host.h 30 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135
  1. #ifndef __KVM_HOST_H
  2. #define __KVM_HOST_H
  3. #if IS_ENABLED(CONFIG_KVM)
  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. #include <linux/types.h>
  9. #include <linux/hardirq.h>
  10. #include <linux/list.h>
  11. #include <linux/mutex.h>
  12. #include <linux/spinlock.h>
  13. #include <linux/signal.h>
  14. #include <linux/sched.h>
  15. #include <linux/bug.h>
  16. #include <linux/mm.h>
  17. #include <linux/mmu_notifier.h>
  18. #include <linux/preempt.h>
  19. #include <linux/msi.h>
  20. #include <linux/slab.h>
  21. #include <linux/rcupdate.h>
  22. #include <linux/ratelimit.h>
  23. #include <linux/err.h>
  24. #include <linux/irqflags.h>
  25. #include <asm/signal.h>
  26. #include <linux/kvm.h>
  27. #include <linux/kvm_para.h>
  28. #include <linux/kvm_types.h>
  29. #include <asm/kvm_host.h>
  30. #ifndef KVM_MMIO_SIZE
  31. #define KVM_MMIO_SIZE 8
  32. #endif
  33. /*
  34. * The bit 16 ~ bit 31 of kvm_memory_region::flags are internally used
  35. * in kvm, other bits are visible for userspace which are defined in
  36. * include/linux/kvm_h.
  37. */
  38. #define KVM_MEMSLOT_INVALID (1UL << 16)
  39. /* Two fragments for cross MMIO pages. */
  40. #define KVM_MAX_MMIO_FRAGMENTS 2
  41. /*
  42. * For the normal pfn, the highest 12 bits should be zero,
  43. * so we can mask bit 62 ~ bit 52 to indicate the error pfn,
  44. * mask bit 63 to indicate the noslot pfn.
  45. */
  46. #define KVM_PFN_ERR_MASK (0x7ffULL << 52)
  47. #define KVM_PFN_ERR_NOSLOT_MASK (0xfffULL << 52)
  48. #define KVM_PFN_NOSLOT (0x1ULL << 63)
  49. #define KVM_PFN_ERR_FAULT (KVM_PFN_ERR_MASK)
  50. #define KVM_PFN_ERR_HWPOISON (KVM_PFN_ERR_MASK + 1)
  51. #define KVM_PFN_ERR_RO_FAULT (KVM_PFN_ERR_MASK + 2)
  52. /*
  53. * error pfns indicate that the gfn is in slot but faild to
  54. * translate it to pfn on host.
  55. */
  56. static inline bool is_error_pfn(pfn_t pfn)
  57. {
  58. return !!(pfn & KVM_PFN_ERR_MASK);
  59. }
  60. /*
  61. * error_noslot pfns indicate that the gfn can not be
  62. * translated to pfn - it is not in slot or failed to
  63. * translate it to pfn.
  64. */
  65. static inline bool is_error_noslot_pfn(pfn_t pfn)
  66. {
  67. return !!(pfn & KVM_PFN_ERR_NOSLOT_MASK);
  68. }
  69. /* noslot pfn indicates that the gfn is not in slot. */
  70. static inline bool is_noslot_pfn(pfn_t pfn)
  71. {
  72. return pfn == KVM_PFN_NOSLOT;
  73. }
  74. #define KVM_HVA_ERR_BAD (PAGE_OFFSET)
  75. #define KVM_HVA_ERR_RO_BAD (PAGE_OFFSET + PAGE_SIZE)
  76. static inline bool kvm_is_error_hva(unsigned long addr)
  77. {
  78. return addr >= PAGE_OFFSET;
  79. }
  80. #define KVM_ERR_PTR_BAD_PAGE (ERR_PTR(-ENOENT))
  81. static inline bool is_error_page(struct page *page)
  82. {
  83. return IS_ERR(page);
  84. }
  85. /*
  86. * vcpu->requests bit members
  87. */
  88. #define KVM_REQ_TLB_FLUSH 0
  89. #define KVM_REQ_MIGRATE_TIMER 1
  90. #define KVM_REQ_REPORT_TPR_ACCESS 2
  91. #define KVM_REQ_MMU_RELOAD 3
  92. #define KVM_REQ_TRIPLE_FAULT 4
  93. #define KVM_REQ_PENDING_TIMER 5
  94. #define KVM_REQ_UNHALT 6
  95. #define KVM_REQ_MMU_SYNC 7
  96. #define KVM_REQ_CLOCK_UPDATE 8
  97. #define KVM_REQ_KICK 9
  98. #define KVM_REQ_DEACTIVATE_FPU 10
  99. #define KVM_REQ_EVENT 11
  100. #define KVM_REQ_APF_HALT 12
  101. #define KVM_REQ_STEAL_UPDATE 13
  102. #define KVM_REQ_NMI 14
  103. #define KVM_REQ_PMU 15
  104. #define KVM_REQ_PMI 16
  105. #define KVM_REQ_WATCHDOG 17
  106. #define KVM_REQ_MASTERCLOCK_UPDATE 18
  107. #define KVM_REQ_MCLOCK_INPROGRESS 19
  108. #define KVM_REQ_EPR_EXIT 20
  109. #define KVM_REQ_SCAN_IOAPIC 21
  110. #define KVM_USERSPACE_IRQ_SOURCE_ID 0
  111. #define KVM_IRQFD_RESAMPLE_IRQ_SOURCE_ID 1
  112. struct kvm;
  113. struct kvm_vcpu;
  114. extern struct kmem_cache *kvm_vcpu_cache;
  115. extern raw_spinlock_t kvm_lock;
  116. extern struct list_head vm_list;
  117. struct kvm_io_range {
  118. gpa_t addr;
  119. int len;
  120. struct kvm_io_device *dev;
  121. };
  122. #define NR_IOBUS_DEVS 1000
  123. struct kvm_io_bus {
  124. int dev_count;
  125. struct kvm_io_range range[];
  126. };
  127. enum kvm_bus {
  128. KVM_MMIO_BUS,
  129. KVM_PIO_BUS,
  130. KVM_VIRTIO_CCW_NOTIFY_BUS,
  131. KVM_NR_BUSES
  132. };
  133. int kvm_io_bus_write(struct kvm *kvm, enum kvm_bus bus_idx, gpa_t addr,
  134. int len, const void *val);
  135. int kvm_io_bus_read(struct kvm *kvm, enum kvm_bus bus_idx, gpa_t addr, int len,
  136. void *val);
  137. int kvm_io_bus_register_dev(struct kvm *kvm, enum kvm_bus bus_idx, gpa_t addr,
  138. int len, struct kvm_io_device *dev);
  139. int kvm_io_bus_unregister_dev(struct kvm *kvm, enum kvm_bus bus_idx,
  140. struct kvm_io_device *dev);
  141. #ifdef CONFIG_KVM_ASYNC_PF
  142. struct kvm_async_pf {
  143. struct work_struct work;
  144. struct list_head link;
  145. struct list_head queue;
  146. struct kvm_vcpu *vcpu;
  147. struct mm_struct *mm;
  148. gva_t gva;
  149. unsigned long addr;
  150. struct kvm_arch_async_pf arch;
  151. struct page *page;
  152. bool done;
  153. };
  154. void kvm_clear_async_pf_completion_queue(struct kvm_vcpu *vcpu);
  155. void kvm_check_async_pf_completion(struct kvm_vcpu *vcpu);
  156. int kvm_setup_async_pf(struct kvm_vcpu *vcpu, gva_t gva, gfn_t gfn,
  157. struct kvm_arch_async_pf *arch);
  158. int kvm_async_pf_wakeup_all(struct kvm_vcpu *vcpu);
  159. #endif
  160. enum {
  161. OUTSIDE_GUEST_MODE,
  162. IN_GUEST_MODE,
  163. EXITING_GUEST_MODE,
  164. READING_SHADOW_PAGE_TABLES,
  165. };
  166. /*
  167. * Sometimes a large or cross-page mmio needs to be broken up into separate
  168. * exits for userspace servicing.
  169. */
  170. struct kvm_mmio_fragment {
  171. gpa_t gpa;
  172. void *data;
  173. unsigned len;
  174. };
  175. struct kvm_vcpu {
  176. struct kvm *kvm;
  177. #ifdef CONFIG_PREEMPT_NOTIFIERS
  178. struct preempt_notifier preempt_notifier;
  179. #endif
  180. int cpu;
  181. int vcpu_id;
  182. int srcu_idx;
  183. int mode;
  184. unsigned long requests;
  185. unsigned long guest_debug;
  186. struct mutex mutex;
  187. struct kvm_run *run;
  188. int fpu_active;
  189. int guest_fpu_loaded, guest_xcr0_loaded;
  190. wait_queue_head_t wq;
  191. struct pid *pid;
  192. int sigset_active;
  193. sigset_t sigset;
  194. struct kvm_vcpu_stat stat;
  195. #ifdef CONFIG_HAS_IOMEM
  196. int mmio_needed;
  197. int mmio_read_completed;
  198. int mmio_is_write;
  199. int mmio_cur_fragment;
  200. int mmio_nr_fragments;
  201. struct kvm_mmio_fragment mmio_fragments[KVM_MAX_MMIO_FRAGMENTS];
  202. #endif
  203. #ifdef CONFIG_KVM_ASYNC_PF
  204. struct {
  205. u32 queued;
  206. struct list_head queue;
  207. struct list_head done;
  208. spinlock_t lock;
  209. } async_pf;
  210. #endif
  211. #ifdef CONFIG_HAVE_KVM_CPU_RELAX_INTERCEPT
  212. /*
  213. * Cpu relax intercept or pause loop exit optimization
  214. * in_spin_loop: set when a vcpu does a pause loop exit
  215. * or cpu relax intercepted.
  216. * dy_eligible: indicates whether vcpu is eligible for directed yield.
  217. */
  218. struct {
  219. bool in_spin_loop;
  220. bool dy_eligible;
  221. } spin_loop;
  222. #endif
  223. bool preempted;
  224. struct kvm_vcpu_arch arch;
  225. };
  226. static inline int kvm_vcpu_exiting_guest_mode(struct kvm_vcpu *vcpu)
  227. {
  228. return cmpxchg(&vcpu->mode, IN_GUEST_MODE, EXITING_GUEST_MODE);
  229. }
  230. /*
  231. * Some of the bitops functions do not support too long bitmaps.
  232. * This number must be determined not to exceed such limits.
  233. */
  234. #define KVM_MEM_MAX_NR_PAGES ((1UL << 31) - 1)
  235. struct kvm_memory_slot {
  236. gfn_t base_gfn;
  237. unsigned long npages;
  238. unsigned long *dirty_bitmap;
  239. struct kvm_arch_memory_slot arch;
  240. unsigned long userspace_addr;
  241. u32 flags;
  242. short id;
  243. };
  244. static inline unsigned long kvm_dirty_bitmap_bytes(struct kvm_memory_slot *memslot)
  245. {
  246. return ALIGN(memslot->npages, BITS_PER_LONG) / 8;
  247. }
  248. struct kvm_kernel_irq_routing_entry {
  249. u32 gsi;
  250. u32 type;
  251. int (*set)(struct kvm_kernel_irq_routing_entry *e,
  252. struct kvm *kvm, int irq_source_id, int level,
  253. bool line_status);
  254. union {
  255. struct {
  256. unsigned irqchip;
  257. unsigned pin;
  258. } irqchip;
  259. struct msi_msg msi;
  260. };
  261. struct hlist_node link;
  262. };
  263. #ifdef CONFIG_HAVE_KVM_IRQ_ROUTING
  264. struct kvm_irq_routing_table {
  265. int chip[KVM_NR_IRQCHIPS][KVM_IRQCHIP_NUM_PINS];
  266. struct kvm_kernel_irq_routing_entry *rt_entries;
  267. u32 nr_rt_entries;
  268. /*
  269. * Array indexed by gsi. Each entry contains list of irq chips
  270. * the gsi is connected to.
  271. */
  272. struct hlist_head map[0];
  273. };
  274. #else
  275. struct kvm_irq_routing_table {};
  276. #endif
  277. #ifndef KVM_PRIVATE_MEM_SLOTS
  278. #define KVM_PRIVATE_MEM_SLOTS 0
  279. #endif
  280. #ifndef KVM_MEM_SLOTS_NUM
  281. #define KVM_MEM_SLOTS_NUM (KVM_USER_MEM_SLOTS + KVM_PRIVATE_MEM_SLOTS)
  282. #endif
  283. /*
  284. * Note:
  285. * memslots are not sorted by id anymore, please use id_to_memslot()
  286. * to get the memslot by its id.
  287. */
  288. struct kvm_memslots {
  289. u64 generation;
  290. struct kvm_memory_slot memslots[KVM_MEM_SLOTS_NUM];
  291. /* The mapping table from slot id to the index in memslots[]. */
  292. short id_to_index[KVM_MEM_SLOTS_NUM];
  293. };
  294. struct kvm {
  295. spinlock_t mmu_lock;
  296. struct mutex slots_lock;
  297. struct mm_struct *mm; /* userspace tied to this vm */
  298. struct kvm_memslots *memslots;
  299. struct srcu_struct srcu;
  300. #ifdef CONFIG_KVM_APIC_ARCHITECTURE
  301. u32 bsp_vcpu_id;
  302. #endif
  303. struct kvm_vcpu *vcpus[KVM_MAX_VCPUS];
  304. atomic_t online_vcpus;
  305. int last_boosted_vcpu;
  306. struct list_head vm_list;
  307. struct mutex lock;
  308. struct kvm_io_bus *buses[KVM_NR_BUSES];
  309. #ifdef CONFIG_HAVE_KVM_EVENTFD
  310. struct {
  311. spinlock_t lock;
  312. struct list_head items;
  313. struct list_head resampler_list;
  314. struct mutex resampler_lock;
  315. } irqfds;
  316. struct list_head ioeventfds;
  317. #endif
  318. struct kvm_vm_stat stat;
  319. struct kvm_arch arch;
  320. atomic_t users_count;
  321. #ifdef KVM_COALESCED_MMIO_PAGE_OFFSET
  322. struct kvm_coalesced_mmio_ring *coalesced_mmio_ring;
  323. spinlock_t ring_lock;
  324. struct list_head coalesced_zones;
  325. #endif
  326. struct mutex irq_lock;
  327. #ifdef CONFIG_HAVE_KVM_IRQCHIP
  328. /*
  329. * Update side is protected by irq_lock and,
  330. * if configured, irqfds.lock.
  331. */
  332. struct kvm_irq_routing_table __rcu *irq_routing;
  333. struct hlist_head mask_notifier_list;
  334. struct hlist_head irq_ack_notifier_list;
  335. #endif
  336. #if defined(CONFIG_MMU_NOTIFIER) && defined(KVM_ARCH_WANT_MMU_NOTIFIER)
  337. struct mmu_notifier mmu_notifier;
  338. unsigned long mmu_notifier_seq;
  339. long mmu_notifier_count;
  340. #endif
  341. long tlbs_dirty;
  342. struct list_head devices;
  343. };
  344. #define kvm_err(fmt, ...) \
  345. pr_err("kvm [%i]: " fmt, task_pid_nr(current), ## __VA_ARGS__)
  346. #define kvm_info(fmt, ...) \
  347. pr_info("kvm [%i]: " fmt, task_pid_nr(current), ## __VA_ARGS__)
  348. #define kvm_debug(fmt, ...) \
  349. pr_debug("kvm [%i]: " fmt, task_pid_nr(current), ## __VA_ARGS__)
  350. #define kvm_pr_unimpl(fmt, ...) \
  351. pr_err_ratelimited("kvm [%i]: " fmt, \
  352. task_tgid_nr(current), ## __VA_ARGS__)
  353. /* The guest did something we don't support. */
  354. #define vcpu_unimpl(vcpu, fmt, ...) \
  355. kvm_pr_unimpl("vcpu%i " fmt, (vcpu)->vcpu_id, ## __VA_ARGS__)
  356. static inline struct kvm_vcpu *kvm_get_vcpu(struct kvm *kvm, int i)
  357. {
  358. smp_rmb();
  359. return kvm->vcpus[i];
  360. }
  361. #define kvm_for_each_vcpu(idx, vcpup, kvm) \
  362. for (idx = 0; \
  363. idx < atomic_read(&kvm->online_vcpus) && \
  364. (vcpup = kvm_get_vcpu(kvm, idx)) != NULL; \
  365. idx++)
  366. #define kvm_for_each_memslot(memslot, slots) \
  367. for (memslot = &slots->memslots[0]; \
  368. memslot < slots->memslots + KVM_MEM_SLOTS_NUM && memslot->npages;\
  369. memslot++)
  370. int kvm_vcpu_init(struct kvm_vcpu *vcpu, struct kvm *kvm, unsigned id);
  371. void kvm_vcpu_uninit(struct kvm_vcpu *vcpu);
  372. int __must_check vcpu_load(struct kvm_vcpu *vcpu);
  373. void vcpu_put(struct kvm_vcpu *vcpu);
  374. #ifdef CONFIG_HAVE_KVM_IRQ_ROUTING
  375. int kvm_irqfd_init(void);
  376. void kvm_irqfd_exit(void);
  377. #else
  378. static inline int kvm_irqfd_init(void)
  379. {
  380. return 0;
  381. }
  382. static inline void kvm_irqfd_exit(void)
  383. {
  384. }
  385. #endif
  386. int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
  387. struct module *module);
  388. void kvm_exit(void);
  389. void kvm_get_kvm(struct kvm *kvm);
  390. void kvm_put_kvm(struct kvm *kvm);
  391. void update_memslots(struct kvm_memslots *slots, struct kvm_memory_slot *new,
  392. u64 last_generation);
  393. static inline struct kvm_memslots *kvm_memslots(struct kvm *kvm)
  394. {
  395. return rcu_dereference_check(kvm->memslots,
  396. srcu_read_lock_held(&kvm->srcu)
  397. || lockdep_is_held(&kvm->slots_lock));
  398. }
  399. static inline struct kvm_memory_slot *
  400. id_to_memslot(struct kvm_memslots *slots, int id)
  401. {
  402. int index = slots->id_to_index[id];
  403. struct kvm_memory_slot *slot;
  404. slot = &slots->memslots[index];
  405. WARN_ON(slot->id != id);
  406. return slot;
  407. }
  408. /*
  409. * KVM_SET_USER_MEMORY_REGION ioctl allows the following operations:
  410. * - create a new memory slot
  411. * - delete an existing memory slot
  412. * - modify an existing memory slot
  413. * -- move it in the guest physical memory space
  414. * -- just change its flags
  415. *
  416. * Since flags can be changed by some of these operations, the following
  417. * differentiation is the best we can do for __kvm_set_memory_region():
  418. */
  419. enum kvm_mr_change {
  420. KVM_MR_CREATE,
  421. KVM_MR_DELETE,
  422. KVM_MR_MOVE,
  423. KVM_MR_FLAGS_ONLY,
  424. };
  425. int kvm_set_memory_region(struct kvm *kvm,
  426. struct kvm_userspace_memory_region *mem);
  427. int __kvm_set_memory_region(struct kvm *kvm,
  428. struct kvm_userspace_memory_region *mem);
  429. void kvm_arch_free_memslot(struct kvm_memory_slot *free,
  430. struct kvm_memory_slot *dont);
  431. int kvm_arch_create_memslot(struct kvm_memory_slot *slot, unsigned long npages);
  432. int kvm_arch_prepare_memory_region(struct kvm *kvm,
  433. struct kvm_memory_slot *memslot,
  434. struct kvm_userspace_memory_region *mem,
  435. enum kvm_mr_change change);
  436. void kvm_arch_commit_memory_region(struct kvm *kvm,
  437. struct kvm_userspace_memory_region *mem,
  438. const struct kvm_memory_slot *old,
  439. enum kvm_mr_change change);
  440. bool kvm_largepages_enabled(void);
  441. void kvm_disable_largepages(void);
  442. /* flush all memory translations */
  443. void kvm_arch_flush_shadow_all(struct kvm *kvm);
  444. /* flush memory translations pointing to 'slot' */
  445. void kvm_arch_flush_shadow_memslot(struct kvm *kvm,
  446. struct kvm_memory_slot *slot);
  447. int gfn_to_page_many_atomic(struct kvm *kvm, gfn_t gfn, struct page **pages,
  448. int nr_pages);
  449. struct page *gfn_to_page(struct kvm *kvm, gfn_t gfn);
  450. unsigned long gfn_to_hva(struct kvm *kvm, gfn_t gfn);
  451. unsigned long gfn_to_hva_memslot(struct kvm_memory_slot *slot, gfn_t gfn);
  452. void kvm_release_page_clean(struct page *page);
  453. void kvm_release_page_dirty(struct page *page);
  454. void kvm_set_page_dirty(struct page *page);
  455. void kvm_set_page_accessed(struct page *page);
  456. pfn_t gfn_to_pfn_atomic(struct kvm *kvm, gfn_t gfn);
  457. pfn_t gfn_to_pfn_async(struct kvm *kvm, gfn_t gfn, bool *async,
  458. bool write_fault, bool *writable);
  459. pfn_t gfn_to_pfn(struct kvm *kvm, gfn_t gfn);
  460. pfn_t gfn_to_pfn_prot(struct kvm *kvm, gfn_t gfn, bool write_fault,
  461. bool *writable);
  462. pfn_t gfn_to_pfn_memslot(struct kvm_memory_slot *slot, gfn_t gfn);
  463. pfn_t gfn_to_pfn_memslot_atomic(struct kvm_memory_slot *slot, gfn_t gfn);
  464. void kvm_release_pfn_dirty(pfn_t pfn);
  465. void kvm_release_pfn_clean(pfn_t pfn);
  466. void kvm_set_pfn_dirty(pfn_t pfn);
  467. void kvm_set_pfn_accessed(pfn_t pfn);
  468. void kvm_get_pfn(pfn_t pfn);
  469. int kvm_read_guest_page(struct kvm *kvm, gfn_t gfn, void *data, int offset,
  470. int len);
  471. int kvm_read_guest_atomic(struct kvm *kvm, gpa_t gpa, void *data,
  472. unsigned long len);
  473. int kvm_read_guest(struct kvm *kvm, gpa_t gpa, void *data, unsigned long len);
  474. int kvm_read_guest_cached(struct kvm *kvm, struct gfn_to_hva_cache *ghc,
  475. void *data, unsigned long len);
  476. int kvm_write_guest_page(struct kvm *kvm, gfn_t gfn, const void *data,
  477. int offset, int len);
  478. int kvm_write_guest(struct kvm *kvm, gpa_t gpa, const void *data,
  479. unsigned long len);
  480. int kvm_write_guest_cached(struct kvm *kvm, struct gfn_to_hva_cache *ghc,
  481. void *data, unsigned long len);
  482. int kvm_gfn_to_hva_cache_init(struct kvm *kvm, struct gfn_to_hva_cache *ghc,
  483. gpa_t gpa);
  484. int kvm_clear_guest_page(struct kvm *kvm, gfn_t gfn, int offset, int len);
  485. int kvm_clear_guest(struct kvm *kvm, gpa_t gpa, unsigned long len);
  486. struct kvm_memory_slot *gfn_to_memslot(struct kvm *kvm, gfn_t gfn);
  487. int kvm_is_visible_gfn(struct kvm *kvm, gfn_t gfn);
  488. unsigned long kvm_host_page_size(struct kvm *kvm, gfn_t gfn);
  489. void mark_page_dirty(struct kvm *kvm, gfn_t gfn);
  490. void mark_page_dirty_in_slot(struct kvm *kvm, struct kvm_memory_slot *memslot,
  491. gfn_t gfn);
  492. void kvm_vcpu_block(struct kvm_vcpu *vcpu);
  493. void kvm_vcpu_kick(struct kvm_vcpu *vcpu);
  494. bool kvm_vcpu_yield_to(struct kvm_vcpu *target);
  495. void kvm_vcpu_on_spin(struct kvm_vcpu *vcpu);
  496. void kvm_resched(struct kvm_vcpu *vcpu);
  497. void kvm_load_guest_fpu(struct kvm_vcpu *vcpu);
  498. void kvm_put_guest_fpu(struct kvm_vcpu *vcpu);
  499. void kvm_flush_remote_tlbs(struct kvm *kvm);
  500. void kvm_reload_remote_mmus(struct kvm *kvm);
  501. void kvm_make_mclock_inprogress_request(struct kvm *kvm);
  502. void kvm_make_scan_ioapic_request(struct kvm *kvm);
  503. long kvm_arch_dev_ioctl(struct file *filp,
  504. unsigned int ioctl, unsigned long arg);
  505. long kvm_arch_vcpu_ioctl(struct file *filp,
  506. unsigned int ioctl, unsigned long arg);
  507. int kvm_arch_vcpu_fault(struct kvm_vcpu *vcpu, struct vm_fault *vmf);
  508. int kvm_dev_ioctl_check_extension(long ext);
  509. int kvm_get_dirty_log(struct kvm *kvm,
  510. struct kvm_dirty_log *log, int *is_dirty);
  511. int kvm_vm_ioctl_get_dirty_log(struct kvm *kvm,
  512. struct kvm_dirty_log *log);
  513. int kvm_vm_ioctl_set_memory_region(struct kvm *kvm,
  514. struct kvm_userspace_memory_region *mem);
  515. int kvm_vm_ioctl_irq_line(struct kvm *kvm, struct kvm_irq_level *irq_level,
  516. bool line_status);
  517. long kvm_arch_vm_ioctl(struct file *filp,
  518. unsigned int ioctl, unsigned long arg);
  519. int kvm_arch_vcpu_ioctl_get_fpu(struct kvm_vcpu *vcpu, struct kvm_fpu *fpu);
  520. int kvm_arch_vcpu_ioctl_set_fpu(struct kvm_vcpu *vcpu, struct kvm_fpu *fpu);
  521. int kvm_arch_vcpu_ioctl_translate(struct kvm_vcpu *vcpu,
  522. struct kvm_translation *tr);
  523. int kvm_arch_vcpu_ioctl_get_regs(struct kvm_vcpu *vcpu, struct kvm_regs *regs);
  524. int kvm_arch_vcpu_ioctl_set_regs(struct kvm_vcpu *vcpu, struct kvm_regs *regs);
  525. int kvm_arch_vcpu_ioctl_get_sregs(struct kvm_vcpu *vcpu,
  526. struct kvm_sregs *sregs);
  527. int kvm_arch_vcpu_ioctl_set_sregs(struct kvm_vcpu *vcpu,
  528. struct kvm_sregs *sregs);
  529. int kvm_arch_vcpu_ioctl_get_mpstate(struct kvm_vcpu *vcpu,
  530. struct kvm_mp_state *mp_state);
  531. int kvm_arch_vcpu_ioctl_set_mpstate(struct kvm_vcpu *vcpu,
  532. struct kvm_mp_state *mp_state);
  533. int kvm_arch_vcpu_ioctl_set_guest_debug(struct kvm_vcpu *vcpu,
  534. struct kvm_guest_debug *dbg);
  535. int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run);
  536. int kvm_arch_init(void *opaque);
  537. void kvm_arch_exit(void);
  538. int kvm_arch_vcpu_init(struct kvm_vcpu *vcpu);
  539. void kvm_arch_vcpu_uninit(struct kvm_vcpu *vcpu);
  540. void kvm_arch_vcpu_free(struct kvm_vcpu *vcpu);
  541. void kvm_arch_vcpu_load(struct kvm_vcpu *vcpu, int cpu);
  542. void kvm_arch_vcpu_put(struct kvm_vcpu *vcpu);
  543. struct kvm_vcpu *kvm_arch_vcpu_create(struct kvm *kvm, unsigned int id);
  544. int kvm_arch_vcpu_setup(struct kvm_vcpu *vcpu);
  545. int kvm_arch_vcpu_postcreate(struct kvm_vcpu *vcpu);
  546. void kvm_arch_vcpu_destroy(struct kvm_vcpu *vcpu);
  547. int kvm_arch_hardware_enable(void *garbage);
  548. void kvm_arch_hardware_disable(void *garbage);
  549. int kvm_arch_hardware_setup(void);
  550. void kvm_arch_hardware_unsetup(void);
  551. void kvm_arch_check_processor_compat(void *rtn);
  552. int kvm_arch_vcpu_runnable(struct kvm_vcpu *vcpu);
  553. int kvm_arch_vcpu_should_kick(struct kvm_vcpu *vcpu);
  554. void kvm_free_physmem(struct kvm *kvm);
  555. void *kvm_kvzalloc(unsigned long size);
  556. void kvm_kvfree(const void *addr);
  557. #ifndef __KVM_HAVE_ARCH_VM_ALLOC
  558. static inline struct kvm *kvm_arch_alloc_vm(void)
  559. {
  560. return kzalloc(sizeof(struct kvm), GFP_KERNEL);
  561. }
  562. static inline void kvm_arch_free_vm(struct kvm *kvm)
  563. {
  564. kfree(kvm);
  565. }
  566. #endif
  567. static inline wait_queue_head_t *kvm_arch_vcpu_wq(struct kvm_vcpu *vcpu)
  568. {
  569. #ifdef __KVM_HAVE_ARCH_WQP
  570. return vcpu->arch.wqp;
  571. #else
  572. return &vcpu->wq;
  573. #endif
  574. }
  575. int kvm_arch_init_vm(struct kvm *kvm, unsigned long type);
  576. void kvm_arch_destroy_vm(struct kvm *kvm);
  577. void kvm_free_all_assigned_devices(struct kvm *kvm);
  578. void kvm_arch_sync_events(struct kvm *kvm);
  579. int kvm_cpu_has_pending_timer(struct kvm_vcpu *vcpu);
  580. void kvm_vcpu_kick(struct kvm_vcpu *vcpu);
  581. bool kvm_is_mmio_pfn(pfn_t pfn);
  582. struct kvm_irq_ack_notifier {
  583. struct hlist_node link;
  584. unsigned gsi;
  585. void (*irq_acked)(struct kvm_irq_ack_notifier *kian);
  586. };
  587. struct kvm_assigned_dev_kernel {
  588. struct kvm_irq_ack_notifier ack_notifier;
  589. struct list_head list;
  590. int assigned_dev_id;
  591. int host_segnr;
  592. int host_busnr;
  593. int host_devfn;
  594. unsigned int entries_nr;
  595. int host_irq;
  596. bool host_irq_disabled;
  597. bool pci_2_3;
  598. struct msix_entry *host_msix_entries;
  599. int guest_irq;
  600. struct msix_entry *guest_msix_entries;
  601. unsigned long irq_requested_type;
  602. int irq_source_id;
  603. int flags;
  604. struct pci_dev *dev;
  605. struct kvm *kvm;
  606. spinlock_t intx_lock;
  607. spinlock_t intx_mask_lock;
  608. char irq_name[32];
  609. struct pci_saved_state *pci_saved_state;
  610. };
  611. struct kvm_irq_mask_notifier {
  612. void (*func)(struct kvm_irq_mask_notifier *kimn, bool masked);
  613. int irq;
  614. struct hlist_node link;
  615. };
  616. void kvm_register_irq_mask_notifier(struct kvm *kvm, int irq,
  617. struct kvm_irq_mask_notifier *kimn);
  618. void kvm_unregister_irq_mask_notifier(struct kvm *kvm, int irq,
  619. struct kvm_irq_mask_notifier *kimn);
  620. void kvm_fire_mask_notifiers(struct kvm *kvm, unsigned irqchip, unsigned pin,
  621. bool mask);
  622. int kvm_set_irq(struct kvm *kvm, int irq_source_id, u32 irq, int level,
  623. bool line_status);
  624. int kvm_set_irq_inatomic(struct kvm *kvm, int irq_source_id, u32 irq, int level);
  625. int kvm_set_msi(struct kvm_kernel_irq_routing_entry *irq_entry, struct kvm *kvm,
  626. int irq_source_id, int level, bool line_status);
  627. bool kvm_irq_has_notifier(struct kvm *kvm, unsigned irqchip, unsigned pin);
  628. void kvm_notify_acked_irq(struct kvm *kvm, unsigned irqchip, unsigned pin);
  629. void kvm_register_irq_ack_notifier(struct kvm *kvm,
  630. struct kvm_irq_ack_notifier *kian);
  631. void kvm_unregister_irq_ack_notifier(struct kvm *kvm,
  632. struct kvm_irq_ack_notifier *kian);
  633. int kvm_request_irq_source_id(struct kvm *kvm);
  634. void kvm_free_irq_source_id(struct kvm *kvm, int irq_source_id);
  635. /* For vcpu->arch.iommu_flags */
  636. #define KVM_IOMMU_CACHE_COHERENCY 0x1
  637. #ifdef CONFIG_IOMMU_API
  638. int kvm_iommu_map_pages(struct kvm *kvm, struct kvm_memory_slot *slot);
  639. void kvm_iommu_unmap_pages(struct kvm *kvm, struct kvm_memory_slot *slot);
  640. int kvm_iommu_map_guest(struct kvm *kvm);
  641. int kvm_iommu_unmap_guest(struct kvm *kvm);
  642. int kvm_assign_device(struct kvm *kvm,
  643. struct kvm_assigned_dev_kernel *assigned_dev);
  644. int kvm_deassign_device(struct kvm *kvm,
  645. struct kvm_assigned_dev_kernel *assigned_dev);
  646. #else /* CONFIG_IOMMU_API */
  647. static inline int kvm_iommu_map_pages(struct kvm *kvm,
  648. struct kvm_memory_slot *slot)
  649. {
  650. return 0;
  651. }
  652. static inline void kvm_iommu_unmap_pages(struct kvm *kvm,
  653. struct kvm_memory_slot *slot)
  654. {
  655. }
  656. static inline int kvm_iommu_map_guest(struct kvm *kvm)
  657. {
  658. return -ENODEV;
  659. }
  660. static inline int kvm_iommu_unmap_guest(struct kvm *kvm)
  661. {
  662. return 0;
  663. }
  664. static inline int kvm_assign_device(struct kvm *kvm,
  665. struct kvm_assigned_dev_kernel *assigned_dev)
  666. {
  667. return 0;
  668. }
  669. static inline int kvm_deassign_device(struct kvm *kvm,
  670. struct kvm_assigned_dev_kernel *assigned_dev)
  671. {
  672. return 0;
  673. }
  674. #endif /* CONFIG_IOMMU_API */
  675. static inline void __guest_enter(void)
  676. {
  677. /*
  678. * This is running in ioctl context so we can avoid
  679. * the call to vtime_account() with its unnecessary idle check.
  680. */
  681. vtime_account_system(current);
  682. current->flags |= PF_VCPU;
  683. }
  684. static inline void __guest_exit(void)
  685. {
  686. /*
  687. * This is running in ioctl context so we can avoid
  688. * the call to vtime_account() with its unnecessary idle check.
  689. */
  690. vtime_account_system(current);
  691. current->flags &= ~PF_VCPU;
  692. }
  693. #ifdef CONFIG_CONTEXT_TRACKING
  694. extern void guest_enter(void);
  695. extern void guest_exit(void);
  696. #else /* !CONFIG_CONTEXT_TRACKING */
  697. static inline void guest_enter(void)
  698. {
  699. __guest_enter();
  700. }
  701. static inline void guest_exit(void)
  702. {
  703. __guest_exit();
  704. }
  705. #endif /* !CONFIG_CONTEXT_TRACKING */
  706. static inline void kvm_guest_enter(void)
  707. {
  708. unsigned long flags;
  709. BUG_ON(preemptible());
  710. local_irq_save(flags);
  711. guest_enter();
  712. local_irq_restore(flags);
  713. /* KVM does not hold any references to rcu protected data when it
  714. * switches CPU into a guest mode. In fact switching to a guest mode
  715. * is very similar to exiting to userspase from rcu point of view. In
  716. * addition CPU may stay in a guest mode for quite a long time (up to
  717. * one time slice). Lets treat guest mode as quiescent state, just like
  718. * we do with user-mode execution.
  719. */
  720. rcu_virt_note_context_switch(smp_processor_id());
  721. }
  722. static inline void kvm_guest_exit(void)
  723. {
  724. unsigned long flags;
  725. local_irq_save(flags);
  726. guest_exit();
  727. local_irq_restore(flags);
  728. }
  729. /*
  730. * search_memslots() and __gfn_to_memslot() are here because they are
  731. * used in non-modular code in arch/powerpc/kvm/book3s_hv_rm_mmu.c.
  732. * gfn_to_memslot() itself isn't here as an inline because that would
  733. * bloat other code too much.
  734. */
  735. static inline struct kvm_memory_slot *
  736. search_memslots(struct kvm_memslots *slots, gfn_t gfn)
  737. {
  738. struct kvm_memory_slot *memslot;
  739. kvm_for_each_memslot(memslot, slots)
  740. if (gfn >= memslot->base_gfn &&
  741. gfn < memslot->base_gfn + memslot->npages)
  742. return memslot;
  743. return NULL;
  744. }
  745. static inline struct kvm_memory_slot *
  746. __gfn_to_memslot(struct kvm_memslots *slots, gfn_t gfn)
  747. {
  748. return search_memslots(slots, gfn);
  749. }
  750. static inline unsigned long
  751. __gfn_to_hva_memslot(struct kvm_memory_slot *slot, gfn_t gfn)
  752. {
  753. return slot->userspace_addr + (gfn - slot->base_gfn) * PAGE_SIZE;
  754. }
  755. static inline int memslot_id(struct kvm *kvm, gfn_t gfn)
  756. {
  757. return gfn_to_memslot(kvm, gfn)->id;
  758. }
  759. static inline gfn_t gfn_to_index(gfn_t gfn, gfn_t base_gfn, int level)
  760. {
  761. /* KVM_HPAGE_GFN_SHIFT(PT_PAGE_TABLE_LEVEL) must be 0. */
  762. return (gfn >> KVM_HPAGE_GFN_SHIFT(level)) -
  763. (base_gfn >> KVM_HPAGE_GFN_SHIFT(level));
  764. }
  765. static inline gfn_t
  766. hva_to_gfn_memslot(unsigned long hva, struct kvm_memory_slot *slot)
  767. {
  768. gfn_t gfn_offset = (hva - slot->userspace_addr) >> PAGE_SHIFT;
  769. return slot->base_gfn + gfn_offset;
  770. }
  771. static inline gpa_t gfn_to_gpa(gfn_t gfn)
  772. {
  773. return (gpa_t)gfn << PAGE_SHIFT;
  774. }
  775. static inline gfn_t gpa_to_gfn(gpa_t gpa)
  776. {
  777. return (gfn_t)(gpa >> PAGE_SHIFT);
  778. }
  779. static inline hpa_t pfn_to_hpa(pfn_t pfn)
  780. {
  781. return (hpa_t)pfn << PAGE_SHIFT;
  782. }
  783. static inline void kvm_migrate_timers(struct kvm_vcpu *vcpu)
  784. {
  785. set_bit(KVM_REQ_MIGRATE_TIMER, &vcpu->requests);
  786. }
  787. enum kvm_stat_kind {
  788. KVM_STAT_VM,
  789. KVM_STAT_VCPU,
  790. };
  791. struct kvm_stats_debugfs_item {
  792. const char *name;
  793. int offset;
  794. enum kvm_stat_kind kind;
  795. struct dentry *dentry;
  796. };
  797. extern struct kvm_stats_debugfs_item debugfs_entries[];
  798. extern struct dentry *kvm_debugfs_dir;
  799. #if defined(CONFIG_MMU_NOTIFIER) && defined(KVM_ARCH_WANT_MMU_NOTIFIER)
  800. static inline int mmu_notifier_retry(struct kvm *kvm, unsigned long mmu_seq)
  801. {
  802. if (unlikely(kvm->mmu_notifier_count))
  803. return 1;
  804. /*
  805. * Ensure the read of mmu_notifier_count happens before the read
  806. * of mmu_notifier_seq. This interacts with the smp_wmb() in
  807. * mmu_notifier_invalidate_range_end to make sure that the caller
  808. * either sees the old (non-zero) value of mmu_notifier_count or
  809. * the new (incremented) value of mmu_notifier_seq.
  810. * PowerPC Book3s HV KVM calls this under a per-page lock
  811. * rather than under kvm->mmu_lock, for scalability, so
  812. * can't rely on kvm->mmu_lock to keep things ordered.
  813. */
  814. smp_rmb();
  815. if (kvm->mmu_notifier_seq != mmu_seq)
  816. return 1;
  817. return 0;
  818. }
  819. #endif
  820. #ifdef CONFIG_HAVE_KVM_IRQ_ROUTING
  821. #define KVM_MAX_IRQ_ROUTES 1024
  822. int kvm_setup_default_irq_routing(struct kvm *kvm);
  823. int kvm_set_irq_routing(struct kvm *kvm,
  824. const struct kvm_irq_routing_entry *entries,
  825. unsigned nr,
  826. unsigned flags);
  827. int kvm_set_routing_entry(struct kvm_irq_routing_table *rt,
  828. struct kvm_kernel_irq_routing_entry *e,
  829. const struct kvm_irq_routing_entry *ue);
  830. void kvm_free_irq_routing(struct kvm *kvm);
  831. int kvm_send_userspace_msi(struct kvm *kvm, struct kvm_msi *msi);
  832. #else
  833. static inline void kvm_free_irq_routing(struct kvm *kvm) {}
  834. #endif
  835. #ifdef CONFIG_HAVE_KVM_EVENTFD
  836. void kvm_eventfd_init(struct kvm *kvm);
  837. int kvm_ioeventfd(struct kvm *kvm, struct kvm_ioeventfd *args);
  838. #ifdef CONFIG_HAVE_KVM_IRQCHIP
  839. int kvm_irqfd(struct kvm *kvm, struct kvm_irqfd *args);
  840. void kvm_irqfd_release(struct kvm *kvm);
  841. void kvm_irq_routing_update(struct kvm *, struct kvm_irq_routing_table *);
  842. #else
  843. static inline int kvm_irqfd(struct kvm *kvm, struct kvm_irqfd *args)
  844. {
  845. return -EINVAL;
  846. }
  847. static inline void kvm_irqfd_release(struct kvm *kvm) {}
  848. #endif
  849. #else
  850. static inline void kvm_eventfd_init(struct kvm *kvm) {}
  851. static inline int kvm_irqfd(struct kvm *kvm, struct kvm_irqfd *args)
  852. {
  853. return -EINVAL;
  854. }
  855. static inline void kvm_irqfd_release(struct kvm *kvm) {}
  856. #ifdef CONFIG_HAVE_KVM_IRQCHIP
  857. static inline void kvm_irq_routing_update(struct kvm *kvm,
  858. struct kvm_irq_routing_table *irq_rt)
  859. {
  860. rcu_assign_pointer(kvm->irq_routing, irq_rt);
  861. }
  862. #endif
  863. static inline int kvm_ioeventfd(struct kvm *kvm, struct kvm_ioeventfd *args)
  864. {
  865. return -ENOSYS;
  866. }
  867. #endif /* CONFIG_HAVE_KVM_EVENTFD */
  868. #ifdef CONFIG_KVM_APIC_ARCHITECTURE
  869. static inline bool kvm_vcpu_is_bsp(struct kvm_vcpu *vcpu)
  870. {
  871. return vcpu->kvm->bsp_vcpu_id == vcpu->vcpu_id;
  872. }
  873. bool kvm_vcpu_compatible(struct kvm_vcpu *vcpu);
  874. #else
  875. static inline bool kvm_vcpu_compatible(struct kvm_vcpu *vcpu) { return true; }
  876. #endif
  877. #ifdef __KVM_HAVE_DEVICE_ASSIGNMENT
  878. long kvm_vm_ioctl_assigned_device(struct kvm *kvm, unsigned ioctl,
  879. unsigned long arg);
  880. #else
  881. static inline long kvm_vm_ioctl_assigned_device(struct kvm *kvm, unsigned ioctl,
  882. unsigned long arg)
  883. {
  884. return -ENOTTY;
  885. }
  886. #endif
  887. static inline void kvm_make_request(int req, struct kvm_vcpu *vcpu)
  888. {
  889. set_bit(req, &vcpu->requests);
  890. }
  891. static inline bool kvm_check_request(int req, struct kvm_vcpu *vcpu)
  892. {
  893. if (test_bit(req, &vcpu->requests)) {
  894. clear_bit(req, &vcpu->requests);
  895. return true;
  896. } else {
  897. return false;
  898. }
  899. }
  900. extern bool kvm_rebooting;
  901. struct kvm_device_ops;
  902. struct kvm_device {
  903. struct kvm_device_ops *ops;
  904. struct kvm *kvm;
  905. void *private;
  906. struct list_head vm_node;
  907. };
  908. /* create, destroy, and name are mandatory */
  909. struct kvm_device_ops {
  910. const char *name;
  911. int (*create)(struct kvm_device *dev, u32 type);
  912. /*
  913. * Destroy is responsible for freeing dev.
  914. *
  915. * Destroy may be called before or after destructors are called
  916. * on emulated I/O regions, depending on whether a reference is
  917. * held by a vcpu or other kvm component that gets destroyed
  918. * after the emulated I/O.
  919. */
  920. void (*destroy)(struct kvm_device *dev);
  921. int (*set_attr)(struct kvm_device *dev, struct kvm_device_attr *attr);
  922. int (*get_attr)(struct kvm_device *dev, struct kvm_device_attr *attr);
  923. int (*has_attr)(struct kvm_device *dev, struct kvm_device_attr *attr);
  924. long (*ioctl)(struct kvm_device *dev, unsigned int ioctl,
  925. unsigned long arg);
  926. };
  927. void kvm_device_get(struct kvm_device *dev);
  928. void kvm_device_put(struct kvm_device *dev);
  929. struct kvm_device *kvm_device_from_filp(struct file *filp);
  930. extern struct kvm_device_ops kvm_mpic_ops;
  931. #ifdef CONFIG_HAVE_KVM_CPU_RELAX_INTERCEPT
  932. static inline void kvm_vcpu_set_in_spin_loop(struct kvm_vcpu *vcpu, bool val)
  933. {
  934. vcpu->spin_loop.in_spin_loop = val;
  935. }
  936. static inline void kvm_vcpu_set_dy_eligible(struct kvm_vcpu *vcpu, bool val)
  937. {
  938. vcpu->spin_loop.dy_eligible = val;
  939. }
  940. #else /* !CONFIG_HAVE_KVM_CPU_RELAX_INTERCEPT */
  941. static inline void kvm_vcpu_set_in_spin_loop(struct kvm_vcpu *vcpu, bool val)
  942. {
  943. }
  944. static inline void kvm_vcpu_set_dy_eligible(struct kvm_vcpu *vcpu, bool val)
  945. {
  946. }
  947. static inline bool kvm_vcpu_eligible_for_directed_yield(struct kvm_vcpu *vcpu)
  948. {
  949. return true;
  950. }
  951. #endif /* CONFIG_HAVE_KVM_CPU_RELAX_INTERCEPT */
  952. #else
  953. static inline void __guest_enter(void) { return; }
  954. static inline void __guest_exit(void) { return; }
  955. #endif /* IS_ENABLED(CONFIG_KVM) */
  956. #endif