From nobody Sun Jun 28 05:29:38 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 694B5C433EF for ; Mon, 14 Feb 2022 02:58:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239315AbiBNC6q (ORCPT ); Sun, 13 Feb 2022 21:58:46 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:41016 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237462AbiBNC6o (ORCPT ); Sun, 13 Feb 2022 21:58:44 -0500 Received: from mga07.intel.com (mga07.intel.com [134.134.136.100]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9ADD250B17 for ; Sun, 13 Feb 2022 18:58:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1644807517; x=1676343517; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=MLEjABaPQRpMPylojsaUggRqEABq92P6LcGDfuqAl7Y=; b=PVOwouWk+CM4BPzM551G0XLNuJUEq60rF2z1ikz/5L2j0omCiSFKa/1m pQTxGn12A2wbIUqhRQZiY9Y29/NgAEB82ygHhpRmQv+2NcT3ZMcASc5ip jT+gU0pvohonmpFjTPDPuXjE4LRxEV4q4yp3UPCbgvuYkL2LsaUYBX/ua m1xXDZOiPLaC146vXLn4K8g6Wyi4RBEzShidDcRc20axp+4J019D6LJe3 5uTWrfaq4AJ9Gs4Xrv6LdqNcT5TSy0eU7NooIxOu0CCTlMTuop7cTWoOk JyF/+oqA6cwg0nu+wYJmmjRrw2eFdDZh0LRqCghz5nxPs3XX+Tj/33noF g==; X-IronPort-AV: E=McAfee;i="6200,9189,10257"; a="313280404" X-IronPort-AV: E=Sophos;i="5.88,366,1635231600"; d="scan'208";a="313280404" Received: from orsmga002.jf.intel.com ([10.7.209.21]) by orsmga105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Feb 2022 18:58:37 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.88,366,1635231600"; d="scan'208";a="501514901" Received: from allen-box.sh.intel.com ([10.239.159.118]) by orsmga002.jf.intel.com with ESMTP; 13 Feb 2022 18:58:34 -0800 From: Lu Baolu To: Joerg Roedel , Kevin Tian , Ashok Raj , Liu Yi L , Jacob Pan Cc: Robin Murphy , Jason Gunthorpe , Christoph Hellwig , iommu@lists.linux-foundation.org, linux-kernel@vger.kernel.org, Lu Baolu Subject: [PATCH v2 01/11] iommu/vt-d: Remove intel_iommu::domains Date: Mon, 14 Feb 2022 10:56:54 +0800 Message-Id: <20220214025704.3184654-2-baolu.lu@linux.intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220214025704.3184654-1-baolu.lu@linux.intel.com> References: <20220214025704.3184654-1-baolu.lu@linux.intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" The "domains" field of the intel_iommu structure keeps the mapping of domain_id to dmar_domain. This information is not used anywhere. Remove and cleanup it to avoid unnecessary memory consumption. Signed-off-by: Lu Baolu Reviewed-by: Christoph Hellwig Reviewed-by: Jason Gunthorpe --- include/linux/intel-iommu.h | 1 - drivers/iommu/intel/iommu.c | 68 ++----------------------------------- 2 files changed, 3 insertions(+), 66 deletions(-) diff --git a/include/linux/intel-iommu.h b/include/linux/intel-iommu.h index 5cfda90b2cca..8c7591b5f3e2 100644 --- a/include/linux/intel-iommu.h +++ b/include/linux/intel-iommu.h @@ -578,7 +578,6 @@ struct intel_iommu { =20 #ifdef CONFIG_INTEL_IOMMU unsigned long *domain_ids; /* bitmap of domains */ - struct dmar_domain ***domains; /* ptr to domains */ spinlock_t lock; /* protect context, domain ids */ struct root_entry *root_entry; /* virtual address */ =20 diff --git a/drivers/iommu/intel/iommu.c b/drivers/iommu/intel/iommu.c index b549172e88ef..e3b04d5d87b0 100644 --- a/drivers/iommu/intel/iommu.c +++ b/drivers/iommu/intel/iommu.c @@ -455,36 +455,6 @@ __setup("intel_iommu=3D", intel_iommu_setup); static struct kmem_cache *iommu_domain_cache; static struct kmem_cache *iommu_devinfo_cache; =20 -static struct dmar_domain* get_iommu_domain(struct intel_iommu *iommu, u16= did) -{ - struct dmar_domain **domains; - int idx =3D did >> 8; - - domains =3D iommu->domains[idx]; - if (!domains) - return NULL; - - return domains[did & 0xff]; -} - -static void set_iommu_domain(struct intel_iommu *iommu, u16 did, - struct dmar_domain *domain) -{ - struct dmar_domain **domains; - int idx =3D did >> 8; - - if (!iommu->domains[idx]) { - size_t size =3D 256 * sizeof(struct dmar_domain *); - iommu->domains[idx] =3D kzalloc(size, GFP_ATOMIC); - } - - domains =3D iommu->domains[idx]; - if (WARN_ON(!domains)) - return; - else - domains[did & 0xff] =3D domain; -} - void *alloc_pgtable_page(int node) { struct page *page; @@ -1751,8 +1721,7 @@ static void intel_flush_iotlb_all(struct iommu_domain= *domain) DMA_TLB_DSI_FLUSH); =20 if (!cap_caching_mode(iommu->cap)) - iommu_flush_dev_iotlb(get_iommu_domain(iommu, did), - 0, MAX_AGAW_PFN_WIDTH); + iommu_flush_dev_iotlb(dmar_domain, 0, MAX_AGAW_PFN_WIDTH); } } =20 @@ -1815,7 +1784,6 @@ static void iommu_disable_translation(struct intel_io= mmu *iommu) static int iommu_init_domains(struct intel_iommu *iommu) { u32 ndomains; - size_t size; =20 ndomains =3D cap_ndoms(iommu->cap); pr_debug("%s: Number of Domains supported <%d>\n", @@ -1827,24 +1795,6 @@ static int iommu_init_domains(struct intel_iommu *io= mmu) if (!iommu->domain_ids) return -ENOMEM; =20 - size =3D (ALIGN(ndomains, 256) >> 8) * sizeof(struct dmar_domain **); - iommu->domains =3D kzalloc(size, GFP_KERNEL); - - if (iommu->domains) { - size =3D 256 * sizeof(struct dmar_domain *); - iommu->domains[0] =3D kzalloc(size, GFP_KERNEL); - } - - if (!iommu->domains || !iommu->domains[0]) { - pr_err("%s: Allocating domain array failed\n", - iommu->name); - bitmap_free(iommu->domain_ids); - kfree(iommu->domains); - iommu->domain_ids =3D NULL; - iommu->domains =3D NULL; - return -ENOMEM; - } - /* * If Caching mode is set, then invalid translations are tagged * with domain-id 0, hence we need to pre-allocate it. We also @@ -1871,7 +1821,7 @@ static void disable_dmar_iommu(struct intel_iommu *io= mmu) struct device_domain_info *info, *tmp; unsigned long flags; =20 - if (!iommu->domains || !iommu->domain_ids) + if (!iommu->domain_ids) return; =20 spin_lock_irqsave(&device_domain_lock, flags); @@ -1892,15 +1842,8 @@ static void disable_dmar_iommu(struct intel_iommu *i= ommu) =20 static void free_dmar_iommu(struct intel_iommu *iommu) { - if ((iommu->domains) && (iommu->domain_ids)) { - int elems =3D ALIGN(cap_ndoms(iommu->cap), 256) >> 8; - int i; - - for (i =3D 0; i < elems; i++) - kfree(iommu->domains[i]); - kfree(iommu->domains); + if (iommu->domain_ids) { bitmap_free(iommu->domain_ids); - iommu->domains =3D NULL; iommu->domain_ids =3D NULL; } =20 @@ -1978,11 +1921,8 @@ static int domain_attach_iommu(struct dmar_domain *d= omain, } =20 set_bit(num, iommu->domain_ids); - set_iommu_domain(iommu, num, domain); - domain->iommu_did[iommu->seq_id] =3D num; domain->nid =3D iommu->node; - domain_update_iommu_cap(domain); } =20 @@ -2001,8 +1941,6 @@ static void domain_detach_iommu(struct dmar_domain *d= omain, if (domain->iommu_refcnt[iommu->seq_id] =3D=3D 0) { num =3D domain->iommu_did[iommu->seq_id]; clear_bit(num, iommu->domain_ids); - set_iommu_domain(iommu, num, NULL); - domain_update_iommu_cap(domain); domain->iommu_did[iommu->seq_id] =3D 0; } --=20 2.25.1 From nobody Sun Jun 28 05:29:38 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 43C08C433EF for ; Mon, 14 Feb 2022 02:58:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239345AbiBNC6v (ORCPT ); Sun, 13 Feb 2022 21:58:51 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:41100 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239320AbiBNC6r (ORCPT ); Sun, 13 Feb 2022 21:58:47 -0500 Received: from mga07.intel.com (mga07.intel.com [134.134.136.100]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E8FB950B31 for ; Sun, 13 Feb 2022 18:58:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1644807520; x=1676343520; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=0JZUGngNJYQNkQxgdzwA+7te07Ku/U9yElxaQVFZPW0=; b=VNQ/CNYoi/b8SKAUWyJM+UAIM3vSGndX1BDc0p6jVoX1Te6onr02UsoP vq21E7spmkQu0C7ulAzGKpgwtX45aicj6YwvzhUy8/eKsWVvyHZXdRT6A y1f/1yQD1/fWF3uhlWGTHRHegewdLZIKAUxksC2/AszmZ2ct9pnvnDIyV wDanMOBJ/6HuajU6nhGbGyCd4nK8vYA2e0bV5xDRkH1533hovIEP/n34R VQhWi7A2ZCCoaqFCygz7MWK2NTjhpue+d772c/0r4z62LA5qAVvcRxInl cMDxbJ9hUwFR81JZJ9ZV3CMHp0xtM8nk0vN3Eq6nzWJIZKkmBnvGzCFf8 g==; X-IronPort-AV: E=McAfee;i="6200,9189,10257"; a="313280408" X-IronPort-AV: E=Sophos;i="5.88,366,1635231600"; d="scan'208";a="313280408" Received: from orsmga002.jf.intel.com ([10.7.209.21]) by orsmga105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Feb 2022 18:58:40 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.88,366,1635231600"; d="scan'208";a="501514913" Received: from allen-box.sh.intel.com ([10.239.159.118]) by orsmga002.jf.intel.com with ESMTP; 13 Feb 2022 18:58:37 -0800 From: Lu Baolu To: Joerg Roedel , Kevin Tian , Ashok Raj , Liu Yi L , Jacob Pan Cc: Robin Murphy , Jason Gunthorpe , Christoph Hellwig , iommu@lists.linux-foundation.org, linux-kernel@vger.kernel.org, Lu Baolu Subject: [PATCH v2 02/11] iommu/vt-d: Remove finding domain in dmar_insert_one_dev_info() Date: Mon, 14 Feb 2022 10:56:55 +0800 Message-Id: <20220214025704.3184654-3-baolu.lu@linux.intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220214025704.3184654-1-baolu.lu@linux.intel.com> References: <20220214025704.3184654-1-baolu.lu@linux.intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" The Intel IOMMU driver has already converted to use default domain framework in iommu core. There's no need to find a domain for the device in the domain attaching path. Cleanup that code. Signed-off-by: Lu Baolu Reviewed-by: Christoph Hellwig Reviewed-by: Jason Gunthorpe --- drivers/iommu/intel/iommu.c | 21 --------------------- 1 file changed, 21 deletions(-) diff --git a/drivers/iommu/intel/iommu.c b/drivers/iommu/intel/iommu.c index e3b04d5d87b0..b3075933864e 100644 --- a/drivers/iommu/intel/iommu.c +++ b/drivers/iommu/intel/iommu.c @@ -2554,7 +2554,6 @@ static struct dmar_domain *dmar_insert_one_dev_info(s= truct intel_iommu *iommu, struct device *dev, struct dmar_domain *domain) { - struct dmar_domain *found =3D NULL; struct device_domain_info *info; unsigned long flags; int ret; @@ -2605,26 +2604,6 @@ static struct dmar_domain *dmar_insert_one_dev_info(= struct intel_iommu *iommu, } =20 spin_lock_irqsave(&device_domain_lock, flags); - if (dev) - found =3D find_domain(dev); - - if (!found) { - struct device_domain_info *info2; - info2 =3D dmar_search_domain_by_dev_info(info->segment, info->bus, - info->devfn); - if (info2) { - found =3D info2->domain; - info2->dev =3D dev; - } - } - - if (found) { - spin_unlock_irqrestore(&device_domain_lock, flags); - free_devinfo_mem(info); - /* Caller must free the original domain */ - return found; - } - spin_lock(&iommu->lock); ret =3D domain_attach_iommu(domain, iommu); spin_unlock(&iommu->lock); --=20 2.25.1 From nobody Sun Jun 28 05:29:38 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 434F2C433EF for ; Mon, 14 Feb 2022 02:58:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239582AbiBNC6x (ORCPT ); Sun, 13 Feb 2022 21:58:53 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:41170 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239334AbiBNC6u (ORCPT ); Sun, 13 Feb 2022 21:58:50 -0500 Received: from mga07.intel.com (mga07.intel.com [134.134.136.100]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DC49550E33 for ; Sun, 13 Feb 2022 18:58:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1644807523; x=1676343523; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=D5ftI+cDmr+pBNTj6lQtPsjYn4ZPXVQ/fQnAmIe2ry4=; b=MyYC/PqVxRcjlt1ztudxCZ2N/55EQSkkwIJ6ZEhnqFhCUWP74JV53u16 1flXXBUMwUwmIqNInxKwHo4eyCptSpwzbVY6e+SscQUG6OZ4Ae+xjlhXd uJV++668dF5aJKAIQhhvNc8pHzz4fEdk6V8c9OL2kX7cqnLJOT0sx9xWm 7cpfvY+9ymtcbnEtlNyfjWekchLkCiJBuQ+QxdUow9No5WQM7FcMafvl9 Yn1FWF2rlWdxFuERo8wpUHorkEdxKmvKQBK5JstAXefGSgL34NJ/XGY+O nIbSlt5es4RTUTL8mGCeiSi5MYsHf538/uH47El1wKNjuuYVyjSVJM8TM Q==; X-IronPort-AV: E=McAfee;i="6200,9189,10257"; a="313280412" X-IronPort-AV: E=Sophos;i="5.88,366,1635231600"; d="scan'208";a="313280412" Received: from orsmga002.jf.intel.com ([10.7.209.21]) by orsmga105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Feb 2022 18:58:43 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.88,366,1635231600"; d="scan'208";a="501514920" Received: from allen-box.sh.intel.com ([10.239.159.118]) by orsmga002.jf.intel.com with ESMTP; 13 Feb 2022 18:58:40 -0800 From: Lu Baolu To: Joerg Roedel , Kevin Tian , Ashok Raj , Liu Yi L , Jacob Pan Cc: Robin Murphy , Jason Gunthorpe , Christoph Hellwig , iommu@lists.linux-foundation.org, linux-kernel@vger.kernel.org, Lu Baolu Subject: [PATCH v2 03/11] iommu/vt-d: Remove iova_cache_get/put() Date: Mon, 14 Feb 2022 10:56:56 +0800 Message-Id: <20220214025704.3184654-4-baolu.lu@linux.intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220214025704.3184654-1-baolu.lu@linux.intel.com> References: <20220214025704.3184654-1-baolu.lu@linux.intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" These have been done in drivers/iommu/dma-iommu.c. Remove this duplicate code. Signed-off-by: Lu Baolu Reviewed-by: Christoph Hellwig Reviewed-by: Jason Gunthorpe --- drivers/iommu/intel/iommu.c | 5 ----- 1 file changed, 5 deletions(-) diff --git a/drivers/iommu/intel/iommu.c b/drivers/iommu/intel/iommu.c index b3075933864e..7c2b427bea3b 100644 --- a/drivers/iommu/intel/iommu.c +++ b/drivers/iommu/intel/iommu.c @@ -3381,9 +3381,6 @@ static inline int iommu_devinfo_cache_init(void) static int __init iommu_init_mempool(void) { int ret; - ret =3D iova_cache_get(); - if (ret) - return ret; =20 ret =3D iommu_domain_cache_init(); if (ret) @@ -3395,7 +3392,6 @@ static int __init iommu_init_mempool(void) =20 kmem_cache_destroy(iommu_domain_cache); domain_error: - iova_cache_put(); =20 return -ENOMEM; } @@ -3404,7 +3400,6 @@ static void __init iommu_exit_mempool(void) { kmem_cache_destroy(iommu_devinfo_cache); kmem_cache_destroy(iommu_domain_cache); - iova_cache_put(); } =20 static void __init init_no_remapping_devices(void) --=20 2.25.1 From nobody Sun Jun 28 05:29:38 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id EBC58C433F5 for ; Mon, 14 Feb 2022 02:58:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239683AbiBNC65 (ORCPT ); Sun, 13 Feb 2022 21:58:57 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:41274 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239580AbiBNC6x (ORCPT ); Sun, 13 Feb 2022 21:58:53 -0500 Received: from mga07.intel.com (mga07.intel.com [134.134.136.100]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A6EFF50E02 for ; Sun, 13 Feb 2022 18:58:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1644807526; x=1676343526; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=QdYhx9EO4AI/TCmCtlewK7xJRADcHuvAfbD9DIvtaeM=; b=G7z5sAY1p60znGdGivYfTS9rBdCBbnqOlXVKWYAMnykLGbWCoZBpU1qe m6/sWx/iZ+sStBzFnZFrLER7zhzPOoREM96zlZLx9C7rdrm05VOenueE/ IDIpZK0t2ylvB4QSjGiBBW/1yHekWXVaa14NyxgjgXzD0H8gtuz3PAs2R 78siVy/dtiuH66Ef1io97ndBEDeRtE8lG8Prg0iyFM7YOVWTX9cqMlBqX eePeSemOIOwxFUbfp36k6p5/exu8Ti3P9SAx7vbwia78kChjP7085Ke/c MVd3GSCfqa2uRzun0yZEcjtr/K/rwy7A1Y1+2ouclOSwxbO00ntxjzOOr g==; X-IronPort-AV: E=McAfee;i="6200,9189,10257"; a="313280418" X-IronPort-AV: E=Sophos;i="5.88,366,1635231600"; d="scan'208";a="313280418" Received: from orsmga002.jf.intel.com ([10.7.209.21]) by orsmga105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Feb 2022 18:58:46 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.88,366,1635231600"; d="scan'208";a="501514930" Received: from allen-box.sh.intel.com ([10.239.159.118]) by orsmga002.jf.intel.com with ESMTP; 13 Feb 2022 18:58:43 -0800 From: Lu Baolu To: Joerg Roedel , Kevin Tian , Ashok Raj , Liu Yi L , Jacob Pan Cc: Robin Murphy , Jason Gunthorpe , Christoph Hellwig , iommu@lists.linux-foundation.org, linux-kernel@vger.kernel.org, Lu Baolu Subject: [PATCH v2 04/11] iommu/vt-d: Remove domain and devinfo mempool Date: Mon, 14 Feb 2022 10:56:57 +0800 Message-Id: <20220214025704.3184654-5-baolu.lu@linux.intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220214025704.3184654-1-baolu.lu@linux.intel.com> References: <20220214025704.3184654-1-baolu.lu@linux.intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" The domain and devinfo memory blocks are only allocated during device probe and released during remove. There's no hot-path context, hence no need for memory pools. Signed-off-by: Lu Baolu Reviewed-by: Christoph Hellwig Reviewed-by: Jason Gunthorpe --- drivers/iommu/intel/iommu.c | 104 ++---------------------------------- 1 file changed, 5 insertions(+), 99 deletions(-) diff --git a/drivers/iommu/intel/iommu.c b/drivers/iommu/intel/iommu.c index 7c2b427bea3b..51db26d8606c 100644 --- a/drivers/iommu/intel/iommu.c +++ b/drivers/iommu/intel/iommu.c @@ -452,9 +452,6 @@ static int __init intel_iommu_setup(char *str) } __setup("intel_iommu=3D", intel_iommu_setup); =20 -static struct kmem_cache *iommu_domain_cache; -static struct kmem_cache *iommu_devinfo_cache; - void *alloc_pgtable_page(int node) { struct page *page; @@ -471,26 +468,6 @@ void free_pgtable_page(void *vaddr) free_page((unsigned long)vaddr); } =20 -static inline void *alloc_domain_mem(void) -{ - return kmem_cache_alloc(iommu_domain_cache, GFP_ATOMIC); -} - -static void free_domain_mem(void *vaddr) -{ - kmem_cache_free(iommu_domain_cache, vaddr); -} - -static inline void * alloc_devinfo_mem(void) -{ - return kmem_cache_alloc(iommu_devinfo_cache, GFP_ATOMIC); -} - -static inline void free_devinfo_mem(void *vaddr) -{ - kmem_cache_free(iommu_devinfo_cache, vaddr); -} - static inline int domain_type_is_si(struct dmar_domain *domain) { return domain->domain.type =3D=3D IOMMU_DOMAIN_IDENTITY; @@ -1885,11 +1862,10 @@ static struct dmar_domain *alloc_domain(unsigned in= t type) { struct dmar_domain *domain; =20 - domain =3D alloc_domain_mem(); + domain =3D kzalloc(sizeof(*domain), GFP_KERNEL); if (!domain) return NULL; =20 - memset(domain, 0, sizeof(*domain)); domain->nid =3D NUMA_NO_NODE; if (first_level_by_default(type)) domain->flags |=3D DOMAIN_FLAG_USE_FIRST_LEVEL; @@ -1973,7 +1949,7 @@ static void domain_exit(struct dmar_domain *domain) put_pages_list(&freelist); } =20 - free_domain_mem(domain); + kfree(domain); } =20 /* @@ -2558,7 +2534,7 @@ static struct dmar_domain *dmar_insert_one_dev_info(s= truct intel_iommu *iommu, unsigned long flags; int ret; =20 - info =3D alloc_devinfo_mem(); + info =3D kzalloc(sizeof(*info), GFP_KERNEL); if (!info) return NULL; =20 @@ -2574,13 +2550,9 @@ static struct dmar_domain *dmar_insert_one_dev_info(= struct intel_iommu *iommu, info->segment =3D pci_domain_nr(pdev->bus); } =20 - info->ats_supported =3D info->pasid_supported =3D info->pri_supported =3D= 0; - info->ats_enabled =3D info->pasid_enabled =3D info->pri_enabled =3D 0; - info->ats_qdep =3D 0; info->dev =3D dev; info->domain =3D domain; info->iommu =3D iommu; - info->pasid_table =3D NULL; =20 if (dev && dev_is_pci(dev)) { struct pci_dev *pdev =3D to_pci_dev(info->dev); @@ -2610,7 +2582,7 @@ static struct dmar_domain *dmar_insert_one_dev_info(s= truct intel_iommu *iommu, =20 if (ret) { spin_unlock_irqrestore(&device_domain_lock, flags); - free_devinfo_mem(info); + kfree(info); return NULL; } =20 @@ -3343,65 +3315,6 @@ static int __init init_dmars(void) return ret; } =20 -static inline int iommu_domain_cache_init(void) -{ - int ret =3D 0; - - iommu_domain_cache =3D kmem_cache_create("iommu_domain", - sizeof(struct dmar_domain), - 0, - SLAB_HWCACHE_ALIGN, - - NULL); - if (!iommu_domain_cache) { - pr_err("Couldn't create iommu_domain cache\n"); - ret =3D -ENOMEM; - } - - return ret; -} - -static inline int iommu_devinfo_cache_init(void) -{ - int ret =3D 0; - - iommu_devinfo_cache =3D kmem_cache_create("iommu_devinfo", - sizeof(struct device_domain_info), - 0, - SLAB_HWCACHE_ALIGN, - NULL); - if (!iommu_devinfo_cache) { - pr_err("Couldn't create devinfo cache\n"); - ret =3D -ENOMEM; - } - - return ret; -} - -static int __init iommu_init_mempool(void) -{ - int ret; - - ret =3D iommu_domain_cache_init(); - if (ret) - goto domain_error; - - ret =3D iommu_devinfo_cache_init(); - if (!ret) - return ret; - - kmem_cache_destroy(iommu_domain_cache); -domain_error: - - return -ENOMEM; -} - -static void __init iommu_exit_mempool(void) -{ - kmem_cache_destroy(iommu_devinfo_cache); - kmem_cache_destroy(iommu_domain_cache); -} - static void __init init_no_remapping_devices(void) { struct dmar_drhd_unit *drhd; @@ -4253,12 +4166,6 @@ int __init intel_iommu_init(void) force_on =3D (!intel_iommu_tboot_noforce && tboot_force_iommu()) || platform_optin_force_iommu(); =20 - if (iommu_init_mempool()) { - if (force_on) - panic("tboot: Failed to initialize iommu memory\n"); - return -ENOMEM; - } - down_write(&dmar_global_lock); if (dmar_table_init()) { if (force_on) @@ -4379,7 +4286,6 @@ int __init intel_iommu_init(void) out_free_dmar: intel_iommu_free_dmars(); up_write(&dmar_global_lock); - iommu_exit_mempool(); return ret; } =20 @@ -4436,7 +4342,7 @@ static void __dmar_remove_one_dev_info(struct device_= domain_info *info) domain_detach_iommu(domain, iommu); spin_unlock_irqrestore(&iommu->lock, flags); =20 - free_devinfo_mem(info); + kfree(info); } =20 static void dmar_remove_one_dev_info(struct device *dev) --=20 2.25.1 From nobody Sun Jun 28 05:29:38 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0701DC433EF for ; Mon, 14 Feb 2022 02:58:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239724AbiBNC67 (ORCPT ); Sun, 13 Feb 2022 21:58:59 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:41368 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239596AbiBNC65 (ORCPT ); Sun, 13 Feb 2022 21:58:57 -0500 Received: from mga07.intel.com (mga07.intel.com [134.134.136.100]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D1B7E50E0C for ; Sun, 13 Feb 2022 18:58:49 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1644807529; x=1676343529; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=O9wbnZuHJK7j3rXRk0f0lAKkJ/IVVT5PxoMM23cEeS0=; b=IuzFrkgFaOxfDke2ax4G7x4BtVxGWsD2aOAMvOSrVk5ONQ+1T7eVLSe5 U7NJIy+KoIhFLl69n4BUz8r5su9WJbWgvnCU4J3YthUxdS0jn5wDHsi3Y ovc9EDQEvMnBMpZp/OYppRSriSTKScWNhHOmFMECBnhKWdzUIC8OQ6Kxe UFaOtzrk9o5BWK0iYWKNjUjo8hAamPoaUcFS/v7LXmdSFB5K+b/mvNrhQ x8VSbf1WHcA3PN6EODzx/VLfaaWPVwgtLOZY+hS1a76DcFfvNKAM1t6ua yNF8jW850Ae1+JtiksLkRGip5En8RNRvhTMMxsGgddo8/J970I/fqmKLy Q==; X-IronPort-AV: E=McAfee;i="6200,9189,10257"; a="313280421" X-IronPort-AV: E=Sophos;i="5.88,366,1635231600"; d="scan'208";a="313280421" Received: from orsmga002.jf.intel.com ([10.7.209.21]) by orsmga105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Feb 2022 18:58:49 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.88,366,1635231600"; d="scan'208";a="501514973" Received: from allen-box.sh.intel.com ([10.239.159.118]) by orsmga002.jf.intel.com with ESMTP; 13 Feb 2022 18:58:46 -0800 From: Lu Baolu To: Joerg Roedel , Kevin Tian , Ashok Raj , Liu Yi L , Jacob Pan Cc: Robin Murphy , Jason Gunthorpe , Christoph Hellwig , iommu@lists.linux-foundation.org, linux-kernel@vger.kernel.org, Lu Baolu Subject: [PATCH v2 05/11] iommu/vt-d: Remove DEFER_DEVICE_DOMAIN_INFO Date: Mon, 14 Feb 2022 10:56:58 +0800 Message-Id: <20220214025704.3184654-6-baolu.lu@linux.intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220214025704.3184654-1-baolu.lu@linux.intel.com> References: <20220214025704.3184654-1-baolu.lu@linux.intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Allocate and set the per-device iommu private data during iommu device probe. This makes the per-device iommu private data always available during iommu_probe_device() and iommu_release_device(). With this changed, the dummy DEFER_DEVICE_DOMAIN_INFO pointer could be removed. The wrappers for getting the private data and domain are also cleaned. Signed-off-by: Lu Baolu Reviewed-by: Christoph Hellwig Reviewed-by: Jason Gunthorpe --- include/linux/intel-iommu.h | 2 - drivers/iommu/intel/debugfs.c | 3 +- drivers/iommu/intel/iommu.c | 186 +++++++++++++--------------------- drivers/iommu/intel/pasid.c | 12 +-- drivers/iommu/intel/svm.c | 6 +- 5 files changed, 79 insertions(+), 130 deletions(-) diff --git a/include/linux/intel-iommu.h b/include/linux/intel-iommu.h index 8c7591b5f3e2..03f1134fc2fe 100644 --- a/include/linux/intel-iommu.h +++ b/include/linux/intel-iommu.h @@ -733,8 +733,6 @@ int for_each_device_domain(int (*fn)(struct device_doma= in_info *info, void *data), void *data); void iommu_flush_write_buffer(struct intel_iommu *iommu); int intel_iommu_enable_pasid(struct intel_iommu *iommu, struct device *dev= ); -struct dmar_domain *find_domain(struct device *dev); -struct device_domain_info *get_domain_info(struct device *dev); struct intel_iommu *device_to_iommu(struct device *dev, u8 *bus, u8 *devfn= ); =20 #ifdef CONFIG_INTEL_IOMMU_SVM diff --git a/drivers/iommu/intel/debugfs.c b/drivers/iommu/intel/debugfs.c index db7a0ca73626..ed796eea4581 100644 --- a/drivers/iommu/intel/debugfs.c +++ b/drivers/iommu/intel/debugfs.c @@ -344,7 +344,8 @@ static void pgtable_walk_level(struct seq_file *m, stru= ct dma_pte *pde, =20 static int show_device_domain_translation(struct device *dev, void *data) { - struct dmar_domain *domain =3D find_domain(dev); + struct device_domain_info *info =3D dev_iommu_priv_get(dev); + struct dmar_domain *domain =3D info->domain; struct seq_file *m =3D data; u64 path[6] =3D { 0 }; =20 diff --git a/drivers/iommu/intel/iommu.c b/drivers/iommu/intel/iommu.c index 51db26d8606c..d9965e72d9a8 100644 --- a/drivers/iommu/intel/iommu.c +++ b/drivers/iommu/intel/iommu.c @@ -342,21 +342,6 @@ static int iommu_skip_te_disable; int intel_iommu_gfx_mapped; EXPORT_SYMBOL_GPL(intel_iommu_gfx_mapped); =20 -#define DEFER_DEVICE_DOMAIN_INFO ((struct device_domain_info *)(-2)) -struct device_domain_info *get_domain_info(struct device *dev) -{ - struct device_domain_info *info; - - if (!dev) - return NULL; - - info =3D dev_iommu_priv_get(dev); - if (unlikely(info =3D=3D DEFER_DEVICE_DOMAIN_INFO)) - return NULL; - - return info; -} - DEFINE_SPINLOCK(device_domain_lock); static LIST_HEAD(device_domain_list); =20 @@ -741,11 +726,6 @@ struct context_entry *iommu_context_addr(struct intel_= iommu *iommu, u8 bus, return &context[devfn]; } =20 -static bool attach_deferred(struct device *dev) -{ - return dev_iommu_priv_get(dev) =3D=3D DEFER_DEVICE_DOMAIN_INFO; -} - /** * is_downstream_to_pci_bridge - test if a device belongs to the PCI * sub-hierarchy of a candidate PCI-PCI bridge @@ -2432,15 +2412,6 @@ static void domain_context_clear_one(struct device_d= omain_info *info, u8 bus, u8 __iommu_flush_dev_iotlb(info, 0, MAX_AGAW_PFN_WIDTH); } =20 -static inline void unlink_domain_info(struct device_domain_info *info) -{ - assert_spin_locked(&device_domain_lock); - list_del(&info->link); - list_del(&info->global); - if (info->dev) - dev_iommu_priv_set(info->dev, NULL); -} - static void domain_remove_dev_info(struct dmar_domain *domain) { struct device_domain_info *info, *tmp; @@ -2452,24 +2423,6 @@ static void domain_remove_dev_info(struct dmar_domai= n *domain) spin_unlock_irqrestore(&device_domain_lock, flags); } =20 -struct dmar_domain *find_domain(struct device *dev) -{ - struct device_domain_info *info; - - if (unlikely(!dev || !dev->iommu)) - return NULL; - - if (unlikely(attach_deferred(dev))) - return NULL; - - /* No lock here, assumes no domain exit in normal case */ - info =3D get_domain_info(dev); - if (likely(info)) - return info->domain; - - return NULL; -} - static inline struct device_domain_info * dmar_search_domain_by_dev_info(int segment, int bus, int devfn) { @@ -2530,66 +2483,20 @@ static struct dmar_domain *dmar_insert_one_dev_info= (struct intel_iommu *iommu, struct device *dev, struct dmar_domain *domain) { - struct device_domain_info *info; + struct device_domain_info *info =3D dev_iommu_priv_get(dev); unsigned long flags; int ret; =20 - info =3D kzalloc(sizeof(*info), GFP_KERNEL); - if (!info) - return NULL; - - if (!dev_is_real_dma_subdevice(dev)) { - info->bus =3D bus; - info->devfn =3D devfn; - info->segment =3D iommu->segment; - } else { - struct pci_dev *pdev =3D to_pci_dev(dev); - - info->bus =3D pdev->bus->number; - info->devfn =3D pdev->devfn; - info->segment =3D pci_domain_nr(pdev->bus); - } - - info->dev =3D dev; - info->domain =3D domain; - info->iommu =3D iommu; - - if (dev && dev_is_pci(dev)) { - struct pci_dev *pdev =3D to_pci_dev(info->dev); - - if (ecap_dev_iotlb_support(iommu->ecap) && - pci_ats_supported(pdev) && - dmar_find_matched_atsr_unit(pdev)) - info->ats_supported =3D 1; - - if (sm_supported(iommu)) { - if (pasid_supported(iommu)) { - int features =3D pci_pasid_features(pdev); - if (features >=3D 0) - info->pasid_supported =3D features | 1; - } - - if (info->ats_supported && ecap_prs(iommu->ecap) && - pci_pri_supported(pdev)) - info->pri_supported =3D 1; - } - } - spin_lock_irqsave(&device_domain_lock, flags); + info->domain =3D domain; spin_lock(&iommu->lock); ret =3D domain_attach_iommu(domain, iommu); spin_unlock(&iommu->lock); - if (ret) { spin_unlock_irqrestore(&device_domain_lock, flags); - kfree(info); return NULL; } - list_add(&info->link, &domain->devices); - list_add(&info->global, &device_domain_list); - if (dev) - dev_iommu_priv_set(dev, info); spin_unlock_irqrestore(&device_domain_lock, flags); =20 /* PASID table is mandatory for a PCI device in scalable mode. */ @@ -4336,13 +4243,11 @@ static void __dmar_remove_one_dev_info(struct devic= e_domain_info *info) intel_pasid_free_table(info->dev); } =20 - unlink_domain_info(info); + list_del(&info->link); =20 spin_lock_irqsave(&iommu->lock, flags); domain_detach_iommu(domain, iommu); spin_unlock_irqrestore(&iommu->lock, flags); - - kfree(info); } =20 static void dmar_remove_one_dev_info(struct device *dev) @@ -4351,7 +4256,7 @@ static void dmar_remove_one_dev_info(struct device *d= ev) unsigned long flags; =20 spin_lock_irqsave(&device_domain_lock, flags); - info =3D get_domain_info(dev); + info =3D dev_iommu_priv_get(dev); if (info) __dmar_remove_one_dev_info(info); spin_unlock_irqrestore(&device_domain_lock, flags); @@ -4475,10 +4380,9 @@ static int intel_iommu_attach_device(struct iommu_do= main *domain, =20 /* normally dev is not mapped */ if (unlikely(domain_context_mapped(dev))) { - struct dmar_domain *old_domain; + struct device_domain_info *info =3D dev_iommu_priv_get(dev); =20 - old_domain =3D find_domain(dev); - if (old_domain) + if (info->domain) dmar_remove_one_dev_info(dev); } =20 @@ -4642,28 +4546,73 @@ static bool intel_iommu_capable(enum iommu_cap cap) =20 static struct iommu_device *intel_iommu_probe_device(struct device *dev) { + struct pci_dev *pdev =3D dev_is_pci(dev) ? to_pci_dev(dev) : NULL; + struct device_domain_info *info; struct intel_iommu *iommu; + unsigned long flags; + u8 bus, devfn; =20 - iommu =3D device_to_iommu(dev, NULL, NULL); + iommu =3D device_to_iommu(dev, &bus, &devfn); if (!iommu) return ERR_PTR(-ENODEV); =20 - if (translation_pre_enabled(iommu)) - dev_iommu_priv_set(dev, DEFER_DEVICE_DOMAIN_INFO); + info =3D kzalloc(sizeof(*info), GFP_KERNEL); + if (!info) + return ERR_PTR(-ENOMEM); + + if (dev_is_real_dma_subdevice(dev)) { + info->bus =3D pdev->bus->number; + info->devfn =3D pdev->devfn; + info->segment =3D pci_domain_nr(pdev->bus); + } else { + info->bus =3D bus; + info->devfn =3D devfn; + info->segment =3D iommu->segment; + } + + info->dev =3D dev; + info->iommu =3D iommu; + if (dev_is_pci(dev)) { + if (ecap_dev_iotlb_support(iommu->ecap) && + pci_ats_supported(pdev) && + dmar_find_matched_atsr_unit(pdev)) + info->ats_supported =3D 1; + + if (sm_supported(iommu)) { + if (pasid_supported(iommu)) { + int features =3D pci_pasid_features(pdev); + + if (features >=3D 0) + info->pasid_supported =3D features | 1; + } + + if (info->ats_supported && ecap_prs(iommu->ecap) && + pci_pri_supported(pdev)) + info->pri_supported =3D 1; + } + } + + spin_lock_irqsave(&device_domain_lock, flags); + list_add(&info->global, &device_domain_list); + dev_iommu_priv_set(dev, info); + spin_unlock_irqrestore(&device_domain_lock, flags); =20 return &iommu->iommu; } =20 static void intel_iommu_release_device(struct device *dev) { - struct intel_iommu *iommu; - - iommu =3D device_to_iommu(dev, NULL, NULL); - if (!iommu) - return; + struct device_domain_info *info =3D dev_iommu_priv_get(dev); + unsigned long flags; =20 dmar_remove_one_dev_info(dev); =20 + spin_lock_irqsave(&device_domain_lock, flags); + dev_iommu_priv_set(dev, NULL); + list_del(&info->global); + spin_unlock_irqrestore(&device_domain_lock, flags); + + kfree(info); set_dma_ops(dev, NULL); } =20 @@ -4732,14 +4681,14 @@ static void intel_iommu_get_resv_regions(struct dev= ice *device, =20 int intel_iommu_enable_pasid(struct intel_iommu *iommu, struct device *dev) { - struct device_domain_info *info; + struct device_domain_info *info =3D dev_iommu_priv_get(dev); struct context_entry *context; struct dmar_domain *domain; unsigned long flags; u64 ctx_lo; int ret; =20 - domain =3D find_domain(dev); + domain =3D info->domain; if (!domain) return -EINVAL; =20 @@ -4747,8 +4696,7 @@ int intel_iommu_enable_pasid(struct intel_iommu *iomm= u, struct device *dev) spin_lock(&iommu->lock); =20 ret =3D -EINVAL; - info =3D get_domain_info(dev); - if (!info || !info->pasid_supported) + if (!info->pasid_supported) goto out; =20 context =3D iommu_context_addr(iommu, info->bus, info->devfn, 0); @@ -4790,7 +4738,7 @@ static struct iommu_group *intel_iommu_device_group(s= truct device *dev) =20 static int intel_iommu_enable_sva(struct device *dev) { - struct device_domain_info *info =3D get_domain_info(dev); + struct device_domain_info *info =3D dev_iommu_priv_get(dev); struct intel_iommu *iommu; int ret; =20 @@ -4819,7 +4767,7 @@ static int intel_iommu_enable_sva(struct device *dev) =20 static int intel_iommu_disable_sva(struct device *dev) { - struct device_domain_info *info =3D get_domain_info(dev); + struct device_domain_info *info =3D dev_iommu_priv_get(dev); struct intel_iommu *iommu =3D info->iommu; int ret; =20 @@ -4832,7 +4780,7 @@ static int intel_iommu_disable_sva(struct device *dev) =20 static int intel_iommu_enable_iopf(struct device *dev) { - struct device_domain_info *info =3D get_domain_info(dev); + struct device_domain_info *info =3D dev_iommu_priv_get(dev); =20 if (info && info->pri_supported) return 0; @@ -4872,7 +4820,9 @@ intel_iommu_dev_disable_feat(struct device *dev, enum= iommu_dev_features feat) =20 static bool intel_iommu_is_attach_deferred(struct device *dev) { - return attach_deferred(dev); + struct device_domain_info *info =3D dev_iommu_priv_get(dev); + + return translation_pre_enabled(info->iommu) && !info->domain; } =20 /* diff --git a/drivers/iommu/intel/pasid.c b/drivers/iommu/intel/pasid.c index 10fb82ea467d..f8d215d85695 100644 --- a/drivers/iommu/intel/pasid.c +++ b/drivers/iommu/intel/pasid.c @@ -150,7 +150,7 @@ int intel_pasid_alloc_table(struct device *dev) int size; =20 might_sleep(); - info =3D get_domain_info(dev); + info =3D dev_iommu_priv_get(dev); if (WARN_ON(!info || !dev_is_pci(dev) || info->pasid_table)) return -EINVAL; =20 @@ -197,7 +197,7 @@ void intel_pasid_free_table(struct device *dev) struct pasid_entry *table; int i, max_pde; =20 - info =3D get_domain_info(dev); + info =3D dev_iommu_priv_get(dev); if (!info || !dev_is_pci(dev) || !info->pasid_table) return; =20 @@ -223,7 +223,7 @@ struct pasid_table *intel_pasid_get_table(struct device= *dev) { struct device_domain_info *info; =20 - info =3D get_domain_info(dev); + info =3D dev_iommu_priv_get(dev); if (!info) return NULL; =20 @@ -234,7 +234,7 @@ static int intel_pasid_get_dev_max_id(struct device *de= v) { struct device_domain_info *info; =20 - info =3D get_domain_info(dev); + info =3D dev_iommu_priv_get(dev); if (!info || !info->pasid_table) return 0; =20 @@ -254,7 +254,7 @@ static struct pasid_entry *intel_pasid_get_entry(struct= device *dev, u32 pasid) return NULL; =20 dir =3D pasid_table->table; - info =3D get_domain_info(dev); + info =3D dev_iommu_priv_get(dev); dir_index =3D pasid >> PASID_PDE_SHIFT; index =3D pasid & PASID_PTE_MASK; =20 @@ -487,7 +487,7 @@ devtlb_invalidation_with_pasid(struct intel_iommu *iomm= u, struct device_domain_info *info; u16 sid, qdep, pfsid; =20 - info =3D get_domain_info(dev); + info =3D dev_iommu_priv_get(dev); if (!info || !info->ats_enabled) return; =20 diff --git a/drivers/iommu/intel/svm.c b/drivers/iommu/intel/svm.c index d04c83dd3a58..944e2408b6d2 100644 --- a/drivers/iommu/intel/svm.c +++ b/drivers/iommu/intel/svm.c @@ -200,7 +200,7 @@ static void __flush_svm_range_dev(struct intel_svm *svm, unsigned long address, unsigned long pages, int ih) { - struct device_domain_info *info =3D get_domain_info(sdev->dev); + struct device_domain_info *info =3D dev_iommu_priv_get(sdev->dev); =20 if (WARN_ON(!pages)) return; @@ -337,7 +337,7 @@ static struct iommu_sva *intel_svm_bind_mm(struct intel= _iommu *iommu, struct mm_struct *mm, unsigned int flags) { - struct device_domain_info *info =3D get_domain_info(dev); + struct device_domain_info *info =3D dev_iommu_priv_get(dev); unsigned long iflags, sflags; struct intel_svm_dev *sdev; struct intel_svm *svm; @@ -545,7 +545,7 @@ static void intel_svm_drain_prq(struct device *dev, u32= pasid) u16 sid, did; int qdep; =20 - info =3D get_domain_info(dev); + info =3D dev_iommu_priv_get(dev); if (WARN_ON(!info || !dev_is_pci(dev))) return; =20 --=20 2.25.1 From nobody Sun Jun 28 05:29:38 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0B0F7C433F5 for ; Mon, 14 Feb 2022 02:59:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239700AbiBNC7H (ORCPT ); Sun, 13 Feb 2022 21:59:07 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:41628 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239725AbiBNC7D (ORCPT ); Sun, 13 Feb 2022 21:59:03 -0500 Received: from mga07.intel.com (mga07.intel.com [134.134.136.100]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AD84950B17 for ; Sun, 13 Feb 2022 18:58:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1644807532; x=1676343532; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=VfnNiH0iyPcpYrZNt/OHwIGhAD5IQG518T5a6b0/BPU=; b=E2+KSTbfs/+lFim55V7AgqbZjgGzROcoLVxxycGZY7eD0I7rd9qai8cE NrXslQTgmV/cPaMrwS3VjIzJjvqEVXAV4+hIHVjT2aVIHcgv4z23wTMDJ QsaH9POzMpc+B45NTDO1s3VLdjh8PbHi105e7gGsv+ZFYxln+9VZw3EIA ilLTalEGtA5FdD+5Oujg5Lw6+k+imm3bLwBrcLiAbsywbEbYqI/Zubdki RfcbMyiNYpHncRWgZZ52mX9463JZm3lQYnbg09slUTaN89wT1SokoGVrA tzyW25VsV4CAFE4exPYQTMeyiJJZSAfpxMCUZi3iq8jSZ9tfjN4/rY3j8 w==; X-IronPort-AV: E=McAfee;i="6200,9189,10257"; a="313280425" X-IronPort-AV: E=Sophos;i="5.88,366,1635231600"; d="scan'208";a="313280425" Received: from orsmga002.jf.intel.com ([10.7.209.21]) by orsmga105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Feb 2022 18:58:52 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.88,366,1635231600"; d="scan'208";a="501514991" Received: from allen-box.sh.intel.com ([10.239.159.118]) by orsmga002.jf.intel.com with ESMTP; 13 Feb 2022 18:58:49 -0800 From: Lu Baolu To: Joerg Roedel , Kevin Tian , Ashok Raj , Liu Yi L , Jacob Pan Cc: Robin Murphy , Jason Gunthorpe , Christoph Hellwig , iommu@lists.linux-foundation.org, linux-kernel@vger.kernel.org, Lu Baolu Subject: [PATCH v2 06/11] iommu/vt-d: Remove unnecessary includes Date: Mon, 14 Feb 2022 10:56:59 +0800 Message-Id: <20220214025704.3184654-7-baolu.lu@linux.intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220214025704.3184654-1-baolu.lu@linux.intel.com> References: <20220214025704.3184654-1-baolu.lu@linux.intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Remove unnecessary include files and sort the remaining alphabetically. Signed-off-by: Lu Baolu Reviewed-by: Christoph Hellwig Reviewed-by: Jason Gunthorpe --- drivers/iommu/intel/iommu.c | 34 +++++++--------------------------- 1 file changed, 7 insertions(+), 27 deletions(-) diff --git a/drivers/iommu/intel/iommu.c b/drivers/iommu/intel/iommu.c index d9965e72d9a8..b6a6fea8525d 100644 --- a/drivers/iommu/intel/iommu.c +++ b/drivers/iommu/intel/iommu.c @@ -13,38 +13,18 @@ #define pr_fmt(fmt) "DMAR: " fmt #define dev_fmt(fmt) pr_fmt(fmt) =20 -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include +#include +#include #include +#include #include #include +#include +#include +#include +#include #include #include -#include -#include -#include -#include -#include -#include -#include -#include -#include =20 #include "../irq_remapping.h" #include "../iommu-sva-lib.h" --=20 2.25.1 From nobody Sun Jun 28 05:29:38 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7933FC433EF for ; Mon, 14 Feb 2022 02:59:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239776AbiBNC7Q (ORCPT ); Sun, 13 Feb 2022 21:59:16 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:41374 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239575AbiBNC7E (ORCPT ); Sun, 13 Feb 2022 21:59:04 -0500 Received: from mga07.intel.com (mga07.intel.com [134.134.136.100]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A643355BC0 for ; Sun, 13 Feb 2022 18:58:55 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1644807535; x=1676343535; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=IPNVUv69Hr9yrUWKfPfYKikMbfHGWWQGb9/xmMifnEg=; b=eirTLS9sLotix/jGXuPJXhUzYR3/MI8oHLPzaWWYau2WDJ9buIAnjjJk +lP3+DWsm4P95BYBSZoSZW7bCTi9pTrxzLlCamREZJN6r5/Q+VC71f/WQ 25PtI7y8OtCFCVTtcAdmNBqdHOcD5WRchq+N74KGBjwTySoDG+3JoboH0 kG0Nz687IxOiH2kCiLkSqmI3TSHhZq+Vm9XlgwMNto2GtgtE98yncxDZv qMZZPza8Ie+7ktmg9t7mNm+zwFv3oZyO4/l0yrBW0irCJ18Bc+l8SF9Qm BRA2IDyHN0Hv6i1GEEKJDZbCmwvCxhbbcqqzwK3F9S6mzNFS2kwgsTwg8 A==; X-IronPort-AV: E=McAfee;i="6200,9189,10257"; a="313280427" X-IronPort-AV: E=Sophos;i="5.88,366,1635231600"; d="scan'208";a="313280427" Received: from orsmga002.jf.intel.com ([10.7.209.21]) by orsmga105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Feb 2022 18:58:55 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.88,366,1635231600"; d="scan'208";a="501515002" Received: from allen-box.sh.intel.com ([10.239.159.118]) by orsmga002.jf.intel.com with ESMTP; 13 Feb 2022 18:58:52 -0800 From: Lu Baolu To: Joerg Roedel , Kevin Tian , Ashok Raj , Liu Yi L , Jacob Pan Cc: Robin Murphy , Jason Gunthorpe , Christoph Hellwig , iommu@lists.linux-foundation.org, linux-kernel@vger.kernel.org, Lu Baolu Subject: [PATCH v2 07/11] iommu/vt-d: Remove unnecessary prototypes Date: Mon, 14 Feb 2022 10:57:00 +0800 Message-Id: <20220214025704.3184654-8-baolu.lu@linux.intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220214025704.3184654-1-baolu.lu@linux.intel.com> References: <20220214025704.3184654-1-baolu.lu@linux.intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Some prototypes in iommu.c are unnecessary. Delete them. Signed-off-by: Lu Baolu Reviewed-by: Christoph Hellwig Reviewed-by: Jason Gunthorpe --- drivers/iommu/intel/iommu.c | 5 ----- 1 file changed, 5 deletions(-) diff --git a/drivers/iommu/intel/iommu.c b/drivers/iommu/intel/iommu.c index b6a6fea8525d..dfd3698406fa 100644 --- a/drivers/iommu/intel/iommu.c +++ b/drivers/iommu/intel/iommu.c @@ -296,14 +296,9 @@ static LIST_HEAD(dmar_satc_units); /* bitmap for indexing intel_iommus */ static int g_num_of_iommus; =20 -static void domain_exit(struct dmar_domain *domain); static void domain_remove_dev_info(struct dmar_domain *domain); static void dmar_remove_one_dev_info(struct device *dev); static void __dmar_remove_one_dev_info(struct device_domain_info *info); -static int intel_iommu_attach_device(struct iommu_domain *domain, - struct device *dev); -static phys_addr_t intel_iommu_iova_to_phys(struct iommu_domain *domain, - dma_addr_t iova); =20 int dmar_disabled =3D !IS_ENABLED(CONFIG_INTEL_IOMMU_DEFAULT_ON); int intel_iommu_sm =3D IS_ENABLED(CONFIG_INTEL_IOMMU_SCALABLE_MODE_DEFAULT= _ON); --=20 2.25.1 From nobody Sun Jun 28 05:29:38 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 908B6C433F5 for ; Mon, 14 Feb 2022 02:59:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239500AbiBNC7N (ORCPT ); Sun, 13 Feb 2022 21:59:13 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:41802 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239707AbiBNC7H (ORCPT ); Sun, 13 Feb 2022 21:59:07 -0500 Received: from mga07.intel.com (mga07.intel.com [134.134.136.100]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 728EB50E3B for ; Sun, 13 Feb 2022 18:58:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1644807538; x=1676343538; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=XnFH65FFxEQ3hwhwcysUPS97E/4r4ucJNSpMglRXUwU=; b=kiKKtsoxAdD51ViJcJHPYcWyH5qKKfIEZ3LD3GaO+cRs4nJCWlG0AlDD 8kJXGNa0h1rgUEP+dDmGtyWqTqjHQ0vbxG1jLlA9COmE2W05ly6AJa4+X jphTLB5UY59v8jTroa6qoIudxn4q5qsgLpO2rjLDNVx7vBROmT66OHxLr 9xsHcxeoZ3RDkOd9DJ/e43McaJgS/tpPfZieKymI62H26Gnw+fxkRvjr9 LieZb6Pzf/fiNdPU5WPvc3RCZbcNqPpJe3JdvAzVhkXMRLECq5XV5fAnu +7EofKL/WyfjCRH2YpPEOH5IZBcDAGGk1hzLOEg3GxNigJGUMfnsCmhrU w==; X-IronPort-AV: E=McAfee;i="6200,9189,10257"; a="313280431" X-IronPort-AV: E=Sophos;i="5.88,366,1635231600"; d="scan'208";a="313280431" Received: from orsmga002.jf.intel.com ([10.7.209.21]) by orsmga105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Feb 2022 18:58:58 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.88,366,1635231600"; d="scan'208";a="501515020" Received: from allen-box.sh.intel.com ([10.239.159.118]) by orsmga002.jf.intel.com with ESMTP; 13 Feb 2022 18:58:55 -0800 From: Lu Baolu To: Joerg Roedel , Kevin Tian , Ashok Raj , Liu Yi L , Jacob Pan Cc: Robin Murphy , Jason Gunthorpe , Christoph Hellwig , iommu@lists.linux-foundation.org, linux-kernel@vger.kernel.org, Lu Baolu Subject: [PATCH v2 08/11] iommu/vt-d: Fix indentation of goto labels Date: Mon, 14 Feb 2022 10:57:01 +0800 Message-Id: <20220214025704.3184654-9-baolu.lu@linux.intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220214025704.3184654-1-baolu.lu@linux.intel.com> References: <20220214025704.3184654-1-baolu.lu@linux.intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Remove blanks before goto labels. Signed-off-by: Lu Baolu Reviewed-by: Christoph Hellwig Reviewed-by: Jason Gunthorpe --- drivers/iommu/intel/iommu.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/iommu/intel/iommu.c b/drivers/iommu/intel/iommu.c index dfd3698406fa..d7fac0a1761d 100644 --- a/drivers/iommu/intel/iommu.c +++ b/drivers/iommu/intel/iommu.c @@ -827,7 +827,7 @@ struct intel_iommu *device_to_iommu(struct device *dev,= u8 *bus, u8 *devfn) } =20 if (pdev && drhd->include_all) { - got_pdev: +got_pdev: if (bus && devfn) { *bus =3D pdev->bus->number; *devfn =3D pdev->devfn; @@ -836,7 +836,7 @@ struct intel_iommu *device_to_iommu(struct device *dev,= u8 *bus, u8 *devfn) } } iommu =3D NULL; - out: +out: if (iommu_is_dummy(iommu, dev)) iommu =3D NULL; =20 --=20 2.25.1 From nobody Sun Jun 28 05:29:38 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id C767EC433EF for ; Mon, 14 Feb 2022 02:59:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239745AbiBNC7i (ORCPT ); Sun, 13 Feb 2022 21:59:38 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:41990 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239765AbiBNC7N (ORCPT ); Sun, 13 Feb 2022 21:59:13 -0500 Received: from mga07.intel.com (mga07.intel.com [134.134.136.100]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6C21C50E19 for ; Sun, 13 Feb 2022 18:59:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1644807541; x=1676343541; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=WEno40C7jLT1PSOtcxME8RVxUTyrL0WdeC6F3m6ZqJM=; b=Id+zggKw6z+c9xh2UZBSdgYeHXPS1isgk0dq63jwMv/VTmETLVyDgpyT aRABAo9MLYbzHU/b33AfTjDQI+YWWp+R46jcPfHvIOYmQaiZVCyztdjRM ky7hURm5Yi18Lx6jg6+duupHygZzg/AdBt7i1Wfs3MX4T8VDA+zPCpYgQ 7qOSOZR+U3JdCWqEstfY5BXEyeC4+2jlmfH0BQ7Ti41KrmEAq0vfHUs/q Z9uCt9KioFbAUpRiMsIwf7jipUEiiWWGgml9pGiA11A70ysMa3dxuDkPk 7wVx36H/bQ82FgjoFpeyEHvCfb0IrEhGXuDUT0QywhDLj0Kg93nchCKZX Q==; X-IronPort-AV: E=McAfee;i="6200,9189,10257"; a="313280433" X-IronPort-AV: E=Sophos;i="5.88,366,1635231600"; d="scan'208";a="313280433" Received: from orsmga002.jf.intel.com ([10.7.209.21]) by orsmga105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Feb 2022 18:59:01 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.88,366,1635231600"; d="scan'208";a="501515031" Received: from allen-box.sh.intel.com ([10.239.159.118]) by orsmga002.jf.intel.com with ESMTP; 13 Feb 2022 18:58:58 -0800 From: Lu Baolu To: Joerg Roedel , Kevin Tian , Ashok Raj , Liu Yi L , Jacob Pan Cc: Robin Murphy , Jason Gunthorpe , Christoph Hellwig , iommu@lists.linux-foundation.org, linux-kernel@vger.kernel.org, Lu Baolu Subject: [PATCH v2 09/11] iommu/vt-d: Remove commented code Date: Mon, 14 Feb 2022 10:57:02 +0800 Message-Id: <20220214025704.3184654-10-baolu.lu@linux.intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220214025704.3184654-1-baolu.lu@linux.intel.com> References: <20220214025704.3184654-1-baolu.lu@linux.intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" This removes unnecessary commented code. Signed-off-by: Lu Baolu Reviewed-by: Christoph Hellwig Reviewed-by: Jason Gunthorpe --- drivers/iommu/intel/iommu.c | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/drivers/iommu/intel/iommu.c b/drivers/iommu/intel/iommu.c index d7fac0a1761d..fb17ed8c08f3 100644 --- a/drivers/iommu/intel/iommu.c +++ b/drivers/iommu/intel/iommu.c @@ -1407,15 +1407,7 @@ static void __iommu_flush_iotlb(struct intel_iommu *= iommu, u16 did, default: BUG(); } - /* Note: set drain read/write */ -#if 0 - /* - * This is probably to be super secure.. Looks like we can - * ignore it without any impact. - */ - if (cap_read_drain(iommu->cap)) - val |=3D DMA_TLB_READ_DRAIN; -#endif + if (cap_write_drain(iommu->cap)) val |=3D DMA_TLB_WRITE_DRAIN; =20 --=20 2.25.1 From nobody Sun Jun 28 05:29:38 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5865FC433F5 for ; Mon, 14 Feb 2022 02:59:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239781AbiBNC72 (ORCPT ); Sun, 13 Feb 2022 21:59:28 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:42314 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239803AbiBNC7Y (ORCPT ); Sun, 13 Feb 2022 21:59:24 -0500 Received: from mga07.intel.com (mga07.intel.com [134.134.136.100]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 364C854FBF for ; Sun, 13 Feb 2022 18:59:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1644807544; x=1676343544; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=VBMsFrh2PTzmv2WOA2c5Cq3XrHldULkt+wE397bzEns=; b=G/oP/38l1aWZwD0DTsFj+fdd7+Iv0gqB0111L2jNh1ogqay6P3J8Z7Xr mhI8J7GOotzKgZxxjdSJOfrZlFyfgZz1SnDLT1Fo92E7N++DolPIo9fEh 5zeQ84xyaKctU1RjerFwuX0hv5XBlwriDd+m4kGQOBwvAg4UUs7dviTbF 2BSqRgP8TsHD3eRG+xImh1+4k6s7QSpZuUrFtTZpgz0F4b5766SCFzruc b82C8NWUpwOH8+mhgwZoAQqRpLfhVh164KU/6o6cRb8Q/G4ZTpyO7qxI7 zRdRbJ46sOyZNEnQMbhYr7J1obVfaFEfFk7QNJaJ2pT2OHdf3U+vnvnJN w==; X-IronPort-AV: E=McAfee;i="6200,9189,10257"; a="313280438" X-IronPort-AV: E=Sophos;i="5.88,366,1635231600"; d="scan'208";a="313280438" Received: from orsmga002.jf.intel.com ([10.7.209.21]) by orsmga105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Feb 2022 18:59:04 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.88,366,1635231600"; d="scan'208";a="501515047" Received: from allen-box.sh.intel.com ([10.239.159.118]) by orsmga002.jf.intel.com with ESMTP; 13 Feb 2022 18:59:01 -0800 From: Lu Baolu To: Joerg Roedel , Kevin Tian , Ashok Raj , Liu Yi L , Jacob Pan Cc: Robin Murphy , Jason Gunthorpe , Christoph Hellwig , iommu@lists.linux-foundation.org, linux-kernel@vger.kernel.org, Lu Baolu Subject: [PATCH v2 10/11] iommu/vt-d: Use xarray for global device_domain_info Date: Mon, 14 Feb 2022 10:57:03 +0800 Message-Id: <20220214025704.3184654-11-baolu.lu@linux.intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220214025704.3184654-1-baolu.lu@linux.intel.com> References: <20220214025704.3184654-1-baolu.lu@linux.intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Replace the existing global device_domain_list with an array so that it could be rapidly searched. The index of the array is composed by the PCI segment, bus and devfn. Use RCU for lock protection. Signed-off-by: Lu Baolu --- include/linux/intel-iommu.h | 1 - drivers/iommu/intel/iommu.c | 72 ++++++++++++++++++------------------- 2 files changed, 34 insertions(+), 39 deletions(-) diff --git a/include/linux/intel-iommu.h b/include/linux/intel-iommu.h index 03f1134fc2fe..aca1c1cc04a8 100644 --- a/include/linux/intel-iommu.h +++ b/include/linux/intel-iommu.h @@ -610,7 +610,6 @@ struct intel_iommu { /* PCI domain-device relationship */ struct device_domain_info { struct list_head link; /* link to domain siblings */ - struct list_head global; /* link to global list */ struct list_head table; /* link to pasid table */ u32 segment; /* PCI segment number */ u8 bus; /* PCI bus number */ diff --git a/drivers/iommu/intel/iommu.c b/drivers/iommu/intel/iommu.c index fb17ed8c08f3..ecec923ce191 100644 --- a/drivers/iommu/intel/iommu.c +++ b/drivers/iommu/intel/iommu.c @@ -131,8 +131,6 @@ static struct intel_iommu **g_iommus; =20 static void __init check_tylersburg_isoch(void); static int rwbf_quirk; -static inline struct device_domain_info * -dmar_search_domain_by_dev_info(int segment, int bus, int devfn); =20 /* * set to 1 to panic kernel if can't successfully enable VT-d @@ -318,30 +316,34 @@ int intel_iommu_gfx_mapped; EXPORT_SYMBOL_GPL(intel_iommu_gfx_mapped); =20 DEFINE_SPINLOCK(device_domain_lock); -static LIST_HEAD(device_domain_list); +static DEFINE_XARRAY_ALLOC(device_domain_array); + +/* Convert device source ID into the index of device_domain_array. */ +static inline unsigned long devi_idx(unsigned long seg, u8 bus, u8 devfn) +{ + return (seg << 16) | PCI_DEVID(bus, devfn); +} =20 /* - * Iterate over elements in device_domain_list and call the specified + * Iterate over elements in device_domain_array and call the specified * callback @fn against each element. */ int for_each_device_domain(int (*fn)(struct device_domain_info *info, void *data), void *data) { - int ret =3D 0; - unsigned long flags; struct device_domain_info *info; + unsigned long index; + int ret =3D 0; =20 - spin_lock_irqsave(&device_domain_lock, flags); - list_for_each_entry(info, &device_domain_list, global) { + rcu_read_lock(); + xa_for_each(&device_domain_array, index, info) { ret =3D fn(info, data); - if (ret) { - spin_unlock_irqrestore(&device_domain_lock, flags); - return ret; - } + if (ret) + break; } - spin_unlock_irqrestore(&device_domain_lock, flags); + rcu_read_unlock(); =20 - return 0; + return ret; } =20 const struct iommu_ops intel_iommu_ops; @@ -903,7 +905,8 @@ static void pgtable_walk(struct intel_iommu *iommu, uns= igned long pfn, u8 bus, u struct dmar_domain *domain; int offset, level; =20 - info =3D dmar_search_domain_by_dev_info(iommu->segment, bus, devfn); + info =3D xa_load(&device_domain_array, + devi_idx(iommu->segment, bus, devfn)); if (!info || !info->domain) { pr_info("device [%02x:%02x.%d] not probed\n", bus, PCI_SLOT(devfn), PCI_FUNC(devfn)); @@ -1742,14 +1745,14 @@ static int iommu_init_domains(struct intel_iommu *i= ommu) =20 static void disable_dmar_iommu(struct intel_iommu *iommu) { - struct device_domain_info *info, *tmp; - unsigned long flags; + struct device_domain_info *info; + unsigned long index; =20 if (!iommu->domain_ids) return; =20 - spin_lock_irqsave(&device_domain_lock, flags); - list_for_each_entry_safe(info, tmp, &device_domain_list, global) { + rcu_read_lock(); + xa_for_each(&device_domain_array, index, info) { if (info->iommu !=3D iommu) continue; =20 @@ -1758,7 +1761,7 @@ static void disable_dmar_iommu(struct intel_iommu *io= mmu) =20 __dmar_remove_one_dev_info(info); } - spin_unlock_irqrestore(&device_domain_lock, flags); + rcu_read_unlock(); =20 if (iommu->gcmd & DMA_GCMD_TE) iommu_disable_translation(iommu); @@ -2390,19 +2393,6 @@ static void domain_remove_dev_info(struct dmar_domai= n *domain) spin_unlock_irqrestore(&device_domain_lock, flags); } =20 -static inline struct device_domain_info * -dmar_search_domain_by_dev_info(int segment, int bus, int devfn) -{ - struct device_domain_info *info; - - list_for_each_entry(info, &device_domain_list, global) - if (info->segment =3D=3D segment && info->bus =3D=3D bus && - info->devfn =3D=3D devfn) - return info; - - return NULL; -} - static int domain_setup_first_level(struct intel_iommu *iommu, struct dmar_domain *domain, struct device *dev, @@ -4516,8 +4506,8 @@ static struct iommu_device *intel_iommu_probe_device(= struct device *dev) struct pci_dev *pdev =3D dev_is_pci(dev) ? to_pci_dev(dev) : NULL; struct device_domain_info *info; struct intel_iommu *iommu; - unsigned long flags; u8 bus, devfn; + void *curr; =20 iommu =3D device_to_iommu(dev, &bus, &devfn); if (!iommu) @@ -4559,10 +4549,15 @@ static struct iommu_device *intel_iommu_probe_devic= e(struct device *dev) } } =20 - spin_lock_irqsave(&device_domain_lock, flags); - list_add(&info->global, &device_domain_list); + curr =3D xa_store(&device_domain_array, + devi_idx(info->segment, info->bus, info->devfn), + info, GFP_KERNEL); + if (xa_err(curr) || WARN_ON(curr)) { + kfree(info); + return ERR_PTR(-ENOSPC); + } + dev_iommu_priv_set(dev, info); - spin_unlock_irqrestore(&device_domain_lock, flags); =20 return &iommu->iommu; } @@ -4576,7 +4571,8 @@ static void intel_iommu_release_device(struct device = *dev) =20 spin_lock_irqsave(&device_domain_lock, flags); dev_iommu_priv_set(dev, NULL); - list_del(&info->global); + xa_erase(&device_domain_array, + devi_idx(info->segment, info->bus, info->devfn)); spin_unlock_irqrestore(&device_domain_lock, flags); =20 kfree(info); --=20 2.25.1 From nobody Sun Jun 28 05:29:38 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 48EFEC433F5 for ; Mon, 14 Feb 2022 02:59:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239739AbiBNC7e (ORCPT ); Sun, 13 Feb 2022 21:59:34 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:41946 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239816AbiBNC7Y (ORCPT ); Sun, 13 Feb 2022 21:59:24 -0500 Received: from mga07.intel.com (mga07.intel.com [134.134.136.100]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6FD6655BCB for ; Sun, 13 Feb 2022 18:59:07 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1644807547; x=1676343547; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=t0+x3e/vMXMgvyaDYDILzrLWoxq/qCmfPpA74cSvLKM=; b=ntx+H7eFEFZAEFJ8GDYK3yE6Y2QcJzTlyXP4RlnTHxfxEo7Y8SPBnTnH UuO+NbvCo599PGeQ2Kpk+yc+AnNm2AmvqjBnGxbWQOhBrl7Ug0gbDzDh4 o8mVk9hEEs/R8vqOmE0doRyYRpm+vvHbxWeASVaTws2/0rhnqk7OM6opW 9mfppED0eZsqEas4JZK442nvDRwpmhKMngsiy/HUbopJahBbdwHH4dyim E9t9D8vCcqtdonQc4FVnyAlgbhCeaMpLE8pvN/GmaeWEVQBkv2Uen38uM OZRdFDFxcyltwV3qJTPmk1EfarHivSIrY2apkObDPK0qSc2zicM3jB2Rz g==; X-IronPort-AV: E=McAfee;i="6200,9189,10257"; a="313280444" X-IronPort-AV: E=Sophos;i="5.88,366,1635231600"; d="scan'208";a="313280444" Received: from orsmga002.jf.intel.com ([10.7.209.21]) by orsmga105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Feb 2022 18:59:07 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.88,366,1635231600"; d="scan'208";a="501515057" Received: from allen-box.sh.intel.com ([10.239.159.118]) by orsmga002.jf.intel.com with ESMTP; 13 Feb 2022 18:59:04 -0800 From: Lu Baolu To: Joerg Roedel , Kevin Tian , Ashok Raj , Liu Yi L , Jacob Pan Cc: Robin Murphy , Jason Gunthorpe , Christoph Hellwig , iommu@lists.linux-foundation.org, linux-kernel@vger.kernel.org, Lu Baolu Subject: [PATCH v2 11/11] iommu/vt-d: Use rculist for per-domain device list Date: Mon, 14 Feb 2022 10:57:04 +0800 Message-Id: <20220214025704.3184654-12-baolu.lu@linux.intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220214025704.3184654-1-baolu.lu@linux.intel.com> References: <20220214025704.3184654-1-baolu.lu@linux.intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Use rculist for list of devices attached by a domain. And use the RCU lock for read/write protection. As both the global device_domain array and per-domain device_domain list are protected by RCU lock now, there is no need to use the spinlock anymore. Cleanup device_domain_lock. Signed-off-by: Lu Baolu --- include/linux/intel-iommu.h | 2 +- drivers/iommu/intel/debugfs.c | 11 +-- drivers/iommu/intel/iommu.c | 126 ++++++++++++++-------------------- 3 files changed, 53 insertions(+), 86 deletions(-) diff --git a/include/linux/intel-iommu.h b/include/linux/intel-iommu.h index aca1c1cc04a8..286bd6f82024 100644 --- a/include/linux/intel-iommu.h +++ b/include/linux/intel-iommu.h @@ -480,7 +480,6 @@ enum { #define VTD_FLAG_SVM_CAPABLE (1 << 2) =20 extern int intel_iommu_sm; -extern spinlock_t device_domain_lock; =20 #define sm_supported(iommu) (intel_iommu_sm && ecap_smts((iommu)->ecap)) #define pasid_supported(iommu) (sm_supported(iommu) && \ @@ -609,6 +608,7 @@ struct intel_iommu { =20 /* PCI domain-device relationship */ struct device_domain_info { + struct rcu_head rcu; struct list_head link; /* link to domain siblings */ struct list_head table; /* link to pasid table */ u32 segment; /* PCI segment number */ diff --git a/drivers/iommu/intel/debugfs.c b/drivers/iommu/intel/debugfs.c index ed796eea4581..6a115103412a 100644 --- a/drivers/iommu/intel/debugfs.c +++ b/drivers/iommu/intel/debugfs.c @@ -364,15 +364,8 @@ static int show_device_domain_translation(struct devic= e *dev, void *data) =20 static int domain_translation_struct_show(struct seq_file *m, void *unused) { - unsigned long flags; - int ret; - - spin_lock_irqsave(&device_domain_lock, flags); - ret =3D bus_for_each_dev(&pci_bus_type, NULL, m, - show_device_domain_translation); - spin_unlock_irqrestore(&device_domain_lock, flags); - - return ret; + return bus_for_each_dev(&pci_bus_type, NULL, m, + show_device_domain_translation); } DEFINE_SHOW_ATTRIBUTE(domain_translation_struct); =20 diff --git a/drivers/iommu/intel/iommu.c b/drivers/iommu/intel/iommu.c index ecec923ce191..303d6d93e381 100644 --- a/drivers/iommu/intel/iommu.c +++ b/drivers/iommu/intel/iommu.c @@ -294,7 +294,6 @@ static LIST_HEAD(dmar_satc_units); /* bitmap for indexing intel_iommus */ static int g_num_of_iommus; =20 -static void domain_remove_dev_info(struct dmar_domain *domain); static void dmar_remove_one_dev_info(struct device *dev); static void __dmar_remove_one_dev_info(struct device_domain_info *info); =20 @@ -315,7 +314,6 @@ static int iommu_skip_te_disable; int intel_iommu_gfx_mapped; EXPORT_SYMBOL_GPL(intel_iommu_gfx_mapped); =20 -DEFINE_SPINLOCK(device_domain_lock); static DEFINE_XARRAY_ALLOC(device_domain_array); =20 /* Convert device source ID into the index of device_domain_array. */ @@ -597,12 +595,11 @@ static int domain_update_device_node(struct dmar_doma= in *domain) struct device_domain_info *info; int nid =3D NUMA_NO_NODE; =20 - assert_spin_locked(&device_domain_lock); - if (list_empty(&domain->devices)) return NUMA_NO_NODE; =20 - list_for_each_entry(info, &domain->devices, link) { + rcu_read_lock(); + list_for_each_entry_rcu(info, &domain->devices, link) { if (!info->dev) continue; =20 @@ -616,6 +613,7 @@ static int domain_update_device_node(struct dmar_domain= *domain) if (nid !=3D NUMA_NO_NODE) break; } + rcu_read_unlock(); =20 return nid; } @@ -1436,25 +1434,26 @@ static void __iommu_flush_iotlb(struct intel_iommu = *iommu, u16 did, } =20 static struct device_domain_info * -iommu_support_dev_iotlb (struct dmar_domain *domain, struct intel_iommu *i= ommu, - u8 bus, u8 devfn) +iommu_support_dev_iotlb(struct dmar_domain *domain, struct intel_iommu *io= mmu, + u8 bus, u8 devfn) { - struct device_domain_info *info; - - assert_spin_locked(&device_domain_lock); + struct device_domain_info *tmp, *info =3D NULL; =20 if (!iommu->qi) return NULL; =20 - list_for_each_entry(info, &domain->devices, link) - if (info->iommu =3D=3D iommu && info->bus =3D=3D bus && - info->devfn =3D=3D devfn) { - if (info->ats_supported && info->dev) - return info; + rcu_read_lock(); + list_for_each_entry_rcu(tmp, &domain->devices, link) { + if (tmp->iommu =3D=3D iommu && tmp->bus =3D=3D bus && + tmp->devfn =3D=3D devfn) { + if (tmp->ats_supported && tmp->dev) + info =3D tmp; break; } + } + rcu_read_unlock(); =20 - return NULL; + return info; } =20 static void domain_update_iotlb(struct dmar_domain *domain) @@ -1462,13 +1461,14 @@ static void domain_update_iotlb(struct dmar_domain = *domain) struct device_domain_info *info; bool has_iotlb_device =3D false; =20 - assert_spin_locked(&device_domain_lock); - - list_for_each_entry(info, &domain->devices, link) + rcu_read_lock(); + list_for_each_entry_rcu(info, &domain->devices, link) { if (info->ats_enabled) { has_iotlb_device =3D true; break; } + } + rcu_read_unlock(); =20 domain->has_iotlb_device =3D has_iotlb_device; } @@ -1477,8 +1477,6 @@ static void iommu_enable_dev_iotlb(struct device_doma= in_info *info) { struct pci_dev *pdev; =20 - assert_spin_locked(&device_domain_lock); - if (!info || !dev_is_pci(info->dev)) return; =20 @@ -1524,8 +1522,6 @@ static void iommu_disable_dev_iotlb(struct device_dom= ain_info *info) { struct pci_dev *pdev; =20 - assert_spin_locked(&device_domain_lock); - if (!dev_is_pci(info->dev)) return; =20 @@ -1565,17 +1561,15 @@ static void __iommu_flush_dev_iotlb(struct device_d= omain_info *info, static void iommu_flush_dev_iotlb(struct dmar_domain *domain, u64 addr, unsigned mask) { - unsigned long flags; struct device_domain_info *info; =20 if (!domain->has_iotlb_device) return; =20 - spin_lock_irqsave(&device_domain_lock, flags); - list_for_each_entry(info, &domain->devices, link) + rcu_read_lock(); + list_for_each_entry_rcu(info, &domain->devices, link) __iommu_flush_dev_iotlb(info, addr, mask); - - spin_unlock_irqrestore(&device_domain_lock, flags); + rcu_read_unlock(); } =20 static void iommu_flush_iotlb_psi(struct intel_iommu *iommu, @@ -1820,7 +1814,7 @@ static struct dmar_domain *alloc_domain(unsigned int = type) if (first_level_by_default(type)) domain->flags |=3D DOMAIN_FLAG_USE_FIRST_LEVEL; domain->has_iotlb_device =3D false; - INIT_LIST_HEAD(&domain->devices); + INIT_LIST_HEAD_RCU(&domain->devices); =20 return domain; } @@ -1832,7 +1826,6 @@ static int domain_attach_iommu(struct dmar_domain *do= main, unsigned long ndomains; int num; =20 - assert_spin_locked(&device_domain_lock); assert_spin_locked(&iommu->lock); =20 domain->iommu_refcnt[iommu->seq_id] +=3D 1; @@ -1860,7 +1853,6 @@ static void domain_detach_iommu(struct dmar_domain *d= omain, { int num; =20 - assert_spin_locked(&device_domain_lock); assert_spin_locked(&iommu->lock); =20 domain->iommu_refcnt[iommu->seq_id] -=3D 1; @@ -1889,8 +1881,15 @@ static inline int guestwidth_to_adjustwidth(int gaw) static void domain_exit(struct dmar_domain *domain) { =20 - /* Remove associated devices and clear attached or cached domains */ - domain_remove_dev_info(domain); + struct device_domain_info *info, *tmp; + + /* + * Remove associated devices and clear attached or cached domains. + * No worries about new devices insertion or removal. Hence no need + * for a lock here. + */ + list_for_each_entry_safe(info, tmp, &domain->devices, link) + __dmar_remove_one_dev_info(info); =20 if (domain->pgd) { LIST_HEAD(freelist); @@ -1973,9 +1972,7 @@ static int domain_context_mapping_one(struct dmar_dom= ain *domain, =20 BUG_ON(!domain->pgd); =20 - spin_lock_irqsave(&device_domain_lock, flags); - spin_lock(&iommu->lock); - + spin_lock_irqsave(&iommu->lock, flags); ret =3D -ENOMEM; context =3D iommu_context_addr(iommu, bus, devfn, 1); if (!context) @@ -2094,8 +2091,7 @@ static int domain_context_mapping_one(struct dmar_dom= ain *domain, ret =3D 0; =20 out_unlock: - spin_unlock(&iommu->lock); - spin_unlock_irqrestore(&device_domain_lock, flags); + spin_unlock_irqrestore(&iommu->lock, flags); =20 return ret; } @@ -2382,17 +2378,6 @@ static void domain_context_clear_one(struct device_d= omain_info *info, u8 bus, u8 __iommu_flush_dev_iotlb(info, 0, MAX_AGAW_PFN_WIDTH); } =20 -static void domain_remove_dev_info(struct dmar_domain *domain) -{ - struct device_domain_info *info, *tmp; - unsigned long flags; - - spin_lock_irqsave(&device_domain_lock, flags); - list_for_each_entry_safe(info, tmp, &domain->devices, link) - __dmar_remove_one_dev_info(info); - spin_unlock_irqrestore(&device_domain_lock, flags); -} - static int domain_setup_first_level(struct intel_iommu *iommu, struct dmar_domain *domain, struct device *dev, @@ -2444,17 +2429,14 @@ static struct dmar_domain *dmar_insert_one_dev_info= (struct intel_iommu *iommu, unsigned long flags; int ret; =20 - spin_lock_irqsave(&device_domain_lock, flags); - info->domain =3D domain; - spin_lock(&iommu->lock); + spin_lock_irqsave(&iommu->lock, flags); ret =3D domain_attach_iommu(domain, iommu); - spin_unlock(&iommu->lock); - if (ret) { - spin_unlock_irqrestore(&device_domain_lock, flags); + spin_unlock_irqrestore(&iommu->lock, flags); + if (ret) return NULL; - } - list_add(&info->link, &domain->devices); - spin_unlock_irqrestore(&device_domain_lock, flags); + + info->domain =3D domain; + list_add_rcu(&info->link, &domain->devices); =20 /* PASID table is mandatory for a PCI device in scalable mode. */ if (dev && dev_is_pci(dev) && sm_supported(iommu)) { @@ -4182,8 +4164,6 @@ static void __dmar_remove_one_dev_info(struct device_= domain_info *info) struct intel_iommu *iommu; unsigned long flags; =20 - assert_spin_locked(&device_domain_lock); - if (WARN_ON(!info)) return; =20 @@ -4191,16 +4171,19 @@ static void __dmar_remove_one_dev_info(struct devic= e_domain_info *info) domain =3D info->domain; =20 if (info->dev && !dev_is_real_dma_subdevice(info->dev)) { - if (dev_is_pci(info->dev) && sm_supported(iommu)) + if (dev_is_pci(info->dev) && sm_supported(iommu)) { + spin_lock_irqsave(&iommu->lock, flags); intel_pasid_tear_down_entry(iommu, info->dev, PASID_RID2PASID, false); + spin_unlock_irqrestore(&iommu->lock, flags); + } =20 iommu_disable_dev_iotlb(info); domain_context_clear(info); intel_pasid_free_table(info->dev); } =20 - list_del(&info->link); + list_del_rcu(&info->link); =20 spin_lock_irqsave(&iommu->lock, flags); domain_detach_iommu(domain, iommu); @@ -4210,13 +4193,10 @@ static void __dmar_remove_one_dev_info(struct devic= e_domain_info *info) static void dmar_remove_one_dev_info(struct device *dev) { struct device_domain_info *info; - unsigned long flags; =20 - spin_lock_irqsave(&device_domain_lock, flags); info =3D dev_iommu_priv_get(dev); if (info) __dmar_remove_one_dev_info(info); - spin_unlock_irqrestore(&device_domain_lock, flags); } =20 static int md_domain_init(struct dmar_domain *domain, int guest_width) @@ -4529,6 +4509,7 @@ static struct iommu_device *intel_iommu_probe_device(= struct device *dev) =20 info->dev =3D dev; info->iommu =3D iommu; + init_rcu_head(&info->rcu); if (dev_is_pci(dev)) { if (ecap_dev_iotlb_support(iommu->ecap) && pci_ats_supported(pdev) && @@ -4553,7 +4534,7 @@ static struct iommu_device *intel_iommu_probe_device(= struct device *dev) devi_idx(info->segment, info->bus, info->devfn), info, GFP_KERNEL); if (xa_err(curr) || WARN_ON(curr)) { - kfree(info); + kfree_rcu(info, rcu); return ERR_PTR(-ENOSPC); } =20 @@ -4565,17 +4546,13 @@ static struct iommu_device *intel_iommu_probe_devic= e(struct device *dev) static void intel_iommu_release_device(struct device *dev) { struct device_domain_info *info =3D dev_iommu_priv_get(dev); - unsigned long flags; =20 dmar_remove_one_dev_info(dev); =20 - spin_lock_irqsave(&device_domain_lock, flags); dev_iommu_priv_set(dev, NULL); xa_erase(&device_domain_array, devi_idx(info->segment, info->bus, info->devfn)); - spin_unlock_irqrestore(&device_domain_lock, flags); - - kfree(info); + kfree_rcu(info, rcu); set_dma_ops(dev, NULL); } =20 @@ -4655,9 +4632,7 @@ int intel_iommu_enable_pasid(struct intel_iommu *iomm= u, struct device *dev) if (!domain) return -EINVAL; =20 - spin_lock_irqsave(&device_domain_lock, flags); - spin_lock(&iommu->lock); - + spin_lock_irqsave(&iommu->lock, flags); ret =3D -EINVAL; if (!info->pasid_supported) goto out; @@ -4686,8 +4661,7 @@ int intel_iommu_enable_pasid(struct intel_iommu *iomm= u, struct device *dev) ret =3D 0; =20 out: - spin_unlock(&iommu->lock); - spin_unlock_irqrestore(&device_domain_lock, flags); + spin_unlock_irqrestore(&iommu->lock, flags); =20 return ret; } --=20 2.25.1