From patchwork Tue Dec 15 02:28:07 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sheng Yang X-Patchwork-Id: 67445 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter.kernel.org (8.14.2/8.14.2) with ESMTP id nBF2SM68002851 for ; Tue, 15 Dec 2009 02:28:22 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1758881AbZLOC2U (ORCPT ); Mon, 14 Dec 2009 21:28:20 -0500 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1758884AbZLOC2U (ORCPT ); Mon, 14 Dec 2009 21:28:20 -0500 Received: from mga09.intel.com ([134.134.136.24]:59835 "EHLO mga09.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1758619AbZLOC2S (ORCPT ); Mon, 14 Dec 2009 21:28:18 -0500 Received: from orsmga002.jf.intel.com ([10.7.209.21]) by orsmga102.jf.intel.com with ESMTP; 14 Dec 2009 18:27:19 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="4.47,398,1257148800"; d="scan'208";a="476103588" Received: from syang10-desktop.sh.intel.com (HELO syang10-desktop) ([10.239.36.76]) by orsmga002.jf.intel.com with ESMTP; 14 Dec 2009 18:28:04 -0800 Received: from yasker by syang10-desktop with local (Exim 4.69) (envelope-from ) id 1NKN96-0001Qx-5P; Tue, 15 Dec 2009 10:28:16 +0800 From: Sheng Yang To: Marcelo Tosatti Cc: Avi Kivity , kvm@vger.kernel.org, Sheng Yang Subject: [PATCH] KVM: Fix possible circular locking in kvm_vm_ioctl_assign_device() Date: Tue, 15 Dec 2009 10:28:07 +0800 Message-Id: <1260844087-5485-1-git-send-email-sheng@linux.intel.com> X-Mailer: git-send-email 1.6.3.3 In-Reply-To: <20091214191233.GA6065@amt.cnet> References: <20091214191233.GA6065@amt.cnet> Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org diff --git a/virt/kvm/assigned-dev.c b/virt/kvm/assigned-dev.c index fd9c097..f73de63 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, 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); @@ -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); @@ -585,8 +585,8 @@ out_put: pci_dev_put(dev); out_free: kfree(match); - mutex_unlock(&kvm->lock); up_read(&kvm->slots_lock); + mutex_unlock(&kvm->lock); return r; } diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c index f92ba13..91b84c9 100644 --- a/virt/kvm/kvm_main.c +++ b/virt/kvm/kvm_main.c @@ -63,7 +63,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);