Skip to content

Commit

Permalink
KVM: Fix possible circular locking in kvm_vm_ioctl_assign_device()
Browse files Browse the repository at this point in the history
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: Sheng Yang <sheng@linux.intel.com>
Signed-off-by: Avi Kivity <avi@redhat.com>
  • Loading branch information
Sheng Yang authored and matosatti committed Dec 27, 2009
1 parent fb341f5 commit fae3a35
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
6 changes: 3 additions & 3 deletions virt/kvm/assigned-dev.c
Original file line number Diff line number Diff line change
Expand Up @@ -508,8 +508,8 @@ static int kvm_vm_ioctl_assign_device(struct kvm *kvm,
struct kvm_assigned_dev_kernel *match;
struct pci_dev *dev;

down_read(&kvm->slots_lock);
mutex_lock(&kvm->lock);
down_read(&kvm->slots_lock);

match = kvm_find_assigned_dev(&kvm->arch.assigned_dev_head,
assigned_dev->assigned_dev_id);
Expand Down Expand Up @@ -573,8 +573,8 @@ static int kvm_vm_ioctl_assign_device(struct kvm *kvm,
}

out:
mutex_unlock(&kvm->lock);
up_read(&kvm->slots_lock);
mutex_unlock(&kvm->lock);
return r;
out_list_del:
list_del(&match->list);
Expand All @@ -585,8 +585,8 @@ static int kvm_vm_ioctl_assign_device(struct kvm *kvm,
pci_dev_put(dev);
out_free:
kfree(match);
mutex_unlock(&kvm->lock);
up_read(&kvm->slots_lock);
mutex_unlock(&kvm->lock);
return r;
}

Expand Down
2 changes: 1 addition & 1 deletion virt/kvm/kvm_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ MODULE_LICENSE("GPL");
/*
* Ordering of locks:
*
* kvm->slots_lock --> kvm->lock --> kvm->irq_lock
* kvm->lock --> kvm->slots_lock --> kvm->irq_lock
*/

DEFINE_SPINLOCK(kvm_lock);
Expand Down

0 comments on commit fae3a35

Please sign in to comment.