From patchwork Tue May 12 09:32:09 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sheng Yang X-Patchwork-Id: 23193 Received: from vger.kernel.org (vger.kernel.org [209.132.176.167]) by demeter.kernel.org (8.14.2/8.14.2) with ESMTP id n4C9YBcN028419 for ; Tue, 12 May 2009 09:34:11 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932149AbZELJbc (ORCPT ); Tue, 12 May 2009 05:31:32 -0400 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S932143AbZELJbc (ORCPT ); Tue, 12 May 2009 05:31:32 -0400 Received: from mga03.intel.com ([143.182.124.21]:10580 "EHLO mga03.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932134AbZELJb1 (ORCPT ); Tue, 12 May 2009 05:31:27 -0400 Received: from azsmga001.ch.intel.com ([10.2.17.19]) by azsmga101.ch.intel.com with ESMTP; 12 May 2009 02:31:27 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="4.41,181,1241420400"; d="scan'208";a="141812062" Received: from syang10-desktop.sh.intel.com (HELO syang10-desktop) ([10.239.13.147]) by azsmga001.ch.intel.com with ESMTP; 12 May 2009 02:31:23 -0700 Received: from yasker by syang10-desktop with local (Exim 4.69) (envelope-from ) id 1M3oLJ-0000b9-LI; Tue, 12 May 2009 17:32:09 +0800 From: Sheng Yang To: Avi Kivity Cc: Marcelo Tosatti , Alex Williamson , kvm@vger.kernel.org, Sheng Yang Subject: [PATCH 1/1] KVM: Fix potentially recursively get kvm lock Date: Tue, 12 May 2009 17:32:09 +0800 Message-Id: <1242120729-2280-1-git-send-email-sheng@linux.intel.com> X-Mailer: git-send-email 1.6.0.4 In-Reply-To: <200905121705.53176.sheng.yang@intel.com> References: <200905121705.53176.sheng.yang@intel.com> Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org 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 Signed-off-by: Sheng Yang --- 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,