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 /virt | |
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 'virt')
-rw-r--r-- | virt/kvm/iommu.c | 17 | ||||
-rw-r--r-- | virt/kvm/kvm_main.c | 14 |
2 files changed, 15 insertions, 16 deletions
diff --git a/virt/kvm/iommu.c b/virt/kvm/iommu.c index a195c07fa829..4e5f7b7f1d2b 100644 --- a/virt/kvm/iommu.c +++ b/virt/kvm/iommu.c | |||
@@ -134,14 +134,15 @@ unmap_pages: | |||
134 | 134 | ||
135 | static int kvm_iommu_map_memslots(struct kvm *kvm) | 135 | static int kvm_iommu_map_memslots(struct kvm *kvm) |
136 | { | 136 | { |
137 | int i, idx, r = 0; | 137 | int idx, r = 0; |
138 | struct kvm_memslots *slots; | 138 | struct kvm_memslots *slots; |
139 | struct kvm_memory_slot *memslot; | ||
139 | 140 | ||
140 | idx = srcu_read_lock(&kvm->srcu); | 141 | idx = srcu_read_lock(&kvm->srcu); |
141 | slots = kvm_memslots(kvm); | 142 | slots = kvm_memslots(kvm); |
142 | 143 | ||
143 | for (i = 0; i < slots->nmemslots; i++) { | 144 | kvm_for_each_memslot(memslot, slots) { |
144 | r = kvm_iommu_map_pages(kvm, &slots->memslots[i]); | 145 | r = kvm_iommu_map_pages(kvm, memslot); |
145 | if (r) | 146 | if (r) |
146 | break; | 147 | break; |
147 | } | 148 | } |
@@ -311,16 +312,16 @@ static void kvm_iommu_put_pages(struct kvm *kvm, | |||
311 | 312 | ||
312 | static int kvm_iommu_unmap_memslots(struct kvm *kvm) | 313 | static int kvm_iommu_unmap_memslots(struct kvm *kvm) |
313 | { | 314 | { |
314 | int i, idx; | 315 | int idx; |
315 | struct kvm_memslots *slots; | 316 | struct kvm_memslots *slots; |
317 | struct kvm_memory_slot *memslot; | ||
316 | 318 | ||
317 | idx = srcu_read_lock(&kvm->srcu); | 319 | idx = srcu_read_lock(&kvm->srcu); |
318 | slots = kvm_memslots(kvm); | 320 | slots = kvm_memslots(kvm); |
319 | 321 | ||
320 | for (i = 0; i < slots->nmemslots; i++) { | 322 | kvm_for_each_memslot(memslot, slots) |
321 | kvm_iommu_put_pages(kvm, slots->memslots[i].base_gfn, | 323 | kvm_iommu_put_pages(kvm, memslot->base_gfn, memslot->npages); |
322 | slots->memslots[i].npages); | 324 | |
323 | } | ||
324 | srcu_read_unlock(&kvm->srcu, idx); | 325 | srcu_read_unlock(&kvm->srcu, idx); |
325 | 326 | ||
326 | return 0; | 327 | return 0; |
diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c index b5ed7770ced3..4c2900c5d81d 100644 --- a/virt/kvm/kvm_main.c +++ b/virt/kvm/kvm_main.c | |||
@@ -547,11 +547,11 @@ static void kvm_free_physmem_slot(struct kvm_memory_slot *free, | |||
547 | 547 | ||
548 | void kvm_free_physmem(struct kvm *kvm) | 548 | void kvm_free_physmem(struct kvm *kvm) |
549 | { | 549 | { |
550 | int i; | ||
551 | struct kvm_memslots *slots = kvm->memslots; | 550 | struct kvm_memslots *slots = kvm->memslots; |
551 | struct kvm_memory_slot *memslot; | ||
552 | 552 | ||
553 | for (i = 0; i < slots->nmemslots; ++i) | 553 | kvm_for_each_memslot(memslot, slots) |
554 | kvm_free_physmem_slot(&slots->memslots[i], NULL); | 554 | kvm_free_physmem_slot(memslot, NULL); |
555 | 555 | ||
556 | kfree(kvm->memslots); | 556 | kfree(kvm->memslots); |
557 | } | 557 | } |
@@ -975,15 +975,13 @@ EXPORT_SYMBOL_GPL(kvm_is_error_hva); | |||
975 | static struct kvm_memory_slot *__gfn_to_memslot(struct kvm_memslots *slots, | 975 | static struct kvm_memory_slot *__gfn_to_memslot(struct kvm_memslots *slots, |
976 | gfn_t gfn) | 976 | gfn_t gfn) |
977 | { | 977 | { |
978 | int i; | 978 | struct kvm_memory_slot *memslot; |
979 | |||
980 | for (i = 0; i < slots->nmemslots; ++i) { | ||
981 | struct kvm_memory_slot *memslot = &slots->memslots[i]; | ||
982 | 979 | ||
980 | kvm_for_each_memslot(memslot, slots) | ||
983 | if (gfn >= memslot->base_gfn | 981 | if (gfn >= memslot->base_gfn |
984 | && gfn < memslot->base_gfn + memslot->npages) | 982 | && gfn < memslot->base_gfn + memslot->npages) |
985 | return memslot; | 983 | return memslot; |
986 | } | 984 | |
987 | return NULL; | 985 | return NULL; |
988 | } | 986 | } |
989 | 987 | ||