Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp1386321pxu; Sat, 5 Dec 2020 14:24:51 -0800 (PST) X-Google-Smtp-Source: ABdhPJxh0X9fkEmYWyQXEW+MWy/LjpX5UuVKvgLvcwjqvzZzfueFa7yyU98UL+05QTM003Xq6FEX X-Received: by 2002:a17:906:4348:: with SMTP id z8mr13456538ejm.119.1607207090810; Sat, 05 Dec 2020 14:24:50 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1607207090; cv=none; d=google.com; s=arc-20160816; b=lCZON3bv3rLelLNhAfx8h7VZhN/yoPMkIat+iF3W6Ws1PdTY82E5Ymueljziz4C/BS jQhpJYvnY33aXG52AMvOhgrxOVe6QtuPQOhccuBrgsyB0/xOu4UO4LiEVd5bZ39EOFi4 EM9k21ZjrHkdql+nYrZsXCl8k/E+3o1E0OXCz4e1/qqbh00ElppPC603qPw5j3shCaNx bUx0XF/o67Gx052wTtTC94BLv+PL95Bq8hwNljuzaudIWfTRvbzKxrn+TENNn0zmwxYX qf9JAr9FqjieQjoP8Nl6I7ZodgWUEdwpGqeECzL+O8uqLGF9/LYM5DH/kiQzOYKLsE4x USag== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:references:in-reply-to:message-id:date:subject :cc:to:from:ironport-sdr:ironport-sdr; bh=uBXQD9ETqntDFWXkW5UBTGaJs7bpdkx4yPo2N0NsGfQ=; b=GY5Wtd254N33/x5EQZW/JKuM32zYOSqXmoMKs4E+ZQVaD94HRfc1zZTvPqYZAHHkEn kfu1TkXzVrZ7WsuRhNAhF6J0Q7HxNMjopXPzi31m9KSI7M8GFP4eSRjq/Yo3uzspTkWm Mq5eDKWDsk63Bd1VpPcFqXE3IN7qX8WrDrFEd5M/s5VVZhcq+SEAFFNciylhpsQDswwH SpagtCSMB5472YYitrOm8O/EoQoO3RK4EIMMAslWm86l97Hq2uwkkp0WO+oIPl0CZ9w0 MM0eyJUtSu6qgM2j9VclkBGyr+yS3YN080uwSPXlcHnDlfGldWyxd8wpbLcdtWiCU5vv haCw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id bz13si3938502ejc.437.2020.12.05.14.24.27; Sat, 05 Dec 2020 14:24:50 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726408AbgLEWTl (ORCPT + 99 others); Sat, 5 Dec 2020 17:19:41 -0500 Received: from mga12.intel.com ([192.55.52.136]:56475 "EHLO mga12.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726016AbgLEWTl (ORCPT ); Sat, 5 Dec 2020 17:19:41 -0500 IronPort-SDR: enJM8yu1pECeHxRt0R5jZ/n1mdZ8nCA+fpDBFeecNBzJWKY2JJXCUBB4swW6GgXxFsgnfBomto syl60IxyVxCg== X-IronPort-AV: E=McAfee;i="6000,8403,9826"; a="152791256" X-IronPort-AV: E=Sophos;i="5.78,395,1599548400"; d="scan'208";a="152791256" Received: from orsmga008.jf.intel.com ([10.7.209.65]) by fmsmga106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 05 Dec 2020 14:18:29 -0800 IronPort-SDR: N3BNoCgKHo17TBTMjXi+SWuMu7YJk2pHvQaKVpVi38JF4BL/zzPj41vmFRAI/O4deJxFT7jF/z SO8nxPhpqYyw== X-IronPort-AV: E=Sophos;i="5.78,395,1599548400"; d="scan'208";a="362584196" Received: from km-skylake-client-platform.sc.intel.com ([10.3.52.146]) by orsmga008-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 05 Dec 2020 14:18:29 -0800 From: Kyung Min Park To: linux-kernel@vger.kernel.org, iommu@lists.linux-foundation.org Cc: dwmw2@infradead.org, baolu.lu@linux.intel.com, joro@8bytes.org, will@kernel.org, ravi.v.shankar@intel.com, kevin.tian@intel.com, ashok.raj@intel.com, ricardo.neri@intel.com, sohil.mehta@intel.com, Kyung Min Park Subject: [PATCH v2 2/3] iommu/vt-d: Move capability check code to cap_audit files Date: Sat, 5 Dec 2020 13:57:42 -0800 Message-Id: <20201205215743.27803-3-kyung.min.park@intel.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20201205215743.27803-1-kyung.min.park@intel.com> References: <20201205215743.27803-1-kyung.min.park@intel.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Move IOMMU capability check and sanity check code to cap_audit files. Also implement some helper functions for sanity checks. Signed-off-by: Kyung Min Park --- drivers/iommu/intel/cap_audit.c | 20 +++++++++ drivers/iommu/intel/cap_audit.h | 20 +++++++++ drivers/iommu/intel/iommu.c | 76 +-------------------------------- 3 files changed, 42 insertions(+), 74 deletions(-) diff --git a/drivers/iommu/intel/cap_audit.c b/drivers/iommu/intel/cap_audit.c index 6b7e47e762ac..0bc77a9bdeed 100644 --- a/drivers/iommu/intel/cap_audit.c +++ b/drivers/iommu/intel/cap_audit.c @@ -186,3 +186,23 @@ int intel_cap_audit(enum cap_audit_type type, struct intel_iommu *iommu) return -EFAULT; } + +bool intel_cap_smts_sanity(void) +{ + return ecap_smts(intel_iommu_ecap_sanity); +} + +bool intel_cap_pasid_sanity(void) +{ + return ecap_pasid(intel_iommu_ecap_sanity); +} + +bool intel_cap_nest_sanity(void) +{ + return ecap_nest(intel_iommu_ecap_sanity); +} + +bool intel_cap_flts_sanity(void) +{ + return ecap_flts(intel_iommu_ecap_sanity); +} diff --git a/drivers/iommu/intel/cap_audit.h b/drivers/iommu/intel/cap_audit.h index 866236581dd3..1ce1dc314950 100644 --- a/drivers/iommu/intel/cap_audit.h +++ b/drivers/iommu/intel/cap_audit.h @@ -103,4 +103,24 @@ enum cap_audit_type { CAP_AUDIT_HOTPLUG_IRQR, }; +bool intel_cap_smts_sanity(void); +bool intel_cap_pasid_sanity(void); +bool intel_cap_nest_sanity(void); +bool intel_cap_flts_sanity(void); + +static inline bool scalable_mode_support(void) +{ + return (intel_iommu_sm && intel_cap_smts_sanity()); +} + +static inline bool pasid_mode_support(void) +{ + return scalable_mode_support() && intel_cap_pasid_sanity(); +} + +static inline bool nested_mode_support(void) +{ + return scalable_mode_support() && intel_cap_nest_sanity(); +} + int intel_cap_audit(enum cap_audit_type type, struct intel_iommu *iommu); diff --git a/drivers/iommu/intel/iommu.c b/drivers/iommu/intel/iommu.c index dd8f41a5e4fa..75add2fd300a 100644 --- a/drivers/iommu/intel/iommu.c +++ b/drivers/iommu/intel/iommu.c @@ -1846,25 +1846,7 @@ static void free_dmar_iommu(struct intel_iommu *iommu) */ static bool first_level_by_default(void) { - struct dmar_drhd_unit *drhd; - struct intel_iommu *iommu; - static int first_level_support = -1; - - if (likely(first_level_support != -1)) - return first_level_support; - - first_level_support = 1; - - rcu_read_lock(); - for_each_active_iommu(iommu, drhd) { - if (!sm_supported(iommu) || !ecap_flts(iommu->ecap)) { - first_level_support = 0; - break; - } - } - rcu_read_unlock(); - - return first_level_support; + return scalable_mode_support() && intel_cap_flts_sanity(); } static struct dmar_domain *alloc_domain(int flags) @@ -5666,60 +5648,6 @@ static phys_addr_t intel_iommu_iova_to_phys(struct iommu_domain *domain, return phys; } -static inline bool scalable_mode_support(void) -{ - struct dmar_drhd_unit *drhd; - struct intel_iommu *iommu; - bool ret = true; - - rcu_read_lock(); - for_each_active_iommu(iommu, drhd) { - if (!sm_supported(iommu)) { - ret = false; - break; - } - } - rcu_read_unlock(); - - return ret; -} - -static inline bool iommu_pasid_support(void) -{ - struct dmar_drhd_unit *drhd; - struct intel_iommu *iommu; - bool ret = true; - - rcu_read_lock(); - for_each_active_iommu(iommu, drhd) { - if (!pasid_supported(iommu)) { - ret = false; - break; - } - } - rcu_read_unlock(); - - return ret; -} - -static inline bool nested_mode_support(void) -{ - struct dmar_drhd_unit *drhd; - struct intel_iommu *iommu; - bool ret = true; - - rcu_read_lock(); - for_each_active_iommu(iommu, drhd) { - if (!sm_supported(iommu) || !ecap_nest(iommu->ecap)) { - ret = false; - break; - } - } - rcu_read_unlock(); - - return ret; -} - static bool intel_iommu_capable(enum iommu_cap cap) { if (cap == IOMMU_CAP_CACHE_COHERENCY) @@ -5973,7 +5901,7 @@ intel_iommu_dev_has_feat(struct device *dev, enum iommu_dev_features feat) int ret; if (!dev_is_pci(dev) || dmar_disabled || - !scalable_mode_support() || !iommu_pasid_support()) + !scalable_mode_support() || !pasid_mode_support()) return false; ret = pci_pasid_features(to_pci_dev(dev)); -- 2.17.1