From nobody Sat Apr 25 11:48:02 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 3C39BC43334 for ; Tue, 12 Jul 2022 00:13:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231451AbiGLANq (ORCPT ); Mon, 11 Jul 2022 20:13:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48936 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229657AbiGLANm (ORCPT ); Mon, 11 Jul 2022 20:13:42 -0400 Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 958A3CFB for ; Mon, 11 Jul 2022 17:13:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1657584821; x=1689120821; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=zL0sNIu0hR/7q129LGe91BkLQRpbxXeLJ8hwcGWo304=; b=FCrueAwGcPKHA9KuJhnC53wTe46ybQJTsZkOS1ugVJ345WZoKLnNre5f DouevFp6MatJA9cXHFKbP142w1JXBOH27hweeERNIlIqelqhXAcLwp6ye xTd+voMUVwBMmDhw+Tz25MTkpcDK6WRmWQhgbu95rRxSJVNZJSLYTFxmS L5FvXa0oXBy9GkjDmZpALfElHite12eCNTNPhjtDbCr61aiRg4c/LuCBt x+sIkxqF5mQQDrmvFPVb2u2qS0w4YffnXU+PgDnEkWoy2pqvLVhrKAS4E cYHuiNk9nkuEnG7X5k9mx3oi6g+0WBZSEDA2w4pUxVAI0Fpj9GOojPQGl w==; X-IronPort-AV: E=McAfee;i="6400,9594,10405"; a="284827864" X-IronPort-AV: E=Sophos;i="5.92,264,1650956400"; d="scan'208";a="284827864" Received: from orsmga007.jf.intel.com ([10.7.209.58]) by fmsmga103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 Jul 2022 17:13:41 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.92,264,1650956400"; d="scan'208";a="592445683" Received: from allen-box.sh.intel.com ([10.239.159.48]) by orsmga007.jf.intel.com with ESMTP; 11 Jul 2022 17:13:40 -0700 From: Lu Baolu To: Joerg Roedel Cc: iommu@lists.linux.dev, linux-kernel@vger.kernel.org Subject: [PATCH 01/25] iommu/vt-d: Move trace/events/intel_iommu.h under iommu Date: Tue, 12 Jul 2022 08:08:44 +0800 Message-Id: <20220712000908.3431936-2-baolu.lu@linux.intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220712000908.3431936-1-baolu.lu@linux.intel.com> References: <20220712000908.3431936-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 header file is private to the Intel IOMMU driver. Move it to the driver folder. Signed-off-by: Lu Baolu Reviewed-by: Christoph Hellwig Reviewed-by: Jason Gunthorpe Reviewed-by: Steve Wahl Link: https://lore.kernel.org/r/20220514014322.2927339-2-baolu.lu@linux.int= el.com --- .../trace/events/intel_iommu.h =3D> drivers/iommu/intel/trace.h | 4 ++++ drivers/iommu/intel/dmar.c | 2 +- drivers/iommu/intel/svm.c | 2 +- drivers/iommu/intel/trace.c | 2 +- 4 files changed, 7 insertions(+), 3 deletions(-) rename include/trace/events/intel_iommu.h =3D> drivers/iommu/intel/trace.h= (94%) diff --git a/include/trace/events/intel_iommu.h b/drivers/iommu/intel/trace= .h similarity index 94% rename from include/trace/events/intel_iommu.h rename to drivers/iommu/intel/trace.h index e5c1ca6d16ee..25cb7f88e1a2 100644 --- a/include/trace/events/intel_iommu.h +++ b/drivers/iommu/intel/trace.h @@ -91,4 +91,8 @@ TRACE_EVENT(prq_report, #endif /* _TRACE_INTEL_IOMMU_H */ =20 /* This part must be outside protection */ +#undef TRACE_INCLUDE_PATH +#undef TRACE_INCLUDE_FILE +#define TRACE_INCLUDE_PATH ../../drivers/iommu/intel/ +#define TRACE_INCLUDE_FILE trace #include diff --git a/drivers/iommu/intel/dmar.c b/drivers/iommu/intel/dmar.c index 9699ca101c62..f91b45be1d92 100644 --- a/drivers/iommu/intel/dmar.c +++ b/drivers/iommu/intel/dmar.c @@ -30,10 +30,10 @@ #include #include #include -#include =20 #include "../irq_remapping.h" #include "perf.h" +#include "trace.h" =20 typedef int (*dmar_res_handler_t)(struct acpi_dmar_header *, void *); struct dmar_res_callback { diff --git a/drivers/iommu/intel/svm.c b/drivers/iommu/intel/svm.c index 7ee37d996e15..70b40d007a52 100644 --- a/drivers/iommu/intel/svm.c +++ b/drivers/iommu/intel/svm.c @@ -21,11 +21,11 @@ #include #include #include -#include =20 #include "pasid.h" #include "perf.h" #include "../iommu-sva-lib.h" +#include "trace.h" =20 static irqreturn_t prq_event_thread(int irq, void *d); static void intel_svm_drain_prq(struct device *dev, u32 pasid); diff --git a/drivers/iommu/intel/trace.c b/drivers/iommu/intel/trace.c index bfb6a6e37a88..117e626e3ea9 100644 --- a/drivers/iommu/intel/trace.c +++ b/drivers/iommu/intel/trace.c @@ -11,4 +11,4 @@ #include =20 #define CREATE_TRACE_POINTS -#include +#include "trace.h" --=20 2.25.1 From nobody Sat Apr 25 11:48:02 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 33953C43334 for ; Tue, 12 Jul 2022 00:13:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231659AbiGLANv (ORCPT ); Mon, 11 Jul 2022 20:13:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48938 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229670AbiGLANo (ORCPT ); Mon, 11 Jul 2022 20:13:44 -0400 Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 98DE1EB3 for ; Mon, 11 Jul 2022 17:13:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1657584822; x=1689120822; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=eG1dMwRZBBGiJ/exhj5l7l6h4h7y0PvHPNn95XiHisA=; b=QIDcU/gbQZ69L+o2qEsZEg4jts46UjxJ0KCU0+WhrvufOM2k35iN59P+ VrdMNPJr8rwZj4gpAi929/eM72DdiSRIkiOSqtpI7bcCa/VeVDakmuxte 4aYfAvEbdEHqhazp0UmQz6mUnLGGfpv3fJyKHwh3K5Fpt440MpZgTNVU/ RdvIrp57HK/tf6XIELrAlx6yEGd3YkK+ecSuNMJ0u3G5x4m0CfpgA5Bwj xeArJPdmM/QRMXjbRTJjuR9WuWsakIfydUhW3BNAOXIziPLOCh7MDJJkG YRjNnoN0hnJriCBzDQ0+iCLoaNImlwVjt/rzxD75wMTLk2IT/f4Yj63Tg g==; X-IronPort-AV: E=McAfee;i="6400,9594,10405"; a="284827875" X-IronPort-AV: E=Sophos;i="5.92,264,1650956400"; d="scan'208";a="284827875" Received: from orsmga007.jf.intel.com ([10.7.209.58]) by fmsmga103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 Jul 2022 17:13:42 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.92,264,1650956400"; d="scan'208";a="592445685" Received: from allen-box.sh.intel.com ([10.239.159.48]) by orsmga007.jf.intel.com with ESMTP; 11 Jul 2022 17:13:41 -0700 From: Lu Baolu To: Joerg Roedel Cc: iommu@lists.linux.dev, linux-kernel@vger.kernel.org Subject: [PATCH 02/25] agp/intel: Use per device iommu check Date: Tue, 12 Jul 2022 08:08:45 +0800 Message-Id: <20220712000908.3431936-3-baolu.lu@linux.intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220712000908.3431936-1-baolu.lu@linux.intel.com> References: <20220712000908.3431936-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 IOMMU subsystem has already provided an interface to query whether the IOMMU hardware is enabled for a specific device. This changes the check from Intel specific intel_iommu_gfx_mapped (globally exported by the Intel IOMMU driver) to probing the presence of IOMMU on a specific device using the generic device_iommu_mapped(). This follows commit cca084692394a ("drm/i915: Use per device iommu check") which converted drm/i915 driver to use device_iommu_mapped(). Signed-off-by: Lu Baolu Reviewed-by: Christoph Hellwig Reviewed-by: Jason Gunthorpe Reviewed-by: Steve Wahl Link: https://lore.kernel.org/r/20220514014322.2927339-3-baolu.lu@linux.int= el.com --- drivers/char/agp/intel-gtt.c | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/drivers/char/agp/intel-gtt.c b/drivers/char/agp/intel-gtt.c index 79a1b65527c2..cfcb450e9b59 100644 --- a/drivers/char/agp/intel-gtt.c +++ b/drivers/char/agp/intel-gtt.c @@ -20,7 +20,7 @@ #include #include #include -#include +#include #include #include #include "agp.h" @@ -573,18 +573,15 @@ static void intel_gtt_cleanup(void) */ static inline int needs_ilk_vtd_wa(void) { -#ifdef CONFIG_INTEL_IOMMU const unsigned short gpu_devid =3D intel_private.pcidev->device; =20 - /* Query intel_iommu to see if we need the workaround. Presumably that - * was loaded first. + /* + * Query iommu subsystem to see if we need the workaround. Presumably + * that was loaded first. */ - if ((gpu_devid =3D=3D PCI_DEVICE_ID_INTEL_IRONLAKE_D_IG || - gpu_devid =3D=3D PCI_DEVICE_ID_INTEL_IRONLAKE_M_IG) && - intel_iommu_gfx_mapped) - return 1; -#endif - return 0; + return ((gpu_devid =3D=3D PCI_DEVICE_ID_INTEL_IRONLAKE_D_IG || + gpu_devid =3D=3D PCI_DEVICE_ID_INTEL_IRONLAKE_M_IG) && + device_iommu_mapped(&intel_private.pcidev->dev)); } =20 static bool intel_gtt_can_wc(void) --=20 2.25.1 From nobody Sat Apr 25 11:48:02 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 C290CC43334 for ; Tue, 12 Jul 2022 00:13:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230353AbiGLANy (ORCPT ); Mon, 11 Jul 2022 20:13:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48966 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229721AbiGLANo (ORCPT ); Mon, 11 Jul 2022 20:13:44 -0400 Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EE96BBC82 for ; Mon, 11 Jul 2022 17:13:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1657584823; x=1689120823; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=uu6VWplyJC0WtS10OxO4TZ5+WvHrBkUqwlK1Uir6SUE=; b=GsWfNQKlVUQim7tR37G9NTMwiaJV7r6wV8AGsLtj/RVwCMlSv4Sach2v ho3DdQXmnrKs43vGcvGN3hKWfxMwyXdi5EvUS1y5jzLek988zcXZwz/Rz kZVFL8ebPFxvSQyxodMlqpRF2oJd3iNvt5zZgkj7k4GVNBOTjAOiULUjX E9X3nTerOD8/SFdIEtQLThvBp3VLj/z+ZOHhZVl2yUwt+l9KBTd55kyyf usnmtjQrt1x4kiqpwQOir880hiUVVyZ3J3t/deSPV3KTiRDo8o610lJoW xb7Q2aPiqxRn0giQa2B3en5rojDzZXrhBGMzs0dAlYBAlDRXUTLNaW+GE w==; X-IronPort-AV: E=McAfee;i="6400,9594,10405"; a="284827883" X-IronPort-AV: E=Sophos;i="5.92,264,1650956400"; d="scan'208";a="284827883" Received: from orsmga007.jf.intel.com ([10.7.209.58]) by fmsmga103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 Jul 2022 17:13:43 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.92,264,1650956400"; d="scan'208";a="592445691" Received: from allen-box.sh.intel.com ([10.239.159.48]) by orsmga007.jf.intel.com with ESMTP; 11 Jul 2022 17:13:42 -0700 From: Lu Baolu To: Joerg Roedel Cc: iommu@lists.linux.dev, linux-kernel@vger.kernel.org Subject: [PATCH 03/25] iommu/vt-d: Remove unnecessary exported symbol Date: Tue, 12 Jul 2022 08:08:46 +0800 Message-Id: <20220712000908.3431936-4-baolu.lu@linux.intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220712000908.3431936-1-baolu.lu@linux.intel.com> References: <20220712000908.3431936-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 exported symbol intel_iommu_gfx_mapped is not used anywhere in the tree. Remove it to avoid dead code. Signed-off-by: Lu Baolu Reviewed-by: Christoph Hellwig Reviewed-by: Jason Gunthorpe Reviewed-by: Steve Wahl Link: https://lore.kernel.org/r/20220514014322.2927339-4-baolu.lu@linux.int= el.com --- include/linux/intel-iommu.h | 1 - drivers/iommu/intel/iommu.c | 6 ------ 2 files changed, 7 deletions(-) diff --git a/include/linux/intel-iommu.h b/include/linux/intel-iommu.h index 5fcf89faa31a..4ebf3c4da45e 100644 --- a/include/linux/intel-iommu.h +++ b/include/linux/intel-iommu.h @@ -787,7 +787,6 @@ extern int iommu_calculate_agaw(struct intel_iommu *iom= mu); extern int iommu_calculate_max_sagaw(struct intel_iommu *iommu); extern int dmar_disabled; extern int intel_iommu_enabled; -extern int intel_iommu_gfx_mapped; #else static inline int iommu_calculate_agaw(struct intel_iommu *iommu) { diff --git a/drivers/iommu/intel/iommu.c b/drivers/iommu/intel/iommu.c index 5c0dce78586a..6564af7ec0dd 100644 --- a/drivers/iommu/intel/iommu.c +++ b/drivers/iommu/intel/iommu.c @@ -314,9 +314,6 @@ static int iommu_skip_te_disable; #define IDENTMAP_GFX 2 #define IDENTMAP_AZALIA 4 =20 -int intel_iommu_gfx_mapped; -EXPORT_SYMBOL_GPL(intel_iommu_gfx_mapped); - DEFINE_SPINLOCK(device_domain_lock); static LIST_HEAD(device_domain_list); =20 @@ -4093,9 +4090,6 @@ int __init intel_iommu_init(void) if (list_empty(&dmar_satc_units)) pr_info("No SATC found\n"); =20 - if (dmar_map_gfx) - intel_iommu_gfx_mapped =3D 1; - init_no_remapping_devices(); =20 ret =3D init_dmars(); --=20 2.25.1 From nobody Sat Apr 25 11:48:02 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 4A07AC43334 for ; Tue, 12 Jul 2022 00:14:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231707AbiGLAN6 (ORCPT ); Mon, 11 Jul 2022 20:13:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49128 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231145AbiGLANq (ORCPT ); Mon, 11 Jul 2022 20:13:46 -0400 Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 19491CFB for ; Mon, 11 Jul 2022 17:13:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1657584825; x=1689120825; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=b1VeSJDIT9XeF1FzLfvrql3G8Neer6XxZf/wBpgqjdM=; b=PxAfizZL0RehlnxEvZPcsTKsQADYPi2gMnRfEuQCUo0SPbD8R/Wnf9Dz P6ViITFciGkIWFEw6WWnf94bc8EGlwMKXFHmMD0U8aSUgLwLOezT3aQqL Cuylr7XJPn5bGM7WhOLZHKqTM2/glmV/rU0dN9BIzrGQybsruAvlHLChK P/5D0b8/YzTq1TiLEcy5Wa+4FBNKXiO1efg22eUZY45wA4xrAnElYamDl rJw5TSXZQfJpiirJNCC7Ad6vU13e1Hr4lgthe+gVO+KgvgEfK5jPw7Ikm tpYlGDGttYVGVUgHryZY8jMOScrgz9oW7kr25a9VuBhSMxDRzlqmytkJO Q==; X-IronPort-AV: E=McAfee;i="6400,9594,10405"; a="284827889" X-IronPort-AV: E=Sophos;i="5.92,264,1650956400"; d="scan'208";a="284827889" Received: from orsmga007.jf.intel.com ([10.7.209.58]) by fmsmga103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 Jul 2022 17:13:44 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.92,264,1650956400"; d="scan'208";a="592445694" Received: from allen-box.sh.intel.com ([10.239.159.48]) by orsmga007.jf.intel.com with ESMTP; 11 Jul 2022 17:13:43 -0700 From: Lu Baolu To: Joerg Roedel Cc: iommu@lists.linux.dev, linux-kernel@vger.kernel.org Subject: [PATCH 04/25] drm/i915: Remove unnecessary include Date: Tue, 12 Jul 2022 08:08:47 +0800 Message-Id: <20220712000908.3431936-5-baolu.lu@linux.intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220712000908.3431936-1-baolu.lu@linux.intel.com> References: <20220712000908.3431936-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" intel-iommu.h is not needed in drm/i915 anymore. Remove its include. Signed-off-by: Lu Baolu Reviewed-by: Steve Wahl Reviewed-by: Christoph Hellwig Reviewed-by: Jason Gunthorpe Acked-by: Jani Nikula Link: https://lore.kernel.org/r/20220514014322.2927339-5-baolu.lu@linux.int= el.com --- drivers/gpu/drm/i915/display/intel_display.c | 1 - drivers/gpu/drm/i915/gem/i915_gem_execbuffer.c | 1 - 2 files changed, 2 deletions(-) diff --git a/drivers/gpu/drm/i915/display/intel_display.c b/drivers/gpu/drm= /i915/display/intel_display.c index 806d50b302ab..493421759afa 100644 --- a/drivers/gpu/drm/i915/display/intel_display.c +++ b/drivers/gpu/drm/i915/display/intel_display.c @@ -27,7 +27,6 @@ #include #include #include -#include #include #include #include diff --git a/drivers/gpu/drm/i915/gem/i915_gem_execbuffer.c b/drivers/gpu/d= rm/i915/gem/i915_gem_execbuffer.c index 30fe847c6664..193c7c83c70f 100644 --- a/drivers/gpu/drm/i915/gem/i915_gem_execbuffer.c +++ b/drivers/gpu/drm/i915/gem/i915_gem_execbuffer.c @@ -6,7 +6,6 @@ =20 #include #include -#include #include #include =20 --=20 2.25.1 From nobody Sat Apr 25 11:48:02 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 9DE51C433EF for ; Tue, 12 Jul 2022 00:14:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231744AbiGLAOC (ORCPT ); Mon, 11 Jul 2022 20:14:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49144 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230136AbiGLANr (ORCPT ); Mon, 11 Jul 2022 20:13:47 -0400 Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2807CDEBB for ; Mon, 11 Jul 2022 17:13:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1657584826; x=1689120826; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=U/6SSeJyFt4HtQDZKoE6TalrVcffk6vqEeNrwtMJkjI=; b=AnsT8QdFU+arUduJSTKz5chnGji3HyvUMymLVZ28VAh7ld+GJxR77MHZ i7hNJ+oZ7oqj/piJ8xZf3eCx3gFuLZ9grkg/EY39iNkfm826lUbhcIJh8 ZFUJ/gkzNCGf23NOGzNfRdzFiieMbyHFyUohXUe6sjg8cx6t+G9v12Fvw BVvLAdvegjvr2tg6lylHgPfVSdyCtICx7xgdMIUynscNNzGaAQjJX8bv3 4PR/AlNFZ2iMN84imvx8k5/iaY4COvCKWTSXHpie4EDrqykSj03pFkgeb wBG+Vm9aQDm4529l/FQqApJsOnXFGlhQdiB534SwAlMv+Lm3pZSBCM3IC A==; X-IronPort-AV: E=McAfee;i="6400,9594,10405"; a="284827896" X-IronPort-AV: E=Sophos;i="5.92,264,1650956400"; d="scan'208";a="284827896" Received: from orsmga007.jf.intel.com ([10.7.209.58]) by fmsmga103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 Jul 2022 17:13:45 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.92,264,1650956400"; d="scan'208";a="592445701" Received: from allen-box.sh.intel.com ([10.239.159.48]) by orsmga007.jf.intel.com with ESMTP; 11 Jul 2022 17:13:44 -0700 From: Lu Baolu To: Joerg Roedel Cc: iommu@lists.linux.dev, linux-kernel@vger.kernel.org Subject: [PATCH 05/25] KVM: x86: Remove unnecessary include Date: Tue, 12 Jul 2022 08:08:48 +0800 Message-Id: <20220712000908.3431936-6-baolu.lu@linux.intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220712000908.3431936-1-baolu.lu@linux.intel.com> References: <20220712000908.3431936-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" intel-iommu.h is not needed in kvm/x86 anymore. Remove its include. Signed-off-by: Lu Baolu Reviewed-by: Christoph Hellwig Reviewed-by: Jason Gunthorpe Reviewed-by: Steve Wahl Link: https://lore.kernel.org/r/20220514014322.2927339-6-baolu.lu@linux.int= el.com --- arch/x86/kvm/x86.c | 1 - 1 file changed, 1 deletion(-) diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index 1910e1e78b15..f7ec1e39eec7 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -41,7 +41,6 @@ #include #include #include -#include #include #include #include --=20 2.25.1 From nobody Sat Apr 25 11:48:02 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 5E010C433EF for ; Tue, 12 Jul 2022 00:14:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231682AbiGLAOH (ORCPT ); Mon, 11 Jul 2022 20:14:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49174 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231601AbiGLANs (ORCPT ); Mon, 11 Jul 2022 20:13:48 -0400 Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 47D8ACFB for ; Mon, 11 Jul 2022 17:13:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1657584827; x=1689120827; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=qHJmFrLLUxOirz4GJC/4U7xWCuECOoNr1MnGlU4dmuk=; b=HyKo00oqyRtzifdAUN9xpXp0+rtBPQ4LyOET9ABfjggIv/2zjzYZU6YF vfIZi72OPsqrPBdSvpCJsNE+rRXgLD6HaYYKD8HX1WEFBVLFB8K+otSOp eNC6oT2QfSUCmpsAlTuMXg3zQgPwFeTUfPWZQsbndMQwg8HRZjF+w1X5W 13XpAxnMUoKu88ptEQQ3jGq3hWfTcdeZDJBIFEmjxgV74yLXTkTmWWDxF x/XUwfQ5/AF4ISQsKM91LFcyG2eFfBU4hJCh2G2TtkysxfatX4fRt4Xc1 c3AEKcSqoXwwOxl3NQRsxwQJ/pgqkCKbl1/GcXTmyywuprkYK0ot0tP9l Q==; X-IronPort-AV: E=McAfee;i="6400,9594,10405"; a="284827901" X-IronPort-AV: E=Sophos;i="5.92,264,1650956400"; d="scan'208";a="284827901" Received: from orsmga007.jf.intel.com ([10.7.209.58]) by fmsmga103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 Jul 2022 17:13:47 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.92,264,1650956400"; d="scan'208";a="592445704" Received: from allen-box.sh.intel.com ([10.239.159.48]) by orsmga007.jf.intel.com with ESMTP; 11 Jul 2022 17:13:46 -0700 From: Lu Baolu To: Joerg Roedel Cc: iommu@lists.linux.dev, linux-kernel@vger.kernel.org Subject: [PATCH 06/25] x86/boot/tboot: Move tboot_force_iommu() to Intel IOMMU Date: Tue, 12 Jul 2022 08:08:49 +0800 Message-Id: <20220712000908.3431936-7-baolu.lu@linux.intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220712000908.3431936-1-baolu.lu@linux.intel.com> References: <20220712000908.3431936-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" tboot_force_iommu() is only called by the Intel IOMMU driver. Move the helper into that driver. No functional change intended. Signed-off-by: Lu Baolu Reviewed-by: Christoph Hellwig Reviewed-by: Jason Gunthorpe Reviewed-by: Steve Wahl Link: https://lore.kernel.org/r/20220514014322.2927339-7-baolu.lu@linux.int= el.com --- include/linux/tboot.h | 2 -- arch/x86/kernel/tboot.c | 15 --------------- drivers/iommu/intel/iommu.c | 14 ++++++++++++++ 3 files changed, 14 insertions(+), 17 deletions(-) diff --git a/include/linux/tboot.h b/include/linux/tboot.h index 5146d2574e85..d2279160ef39 100644 --- a/include/linux/tboot.h +++ b/include/linux/tboot.h @@ -126,7 +126,6 @@ extern void tboot_probe(void); extern void tboot_shutdown(u32 shutdown_type); extern struct acpi_table_header *tboot_get_dmar_table( struct acpi_table_header *dmar_tbl); -extern int tboot_force_iommu(void); =20 #else =20 @@ -136,7 +135,6 @@ extern int tboot_force_iommu(void); #define tboot_sleep(sleep_state, pm1a_control, pm1b_control) \ do { } while (0) #define tboot_get_dmar_table(dmar_tbl) (dmar_tbl) -#define tboot_force_iommu() 0 =20 #endif /* !CONFIG_INTEL_TXT */ =20 diff --git a/arch/x86/kernel/tboot.c b/arch/x86/kernel/tboot.c index 0c1154a1c403..3bacd935f840 100644 --- a/arch/x86/kernel/tboot.c +++ b/arch/x86/kernel/tboot.c @@ -6,7 +6,6 @@ * Copyright (c) 2006-2009, Intel Corporation */ =20 -#include #include #include #include @@ -516,17 +515,3 @@ struct acpi_table_header *tboot_get_dmar_table(struct = acpi_table_header *dmar_tb =20 return dmar_tbl; } - -int tboot_force_iommu(void) -{ - if (!tboot_enabled()) - return 0; - - if (no_iommu || dmar_disabled) - pr_warn("Forcing Intel-IOMMU to enabled\n"); - - dmar_disabled =3D 0; - no_iommu =3D 0; - - return 1; -} diff --git a/drivers/iommu/intel/iommu.c b/drivers/iommu/intel/iommu.c index 6564af7ec0dd..c70948021e8e 100644 --- a/drivers/iommu/intel/iommu.c +++ b/drivers/iommu/intel/iommu.c @@ -4019,6 +4019,20 @@ static int __init probe_acpi_namespace_devices(void) return 0; } =20 +static __init int tboot_force_iommu(void) +{ + if (!tboot_enabled()) + return 0; + + if (no_iommu || dmar_disabled) + pr_warn("Forcing Intel-IOMMU to enabled\n"); + + dmar_disabled =3D 0; + no_iommu =3D 0; + + return 1; +} + int __init intel_iommu_init(void) { int ret =3D -ENODEV; --=20 2.25.1 From nobody Sat Apr 25 11:48:02 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 C33F9C43334 for ; Tue, 12 Jul 2022 00:14:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231800AbiGLAOJ (ORCPT ); Mon, 11 Jul 2022 20:14:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49234 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229835AbiGLANt (ORCPT ); Mon, 11 Jul 2022 20:13:49 -0400 Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B9335E09D for ; Mon, 11 Jul 2022 17:13:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1657584828; x=1689120828; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=M97alGPHahpFMJq5hktdoW+S1aLfwbqCfek6UlykYlk=; b=RWF02nTk6WoZTW36N7kAH0h2ZPsfie7DYpJySJI3XT4JFpsRZpEJ3viG 8mRDP1yUvzSS9rEjk/OgF37LBT+dMbrWaXwpHZwLXZnKDJ37fC88LX3LX G0HckOIih54Mr/dcxrS5bU4x0e0IC8r4dNfn+26UlFhGFKK06v4098A1h srzGRQupv0IlifPcgwHd1WzHSQpdqb1QOuea8ybmUGtxtDusR14TAVRbS /Snfc85gawxKcmW8Qxpk/Lq9MunKNjC2i3OxPCt2uPZevgWczJ4GXQI2S j1U9H1ou/1OnLBRTL492m+OUUHxo0G2H9fiB4XhkWsCcOyzrCDM7qaInR w==; X-IronPort-AV: E=McAfee;i="6400,9594,10405"; a="284827913" X-IronPort-AV: E=Sophos;i="5.92,264,1650956400"; d="scan'208";a="284827913" Received: from orsmga007.jf.intel.com ([10.7.209.58]) by fmsmga103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 Jul 2022 17:13:48 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.92,264,1650956400"; d="scan'208";a="592445705" Received: from allen-box.sh.intel.com ([10.239.159.48]) by orsmga007.jf.intel.com with ESMTP; 11 Jul 2022 17:13:47 -0700 From: Lu Baolu To: Joerg Roedel Cc: iommu@lists.linux.dev, linux-kernel@vger.kernel.org Subject: [PATCH 07/25] iommu/vt-d: Move include/linux/intel-iommu.h under iommu Date: Tue, 12 Jul 2022 08:08:50 +0800 Message-Id: <20220712000908.3431936-8-baolu.lu@linux.intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220712000908.3431936-1-baolu.lu@linux.intel.com> References: <20220712000908.3431936-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 header file is private to the Intel IOMMU driver. Move it to the driver folder. Signed-off-by: Lu Baolu Reviewed-by: Christoph Hellwig Reviewed-by: Jason Gunthorpe Reviewed-by: Steve Wahl Link: https://lore.kernel.org/r/20220514014322.2927339-8-baolu.lu@linux.int= el.com --- include/linux/intel-iommu.h =3D> drivers/iommu/intel/iommu.h | 0 drivers/iommu/intel/trace.h | 3 ++- drivers/iommu/intel/cap_audit.c | 2 +- drivers/iommu/intel/debugfs.c | 2 +- drivers/iommu/intel/dmar.c | 2 +- drivers/iommu/intel/iommu.c | 2 +- drivers/iommu/intel/irq_remapping.c | 2 +- drivers/iommu/intel/pasid.c | 2 +- drivers/iommu/intel/perf.c | 2 +- drivers/iommu/intel/svm.c | 2 +- MAINTAINERS | 1 - 11 files changed, 10 insertions(+), 10 deletions(-) rename include/linux/intel-iommu.h =3D> drivers/iommu/intel/iommu.h (100%) diff --git a/include/linux/intel-iommu.h b/drivers/iommu/intel/iommu.h similarity index 100% rename from include/linux/intel-iommu.h rename to drivers/iommu/intel/iommu.h diff --git a/drivers/iommu/intel/trace.h b/drivers/iommu/intel/trace.h index 25cb7f88e1a2..93d96f93a89b 100644 --- a/drivers/iommu/intel/trace.h +++ b/drivers/iommu/intel/trace.h @@ -13,7 +13,8 @@ #define _TRACE_INTEL_IOMMU_H =20 #include -#include + +#include "iommu.h" =20 #define MSG_MAX 256 =20 diff --git a/drivers/iommu/intel/cap_audit.c b/drivers/iommu/intel/cap_audi= t.c index 71596fc62822..3ee68393122f 100644 --- a/drivers/iommu/intel/cap_audit.c +++ b/drivers/iommu/intel/cap_audit.c @@ -10,7 +10,7 @@ =20 #define pr_fmt(fmt) "DMAR: " fmt =20 -#include +#include "iommu.h" #include "cap_audit.h" =20 static u64 intel_iommu_cap_sanity; diff --git a/drivers/iommu/intel/debugfs.c b/drivers/iommu/intel/debugfs.c index ed796eea4581..d927ef10641b 100644 --- a/drivers/iommu/intel/debugfs.c +++ b/drivers/iommu/intel/debugfs.c @@ -10,11 +10,11 @@ =20 #include #include -#include #include =20 #include =20 +#include "iommu.h" #include "pasid.h" #include "perf.h" =20 diff --git a/drivers/iommu/intel/dmar.c b/drivers/iommu/intel/dmar.c index f91b45be1d92..2a5e0f91e647 100644 --- a/drivers/iommu/intel/dmar.c +++ b/drivers/iommu/intel/dmar.c @@ -19,7 +19,6 @@ #include #include #include -#include #include #include #include @@ -31,6 +30,7 @@ #include #include =20 +#include "iommu.h" #include "../irq_remapping.h" #include "perf.h" #include "trace.h" diff --git a/drivers/iommu/intel/iommu.c b/drivers/iommu/intel/iommu.c index c70948021e8e..10bda4bec8fe 100644 --- a/drivers/iommu/intel/iommu.c +++ b/drivers/iommu/intel/iommu.c @@ -17,7 +17,6 @@ #include #include #include -#include #include #include #include @@ -26,6 +25,7 @@ #include #include =20 +#include "iommu.h" #include "../irq_remapping.h" #include "../iommu-sva-lib.h" #include "pasid.h" diff --git a/drivers/iommu/intel/irq_remapping.c b/drivers/iommu/intel/irq_= remapping.c index a67319597884..2e9683e970f8 100644 --- a/drivers/iommu/intel/irq_remapping.c +++ b/drivers/iommu/intel/irq_remapping.c @@ -10,7 +10,6 @@ #include #include #include -#include #include #include #include @@ -21,6 +20,7 @@ #include #include =20 +#include "iommu.h" #include "../irq_remapping.h" #include "cap_audit.h" =20 diff --git a/drivers/iommu/intel/pasid.c b/drivers/iommu/intel/pasid.c index 17cad7c1f62d..43f090381ec7 100644 --- a/drivers/iommu/intel/pasid.c +++ b/drivers/iommu/intel/pasid.c @@ -12,13 +12,13 @@ #include #include #include -#include #include #include #include #include #include =20 +#include "iommu.h" #include "pasid.h" =20 /* diff --git a/drivers/iommu/intel/perf.c b/drivers/iommu/intel/perf.c index 0e8e03252d92..94ee70ac38e3 100644 --- a/drivers/iommu/intel/perf.c +++ b/drivers/iommu/intel/perf.c @@ -9,8 +9,8 @@ */ =20 #include -#include =20 +#include "iommu.h" #include "perf.h" =20 static DEFINE_SPINLOCK(latency_lock); diff --git a/drivers/iommu/intel/svm.c b/drivers/iommu/intel/svm.c index 70b40d007a52..580713aa9e07 100644 --- a/drivers/iommu/intel/svm.c +++ b/drivers/iommu/intel/svm.c @@ -5,7 +5,6 @@ * Authors: David Woodhouse */ =20 -#include #include #include #include @@ -22,6 +21,7 @@ #include #include =20 +#include "iommu.h" #include "pasid.h" #include "perf.h" #include "../iommu-sva-lib.h" diff --git a/MAINTAINERS b/MAINTAINERS index ead381fdfc5a..fa2cde7dc644 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -9998,7 +9998,6 @@ L: iommu@lists.linux.dev S: Supported T: git git://git.kernel.org/pub/scm/linux/kernel/git/joro/iommu.git F: drivers/iommu/intel/ -F: include/linux/intel-iommu.h F: include/linux/intel-svm.h =20 INTEL IOP-ADMA DMA DRIVER --=20 2.25.1 From nobody Sat Apr 25 11:48:02 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 D4C6ACCA480 for ; Tue, 12 Jul 2022 00:14:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231839AbiGLAOL (ORCPT ); Mon, 11 Jul 2022 20:14:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49266 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231641AbiGLANu (ORCPT ); Mon, 11 Jul 2022 20:13:50 -0400 Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B0696EE17 for ; Mon, 11 Jul 2022 17:13:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1657584829; x=1689120829; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=NpRwK872iEsLurKjmmUKzy5zljzIR91UH4ONOmkOXB0=; b=AraBg2mOYwquLVZUQaUvqSHIAztfTx+VzA3nGMDJlmlV0YMo3MHcJWrv pvqvMX82HNK1v5ABItM4MxAKqJhEFwx9pZlqVLsdAhj1PknO2GA9yHYdc Tz4LEA4cdYx5lbnbT4PTcp7g9kDa/ziE9bNddH89CdZzPcIU/NG+2Ai6+ nLKLbvmNSJkE2ynfKGNrgk1zT3r82XCh9Jp9GVbGm/5d/uc0kgfK9H2Ht E/mT+YykOuWDjxWU44Umnpax/H5ReBgQp7iFdrwesVt9AmxOSUdRjqrC5 OjKf66OZx4U/8uF4jmwDofs5FBcumoqT+sK6Ieankdt8aoUaSizulkocV g==; X-IronPort-AV: E=McAfee;i="6400,9594,10405"; a="284827921" X-IronPort-AV: E=Sophos;i="5.92,264,1650956400"; d="scan'208";a="284827921" Received: from orsmga007.jf.intel.com ([10.7.209.58]) by fmsmga103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 Jul 2022 17:13:49 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.92,264,1650956400"; d="scan'208";a="592445717" Received: from allen-box.sh.intel.com ([10.239.159.48]) by orsmga007.jf.intel.com with ESMTP; 11 Jul 2022 17:13:48 -0700 From: Lu Baolu To: Joerg Roedel Cc: iommu@lists.linux.dev, linux-kernel@vger.kernel.org Subject: [PATCH 08/25] iommu/vt-d: Remove unused iovad from dmar_domain Date: Tue, 12 Jul 2022 08:08:51 +0800 Message-Id: <20220712000908.3431936-9-baolu.lu@linux.intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220712000908.3431936-1-baolu.lu@linux.intel.com> References: <20220712000908.3431936-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" Not used anywhere. Cleanup it to avoid dead code. Signed-off-by: Lu Baolu Link: https://lore.kernel.org/r/20220527053424.3111186-1-baolu.lu@linux.int= el.com --- drivers/iommu/intel/iommu.h | 1 - 1 file changed, 1 deletion(-) diff --git a/drivers/iommu/intel/iommu.h b/drivers/iommu/intel/iommu.h index 4ebf3c4da45e..8285fcfa5fea 100644 --- a/drivers/iommu/intel/iommu.h +++ b/drivers/iommu/intel/iommu.h @@ -543,7 +543,6 @@ struct dmar_domain { u8 set_pte_snp:1; =20 struct list_head devices; /* all devices' list */ - struct iova_domain iovad; /* iova's that belong to this domain */ =20 struct dma_pte *pgd; /* virtual address */ int gaw; /* max guest address width */ --=20 2.25.1 From nobody Sat Apr 25 11:48:02 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 7916AC433EF for ; Tue, 12 Jul 2022 00:14:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231797AbiGLAO1 (ORCPT ); Mon, 11 Jul 2022 20:14:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49726 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231892AbiGLAON (ORCPT ); Mon, 11 Jul 2022 20:14:13 -0400 Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8C8AB2253E for ; Mon, 11 Jul 2022 17:13:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1657584836; x=1689120836; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=lVXK6Iq000XAJQrKp2llUOsuHDocInUwavit7SYPBAo=; b=WrKzr1dt/LTUILltg1bg11VLB21I41d1fpYP5yIzZNPvbKt5kONHLmJD kljqQFo9UCpSjFH9DPxMiJOeWOaH4pqGe24Deh14ZjLBRVz1oR/vSUpDi 9AVW2KQW8p9mgjMOiAWrtZZforTdDjRc5MtE5lHM0mBuxatH9LHLQZRJh /snUKNYkd3XnPiFxCWNYO6xF3Bz3btXGVlVP39mPG34ge9BNnvi9di6ze EXR71KcHLmVSPOdKOivOBxGtJnNTznEauGwfF+4gYpjufTGfypYoWUOWE LS8CEW1koBGcPKsWAi1R5m1n2O81+JysxVE5KsjWnkwFuC1BxxXiY4rUv A==; X-IronPort-AV: E=McAfee;i="6400,9594,10405"; a="284827955" X-IronPort-AV: E=Sophos;i="5.92,264,1650956400"; d="scan'208";a="284827955" Received: from orsmga007.jf.intel.com ([10.7.209.58]) by fmsmga103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 Jul 2022 17:13:55 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.92,264,1650956400"; d="scan'208";a="592445722" Received: from allen-box.sh.intel.com ([10.239.159.48]) by orsmga007.jf.intel.com with ESMTP; 11 Jul 2022 17:13:49 -0700 From: Lu Baolu To: Joerg Roedel Cc: iommu@lists.linux.dev, linux-kernel@vger.kernel.org Subject: [PATCH 09/25] iommu/vt-d: debugfs: Remove device_domain_lock usage Date: Tue, 12 Jul 2022 08:08:52 +0800 Message-Id: <20220712000908.3431936-10-baolu.lu@linux.intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220712000908.3431936-1-baolu.lu@linux.intel.com> References: <20220712000908.3431936-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_translation_struct debugfs node is used to dump the DMAR page tables for the PCI devices. It potentially races with setting domains to devices. The existing code uses the global spinlock device_domain_lock to avoid the races. This removes the use of device_domain_lock outside of iommu.c by replacing it with the group mutex lock. Using the group mutex lock is cleaner and more compatible to following cleanups. Signed-off-by: Lu Baolu Reviewed-by: Kevin Tian Link: https://lore.kernel.org/r/20220706025524.2904370-2-baolu.lu@linux.int= el.com --- drivers/iommu/intel/iommu.h | 1 - drivers/iommu/intel/debugfs.c | 43 +++++++++++++++++++++++++---------- drivers/iommu/intel/iommu.c | 2 +- 3 files changed, 32 insertions(+), 14 deletions(-) diff --git a/drivers/iommu/intel/iommu.h b/drivers/iommu/intel/iommu.h index 8285fcfa5fea..8deb745d8b36 100644 --- a/drivers/iommu/intel/iommu.h +++ b/drivers/iommu/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) && \ diff --git a/drivers/iommu/intel/debugfs.c b/drivers/iommu/intel/debugfs.c index d927ef10641b..6e1a3f88abc8 100644 --- a/drivers/iommu/intel/debugfs.c +++ b/drivers/iommu/intel/debugfs.c @@ -342,13 +342,13 @@ static void pgtable_walk_level(struct seq_file *m, st= ruct dma_pte *pde, } } =20 -static int show_device_domain_translation(struct device *dev, void *data) +static int __show_device_domain_translation(struct device *dev, void *data) { - struct device_domain_info *info =3D dev_iommu_priv_get(dev); - struct dmar_domain *domain =3D info->domain; + struct dmar_domain *domain; struct seq_file *m =3D data; u64 path[6] =3D { 0 }; =20 + domain =3D to_dmar_domain(iommu_get_domain_for_dev(dev)); if (!domain) return 0; =20 @@ -359,20 +359,39 @@ static int show_device_domain_translation(struct devi= ce *dev, void *data) pgtable_walk_level(m, domain->pgd, domain->agaw + 2, 0, path); seq_putc(m, '\n'); =20 - return 0; + /* Don't iterate */ + return 1; } =20 -static int domain_translation_struct_show(struct seq_file *m, void *unused) +static int show_device_domain_translation(struct device *dev, void *data) { - unsigned long flags; - int ret; + struct iommu_group *group; =20 - 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); + group =3D iommu_group_get(dev); + if (group) { + /* + * The group->mutex is held across the callback, which will + * block calls to iommu_attach/detach_group/device. Hence, + * the domain of the device will not change during traversal. + * + * All devices in an iommu group share a single domain, hence + * we only dump the domain of the first device. Even though, + * this code still possibly races with the iommu_unmap() + * interface. This could be solved by RCU-freeing the page + * table pages in the iommu_unmap() path. + */ + iommu_group_for_each_dev(group, data, + __show_device_domain_translation); + iommu_group_put(group); + } =20 - return ret; + return 0; +} + +static int domain_translation_struct_show(struct seq_file *m, void *unused) +{ + 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 10bda4bec8fe..3b6571681bdd 100644 --- a/drivers/iommu/intel/iommu.c +++ b/drivers/iommu/intel/iommu.c @@ -314,7 +314,7 @@ static int iommu_skip_te_disable; #define IDENTMAP_GFX 2 #define IDENTMAP_AZALIA 4 =20 -DEFINE_SPINLOCK(device_domain_lock); +static DEFINE_SPINLOCK(device_domain_lock); static LIST_HEAD(device_domain_list); =20 const struct iommu_ops intel_iommu_ops; --=20 2.25.1 From nobody Sat Apr 25 11:48:02 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 1AAEDC43334 for ; Tue, 12 Jul 2022 00:14:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229606AbiGLAOf (ORCPT ); Mon, 11 Jul 2022 20:14:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50234 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229476AbiGLAOP (ORCPT ); Mon, 11 Jul 2022 20:14:15 -0400 Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 033611FCC0 for ; Mon, 11 Jul 2022 17:13:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1657584838; x=1689120838; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=JZxZdCVM9VdvZ5C9SB8NDFeX/+e0lgtKOLXXi+obFWY=; b=DNAcByYZuiehcwD/g6UC9+Snn/PEfITXECKboDU39RsMEXl7F0ibR1nG F5t8w0i4kFeABGQhBIj2LY/lcyB8ayUfgwVQNLtpPDhGuRBhTvqlcYk8M V6fw5RGgWBvH8m4xOFUZy96my/ZpR/RerEILK5pI4MyiNrvVfZoZCKYAZ aaqwBrh6LjdGoMPqRF9ILh4VAeKW2tqQ4XurIkQHwzTEzsM2sFgrAfOas xLzoXpUsA9pqBQl4PB/SuatfrdOo6OBdZToqZlci0Vg2T8nesa+B9kw7l 1uIr9BkTbBVJz1Zd4tVvfeUkHQgLLpXdaMLmVf4cFhRQEoPGUoo86Mgaw g==; X-IronPort-AV: E=McAfee;i="6400,9594,10405"; a="284827958" X-IronPort-AV: E=Sophos;i="5.92,264,1650956400"; d="scan'208";a="284827958" Received: from orsmga007.jf.intel.com ([10.7.209.58]) by fmsmga103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 Jul 2022 17:13:56 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.92,264,1650956400"; d="scan'208";a="592445746" Received: from allen-box.sh.intel.com ([10.239.159.48]) by orsmga007.jf.intel.com with ESMTP; 11 Jul 2022 17:13:54 -0700 From: Lu Baolu To: Joerg Roedel Cc: iommu@lists.linux.dev, linux-kernel@vger.kernel.org Subject: [PATCH 10/25] iommu/vt-d: Remove clearing translation data in disable_dmar_iommu() Date: Tue, 12 Jul 2022 08:08:53 +0800 Message-Id: <20220712000908.3431936-11-baolu.lu@linux.intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220712000908.3431936-1-baolu.lu@linux.intel.com> References: <20220712000908.3431936-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 disable_dmar_iommu() is called when IOMMU initialization fails or the IOMMU is hot-removed from the system. In both cases, there is no need to clear the IOMMU translation data structures for devices. On the initialization path, the device probing only happens after the IOMMU is initialized successfully, hence there're no translation data structures. On the hot-remove path, there is no real use case where the IOMMU is hot-removed, but the devices that it manages are still alive in the system. The translation data structures were torn down during device release, hence there's no need to repeat it in IOMMU hot-remove path either. This removes the unnecessary code and only leaves a check. Signed-off-by: Lu Baolu Reviewed-by: Kevin Tian Link: https://lore.kernel.org/r/20220706025524.2904370-3-baolu.lu@linux.int= el.com --- drivers/iommu/intel/pasid.h | 1 + drivers/iommu/intel/iommu.c | 21 +++++++-------------- 2 files changed, 8 insertions(+), 14 deletions(-) diff --git a/drivers/iommu/intel/pasid.h b/drivers/iommu/intel/pasid.h index bf5b937848b4..20c54e50f533 100644 --- a/drivers/iommu/intel/pasid.h +++ b/drivers/iommu/intel/pasid.h @@ -39,6 +39,7 @@ * only and pass-through transfer modes. */ #define FLPT_DEFAULT_DID 1 +#define NUM_RESERVED_DID 2 =20 /* * The SUPERVISOR_MODE flag indicates a first level translation which diff --git a/drivers/iommu/intel/iommu.c b/drivers/iommu/intel/iommu.c index 3b6571681bdd..43aaec5bdd84 100644 --- a/drivers/iommu/intel/iommu.c +++ b/drivers/iommu/intel/iommu.c @@ -1716,23 +1716,16 @@ 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; - if (!iommu->domain_ids) return; =20 - spin_lock_irqsave(&device_domain_lock, flags); - list_for_each_entry_safe(info, tmp, &device_domain_list, global) { - if (info->iommu !=3D iommu) - continue; - - if (!info->dev || !info->domain) - continue; - - __dmar_remove_one_dev_info(info); - } - spin_unlock_irqrestore(&device_domain_lock, flags); + /* + * All iommu domains must have been detached from the devices, + * hence there should be no domain IDs in use. + */ + if (WARN_ON(bitmap_weight(iommu->domain_ids, cap_ndoms(iommu->cap)) + > NUM_RESERVED_DID)) + return; =20 if (iommu->gcmd & DMA_GCMD_TE) iommu_disable_translation(iommu); --=20 2.25.1 From nobody Sat Apr 25 11:48:02 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 A1399C433EF for ; Tue, 12 Jul 2022 00:14:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229910AbiGLAOa (ORCPT ); Mon, 11 Jul 2022 20:14:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49412 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231909AbiGLAON (ORCPT ); Mon, 11 Jul 2022 20:14:13 -0400 Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8D0CC1EEE6 for ; Mon, 11 Jul 2022 17:13:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1657584838; x=1689120838; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=UYzNBPbVg8yrUM0rXnEd1Fl2izddC+hNiEZ3tUWLG+s=; b=F/RAU84dFmWdTFAp8z6rjZ6mMiY722tsp0Trdu21KbFIjPYvwJ3tYODT EkyBc9Oq04AFa6FXqKiwi9xXVxR0Ba8hu576yPAvYM5hopSsH8avtBHFB SB9gGoALrV3uT0e39VXDHDPFYmynbefIuhWQmyKnmyLlasVZ7+jUxZIp9 xyAyCkJN4QTMLthlmDgi0S/6zW1jkJcllDeyV67/fTznPhOdb4q1yWFVB 1ZcHD5nYpALGG2yfUZFXE7tCFiVEv9rw4A4cLqV+LtxzLky0cVEMulbUc Bm5qL6EybrmAbAZqjgLYPXMEJKfpEgx/p27x/gX2cnjWDYK4KoObYL0yI w==; X-IronPort-AV: E=McAfee;i="6400,9594,10405"; a="284827962" X-IronPort-AV: E=Sophos;i="5.92,264,1650956400"; d="scan'208";a="284827962" Received: from orsmga007.jf.intel.com ([10.7.209.58]) by fmsmga103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 Jul 2022 17:13:57 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.92,264,1650956400"; d="scan'208";a="592445761" Received: from allen-box.sh.intel.com ([10.239.159.48]) by orsmga007.jf.intel.com with ESMTP; 11 Jul 2022 17:13:56 -0700 From: Lu Baolu To: Joerg Roedel Cc: iommu@lists.linux.dev, linux-kernel@vger.kernel.org Subject: [PATCH 11/25] iommu/vt-d: Use pci_get_domain_bus_and_slot() in pgtable_walk() Date: Tue, 12 Jul 2022 08:08:54 +0800 Message-Id: <20220712000908.3431936-12-baolu.lu@linux.intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220712000908.3431936-1-baolu.lu@linux.intel.com> References: <20220712000908.3431936-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 pci_get_domain_bus_and_slot() instead of searching the global list to retrieve the pci device pointer. This also removes the global device_domain_list as there isn't any consumer anymore. Signed-off-by: Lu Baolu Reviewed-by: Jason Gunthorpe Reviewed-by: Kevin Tian Link: https://lore.kernel.org/r/20220706025524.2904370-4-baolu.lu@linux.int= el.com --- drivers/iommu/intel/iommu.h | 1 - drivers/iommu/intel/iommu.c | 34 ++++++---------------------------- 2 files changed, 6 insertions(+), 29 deletions(-) diff --git a/drivers/iommu/intel/iommu.h b/drivers/iommu/intel/iommu.h index 8deb745d8b36..198c6c822ef4 100644 --- a/drivers/iommu/intel/iommu.h +++ b/drivers/iommu/intel/iommu.h @@ -609,7 +609,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 */ u32 segment; /* PCI segment number */ u8 bus; /* PCI bus number */ u8 devfn; /* PCI devfn number */ diff --git a/drivers/iommu/intel/iommu.c b/drivers/iommu/intel/iommu.c index 43aaec5bdd84..77915d61f7ec 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 @@ -315,8 +313,6 @@ static int iommu_skip_te_disable; #define IDENTMAP_AZALIA 4 =20 static DEFINE_SPINLOCK(device_domain_lock); -static LIST_HEAD(device_domain_list); - const struct iommu_ops intel_iommu_ops; =20 static bool translation_pre_enabled(struct intel_iommu *iommu) @@ -846,9 +842,14 @@ static void pgtable_walk(struct intel_iommu *iommu, un= signed long pfn, u8 bus, u struct device_domain_info *info; struct dma_pte *parent, *pte; struct dmar_domain *domain; + struct pci_dev *pdev; int offset, level; =20 - info =3D dmar_search_domain_by_dev_info(iommu->segment, bus, devfn); + pdev =3D pci_get_domain_bus_and_slot(iommu->segment, bus, devfn); + if (!pdev) + return; + + info =3D dev_iommu_priv_get(&pdev->dev); if (!info || !info->domain) { pr_info("device [%02x:%02x.%d] not probed\n", bus, PCI_SLOT(devfn), PCI_FUNC(devfn)); @@ -2357,19 +2358,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, @@ -4573,7 +4561,6 @@ 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, &bus, &devfn); @@ -4616,10 +4603,7 @@ static struct iommu_device *intel_iommu_probe_device= (struct device *dev) } } =20 - 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; } @@ -4627,15 +4611,9 @@ static struct iommu_device *intel_iommu_probe_device= (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); - - 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 2.25.1 From nobody Sat Apr 25 11:48:02 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 A5AD2C433EF for ; Tue, 12 Jul 2022 00:14:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229664AbiGLAOk (ORCPT ); Mon, 11 Jul 2022 20:14:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50498 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230514AbiGLAOR (ORCPT ); Mon, 11 Jul 2022 20:14:17 -0400 Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 826F628E2E for ; Mon, 11 Jul 2022 17:14:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1657584841; x=1689120841; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=GzlhirecLvIVUu2iZ2UlHBIY5boXyb2x1HwRo/KzfaU=; b=jarvSwXaZSpp0+dQhdTDpPgy6W3QgoFPI2IVSjc3kIX/ps1zNMintArC 4cFrOeGPmKUv/8jXCYDvVfnImbQ//NAJxUVCDpIUG/iGyxjK0atCAuCB8 2okjmjcDqZeNH3xplGYPbvL90N5oymxrrrZ/T8tyaCpenKpVTYzW0uAMN 26ns1+ipXW4ViWF9loCMeEmzQQI92YM1931RsS2ld6P5uT0W8XGextMqO 7dQ9xpghZd9FV7Lg86pP5ZLC0gGty5MFGWxpvGVv2AbXQsNAPfEp73IXc qam4Pi+wBTyuEizaj/Q2iGdknmsbHZ9v5lI5eZHIqKwtPrOyxPOY+gHNt Q==; X-IronPort-AV: E=McAfee;i="6400,9594,10405"; a="284827972" X-IronPort-AV: E=Sophos;i="5.92,264,1650956400"; d="scan'208";a="284827972" Received: from orsmga007.jf.intel.com ([10.7.209.58]) by fmsmga103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 Jul 2022 17:14:00 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.92,264,1650956400"; d="scan'208";a="592445785" Received: from allen-box.sh.intel.com ([10.239.159.48]) by orsmga007.jf.intel.com with ESMTP; 11 Jul 2022 17:13:57 -0700 From: Lu Baolu To: Joerg Roedel Cc: iommu@lists.linux.dev, linux-kernel@vger.kernel.org Subject: [PATCH 12/25] iommu/vt-d: Unnecessary spinlock for root table alloc and free Date: Tue, 12 Jul 2022 08:08:55 +0800 Message-Id: <20220712000908.3431936-13-baolu.lu@linux.intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220712000908.3431936-1-baolu.lu@linux.intel.com> References: <20220712000908.3431936-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 IOMMU root table is allocated and freed in the IOMMU initialization code in static boot or hot-remove paths. There's no need for a spinlock. Signed-off-by: Lu Baolu Reviewed-by: Kevin Tian Link: https://lore.kernel.org/r/20220706025524.2904370-5-baolu.lu@linux.int= el.com --- drivers/iommu/intel/iommu.c | 18 +++++------------- 1 file changed, 5 insertions(+), 13 deletions(-) diff --git a/drivers/iommu/intel/iommu.c b/drivers/iommu/intel/iommu.c index 77915d61f7ec..ff49c9460ede 100644 --- a/drivers/iommu/intel/iommu.c +++ b/drivers/iommu/intel/iommu.c @@ -809,14 +809,12 @@ static int device_context_mapped(struct intel_iommu *= iommu, u8 bus, u8 devfn) =20 static void free_context_table(struct intel_iommu *iommu) { - int i; - unsigned long flags; struct context_entry *context; + int i; + + if (!iommu->root_entry) + return; =20 - spin_lock_irqsave(&iommu->lock, flags); - if (!iommu->root_entry) { - goto out; - } for (i =3D 0; i < ROOT_ENTRY_NR; i++) { context =3D iommu_context_addr(iommu, i, 0, 0); if (context) @@ -828,12 +826,10 @@ static void free_context_table(struct intel_iommu *io= mmu) context =3D iommu_context_addr(iommu, i, 0x80, 0); if (context) free_pgtable_page(context); - } + free_pgtable_page(iommu->root_entry); iommu->root_entry =3D NULL; -out: - spin_unlock_irqrestore(&iommu->lock, flags); } =20 #ifdef CONFIG_DMAR_DEBUG @@ -1232,7 +1228,6 @@ static void domain_unmap(struct dmar_domain *domain, = unsigned long start_pfn, static int iommu_alloc_root_entry(struct intel_iommu *iommu) { struct root_entry *root; - unsigned long flags; =20 root =3D (struct root_entry *)alloc_pgtable_page(iommu->node); if (!root) { @@ -1242,10 +1237,7 @@ static int iommu_alloc_root_entry(struct intel_iommu= *iommu) } =20 __iommu_flush_cache(iommu, root, ROOT_SIZE); - - spin_lock_irqsave(&iommu->lock, flags); iommu->root_entry =3D root; - spin_unlock_irqrestore(&iommu->lock, flags); =20 return 0; } --=20 2.25.1 From nobody Sat Apr 25 11:48:02 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 49451C43334 for ; Tue, 12 Jul 2022 00:15:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231835AbiGLAPU (ORCPT ); Mon, 11 Jul 2022 20:15:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50618 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231191AbiGLAPA (ORCPT ); Mon, 11 Jul 2022 20:15:00 -0400 Received: from mga17.intel.com (mga17.intel.com [192.55.52.151]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A42022559F for ; Mon, 11 Jul 2022 17:14:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1657584865; x=1689120865; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=Rw0bt1lwIejGYkqJC+RFz3d5K0YBnIC0MJskMj+sdcI=; b=h1vr4prh4MSQy6YMJxmkDMDDfwG1+MoJiCcsfxtGsla0JWPIpvqtzARD vjh8YLR3bb+ZEuN/JybIlAX15rmpvHqwMUT/i0v7ckbCNc3eV2DtuCBXU 5ssp7kC9i6tcTDn6BnOjfYaJ1HK2VhceN7MMVp9ApS2jvecZPrpZB3YYW AXWKxZSDQp7eLTFCRn1ERzIUNbPHN4FXGxzyVarYtf3JQPwCpu7ZQR9K4 942nM5SIXAAL4D4LgjnYJGO493i2hyCgaY9p5xG1gaSyvUCl5V/1aCNPz ogYgDdqKN9HDSMBv7neC2dgMleQxRv4hD6akP0Rnpsdn8Z/8s6jbrgH+T g==; X-IronPort-AV: E=McAfee;i="6400,9594,10405"; a="265213592" X-IronPort-AV: E=Sophos;i="5.92,264,1650956400"; d="scan'208";a="265213592" Received: from orsmga007.jf.intel.com ([10.7.209.58]) by fmsmga107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 Jul 2022 17:14:22 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.92,264,1650956400"; d="scan'208";a="592445803" Received: from allen-box.sh.intel.com ([10.239.159.48]) by orsmga007.jf.intel.com with ESMTP; 11 Jul 2022 17:14:01 -0700 From: Lu Baolu To: Joerg Roedel Cc: iommu@lists.linux.dev, linux-kernel@vger.kernel.org Subject: [PATCH 13/25] iommu/vt-d: Replace spin_lock_irqsave() with spin_lock() Date: Tue, 12 Jul 2022 08:08:56 +0800 Message-Id: <20220712000908.3431936-14-baolu.lu@linux.intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220712000908.3431936-1-baolu.lu@linux.intel.com> References: <20220712000908.3431936-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 iommu->lock is used to protect changes in root/context/pasid tables and domain ID allocation. There's no use case to change these resources in any interrupt context. Therefore, it is unnecessary to disable the interrupts when the spinlock is held. The same thing happens on the device_domain_lock side, which protects the device domain attachment information. This replaces spin_lock/unlock_irqsave/irqrestore() calls with the normal spin_lock/unlock(). Signed-off-by: Lu Baolu Reviewed-by: Kevin Tian Link: https://lore.kernel.org/r/20220706025524.2904370-6-baolu.lu@linux.int= el.com --- drivers/iommu/intel/debugfs.c | 6 ++-- drivers/iommu/intel/iommu.c | 66 ++++++++++++++--------------------- drivers/iommu/intel/svm.c | 6 ++-- 3 files changed, 32 insertions(+), 46 deletions(-) diff --git a/drivers/iommu/intel/debugfs.c b/drivers/iommu/intel/debugfs.c index 6e1a3f88abc8..1f925285104e 100644 --- a/drivers/iommu/intel/debugfs.c +++ b/drivers/iommu/intel/debugfs.c @@ -263,10 +263,9 @@ static void ctx_tbl_walk(struct seq_file *m, struct in= tel_iommu *iommu, u16 bus) =20 static void root_tbl_walk(struct seq_file *m, struct intel_iommu *iommu) { - unsigned long flags; u16 bus; =20 - spin_lock_irqsave(&iommu->lock, flags); + spin_lock(&iommu->lock); seq_printf(m, "IOMMU %s: Root Table Address: 0x%llx\n", iommu->name, (u64)virt_to_phys(iommu->root_entry)); seq_puts(m, "B.D.F\tRoot_entry\t\t\t\tContext_entry\t\t\t\tPASID\tPASID_t= able_entry\n"); @@ -278,8 +277,7 @@ static void root_tbl_walk(struct seq_file *m, struct in= tel_iommu *iommu) */ for (bus =3D 0; bus < 256; bus++) ctx_tbl_walk(m, iommu, bus); - - spin_unlock_irqrestore(&iommu->lock, flags); + spin_unlock(&iommu->lock); } =20 static int dmar_translation_struct_show(struct seq_file *m, void *unused) diff --git a/drivers/iommu/intel/iommu.c b/drivers/iommu/intel/iommu.c index ff49c9460ede..93f01082dce1 100644 --- a/drivers/iommu/intel/iommu.c +++ b/drivers/iommu/intel/iommu.c @@ -797,13 +797,12 @@ static int device_context_mapped(struct intel_iommu *= iommu, u8 bus, u8 devfn) { struct context_entry *context; int ret =3D 0; - unsigned long flags; =20 - spin_lock_irqsave(&iommu->lock, flags); + spin_lock(&iommu->lock); context =3D iommu_context_addr(iommu, bus, devfn, 0); if (context) ret =3D context_present(context); - spin_unlock_irqrestore(&iommu->lock, flags); + spin_unlock(&iommu->lock); return ret; } =20 @@ -1508,17 +1507,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); + spin_lock(&device_domain_lock); list_for_each_entry(info, &domain->devices, link) __iommu_flush_dev_iotlb(info, addr, mask); - - spin_unlock_irqrestore(&device_domain_lock, flags); + spin_unlock(&device_domain_lock); } =20 static void iommu_flush_iotlb_psi(struct intel_iommu *iommu, @@ -1917,7 +1914,6 @@ static int domain_context_mapping_one(struct dmar_dom= ain *domain, int translation =3D CONTEXT_TT_MULTI_LEVEL; struct device_domain_info *info =3D NULL; struct context_entry *context; - unsigned long flags; int ret; =20 WARN_ON(did =3D=3D 0); @@ -1930,7 +1926,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(&device_domain_lock); spin_lock(&iommu->lock); =20 ret =3D -ENOMEM; @@ -2052,7 +2048,7 @@ static int domain_context_mapping_one(struct dmar_dom= ain *domain, =20 out_unlock: spin_unlock(&iommu->lock); - spin_unlock_irqrestore(&device_domain_lock, flags); + spin_unlock(&device_domain_lock); =20 return ret; } @@ -2296,16 +2292,15 @@ static void domain_context_clear_one(struct device_= domain_info *info, u8 bus, u8 { struct intel_iommu *iommu =3D info->iommu; struct context_entry *context; - unsigned long flags; u16 did_old; =20 if (!iommu) return; =20 - spin_lock_irqsave(&iommu->lock, flags); + spin_lock(&iommu->lock); context =3D iommu_context_addr(iommu, bus, devfn, 0); if (!context) { - spin_unlock_irqrestore(&iommu->lock, flags); + spin_unlock(&iommu->lock); return; } =20 @@ -2320,7 +2315,7 @@ static void domain_context_clear_one(struct device_do= main_info *info, u8 bus, u8 =20 context_clear_entry(context); __iommu_flush_cache(iommu, context, sizeof(*context)); - spin_unlock_irqrestore(&iommu->lock, flags); + spin_unlock(&iommu->lock); iommu->flush.flush_context(iommu, did_old, (((u16)bus) << 8) | devfn, @@ -2342,12 +2337,11 @@ static void domain_context_clear_one(struct device_= domain_info *info, u8 bus, u8 static void domain_remove_dev_info(struct dmar_domain *domain) { struct device_domain_info *info, *tmp; - unsigned long flags; =20 - spin_lock_irqsave(&device_domain_lock, flags); + spin_lock(&device_domain_lock); list_for_each_entry_safe(info, tmp, &domain->devices, link) __dmar_remove_one_dev_info(info); - spin_unlock_irqrestore(&device_domain_lock, flags); + spin_unlock(&device_domain_lock); } =20 static int domain_setup_first_level(struct intel_iommu *iommu, @@ -2469,7 +2463,6 @@ static int domain_add_dev_info(struct dmar_domain *do= main, struct device *dev) { struct device_domain_info *info =3D dev_iommu_priv_get(dev); struct intel_iommu *iommu; - unsigned long flags; u8 bus, devfn; int ret; =20 @@ -2477,17 +2470,17 @@ static int domain_add_dev_info(struct dmar_domain *= domain, struct device *dev) if (!iommu) return -ENODEV; =20 - spin_lock_irqsave(&device_domain_lock, flags); + spin_lock(&device_domain_lock); 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); + spin_unlock(&device_domain_lock); return ret; } list_add(&info->link, &domain->devices); - spin_unlock_irqrestore(&device_domain_lock, flags); + spin_unlock(&device_domain_lock); =20 /* PASID table is mandatory for a PCI device in scalable mode. */ if (sm_supported(iommu) && !dev_is_real_dma_subdevice(dev)) { @@ -2499,7 +2492,7 @@ static int domain_add_dev_info(struct dmar_domain *do= main, struct device *dev) } =20 /* Setup the PASID entry for requests without PASID: */ - spin_lock_irqsave(&iommu->lock, flags); + spin_lock(&iommu->lock); if (hw_pass_through && domain_type_is_si(domain)) ret =3D intel_pasid_setup_pass_through(iommu, domain, dev, PASID_RID2PASID); @@ -2509,7 +2502,7 @@ static int domain_add_dev_info(struct dmar_domain *do= main, struct device *dev) else ret =3D intel_pasid_setup_second_level(iommu, domain, dev, PASID_RID2PASID); - spin_unlock_irqrestore(&iommu->lock, flags); + spin_unlock(&iommu->lock); if (ret) { dev_err(dev, "Setup RID2PASID failed\n"); dmar_remove_one_dev_info(dev); @@ -2777,7 +2770,6 @@ static int copy_translation_tables(struct intel_iommu= *iommu) struct root_entry *old_rt; phys_addr_t old_rt_phys; int ctxt_table_entries; - unsigned long flags; u64 rtaddr_reg; int bus, ret; bool new_ext, ext; @@ -2820,7 +2812,7 @@ static int copy_translation_tables(struct intel_iommu= *iommu) } } =20 - spin_lock_irqsave(&iommu->lock, flags); + spin_lock(&iommu->lock); =20 /* Context tables are copied, now write them to the root_entry table */ for (bus =3D 0; bus < 256; bus++) { @@ -2839,7 +2831,7 @@ static int copy_translation_tables(struct intel_iommu= *iommu) iommu->root_entry[bus].hi =3D val; } =20 - spin_unlock_irqrestore(&iommu->lock, flags); + spin_unlock(&iommu->lock); =20 kfree(ctxt_tbls); =20 @@ -4166,7 +4158,6 @@ static void __dmar_remove_one_dev_info(struct device_= domain_info *info) { struct dmar_domain *domain; struct intel_iommu *iommu; - unsigned long flags; =20 assert_spin_locked(&device_domain_lock); =20 @@ -4188,21 +4179,20 @@ static void __dmar_remove_one_dev_info(struct devic= e_domain_info *info) =20 list_del(&info->link); =20 - spin_lock_irqsave(&iommu->lock, flags); + spin_lock(&iommu->lock); domain_detach_iommu(domain, iommu); - spin_unlock_irqrestore(&iommu->lock, flags); + spin_unlock(&iommu->lock); } =20 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); + spin_lock(&device_domain_lock); info =3D dev_iommu_priv_get(dev); if (info) __dmar_remove_one_dev_info(info); - spin_unlock_irqrestore(&device_domain_lock, flags); + spin_unlock(&device_domain_lock); } =20 static int md_domain_init(struct dmar_domain *domain, int guest_width) @@ -4518,20 +4508,19 @@ static void domain_set_force_snooping(struct dmar_d= omain *domain) static bool intel_iommu_enforce_cache_coherency(struct iommu_domain *domai= n) { struct dmar_domain *dmar_domain =3D to_dmar_domain(domain); - unsigned long flags; =20 if (dmar_domain->force_snooping) return true; =20 - spin_lock_irqsave(&device_domain_lock, flags); + spin_lock(&device_domain_lock); if (!domain_support_force_snooping(dmar_domain)) { - spin_unlock_irqrestore(&device_domain_lock, flags); + spin_unlock(&device_domain_lock); return false; } =20 domain_set_force_snooping(dmar_domain); dmar_domain->force_snooping =3D true; - spin_unlock_irqrestore(&device_domain_lock, flags); + spin_unlock(&device_domain_lock); =20 return true; } @@ -4678,7 +4667,6 @@ int intel_iommu_enable_pasid(struct intel_iommu *iomm= u, struct device *dev) 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 @@ -4686,7 +4674,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(&device_domain_lock); spin_lock(&iommu->lock); =20 ret =3D -EINVAL; @@ -4718,7 +4706,7 @@ int intel_iommu_enable_pasid(struct intel_iommu *iomm= u, struct device *dev) =20 out: spin_unlock(&iommu->lock); - spin_unlock_irqrestore(&device_domain_lock, flags); + spin_unlock(&device_domain_lock); =20 return ret; } diff --git a/drivers/iommu/intel/svm.c b/drivers/iommu/intel/svm.c index 580713aa9e07..82288a50660d 100644 --- a/drivers/iommu/intel/svm.c +++ b/drivers/iommu/intel/svm.c @@ -328,9 +328,9 @@ static struct iommu_sva *intel_svm_bind_mm(struct intel= _iommu *iommu, unsigned int flags) { struct device_domain_info *info =3D dev_iommu_priv_get(dev); - unsigned long iflags, sflags; struct intel_svm_dev *sdev; struct intel_svm *svm; + unsigned long sflags; int ret =3D 0; =20 svm =3D pasid_private_find(mm->pasid); @@ -394,10 +394,10 @@ static struct iommu_sva *intel_svm_bind_mm(struct int= el_iommu *iommu, sflags =3D (flags & SVM_FLAG_SUPERVISOR_MODE) ? PASID_FLAG_SUPERVISOR_MODE : 0; sflags |=3D cpu_feature_enabled(X86_FEATURE_LA57) ? PASID_FLAG_FL5LP : 0; - spin_lock_irqsave(&iommu->lock, iflags); + spin_lock(&iommu->lock); ret =3D intel_pasid_setup_first_level(iommu, dev, mm->pgd, mm->pasid, FLPT_DEFAULT_DID, sflags); - spin_unlock_irqrestore(&iommu->lock, iflags); + spin_unlock(&iommu->lock); =20 if (ret) goto free_sdev; --=20 2.25.1 From nobody Sat Apr 25 11:48:02 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 26B81C433EF for ; Tue, 12 Jul 2022 00:15:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231337AbiGLAP3 (ORCPT ); Mon, 11 Jul 2022 20:15:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50364 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229929AbiGLAPF (ORCPT ); Mon, 11 Jul 2022 20:15:05 -0400 Received: from mga03.intel.com (mga03.intel.com [134.134.136.65]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D8296193DD for ; Mon, 11 Jul 2022 17:14:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1657584868; x=1689120868; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=Ja5IsQKhb4CVYQ9JckY0NN2jrC0vCxngqZ6SO6WGVVI=; b=ggFkal6Tn+lNim+5u/pE4hiHzotISJ42KIKtEoOjrM2yhXlzGK0EEVnd Glb/M9PWoA3A6MaElZ2zqaJyvRR/UiqjTG4qSHUYMNcvN2x1PQ3zlPnak q34yggDghaCaU2QdPiS9vnzl+cai1iXbn7npxr3pELLrY6klCU3nDLwEl jcs+I5lRN3tY8BOtQYwBwr/UVqfEPluoWmGBN+JsqHxi2QprAhQt4w1N3 DJYiycJ8Kzo+5BDVy+JZi0XNA7wbLyN4Ywft94VS+hclklb8IHzK4a8ab fqkrxzaH9Vg0ay4jW0bLFjg8lDdUSWnpRbZLLOKBy7aj+rSUVh1CzS8Wl A==; X-IronPort-AV: E=McAfee;i="6400,9594,10405"; a="285929300" X-IronPort-AV: E=Sophos;i="5.92,264,1650956400"; d="scan'208";a="285929300" Received: from orsmga007.jf.intel.com ([10.7.209.58]) by orsmga103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 Jul 2022 17:14:26 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.92,264,1650956400"; d="scan'208";a="592445821" Received: from allen-box.sh.intel.com ([10.239.159.48]) by orsmga007.jf.intel.com with ESMTP; 11 Jul 2022 17:14:02 -0700 From: Lu Baolu To: Joerg Roedel Cc: iommu@lists.linux.dev, linux-kernel@vger.kernel.org Subject: [PATCH 14/25] iommu/vt-d: Acquiring lock in domain ID allocation helpers Date: Tue, 12 Jul 2022 08:08:57 +0800 Message-Id: <20220712000908.3431936-15-baolu.lu@linux.intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220712000908.3431936-1-baolu.lu@linux.intel.com> References: <20220712000908.3431936-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 iommu->lock is used to protect the per-IOMMU domain ID resource. Moving the lock into the ID alloc/free helpers makes the code more compact. At the same time, the device_domain_lock is irrelevant to the domain ID resource, remove its assertion as well. Signed-off-by: Lu Baolu Reviewed-by: Kevin Tian Link: https://lore.kernel.org/r/20220706025524.2904370-7-baolu.lu@linux.int= el.com --- drivers/iommu/intel/iommu.c | 24 +++++++++--------------- 1 file changed, 9 insertions(+), 15 deletions(-) diff --git a/drivers/iommu/intel/iommu.c b/drivers/iommu/intel/iommu.c index 93f01082dce1..7f03576e72d7 100644 --- a/drivers/iommu/intel/iommu.c +++ b/drivers/iommu/intel/iommu.c @@ -1779,16 +1779,13 @@ static struct dmar_domain *alloc_domain(unsigned in= t type) return domain; } =20 -/* 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 =3D 0; =20 + spin_lock(&iommu->lock); domain->iommu_refcnt[iommu->seq_id] +=3D 1; if (domain->iommu_refcnt[iommu->seq_id] =3D=3D 1) { ndomains =3D cap_ndoms(iommu->cap); @@ -1797,7 +1794,8 @@ static int domain_attach_iommu(struct dmar_domain *do= main, if (num >=3D ndomains) { pr_err("%s: No free domain ids\n", iommu->name); domain->iommu_refcnt[iommu->seq_id] -=3D 1; - return -ENOSPC; + ret =3D -ENOSPC; + goto out_unlock; } =20 set_bit(num, iommu->domain_ids); @@ -1806,7 +1804,9 @@ static int domain_attach_iommu(struct dmar_domain *do= main, domain_update_iommu_cap(domain); } =20 - return 0; +out_unlock: + spin_unlock(&iommu->lock); + return ret; } =20 static void domain_detach_iommu(struct dmar_domain *domain, @@ -1814,9 +1814,7 @@ static void domain_detach_iommu(struct dmar_domain *d= omain, { int num; =20 - assert_spin_locked(&device_domain_lock); - assert_spin_locked(&iommu->lock); - + spin_lock(&iommu->lock); domain->iommu_refcnt[iommu->seq_id] -=3D 1; if (domain->iommu_refcnt[iommu->seq_id] =3D=3D 0) { num =3D domain->iommu_did[iommu->seq_id]; @@ -1824,6 +1822,7 @@ static void domain_detach_iommu(struct dmar_domain *d= omain, domain_update_iommu_cap(domain); domain->iommu_did[iommu->seq_id] =3D 0; } + spin_unlock(&iommu->lock); } =20 static inline int guestwidth_to_adjustwidth(int gaw) @@ -2472,9 +2471,7 @@ static int domain_add_dev_info(struct dmar_domain *do= main, struct device *dev) =20 spin_lock(&device_domain_lock); info->domain =3D domain; - spin_lock(&iommu->lock); ret =3D domain_attach_iommu(domain, iommu); - spin_unlock(&iommu->lock); if (ret) { spin_unlock(&device_domain_lock); return ret; @@ -4178,10 +4175,7 @@ static void __dmar_remove_one_dev_info(struct device= _domain_info *info) } =20 list_del(&info->link); - - spin_lock(&iommu->lock); domain_detach_iommu(domain, iommu); - spin_unlock(&iommu->lock); } =20 static void dmar_remove_one_dev_info(struct device *dev) --=20 2.25.1 From nobody Sat Apr 25 11:48:02 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 DDFDAC43334 for ; Tue, 12 Jul 2022 00:15:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231765AbiGLAPl (ORCPT ); Mon, 11 Jul 2022 20:15:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50856 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231755AbiGLAPM (ORCPT ); Mon, 11 Jul 2022 20:15:12 -0400 Received: from mga03.intel.com (mga03.intel.com [134.134.136.65]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 944A07D793 for ; Mon, 11 Jul 2022 17:14:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1657584877; x=1689120877; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=VoY7bFDW0XhDxJcxsRT3+MNmRvmSbnHbKWNookuikwE=; b=S6fTdMcqBa+7I7nyU8XMHCz1CMotcS1LlP2ryGZxn6f0hqL9LlEPN5YA m6LQiG+UMgyulnAheAlRJbUkxy6I/EDEvAmGqcQpT6q2lVix9XjxUpEhO GNdCt0e9YpWRfYg1hxsG5S4vB/1BIYleaqLt5WMTFgx1b9ndlzaLO5502 4BivNxK+lbPxQ4QN7i7YwMoXGf/h0c+p7dugmkx5A26PRh8c1IIlzFcz4 AA9Elrns1+IcDuBXXmpwf8mymCPivvHAgIo1zOSr39gJzEjMwQUTAFqmm ySxAuYDyiVpMC8geDCypi8xAF0TznOuzR7Agg/WuAtVtZ/XS2ZmXIJbps g==; X-IronPort-AV: E=McAfee;i="6400,9594,10405"; a="285929306" X-IronPort-AV: E=Sophos;i="5.92,264,1650956400"; d="scan'208";a="285929306" Received: from orsmga007.jf.intel.com ([10.7.209.58]) by orsmga103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 Jul 2022 17:14:26 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.92,264,1650956400"; d="scan'208";a="592445830" Received: from allen-box.sh.intel.com ([10.239.159.48]) by orsmga007.jf.intel.com with ESMTP; 11 Jul 2022 17:14:03 -0700 From: Lu Baolu To: Joerg Roedel Cc: iommu@lists.linux.dev, linux-kernel@vger.kernel.org Subject: [PATCH 15/25] iommu/vt-d: Acquiring lock in pasid manipulation helpers Date: Tue, 12 Jul 2022 08:08:58 +0800 Message-Id: <20220712000908.3431936-16-baolu.lu@linux.intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220712000908.3431936-1-baolu.lu@linux.intel.com> References: <20220712000908.3431936-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 iommu->lock is used to protect the per-IOMMU pasid directory table and pasid table. Move the spinlock acquisition/release into the helpers to make the code self-contained. Signed-off-by: Lu Baolu Reviewed-by: Kevin Tian Link: https://lore.kernel.org/r/20220706025524.2904370-8-baolu.lu@linux.int= el.com --- drivers/iommu/intel/iommu.c | 2 - drivers/iommu/intel/pasid.c | 103 +++++++++++++++++++----------------- drivers/iommu/intel/svm.c | 3 -- 3 files changed, 55 insertions(+), 53 deletions(-) diff --git a/drivers/iommu/intel/iommu.c b/drivers/iommu/intel/iommu.c index 7f03576e72d7..3d53de8c7634 100644 --- a/drivers/iommu/intel/iommu.c +++ b/drivers/iommu/intel/iommu.c @@ -2489,7 +2489,6 @@ static int domain_add_dev_info(struct dmar_domain *do= main, struct device *dev) } =20 /* Setup the PASID entry for requests without PASID: */ - spin_lock(&iommu->lock); if (hw_pass_through && domain_type_is_si(domain)) ret =3D intel_pasid_setup_pass_through(iommu, domain, dev, PASID_RID2PASID); @@ -2499,7 +2498,6 @@ static int domain_add_dev_info(struct dmar_domain *do= main, struct device *dev) else ret =3D intel_pasid_setup_second_level(iommu, domain, dev, PASID_RID2PASID); - spin_unlock(&iommu->lock); if (ret) { dev_err(dev, "Setup RID2PASID failed\n"); dmar_remove_one_dev_info(dev); diff --git a/drivers/iommu/intel/pasid.c b/drivers/iommu/intel/pasid.c index 43f090381ec7..7792a1b2ebc4 100644 --- a/drivers/iommu/intel/pasid.c +++ b/drivers/iommu/intel/pasid.c @@ -450,17 +450,17 @@ void intel_pasid_tear_down_entry(struct intel_iommu *= iommu, struct device *dev, struct pasid_entry *pte; u16 did, pgtt; =20 + spin_lock(&iommu->lock); pte =3D intel_pasid_get_entry(dev, pasid); - if (WARN_ON(!pte)) - return; - - if (!pasid_pte_is_present(pte)) + if (WARN_ON(!pte) || !pasid_pte_is_present(pte)) { + spin_unlock(&iommu->lock); return; + } =20 did =3D pasid_get_domain_id(pte); pgtt =3D pasid_pte_get_pgtt(pte); - intel_pasid_clear_entry(dev, pasid, fault_ignore); + spin_unlock(&iommu->lock); =20 if (!ecap_coherent(iommu->ecap)) clflush_cache_range(pte, sizeof(*pte)); @@ -496,22 +496,6 @@ static void pasid_flush_caches(struct intel_iommu *iom= mu, } } =20 -static inline int pasid_enable_wpe(struct pasid_entry *pte) -{ -#ifdef CONFIG_X86 - unsigned long cr0 =3D read_cr0(); - - /* CR0.WP is normally set but just to be sure */ - if (unlikely(!(cr0 & X86_CR0_WP))) { - pr_err_ratelimited("No CPU write protect!\n"); - return -EINVAL; - } -#endif - pasid_set_wpe(pte); - - return 0; -}; - /* * Set up the scalable mode pasid table entry for first only * translation type. @@ -528,39 +512,52 @@ int intel_pasid_setup_first_level(struct intel_iommu = *iommu, return -EINVAL; } =20 - pte =3D intel_pasid_get_entry(dev, pasid); - if (WARN_ON(!pte)) + if (flags & PASID_FLAG_SUPERVISOR_MODE) { +#ifdef CONFIG_X86 + unsigned long cr0 =3D read_cr0(); + + /* CR0.WP is normally set but just to be sure */ + if (unlikely(!(cr0 & X86_CR0_WP))) { + pr_err("No CPU write protect!\n"); + return -EINVAL; + } +#endif + if (!ecap_srs(iommu->ecap)) { + pr_err("No supervisor request support on %s\n", + iommu->name); + return -EINVAL; + } + } + + if ((flags & PASID_FLAG_FL5LP) && !cap_5lp_support(iommu->cap)) { + pr_err("No 5-level paging support for first-level on %s\n", + iommu->name); return -EINVAL; + } =20 - /* Caller must ensure PASID entry is not in use. */ - if (pasid_pte_is_present(pte)) + spin_lock(&iommu->lock); + pte =3D intel_pasid_get_entry(dev, pasid); + if (!pte) { + spin_unlock(&iommu->lock); + return -ENODEV; + } + + if (pasid_pte_is_present(pte)) { + spin_unlock(&iommu->lock); return -EBUSY; + } =20 pasid_clear_entry(pte); =20 /* Setup the first level page table pointer: */ pasid_set_flptr(pte, (u64)__pa(pgd)); if (flags & PASID_FLAG_SUPERVISOR_MODE) { - if (!ecap_srs(iommu->ecap)) { - pr_err("No supervisor request support on %s\n", - iommu->name); - return -EINVAL; - } pasid_set_sre(pte); - if (pasid_enable_wpe(pte)) - return -EINVAL; - + pasid_set_wpe(pte); } =20 - if (flags & PASID_FLAG_FL5LP) { - if (cap_5lp_support(iommu->cap)) { - pasid_set_flpm(pte, 1); - } else { - pr_err("No 5-level paging support for first-level\n"); - pasid_clear_entry(pte); - return -EINVAL; - } - } + if (flags & PASID_FLAG_FL5LP) + pasid_set_flpm(pte, 1); =20 if (flags & PASID_FLAG_PAGE_SNOOP) pasid_set_pgsnp(pte); @@ -572,6 +569,8 @@ int intel_pasid_setup_first_level(struct intel_iommu *i= ommu, /* Setup Present and PASID Granular Transfer Type: */ pasid_set_translation_type(pte, PASID_ENTRY_PGTT_FL_ONLY); pasid_set_present(pte); + spin_unlock(&iommu->lock); + pasid_flush_caches(iommu, pte, pasid, did); =20 return 0; @@ -629,15 +628,17 @@ int intel_pasid_setup_second_level(struct intel_iommu= *iommu, pgd_val =3D virt_to_phys(pgd); did =3D domain->iommu_did[iommu->seq_id]; =20 + spin_lock(&iommu->lock); pte =3D intel_pasid_get_entry(dev, pasid); if (!pte) { - dev_err(dev, "Failed to get pasid entry of PASID %d\n", pasid); + spin_unlock(&iommu->lock); return -ENODEV; } =20 - /* Caller must ensure PASID entry is not in use. */ - if (pasid_pte_is_present(pte)) + if (pasid_pte_is_present(pte)) { + spin_unlock(&iommu->lock); return -EBUSY; + } =20 pasid_clear_entry(pte); pasid_set_domain_id(pte, did); @@ -654,6 +655,8 @@ int intel_pasid_setup_second_level(struct intel_iommu *= iommu, if (pasid !=3D PASID_RID2PASID) pasid_set_sre(pte); pasid_set_present(pte); + spin_unlock(&iommu->lock); + pasid_flush_caches(iommu, pte, pasid, did); =20 return 0; @@ -669,15 +672,17 @@ int intel_pasid_setup_pass_through(struct intel_iommu= *iommu, u16 did =3D FLPT_DEFAULT_DID; struct pasid_entry *pte; =20 + spin_lock(&iommu->lock); pte =3D intel_pasid_get_entry(dev, pasid); if (!pte) { - dev_err(dev, "Failed to get pasid entry of PASID %d\n", pasid); + spin_unlock(&iommu->lock); return -ENODEV; } =20 - /* Caller must ensure PASID entry is not in use. */ - if (pasid_pte_is_present(pte)) + if (pasid_pte_is_present(pte)) { + spin_unlock(&iommu->lock); return -EBUSY; + } =20 pasid_clear_entry(pte); pasid_set_domain_id(pte, did); @@ -692,6 +697,8 @@ int intel_pasid_setup_pass_through(struct intel_iommu *= iommu, */ pasid_set_sre(pte); pasid_set_present(pte); + spin_unlock(&iommu->lock); + pasid_flush_caches(iommu, pte, pasid, did); =20 return 0; diff --git a/drivers/iommu/intel/svm.c b/drivers/iommu/intel/svm.c index 82288a50660d..64072e628bbd 100644 --- a/drivers/iommu/intel/svm.c +++ b/drivers/iommu/intel/svm.c @@ -394,11 +394,8 @@ static struct iommu_sva *intel_svm_bind_mm(struct inte= l_iommu *iommu, sflags =3D (flags & SVM_FLAG_SUPERVISOR_MODE) ? PASID_FLAG_SUPERVISOR_MODE : 0; sflags |=3D cpu_feature_enabled(X86_FEATURE_LA57) ? PASID_FLAG_FL5LP : 0; - spin_lock(&iommu->lock); ret =3D intel_pasid_setup_first_level(iommu, dev, mm->pgd, mm->pasid, FLPT_DEFAULT_DID, sflags); - spin_unlock(&iommu->lock); - if (ret) goto free_sdev; =20 --=20 2.25.1 From nobody Sat Apr 25 11:48:02 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 A6D5AC433EF for ; Tue, 12 Jul 2022 00:16:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231207AbiGLAQG (ORCPT ); Mon, 11 Jul 2022 20:16:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50388 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231163AbiGLAPb (ORCPT ); Mon, 11 Jul 2022 20:15:31 -0400 Received: from mga03.intel.com (mga03.intel.com [134.134.136.65]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 30DD33DF39 for ; Mon, 11 Jul 2022 17:14:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1657584885; x=1689120885; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=k1ng+aqSA3bxg6XtqN0sxaxbhfr1xdkgYzRBbz8ItSE=; b=afUosRXNM0RYHtIjPHXb7TYs8Wt584uU1Bhf+rT/lq+0aH+AY17w2HrC 52EqtMWByVK5uGL7Knz+0X97bDaZKZP7RsRwmNXy0mmYg1+jNdDUs/+rB jsG/QC+vJCjPry7ouOPKj1bxbyedrbGbw/fr/rUw55ZN3PaDHlGPXyi28 FAacoHepUXRZLIhIMr8sCwP4y57S51x6BKQsu9mxn/mI77rYey5d/chSw v3EMBlbTFAsmirlFuC293f1xwCP2gbmx0PVE3rpfi9CvcuEh1BEpubYU0 tC2DiPNLu9YXaRObmPutWiAY699cs3fr+AkDPDb0IqyKcq/ZCBnx6yTfL Q==; X-IronPort-AV: E=McAfee;i="6400,9594,10405"; a="285929322" X-IronPort-AV: E=Sophos;i="5.92,264,1650956400"; d="scan'208";a="285929322" Received: from orsmga007.jf.intel.com ([10.7.209.58]) by orsmga103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 Jul 2022 17:14:26 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.92,264,1650956400"; d="scan'208";a="592445835" Received: from allen-box.sh.intel.com ([10.239.159.48]) by orsmga007.jf.intel.com with ESMTP; 11 Jul 2022 17:14:05 -0700 From: Lu Baolu To: Joerg Roedel Cc: iommu@lists.linux.dev, linux-kernel@vger.kernel.org Subject: [PATCH 16/25] iommu/vt-d: Check device list of domain in domain free path Date: Tue, 12 Jul 2022 08:08:59 +0800 Message-Id: <20220712000908.3431936-17-baolu.lu@linux.intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220712000908.3431936-1-baolu.lu@linux.intel.com> References: <20220712000908.3431936-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" When the IOMMU domain is about to be freed, it should not be set on any device. Instead of silently dealing with some bug cases, it's better to trigger a warning to report and fix any potential bugs at the first time. Signed-off-by: Lu Baolu Reviewed-by: Jason Gunthorpe Reviewed-by: Kevin Tian Link: https://lore.kernel.org/r/20220706025524.2904370-9-baolu.lu@linux.int= el.com --- drivers/iommu/intel/iommu.c | 18 +++--------------- 1 file changed, 3 insertions(+), 15 deletions(-) diff --git a/drivers/iommu/intel/iommu.c b/drivers/iommu/intel/iommu.c index 3d53de8c7634..a94fb69e1f9a 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 @@ -1841,10 +1840,6 @@ static inline int guestwidth_to_adjustwidth(int gaw) =20 static void domain_exit(struct dmar_domain *domain) { - - /* Remove associated devices and clear attached or cached domains */ - domain_remove_dev_info(domain); - if (domain->pgd) { LIST_HEAD(freelist); =20 @@ -1852,6 +1847,9 @@ static void domain_exit(struct dmar_domain *domain) put_pages_list(&freelist); } =20 + if (WARN_ON(!list_empty(&domain->devices))) + return; + kfree(domain); } =20 @@ -2333,16 +2331,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; - - spin_lock(&device_domain_lock); - list_for_each_entry_safe(info, tmp, &domain->devices, link) - __dmar_remove_one_dev_info(info); - spin_unlock(&device_domain_lock); -} - static int domain_setup_first_level(struct intel_iommu *iommu, struct dmar_domain *domain, struct device *dev, --=20 2.25.1 From nobody Sat Apr 25 11:48:02 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 2B7BBC43334 for ; Tue, 12 Jul 2022 00:15:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231909AbiGLAP5 (ORCPT ); Mon, 11 Jul 2022 20:15:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50650 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231858AbiGLAPU (ORCPT ); Mon, 11 Jul 2022 20:15:20 -0400 Received: from mga03.intel.com (mga03.intel.com [134.134.136.65]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 65F5E2871F for ; Mon, 11 Jul 2022 17:14:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1657584882; x=1689120882; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=P4gYB+84y2MPIxSa53ZGkHcAK9t8GT0kmT5bXXwNBjs=; b=bdx8o3NEgllE6qLgAjRQmxzgEeZ96K/RadiiXk8zWmG3yDXM+aPUgIdz nQ4NToweabohqjcaU8uY+qfHBRTvEMIAV2N9cSKsIcmbKxjxlnxNV06z9 e/ns8G/mq5gAyGisqPsDRDI0pBs90OeYo+NIXo+IRnFVxhWFkaQKUAnqR Xnuyef5UI1RSdbv/IGbx5ZjGWXnHXQm/TiGNMy8/Fuj8JSYpYlZ1sta4K sj5PkguoWsx4et5pWo6l+tElEiL/KFs9y5Zzhf9dy5IkF7iMeuvL0XMW6 k5OPKPCLnuwteoH1EdTIWAyDgXVHxDxeR4yzqp3P7PnEUDPchWuDhI4Mw w==; X-IronPort-AV: E=McAfee;i="6400,9594,10405"; a="285929316" X-IronPort-AV: E=Sophos;i="5.92,264,1650956400"; d="scan'208";a="285929316" Received: from orsmga007.jf.intel.com ([10.7.209.58]) by orsmga103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 Jul 2022 17:14:26 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.92,264,1650956400"; d="scan'208";a="592445841" Received: from allen-box.sh.intel.com ([10.239.159.48]) by orsmga007.jf.intel.com with ESMTP; 11 Jul 2022 17:14:06 -0700 From: Lu Baolu To: Joerg Roedel Cc: iommu@lists.linux.dev, linux-kernel@vger.kernel.org Subject: [PATCH 17/25] iommu/vt-d: Fold __dmar_remove_one_dev_info() into its caller Date: Tue, 12 Jul 2022 08:09:00 +0800 Message-Id: <20220712000908.3431936-18-baolu.lu@linux.intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220712000908.3431936-1-baolu.lu@linux.intel.com> References: <20220712000908.3431936-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" Fold __dmar_remove_one_dev_info() into dmar_remove_one_dev_info() which is its only caller. Make the spin lock critical range only cover the device list change code and remove some unnecessary checks. Signed-off-by: Lu Baolu Reviewed-by: Kevin Tian Link: https://lore.kernel.org/r/20220706025524.2904370-10-baolu.lu@linux.in= tel.com --- drivers/iommu/intel/iommu.c | 32 ++++++++------------------------ 1 file changed, 8 insertions(+), 24 deletions(-) diff --git a/drivers/iommu/intel/iommu.c b/drivers/iommu/intel/iommu.c index a94fb69e1f9a..ccddf634fae9 100644 --- a/drivers/iommu/intel/iommu.c +++ b/drivers/iommu/intel/iommu.c @@ -295,7 +295,6 @@ static LIST_HEAD(dmar_satc_units); static int g_num_of_iommus; =20 static void dmar_remove_one_dev_info(struct device *dev); -static void __dmar_remove_one_dev_info(struct device_domain_info *info); =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); @@ -4137,20 +4136,12 @@ static void domain_context_clear(struct device_doma= in_info *info) &domain_context_clear_one_cb, info); } =20 -static void __dmar_remove_one_dev_info(struct device_domain_info *info) +static void dmar_remove_one_dev_info(struct device *dev) { - struct dmar_domain *domain; - struct intel_iommu *iommu; - - assert_spin_locked(&device_domain_lock); - - if (WARN_ON(!info)) - return; - - iommu =3D info->iommu; - domain =3D info->domain; + struct device_domain_info *info =3D dev_iommu_priv_get(dev); + struct intel_iommu *iommu =3D info->iommu; =20 - if (info->dev && !dev_is_real_dma_subdevice(info->dev)) { + if (!dev_is_real_dma_subdevice(info->dev)) { if (dev_is_pci(info->dev) && sm_supported(iommu)) intel_pasid_tear_down_entry(iommu, info->dev, PASID_RID2PASID, false); @@ -4160,19 +4151,12 @@ static void __dmar_remove_one_dev_info(struct devic= e_domain_info *info) intel_pasid_free_table(info->dev); } =20 - list_del(&info->link); - domain_detach_iommu(domain, iommu); -} - -static void dmar_remove_one_dev_info(struct device *dev) -{ - struct device_domain_info *info; - spin_lock(&device_domain_lock); - info =3D dev_iommu_priv_get(dev); - if (info) - __dmar_remove_one_dev_info(info); + list_del(&info->link); spin_unlock(&device_domain_lock); + + domain_detach_iommu(info->domain, iommu); + info->domain =3D NULL; } =20 static int md_domain_init(struct dmar_domain *domain, int guest_width) --=20 2.25.1 From nobody Sat Apr 25 11:48:02 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 D093FC433EF for ; Tue, 12 Jul 2022 00:16:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231971AbiGLAQL (ORCPT ); Mon, 11 Jul 2022 20:16:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50808 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231445AbiGLAPg (ORCPT ); Mon, 11 Jul 2022 20:15:36 -0400 Received: from mga03.intel.com (mga03.intel.com [134.134.136.65]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BBEA38AB3D for ; Mon, 11 Jul 2022 17:14:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1657584886; x=1689120886; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=C8Uzw/OFgKD9tbEvzPbFnAX3iv82DoXowylUk3SZ2PY=; b=hhvXF/CUXHCocdnQxbJ2Ch7b1Os+WcEuMmuoMfpDqFg5CgWVzXFs8o+L Z/fnjc6tF/6KMFdty7/hFX1nRzemmzrnlcs5EOrUUZp7wOkm8xFqcMcEK 6YqAqzFt2jxwzvwg/jNVq0vJUqvomaBgnstMbMCpegpIn0OFziHNrUd3b 5QiDio70YdykkusbwKjPmsAgeVc4igC71lNwQDEInZIzxpTbu+/jpmYrX cqOkXmfhPXEUVLCDq9Qwn1H7k8LNMJZpNFdT+SMyUuuHxrDr2PkrEiiNE PMtIY2dY6gBaNnhiib8/+dtDmLdfZFuXJBBUM6wN4nwJlaQTl6MnHclRp Q==; X-IronPort-AV: E=McAfee;i="6400,9594,10405"; a="285929325" X-IronPort-AV: E=Sophos;i="5.92,264,1650956400"; d="scan'208";a="285929325" Received: from orsmga007.jf.intel.com ([10.7.209.58]) by orsmga103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 Jul 2022 17:14:26 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.92,264,1650956400"; d="scan'208";a="592445847" Received: from allen-box.sh.intel.com ([10.239.159.48]) by orsmga007.jf.intel.com with ESMTP; 11 Jul 2022 17:14:07 -0700 From: Lu Baolu To: Joerg Roedel Cc: iommu@lists.linux.dev, linux-kernel@vger.kernel.org Subject: [PATCH 18/25] iommu/vt-d: Use device_domain_lock accurately Date: Tue, 12 Jul 2022 08:09:01 +0800 Message-Id: <20220712000908.3431936-19-baolu.lu@linux.intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220712000908.3431936-1-baolu.lu@linux.intel.com> References: <20220712000908.3431936-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 device_domain_lock is used to protect the device tracking list of a domain. Remove unnecessary spin_lock/unlock()'s and move the necessary ones around the list access. Signed-off-by: Lu Baolu Reviewed-by: Kevin Tian Link: https://lore.kernel.org/r/20220706025524.2904370-11-baolu.lu@linux.in= tel.com --- drivers/iommu/intel/iommu.c | 57 +++++++++++++------------------------ 1 file changed, 19 insertions(+), 38 deletions(-) diff --git a/drivers/iommu/intel/iommu.c b/drivers/iommu/intel/iommu.c index ccddf634fae9..ae42a9e43997 100644 --- a/drivers/iommu/intel/iommu.c +++ b/drivers/iommu/intel/iommu.c @@ -535,15 +535,8 @@ static int domain_update_device_node(struct dmar_domai= n *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; - + spin_lock(&device_domain_lock); list_for_each_entry(info, &domain->devices, link) { - if (!info->dev) - continue; - /* * There could possibly be multiple device numa nodes as devices * within the same domain may sit behind different IOMMUs. There @@ -554,6 +547,7 @@ static int domain_update_device_node(struct dmar_domain= *domain) if (nid !=3D NUMA_NO_NODE) break; } + spin_unlock(&device_domain_lock); =20 return nid; } @@ -1376,23 +1370,23 @@ 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; =20 - assert_spin_locked(&device_domain_lock); - if (!iommu->qi) return NULL; =20 - list_for_each_entry(info, &domain->devices, link) + spin_lock(&device_domain_lock); + 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; - break; + spin_unlock(&device_domain_lock); + return info->ats_supported ? info : NULL; } + } + spin_unlock(&device_domain_lock); =20 return NULL; } @@ -1402,23 +1396,21 @@ 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) + spin_lock(&device_domain_lock); + list_for_each_entry(info, &domain->devices, link) { if (info->ats_enabled) { has_iotlb_device =3D true; break; } - + } domain->has_iotlb_device =3D has_iotlb_device; + spin_unlock(&device_domain_lock); } =20 static void iommu_enable_dev_iotlb(struct device_domain_info *info) { struct pci_dev *pdev; =20 - assert_spin_locked(&device_domain_lock); - if (!info || !dev_is_pci(info->dev)) return; =20 @@ -1464,8 +1456,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 @@ -1906,9 +1896,10 @@ static int domain_context_mapping_one(struct dmar_do= main *domain, struct pasid_table *table, u8 bus, u8 devfn) { + struct device_domain_info *info =3D + iommu_support_dev_iotlb(domain, iommu, bus, devfn); u16 did =3D domain->iommu_did[iommu->seq_id]; int translation =3D CONTEXT_TT_MULTI_LEVEL; - struct device_domain_info *info =3D NULL; struct context_entry *context; int ret; =20 @@ -1922,9 +1913,7 @@ static int domain_context_mapping_one(struct dmar_dom= ain *domain, =20 BUG_ON(!domain->pgd); =20 - spin_lock(&device_domain_lock); spin_lock(&iommu->lock); - ret =3D -ENOMEM; context =3D iommu_context_addr(iommu, bus, devfn, 1); if (!context) @@ -1975,7 +1964,6 @@ static int domain_context_mapping_one(struct dmar_dom= ain *domain, * Setup the Device-TLB enable bit and Page request * Enable bit: */ - info =3D iommu_support_dev_iotlb(domain, iommu, bus, devfn); if (info && info->ats_supported) context_set_sm_dte(context); if (info && info->pri_supported) @@ -1998,7 +1986,6 @@ static int domain_context_mapping_one(struct dmar_dom= ain *domain, goto out_unlock; } =20 - info =3D iommu_support_dev_iotlb(domain, iommu, bus, devfn); if (info && info->ats_supported) translation =3D CONTEXT_TT_DEV_IOTLB; else @@ -2044,7 +2031,6 @@ static int domain_context_mapping_one(struct dmar_dom= ain *domain, =20 out_unlock: spin_unlock(&iommu->lock); - spin_unlock(&device_domain_lock); =20 return ret; } @@ -2456,13 +2442,11 @@ static int domain_add_dev_info(struct dmar_domain *= domain, struct device *dev) if (!iommu) return -ENODEV; =20 - spin_lock(&device_domain_lock); - info->domain =3D domain; ret =3D domain_attach_iommu(domain, iommu); - if (ret) { - spin_unlock(&device_domain_lock); + if (ret) return ret; - } + info->domain =3D domain; + spin_lock(&device_domain_lock); list_add(&info->link, &domain->devices); spin_unlock(&device_domain_lock); =20 @@ -4638,9 +4622,7 @@ int intel_iommu_enable_pasid(struct intel_iommu *iomm= u, struct device *dev) if (!domain) return -EINVAL; =20 - spin_lock(&device_domain_lock); spin_lock(&iommu->lock); - ret =3D -EINVAL; if (!info->pasid_supported) goto out; @@ -4670,7 +4652,6 @@ int intel_iommu_enable_pasid(struct intel_iommu *iomm= u, struct device *dev) =20 out: spin_unlock(&iommu->lock); - spin_unlock(&device_domain_lock); =20 return ret; } --=20 2.25.1 From nobody Sat Apr 25 11:48:02 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 BD392C43334 for ; Tue, 12 Jul 2022 00:16:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231945AbiGLAQ3 (ORCPT ); Mon, 11 Jul 2022 20:16:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50008 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231882AbiGLAPx (ORCPT ); Mon, 11 Jul 2022 20:15:53 -0400 Received: from mga03.intel.com (mga03.intel.com [134.134.136.65]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D849E8C75A for ; Mon, 11 Jul 2022 17:14:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1657584896; x=1689120896; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=j52eFjojsS3ryVUuyUpOBq6jAIhg/qeDs4m74HzKtcA=; b=MKwCVg4o5OVrxoBOrgIA7nCcP9IgzZK2c4RS5KSkN8tjobOmOROqRK0s T7LBbEWOBpW4hpj9YKxpK4L+eqr9u+Gq1lNqAk7aLN4hx8HGFQ/D43eaO pcSZFf4UjebUoVgZtY1zDYhvO1YlKw4YT3mu3uIsPpXpn2GLJT0mL6afi sSglmnu/JRVg4EVfLyv0i19n62Mzx4P3wHFvSiL3fE9GXlsqSGP2QwRja sY5e4Fxjb85PpllwP+RFJYKuS/FEH1JVDO9tfrQ0YpAZx/gqRegzxnSRt i+Y3+VsaEr1Fw8zE5CZpDQRj3Tq8Yz14henO/Iw8L8+/uqsnUBmyGM0Lf Q==; X-IronPort-AV: E=McAfee;i="6400,9594,10405"; a="285929341" X-IronPort-AV: E=Sophos;i="5.92,264,1650956400"; d="scan'208";a="285929341" Received: from orsmga007.jf.intel.com ([10.7.209.58]) by orsmga103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 Jul 2022 17:14:27 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.92,264,1650956400"; d="scan'208";a="592445854" Received: from allen-box.sh.intel.com ([10.239.159.48]) by orsmga007.jf.intel.com with ESMTP; 11 Jul 2022 17:14:08 -0700 From: Lu Baolu To: Joerg Roedel Cc: iommu@lists.linux.dev, linux-kernel@vger.kernel.org Subject: [PATCH 19/25] iommu/vt-d: Convert global spinlock into per domain lock Date: Tue, 12 Jul 2022 08:09:02 +0800 Message-Id: <20220712000908.3431936-20-baolu.lu@linux.intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220712000908.3431936-1-baolu.lu@linux.intel.com> References: <20220712000908.3431936-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" Using a global device_domain_lock spinlock to protect per-domain device tracking lists is an inefficient way, especially considering this lock is also needed in the hot paths. This optimizes the locking mechanism by converting the global lock to per domain lock. On the other hand, as the device tracking lists are never accessed in any interrupt context, there is no need to disable interrupts while spinning. Replace irqsave variant with spinlock calls. Signed-off-by: Lu Baolu Reviewed-by: Kevin Tian Link: https://lore.kernel.org/r/20220706025524.2904370-12-baolu.lu@linux.in= tel.com --- drivers/iommu/intel/iommu.h | 1 + drivers/iommu/intel/iommu.c | 42 ++++++++++++++++++------------------- 2 files changed, 22 insertions(+), 21 deletions(-) diff --git a/drivers/iommu/intel/iommu.h b/drivers/iommu/intel/iommu.h index 198c6c822ef4..df64d3d9c49a 100644 --- a/drivers/iommu/intel/iommu.h +++ b/drivers/iommu/intel/iommu.h @@ -541,6 +541,7 @@ struct dmar_domain { u8 force_snooping : 1; /* Create IOPTEs with snoop control */ u8 set_pte_snp:1; =20 + spinlock_t lock; /* Protect device tracking lists */ struct list_head devices; /* all devices' list */ =20 struct dma_pte *pgd; /* virtual address */ diff --git a/drivers/iommu/intel/iommu.c b/drivers/iommu/intel/iommu.c index ae42a9e43997..769e850b9767 100644 --- a/drivers/iommu/intel/iommu.c +++ b/drivers/iommu/intel/iommu.c @@ -310,7 +310,6 @@ static int iommu_skip_te_disable; #define IDENTMAP_GFX 2 #define IDENTMAP_AZALIA 4 =20 -static DEFINE_SPINLOCK(device_domain_lock); const struct iommu_ops intel_iommu_ops; =20 static bool translation_pre_enabled(struct intel_iommu *iommu) @@ -535,7 +534,7 @@ static int domain_update_device_node(struct dmar_domain= *domain) struct device_domain_info *info; int nid =3D NUMA_NO_NODE; =20 - spin_lock(&device_domain_lock); + spin_lock(&domain->lock); list_for_each_entry(info, &domain->devices, link) { /* * There could possibly be multiple device numa nodes as devices @@ -547,7 +546,7 @@ static int domain_update_device_node(struct dmar_domain= *domain) if (nid !=3D NUMA_NO_NODE) break; } - spin_unlock(&device_domain_lock); + spin_unlock(&domain->lock); =20 return nid; } @@ -1378,15 +1377,15 @@ iommu_support_dev_iotlb(struct dmar_domain *domain,= struct intel_iommu *iommu, if (!iommu->qi) return NULL; =20 - spin_lock(&device_domain_lock); + spin_lock(&domain->lock); list_for_each_entry(info, &domain->devices, link) { if (info->iommu =3D=3D iommu && info->bus =3D=3D bus && info->devfn =3D=3D devfn) { - spin_unlock(&device_domain_lock); + spin_unlock(&domain->lock); return info->ats_supported ? info : NULL; } } - spin_unlock(&device_domain_lock); + spin_unlock(&domain->lock); =20 return NULL; } @@ -1396,7 +1395,7 @@ static void domain_update_iotlb(struct dmar_domain *d= omain) struct device_domain_info *info; bool has_iotlb_device =3D false; =20 - spin_lock(&device_domain_lock); + spin_lock(&domain->lock); list_for_each_entry(info, &domain->devices, link) { if (info->ats_enabled) { has_iotlb_device =3D true; @@ -1404,7 +1403,7 @@ static void domain_update_iotlb(struct dmar_domain *d= omain) } } domain->has_iotlb_device =3D has_iotlb_device; - spin_unlock(&device_domain_lock); + spin_unlock(&domain->lock); } =20 static void iommu_enable_dev_iotlb(struct device_domain_info *info) @@ -1500,10 +1499,10 @@ static void iommu_flush_dev_iotlb(struct dmar_domai= n *domain, if (!domain->has_iotlb_device) return; =20 - spin_lock(&device_domain_lock); + spin_lock(&domain->lock); list_for_each_entry(info, &domain->devices, link) __iommu_flush_dev_iotlb(info, addr, mask); - spin_unlock(&device_domain_lock); + spin_unlock(&domain->lock); } =20 static void iommu_flush_iotlb_psi(struct intel_iommu *iommu, @@ -1763,6 +1762,7 @@ static struct dmar_domain *alloc_domain(unsigned int = type) domain->flags |=3D DOMAIN_FLAG_USE_FIRST_LEVEL; domain->has_iotlb_device =3D false; INIT_LIST_HEAD(&domain->devices); + spin_lock_init(&domain->lock); =20 return domain; } @@ -2446,9 +2446,9 @@ static int domain_add_dev_info(struct dmar_domain *do= main, struct device *dev) if (ret) return ret; info->domain =3D domain; - spin_lock(&device_domain_lock); + spin_lock(&domain->lock); list_add(&info->link, &domain->devices); - spin_unlock(&device_domain_lock); + spin_unlock(&domain->lock); =20 /* PASID table is mandatory for a PCI device in scalable mode. */ if (sm_supported(iommu) && !dev_is_real_dma_subdevice(dev)) { @@ -4123,6 +4123,7 @@ static void domain_context_clear(struct device_domain= _info *info) static void dmar_remove_one_dev_info(struct device *dev) { struct device_domain_info *info =3D dev_iommu_priv_get(dev); + struct dmar_domain *domain =3D info->domain; struct intel_iommu *iommu =3D info->iommu; =20 if (!dev_is_real_dma_subdevice(info->dev)) { @@ -4135,11 +4136,11 @@ static void dmar_remove_one_dev_info(struct device = *dev) intel_pasid_free_table(info->dev); } =20 - spin_lock(&device_domain_lock); + spin_lock(&domain->lock); list_del(&info->link); - spin_unlock(&device_domain_lock); + spin_unlock(&domain->lock); =20 - domain_detach_iommu(info->domain, iommu); + domain_detach_iommu(domain, iommu); info->domain =3D NULL; } =20 @@ -4422,7 +4423,7 @@ static bool domain_support_force_snooping(struct dmar= _domain *domain) struct device_domain_info *info; bool support =3D true; =20 - assert_spin_locked(&device_domain_lock); + assert_spin_locked(&domain->lock); list_for_each_entry(info, &domain->devices, link) { if (!ecap_sc_support(info->iommu->ecap)) { support =3D false; @@ -4437,8 +4438,7 @@ static void domain_set_force_snooping(struct dmar_dom= ain *domain) { struct device_domain_info *info; =20 - assert_spin_locked(&device_domain_lock); - + assert_spin_locked(&domain->lock); /* * Second level page table supports per-PTE snoop control. The * iommu_map() interface will handle this by setting SNP bit. @@ -4460,15 +4460,15 @@ static bool intel_iommu_enforce_cache_coherency(str= uct iommu_domain *domain) if (dmar_domain->force_snooping) return true; =20 - spin_lock(&device_domain_lock); + spin_lock(&dmar_domain->lock); if (!domain_support_force_snooping(dmar_domain)) { - spin_unlock(&device_domain_lock); + spin_unlock(&dmar_domain->lock); return false; } =20 domain_set_force_snooping(dmar_domain); dmar_domain->force_snooping =3D true; - spin_unlock(&device_domain_lock); + spin_unlock(&dmar_domain->lock); =20 return true; } --=20 2.25.1 From nobody Sat Apr 25 11:48:02 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 97E6EC433EF for ; Tue, 12 Jul 2022 00:15:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231880AbiGLAP1 (ORCPT ); Mon, 11 Jul 2022 20:15:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49412 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230370AbiGLAPF (ORCPT ); Mon, 11 Jul 2022 20:15:05 -0400 Received: from mga04.intel.com (mga04.intel.com [192.55.52.120]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 334AF32BAC for ; Mon, 11 Jul 2022 17:14:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1657584869; x=1689120869; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=94MIxLZGh7cLOMunSeLNvcXgG4W8P5quRK88jbR6hII=; b=M87iP3qVwGgymewFelUhHkm2v0mZ/qvzSfMN5Vy6HES9yD/JtW2HMDVE Ku0wHF6WyBq7kJirybAMj6IOzN2/4xU8BpXDSlUCHialpo+v8zwJSvAHX c7cNmR1CCUOUzOCpcCqKLewXCnfz3g9MkpxPb0+IqpfgtEZrulEK6jJ82 bgwhBtqBK7LiNa0UBX99H9xkg9mFjQSH2pKB+pTMukiw7GhmoHQqZw1Zd u38zP3TGwiNacPqyzMoEJvXvnmLq3ONcy1JJn7rDK6kdDhUtrKd7bfQTE 7cbuvFQoFeGMZ/V9xZuTp1wVHNN1Ofwy7ufTES/dX5QUeUwQ67UDsr1oK w==; X-IronPort-AV: E=McAfee;i="6400,9594,10405"; a="283555235" X-IronPort-AV: E=Sophos;i="5.92,264,1650956400"; d="scan'208";a="283555235" Received: from orsmga007.jf.intel.com ([10.7.209.58]) by fmsmga104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 Jul 2022 17:14:27 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.92,264,1650956400"; d="scan'208";a="592445861" Received: from allen-box.sh.intel.com ([10.239.159.48]) by orsmga007.jf.intel.com with ESMTP; 11 Jul 2022 17:14:10 -0700 From: Lu Baolu To: Joerg Roedel Cc: iommu@lists.linux.dev, linux-kernel@vger.kernel.org Subject: [PATCH 20/25] iommu/vt-d: Remove unused domain_get_iommu() Date: Tue, 12 Jul 2022 08:09:03 +0800 Message-Id: <20220712000908.3431936-21-baolu.lu@linux.intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220712000908.3431936-1-baolu.lu@linux.intel.com> References: <20220712000908.3431936-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" It is not used anywhere. Remove it to avoid dead code. Signed-off-by: Lu Baolu Reviewed-by: Kevin Tian Reviewed-by: Steve Wahl Link: https://lore.kernel.org/r/20220702015610.2849494-2-baolu.lu@linux.int= el.com --- drivers/iommu/intel/iommu.h | 1 - drivers/iommu/intel/iommu.c | 18 ------------------ 2 files changed, 19 deletions(-) diff --git a/drivers/iommu/intel/iommu.h b/drivers/iommu/intel/iommu.h index df64d3d9c49a..56e0d8cd2102 100644 --- a/drivers/iommu/intel/iommu.h +++ b/drivers/iommu/intel/iommu.h @@ -725,7 +725,6 @@ extern int dmar_ir_support(void); =20 void *alloc_pgtable_page(int node); void free_pgtable_page(void *vaddr); -struct intel_iommu *domain_get_iommu(struct dmar_domain *domain); void iommu_flush_write_buffer(struct intel_iommu *iommu); int intel_iommu_enable_pasid(struct intel_iommu *iommu, struct device *dev= ); struct intel_iommu *device_to_iommu(struct device *dev, u8 *bus, u8 *devfn= ); diff --git a/drivers/iommu/intel/iommu.c b/drivers/iommu/intel/iommu.c index 769e850b9767..55a055a8ed4b 100644 --- a/drivers/iommu/intel/iommu.c +++ b/drivers/iommu/intel/iommu.c @@ -445,24 +445,6 @@ int iommu_calculate_agaw(struct intel_iommu *iommu) return __iommu_calculate_agaw(iommu, DEFAULT_DOMAIN_ADDRESS_WIDTH); } =20 -/* This functionin only returns single iommu in a domain */ -struct intel_iommu *domain_get_iommu(struct dmar_domain *domain) -{ - int iommu_id; - - /* si_domain and vm domain should not get here. */ - if (WARN_ON(!iommu_is_dma_domain(&domain->domain))) - return NULL; - - for_each_domain_iommu(iommu_id, domain) - break; - - if (iommu_id < 0 || iommu_id >=3D g_num_of_iommus) - return NULL; - - return g_iommus[iommu_id]; -} - static inline bool iommu_paging_structure_coherency(struct intel_iommu *io= mmu) { return sm_supported(iommu) ? --=20 2.25.1 From nobody Sat Apr 25 11:48:02 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 38482C43334 for ; Tue, 12 Jul 2022 00:16:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231926AbiGLAQB (ORCPT ); Mon, 11 Jul 2022 20:16:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50010 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229764AbiGLAPX (ORCPT ); Mon, 11 Jul 2022 20:15:23 -0400 Received: from mga17.intel.com (mga17.intel.com [192.55.52.151]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A06902AC56 for ; Mon, 11 Jul 2022 17:14:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1657584884; x=1689120884; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=+PRn+weX3k7n//TPZyvFREn2hlm1uJvICybl4nuKpt8=; b=GxxE4KH0x+zj7WoJlCuukrQQLf0PqUWnJmLE/CtG6cp7Agb78Lk0xiv6 0hcI4fFhvv96YN/aTxJMAZDolft/b1wzqddW2oMq/w5TTE4dApFvml2S/ 9Zi2B4Kn/66j4Kg/ZaLVsnWSTltmN6xGI4/IQEHgr1Q4Z8pMOD8B41msk I9AU21wz09wZzn1gbunwH5ik2wdbbuDw/M68/uv3NLNt7HUOtPjWfbSP9 lsM2BFjT6ieIFbfYvSbe+lIoQf9eTDGRcpMz6W60SrClSHN+qkd5qMJtt krUBRmAAgnq9llErs5t5/ykXO2rYEGyCtoj3YOOCJfQusbwMTje2bE0hB A==; X-IronPort-AV: E=McAfee;i="6400,9594,10405"; a="265213623" X-IronPort-AV: E=Sophos;i="5.92,264,1650956400"; d="scan'208";a="265213623" Received: from orsmga007.jf.intel.com ([10.7.209.58]) by fmsmga107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 Jul 2022 17:14:27 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.92,264,1650956400"; d="scan'208";a="592445863" Received: from allen-box.sh.intel.com ([10.239.159.48]) by orsmga007.jf.intel.com with ESMTP; 11 Jul 2022 17:14:11 -0700 From: Lu Baolu To: Joerg Roedel Cc: iommu@lists.linux.dev, linux-kernel@vger.kernel.org Subject: [PATCH 21/25] iommu/vt-d: Use IDA interface to manage iommu sequence id Date: Tue, 12 Jul 2022 08:09:04 +0800 Message-Id: <20220712000908.3431936-22-baolu.lu@linux.intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220712000908.3431936-1-baolu.lu@linux.intel.com> References: <20220712000908.3431936-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" Switch dmar unit sequence id allocation and release from bitmap to IDA interface. Signed-off-by: Lu Baolu Reviewed-by: Kevin Tian Reviewed-by: Steve Wahl Link: https://lore.kernel.org/r/20220702015610.2849494-3-baolu.lu@linux.int= el.com --- drivers/iommu/intel/dmar.c | 35 ++++++++--------------------------- 1 file changed, 8 insertions(+), 27 deletions(-) diff --git a/drivers/iommu/intel/dmar.c b/drivers/iommu/intel/dmar.c index 2a5e0f91e647..6327b34f5aa7 100644 --- a/drivers/iommu/intel/dmar.c +++ b/drivers/iommu/intel/dmar.c @@ -60,7 +60,7 @@ LIST_HEAD(dmar_drhd_units); =20 struct acpi_table_header * __initdata dmar_tbl; static int dmar_dev_scope_status =3D 1; -static unsigned long dmar_seq_ids[BITS_TO_LONGS(DMAR_UNITS_SUPPORTED)]; +static DEFINE_IDA(dmar_seq_ids); =20 static int alloc_iommu(struct dmar_drhd_unit *drhd); static void free_iommu(struct intel_iommu *iommu); @@ -1023,28 +1023,6 @@ static int map_iommu(struct intel_iommu *iommu, u64 = phys_addr) return err; } =20 -static int dmar_alloc_seq_id(struct intel_iommu *iommu) -{ - iommu->seq_id =3D find_first_zero_bit(dmar_seq_ids, - DMAR_UNITS_SUPPORTED); - if (iommu->seq_id >=3D DMAR_UNITS_SUPPORTED) { - iommu->seq_id =3D -1; - } else { - set_bit(iommu->seq_id, dmar_seq_ids); - sprintf(iommu->name, "dmar%d", iommu->seq_id); - } - - return iommu->seq_id; -} - -static void dmar_free_seq_id(struct intel_iommu *iommu) -{ - if (iommu->seq_id >=3D 0) { - clear_bit(iommu->seq_id, dmar_seq_ids); - iommu->seq_id =3D -1; - } -} - static int alloc_iommu(struct dmar_drhd_unit *drhd) { struct intel_iommu *iommu; @@ -1062,11 +1040,14 @@ static int alloc_iommu(struct dmar_drhd_unit *drhd) if (!iommu) return -ENOMEM; =20 - if (dmar_alloc_seq_id(iommu) < 0) { + iommu->seq_id =3D ida_alloc_range(&dmar_seq_ids, 0, + DMAR_UNITS_SUPPORTED - 1, GFP_KERNEL); + if (iommu->seq_id < 0) { pr_err("Failed to allocate seq_id\n"); - err =3D -ENOSPC; + err =3D iommu->seq_id; goto error; } + sprintf(iommu->name, "dmar%d", iommu->seq_id); =20 err =3D map_iommu(iommu, drhd->reg_base_addr); if (err) { @@ -1150,7 +1131,7 @@ static int alloc_iommu(struct dmar_drhd_unit *drhd) err_unmap: unmap_iommu(iommu); error_free_seq_id: - dmar_free_seq_id(iommu); + ida_free(&dmar_seq_ids, iommu->seq_id); error: kfree(iommu); return err; @@ -1183,7 +1164,7 @@ static void free_iommu(struct intel_iommu *iommu) if (iommu->reg) unmap_iommu(iommu); =20 - dmar_free_seq_id(iommu); + ida_free(&dmar_seq_ids, iommu->seq_id); kfree(iommu); } =20 --=20 2.25.1 From nobody Sat Apr 25 11:48:02 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 5E5C6C43334 for ; Tue, 12 Jul 2022 00:15:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230224AbiGLAPx (ORCPT ); Mon, 11 Jul 2022 20:15:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50646 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231862AbiGLAPU (ORCPT ); Mon, 11 Jul 2022 20:15:20 -0400 Received: from mga17.intel.com (mga17.intel.com [192.55.52.151]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E69C52B258 for ; Mon, 11 Jul 2022 17:14:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1657584881; x=1689120881; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=lwF2Fvtia29PT9os1xwLru7hutISh3/dt5WXPQUZdME=; b=JJYSyk7/w92CoRQYa9uLXj1iozOmZFqzWLxwV1xhNfCDRG5ulEM9oQY2 MsqgmFt3hRU/89eCVIlyFqDA/4c7IF+NPSi2IEZs1THmubr+/EE/Jz6+y soRpp8wzMlnPHIvxdwByrsH8sHqywI6G05tDgOOLUyavovXUUXQ7RqVSl rHr4E2j6mfK/Syyd2m2W6L7LLJplysfQlcCXSIXQgYzhEGfKaKVwt1My/ js03M00Ioqze/P/C/9ys+1xkFu4J+8yVZr7QJ6/Lte7NFOeqJrNTYwArB 9v0rIxTGTXFkw2d6JzPlRKhCy0y6s00epvN0W6NVkyup00VDRPt31bG8I g==; X-IronPort-AV: E=McAfee;i="6400,9594,10405"; a="265213622" X-IronPort-AV: E=Sophos;i="5.92,264,1650956400"; d="scan'208";a="265213622" Received: from orsmga007.jf.intel.com ([10.7.209.58]) by fmsmga107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 Jul 2022 17:14:27 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.92,264,1650956400"; d="scan'208";a="592445864" Received: from allen-box.sh.intel.com ([10.239.159.48]) by orsmga007.jf.intel.com with ESMTP; 11 Jul 2022 17:14:12 -0700 From: Lu Baolu To: Joerg Roedel Cc: iommu@lists.linux.dev, linux-kernel@vger.kernel.org Subject: [PATCH 22/25] iommu/vt-d: Refactor iommu information of each domain Date: Tue, 12 Jul 2022 08:09:05 +0800 Message-Id: <20220712000908.3431936-23-baolu.lu@linux.intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220712000908.3431936-1-baolu.lu@linux.intel.com> References: <20220712000908.3431936-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" When a DMA domain is attached to a device, it needs to allocate a domain ID from its IOMMU. Currently, the domain ID information is stored in two static arrays embedded in the domain structure. This can lead to memory waste when the driver is running on a small platform. This optimizes these static arrays by replacing them with an xarray and consuming memory on demand. Signed-off-by: Lu Baolu Reviewed-by: Kevin Tian Reviewed-by: Steve Wahl Link: https://lore.kernel.org/r/20220702015610.2849494-4-baolu.lu@linux.int= el.com --- drivers/iommu/intel/iommu.h | 29 ++++++--- drivers/iommu/intel/iommu.c | 123 +++++++++++++++++++++--------------- drivers/iommu/intel/pasid.c | 2 +- drivers/iommu/intel/svm.c | 2 +- 4 files changed, 93 insertions(+), 63 deletions(-) diff --git a/drivers/iommu/intel/iommu.h b/drivers/iommu/intel/iommu.h index 56e0d8cd2102..fae45bbb0c7f 100644 --- a/drivers/iommu/intel/iommu.h +++ b/drivers/iommu/intel/iommu.h @@ -21,6 +21,7 @@ #include #include #include +#include =20 #include #include @@ -524,17 +525,17 @@ struct context_entry { */ #define DOMAIN_FLAG_USE_FIRST_LEVEL BIT(1) =20 -struct dmar_domain { - int nid; /* node id */ - - unsigned int iommu_refcnt[DMAR_UNITS_SUPPORTED]; - /* Refcount of devices per iommu */ - - - u16 iommu_did[DMAR_UNITS_SUPPORTED]; - /* Domain ids per IOMMU. Use u16 since +struct iommu_domain_info { + struct intel_iommu *iommu; + unsigned int refcnt; /* Refcount of devices per iommu */ + u16 did; /* Domain ids per IOMMU. Use u16 since * domain ids are 16 bit wide according * to VT-d spec, section 9.3 */ +}; + +struct dmar_domain { + int nid; /* node id */ + struct xarray iommu_array; /* Attached IOMMU array */ =20 u8 has_iotlb_device: 1; u8 iommu_coherency: 1; /* indicate coherency of iommu access */ @@ -640,6 +641,16 @@ static inline struct dmar_domain *to_dmar_domain(struc= t iommu_domain *dom) return container_of(dom, struct dmar_domain, domain); } =20 +/* Retrieve the domain ID which has allocated to the domain */ +static inline u16 +domain_id_iommu(struct dmar_domain *domain, struct intel_iommu *iommu) +{ + struct iommu_domain_info *info =3D + xa_load(&domain->iommu_array, iommu->seq_id); + + return info->did; +} + /* * 0: readable * 1: writable diff --git a/drivers/iommu/intel/iommu.c b/drivers/iommu/intel/iommu.c index 55a055a8ed4b..36b3649a83e8 100644 --- a/drivers/iommu/intel/iommu.c +++ b/drivers/iommu/intel/iommu.c @@ -254,10 +254,6 @@ static inline void context_clear_entry(struct context_= entry *context) static struct dmar_domain *si_domain; static int hw_pass_through =3D 1; =20 -#define for_each_domain_iommu(idx, domain) \ - for (idx =3D 0; idx < g_num_of_iommus; idx++) \ - if (domain->iommu_refcnt[idx]) - struct dmar_rmrr_unit { struct list_head list; /* list of rmrr units */ struct acpi_dmar_header *hdr; /* ACPI header */ @@ -453,16 +449,16 @@ static inline bool iommu_paging_structure_coherency(s= truct intel_iommu *iommu) =20 static void domain_update_iommu_coherency(struct dmar_domain *domain) { + struct iommu_domain_info *info; struct dmar_drhd_unit *drhd; struct intel_iommu *iommu; bool found =3D false; - int i; + unsigned long i; =20 domain->iommu_coherency =3D true; - - for_each_domain_iommu(i, domain) { + xa_for_each(&domain->iommu_array, i, info) { found =3D true; - if (!iommu_paging_structure_coherency(g_iommus[i])) { + if (!iommu_paging_structure_coherency(info->iommu)) { domain->iommu_coherency =3D false; break; } @@ -1495,7 +1491,7 @@ static void iommu_flush_iotlb_psi(struct intel_iommu = *iommu, unsigned int aligned_pages =3D __roundup_pow_of_two(pages); unsigned int mask =3D ilog2(aligned_pages); uint64_t addr =3D (uint64_t)pfn << VTD_PAGE_SHIFT; - u16 did =3D domain->iommu_did[iommu->seq_id]; + u16 did =3D domain_id_iommu(domain, iommu); =20 BUG_ON(pages =3D=3D 0); =20 @@ -1565,11 +1561,12 @@ static inline void __mapping_notify_one(struct inte= l_iommu *iommu, static void intel_flush_iotlb_all(struct iommu_domain *domain) { struct dmar_domain *dmar_domain =3D to_dmar_domain(domain); - int idx; + struct iommu_domain_info *info; + unsigned long idx; =20 - for_each_domain_iommu(idx, dmar_domain) { - struct intel_iommu *iommu =3D g_iommus[idx]; - u16 did =3D dmar_domain->iommu_did[iommu->seq_id]; + xa_for_each(&dmar_domain->iommu_array, idx, info) { + struct intel_iommu *iommu =3D info->iommu; + u16 did =3D domain_id_iommu(dmar_domain, iommu); =20 if (domain_use_first_level(dmar_domain)) qi_flush_piotlb(iommu, did, PASID_RID2PASID, 0, -1, 0); @@ -1745,6 +1742,7 @@ static struct dmar_domain *alloc_domain(unsigned int = type) domain->has_iotlb_device =3D false; INIT_LIST_HEAD(&domain->devices); spin_lock_init(&domain->lock); + xa_init(&domain->iommu_array); =20 return domain; } @@ -1752,45 +1750,66 @@ static struct dmar_domain *alloc_domain(unsigned in= t type) static int domain_attach_iommu(struct dmar_domain *domain, struct intel_iommu *iommu) { + struct iommu_domain_info *info, *curr; unsigned long ndomains; - int num, ret =3D 0; + int num, ret =3D -ENOSPC; + + info =3D kzalloc(sizeof(*info), GFP_KERNEL); + if (!info) + return -ENOMEM; =20 spin_lock(&iommu->lock); - domain->iommu_refcnt[iommu->seq_id] +=3D 1; - if (domain->iommu_refcnt[iommu->seq_id] =3D=3D 1) { - ndomains =3D cap_ndoms(iommu->cap); - num =3D find_first_zero_bit(iommu->domain_ids, ndomains); - - if (num >=3D ndomains) { - pr_err("%s: No free domain ids\n", iommu->name); - domain->iommu_refcnt[iommu->seq_id] -=3D 1; - ret =3D -ENOSPC; - goto out_unlock; - } + curr =3D xa_load(&domain->iommu_array, iommu->seq_id); + if (curr) { + curr->refcnt++; + spin_unlock(&iommu->lock); + kfree(info); + return 0; + } =20 - set_bit(num, iommu->domain_ids); - domain->iommu_did[iommu->seq_id] =3D num; - domain->nid =3D iommu->node; - domain_update_iommu_cap(domain); + ndomains =3D cap_ndoms(iommu->cap); + num =3D find_first_zero_bit(iommu->domain_ids, ndomains); + if (num >=3D ndomains) { + pr_err("%s: No free domain ids\n", iommu->name); + goto err_unlock; } =20 -out_unlock: + set_bit(num, iommu->domain_ids); + info->refcnt =3D 1; + info->did =3D num; + info->iommu =3D iommu; + curr =3D xa_cmpxchg(&domain->iommu_array, iommu->seq_id, + NULL, info, GFP_ATOMIC); + if (curr) { + ret =3D xa_err(curr) ? : -EBUSY; + goto err_clear; + } + domain_update_iommu_cap(domain); + spin_unlock(&iommu->lock); + return 0; + +err_clear: + clear_bit(info->did, iommu->domain_ids); +err_unlock: + spin_unlock(&iommu->lock); + kfree(info); return ret; } =20 static void domain_detach_iommu(struct dmar_domain *domain, struct intel_iommu *iommu) { - int num; + struct iommu_domain_info *info; =20 spin_lock(&iommu->lock); - domain->iommu_refcnt[iommu->seq_id] -=3D 1; - if (domain->iommu_refcnt[iommu->seq_id] =3D=3D 0) { - num =3D domain->iommu_did[iommu->seq_id]; - clear_bit(num, iommu->domain_ids); + info =3D xa_load(&domain->iommu_array, iommu->seq_id); + if (--info->refcnt =3D=3D 0) { + clear_bit(info->did, iommu->domain_ids); + xa_erase(&domain->iommu_array, iommu->seq_id); + domain->nid =3D NUMA_NO_NODE; domain_update_iommu_cap(domain); - domain->iommu_did[iommu->seq_id] =3D 0; + kfree(info); } spin_unlock(&iommu->lock); } @@ -1880,7 +1899,7 @@ static int domain_context_mapping_one(struct dmar_dom= ain *domain, { struct device_domain_info *info =3D iommu_support_dev_iotlb(domain, iommu, bus, devfn); - u16 did =3D domain->iommu_did[iommu->seq_id]; + u16 did =3D domain_id_iommu(domain, iommu); int translation =3D CONTEXT_TT_MULTI_LEVEL; struct context_entry *context; int ret; @@ -2129,8 +2148,9 @@ static void switch_to_super_page(struct dmar_domain *= domain, unsigned long end_pfn, int level) { unsigned long lvl_pages =3D lvl_to_nr_pages(level); + struct iommu_domain_info *info; struct dma_pte *pte =3D NULL; - int i; + unsigned long i; =20 while (start_pfn <=3D end_pfn) { if (!pte) @@ -2141,8 +2161,8 @@ static void switch_to_super_page(struct dmar_domain *= domain, start_pfn + lvl_pages - 1, level + 1); =20 - for_each_domain_iommu(i, domain) - iommu_flush_iotlb_psi(g_iommus[i], domain, + xa_for_each(&domain->iommu_array, i, info) + iommu_flush_iotlb_psi(info->iommu, domain, start_pfn, lvl_pages, 0, 0); } @@ -2272,7 +2292,7 @@ static void domain_context_clear_one(struct device_do= main_info *info, u8 bus, u8 if (hw_pass_through && domain_type_is_si(info->domain)) did_old =3D FLPT_DEFAULT_DID; else - did_old =3D info->domain->iommu_did[iommu->seq_id]; + did_old =3D domain_id_iommu(info->domain, iommu); } else { did_old =3D context_domain_id(context); } @@ -2330,7 +2350,7 @@ static int domain_setup_first_level(struct intel_iomm= u *iommu, flags |=3D PASID_FLAG_PAGE_SNOOP; =20 return intel_pasid_setup_first_level(iommu, dev, (pgd_t *)pgd, pasid, - domain->iommu_did[iommu->seq_id], + domain_id_iommu(domain, iommu), flags); } =20 @@ -4368,15 +4388,16 @@ static void intel_iommu_tlb_sync(struct iommu_domai= n *domain, struct dmar_domain *dmar_domain =3D to_dmar_domain(domain); unsigned long iova_pfn =3D IOVA_PFN(gather->start); size_t size =3D gather->end - gather->start; + struct iommu_domain_info *info; unsigned long start_pfn; unsigned long nrpages; - int iommu_id; + unsigned long i; =20 nrpages =3D aligned_nrpages(gather->start, size); start_pfn =3D mm_to_dma_pfn(iova_pfn); =20 - for_each_domain_iommu(iommu_id, dmar_domain) - iommu_flush_iotlb_psi(g_iommus[iommu_id], dmar_domain, + xa_for_each(&dmar_domain->iommu_array, i, info) + iommu_flush_iotlb_psi(info->iommu, dmar_domain, start_pfn, nrpages, list_empty(&gather->freelist), 0); =20 @@ -4620,7 +4641,7 @@ int intel_iommu_enable_pasid(struct intel_iommu *iomm= u, struct device *dev) context[0].lo =3D ctx_lo; wmb(); iommu->flush.flush_context(iommu, - domain->iommu_did[iommu->seq_id], + domain_id_iommu(domain, iommu), PCI_DEVID(info->bus, info->devfn), DMA_CCMD_MASK_NOBIT, DMA_CCMD_DEVICE_INVL); @@ -4757,13 +4778,11 @@ static void intel_iommu_iotlb_sync_map(struct iommu= _domain *domain, struct dmar_domain *dmar_domain =3D to_dmar_domain(domain); unsigned long pages =3D aligned_nrpages(iova, size); unsigned long pfn =3D iova >> VTD_PAGE_SHIFT; - struct intel_iommu *iommu; - int iommu_id; + struct iommu_domain_info *info; + unsigned long i; =20 - for_each_domain_iommu(iommu_id, dmar_domain) { - iommu =3D g_iommus[iommu_id]; - __mapping_notify_one(iommu, dmar_domain, pfn, pages); - } + xa_for_each(&dmar_domain->iommu_array, i, info) + __mapping_notify_one(info->iommu, dmar_domain, pfn, pages); } =20 const struct iommu_ops intel_iommu_ops =3D { diff --git a/drivers/iommu/intel/pasid.c b/drivers/iommu/intel/pasid.c index 7792a1b2ebc4..c5e7e8b020a5 100644 --- a/drivers/iommu/intel/pasid.c +++ b/drivers/iommu/intel/pasid.c @@ -626,7 +626,7 @@ int intel_pasid_setup_second_level(struct intel_iommu *= iommu, } =20 pgd_val =3D virt_to_phys(pgd); - did =3D domain->iommu_did[iommu->seq_id]; + did =3D domain_id_iommu(domain, iommu); =20 spin_lock(&iommu->lock); pte =3D intel_pasid_get_entry(dev, pasid); diff --git a/drivers/iommu/intel/svm.c b/drivers/iommu/intel/svm.c index 64072e628bbd..8bcfb93dda56 100644 --- a/drivers/iommu/intel/svm.c +++ b/drivers/iommu/intel/svm.c @@ -541,7 +541,7 @@ static void intel_svm_drain_prq(struct device *dev, u32= pasid) domain =3D info->domain; pdev =3D to_pci_dev(dev); sid =3D PCI_DEVID(info->bus, info->devfn); - did =3D domain->iommu_did[iommu->seq_id]; + did =3D domain_id_iommu(domain, iommu); qdep =3D pci_ats_queue_depth(pdev); =20 /* --=20 2.25.1 From nobody Sat Apr 25 11:48:02 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 91BEBCCA47B for ; Tue, 12 Jul 2022 00:16:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231903AbiGLAQ1 (ORCPT ); Mon, 11 Jul 2022 20:16:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49412 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231895AbiGLAPw (ORCPT ); Mon, 11 Jul 2022 20:15:52 -0400 Received: from mga03.intel.com (mga03.intel.com [134.134.136.65]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 184FB8BA99 for ; Mon, 11 Jul 2022 17:14:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1657584896; x=1689120896; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=qKKsYPnFKnFFJPzOZhVWU6Nqf98mNpvKExXx01NfN9M=; b=dzJxJV077CaU1ysDrYo1ZJ69sjV12GqISlqo3Jee/A2NfcA70MzTsxrw PhQ0tMJgdkD73KbEEMRfAl6Krx1PxLyaWn3sxeHM9/T008+H6Xb9Uotff eHoPyzb0Dn418fl6M7oltZLxD8TeOnSuzp5VXrn6uktAccPC/IkQ1ke/G J8L9WaH2MAtex5DRVJt1AWtULhZvmH87zWOz+NFvWnFz2XZ2xQMkW9l+Q hwdMnuWwbyOXBJbITUrPdzydffqPR2VcScCmhirnZVi76qG0YlJlZ6afd 3f+EzIm16u+1SE9UtOAHD0hGxwdK8LfDrRlZyCY6D/FE6pStDFV5dV+xr w==; X-IronPort-AV: E=McAfee;i="6400,9594,10405"; a="285929340" X-IronPort-AV: E=Sophos;i="5.92,264,1650956400"; d="scan'208";a="285929340" Received: from orsmga007.jf.intel.com ([10.7.209.58]) by orsmga103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 Jul 2022 17:14:27 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.92,264,1650956400"; d="scan'208";a="592445865" Received: from allen-box.sh.intel.com ([10.239.159.48]) by orsmga007.jf.intel.com with ESMTP; 11 Jul 2022 17:14:14 -0700 From: Lu Baolu To: Joerg Roedel Cc: iommu@lists.linux.dev, linux-kernel@vger.kernel.org Subject: [PATCH 23/25] iommu/vt-d: Remove unnecessary check in intel_iommu_add() Date: Tue, 12 Jul 2022 08:09:06 +0800 Message-Id: <20220712000908.3431936-24-baolu.lu@linux.intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220712000908.3431936-1-baolu.lu@linux.intel.com> References: <20220712000908.3431936-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 hot-add process starts from dmar_device_hotplug(). It uses the global dmar_global_lock to synchronize all the hot-add and hot-remove paths. In the hot-add path, the new IOMMU data structures are allocated firstly by dmar_parse_one_drhd() and then initialized by dmar_hp_add_drhd(). All the IOMMU units are allocated and initialized in the same synchronized path. There is no case where any IOMMU unit is created and then initialized for multiple times. This removes the unnecessary check in intel_iommu_add() which is the last reference place of the global IOMMU array. Signed-off-by: Lu Baolu Reviewed-by: Kevin Tian Reviewed-by: Steve Wahl Link: https://lore.kernel.org/r/20220702015610.2849494-5-baolu.lu@linux.int= el.com --- drivers/iommu/intel/iommu.c | 3 --- 1 file changed, 3 deletions(-) diff --git a/drivers/iommu/intel/iommu.c b/drivers/iommu/intel/iommu.c index 36b3649a83e8..2f64ff6e6e75 100644 --- a/drivers/iommu/intel/iommu.c +++ b/drivers/iommu/intel/iommu.c @@ -3460,9 +3460,6 @@ static int intel_iommu_add(struct dmar_drhd_unit *dma= ru) int sp, ret; struct intel_iommu *iommu =3D dmaru->iommu; =20 - if (g_iommus[iommu->seq_id]) - return 0; - ret =3D intel_cap_audit(CAP_AUDIT_HOTPLUG_DMAR, iommu); if (ret) goto out; --=20 2.25.1 From nobody Sat Apr 25 11:48:02 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 1F32DC43334 for ; Tue, 12 Jul 2022 00:16:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231868AbiGLAQ0 (ORCPT ); Mon, 11 Jul 2022 20:16:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50328 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231806AbiGLAPt (ORCPT ); Mon, 11 Jul 2022 20:15:49 -0400 Received: from mga03.intel.com (mga03.intel.com [134.134.136.65]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5F0252AC59 for ; Mon, 11 Jul 2022 17:14:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1657584893; x=1689120893; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=n8OUlNT9qDkBFdgYmQfEEoxusEpBSjX1aHY1EnVMf08=; b=Dh/3m8B9c6CvBhqVZeweqyLpkBCn77S1vmcWI7TUzPs3DYI3kno2973s zko/Z5EPAxXcU7530ldV2EtjsVpKUEUnOruQjfQlyUXJZaHXE6IyopXcH nQ/mNQeKqAgEQ3mofC3WOFa1HkhTv+VlSQq/TlmmeJVDhqGbI35+hmOjn yH2bSASC26eDswWilCT+MKZZt/SAijyxghf5FcP+avGW+Kau085xeKTvk iXBWdpXD6pRo3X5eX4+5pS8VYtIaH626ko8etZ01/bJfv6LwkpUac4jF5 Chhl5DV5hIpfBjFqHA63hJxia1G9MWH6cWJTHb6eqMHsIT5ZtlsNfsOA5 Q==; X-IronPort-AV: E=McAfee;i="6400,9594,10405"; a="285929339" X-IronPort-AV: E=Sophos;i="5.92,264,1650956400"; d="scan'208";a="285929339" Received: from orsmga007.jf.intel.com ([10.7.209.58]) by orsmga103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 Jul 2022 17:14:27 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.92,264,1650956400"; d="scan'208";a="592445867" Received: from allen-box.sh.intel.com ([10.239.159.48]) by orsmga007.jf.intel.com with ESMTP; 11 Jul 2022 17:14:15 -0700 From: Lu Baolu To: Joerg Roedel Cc: iommu@lists.linux.dev, linux-kernel@vger.kernel.org Subject: [PATCH 24/25] iommu/vt-d: Remove global g_iommus array Date: Tue, 12 Jul 2022 08:09:07 +0800 Message-Id: <20220712000908.3431936-25-baolu.lu@linux.intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220712000908.3431936-1-baolu.lu@linux.intel.com> References: <20220712000908.3431936-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 g_iommus and g_num_of_iommus is not used anywhere. Remove them to avoid dead code. Signed-off-by: Lu Baolu Reviewed-by: Kevin Tian Reviewed-by: Steve Wahl Link: https://lore.kernel.org/r/20220702015610.2849494-6-baolu.lu@linux.int= el.com --- drivers/iommu/intel/iommu.c | 44 ------------------------------------- 1 file changed, 44 deletions(-) diff --git a/drivers/iommu/intel/iommu.c b/drivers/iommu/intel/iommu.c index 2f64ff6e6e75..3ba0d7e76efd 100644 --- a/drivers/iommu/intel/iommu.c +++ b/drivers/iommu/intel/iommu.c @@ -126,9 +126,6 @@ static inline unsigned long virt_to_dma_pfn(void *p) return page_to_dma_pfn(virt_to_page(p)); } =20 -/* global iommu list, set NULL for ignored DMAR units */ -static struct intel_iommu **g_iommus; - static void __init check_tylersburg_isoch(void); static int rwbf_quirk; =20 @@ -287,9 +284,6 @@ static LIST_HEAD(dmar_satc_units); #define for_each_rmrr_units(rmrr) \ list_for_each_entry(rmrr, &dmar_rmrr_units, list) =20 -/* bitmap for indexing intel_iommus */ -static int g_num_of_iommus; - static void dmar_remove_one_dev_info(struct device *dev); =20 int dmar_disabled =3D !IS_ENABLED(CONFIG_INTEL_IOMMU_DEFAULT_ON); @@ -1694,8 +1688,6 @@ static void free_dmar_iommu(struct intel_iommu *iommu) iommu->domain_ids =3D NULL; } =20 - g_iommus[iommu->seq_id] =3D NULL; - /* free context mapping */ free_context_table(iommu); =20 @@ -2898,36 +2890,6 @@ static int __init init_dmars(void) struct intel_iommu *iommu; int ret; =20 - /* - * for each drhd - * allocate root - * initialize and program root entry to not present - * endfor - */ - for_each_drhd_unit(drhd) { - /* - * lock not needed as this is only incremented in the single - * threaded kernel __init code path all other access are read - * only - */ - if (g_num_of_iommus < DMAR_UNITS_SUPPORTED) { - g_num_of_iommus++; - continue; - } - pr_err_once("Exceeded %d IOMMUs\n", DMAR_UNITS_SUPPORTED); - } - - /* Preallocate enough resources for IOMMU hot-addition */ - if (g_num_of_iommus < DMAR_UNITS_SUPPORTED) - g_num_of_iommus =3D DMAR_UNITS_SUPPORTED; - - g_iommus =3D kcalloc(g_num_of_iommus, sizeof(struct intel_iommu *), - GFP_KERNEL); - if (!g_iommus) { - ret =3D -ENOMEM; - goto error; - } - ret =3D intel_cap_audit(CAP_AUDIT_STATIC_DMAR, NULL); if (ret) goto free_iommu; @@ -2950,8 +2912,6 @@ static int __init init_dmars(void) intel_pasid_max_id); } =20 - g_iommus[iommu->seq_id] =3D iommu; - intel_iommu_init_qi(iommu); =20 ret =3D iommu_init_domains(iommu); @@ -3077,9 +3037,6 @@ static int __init init_dmars(void) free_dmar_iommu(iommu); } =20 - kfree(g_iommus); - -error: return ret; } =20 @@ -3483,7 +3440,6 @@ static int intel_iommu_add(struct dmar_drhd_unit *dma= ru) if (iommu->gcmd & DMA_GCMD_TE) iommu_disable_translation(iommu); =20 - g_iommus[iommu->seq_id] =3D iommu; ret =3D iommu_init_domains(iommu); if (ret =3D=3D 0) ret =3D iommu_alloc_root_entry(iommu); --=20 2.25.1 From nobody Sat Apr 25 11:48:02 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 2C540C43334 for ; Tue, 12 Jul 2022 00:16:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229578AbiGLAQo (ORCPT ); Mon, 11 Jul 2022 20:16:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50400 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231718AbiGLAQH (ORCPT ); Mon, 11 Jul 2022 20:16:07 -0400 Received: from mga03.intel.com (mga03.intel.com [134.134.136.65]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6E29227173 for ; Mon, 11 Jul 2022 17:14:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1657584897; x=1689120897; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=MroiDNvha1/tb3MUIk3o7dPI2u8+aAn6KRPZNnMo4Z4=; b=eAcxnTqcj415+c3cyEORjvBc8GorFbDFaLsvirYSFkHFe5Jfs9VzDtT1 CXRkxCD8empaYbHSTJA26a3GT71SOf9zOInBrVJ1N8a4PRaMGtf110wLf 82u6G2/FWi/kehBx/blPmdaLyEHH0q4x6cqzJN4NqZSsukGRCF6NzASt1 oIiGoJXs9K1AToPkz5+/yZ2KoC8F72Rcx1dFxopKmi7GaPun20gjnPNZ7 PMYaAclixJHb2WfYqBftYwl0n61RNeb+HAc5ZFk24h71vdW87iUAGpO83 TeFEVVuRKyWb9nFQDx/ZNPMUT/DE3knjDPPyEREHSV1yWuE5Cn10rOo3B g==; X-IronPort-AV: E=McAfee;i="6400,9594,10405"; a="285929342" X-IronPort-AV: E=Sophos;i="5.92,264,1650956400"; d="scan'208";a="285929342" Received: from orsmga007.jf.intel.com ([10.7.209.58]) by orsmga103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 Jul 2022 17:14:27 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.92,264,1650956400"; d="scan'208";a="592445868" Received: from allen-box.sh.intel.com ([10.239.159.48]) by orsmga007.jf.intel.com with ESMTP; 11 Jul 2022 17:14:16 -0700 From: Lu Baolu To: Joerg Roedel Cc: iommu@lists.linux.dev, linux-kernel@vger.kernel.org Subject: [PATCH 25/25] iommu/vt-d: Make DMAR_UNITS_SUPPORTED default 1024 Date: Tue, 12 Jul 2022 08:09:08 +0800 Message-Id: <20220712000908.3431936-26-baolu.lu@linux.intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220712000908.3431936-1-baolu.lu@linux.intel.com> References: <20220712000908.3431936-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" If the available hardware exceeds DMAR_UNITS_SUPPORTED (previously set to MAX_IO_APICS, or 128), it causes these messages: "DMAR: Failed to allocate seq_id", "DMAR: Parse DMAR table failure.", and "x2apic: IRQ remapping doesn't support X2APIC mode x2apic disabled"; and the system fails to boot properly. To support up to 64 sockets with 10 DMAR units each (640), make the value of DMAR_UNITS_SUPPORTED default 1024. Signed-off-by: Steve Wahl Signed-off-by: Lu Baolu Reviewed-by: Kevin Tian Reviewed-by: Steve Wahl Link: https://lore.kernel.org/linux-iommu/20220615183650.32075-1-steve.wahl= @hpe.com/ Link: https://lore.kernel.org/r/20220702015610.2849494-7-baolu.lu@linux.int= el.com --- include/linux/dmar.h | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/include/linux/dmar.h b/include/linux/dmar.h index cbd714a198a0..d81a51978d01 100644 --- a/include/linux/dmar.h +++ b/include/linux/dmar.h @@ -18,11 +18,7 @@ =20 struct acpi_dmar_header; =20 -#ifdef CONFIG_X86 -# define DMAR_UNITS_SUPPORTED MAX_IO_APICS -#else -# define DMAR_UNITS_SUPPORTED 64 -#endif +#define DMAR_UNITS_SUPPORTED 1024 =20 /* DMAR Flags */ #define DMAR_INTR_REMAP 0x1 --=20 2.25.1