Commit 682edb4c authored by Mark McLoughlin's avatar Mark McLoughlin Committed by Avi Kivity

KVM: Fix assigned devices circular locking dependency

kvm->slots_lock is outer to kvm->lock, so take slots_lock
in kvm_vm_ioctl_assign_device() before taking kvm->lock,
rather than taking it in kvm_iommu_map_memslots().

Cc: stable@kernel.org
Signed-off-by: default avatarMark McLoughlin <markmc@redhat.com>
Acked-by: default avatarMarcelo Tosatti <mtosatti@redhat.com>
Signed-off-by: default avatarAvi Kivity <avi@redhat.com>
parent b682b814
...@@ -73,14 +73,13 @@ static int kvm_iommu_map_memslots(struct kvm *kvm) ...@@ -73,14 +73,13 @@ static int kvm_iommu_map_memslots(struct kvm *kvm)
{ {
int i, r = 0; int i, r = 0;
down_read(&kvm->slots_lock);
for (i = 0; i < kvm->nmemslots; i++) { for (i = 0; i < kvm->nmemslots; i++) {
r = kvm_iommu_map_pages(kvm, kvm->memslots[i].base_gfn, r = kvm_iommu_map_pages(kvm, kvm->memslots[i].base_gfn,
kvm->memslots[i].npages); kvm->memslots[i].npages);
if (r) if (r)
break; break;
} }
up_read(&kvm->slots_lock);
return r; return r;
} }
...@@ -190,12 +189,11 @@ static void kvm_iommu_put_pages(struct kvm *kvm, ...@@ -190,12 +189,11 @@ static void kvm_iommu_put_pages(struct kvm *kvm,
static int kvm_iommu_unmap_memslots(struct kvm *kvm) static int kvm_iommu_unmap_memslots(struct kvm *kvm)
{ {
int i; int i;
down_read(&kvm->slots_lock);
for (i = 0; i < kvm->nmemslots; i++) { for (i = 0; i < kvm->nmemslots; i++) {
kvm_iommu_put_pages(kvm, kvm->memslots[i].base_gfn, kvm_iommu_put_pages(kvm, kvm->memslots[i].base_gfn,
kvm->memslots[i].npages); kvm->memslots[i].npages);
} }
up_read(&kvm->slots_lock);
return 0; return 0;
} }
......
...@@ -466,6 +466,7 @@ static int kvm_vm_ioctl_assign_device(struct kvm *kvm, ...@@ -466,6 +466,7 @@ static int kvm_vm_ioctl_assign_device(struct kvm *kvm,
struct kvm_assigned_dev_kernel *match; struct kvm_assigned_dev_kernel *match;
struct pci_dev *dev; struct pci_dev *dev;
down_read(&kvm->slots_lock);
mutex_lock(&kvm->lock); mutex_lock(&kvm->lock);
match = kvm_find_assigned_dev(&kvm->arch.assigned_dev_head, match = kvm_find_assigned_dev(&kvm->arch.assigned_dev_head,
...@@ -527,6 +528,7 @@ static int kvm_vm_ioctl_assign_device(struct kvm *kvm, ...@@ -527,6 +528,7 @@ static int kvm_vm_ioctl_assign_device(struct kvm *kvm,
out: out:
mutex_unlock(&kvm->lock); mutex_unlock(&kvm->lock);
up_read(&kvm->slots_lock);
return r; return r;
out_list_del: out_list_del:
list_del(&match->list); list_del(&match->list);
...@@ -538,6 +540,7 @@ static int kvm_vm_ioctl_assign_device(struct kvm *kvm, ...@@ -538,6 +540,7 @@ static int kvm_vm_ioctl_assign_device(struct kvm *kvm,
out_free: out_free:
kfree(match); kfree(match);
mutex_unlock(&kvm->lock); mutex_unlock(&kvm->lock);
up_read(&kvm->slots_lock);
return r; return r;
} }
#endif #endif
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment