diff options
author | Linus Torvalds <torvalds@linux-foundation.org> | 2012-04-19 13:28:59 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2012-04-19 13:28:59 -0400 |
commit | 9e01297ee1ada71e621c8b58a80a28a421a00471 (patch) | |
tree | b62959354c0b514d95b9829b8395aae12869d3e0 | |
parent | 9b7f43afd417a6feb80841d30ced4051c362eb5d (diff) | |
parent | 21a1416a1c945c5aeaeaf791b63c64926018eb77 (diff) |
Merge git://git.kernel.org/pub/scm/virt/kvm/kvm
Pull KVM updates from Marcelo Tosatti.
* git://git.kernel.org/pub/scm/virt/kvm/kvm:
KVM: lock slots_lock around device assignment
KVM: VMX: Fix kvm_set_shared_msr() called in preemptible context
KVM: unmap pages from the iommu when slots are removed
KVM: PMU emulation: GLOBAL_CTRL MSR should be enabled on reset
-rw-r--r-- | arch/x86/kvm/pmu.c | 18 | ||||
-rw-r--r-- | arch/x86/kvm/vmx.c | 5 | ||||
-rw-r--r-- | include/linux/kvm_host.h | 6 | ||||
-rw-r--r-- | virt/kvm/iommu.c | 30 | ||||
-rw-r--r-- | virt/kvm/kvm_main.c | 5 |
5 files changed, 43 insertions, 21 deletions
diff --git a/arch/x86/kvm/pmu.c b/arch/x86/kvm/pmu.c index 173df38dbda5..2e88438ffd83 100644 --- a/arch/x86/kvm/pmu.c +++ b/arch/x86/kvm/pmu.c | |||
@@ -459,17 +459,17 @@ void kvm_pmu_cpuid_update(struct kvm_vcpu *vcpu) | |||
459 | pmu->available_event_types = ~entry->ebx & ((1ull << bitmap_len) - 1); | 459 | pmu->available_event_types = ~entry->ebx & ((1ull << bitmap_len) - 1); |
460 | 460 | ||
461 | if (pmu->version == 1) { | 461 | if (pmu->version == 1) { |
462 | pmu->global_ctrl = (1 << pmu->nr_arch_gp_counters) - 1; | 462 | pmu->nr_arch_fixed_counters = 0; |
463 | return; | 463 | } else { |
464 | pmu->nr_arch_fixed_counters = min((int)(entry->edx & 0x1f), | ||
465 | X86_PMC_MAX_FIXED); | ||
466 | pmu->counter_bitmask[KVM_PMC_FIXED] = | ||
467 | ((u64)1 << ((entry->edx >> 5) & 0xff)) - 1; | ||
464 | } | 468 | } |
465 | 469 | ||
466 | pmu->nr_arch_fixed_counters = min((int)(entry->edx & 0x1f), | 470 | pmu->global_ctrl = ((1 << pmu->nr_arch_gp_counters) - 1) | |
467 | X86_PMC_MAX_FIXED); | 471 | (((1ull << pmu->nr_arch_fixed_counters) - 1) << X86_PMC_IDX_FIXED); |
468 | pmu->counter_bitmask[KVM_PMC_FIXED] = | 472 | pmu->global_ctrl_mask = ~pmu->global_ctrl; |
469 | ((u64)1 << ((entry->edx >> 5) & 0xff)) - 1; | ||
470 | pmu->global_ctrl_mask = ~(((1 << pmu->nr_arch_gp_counters) - 1) | ||
471 | | (((1ull << pmu->nr_arch_fixed_counters) - 1) | ||
472 | << X86_PMC_IDX_FIXED)); | ||
473 | } | 473 | } |
474 | 474 | ||
475 | void kvm_pmu_init(struct kvm_vcpu *vcpu) | 475 | void kvm_pmu_init(struct kvm_vcpu *vcpu) |
diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c index ad85adfef843..4ff0ab9bc3c8 100644 --- a/arch/x86/kvm/vmx.c +++ b/arch/x86/kvm/vmx.c | |||
@@ -2210,9 +2210,12 @@ static int vmx_set_msr(struct kvm_vcpu *vcpu, u32 msr_index, u64 data) | |||
2210 | msr = find_msr_entry(vmx, msr_index); | 2210 | msr = find_msr_entry(vmx, msr_index); |
2211 | if (msr) { | 2211 | if (msr) { |
2212 | msr->data = data; | 2212 | msr->data = data; |
2213 | if (msr - vmx->guest_msrs < vmx->save_nmsrs) | 2213 | if (msr - vmx->guest_msrs < vmx->save_nmsrs) { |
2214 | preempt_disable(); | ||
2214 | kvm_set_shared_msr(msr->index, msr->data, | 2215 | kvm_set_shared_msr(msr->index, msr->data, |
2215 | msr->mask); | 2216 | msr->mask); |
2217 | preempt_enable(); | ||
2218 | } | ||
2216 | break; | 2219 | break; |
2217 | } | 2220 | } |
2218 | ret = kvm_set_msr_common(vcpu, msr_index, data); | 2221 | ret = kvm_set_msr_common(vcpu, msr_index, data); |
diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h index 665a260c7e09..72cbf08d45fb 100644 --- a/include/linux/kvm_host.h +++ b/include/linux/kvm_host.h | |||
@@ -596,6 +596,7 @@ void kvm_free_irq_source_id(struct kvm *kvm, int irq_source_id); | |||
596 | 596 | ||
597 | #ifdef CONFIG_IOMMU_API | 597 | #ifdef CONFIG_IOMMU_API |
598 | int kvm_iommu_map_pages(struct kvm *kvm, struct kvm_memory_slot *slot); | 598 | int kvm_iommu_map_pages(struct kvm *kvm, struct kvm_memory_slot *slot); |
599 | void kvm_iommu_unmap_pages(struct kvm *kvm, struct kvm_memory_slot *slot); | ||
599 | int kvm_iommu_map_guest(struct kvm *kvm); | 600 | int kvm_iommu_map_guest(struct kvm *kvm); |
600 | int kvm_iommu_unmap_guest(struct kvm *kvm); | 601 | int kvm_iommu_unmap_guest(struct kvm *kvm); |
601 | int kvm_assign_device(struct kvm *kvm, | 602 | int kvm_assign_device(struct kvm *kvm, |
@@ -609,6 +610,11 @@ static inline int kvm_iommu_map_pages(struct kvm *kvm, | |||
609 | return 0; | 610 | return 0; |
610 | } | 611 | } |
611 | 612 | ||
613 | static inline void kvm_iommu_unmap_pages(struct kvm *kvm, | ||
614 | struct kvm_memory_slot *slot) | ||
615 | { | ||
616 | } | ||
617 | |||
612 | static inline int kvm_iommu_map_guest(struct kvm *kvm) | 618 | static inline int kvm_iommu_map_guest(struct kvm *kvm) |
613 | { | 619 | { |
614 | return -ENODEV; | 620 | return -ENODEV; |
diff --git a/virt/kvm/iommu.c b/virt/kvm/iommu.c index a457d2138f49..e9fff9830bf0 100644 --- a/virt/kvm/iommu.c +++ b/virt/kvm/iommu.c | |||
@@ -240,9 +240,13 @@ int kvm_iommu_map_guest(struct kvm *kvm) | |||
240 | return -ENODEV; | 240 | return -ENODEV; |
241 | } | 241 | } |
242 | 242 | ||
243 | mutex_lock(&kvm->slots_lock); | ||
244 | |||
243 | kvm->arch.iommu_domain = iommu_domain_alloc(&pci_bus_type); | 245 | kvm->arch.iommu_domain = iommu_domain_alloc(&pci_bus_type); |
244 | if (!kvm->arch.iommu_domain) | 246 | if (!kvm->arch.iommu_domain) { |
245 | return -ENOMEM; | 247 | r = -ENOMEM; |
248 | goto out_unlock; | ||
249 | } | ||
246 | 250 | ||
247 | if (!allow_unsafe_assigned_interrupts && | 251 | if (!allow_unsafe_assigned_interrupts && |
248 | !iommu_domain_has_cap(kvm->arch.iommu_domain, | 252 | !iommu_domain_has_cap(kvm->arch.iommu_domain, |
@@ -253,17 +257,16 @@ int kvm_iommu_map_guest(struct kvm *kvm) | |||
253 | " module option.\n", __func__); | 257 | " module option.\n", __func__); |
254 | iommu_domain_free(kvm->arch.iommu_domain); | 258 | iommu_domain_free(kvm->arch.iommu_domain); |
255 | kvm->arch.iommu_domain = NULL; | 259 | kvm->arch.iommu_domain = NULL; |
256 | return -EPERM; | 260 | r = -EPERM; |
261 | goto out_unlock; | ||
257 | } | 262 | } |
258 | 263 | ||
259 | r = kvm_iommu_map_memslots(kvm); | 264 | r = kvm_iommu_map_memslots(kvm); |
260 | if (r) | 265 | if (r) |
261 | goto out_unmap; | 266 | kvm_iommu_unmap_memslots(kvm); |
262 | |||
263 | return 0; | ||
264 | 267 | ||
265 | out_unmap: | 268 | out_unlock: |
266 | kvm_iommu_unmap_memslots(kvm); | 269 | mutex_unlock(&kvm->slots_lock); |
267 | return r; | 270 | return r; |
268 | } | 271 | } |
269 | 272 | ||
@@ -310,6 +313,11 @@ static void kvm_iommu_put_pages(struct kvm *kvm, | |||
310 | } | 313 | } |
311 | } | 314 | } |
312 | 315 | ||
316 | void kvm_iommu_unmap_pages(struct kvm *kvm, struct kvm_memory_slot *slot) | ||
317 | { | ||
318 | kvm_iommu_put_pages(kvm, slot->base_gfn, slot->npages); | ||
319 | } | ||
320 | |||
313 | static int kvm_iommu_unmap_memslots(struct kvm *kvm) | 321 | static int kvm_iommu_unmap_memslots(struct kvm *kvm) |
314 | { | 322 | { |
315 | int idx; | 323 | int idx; |
@@ -320,7 +328,7 @@ static int kvm_iommu_unmap_memslots(struct kvm *kvm) | |||
320 | slots = kvm_memslots(kvm); | 328 | slots = kvm_memslots(kvm); |
321 | 329 | ||
322 | kvm_for_each_memslot(memslot, slots) | 330 | kvm_for_each_memslot(memslot, slots) |
323 | kvm_iommu_put_pages(kvm, memslot->base_gfn, memslot->npages); | 331 | kvm_iommu_unmap_pages(kvm, memslot); |
324 | 332 | ||
325 | srcu_read_unlock(&kvm->srcu, idx); | 333 | srcu_read_unlock(&kvm->srcu, idx); |
326 | 334 | ||
@@ -335,7 +343,11 @@ int kvm_iommu_unmap_guest(struct kvm *kvm) | |||
335 | if (!domain) | 343 | if (!domain) |
336 | return 0; | 344 | return 0; |
337 | 345 | ||
346 | mutex_lock(&kvm->slots_lock); | ||
338 | kvm_iommu_unmap_memslots(kvm); | 347 | kvm_iommu_unmap_memslots(kvm); |
348 | kvm->arch.iommu_domain = NULL; | ||
349 | mutex_unlock(&kvm->slots_lock); | ||
350 | |||
339 | iommu_domain_free(domain); | 351 | iommu_domain_free(domain); |
340 | return 0; | 352 | return 0; |
341 | } | 353 | } |
diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c index 42b73930a6de..9739b533ca2e 100644 --- a/virt/kvm/kvm_main.c +++ b/virt/kvm/kvm_main.c | |||
@@ -808,12 +808,13 @@ int __kvm_set_memory_region(struct kvm *kvm, | |||
808 | if (r) | 808 | if (r) |
809 | goto out_free; | 809 | goto out_free; |
810 | 810 | ||
811 | /* map the pages in iommu page table */ | 811 | /* map/unmap the pages in iommu page table */ |
812 | if (npages) { | 812 | if (npages) { |
813 | r = kvm_iommu_map_pages(kvm, &new); | 813 | r = kvm_iommu_map_pages(kvm, &new); |
814 | if (r) | 814 | if (r) |
815 | goto out_free; | 815 | goto out_free; |
816 | } | 816 | } else |
817 | kvm_iommu_unmap_pages(kvm, &old); | ||
817 | 818 | ||
818 | r = -ENOMEM; | 819 | r = -ENOMEM; |
819 | slots = kmemdup(kvm->memslots, sizeof(struct kvm_memslots), | 820 | slots = kmemdup(kvm->memslots, sizeof(struct kvm_memslots), |