diff options
| author | Linus Torvalds <torvalds@linux-foundation.org> | 2013-11-14 23:51:36 -0500 |
|---|---|---|
| committer | Linus Torvalds <torvalds@linux-foundation.org> | 2013-11-14 23:51:36 -0500 |
| commit | f080480488028bcc25357f85e8ae54ccc3bb7173 (patch) | |
| tree | 8fcc943f16d26c795b3b6324b478af2d5a30285d /virt | |
| parent | eda670c626a4f53eb8ac5f20d8c10d3f0b54c583 (diff) | |
| parent | e504c9098ed6acd9e1079c5e10e4910724ad429f (diff) | |
Merge tag 'for-linus' of git://git.kernel.org/pub/scm/virt/kvm/kvm
Pull KVM changes from Paolo Bonzini:
"Here are the 3.13 KVM changes. There was a lot of work on the PPC
side: the HV and emulation flavors can now coexist in a single kernel
is probably the most interesting change from a user point of view.
On the x86 side there are nested virtualization improvements and a few
bugfixes.
ARM got transparent huge page support, improved overcommit, and
support for big endian guests.
Finally, there is a new interface to connect KVM with VFIO. This
helps with devices that use NoSnoop PCI transactions, letting the
driver in the guest execute WBINVD instructions. This includes some
nVidia cards on Windows, that fail to start without these patches and
the corresponding userspace changes"
* tag 'for-linus' of git://git.kernel.org/pub/scm/virt/kvm/kvm: (146 commits)
kvm, vmx: Fix lazy FPU on nested guest
arm/arm64: KVM: PSCI: propagate caller endianness to the incoming vcpu
arm/arm64: KVM: MMIO support for BE guest
kvm, cpuid: Fix sparse warning
kvm: Delete prototype for non-existent function kvm_check_iopl
kvm: Delete prototype for non-existent function complete_pio
hung_task: add method to reset detector
pvclock: detect watchdog reset at pvclock read
kvm: optimize out smp_mb after srcu_read_unlock
srcu: API for barrier after srcu read unlock
KVM: remove vm mmap method
KVM: IOMMU: hva align mapping page size
KVM: x86: trace cpuid emulation when called from emulator
KVM: emulator: cleanup decode_register_operand() a bit
KVM: emulator: check rex prefix inside decode_register()
KVM: x86: fix emulation of "movzbl %bpl, %eax"
kvm_host: typo fix
KVM: x86: emulate SAHF instruction
MAINTAINERS: add tree for kvm.git
Documentation/kvm: add a 00-INDEX file
...
Diffstat (limited to 'virt')
| -rw-r--r-- | virt/kvm/Kconfig | 3 | ||||
| -rw-r--r-- | virt/kvm/async_pf.c | 22 | ||||
| -rw-r--r-- | virt/kvm/iommu.c | 38 | ||||
| -rw-r--r-- | virt/kvm/kvm_main.c | 134 | ||||
| -rw-r--r-- | virt/kvm/vfio.c | 264 |
5 files changed, 348 insertions, 113 deletions
diff --git a/virt/kvm/Kconfig b/virt/kvm/Kconfig index 779262f59e25..fbe1a48bd629 100644 --- a/virt/kvm/Kconfig +++ b/virt/kvm/Kconfig | |||
| @@ -27,3 +27,6 @@ config HAVE_KVM_MSI | |||
| 27 | 27 | ||
| 28 | config HAVE_KVM_CPU_RELAX_INTERCEPT | 28 | config HAVE_KVM_CPU_RELAX_INTERCEPT |
| 29 | bool | 29 | bool |
| 30 | |||
| 31 | config KVM_VFIO | ||
| 32 | bool | ||
diff --git a/virt/kvm/async_pf.c b/virt/kvm/async_pf.c index 8a39dda7a325..8631d9c14320 100644 --- a/virt/kvm/async_pf.c +++ b/virt/kvm/async_pf.c | |||
| @@ -56,7 +56,6 @@ void kvm_async_pf_vcpu_init(struct kvm_vcpu *vcpu) | |||
| 56 | 56 | ||
| 57 | static void async_pf_execute(struct work_struct *work) | 57 | static void async_pf_execute(struct work_struct *work) |
| 58 | { | 58 | { |
| 59 | struct page *page = NULL; | ||
| 60 | struct kvm_async_pf *apf = | 59 | struct kvm_async_pf *apf = |
| 61 | container_of(work, struct kvm_async_pf, work); | 60 | container_of(work, struct kvm_async_pf, work); |
| 62 | struct mm_struct *mm = apf->mm; | 61 | struct mm_struct *mm = apf->mm; |
| @@ -68,14 +67,12 @@ static void async_pf_execute(struct work_struct *work) | |||
| 68 | 67 | ||
| 69 | use_mm(mm); | 68 | use_mm(mm); |
| 70 | down_read(&mm->mmap_sem); | 69 | down_read(&mm->mmap_sem); |
| 71 | get_user_pages(current, mm, addr, 1, 1, 0, &page, NULL); | 70 | get_user_pages(current, mm, addr, 1, 1, 0, NULL, NULL); |
| 72 | up_read(&mm->mmap_sem); | 71 | up_read(&mm->mmap_sem); |
| 73 | unuse_mm(mm); | 72 | unuse_mm(mm); |
| 74 | 73 | ||
| 75 | spin_lock(&vcpu->async_pf.lock); | 74 | spin_lock(&vcpu->async_pf.lock); |
| 76 | list_add_tail(&apf->link, &vcpu->async_pf.done); | 75 | list_add_tail(&apf->link, &vcpu->async_pf.done); |
| 77 | apf->page = page; | ||
| 78 | apf->done = true; | ||
| 79 | spin_unlock(&vcpu->async_pf.lock); | 76 | spin_unlock(&vcpu->async_pf.lock); |
| 80 | 77 | ||
| 81 | /* | 78 | /* |
| @@ -83,7 +80,7 @@ static void async_pf_execute(struct work_struct *work) | |||
| 83 | * this point | 80 | * this point |
| 84 | */ | 81 | */ |
| 85 | 82 | ||
| 86 | trace_kvm_async_pf_completed(addr, page, gva); | 83 | trace_kvm_async_pf_completed(addr, gva); |
| 87 | 84 | ||
| 88 | if (waitqueue_active(&vcpu->wq)) | 85 | if (waitqueue_active(&vcpu->wq)) |
| 89 | wake_up_interruptible(&vcpu->wq); | 86 | wake_up_interruptible(&vcpu->wq); |
| @@ -99,9 +96,8 @@ void kvm_clear_async_pf_completion_queue(struct kvm_vcpu *vcpu) | |||
| 99 | struct kvm_async_pf *work = | 96 | struct kvm_async_pf *work = |
| 100 | list_entry(vcpu->async_pf.queue.next, | 97 | list_entry(vcpu->async_pf.queue.next, |
| 101 | typeof(*work), queue); | 98 | typeof(*work), queue); |
| 102 | cancel_work_sync(&work->work); | ||
| 103 | list_del(&work->queue); | 99 | list_del(&work->queue); |
| 104 | if (!work->done) { /* work was canceled */ | 100 | if (cancel_work_sync(&work->work)) { |
| 105 | mmdrop(work->mm); | 101 | mmdrop(work->mm); |
| 106 | kvm_put_kvm(vcpu->kvm); /* == work->vcpu->kvm */ | 102 | kvm_put_kvm(vcpu->kvm); /* == work->vcpu->kvm */ |
| 107 | kmem_cache_free(async_pf_cache, work); | 103 | kmem_cache_free(async_pf_cache, work); |
| @@ -114,8 +110,6 @@ void kvm_clear_async_pf_completion_queue(struct kvm_vcpu *vcpu) | |||
| 114 | list_entry(vcpu->async_pf.done.next, | 110 | list_entry(vcpu->async_pf.done.next, |
| 115 | typeof(*work), link); | 111 | typeof(*work), link); |
| 116 | list_del(&work->link); | 112 | list_del(&work->link); |
| 117 | if (!is_error_page(work->page)) | ||
| 118 | kvm_release_page_clean(work->page); | ||
| 119 | kmem_cache_free(async_pf_cache, work); | 113 | kmem_cache_free(async_pf_cache, work); |
| 120 | } | 114 | } |
| 121 | spin_unlock(&vcpu->async_pf.lock); | 115 | spin_unlock(&vcpu->async_pf.lock); |
| @@ -135,14 +129,11 @@ void kvm_check_async_pf_completion(struct kvm_vcpu *vcpu) | |||
| 135 | list_del(&work->link); | 129 | list_del(&work->link); |
| 136 | spin_unlock(&vcpu->async_pf.lock); | 130 | spin_unlock(&vcpu->async_pf.lock); |
| 137 | 131 | ||
| 138 | if (work->page) | 132 | kvm_arch_async_page_ready(vcpu, work); |
| 139 | kvm_arch_async_page_ready(vcpu, work); | ||
| 140 | kvm_arch_async_page_present(vcpu, work); | 133 | kvm_arch_async_page_present(vcpu, work); |
| 141 | 134 | ||
| 142 | list_del(&work->queue); | 135 | list_del(&work->queue); |
| 143 | vcpu->async_pf.queued--; | 136 | vcpu->async_pf.queued--; |
| 144 | if (!is_error_page(work->page)) | ||
| 145 | kvm_release_page_clean(work->page); | ||
| 146 | kmem_cache_free(async_pf_cache, work); | 137 | kmem_cache_free(async_pf_cache, work); |
| 147 | } | 138 | } |
| 148 | } | 139 | } |
| @@ -165,8 +156,7 @@ int kvm_setup_async_pf(struct kvm_vcpu *vcpu, gva_t gva, gfn_t gfn, | |||
| 165 | if (!work) | 156 | if (!work) |
| 166 | return 0; | 157 | return 0; |
| 167 | 158 | ||
| 168 | work->page = NULL; | 159 | work->wakeup_all = false; |
| 169 | work->done = false; | ||
| 170 | work->vcpu = vcpu; | 160 | work->vcpu = vcpu; |
| 171 | work->gva = gva; | 161 | work->gva = gva; |
| 172 | work->addr = gfn_to_hva(vcpu->kvm, gfn); | 162 | work->addr = gfn_to_hva(vcpu->kvm, gfn); |
| @@ -206,7 +196,7 @@ int kvm_async_pf_wakeup_all(struct kvm_vcpu *vcpu) | |||
| 206 | if (!work) | 196 | if (!work) |
| 207 | return -ENOMEM; | 197 | return -ENOMEM; |
| 208 | 198 | ||
| 209 | work->page = KVM_ERR_PTR_BAD_PAGE; | 199 | work->wakeup_all = true; |
| 210 | INIT_LIST_HEAD(&work->queue); /* for list_del to work */ | 200 | INIT_LIST_HEAD(&work->queue); /* for list_del to work */ |
| 211 | 201 | ||
| 212 | spin_lock(&vcpu->async_pf.lock); | 202 | spin_lock(&vcpu->async_pf.lock); |
diff --git a/virt/kvm/iommu.c b/virt/kvm/iommu.c index 72a130bc448a..0df7d4b34dfe 100644 --- a/virt/kvm/iommu.c +++ b/virt/kvm/iommu.c | |||
| @@ -79,7 +79,7 @@ int kvm_iommu_map_pages(struct kvm *kvm, struct kvm_memory_slot *slot) | |||
| 79 | flags = IOMMU_READ; | 79 | flags = IOMMU_READ; |
| 80 | if (!(slot->flags & KVM_MEM_READONLY)) | 80 | if (!(slot->flags & KVM_MEM_READONLY)) |
| 81 | flags |= IOMMU_WRITE; | 81 | flags |= IOMMU_WRITE; |
| 82 | if (kvm->arch.iommu_flags & KVM_IOMMU_CACHE_COHERENCY) | 82 | if (!kvm->arch.iommu_noncoherent) |
| 83 | flags |= IOMMU_CACHE; | 83 | flags |= IOMMU_CACHE; |
| 84 | 84 | ||
| 85 | 85 | ||
| @@ -103,6 +103,10 @@ int kvm_iommu_map_pages(struct kvm *kvm, struct kvm_memory_slot *slot) | |||
| 103 | while ((gfn << PAGE_SHIFT) & (page_size - 1)) | 103 | while ((gfn << PAGE_SHIFT) & (page_size - 1)) |
| 104 | page_size >>= 1; | 104 | page_size >>= 1; |
| 105 | 105 | ||
| 106 | /* Make sure hva is aligned to the page size we want to map */ | ||
| 107 | while (__gfn_to_hva_memslot(slot, gfn) & (page_size - 1)) | ||
| 108 | page_size >>= 1; | ||
| 109 | |||
| 106 | /* | 110 | /* |
| 107 | * Pin all pages we are about to map in memory. This is | 111 | * Pin all pages we are about to map in memory. This is |
| 108 | * important because we unmap and unpin in 4kb steps later. | 112 | * important because we unmap and unpin in 4kb steps later. |
| @@ -140,6 +144,9 @@ static int kvm_iommu_map_memslots(struct kvm *kvm) | |||
| 140 | struct kvm_memslots *slots; | 144 | struct kvm_memslots *slots; |
| 141 | struct kvm_memory_slot *memslot; | 145 | struct kvm_memory_slot *memslot; |
| 142 | 146 | ||
| 147 | if (kvm->arch.iommu_noncoherent) | ||
| 148 | kvm_arch_register_noncoherent_dma(kvm); | ||
| 149 | |||
| 143 | idx = srcu_read_lock(&kvm->srcu); | 150 | idx = srcu_read_lock(&kvm->srcu); |
| 144 | slots = kvm_memslots(kvm); | 151 | slots = kvm_memslots(kvm); |
| 145 | 152 | ||
| @@ -158,7 +165,8 @@ int kvm_assign_device(struct kvm *kvm, | |||
| 158 | { | 165 | { |
| 159 | struct pci_dev *pdev = NULL; | 166 | struct pci_dev *pdev = NULL; |
| 160 | struct iommu_domain *domain = kvm->arch.iommu_domain; | 167 | struct iommu_domain *domain = kvm->arch.iommu_domain; |
| 161 | int r, last_flags; | 168 | int r; |
| 169 | bool noncoherent; | ||
| 162 | 170 | ||
| 163 | /* check if iommu exists and in use */ | 171 | /* check if iommu exists and in use */ |
| 164 | if (!domain) | 172 | if (!domain) |
| @@ -174,15 +182,13 @@ int kvm_assign_device(struct kvm *kvm, | |||
| 174 | return r; | 182 | return r; |
| 175 | } | 183 | } |
| 176 | 184 | ||
| 177 | last_flags = kvm->arch.iommu_flags; | 185 | noncoherent = !iommu_domain_has_cap(kvm->arch.iommu_domain, |
| 178 | if (iommu_domain_has_cap(kvm->arch.iommu_domain, | 186 | IOMMU_CAP_CACHE_COHERENCY); |
