aboutsummaryrefslogtreecommitdiffstats
path: root/virt
diff options
context:
space:
mode:
authorMarcelo Tosatti <mtosatti@redhat.com>2012-04-19 16:06:26 -0400
committerMarcelo Tosatti <mtosatti@redhat.com>2012-04-19 16:06:26 -0400
commiteac0556750e727ff39144a9a9e59d5ccf1fc0e2a (patch)
treef5ccff7795b2ad5e47f17fb475599c526f533e79 /virt
parentf71fa31f9f7ac33cba12b8897983f950ad2c7a5b (diff)
parent19853301ef3289bda2d5264c1093e74efddaeab9 (diff)
Merge branch 'linus' into queue
Merge reason: development work has dependency on kvm patches merged upstream. Conflicts: Documentation/feature-removal-schedule.txt Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
Diffstat (limited to 'virt')
-rw-r--r--virt/kvm/iommu.c30
-rw-r--r--virt/kvm/kvm_main.c5
2 files changed, 24 insertions, 11 deletions
diff --git a/virt/kvm/iommu.c b/virt/kvm/iommu.c
index a457d2138f49..e9fff9830bf0 100644
--- a/virt/kvm/iommu.c
+++ b/virt/kvm/iommu.c
@@ -240,9 +240,13 @@ int kvm_iommu_map_guest(struct kvm *kvm)
240 return -ENODEV; 240 return -ENODEV;
241 } 241 }
242 242
243 mutex_lock(&kvm->slots_lock);
244
243 kvm->arch.iommu_domain = iommu_domain_alloc(&pci_bus_type); 245 kvm->arch.iommu_domain = iommu_domain_alloc(&pci_bus_type);
244 if (!kvm->arch.iommu_domain) 246 if (!kvm->arch.iommu_domain) {
245 return -ENOMEM; 247 r = -ENOMEM;
248 goto out_unlock;
249 }
246 250
247 if (!allow_unsafe_assigned_interrupts && 251 if (!allow_unsafe_assigned_interrupts &&
248 !iommu_domain_has_cap(kvm->arch.iommu_domain, 252 !iommu_domain_has_cap(kvm->arch.iommu_domain,
@@ -253,17 +257,16 @@ int kvm_iommu_map_guest(struct kvm *kvm)
253 " module option.\n", __func__); 257 " module option.\n", __func__);
254 iommu_domain_free(kvm->arch.iommu_domain); 258 iommu_domain_free(kvm->arch.iommu_domain);
255 kvm->arch.iommu_domain = NULL; 259 kvm->arch.iommu_domain = NULL;
256 return -EPERM; 260 r = -EPERM;
261 goto out_unlock;
257 } 262 }
258 263
259 r = kvm_iommu_map_memslots(kvm); 264 r = kvm_iommu_map_memslots(kvm);
260 if (r) 265 if (r)
261 goto out_unmap; 266 kvm_iommu_unmap_memslots(kvm);
262
263 return 0;
264 267
265out_unmap: 268out_unlock:
266 kvm_iommu_unmap_memslots(kvm); 269 mutex_unlock(&kvm->slots_lock);
267 return r; 270 return r;
268} 271}
269 272
@@ -310,6 +313,11 @@ static void kvm_iommu_put_pages(struct kvm *kvm,
310 } 313 }
311} 314}
312 315
316void kvm_iommu_unmap_pages(struct kvm *kvm, struct kvm_memory_slot *slot)
317{
318 kvm_iommu_put_pages(kvm, slot->base_gfn, slot->npages);
319}
320
313static int kvm_iommu_unmap_memslots(struct kvm *kvm) 321static int kvm_iommu_unmap_memslots(struct kvm *kvm)
314{ 322{
315 int idx; 323 int idx;
@@ -320,7 +328,7 @@ static int kvm_iommu_unmap_memslots(struct kvm *kvm)
320 slots = kvm_memslots(kvm); 328 slots = kvm_memslots(kvm);
321 329
322 kvm_for_each_memslot(memslot, slots) 330 kvm_for_each_memslot(memslot, slots)
323 kvm_iommu_put_pages(kvm, memslot->base_gfn, memslot->npages); 331 kvm_iommu_unmap_pages(kvm, memslot);
324 332
325 srcu_read_unlock(&kvm->srcu, idx); 333 srcu_read_unlock(&kvm->srcu, idx);
326 334
@@ -335,7 +343,11 @@ int kvm_iommu_unmap_guest(struct kvm *kvm)
335 if (!domain) 343 if (!domain)
336 return 0; 344 return 0;
337 345
346 mutex_lock(&kvm->slots_lock);
338 kvm_iommu_unmap_memslots(kvm); 347 kvm_iommu_unmap_memslots(kvm);
348 kvm->arch.iommu_domain = NULL;
349 mutex_unlock(&kvm->slots_lock);
350
339 iommu_domain_free(domain); 351 iommu_domain_free(domain);
340 return 0; 352 return 0;
341} 353}
diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
index 6bd34a6ecca1..9eb7936e491d 100644
--- a/virt/kvm/kvm_main.c
+++ b/virt/kvm/kvm_main.c
@@ -804,12 +804,13 @@ int __kvm_set_memory_region(struct kvm *kvm,
804 if (r) 804 if (r)
805 goto out_free; 805 goto out_free;
806 806
807 /* map the pages in iommu page table */ 807 /* map/unmap the pages in iommu page table */
808 if (npages) { 808 if (npages) {
809 r = kvm_iommu_map_pages(kvm, &new); 809 r = kvm_iommu_map_pages(kvm, &new);
810 if (r) 810 if (r)
811 goto out_free; 811 goto out_free;
812 } 812 } else
813 kvm_iommu_unmap_pages(kvm, &old);
813 814
814 r = -ENOMEM; 815 r = -ENOMEM;
815 slots = kmemdup(kvm->memslots, sizeof(struct kvm_memslots), 816 slots = kmemdup(kvm->memslots, sizeof(struct kvm_memslots),