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/kvm/iommu.c | |
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/kvm/iommu.c')
-rw-r--r-- | virt/kvm/iommu.c | 17 |
1 files changed, 9 insertions, 8 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; |