Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp2692403pxb; Sat, 30 Jan 2021 10:50:01 -0800 (PST) X-Google-Smtp-Source: ABdhPJxBUCUyLisRQYeUO5LbJypV/w5hGDiHvEoThTVPk5+VJv0KLcDYGiQgTXkLKm9Y7nfcDfVZ X-Received: by 2002:aa7:c884:: with SMTP id p4mr11380347eds.212.1612032601330; Sat, 30 Jan 2021 10:50:01 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1612032601; cv=none; d=google.com; s=arc-20160816; b=gp0PB6yR3kJD3T/C7jbNfELaTf7szLag+agv1a0WfjJ4YNVAiV3D3oZWGExYb405oB RKL6YXx15YqV4hdIeELI1MyVrX3mlDJRiNiAC3G9jRxph/Q8BZVYi5bsIT6Ep11Skqim w1igSBxDrQomKkkhIucXLE0d9Vv5uOsR/VTz/wNm4Gp8ITQv5yB4dvqaFcralJeWJsN8 FDBsOQ2i3z5fXB1aN4cRRFH5GuMoRSJpYcKx78GevJoM2j9Tu6nuxPibfFsb/Ev9DqZh Q78x7AmCndWpieNOz8PWnMxTWyNqN7Vig10TVbWIrM8J+mifTMc++IMgQ2+8n4N93e3D mQ3w== 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=c5U7j7nKpjxsm8jkN8u1bHEdCuZzKg0VJD/grYJZIbk=; b=iUALWSUnW9BdW7GKoX4rvcuqAciGfNgl9ezN0tMaH0xvVwqvQ717G/mJQVvFlprzdx oIG6DWwygmQ9qCW0UWk33KjggPf9mn02oCOWW9Wwc9oUdDymVdihTk+478gTpFAynC9j oSxlVCafrwZ/fxvc/34/tgKigcrrQX4pTW0Ag/P31T5TOEGUcdtYrHm8hYzxqUjTuMPS PzYyo9p+q5A9rnvWXf1hMlXpTQPnOfb3Q5GRWuosxY1BR6OfvORmgV2b8uoPlBuvokP+ /box3/6iQcMqHRLNsyT9W8HFMpZH4ciNuVq6sTKql5/nDp6HAVcdAqDOInVMQdzUhve5 V+Rw== 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 dk5si7144638edb.586.2021.01.30.10.49.36; Sat, 30 Jan 2021 10:50:01 -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 S232016AbhA3Sqw (ORCPT + 99 others); Sat, 30 Jan 2021 13:46:52 -0500 Received: from mga05.intel.com ([192.55.52.43]:15035 "EHLO mga05.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232010AbhA3Sqo (ORCPT ); Sat, 30 Jan 2021 13:46:44 -0500 IronPort-SDR: 6QsSitdiXGyvpHrx0HcU5b+pESxSZwB0JjweToI9JijX7AbmfJvPC/GyLsRGMsZg1gwEEW5sr5 6s/6PsuruLIQ== X-IronPort-AV: E=McAfee;i="6000,8403,9880"; a="265377342" X-IronPort-AV: E=Sophos;i="5.79,388,1602572400"; d="scan'208";a="265377342" Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by fmsmga105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 30 Jan 2021 10:45:28 -0800 IronPort-SDR: fUKAcnFu3QJu7aNwZhqdigA6wXtN95rzIpk1wS+hFCbWqEZeIhvNGzP0Cp3vrCmnxVqF+a3/zC Z/NahULr5Bpg== X-IronPort-AV: E=Sophos;i="5.79,388,1602572400"; d="scan'208";a="580053464" Received: from km-skylake-client-platform.sc.intel.com ([172.25.103.115]) by fmsmga005-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 30 Jan 2021 10:45:28 -0800 From: Kyung Min Park To: linux-kernel@vger.kernel.org, iommu@lists.linux-foundation.org Cc: baolu.lu@linux.intel.com, dwmw2@infradead.org, joro@8bytes.org, will@kernel.org, ricardo.neri@intel.com, ravi.v.shankar@intel.com, kevin.tian@intel.com, ashok.raj@intel.com, sohil.mehta@intel.com, kyung.min.park@intel.com Subject: [PATCH v5 2/2] iommu/vt-d: Move capability check code to cap_audit files Date: Sat, 30 Jan 2021 10:44:52 -0800 Message-Id: <20210130184452.31711-3-kyung.min.park@intel.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20210130184452.31711-1-kyung.min.park@intel.com> References: <20210130184452.31711-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 049bc0c76a00..b12e421a2f1a 100644 --- a/drivers/iommu/intel/cap_audit.c +++ b/drivers/iommu/intel/cap_audit.c @@ -183,3 +183,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 a6a1530441b7..74cfccae0e81 100644 --- a/drivers/iommu/intel/cap_audit.h +++ b/drivers/iommu/intel/cap_audit.h @@ -107,4 +107,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 861b6b84074d..0ea2e1440a9b 100644 --- a/drivers/iommu/intel/iommu.c +++ b/drivers/iommu/intel/iommu.c @@ -1862,25 +1862,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) @@ -5049,60 +5031,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) @@ -5343,7 +5271,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