From: Sheng Yang <sheng@linux.intel.com>
To: Avi Kivity <avi@redhat.com>
Cc: Marcelo Tosatti <mtosatti@redhat.com>,
Alex Williamson <alex.williamson@hp.com>,
kvm@vger.kernel.org, Sheng Yang <sheng@linux.intel.com>
Subject: [PATCH 1/1] KVM: Fix potentially recursively get kvm lock
Date: Tue, 12 May 2009 17:32:09 +0800 [thread overview]
Message-ID: <1242120729-2280-1-git-send-email-sheng@linux.intel.com> (raw)
In-Reply-To: <200905121705.53176.sheng.yang@intel.com>
kvm_vm_ioctl_deassign_dev_irq() would potentially recursively get kvm->lock,
because it called kvm_deassigned_irq() which implicit hold kvm->lock by calling
deassign_host_irq().
Fix it by move kvm_deassign_irq() out of critial region. And add the missing
lock for deassign_guest_irq().
Reported-by: Alex Williamson <alex.williamson@hp.com>
Signed-off-by: Sheng Yang <sheng@linux.intel.com>
---
virt/kvm/kvm_main.c | 14 +++++++-------
1 files changed, 7 insertions(+), 7 deletions(-)
diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
index 4d00942..3c69655 100644
--- a/virt/kvm/kvm_main.c
+++ b/virt/kvm/kvm_main.c
@@ -215,6 +215,8 @@ static void kvm_assigned_dev_ack_irq(struct kvm_irq_ack_notifier *kian)
static void deassign_guest_irq(struct kvm *kvm,
struct kvm_assigned_dev_kernel *assigned_dev)
{
+ mutex_lock(&kvm->lock);
+
kvm_unregister_irq_ack_notifier(&assigned_dev->ack_notifier);
assigned_dev->ack_notifier.gsi = -1;
@@ -222,6 +224,8 @@ static void deassign_guest_irq(struct kvm *kvm,
kvm_free_irq_source_id(kvm, assigned_dev->irq_source_id);
assigned_dev->irq_source_id = -1;
assigned_dev->irq_requested_type &= ~(KVM_DEV_IRQ_GUEST_MASK);
+
+ mutex_unlock(&kvm->lock);
}
/* The function implicit hold kvm->lock mutex due to cancel_work_sync() */
@@ -558,20 +562,16 @@ static int kvm_vm_ioctl_deassign_dev_irq(struct kvm *kvm,
struct kvm_assigned_irq
*assigned_irq)
{
- int r = -ENODEV;
struct kvm_assigned_dev_kernel *match;
mutex_lock(&kvm->lock);
-
match = kvm_find_assigned_dev(&kvm->arch.assigned_dev_head,
assigned_irq->assigned_dev_id);
+ mutex_unlock(&kvm->lock);
if (!match)
- goto out;
+ return -ENODEV;
- r = kvm_deassign_irq(kvm, match, assigned_irq->flags);
-out:
- mutex_unlock(&kvm->lock);
- return r;
+ return kvm_deassign_irq(kvm, match, assigned_irq->flags);
}
static int kvm_vm_ioctl_assign_device(struct kvm *kvm,
--
1.5.4.5
next prev parent reply other threads:[~2009-05-12 9:31 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-05-12 9:05 device-assignment deadlock Yang, Sheng
2009-05-12 9:32 ` Sheng Yang [this message]
2009-05-12 11:55 ` [PATCH 1/1] KVM: Fix potentially recursively get kvm lock Marcelo Tosatti
2009-05-12 14:13 ` Yang, Sheng
2009-05-12 14:30 ` Marcelo Tosatti
2009-05-12 15:59 ` Marcelo Tosatti
2009-05-12 19:44 ` Marcelo Tosatti
2009-05-12 21:36 ` Alex Williamson
2009-05-12 22:09 ` Marcelo Tosatti
2009-05-12 22:17 ` Alex Williamson
2009-05-22 15:06 ` Chris Wright
2009-05-22 15:34 ` Alex Williamson
2009-05-22 15:36 ` Chris Wright
2009-05-13 2:07 ` Yang, Sheng
2009-05-13 13:14 ` Marcelo Tosatti
2009-05-13 11:43 ` Gleb Natapov
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1242120729-2280-1-git-send-email-sheng@linux.intel.com \
--to=sheng@linux.intel.com \
--cc=alex.williamson@hp.com \
--cc=avi@redhat.com \
--cc=kvm@vger.kernel.org \
--cc=mtosatti@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.