diff options
author | Xiao Guangrong <xiaoguangrong@linux.vnet.ibm.com> | 2011-11-24 04:38:24 -0500 |
---|---|---|
committer | Avi Kivity <avi@redhat.com> | 2011-12-27 04:17:35 -0500 |
commit | be593d6286075801bba6d60fa466a39c24cc7616 (patch) | |
tree | 7d2b156d7a9fa19700cb7ac5327a15093114905a /virt/kvm | |
parent | 93a5cef07d686a0341d056b0f930a762c7174a13 (diff) |
KVM: introduce update_memslots function
Introduce update_memslots to update slot which will be update to
kvm->memslots
Signed-off-by: Xiao Guangrong <xiaoguangrong@linux.vnet.ibm.com>
Signed-off-by: Avi Kivity <avi@redhat.com>
Diffstat (limited to 'virt/kvm')
-rw-r--r-- | virt/kvm/kvm_main.c | 22 |
1 files changed, 15 insertions, 7 deletions
diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c index 9ad94c9996e7..b5ed7770ced3 100644 --- a/virt/kvm/kvm_main.c +++ b/virt/kvm/kvm_main.c | |||
@@ -630,6 +630,19 @@ static int kvm_create_dirty_bitmap(struct kvm_memory_slot *memslot) | |||
630 | } | 630 | } |
631 | #endif /* !CONFIG_S390 */ | 631 | #endif /* !CONFIG_S390 */ |
632 | 632 | ||
633 | void update_memslots(struct kvm_memslots *slots, struct kvm_memory_slot *new) | ||
634 | { | ||
635 | if (new) { | ||
636 | int id = new->id; | ||
637 | |||
638 | slots->memslots[id] = *new; | ||
639 | if (id >= slots->nmemslots) | ||
640 | slots->nmemslots = id + 1; | ||
641 | } | ||
642 | |||
643 | slots->generation++; | ||
644 | } | ||
645 | |||
633 | /* | 646 | /* |
634 | * Allocate some memory and give it an address in the guest physical address | 647 | * Allocate some memory and give it an address in the guest physical address |
635 | * space. | 648 | * space. |
@@ -780,10 +793,8 @@ skip_lpage: | |||
780 | GFP_KERNEL); | 793 | GFP_KERNEL); |
781 | if (!slots) | 794 | if (!slots) |
782 | goto out_free; | 795 | goto out_free; |
783 | if (mem->slot >= slots->nmemslots) | ||
784 | slots->nmemslots = mem->slot + 1; | ||
785 | slots->generation++; | ||
786 | slots->memslots[mem->slot].flags |= KVM_MEMSLOT_INVALID; | 796 | slots->memslots[mem->slot].flags |= KVM_MEMSLOT_INVALID; |
797 | update_memslots(slots, NULL); | ||
787 | 798 | ||
788 | old_memslots = kvm->memslots; | 799 | old_memslots = kvm->memslots; |
789 | rcu_assign_pointer(kvm->memslots, slots); | 800 | rcu_assign_pointer(kvm->memslots, slots); |
@@ -815,9 +826,6 @@ skip_lpage: | |||
815 | GFP_KERNEL); | 826 | GFP_KERNEL); |
816 | if (!slots) | 827 | if (!slots) |
817 | goto out_free; | 828 | goto out_free; |
818 | if (mem->slot >= slots->nmemslots) | ||
819 | slots->nmemslots = mem->slot + 1; | ||
820 | slots->generation++; | ||
821 | 829 | ||
822 | /* actual memory is freed via old in kvm_free_physmem_slot below */ | 830 | /* actual memory is freed via old in kvm_free_physmem_slot below */ |
823 | if (!npages) { | 831 | if (!npages) { |
@@ -827,7 +835,7 @@ skip_lpage: | |||
827 | new.lpage_info[i] = NULL; | 835 | new.lpage_info[i] = NULL; |
828 | } | 836 | } |
829 | 837 | ||
830 | slots->memslots[mem->slot] = new; | 838 | update_memslots(slots, &new); |
831 | old_memslots = kvm->memslots; | 839 | old_memslots = kvm->memslots; |
832 | rcu_assign_pointer(kvm->memslots, slots); | 840 | rcu_assign_pointer(kvm->memslots, slots); |
833 | synchronize_srcu_expedited(&kvm->srcu); | 841 | synchronize_srcu_expedited(&kvm->srcu); |