aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTakuya Yoshikawa <yoshikawa.takuya@oss.ntt.co.jp>2012-02-07 23:01:09 -0500
committerAvi Kivity <avi@redhat.com>2012-03-08 07:10:21 -0500
commit189a2f7b24677deced3d2a9803969ba69f4b75f6 (patch)
treef39aabbaf24bfea65bbf77e215abac829fcb54d6
parenta64f273a08d16bc66ccc5546bd28b1bba554ec81 (diff)
KVM: Simplify ifndef conditional usage in __kvm_set_memory_region()
Narrow down the controlled text inside the conditional so that it will include lpage_info and rmap stuff only. For this we change the way we check whether the slot is being created from "if (npages && !new.rmap)" to "if (npages && !old.npages)". We also stop checking if lpage_info is NULL when we create lpage_info because we do it from inside the slot creation code block. Signed-off-by: Takuya Yoshikawa <yoshikawa.takuya@oss.ntt.co.jp> Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com> Signed-off-by: Avi Kivity <avi@redhat.com>
-rw-r--r--virt/kvm/kvm_main.c29
1 files changed, 8 insertions, 21 deletions
diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
index 7adaa2063415..a30447c5eb4a 100644
--- a/virt/kvm/kvm_main.c
+++ b/virt/kvm/kvm_main.c
@@ -616,7 +616,6 @@ static int kvm_vm_release(struct inode *inode, struct file *filp)
616 return 0; 616 return 0;
617} 617}
618 618
619#ifndef CONFIG_S390
620/* 619/*
621 * Allocation size is twice as large as the actual dirty bitmap size. 620 * Allocation size is twice as large as the actual dirty bitmap size.
622 * This makes it possible to do double buffering: see x86's 621 * This makes it possible to do double buffering: see x86's
@@ -624,6 +623,7 @@ static int kvm_vm_release(struct inode *inode, struct file *filp)
624 */ 623 */
625static int kvm_create_dirty_bitmap(struct kvm_memory_slot *memslot) 624static int kvm_create_dirty_bitmap(struct kvm_memory_slot *memslot)
626{ 625{
626#ifndef CONFIG_S390
627 unsigned long dirty_bytes = 2 * kvm_dirty_bitmap_bytes(memslot); 627 unsigned long dirty_bytes = 2 * kvm_dirty_bitmap_bytes(memslot);
628 628
629 if (dirty_bytes > PAGE_SIZE) 629 if (dirty_bytes > PAGE_SIZE)
@@ -636,9 +636,9 @@ static int kvm_create_dirty_bitmap(struct kvm_memory_slot *memslot)
636 636
637 memslot->dirty_bitmap_head = memslot->dirty_bitmap; 637 memslot->dirty_bitmap_head = memslot->dirty_bitmap;
638 memslot->nr_dirty_pages = 0; 638 memslot->nr_dirty_pages = 0;
639#endif /* !CONFIG_S390 */
639 return 0; 640 return 0;
640} 641}
641#endif /* !CONFIG_S390 */
642 642
643static int cmp_memslot(const void *slot1, const void *slot2) 643static int cmp_memslot(const void *slot1, const void *slot2)
644{ 644{
@@ -695,9 +695,6 @@ static int create_lpage_info(struct kvm_memory_slot *slot, unsigned long npages)
695 int lpages; 695 int lpages;
696 int level = i + 2; 696 int level = i + 2;
697 697
698 if (slot->lpage_info[i])
699 continue;
700
701 lpages = gfn_to_index(slot->base_gfn + npages - 1, 698 lpages = gfn_to_index(slot->base_gfn + npages - 1,
702 slot->base_gfn, level) + 1; 699 slot->base_gfn, level) + 1;
703 700
@@ -815,23 +812,18 @@ int __kvm_set_memory_region(struct kvm *kvm,
815 r = -ENOMEM; 812 r = -ENOMEM;
816 813
817 /* Allocate if a slot is being created */ 814 /* Allocate if a slot is being created */
815 if (npages && !old.npages) {
816 new.user_alloc = user_alloc;
817 new.userspace_addr = mem->userspace_addr;
818#ifndef CONFIG_S390 818#ifndef CONFIG_S390
819 if (npages && !new.rmap) {
820 new.rmap = vzalloc(npages * sizeof(*new.rmap)); 819 new.rmap = vzalloc(npages * sizeof(*new.rmap));
821
822 if (!new.rmap) 820 if (!new.rmap)
823 goto out_free; 821 goto out_free;
824 822
825 new.user_alloc = user_alloc; 823 if (create_lpage_info(&new, npages))
826 new.userspace_addr = mem->userspace_addr; 824 goto out_free;
825#endif /* not defined CONFIG_S390 */
827 } 826 }
828 if (!npages)
829 goto skip_lpage;
830
831 if (create_lpage_info(&new, npages))
832 goto out_free;
833
834skip_lpage:
835 827
836 /* Allocate page dirty bitmap if needed */ 828 /* Allocate page dirty bitmap if needed */
837 if ((new.flags & KVM_MEM_LOG_DIRTY_PAGES) && !new.dirty_bitmap) { 829 if ((new.flags & KVM_MEM_LOG_DIRTY_PAGES) && !new.dirty_bitmap) {
@@ -839,11 +831,6 @@ skip_lpage:
839 goto out_free; 831 goto out_free;
840 /* destroy any largepage mappings for dirty tracking */ 832 /* destroy any largepage mappings for dirty tracking */
841 } 833 }
842#else /* not defined CONFIG_S390 */
843 new.user_alloc = user_alloc;
844 if (user_alloc)
845 new.userspace_addr = mem->userspace_addr;
846#endif /* not defined CONFIG_S390 */
847 834
848 if (!npages) { 835 if (!npages) {
849 struct kvm_memory_slot *slot; 836 struct kvm_memory_slot *slot;