aboutsummaryrefslogtreecommitdiffstats
path: root/include
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2012-03-28 17:35:31 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2012-03-28 17:35:31 -0400
commit2e7580b0e75d771d93e24e681031a165b1d31071 (patch)
treed9449702609eeaab28913a43b5a4434667e09d43 /include
parentd25413efa9536e2f425ea45c7720598035c597bc (diff)
parentcf9eeac46350b8b43730b7dc5e999757bed089a4 (diff)
Merge branch 'kvm-updates/3.4' of git://git.kernel.org/pub/scm/virt/kvm/kvm
Pull kvm updates from Avi Kivity: "Changes include timekeeping improvements, support for assigning host PCI devices that share interrupt lines, s390 user-controlled guests, a large ppc update, and random fixes." This is with the sign-off's fixed, hopefully next merge window we won't have rebased commits. * 'kvm-updates/3.4' of git://git.kernel.org/pub/scm/virt/kvm/kvm: (130 commits) KVM: Convert intx_mask_lock to spin lock KVM: x86: fix kvm_write_tsc() TSC matching thinko x86: kvmclock: abstract save/restore sched_clock_state KVM: nVMX: Fix erroneous exception bitmap check KVM: Ignore the writes to MSR_K7_HWCR(3) KVM: MMU: make use of ->root_level in reset_rsvds_bits_mask KVM: PMU: add proper support for fixed counter 2 KVM: PMU: Fix raw event check KVM: PMU: warn when pin control is set in eventsel msr KVM: VMX: Fix delayed load of shared MSRs KVM: use correct tlbs dirty type in cmpxchg KVM: Allow host IRQ sharing for assigned PCI 2.3 devices KVM: Ensure all vcpus are consistent with in-kernel irqchip settings KVM: x86 emulator: Allow PM/VM86 switch during task switch KVM: SVM: Fix CPL updates KVM: x86 emulator: VM86 segments must have DPL 3 KVM: x86 emulator: Fix task switch privilege checks arch/powerpc/kvm/book3s_hv.c: included linux/sched.h twice KVM: x86 emulator: correctly mask pmc index bits in RDPMC instruction emulation KVM: mmu_notifier: Flush TLBs before releasing mmu_lock ...
Diffstat (limited to 'include')
-rw-r--r--include/linux/kvm.h98
-rw-r--r--include/linux/kvm_host.h69
2 files changed, 155 insertions, 12 deletions
diff --git a/include/linux/kvm.h b/include/linux/kvm.h
index 68e67e50d028..6c322a90b92f 100644
--- a/include/linux/kvm.h
+++ b/include/linux/kvm.h
@@ -162,6 +162,7 @@ struct kvm_pit_config {
162#define KVM_EXIT_INTERNAL_ERROR 17 162#define KVM_EXIT_INTERNAL_ERROR 17
163#define KVM_EXIT_OSI 18 163#define KVM_EXIT_OSI 18
164#define KVM_EXIT_PAPR_HCALL 19 164#define KVM_EXIT_PAPR_HCALL 19
165#define KVM_EXIT_S390_UCONTROL 20
165 166
166/* For KVM_EXIT_INTERNAL_ERROR */ 167/* For KVM_EXIT_INTERNAL_ERROR */
167#define KVM_INTERNAL_ERROR_EMULATION 1 168#define KVM_INTERNAL_ERROR_EMULATION 1
@@ -249,6 +250,11 @@ struct kvm_run {
249#define KVM_S390_RESET_CPU_INIT 8 250#define KVM_S390_RESET_CPU_INIT 8
250#define KVM_S390_RESET_IPL 16 251#define KVM_S390_RESET_IPL 16
251 __u64 s390_reset_flags; 252 __u64 s390_reset_flags;
253 /* KVM_EXIT_S390_UCONTROL */
254 struct {
255 __u64 trans_exc_code;
256 __u32 pgm_code;
257 } s390_ucontrol;
252 /* KVM_EXIT_DCR */ 258 /* KVM_EXIT_DCR */
253 struct { 259 struct {
254 __u32 dcrn; 260 __u32 dcrn;
@@ -273,6 +279,20 @@ struct kvm_run {
273 /* Fix the size of the union. */ 279 /* Fix the size of the union. */
274 char padding[256]; 280 char padding[256];
275 }; 281 };
282
283 /*
284 * shared registers between kvm and userspace.
285 * kvm_valid_regs specifies the register classes set by the host
286 * kvm_dirty_regs specified the register classes dirtied by userspace
287 * struct kvm_sync_regs is architecture specific, as well as the
288 * bits for kvm_valid_regs and kvm_dirty_regs
289 */
290 __u64 kvm_valid_regs;
291 __u64 kvm_dirty_regs;
292 union {
293 struct kvm_sync_regs regs;
294 char padding[1024];
295 } s;
276}; 296};
277 297
278/* for KVM_REGISTER_COALESCED_MMIO / KVM_UNREGISTER_COALESCED_MMIO */ 298/* for KVM_REGISTER_COALESCED_MMIO / KVM_UNREGISTER_COALESCED_MMIO */
@@ -431,6 +451,11 @@ struct kvm_ppc_pvinfo {
431 451
432#define KVMIO 0xAE 452#define KVMIO 0xAE
433 453
454/* machine type bits, to be used as argument to KVM_CREATE_VM */
455#define KVM_VM_S390_UCONTROL 1
456
457#define KVM_S390_SIE_PAGE_OFFSET 1
458
434/* 459/*
435 * ioctls for /dev/kvm fds: 460 * ioctls for /dev/kvm fds:
436 */ 461 */
@@ -555,9 +580,15 @@ struct kvm_ppc_pvinfo {
555#define KVM_CAP_PPC_SMT 64 580#define KVM_CAP_PPC_SMT 64
556#define KVM_CAP_PPC_RMA 65 581#define KVM_CAP_PPC_RMA 65
557#define KVM_CAP_MAX_VCPUS 66 /* returns max vcpus per vm */ 582#define KVM_CAP_MAX_VCPUS 66 /* returns max vcpus per vm */
583#define KVM_CAP_PPC_HIOR 67
558#define KVM_CAP_PPC_PAPR 68 584#define KVM_CAP_PPC_PAPR 68
585#define KVM_CAP_SW_TLB 69
586#define KVM_CAP_ONE_REG 70
559#define KVM_CAP_S390_GMAP 71 587#define KVM_CAP_S390_GMAP 71
560#define KVM_CAP_TSC_DEADLINE_TIMER 72 588#define KVM_CAP_TSC_DEADLINE_TIMER 72
589#define KVM_CAP_S390_UCONTROL 73
590#define KVM_CAP_SYNC_REGS 74
591#define KVM_CAP_PCI_2_3 75
561 592
562#ifdef KVM_CAP_IRQ_ROUTING 593#ifdef KVM_CAP_IRQ_ROUTING
563 594
@@ -637,6 +668,52 @@ struct kvm_clock_data {
637 __u32 pad[9]; 668 __u32 pad[9];
638}; 669};
639 670
671#define KVM_MMU_FSL_BOOKE_NOHV 0
672#define KVM_MMU_FSL_BOOKE_HV 1
673
674struct kvm_config_tlb {
675 __u64 params;
676 __u64 array;
677 __u32 mmu_type;
678 __u32 array_len;
679};
680
681struct kvm_dirty_tlb {
682 __u64 bitmap;
683 __u32 num_dirty;
684};
685
686/* Available with KVM_CAP_ONE_REG */
687
688#define KVM_REG_ARCH_MASK 0xff00000000000000ULL
689#define KVM_REG_GENERIC 0x0000000000000000ULL
690
691/*
692 * Architecture specific registers are to be defined in arch headers and
693 * ORed with the arch identifier.
694 */
695#define KVM_REG_PPC 0x1000000000000000ULL
696#define KVM_REG_X86 0x2000000000000000ULL
697#define KVM_REG_IA64 0x3000000000000000ULL
698#define KVM_REG_ARM 0x4000000000000000ULL
699#define KVM_REG_S390 0x5000000000000000ULL
700
701#define KVM_REG_SIZE_SHIFT 52
702#define KVM_REG_SIZE_MASK 0x00f0000000000000ULL
703#define KVM_REG_SIZE_U8 0x0000000000000000ULL
704#define KVM_REG_SIZE_U16 0x0010000000000000ULL
705#define KVM_REG_SIZE_U32 0x0020000000000000ULL
706#define KVM_REG_SIZE_U64 0x0030000000000000ULL
707#define KVM_REG_SIZE_U128 0x0040000000000000ULL
708#define KVM_REG_SIZE_U256 0x0050000000000000ULL
709#define KVM_REG_SIZE_U512 0x0060000000000000ULL
710#define KVM_REG_SIZE_U1024 0x0070000000000000ULL
711
712struct kvm_one_reg {
713 __u64 id;
714 __u64 addr;
715};
716
640/* 717/*
641 * ioctls for VM fds 718 * ioctls for VM fds
642 */ 719 */
@@ -655,6 +732,17 @@ struct kvm_clock_data {
655 struct kvm_userspace_memory_region) 732 struct kvm_userspace_memory_region)
656#define KVM_SET_TSS_ADDR _IO(KVMIO, 0x47) 733#define KVM_SET_TSS_ADDR _IO(KVMIO, 0x47)
657#define KVM_SET_IDENTITY_MAP_ADDR _IOW(KVMIO, 0x48, __u64) 734#define KVM_SET_IDENTITY_MAP_ADDR _IOW(KVMIO, 0x48, __u64)
735
736/* enable ucontrol for s390 */
737struct kvm_s390_ucas_mapping {
738 __u64 user_addr;
739 __u64 vcpu_addr;
740 __u64 length;
741};
742#define KVM_S390_UCAS_MAP _IOW(KVMIO, 0x50, struct kvm_s390_ucas_mapping)
743#define KVM_S390_UCAS_UNMAP _IOW(KVMIO, 0x51, struct kvm_s390_ucas_mapping)
744#define KVM_S390_VCPU_FAULT _IOW(KVMIO, 0x52, unsigned long)
745
658/* Device model IOC */ 746/* Device model IOC */
659#define KVM_CREATE_IRQCHIP _IO(KVMIO, 0x60) 747#define KVM_CREATE_IRQCHIP _IO(KVMIO, 0x60)
660#define KVM_IRQ_LINE _IOW(KVMIO, 0x61, struct kvm_irq_level) 748#define KVM_IRQ_LINE _IOW(KVMIO, 0x61, struct kvm_irq_level)
@@ -697,6 +785,9 @@ struct kvm_clock_data {
697/* Available with KVM_CAP_TSC_CONTROL */ 785/* Available with KVM_CAP_TSC_CONTROL */
698#define KVM_SET_TSC_KHZ _IO(KVMIO, 0xa2) 786#define KVM_SET_TSC_KHZ _IO(KVMIO, 0xa2)
699#define KVM_GET_TSC_KHZ _IO(KVMIO, 0xa3) 787#define KVM_GET_TSC_KHZ _IO(KVMIO, 0xa3)
788/* Available with KVM_CAP_PCI_2_3 */
789#define KVM_ASSIGN_SET_INTX_MASK _IOW(KVMIO, 0xa4, \
790 struct kvm_assigned_pci_dev)
700 791
701/* 792/*
702 * ioctls for vcpu fds 793 * ioctls for vcpu fds
@@ -763,8 +854,15 @@ struct kvm_clock_data {
763#define KVM_CREATE_SPAPR_TCE _IOW(KVMIO, 0xa8, struct kvm_create_spapr_tce) 854#define KVM_CREATE_SPAPR_TCE _IOW(KVMIO, 0xa8, struct kvm_create_spapr_tce)
764/* Available with KVM_CAP_RMA */ 855/* Available with KVM_CAP_RMA */
765#define KVM_ALLOCATE_RMA _IOR(KVMIO, 0xa9, struct kvm_allocate_rma) 856#define KVM_ALLOCATE_RMA _IOR(KVMIO, 0xa9, struct kvm_allocate_rma)
857/* Available with KVM_CAP_SW_TLB */
858#define KVM_DIRTY_TLB _IOW(KVMIO, 0xaa, struct kvm_dirty_tlb)
859/* Available with KVM_CAP_ONE_REG */
860#define KVM_GET_ONE_REG _IOW(KVMIO, 0xab, struct kvm_one_reg)
861#define KVM_SET_ONE_REG _IOW(KVMIO, 0xac, struct kvm_one_reg)
766 862
767#define KVM_DEV_ASSIGN_ENABLE_IOMMU (1 << 0) 863#define KVM_DEV_ASSIGN_ENABLE_IOMMU (1 << 0)
864#define KVM_DEV_ASSIGN_PCI_2_3 (1 << 1)
865#define KVM_DEV_ASSIGN_MASK_INTX (1 << 2)
768 866
769struct kvm_assigned_pci_dev { 867struct kvm_assigned_pci_dev {
770 __u32 assigned_dev_id; 868 __u32 assigned_dev_id;
diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h
index ca1b153585d3..665a260c7e09 100644
--- a/include/linux/kvm_host.h
+++ b/include/linux/kvm_host.h
@@ -172,11 +172,6 @@ static inline int kvm_vcpu_exiting_guest_mode(struct kvm_vcpu *vcpu)
172 */ 172 */
173#define KVM_MEM_MAX_NR_PAGES ((1UL << 31) - 1) 173#define KVM_MEM_MAX_NR_PAGES ((1UL << 31) - 1)
174 174
175struct kvm_lpage_info {
176 unsigned long rmap_pde;
177 int write_count;
178};
179
180struct kvm_memory_slot { 175struct kvm_memory_slot {
181 gfn_t base_gfn; 176 gfn_t base_gfn;
182 unsigned long npages; 177 unsigned long npages;
@@ -185,7 +180,7 @@ struct kvm_memory_slot {
185 unsigned long *dirty_bitmap; 180 unsigned long *dirty_bitmap;
186 unsigned long *dirty_bitmap_head; 181 unsigned long *dirty_bitmap_head;
187 unsigned long nr_dirty_pages; 182 unsigned long nr_dirty_pages;
188 struct kvm_lpage_info *lpage_info[KVM_NR_PAGE_SIZES - 1]; 183 struct kvm_arch_memory_slot arch;
189 unsigned long userspace_addr; 184 unsigned long userspace_addr;
190 int user_alloc; 185 int user_alloc;
191 int id; 186 int id;
@@ -377,6 +372,9 @@ int kvm_set_memory_region(struct kvm *kvm,
377int __kvm_set_memory_region(struct kvm *kvm, 372int __kvm_set_memory_region(struct kvm *kvm,
378 struct kvm_userspace_memory_region *mem, 373 struct kvm_userspace_memory_region *mem,
379 int user_alloc); 374 int user_alloc);
375void kvm_arch_free_memslot(struct kvm_memory_slot *free,
376 struct kvm_memory_slot *dont);
377int kvm_arch_create_memslot(struct kvm_memory_slot *slot, unsigned long npages);
380int kvm_arch_prepare_memory_region(struct kvm *kvm, 378int kvm_arch_prepare_memory_region(struct kvm *kvm,
381 struct kvm_memory_slot *memslot, 379 struct kvm_memory_slot *memslot,
382 struct kvm_memory_slot old, 380 struct kvm_memory_slot old,
@@ -386,6 +384,7 @@ void kvm_arch_commit_memory_region(struct kvm *kvm,
386 struct kvm_userspace_memory_region *mem, 384 struct kvm_userspace_memory_region *mem,
387 struct kvm_memory_slot old, 385 struct kvm_memory_slot old,
388 int user_alloc); 386 int user_alloc);
387bool kvm_largepages_enabled(void);
389void kvm_disable_largepages(void); 388void kvm_disable_largepages(void);
390void kvm_arch_flush_shadow(struct kvm *kvm); 389void kvm_arch_flush_shadow(struct kvm *kvm);
391 390
@@ -451,6 +450,7 @@ long kvm_arch_dev_ioctl(struct file *filp,
451 unsigned int ioctl, unsigned long arg); 450 unsigned int ioctl, unsigned long arg);
452long kvm_arch_vcpu_ioctl(struct file *filp, 451long kvm_arch_vcpu_ioctl(struct file *filp,
453 unsigned int ioctl, unsigned long arg); 452 unsigned int ioctl, unsigned long arg);
453int kvm_arch_vcpu_fault(struct kvm_vcpu *vcpu, struct vm_fault *vmf);
454 454
455int kvm_dev_ioctl_check_extension(long ext); 455int kvm_dev_ioctl_check_extension(long ext);
456 456
@@ -521,7 +521,7 @@ static inline void kvm_arch_free_vm(struct kvm *kvm)
521} 521}
522#endif 522#endif
523 523
524int kvm_arch_init_vm(struct kvm *kvm); 524int kvm_arch_init_vm(struct kvm *kvm, unsigned long type);
525void kvm_arch_destroy_vm(struct kvm *kvm); 525void kvm_arch_destroy_vm(struct kvm *kvm);
526void kvm_free_all_assigned_devices(struct kvm *kvm); 526void kvm_free_all_assigned_devices(struct kvm *kvm);
527void kvm_arch_sync_events(struct kvm *kvm); 527void kvm_arch_sync_events(struct kvm *kvm);
@@ -547,6 +547,7 @@ struct kvm_assigned_dev_kernel {
547 unsigned int entries_nr; 547 unsigned int entries_nr;
548 int host_irq; 548 int host_irq;
549 bool host_irq_disabled; 549 bool host_irq_disabled;
550 bool pci_2_3;
550 struct msix_entry *host_msix_entries; 551 struct msix_entry *host_msix_entries;
551 int guest_irq; 552 int guest_irq;
552 struct msix_entry *guest_msix_entries; 553 struct msix_entry *guest_msix_entries;
@@ -556,6 +557,7 @@ struct kvm_assigned_dev_kernel {
556 struct pci_dev *dev; 557 struct pci_dev *dev;
557 struct kvm *kvm; 558 struct kvm *kvm;
558 spinlock_t intx_lock; 559 spinlock_t intx_lock;
560 spinlock_t intx_mask_lock;
559 char irq_name[32]; 561 char irq_name[32];
560 struct pci_saved_state *pci_saved_state; 562 struct pci_saved_state *pci_saved_state;
561}; 563};
@@ -651,11 +653,43 @@ static inline void kvm_guest_exit(void)
651 current->flags &= ~PF_VCPU; 653 current->flags &= ~PF_VCPU;
652} 654}
653 655
656/*
657 * search_memslots() and __gfn_to_memslot() are here because they are
658 * used in non-modular code in arch/powerpc/kvm/book3s_hv_rm_mmu.c.
659 * gfn_to_memslot() itself isn't here as an inline because that would
660 * bloat other code too much.
661 */
662static inline struct kvm_memory_slot *
663search_memslots(struct kvm_memslots *slots, gfn_t gfn)
664{
665 struct kvm_memory_slot *memslot;
666
667 kvm_for_each_memslot(memslot, slots)
668 if (gfn >= memslot->base_gfn &&
669 gfn < memslot->base_gfn + memslot->npages)
670 return memslot;
671
672 return NULL;
673}
674
675static inline struct kvm_memory_slot *
676__gfn_to_memslot(struct kvm_memslots *slots, gfn_t gfn)
677{
678 return search_memslots(slots, gfn);
679}
680
654static inline int memslot_id(struct kvm *kvm, gfn_t gfn) 681static inline int memslot_id(struct kvm *kvm, gfn_t gfn)
655{ 682{
656 return gfn_to_memslot(kvm, gfn)->id; 683 return gfn_to_memslot(kvm, gfn)->id;
657} 684}
658 685
686static inline gfn_t gfn_to_index(gfn_t gfn, gfn_t base_gfn, int level)
687{
688 /* KVM_HPAGE_GFN_SHIFT(PT_PAGE_TABLE_LEVEL) must be 0. */
689 return (gfn >> KVM_HPAGE_GFN_SHIFT(level)) -
690 (base_gfn >> KVM_HPAGE_GFN_SHIFT(level));
691}
692
659static inline unsigned long gfn_to_hva_memslot(struct kvm_memory_slot *slot, 693static inline unsigned long gfn_to_hva_memslot(struct kvm_memory_slot *slot,
660 gfn_t gfn) 694 gfn_t gfn)
661{ 695{
@@ -702,12 +736,16 @@ static inline int mmu_notifier_retry(struct kvm_vcpu *vcpu, unsigned long mmu_se
702 if (unlikely(vcpu->kvm->mmu_notifier_count)) 736 if (unlikely(vcpu->kvm->mmu_notifier_count))
703 return 1; 737 return 1;
704 /* 738 /*
705 * Both reads happen under the mmu_lock and both values are 739 * Ensure the read of mmu_notifier_count happens before the read
706 * modified under mmu_lock, so there's no need of smb_rmb() 740 * of mmu_notifier_seq. This interacts with the smp_wmb() in
707 * here in between, otherwise mmu_notifier_count should be 741 * mmu_notifier_invalidate_range_end to make sure that the caller
708 * read before mmu_notifier_seq, see 742 * either sees the old (non-zero) value of mmu_notifier_count or
709 * mmu_notifier_invalidate_range_end write side. 743 * the new (incremented) value of mmu_notifier_seq.
744 * PowerPC Book3s HV KVM calls this under a per-page lock
745 * rather than under kvm->mmu_lock, for scalability, so
746 * can't rely on kvm->mmu_lock to keep things ordered.
710 */ 747 */
748 smp_rmb();
711 if (vcpu->kvm->mmu_notifier_seq != mmu_seq) 749 if (vcpu->kvm->mmu_notifier_seq != mmu_seq)
712 return 1; 750 return 1;
713 return 0; 751 return 0;
@@ -770,6 +808,13 @@ static inline bool kvm_vcpu_is_bsp(struct kvm_vcpu *vcpu)
770{ 808{
771 return vcpu->kvm->bsp_vcpu_id == vcpu->vcpu_id; 809 return vcpu->kvm->bsp_vcpu_id == vcpu->vcpu_id;
772} 810}
811
812bool kvm_vcpu_compatible(struct kvm_vcpu *vcpu);
813
814#else
815
816static inline bool kvm_vcpu_compatible(struct kvm_vcpu *vcpu) { return true; }
817
773#endif 818#endif
774 819
775#ifdef __KVM_HAVE_DEVICE_ASSIGNMENT 820#ifdef __KVM_HAVE_DEVICE_ASSIGNMENT