aboutsummaryrefslogtreecommitdiffstats
path: root/virt/kvm/kvm_main.c
diff options
context:
space:
mode:
authorMarcelo Tosatti <mtosatti@redhat.com>2009-12-23 11:35:16 -0500
committerMarcelo Tosatti <mtosatti@redhat.com>2010-03-01 10:35:43 -0500
commit46a26bf55714c1e2f17e34683292a389acb8e601 (patch)
tree3df70225ce6a076d7e4be604a5d72465383043ee /virt/kvm/kvm_main.c
parent2044892d4a005a78796c92fd1aef4633be896698 (diff)
KVM: modify memslots layout in struct kvm
Have a pointer to an allocated region inside struct kvm. [alex: fix ppc book 3s] Signed-off-by: Alexander Graf <agraf@suse.de> Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
Diffstat (limited to 'virt/kvm/kvm_main.c')
-rw-r--r--virt/kvm/kvm_main.c36
1 files changed, 23 insertions, 13 deletions
diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
index bc23b8e0609b..86dd8f3d29c9 100644
--- a/virt/kvm/kvm_main.c
+++ b/virt/kvm/kvm_main.c
@@ -375,12 +375,16 @@ static struct kvm *kvm_create_vm(void)
375 INIT_HLIST_HEAD(&kvm->irq_ack_notifier_list); 375 INIT_HLIST_HEAD(&kvm->irq_ack_notifier_list);
376#endif 376#endif
377 377
378 r = -ENOMEM;
379 kvm->memslots = kzalloc(sizeof(struct kvm_memslots), GFP_KERNEL);
380 if (!kvm->memslots)
381 goto out_err;
382
378#ifdef KVM_COALESCED_MMIO_PAGE_OFFSET 383#ifdef KVM_COALESCED_MMIO_PAGE_OFFSET
379 page = alloc_page(GFP_KERNEL | __GFP_ZERO); 384 page = alloc_page(GFP_KERNEL | __GFP_ZERO);
380 if (!page) { 385 if (!page)
381 r = -ENOMEM;
382 goto out_err; 386 goto out_err;
383 } 387
384 kvm->coalesced_mmio_ring = 388 kvm->coalesced_mmio_ring =
385 (struct kvm_coalesced_mmio_ring *)page_address(page); 389 (struct kvm_coalesced_mmio_ring *)page_address(page);
386#endif 390#endif
@@ -416,6 +420,7 @@ out:
416out_err: 420out_err:
417 hardware_disable_all(); 421 hardware_disable_all();
418out_err_nodisable: 422out_err_nodisable:
423 kfree(kvm->memslots);
419 kfree(kvm); 424 kfree(kvm);
420 return ERR_PTR(r); 425 return ERR_PTR(r);
421} 426}
@@ -450,9 +455,12 @@ static void kvm_free_physmem_slot(struct kvm_memory_slot *free,
450void kvm_free_physmem(struct kvm *kvm) 455void kvm_free_physmem(struct kvm *kvm)
451{ 456{
452 int i; 457 int i;
458 struct kvm_memslots *slots = kvm->memslots;
459
460 for (i = 0; i < slots->nmemslots; ++i)
461 kvm_free_physmem_slot(&slots->memslots[i], NULL);
453 462
454 for (i = 0; i < kvm->nmemslots; ++i) 463 kfree(kvm->memslots);
455 kvm_free_physmem_slot(&kvm->memslots[i], NULL);
456} 464}
457 465
458static void kvm_destroy_vm(struct kvm *kvm) 466static void kvm_destroy_vm(struct kvm *kvm)
@@ -533,7 +541,7 @@ int __kvm_set_memory_region(struct kvm *kvm,
533 if (mem->guest_phys_addr + mem->memory_size < mem->guest_phys_addr) 541 if (mem->guest_phys_addr + mem->memory_size < mem->guest_phys_addr)
534 goto out; 542 goto out;
535 543
536 memslot = &kvm->memslots[mem->slot]; 544 memslot = &kvm->memslots->memslots[mem->slot];
537 base_gfn = mem->guest_phys_addr >> PAGE_SHIFT; 545 base_gfn = mem->guest_phys_addr >> PAGE_SHIFT;
538 npages = mem->memory_size >> PAGE_SHIFT; 546 npages = mem->memory_size >> PAGE_SHIFT;
539 547
@@ -554,7 +562,7 @@ int __kvm_set_memory_region(struct kvm *kvm,
554 /* Check for overlaps */ 562 /* Check for overlaps */
555 r = -EEXIST; 563 r = -EEXIST;
556 for (i = 0; i < KVM_MEMORY_SLOTS; ++i) { 564 for (i = 0; i < KVM_MEMORY_SLOTS; ++i) {
557 struct kvm_memory_slot *s = &kvm->memslots[i]; 565 struct kvm_memory_slot *s = &kvm->memslots->memslots[i];
558 566
559 if (s == memslot || !s->npages) 567 if (s == memslot || !s->npages)
560 continue; 568 continue;
@@ -656,8 +664,8 @@ skip_lpage:
656 kvm_arch_flush_shadow(kvm); 664 kvm_arch_flush_shadow(kvm);
657 665
658 spin_lock(&kvm->mmu_lock); 666 spin_lock(&kvm->mmu_lock);
659 if (mem->slot >= kvm->nmemslots) 667 if (mem->slot >= kvm->memslots->nmemslots)
660 kvm->nmemslots = mem->slot + 1; 668 kvm->memslots->nmemslots = mem->slot + 1;
661 669
662 *memslot = new; 670 *memslot = new;
663 spin_unlock(&kvm->mmu_lock); 671 spin_unlock(&kvm->mmu_lock);
@@ -727,7 +735,7 @@ int kvm_get_dirty_log(struct kvm *kvm,
727 if (log->slot >= KVM_MEMORY_SLOTS) 735 if (log->slot >= KVM_MEMORY_SLOTS)
728 goto out; 736 goto out;
729 737
730 memslot = &kvm->memslots[log->slot]; 738 memslot = &kvm->memslots->memslots[log->slot];
731 r = -ENOENT; 739 r = -ENOENT;
732 if (!memslot->dirty_bitmap) 740 if (!memslot->dirty_bitmap)
733 goto out; 741 goto out;
@@ -781,9 +789,10 @@ EXPORT_SYMBOL_GPL(kvm_is_error_hva);
781struct kvm_memory_slot *gfn_to_memslot_unaliased(struct kvm *kvm, gfn_t gfn) 789struct kvm_memory_slot *gfn_to_memslot_unaliased(struct kvm *kvm, gfn_t gfn)
782{ 790{
783 int i; 791 int i;
792 struct kvm_memslots *slots = kvm->memslots;
784 793
785 for (i = 0; i < kvm->nmemslots; ++i) { 794 for (i = 0; i < slots->nmemslots; ++i) {
786 struct kvm_memory_slot *memslot = &kvm->memslots[i]; 795 struct kvm_memory_slot *memslot = &slots->memslots[i];
787 796
788 if (gfn >= memslot->base_gfn 797 if (gfn >= memslot->base_gfn
789 && gfn < memslot->base_gfn + memslot->npages) 798 && gfn < memslot->base_gfn + memslot->npages)
@@ -802,10 +811,11 @@ struct kvm_memory_slot *gfn_to_memslot(struct kvm *kvm, gfn_t gfn)
802int kvm_is_visible_gfn(struct kvm *kvm, gfn_t gfn) 811int kvm_is_visible_gfn(struct kvm *kvm, gfn_t gfn)
803{ 812{
804 int i; 813 int i;
814 struct kvm_memslots *slots = kvm->memslots;
805 815
806 gfn = unalias_gfn(kvm, gfn); 816 gfn = unalias_gfn(kvm, gfn);
807 for (i = 0; i < KVM_MEMORY_SLOTS; ++i) { 817 for (i = 0; i < KVM_MEMORY_SLOTS; ++i) {
808 struct kvm_memory_slot *memslot = &kvm->memslots[i]; 818 struct kvm_memory_slot *memslot = &slots->memslots[i];
809 819
810 if (gfn >= memslot->base_gfn 820 if (gfn >= memslot->base_gfn
811 && gfn < memslot->base_gfn + memslot->npages) 821 && gfn < memslot->base_gfn + memslot->npages)