From patchwork Wed Mar 9 13:17:34 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Quan Xu X-Patchwork-Id: 8546301 Return-Path: X-Original-To: patchwork-xen-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 01E58C0554 for ; Wed, 9 Mar 2016 13:22:39 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 2AC0D202A1 for ; Wed, 9 Mar 2016 13:22:38 +0000 (UTC) Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 4324220218 for ; Wed, 9 Mar 2016 13:22:36 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xen.org with esmtp (Exim 4.84) (envelope-from ) id 1ade1w-0006Ji-DH; Wed, 09 Mar 2016 13:20:00 +0000 Received: from mail6.bemta6.messagelabs.com ([85.158.143.247]) by lists.xen.org with esmtp (Exim 4.84) (envelope-from ) id 1ade1v-0006JK-17 for xen-devel@lists.xen.org; Wed, 09 Mar 2016 13:19:59 +0000 Received: from [85.158.143.35] by server-2.bemta-6.messagelabs.com id C5/7A-01728-EF220E65; Wed, 09 Mar 2016 13:19:58 +0000 X-Env-Sender: quan.xu@intel.com X-Msg-Ref: server-13.tower-21.messagelabs.com!1457529597!5113306!2 X-Originating-IP: [192.55.52.93] X-SpamReason: No, hits=0.0 required=7.0 tests=sa_preprocessor: VHJ1c3RlZCBJUDogMTkyLjU1LjUyLjkzID0+IDMyNDY2NQ==\n X-StarScan-Received: X-StarScan-Version: 8.11; banners=-,-,- X-VirusChecked: Checked Received: (qmail 4181 invoked from network); 9 Mar 2016 13:19:58 -0000 Received: from mga11.intel.com (HELO mga11.intel.com) (192.55.52.93) by server-13.tower-21.messagelabs.com with SMTP; 9 Mar 2016 13:19:58 -0000 Received: from orsmga003.jf.intel.com ([10.7.209.27]) by fmsmga102.fm.intel.com with ESMTP; 09 Mar 2016 05:19:55 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.24,311,1455004800"; d="scan'208";a="760923601" Received: from xen-commits.sh.intel.com ([10.239.82.178]) by orsmga003.jf.intel.com with ESMTP; 09 Mar 2016 05:19:54 -0800 From: Quan Xu To: xen-devel@lists.xen.org Date: Wed, 9 Mar 2016 21:17:34 +0800 Message-Id: <1457529455-38314-2-git-send-email-quan.xu@intel.com> X-Mailer: git-send-email 1.8.3.2 In-Reply-To: <1457529455-38314-1-git-send-email-quan.xu@intel.com> References: <1457529455-38314-1-git-send-email-quan.xu@intel.com> Cc: Dario Faggioli , Jan Beulich , Suravee Suthikulpanit , Quan Xu Subject: [Xen-devel] [PATCH v3 1/2] IOMMU/spinlock: Fix a bug found in AMD IOMMU initialization X-BeenThere: xen-devel@lists.xen.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: xen-devel-bounces@lists.xen.org Sender: "Xen-devel" X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP pcidevs_lock should be held with interrupt enabled. However there remains an exception in AMD IOMMU code, where the lock is acquired with interrupt disabled. This inconsistency might lead to deadlock. The fix is straightforward to use spin_lock instead. Also interrupt has been enabled when this function is invoked, so we're sure consistency around pcidevs_lock can be guaranteed after this fix. Signed-off-by: Quan Xu Reviewed-by: Dario Faggioli CC: Suravee Suthikulpanit CC: Dario Faggioli CC: Jan Beulich --- xen/drivers/passthrough/amd/iommu_init.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/xen/drivers/passthrough/amd/iommu_init.c b/xen/drivers/passthrough/amd/iommu_init.c index d90a2d2..a400497 100644 --- a/xen/drivers/passthrough/amd/iommu_init.c +++ b/xen/drivers/passthrough/amd/iommu_init.c @@ -778,7 +778,6 @@ static bool_t __init set_iommu_interrupt_handler(struct amd_iommu *iommu) { int irq, ret; hw_irq_controller *handler; - unsigned long flags; u16 control; irq = create_irq(NUMA_NO_NODE); @@ -788,10 +787,10 @@ static bool_t __init set_iommu_interrupt_handler(struct amd_iommu *iommu) return 0; } - spin_lock_irqsave(&pcidevs_lock, flags); + spin_lock(&pcidevs_lock); iommu->msi.dev = pci_get_pdev(iommu->seg, PCI_BUS(iommu->bdf), PCI_DEVFN2(iommu->bdf)); - spin_unlock_irqrestore(&pcidevs_lock, flags); + spin_unlock(&pcidevs_lock); if ( !iommu->msi.dev ) { AMD_IOMMU_DEBUG("IOMMU: no pdev for %04x:%02x:%02x.%u\n",