diff options
author | Sheng Yang <sheng@linux.intel.com> | 2009-12-14 21:28:07 -0500 |
---|---|---|
committer | Marcelo Tosatti <mtosatti@redhat.com> | 2009-12-27 10:36:31 -0500 |
commit | fae3a3536a6fecedebd49fa847f810e599bfb132 (patch) | |
tree | 18b555c3f6bcc6735fd7a90db2c398a35e29c84e | |
parent | fb341f572d26e0786167cd96b90cc4febed830cf (diff) |
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: Sheng Yang <sheng@linux.intel.com>
Signed-off-by: Avi Kivity <avi@redhat.com>
-rw-r--r-- | virt/kvm/assigned-dev.c | 6 | ||||
-rw-r--r-- | virt/kvm/kvm_main.c | 2 |
2 files changed, 4 insertions, 4 deletions
diff --git a/virt/kvm/assigned-dev.c b/virt/kvm/assigned-dev.c index fd9c097b760a..f73de631e3ee 100644 --- a/virt/kvm/assigned-dev.c +++ b/virt/kvm/assigned-dev.c | |||
@@ -508,8 +508,8 @@ static int kvm_vm_ioctl_assign_device(struct kvm *kvm, | |||
508 | struct kvm_assigned_dev_kernel *match; | 508 | struct kvm_assigned_dev_kernel *match; |
509 | struct pci_dev *dev; | 509 | struct pci_dev *dev; |
510 | 510 | ||
511 | down_read(&kvm->slots_lock); | ||
512 | mutex_lock(&kvm->lock); | 511 | mutex_lock(&kvm->lock); |
512 | down_read(&kvm->slots_lock); | ||
513 | 513 | ||
514 | match = kvm_find_assigned_dev(&kvm->arch.assigned_dev_head, | 514 | match = kvm_find_assigned_dev(&kvm->arch.assigned_dev_head, |
515 | assigned_dev->assigned_dev_id); | 515 | assigned_dev->assigned_dev_id); |
@@ -573,8 +573,8 @@ static int kvm_vm_ioctl_assign_device(struct kvm *kvm, | |||
573 | } | 573 | } |
574 | 574 | ||
575 | out: | 575 | out: |
576 | mutex_unlock(&kvm->lock); | ||
577 | up_read(&kvm->slots_lock); | 576 | up_read(&kvm->slots_lock); |
577 | mutex_unlock(&kvm->lock); | ||
578 | return r; | 578 | return r; |
579 | out_list_del: | 579 | out_list_del: |
580 | list_del(&match->list); | 580 | list_del(&match->list); |
@@ -585,8 +585,8 @@ out_put: | |||
585 | pci_dev_put(dev); | 585 | pci_dev_put(dev); |
586 | out_free: | 586 | out_free: |
587 | kfree(match); | 587 | kfree(match); |
588 | mutex_unlock(&kvm->lock); | ||
589 | up_read(&kvm->slots_lock); | 588 | up_read(&kvm->slots_lock); |
589 | mutex_unlock(&kvm->lock); | ||
590 | return r; | 590 | return r; |
591 | } | 591 | } |
592 | 592 | ||
diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c index b5af88167613..7db071ba466c 100644 --- a/virt/kvm/kvm_main.c +++ b/virt/kvm/kvm_main.c | |||
@@ -64,7 +64,7 @@ MODULE_LICENSE("GPL"); | |||
64 | /* | 64 | /* |
65 | * Ordering of locks: | 65 | * Ordering of locks: |
66 | * | 66 | * |
67 | * kvm->slots_lock --> kvm->lock --> kvm->irq_lock | 67 | * kvm->lock --> kvm->slots_lock --> kvm->irq_lock |
68 | */ | 68 | */ |
69 | 69 | ||
70 | DEFINE_SPINLOCK(kvm_lock); | 70 | DEFINE_SPINLOCK(kvm_lock); |