From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from smtp4.osuosl.org (smtp4.osuosl.org [140.211.166.137]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 0BFE3C433F5 for ; Fri, 27 May 2022 06:34:18 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by smtp4.osuosl.org (Postfix) with ESMTP id AB270425C7; Fri, 27 May 2022 06:34:18 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from smtp4.osuosl.org ([127.0.0.1]) by localhost (smtp4.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id RGcritpCAjCq; Fri, 27 May 2022 06:34:17 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [140.211.9.56]) by smtp4.osuosl.org (Postfix) with ESMTPS id 5B56F4256D; Fri, 27 May 2022 06:34:17 +0000 (UTC) Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id 31532C0032; Fri, 27 May 2022 06:34:17 +0000 (UTC) Received: from smtp2.osuosl.org (smtp2.osuosl.org [140.211.166.133]) by lists.linuxfoundation.org (Postfix) with ESMTP id E9DF9C002D for ; Fri, 27 May 2022 06:34:15 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by smtp2.osuosl.org (Postfix) with ESMTP id E6155412E9 for ; Fri, 27 May 2022 06:34:15 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Authentication-Results: smtp2.osuosl.org (amavisd-new); dkim=pass (2048-bit key) header.d=intel.com Received: from smtp2.osuosl.org ([127.0.0.1]) by localhost (smtp2.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id GH0sZfCrL_vw for ; Fri, 27 May 2022 06:34:15 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.8.0 Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) by smtp2.osuosl.org (Postfix) with ESMTPS id 36536412E7 for ; Fri, 27 May 2022 06:34:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1653633255; x=1685169255; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=9f5hL9z5d19jdu/plR8UsfSukdVmRN5xbUanYDDkUoY=; b=BaB+QqQsrGTaNqDwCbUMdCklQyFalVmJrLetUZ0AAAppYgr6V9KNdZV6 4kcUDB7OmB8Qyjcxd3KQPLYUMFthmn+wrRDFi70tL3I5v5DfLlEac5ws+ gRohKClGGcsHPkME82FNbLSMpaQBDhTfk9QLs2IiIrlYB+vsLmCjtp/SU JCF/HIGxA7a7+A2KOLn1JyYFGWVprPdc35RJbNs21osiVa0KfHfwGwwSN MyEzC//aJTsc7uUks0tp0MGCVHMQyCLGBL8hQ1HytpmeEdkIfjgZl63vf OPDBsonUjQMMGsh+PQG3BEDBwuA6Io7qbcP73HQQ2dN2596YF1PODTQXW Q==; X-IronPort-AV: E=McAfee;i="6400,9594,10359"; a="274123286" X-IronPort-AV: E=Sophos;i="5.91,254,1647327600"; d="scan'208";a="274123286" Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by orsmga102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 26 May 2022 23:34:14 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.91,254,1647327600"; d="scan'208";a="718688485" Received: from allen-box.sh.intel.com ([10.239.159.48]) by fmsmga001.fm.intel.com with ESMTP; 26 May 2022 23:34:11 -0700 From: Lu Baolu To: Joerg Roedel , Kevin Tian , Ashok Raj , Christoph Hellwig , Jason Gunthorpe Subject: [PATCH 06/12] iommu/vt-d: Acquiring lock in domain ID allocation helpers Date: Fri, 27 May 2022 14:30:13 +0800 Message-Id: <20220527063019.3112905-7-baolu.lu@linux.intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220527063019.3112905-1-baolu.lu@linux.intel.com> References: <20220527063019.3112905-1-baolu.lu@linux.intel.com> MIME-Version: 1.0 Cc: Will Deacon , linux-kernel@vger.kernel.org, iommu@lists.linux-foundation.org, Jacob jun Pan , Robin Murphy X-BeenThere: iommu@lists.linux-foundation.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: Development issues for Linux IOMMU support List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: iommu-bounces@lists.linux-foundation.org Sender: "iommu" The iommu->lock is used to protect the per-IOMMU domain ID resource. Move the spinlock acquisition/release into the helpers where domain IDs are allocated and freed. The device_domain_lock is irrelevant to domain ID resources, remove its assertion as well. Signed-off-by: Lu Baolu --- drivers/iommu/intel/iommu.c | 25 +++++++++---------------- 1 file changed, 9 insertions(+), 16 deletions(-) diff --git a/drivers/iommu/intel/iommu.c b/drivers/iommu/intel/iommu.c index 2d5f02b85de8..0da937ce0534 100644 --- a/drivers/iommu/intel/iommu.c +++ b/drivers/iommu/intel/iommu.c @@ -1774,16 +1774,13 @@ static struct dmar_domain *alloc_domain(unsigned int type) return domain; } -/* Must be called with iommu->lock */ static int domain_attach_iommu(struct dmar_domain *domain, struct intel_iommu *iommu) { unsigned long ndomains; - int num; - - assert_spin_locked(&device_domain_lock); - assert_spin_locked(&iommu->lock); + int num, ret = 0; + spin_lock(&iommu->lock); domain->iommu_refcnt[iommu->seq_id] += 1; if (domain->iommu_refcnt[iommu->seq_id] == 1) { ndomains = cap_ndoms(iommu->cap); @@ -1792,7 +1789,8 @@ static int domain_attach_iommu(struct dmar_domain *domain, if (num >= ndomains) { pr_err("%s: No free domain ids\n", iommu->name); domain->iommu_refcnt[iommu->seq_id] -= 1; - return -ENOSPC; + ret = -ENOSPC; + goto out_unlock; } set_bit(num, iommu->domain_ids); @@ -1801,7 +1799,9 @@ static int domain_attach_iommu(struct dmar_domain *domain, domain_update_iommu_cap(domain); } - return 0; +out_unlock: + spin_unlock(&iommu->lock); + return ret; } static void domain_detach_iommu(struct dmar_domain *domain, @@ -1809,9 +1809,7 @@ static void domain_detach_iommu(struct dmar_domain *domain, { int num; - assert_spin_locked(&device_domain_lock); - assert_spin_locked(&iommu->lock); - + spin_lock(&iommu->lock); domain->iommu_refcnt[iommu->seq_id] -= 1; if (domain->iommu_refcnt[iommu->seq_id] == 0) { num = domain->iommu_did[iommu->seq_id]; @@ -1819,6 +1817,7 @@ static void domain_detach_iommu(struct dmar_domain *domain, domain_update_iommu_cap(domain); domain->iommu_did[iommu->seq_id] = 0; } + spin_unlock(&iommu->lock); } static inline int guestwidth_to_adjustwidth(int gaw) @@ -2471,9 +2470,7 @@ static int domain_add_dev_info(struct dmar_domain *domain, struct device *dev) spin_lock_irqsave(&device_domain_lock, flags); info->domain = domain; - spin_lock(&iommu->lock); ret = domain_attach_iommu(domain, iommu); - spin_unlock(&iommu->lock); if (ret) { spin_unlock_irqrestore(&device_domain_lock, flags); return ret; @@ -4158,7 +4155,6 @@ static void __dmar_remove_one_dev_info(struct device_domain_info *info) { struct dmar_domain *domain; struct intel_iommu *iommu; - unsigned long flags; assert_spin_locked(&device_domain_lock); @@ -4179,10 +4175,7 @@ static void __dmar_remove_one_dev_info(struct device_domain_info *info) } list_del(&info->link); - - spin_lock_irqsave(&iommu->lock, flags); domain_detach_iommu(domain, iommu); - spin_unlock_irqrestore(&iommu->lock, flags); } static void dmar_remove_one_dev_info(struct device *dev) -- 2.25.1 _______________________________________________ iommu mailing list iommu@lists.linux-foundation.org https://lists.linuxfoundation.org/mailman/listinfo/iommu