Commit fae3a353 authored by Sheng Yang's avatar Sheng Yang Committed by Marcelo Tosatti

KVM: Fix possible circular locking in kvm_vm_ioctl_assign_device()

One possible order is:

KVM_CREATE_IRQCHIP ioctl(took kvm->lock) -> kvm_iobus_register_dev() ->
down_write(kvm->slots_lock).

The other one is in kvm_vm_ioctl_assign_device(), which take kvm->slots_lock
first, then kvm->lock.

Update the comment of lock order as well.

Observe it due to kernel locking debug warnings.

Cc: stable@kernel.org
Signed-off-by: default avatarSheng Yang <sheng@linux.intel.com>
Signed-off-by: default avatarAvi Kivity <avi@redhat.com>
parent fb341f57
...@@ -508,8 +508,8 @@ static int kvm_vm_ioctl_assign_device(struct kvm *kvm, ...@@ -508,8 +508,8 @@ 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);
down_read(&kvm->slots_lock);
match = kvm_find_assigned_dev(&kvm->arch.assigned_dev_head, match = kvm_find_assigned_dev(&kvm->arch.assigned_dev_head,
assigned_dev->assigned_dev_id); assigned_dev->assigned_dev_id);
...@@ -573,8 +573,8 @@ static int kvm_vm_ioctl_assign_device(struct kvm *kvm, ...@@ -573,8 +573,8 @@ static int kvm_vm_ioctl_assign_device(struct kvm *kvm,
} }
out: out:
mutex_unlock(&kvm->lock);
up_read(&kvm->slots_lock); up_read(&kvm->slots_lock);
mutex_unlock(&kvm->lock);
return r; return r;
out_list_del: out_list_del:
list_del(&match->list); list_del(&match->list);
...@@ -585,8 +585,8 @@ static int kvm_vm_ioctl_assign_device(struct kvm *kvm, ...@@ -585,8 +585,8 @@ static int kvm_vm_ioctl_assign_device(struct kvm *kvm,
pci_dev_put(dev); pci_dev_put(dev);
out_free: out_free:
kfree(match); kfree(match);
mutex_unlock(&kvm->lock);
up_read(&kvm->slots_lock); up_read(&kvm->slots_lock);
mutex_unlock(&kvm->lock);
return r; return r;
} }
......
...@@ -64,7 +64,7 @@ MODULE_LICENSE("GPL"); ...@@ -64,7 +64,7 @@ MODULE_LICENSE("GPL");
/* /*
* Ordering of locks: * Ordering of locks:
* *
* kvm->slots_lock --> kvm->lock --> kvm->irq_lock * kvm->lock --> kvm->slots_lock --> kvm->irq_lock
*/ */
DEFINE_SPINLOCK(kvm_lock); DEFINE_SPINLOCK(kvm_lock);
......
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