aboutsummaryrefslogtreecommitdiffstats
path: root/include/linux/kvm_host.h
diff options
context:
space:
mode:
Diffstat (limited to 'include/linux/kvm_host.h')
-rw-r--r--include/linux/kvm_host.h101
1 files changed, 86 insertions, 15 deletions
diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h
index a0557422715e..b5021db21858 100644
--- a/include/linux/kvm_host.h
+++ b/include/linux/kvm_host.h
@@ -16,6 +16,8 @@
16#include <linux/mm.h> 16#include <linux/mm.h>
17#include <linux/preempt.h> 17#include <linux/preempt.h>
18#include <linux/msi.h> 18#include <linux/msi.h>
19#include <linux/slab.h>
20#include <linux/rcupdate.h>
19#include <asm/signal.h> 21#include <asm/signal.h>
20 22
21#include <linux/kvm.h> 23#include <linux/kvm.h>
@@ -40,6 +42,7 @@
40#define KVM_REQ_KICK 9 42#define KVM_REQ_KICK 9
41#define KVM_REQ_DEACTIVATE_FPU 10 43#define KVM_REQ_DEACTIVATE_FPU 10
42#define KVM_REQ_EVENT 11 44#define KVM_REQ_EVENT 11
45#define KVM_REQ_APF_HALT 12
43 46
44#define KVM_USERSPACE_IRQ_SOURCE_ID 0 47#define KVM_USERSPACE_IRQ_SOURCE_ID 0
45 48
@@ -74,6 +77,27 @@ int kvm_io_bus_register_dev(struct kvm *kvm, enum kvm_bus bus_idx,
74int kvm_io_bus_unregister_dev(struct kvm *kvm, enum kvm_bus bus_idx, 77int kvm_io_bus_unregister_dev(struct kvm *kvm, enum kvm_bus bus_idx,
75 struct kvm_io_device *dev); 78 struct kvm_io_device *dev);
76 79
80#ifdef CONFIG_KVM_ASYNC_PF
81struct kvm_async_pf {
82 struct work_struct work;
83 struct list_head link;
84 struct list_head queue;
85 struct kvm_vcpu *vcpu;
86 struct mm_struct *mm;
87 gva_t gva;
88 unsigned long addr;
89 struct kvm_arch_async_pf arch;
90 struct page *page;
91 bool done;
92};
93
94void kvm_clear_async_pf_completion_queue(struct kvm_vcpu *vcpu);
95void kvm_check_async_pf_completion(struct kvm_vcpu *vcpu);
96int kvm_setup_async_pf(struct kvm_vcpu *vcpu, gva_t gva, gfn_t gfn,
97 struct kvm_arch_async_pf *arch);
98int kvm_async_pf_wakeup_all(struct kvm_vcpu *vcpu);
99#endif
100
77struct kvm_vcpu { 101struct kvm_vcpu {
78 struct kvm *kvm; 102 struct kvm *kvm;
79#ifdef CONFIG_PREEMPT_NOTIFIERS 103#ifdef CONFIG_PREEMPT_NOTIFIERS
@@ -104,6 +128,15 @@ struct kvm_vcpu {
104 gpa_t mmio_phys_addr; 128 gpa_t mmio_phys_addr;
105#endif 129#endif
106 130
131#ifdef CONFIG_KVM_ASYNC_PF
132 struct {
133 u32 queued;
134 struct list_head queue;
135 struct list_head done;
136 spinlock_t lock;
137 } async_pf;
138#endif
139
107 struct kvm_vcpu_arch arch; 140 struct kvm_vcpu_arch arch;
108}; 141};
109 142
@@ -113,16 +146,19 @@ struct kvm_vcpu {
113 */ 146 */
114#define KVM_MEM_MAX_NR_PAGES ((1UL << 31) - 1) 147#define KVM_MEM_MAX_NR_PAGES ((1UL << 31) - 1)
115 148
149struct kvm_lpage_info {
150 unsigned long rmap_pde;
151 int write_count;
152};
153
116struct kvm_memory_slot { 154struct kvm_memory_slot {
117 gfn_t base_gfn; 155 gfn_t base_gfn;
118 unsigned long npages; 156 unsigned long npages;
119 unsigned long flags; 157 unsigned long flags;
120 unsigned long *rmap; 158 unsigned long *rmap;
121 unsigned long *dirty_bitmap; 159 unsigned long *dirty_bitmap;
122 struct { 160 unsigned long *dirty_bitmap_head;
123 unsigned long rmap_pde; 161 struct kvm_lpage_info *lpage_info[KVM_NR_PAGE_SIZES - 1];
124 int write_count;
125 } *lpage_info[KVM_NR_PAGE_SIZES - 1];
126 unsigned long userspace_addr; 162 unsigned long userspace_addr;
127 int user_alloc; 163 int user_alloc;
128 int id; 164 int id;
@@ -169,6 +205,7 @@ struct kvm_irq_routing_table {};
169 205
170struct kvm_memslots { 206struct kvm_memslots {
171 int nmemslots; 207 int nmemslots;
208 u64 generation;
172 struct kvm_memory_slot memslots[KVM_MEMORY_SLOTS + 209 struct kvm_memory_slot memslots[KVM_MEMORY_SLOTS +
173 KVM_PRIVATE_MEM_SLOTS]; 210 KVM_PRIVATE_MEM_SLOTS];
174}; 211};
@@ -206,6 +243,10 @@ struct kvm {
206 243
207 struct mutex irq_lock; 244 struct mutex irq_lock;
208#ifdef CONFIG_HAVE_KVM_IRQCHIP 245#ifdef CONFIG_HAVE_KVM_IRQCHIP
246 /*
247 * Update side is protected by irq_lock and,
248 * if configured, irqfds.lock.
249 */
209 struct kvm_irq_routing_table __rcu *irq_routing; 250 struct kvm_irq_routing_table __rcu *irq_routing;
210 struct hlist_head mask_notifier_list; 251 struct hlist_head mask_notifier_list;
211 struct hlist_head irq_ack_notifier_list; 252 struct hlist_head irq_ack_notifier_list;
@@ -216,6 +257,7 @@ struct kvm {
216 unsigned long mmu_notifier_seq; 257 unsigned long mmu_notifier_seq;
217 long mmu_notifier_count; 258 long mmu_notifier_count;
218#endif 259#endif
260 long tlbs_dirty;
219}; 261};
220 262
221/* The guest did something we don't support. */ 263/* The guest did something we don't support. */
@@ -302,7 +344,11 @@ void kvm_set_page_accessed(struct page *page);
302 344
303pfn_t hva_to_pfn_atomic(struct kvm *kvm, unsigned long addr); 345pfn_t hva_to_pfn_atomic(struct kvm *kvm, unsigned long addr);
304pfn_t gfn_to_pfn_atomic(struct kvm *kvm, gfn_t gfn); 346pfn_t gfn_to_pfn_atomic(struct kvm *kvm, gfn_t gfn);
347pfn_t gfn_to_pfn_async(struct kvm *kvm, gfn_t gfn, bool *async,
348 bool write_fault, bool *writable);
305pfn_t gfn_to_pfn(struct kvm *kvm, gfn_t gfn); 349pfn_t gfn_to_pfn(struct kvm *kvm, gfn_t gfn);
350pfn_t gfn_to_pfn_prot(struct kvm *kvm, gfn_t gfn, bool write_fault,
351 bool *writable);
306pfn_t gfn_to_pfn_memslot(struct kvm *kvm, 352pfn_t gfn_to_pfn_memslot(struct kvm *kvm,
307 struct kvm_memory_slot *slot, gfn_t gfn); 353 struct kvm_memory_slot *slot, gfn_t gfn);
308int memslot_id(struct kvm *kvm, gfn_t gfn); 354int memslot_id(struct kvm *kvm, gfn_t gfn);
@@ -321,18 +367,25 @@ int kvm_write_guest_page(struct kvm *kvm, gfn_t gfn, const void *data,
321 int offset, int len); 367 int offset, int len);
322int kvm_write_guest(struct kvm *kvm, gpa_t gpa, const void *data, 368int kvm_write_guest(struct kvm *kvm, gpa_t gpa, const void *data,
323 unsigned long len); 369 unsigned long len);
370int kvm_write_guest_cached(struct kvm *kvm, struct gfn_to_hva_cache *ghc,
371 void *data, unsigned long len);
372int kvm_gfn_to_hva_cache_init(struct kvm *kvm, struct gfn_to_hva_cache *ghc,
373 gpa_t gpa);
324int kvm_clear_guest_page(struct kvm *kvm, gfn_t gfn, int offset, int len); 374int kvm_clear_guest_page(struct kvm *kvm, gfn_t gfn, int offset, int len);
325int kvm_clear_guest(struct kvm *kvm, gpa_t gpa, unsigned long len); 375int kvm_clear_guest(struct kvm *kvm, gpa_t gpa, unsigned long len);
326struct kvm_memory_slot *gfn_to_memslot(struct kvm *kvm, gfn_t gfn); 376struct kvm_memory_slot *gfn_to_memslot(struct kvm *kvm, gfn_t gfn);
327int kvm_is_visible_gfn(struct kvm *kvm, gfn_t gfn); 377int kvm_is_visible_gfn(struct kvm *kvm, gfn_t gfn);
328unsigned long kvm_host_page_size(struct kvm *kvm, gfn_t gfn); 378unsigned long kvm_host_page_size(struct kvm *kvm, gfn_t gfn);
329void mark_page_dirty(struct kvm *kvm, gfn_t gfn); 379void mark_page_dirty(struct kvm *kvm, gfn_t gfn);
380void mark_page_dirty_in_slot(struct kvm *kvm, struct kvm_memory_slot *memslot,
381 gfn_t gfn);
330 382
331void kvm_vcpu_block(struct kvm_vcpu *vcpu); 383void kvm_vcpu_block(struct kvm_vcpu *vcpu);
332void kvm_vcpu_on_spin(struct kvm_vcpu *vcpu); 384void kvm_vcpu_on_spin(struct kvm_vcpu *vcpu);
333void kvm_resched(struct kvm_vcpu *vcpu); 385void kvm_resched(struct kvm_vcpu *vcpu);
334void kvm_load_guest_fpu(struct kvm_vcpu *vcpu); 386void kvm_load_guest_fpu(struct kvm_vcpu *vcpu);
335void kvm_put_guest_fpu(struct kvm_vcpu *vcpu); 387void kvm_put_guest_fpu(struct kvm_vcpu *vcpu);
388
336void kvm_flush_remote_tlbs(struct kvm *kvm); 389void kvm_flush_remote_tlbs(struct kvm *kvm);
337void kvm_reload_remote_mmus(struct kvm *kvm); 390void kvm_reload_remote_mmus(struct kvm *kvm);
338 391
@@ -398,7 +451,19 @@ int kvm_arch_vcpu_runnable(struct kvm_vcpu *vcpu);
398 451
399void kvm_free_physmem(struct kvm *kvm); 452void kvm_free_physmem(struct kvm *kvm);
400 453
401struct kvm *kvm_arch_create_vm(void); 454#ifndef __KVM_HAVE_ARCH_VM_ALLOC
455static inline struct kvm *kvm_arch_alloc_vm(void)
456{
457 return kzalloc(sizeof(struct kvm), GFP_KERNEL);
458}
459
460static inline void kvm_arch_free_vm(struct kvm *kvm)
461{
462 kfree(kvm);
463}
464#endif
465
466int kvm_arch_init_vm(struct kvm *kvm);
402void kvm_arch_destroy_vm(struct kvm *kvm); 467void kvm_arch_destroy_vm(struct kvm *kvm);
403void kvm_free_all_assigned_devices(struct kvm *kvm); 468void kvm_free_all_assigned_devices(struct kvm *kvm);
404void kvm_arch_sync_events(struct kvm *kvm); 469void kvm_arch_sync_events(struct kvm *kvm);
@@ -414,16 +479,8 @@ struct kvm_irq_ack_notifier {
414 void (*irq_acked)(struct kvm_irq_ack_notifier *kian); 479 void (*irq_acked)(struct kvm_irq_ack_notifier *kian);
415}; 480};
416 481
417#define KVM_ASSIGNED_MSIX_PENDING 0x1
418struct kvm_guest_msix_entry {
419 u32 vector;
420 u16 entry;
421 u16 flags;
422};
423
424struct kvm_assigned_dev_kernel { 482struct kvm_assigned_dev_kernel {
425 struct kvm_irq_ack_notifier ack_notifier; 483 struct kvm_irq_ack_notifier ack_notifier;
426 struct work_struct interrupt_work;
427 struct list_head list; 484 struct list_head list;
428 int assigned_dev_id; 485 int assigned_dev_id;
429 int host_segnr; 486 int host_segnr;
@@ -434,13 +491,14 @@ struct kvm_assigned_dev_kernel {
434 bool host_irq_disabled; 491 bool host_irq_disabled;
435 struct msix_entry *host_msix_entries; 492 struct msix_entry *host_msix_entries;
436 int guest_irq; 493 int guest_irq;
437 struct kvm_guest_msix_entry *guest_msix_entries; 494 struct msix_entry *guest_msix_entries;
438 unsigned long irq_requested_type; 495 unsigned long irq_requested_type;
439 int irq_source_id; 496 int irq_source_id;
440 int flags; 497 int flags;
441 struct pci_dev *dev; 498 struct pci_dev *dev;
442 struct kvm *kvm; 499 struct kvm *kvm;
443 spinlock_t assigned_dev_lock; 500 spinlock_t intx_lock;
501 char irq_name[32];
444}; 502};
445 503
446struct kvm_irq_mask_notifier { 504struct kvm_irq_mask_notifier {
@@ -462,6 +520,8 @@ void kvm_get_intr_delivery_bitmask(struct kvm_ioapic *ioapic,
462 unsigned long *deliver_bitmask); 520 unsigned long *deliver_bitmask);
463#endif 521#endif
464int kvm_set_irq(struct kvm *kvm, int irq_source_id, u32 irq, int level); 522int kvm_set_irq(struct kvm *kvm, int irq_source_id, u32 irq, int level);
523int kvm_set_msi(struct kvm_kernel_irq_routing_entry *irq_entry, struct kvm *kvm,
524 int irq_source_id, int level);
465void kvm_notify_acked_irq(struct kvm *kvm, unsigned irqchip, unsigned pin); 525void kvm_notify_acked_irq(struct kvm *kvm, unsigned irqchip, unsigned pin);
466void kvm_register_irq_ack_notifier(struct kvm *kvm, 526void kvm_register_irq_ack_notifier(struct kvm *kvm,
467 struct kvm_irq_ack_notifier *kian); 527 struct kvm_irq_ack_notifier *kian);
@@ -603,17 +663,28 @@ static inline void kvm_free_irq_routing(struct kvm *kvm) {}
603void kvm_eventfd_init(struct kvm *kvm); 663void kvm_eventfd_init(struct kvm *kvm);
604int kvm_irqfd(struct kvm *kvm, int fd, int gsi, int flags); 664int kvm_irqfd(struct kvm *kvm, int fd, int gsi, int flags);
605void kvm_irqfd_release(struct kvm *kvm); 665void kvm_irqfd_release(struct kvm *kvm);
666void kvm_irq_routing_update(struct kvm *, struct kvm_irq_routing_table *);
606int kvm_ioeventfd(struct kvm *kvm, struct kvm_ioeventfd *args); 667int kvm_ioeventfd(struct kvm *kvm, struct kvm_ioeventfd *args);
607 668
608#else 669#else
609 670
610static inline void kvm_eventfd_init(struct kvm *kvm) {} 671static inline void kvm_eventfd_init(struct kvm *kvm) {}
672
611static inline int kvm_irqfd(struct kvm *kvm, int fd, int gsi, int flags) 673static inline int kvm_irqfd(struct kvm *kvm, int fd, int gsi, int flags)
612{ 674{
613 return -EINVAL; 675 return -EINVAL;
614} 676}
615 677
616static inline void kvm_irqfd_release(struct kvm *kvm) {} 678static inline void kvm_irqfd_release(struct kvm *kvm) {}
679
680#ifdef CONFIG_HAVE_KVM_IRQCHIP
681static inline void kvm_irq_routing_update(struct kvm *kvm,
682 struct kvm_irq_routing_table *irq_rt)
683{
684 rcu_assign_pointer(kvm->irq_routing, irq_rt);
685}
686#endif
687
617static inline int kvm_ioeventfd(struct kvm *kvm, struct kvm_ioeventfd *args) 688static inline int kvm_ioeventfd(struct kvm *kvm, struct kvm_ioeventfd *args)
618{ 689{
619 return -ENOSYS; 690 return -ENOSYS;