diff options
author | Xiao Guangrong <xiaoguangrong@linux.vnet.ibm.com> | 2011-11-24 04:39:18 -0500 |
---|---|---|
committer | Avi Kivity <avi@redhat.com> | 2011-12-27 04:17:37 -0500 |
commit | be6ba0f0962a39091c52eb9167ddea201fe80716 (patch) | |
tree | 52e46aad8cce4857def4dc03fc75955677027054 /arch | |
parent | be593d6286075801bba6d60fa466a39c24cc7616 (diff) |
KVM: introduce kvm_for_each_memslot macro
Introduce kvm_for_each_memslot to walk all valid memslot
Signed-off-by: Xiao Guangrong <xiaoguangrong@linux.vnet.ibm.com>
Signed-off-by: Avi Kivity <avi@redhat.com>
Diffstat (limited to 'arch')
-rw-r--r-- | arch/ia64/kvm/kvm-ia64.c | 6 | ||||
-rw-r--r-- | arch/x86/kvm/mmu.c | 12 |
2 files changed, 8 insertions, 10 deletions
diff --git a/arch/ia64/kvm/kvm-ia64.c b/arch/ia64/kvm/kvm-ia64.c index 43f4c92816ef..42ad1f9c9f01 100644 --- a/arch/ia64/kvm/kvm-ia64.c +++ b/arch/ia64/kvm/kvm-ia64.c | |||
@@ -1366,14 +1366,12 @@ static void kvm_release_vm_pages(struct kvm *kvm) | |||
1366 | { | 1366 | { |
1367 | struct kvm_memslots *slots; | 1367 | struct kvm_memslots *slots; |
1368 | struct kvm_memory_slot *memslot; | 1368 | struct kvm_memory_slot *memslot; |
1369 | int i, j; | 1369 | int j; |
1370 | unsigned long base_gfn; | 1370 | unsigned long base_gfn; |
1371 | 1371 | ||
1372 | slots = kvm_memslots(kvm); | 1372 | slots = kvm_memslots(kvm); |
1373 | for (i = 0; i < slots->nmemslots; i++) { | 1373 | kvm_for_each_memslot(memslot, slots) { |
1374 | memslot = &slots->memslots[i]; | ||
1375 | base_gfn = memslot->base_gfn; | 1374 | base_gfn = memslot->base_gfn; |
1376 | |||
1377 | for (j = 0; j < memslot->npages; j++) { | 1375 | for (j = 0; j < memslot->npages; j++) { |
1378 | if (memslot->rmap[j]) | 1376 | if (memslot->rmap[j]) |
1379 | put_page((struct page *)memslot->rmap[j]); | 1377 | put_page((struct page *)memslot->rmap[j]); |
diff --git a/arch/x86/kvm/mmu.c b/arch/x86/kvm/mmu.c index 715dcb4fb798..d737443cdfdb 100644 --- a/arch/x86/kvm/mmu.c +++ b/arch/x86/kvm/mmu.c | |||
@@ -1128,15 +1128,15 @@ static int kvm_handle_hva(struct kvm *kvm, unsigned long hva, | |||
1128 | int (*handler)(struct kvm *kvm, unsigned long *rmapp, | 1128 | int (*handler)(struct kvm *kvm, unsigned long *rmapp, |
1129 | unsigned long data)) | 1129 | unsigned long data)) |
1130 | { | 1130 | { |
1131 | int i, j; | 1131 | int j; |
1132 | int ret; | 1132 | int ret; |
1133 | int retval = 0; | 1133 | int retval = 0; |
1134 | struct kvm_memslots *slots; | 1134 | struct kvm_memslots *slots; |
1135 | struct kvm_memory_slot *memslot; | ||
1135 | 1136 | ||
1136 | slots = kvm_memslots(kvm); | 1137 | slots = kvm_memslots(kvm); |
1137 | 1138 | ||
1138 | for (i = 0; i < slots->nmemslots; i++) { | 1139 | kvm_for_each_memslot(memslot, slots) { |
1139 | struct kvm_memory_slot *memslot = &slots->memslots[i]; | ||
1140 | unsigned long start = memslot->userspace_addr; | 1140 | unsigned long start = memslot->userspace_addr; |
1141 | unsigned long end; | 1141 | unsigned long end; |
1142 | 1142 | ||
@@ -3985,15 +3985,15 @@ nomem: | |||
3985 | */ | 3985 | */ |
3986 | unsigned int kvm_mmu_calculate_mmu_pages(struct kvm *kvm) | 3986 | unsigned int kvm_mmu_calculate_mmu_pages(struct kvm *kvm) |
3987 | { | 3987 | { |
3988 | int i; | ||
3989 | unsigned int nr_mmu_pages; | 3988 | unsigned int nr_mmu_pages; |
3990 | unsigned int nr_pages = 0; | 3989 | unsigned int nr_pages = 0; |
3991 | struct kvm_memslots *slots; | 3990 | struct kvm_memslots *slots; |
3991 | struct kvm_memory_slot *memslot; | ||
3992 | 3992 | ||
3993 | slots = kvm_memslots(kvm); | 3993 | slots = kvm_memslots(kvm); |
3994 | 3994 | ||
3995 | for (i = 0; i < slots->nmemslots; i++) | 3995 | kvm_for_each_memslot(memslot, slots) |
3996 | nr_pages += slots->memslots[i].npages; | 3996 | nr_pages += memslot->npages; |
3997 | 3997 | ||
3998 | nr_mmu_pages = nr_pages * KVM_PERMILLE_MMU_PAGES / 1000; | 3998 | nr_mmu_pages = nr_pages * KVM_PERMILLE_MMU_PAGES / 1000; |
3999 | nr_mmu_pages = max(nr_mmu_pages, | 3999 | nr_mmu_pages = max(nr_mmu_pages, |