kvm_host.h 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574
  1. #ifndef __KVM_HOST_H
  2. #define __KVM_HOST_H
  3. /*
  4. * This work is licensed under the terms of the GNU GPL, version 2. See
  5. * the COPYING file in the top-level directory.
  6. */
  7. #include <linux/types.h>
  8. #include <linux/hardirq.h>
  9. #include <linux/list.h>
  10. #include <linux/mutex.h>
  11. #include <linux/spinlock.h>
  12. #include <linux/signal.h>
  13. #include <linux/sched.h>
  14. #include <linux/mm.h>
  15. #include <linux/preempt.h>
  16. #include <linux/marker.h>
  17. #include <linux/msi.h>
  18. #include <asm/signal.h>
  19. #include <linux/kvm.h>
  20. #include <linux/kvm_para.h>
  21. #include <linux/kvm_types.h>
  22. #include <asm/kvm_host.h>
  23. /*
  24. * vcpu->requests bit members
  25. */
  26. #define KVM_REQ_TLB_FLUSH 0
  27. #define KVM_REQ_MIGRATE_TIMER 1
  28. #define KVM_REQ_REPORT_TPR_ACCESS 2
  29. #define KVM_REQ_MMU_RELOAD 3
  30. #define KVM_REQ_TRIPLE_FAULT 4
  31. #define KVM_REQ_PENDING_TIMER 5
  32. #define KVM_REQ_UNHALT 6
  33. #define KVM_REQ_MMU_SYNC 7
  34. #define KVM_REQ_KVMCLOCK_UPDATE 8
  35. #define KVM_REQ_KICK 9
  36. #define KVM_USERSPACE_IRQ_SOURCE_ID 0
  37. struct kvm_vcpu;
  38. extern struct kmem_cache *kvm_vcpu_cache;
  39. /*
  40. * It would be nice to use something smarter than a linear search, TBD...
  41. * Thankfully we dont expect many devices to register (famous last words :),
  42. * so until then it will suffice. At least its abstracted so we can change
  43. * in one place.
  44. */
  45. struct kvm_io_bus {
  46. int dev_count;
  47. #define NR_IOBUS_DEVS 6
  48. struct kvm_io_device *devs[NR_IOBUS_DEVS];
  49. };
  50. void kvm_io_bus_init(struct kvm_io_bus *bus);
  51. void kvm_io_bus_destroy(struct kvm_io_bus *bus);
  52. struct kvm_io_device *kvm_io_bus_find_dev(struct kvm_io_bus *bus,
  53. gpa_t addr, int len, int is_write);
  54. void kvm_io_bus_register_dev(struct kvm_io_bus *bus,
  55. struct kvm_io_device *dev);
  56. struct kvm_vcpu {
  57. struct kvm *kvm;
  58. #ifdef CONFIG_PREEMPT_NOTIFIERS
  59. struct preempt_notifier preempt_notifier;
  60. #endif
  61. int vcpu_id;
  62. struct mutex mutex;
  63. int cpu;
  64. struct kvm_run *run;
  65. unsigned long requests;
  66. unsigned long guest_debug;
  67. int fpu_active;
  68. int guest_fpu_loaded;
  69. wait_queue_head_t wq;
  70. int sigset_active;
  71. sigset_t sigset;
  72. struct kvm_vcpu_stat stat;
  73. #ifdef CONFIG_HAS_IOMEM
  74. int mmio_needed;
  75. int mmio_read_completed;
  76. int mmio_is_write;
  77. int mmio_size;
  78. unsigned char mmio_data[8];
  79. gpa_t mmio_phys_addr;
  80. #endif
  81. struct kvm_vcpu_arch arch;
  82. };
  83. struct kvm_memory_slot {
  84. gfn_t base_gfn;
  85. unsigned long npages;
  86. unsigned long flags;
  87. unsigned long *rmap;
  88. unsigned long *dirty_bitmap;
  89. struct {
  90. unsigned long rmap_pde;
  91. int write_count;
  92. } *lpage_info;
  93. unsigned long userspace_addr;
  94. int user_alloc;
  95. };
  96. struct kvm_kernel_irq_routing_entry {
  97. u32 gsi;
  98. u32 type;
  99. int (*set)(struct kvm_kernel_irq_routing_entry *e,
  100. struct kvm *kvm, int level);
  101. union {
  102. struct {
  103. unsigned irqchip;
  104. unsigned pin;
  105. } irqchip;
  106. struct msi_msg msi;
  107. };
  108. struct list_head link;
  109. };
  110. struct kvm {
  111. spinlock_t mmu_lock;
  112. spinlock_t requests_lock;
  113. struct rw_semaphore slots_lock;
  114. struct mm_struct *mm; /* userspace tied to this vm */
  115. int nmemslots;
  116. struct kvm_memory_slot memslots[KVM_MEMORY_SLOTS +
  117. KVM_PRIVATE_MEM_SLOTS];
  118. #ifdef CONFIG_KVM_APIC_ARCHITECTURE
  119. u32 bsp_vcpu_id;
  120. struct kvm_vcpu *bsp_vcpu;
  121. #endif
  122. struct kvm_vcpu *vcpus[KVM_MAX_VCPUS];
  123. atomic_t online_vcpus;
  124. struct list_head vm_list;
  125. struct mutex lock;
  126. struct kvm_io_bus mmio_bus;
  127. struct kvm_io_bus pio_bus;
  128. #ifdef CONFIG_HAVE_KVM_EVENTFD
  129. struct {
  130. spinlock_t lock;
  131. struct list_head items;
  132. } irqfds;
  133. #endif
  134. struct kvm_vm_stat stat;
  135. struct kvm_arch arch;
  136. atomic_t users_count;
  137. #ifdef KVM_COALESCED_MMIO_PAGE_OFFSET
  138. struct kvm_coalesced_mmio_dev *coalesced_mmio_dev;
  139. struct kvm_coalesced_mmio_ring *coalesced_mmio_ring;
  140. #endif
  141. struct mutex irq_lock;
  142. #ifdef CONFIG_HAVE_KVM_IRQCHIP
  143. struct list_head irq_routing; /* of kvm_kernel_irq_routing_entry */
  144. struct hlist_head mask_notifier_list;
  145. #endif
  146. #ifdef KVM_ARCH_WANT_MMU_NOTIFIER
  147. struct mmu_notifier mmu_notifier;
  148. unsigned long mmu_notifier_seq;
  149. long mmu_notifier_count;
  150. #endif
  151. };
  152. /* The guest did something we don't support. */
  153. #define pr_unimpl(vcpu, fmt, ...) \
  154. do { \
  155. if (printk_ratelimit()) \
  156. printk(KERN_ERR "kvm: %i: cpu%i " fmt, \
  157. current->tgid, (vcpu)->vcpu_id , ## __VA_ARGS__); \
  158. } while (0)
  159. #define kvm_printf(kvm, fmt ...) printk(KERN_DEBUG fmt)
  160. #define vcpu_printf(vcpu, fmt...) kvm_printf(vcpu->kvm, fmt)
  161. static inline struct kvm_vcpu *kvm_get_vcpu(struct kvm *kvm, int i)
  162. {
  163. smp_rmb();
  164. return kvm->vcpus[i];
  165. }
  166. #define kvm_for_each_vcpu(idx, vcpup, kvm) \
  167. for (idx = 0, vcpup = kvm_get_vcpu(kvm, idx); \
  168. idx < atomic_read(&kvm->online_vcpus) && vcpup; \
  169. vcpup = kvm_get_vcpu(kvm, ++idx))
  170. int kvm_vcpu_init(struct kvm_vcpu *vcpu, struct kvm *kvm, unsigned id);
  171. void kvm_vcpu_uninit(struct kvm_vcpu *vcpu);
  172. void vcpu_load(struct kvm_vcpu *vcpu);
  173. void vcpu_put(struct kvm_vcpu *vcpu);
  174. int kvm_init(void *opaque, unsigned int vcpu_size,
  175. struct module *module);
  176. void kvm_exit(void);
  177. void kvm_get_kvm(struct kvm *kvm);
  178. void kvm_put_kvm(struct kvm *kvm);
  179. #define HPA_MSB ((sizeof(hpa_t) * 8) - 1)
  180. #define HPA_ERR_MASK ((hpa_t)1 << HPA_MSB)
  181. static inline int is_error_hpa(hpa_t hpa) { return hpa >> HPA_MSB; }
  182. struct page *gva_to_page(struct kvm_vcpu *vcpu, gva_t gva);
  183. extern struct page *bad_page;
  184. extern pfn_t bad_pfn;
  185. int is_error_page(struct page *page);
  186. int is_error_pfn(pfn_t pfn);
  187. int kvm_is_error_hva(unsigned long addr);
  188. int kvm_set_memory_region(struct kvm *kvm,
  189. struct kvm_userspace_memory_region *mem,
  190. int user_alloc);
  191. int __kvm_set_memory_region(struct kvm *kvm,
  192. struct kvm_userspace_memory_region *mem,
  193. int user_alloc);
  194. int kvm_arch_set_memory_region(struct kvm *kvm,
  195. struct kvm_userspace_memory_region *mem,
  196. struct kvm_memory_slot old,
  197. int user_alloc);
  198. void kvm_arch_flush_shadow(struct kvm *kvm);
  199. gfn_t unalias_gfn(struct kvm *kvm, gfn_t gfn);
  200. struct page *gfn_to_page(struct kvm *kvm, gfn_t gfn);
  201. unsigned long gfn_to_hva(struct kvm *kvm, gfn_t gfn);
  202. void kvm_release_page_clean(struct page *page);
  203. void kvm_release_page_dirty(struct page *page);
  204. void kvm_set_page_dirty(struct page *page);
  205. void kvm_set_page_accessed(struct page *page);
  206. pfn_t gfn_to_pfn(struct kvm *kvm, gfn_t gfn);
  207. void kvm_release_pfn_dirty(pfn_t);
  208. void kvm_release_pfn_clean(pfn_t pfn);
  209. void kvm_set_pfn_dirty(pfn_t pfn);
  210. void kvm_set_pfn_accessed(pfn_t pfn);
  211. void kvm_get_pfn(pfn_t pfn);
  212. int kvm_read_guest_page(struct kvm *kvm, gfn_t gfn, void *data, int offset,
  213. int len);
  214. int kvm_read_guest_atomic(struct kvm *kvm, gpa_t gpa, void *data,
  215. unsigned long len);
  216. int kvm_read_guest(struct kvm *kvm, gpa_t gpa, void *data, unsigned long len);
  217. int kvm_write_guest_page(struct kvm *kvm, gfn_t gfn, const void *data,
  218. int offset, int len);
  219. int kvm_write_guest(struct kvm *kvm, gpa_t gpa, const void *data,
  220. unsigned long len);
  221. int kvm_clear_guest_page(struct kvm *kvm, gfn_t gfn, int offset, int len);
  222. int kvm_clear_guest(struct kvm *kvm, gpa_t gpa, unsigned long len);
  223. struct kvm_memory_slot *gfn_to_memslot(struct kvm *kvm, gfn_t gfn);
  224. int kvm_is_visible_gfn(struct kvm *kvm, gfn_t gfn);
  225. void mark_page_dirty(struct kvm *kvm, gfn_t gfn);
  226. void kvm_vcpu_block(struct kvm_vcpu *vcpu);
  227. void kvm_resched(struct kvm_vcpu *vcpu);
  228. void kvm_load_guest_fpu(struct kvm_vcpu *vcpu);
  229. void kvm_put_guest_fpu(struct kvm_vcpu *vcpu);
  230. void kvm_flush_remote_tlbs(struct kvm *kvm);
  231. void kvm_reload_remote_mmus(struct kvm *kvm);
  232. long kvm_arch_dev_ioctl(struct file *filp,
  233. unsigned int ioctl, unsigned long arg);
  234. long kvm_arch_vcpu_ioctl(struct file *filp,
  235. unsigned int ioctl, unsigned long arg);
  236. int kvm_dev_ioctl_check_extension(long ext);
  237. int kvm_get_dirty_log(struct kvm *kvm,
  238. struct kvm_dirty_log *log, int *is_dirty);
  239. int kvm_vm_ioctl_get_dirty_log(struct kvm *kvm,
  240. struct kvm_dirty_log *log);
  241. int kvm_vm_ioctl_set_memory_region(struct kvm *kvm,
  242. struct
  243. kvm_userspace_memory_region *mem,
  244. int user_alloc);
  245. long kvm_arch_vm_ioctl(struct file *filp,
  246. unsigned int ioctl, unsigned long arg);
  247. int kvm_arch_vcpu_ioctl_get_fpu(struct kvm_vcpu *vcpu, struct kvm_fpu *fpu);
  248. int kvm_arch_vcpu_ioctl_set_fpu(struct kvm_vcpu *vcpu, struct kvm_fpu *fpu);
  249. int kvm_arch_vcpu_ioctl_translate(struct kvm_vcpu *vcpu,
  250. struct kvm_translation *tr);
  251. int kvm_arch_vcpu_ioctl_get_regs(struct kvm_vcpu *vcpu, struct kvm_regs *regs);
  252. int kvm_arch_vcpu_ioctl_set_regs(struct kvm_vcpu *vcpu, struct kvm_regs *regs);
  253. int kvm_arch_vcpu_ioctl_get_sregs(struct kvm_vcpu *vcpu,
  254. struct kvm_sregs *sregs);
  255. int kvm_arch_vcpu_ioctl_set_sregs(struct kvm_vcpu *vcpu,
  256. struct kvm_sregs *sregs);
  257. int kvm_arch_vcpu_ioctl_get_mpstate(struct kvm_vcpu *vcpu,
  258. struct kvm_mp_state *mp_state);
  259. int kvm_arch_vcpu_ioctl_set_mpstate(struct kvm_vcpu *vcpu,
  260. struct kvm_mp_state *mp_state);
  261. int kvm_arch_vcpu_ioctl_set_guest_debug(struct kvm_vcpu *vcpu,
  262. struct kvm_guest_debug *dbg);
  263. int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run);
  264. int kvm_arch_init(void *opaque);
  265. void kvm_arch_exit(void);
  266. int kvm_arch_vcpu_init(struct kvm_vcpu *vcpu);
  267. void kvm_arch_vcpu_uninit(struct kvm_vcpu *vcpu);
  268. void kvm_arch_vcpu_free(struct kvm_vcpu *vcpu);
  269. void kvm_arch_vcpu_load(struct kvm_vcpu *vcpu, int cpu);
  270. void kvm_arch_vcpu_put(struct kvm_vcpu *vcpu);
  271. struct kvm_vcpu *kvm_arch_vcpu_create(struct kvm *kvm, unsigned int id);
  272. int kvm_arch_vcpu_setup(struct kvm_vcpu *vcpu);
  273. void kvm_arch_vcpu_destroy(struct kvm_vcpu *vcpu);
  274. int kvm_arch_vcpu_reset(struct kvm_vcpu *vcpu);
  275. void kvm_arch_hardware_enable(void *garbage);
  276. void kvm_arch_hardware_disable(void *garbage);
  277. int kvm_arch_hardware_setup(void);
  278. void kvm_arch_hardware_unsetup(void);
  279. void kvm_arch_check_processor_compat(void *rtn);
  280. int kvm_arch_vcpu_runnable(struct kvm_vcpu *vcpu);
  281. int kvm_arch_interrupt_allowed(struct kvm_vcpu *vcpu);
  282. void kvm_free_physmem(struct kvm *kvm);
  283. struct kvm *kvm_arch_create_vm(void);
  284. void kvm_arch_destroy_vm(struct kvm *kvm);
  285. void kvm_free_all_assigned_devices(struct kvm *kvm);
  286. void kvm_arch_sync_events(struct kvm *kvm);
  287. int kvm_cpu_get_interrupt(struct kvm_vcpu *v);
  288. int kvm_cpu_has_interrupt(struct kvm_vcpu *v);
  289. int kvm_cpu_has_pending_timer(struct kvm_vcpu *vcpu);
  290. void kvm_vcpu_kick(struct kvm_vcpu *vcpu);
  291. int kvm_is_mmio_pfn(pfn_t pfn);
  292. struct kvm_irq_ack_notifier {
  293. struct hlist_node link;
  294. unsigned gsi;
  295. void (*irq_acked)(struct kvm_irq_ack_notifier *kian);
  296. };
  297. #define KVM_ASSIGNED_MSIX_PENDING 0x1
  298. struct kvm_guest_msix_entry {
  299. u32 vector;
  300. u16 entry;
  301. u16 flags;
  302. };
  303. struct kvm_assigned_dev_kernel {
  304. struct kvm_irq_ack_notifier ack_notifier;
  305. struct work_struct interrupt_work;
  306. struct list_head list;
  307. int assigned_dev_id;
  308. int host_busnr;
  309. int host_devfn;
  310. unsigned int entries_nr;
  311. int host_irq;
  312. bool host_irq_disabled;
  313. struct msix_entry *host_msix_entries;
  314. int guest_irq;
  315. struct kvm_guest_msix_entry *guest_msix_entries;
  316. unsigned long irq_requested_type;
  317. int irq_source_id;
  318. int flags;
  319. struct pci_dev *dev;
  320. struct kvm *kvm;
  321. spinlock_t assigned_dev_lock;
  322. };
  323. struct kvm_irq_mask_notifier {
  324. void (*func)(struct kvm_irq_mask_notifier *kimn, bool masked);
  325. int irq;
  326. struct hlist_node link;
  327. };
  328. void kvm_register_irq_mask_notifier(struct kvm *kvm, int irq,
  329. struct kvm_irq_mask_notifier *kimn);
  330. void kvm_unregister_irq_mask_notifier(struct kvm *kvm, int irq,
  331. struct kvm_irq_mask_notifier *kimn);
  332. void kvm_fire_mask_notifiers(struct kvm *kvm, int irq, bool mask);
  333. int kvm_set_irq(struct kvm *kvm, int irq_source_id, int irq, int level);
  334. void kvm_notify_acked_irq(struct kvm *kvm, unsigned irqchip, unsigned pin);
  335. void kvm_register_irq_ack_notifier(struct kvm *kvm,
  336. struct kvm_irq_ack_notifier *kian);
  337. void kvm_unregister_irq_ack_notifier(struct kvm *kvm,
  338. struct kvm_irq_ack_notifier *kian);
  339. int kvm_request_irq_source_id(struct kvm *kvm);
  340. void kvm_free_irq_source_id(struct kvm *kvm, int irq_source_id);
  341. /* For vcpu->arch.iommu_flags */
  342. #define KVM_IOMMU_CACHE_COHERENCY 0x1
  343. #ifdef CONFIG_IOMMU_API
  344. int kvm_iommu_map_pages(struct kvm *kvm, gfn_t base_gfn,
  345. unsigned long npages);
  346. int kvm_iommu_map_guest(struct kvm *kvm);
  347. int kvm_iommu_unmap_guest(struct kvm *kvm);
  348. int kvm_assign_device(struct kvm *kvm,
  349. struct kvm_assigned_dev_kernel *assigned_dev);
  350. int kvm_deassign_device(struct kvm *kvm,
  351. struct kvm_assigned_dev_kernel *assigned_dev);
  352. #else /* CONFIG_IOMMU_API */
  353. static inline int kvm_iommu_map_pages(struct kvm *kvm,
  354. gfn_t base_gfn,
  355. unsigned long npages)
  356. {
  357. return 0;
  358. }
  359. static inline int kvm_iommu_map_guest(struct kvm *kvm)
  360. {
  361. return -ENODEV;
  362. }
  363. static inline int kvm_iommu_unmap_guest(struct kvm *kvm)
  364. {
  365. return 0;
  366. }
  367. static inline int kvm_assign_device(struct kvm *kvm,
  368. struct kvm_assigned_dev_kernel *assigned_dev)
  369. {
  370. return 0;
  371. }
  372. static inline int kvm_deassign_device(struct kvm *kvm,
  373. struct kvm_assigned_dev_kernel *assigned_dev)
  374. {
  375. return 0;
  376. }
  377. #endif /* CONFIG_IOMMU_API */
  378. static inline void kvm_guest_enter(void)
  379. {
  380. account_system_vtime(current);
  381. current->flags |= PF_VCPU;
  382. }
  383. static inline void kvm_guest_exit(void)
  384. {
  385. account_system_vtime(current);
  386. current->flags &= ~PF_VCPU;
  387. }
  388. static inline int memslot_id(struct kvm *kvm, struct kvm_memory_slot *slot)
  389. {
  390. return slot - kvm->memslots;
  391. }
  392. static inline gpa_t gfn_to_gpa(gfn_t gfn)
  393. {
  394. return (gpa_t)gfn << PAGE_SHIFT;
  395. }
  396. static inline hpa_t pfn_to_hpa(pfn_t pfn)
  397. {
  398. return (hpa_t)pfn << PAGE_SHIFT;
  399. }
  400. static inline void kvm_migrate_timers(struct kvm_vcpu *vcpu)
  401. {
  402. set_bit(KVM_REQ_MIGRATE_TIMER, &vcpu->requests);
  403. }
  404. enum kvm_stat_kind {
  405. KVM_STAT_VM,
  406. KVM_STAT_VCPU,
  407. };
  408. struct kvm_stats_debugfs_item {
  409. const char *name;
  410. int offset;
  411. enum kvm_stat_kind kind;
  412. struct dentry *dentry;
  413. };
  414. extern struct kvm_stats_debugfs_item debugfs_entries[];
  415. extern struct dentry *kvm_debugfs_dir;
  416. #define KVMTRACE_5D(evt, vcpu, d1, d2, d3, d4, d5, name) \
  417. trace_mark(kvm_trace_##name, "%u %p %u %u %u %u %u %u", KVM_TRC_##evt, \
  418. vcpu, 5, d1, d2, d3, d4, d5)
  419. #define KVMTRACE_4D(evt, vcpu, d1, d2, d3, d4, name) \
  420. trace_mark(kvm_trace_##name, "%u %p %u %u %u %u %u %u", KVM_TRC_##evt, \
  421. vcpu, 4, d1, d2, d3, d4, 0)
  422. #define KVMTRACE_3D(evt, vcpu, d1, d2, d3, name) \
  423. trace_mark(kvm_trace_##name, "%u %p %u %u %u %u %u %u", KVM_TRC_##evt, \
  424. vcpu, 3, d1, d2, d3, 0, 0)
  425. #define KVMTRACE_2D(evt, vcpu, d1, d2, name) \
  426. trace_mark(kvm_trace_##name, "%u %p %u %u %u %u %u %u", KVM_TRC_##evt, \
  427. vcpu, 2, d1, d2, 0, 0, 0)
  428. #define KVMTRACE_1D(evt, vcpu, d1, name) \
  429. trace_mark(kvm_trace_##name, "%u %p %u %u %u %u %u %u", KVM_TRC_##evt, \
  430. vcpu, 1, d1, 0, 0, 0, 0)
  431. #define KVMTRACE_0D(evt, vcpu, name) \
  432. trace_mark(kvm_trace_##name, "%u %p %u %u %u %u %u %u", KVM_TRC_##evt, \
  433. vcpu, 0, 0, 0, 0, 0, 0)
  434. #ifdef CONFIG_KVM_TRACE
  435. int kvm_trace_ioctl(unsigned int ioctl, unsigned long arg);
  436. void kvm_trace_cleanup(void);
  437. #else
  438. static inline
  439. int kvm_trace_ioctl(unsigned int ioctl, unsigned long arg)
  440. {
  441. return -EINVAL;
  442. }
  443. #define kvm_trace_cleanup() ((void)0)
  444. #endif
  445. #ifdef KVM_ARCH_WANT_MMU_NOTIFIER
  446. static inline int mmu_notifier_retry(struct kvm_vcpu *vcpu, unsigned long mmu_seq)
  447. {
  448. if (unlikely(vcpu->kvm->mmu_notifier_count))
  449. return 1;
  450. /*
  451. * Both reads happen under the mmu_lock and both values are
  452. * modified under mmu_lock, so there's no need of smb_rmb()
  453. * here in between, otherwise mmu_notifier_count should be
  454. * read before mmu_notifier_seq, see
  455. * mmu_notifier_invalidate_range_end write side.
  456. */
  457. if (vcpu->kvm->mmu_notifier_seq != mmu_seq)
  458. return 1;
  459. return 0;
  460. }
  461. #endif
  462. #ifdef CONFIG_HAVE_KVM_IRQCHIP
  463. #define KVM_MAX_IRQ_ROUTES 1024
  464. int kvm_setup_default_irq_routing(struct kvm *kvm);
  465. int kvm_set_irq_routing(struct kvm *kvm,
  466. const struct kvm_irq_routing_entry *entries,
  467. unsigned nr,
  468. unsigned flags);
  469. void kvm_free_irq_routing(struct kvm *kvm);
  470. #else
  471. static inline void kvm_free_irq_routing(struct kvm *kvm) {}
  472. #endif
  473. #ifdef CONFIG_HAVE_KVM_EVENTFD
  474. void kvm_irqfd_init(struct kvm *kvm);
  475. int kvm_irqfd(struct kvm *kvm, int fd, int gsi, int flags);
  476. void kvm_irqfd_release(struct kvm *kvm);
  477. #else
  478. static inline void kvm_irqfd_init(struct kvm *kvm) {}
  479. static inline int kvm_irqfd(struct kvm *kvm, int fd, int gsi, int flags)
  480. {
  481. return -EINVAL;
  482. }
  483. static inline void kvm_irqfd_release(struct kvm *kvm) {}
  484. #endif /* CONFIG_HAVE_KVM_EVENTFD */
  485. #ifdef CONFIG_KVM_APIC_ARCHITECTURE
  486. static inline bool kvm_vcpu_is_bsp(struct kvm_vcpu *vcpu)
  487. {
  488. return vcpu->kvm->bsp_vcpu == vcpu;
  489. }
  490. #endif
  491. #endif