kvm_host.h 16 KB

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