Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp499109pxu; Tue, 5 Jan 2021 17:56:22 -0800 (PST) X-Google-Smtp-Source: ABdhPJzZKfit+q8QtGHEn1p6LWAhYPAADJsbcpPzTjUj/kYfRRRO5YqfNFy6GByBg2729dsX7okz X-Received: by 2002:a50:ac86:: with SMTP id x6mr2362104edc.197.1609898181843; Tue, 05 Jan 2021 17:56:21 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1609898181; cv=none; d=google.com; s=arc-20160816; b=iHwHaIm7bzeVLDkd31+ObMtQtgYf0rBDBlPM6j8fc/HFjfIDQdKKX79qS71p96cCPN k21ML6qcWp12hdDW1fkky7sli2TIaGqKrV+7iZZd2UWS8Vlxk1T72BkjtRUB8h+nsf4B TUyiQ2q23sVHvHBP/9yEbF8KtFX2ZJyUcXUKBtdJsi0IdFPSFV2KYOOYpGedo6d18Q7W Zxqn41SoaU8XUxeIguDim4O0s9LZILGoqJRYpKV3zpQ8waXbcD4K/TdJbHc5x3VKp+1d NFuOObYxDT+MxoQf/aDPjHnaXan3vahOB6BJdRd6p/DA4MG0dKfUXNXuv6rui1JLXmaA 343A== 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=RCwZ93M4Su3QAZABrLCrnCL9L95zmn75yTI+MEvlgD4=; b=PJSesMkWTRDNJIZIaKFsHndlpVJkGdNKOznRkOyupSOC84FIZUvMJHQd7mzRa2/7gJ +aTqFHQyx4s7xSdpK6ZBmbK5+ZC5owhXYzZqIYRqkg0w9N1A4d3U/EfKilBH5dfOGFEp UVYXmT1a7Ssmb6shC0/iUY2WXCcwa9kGBdFvqfWojZDGUcNGbBx6A7CNCiKCNOpC3LEh BZc3mJZIqH6d+5xNHh6EFhYBJZPammQ1IPP4ewQ6oHClhGGPj+fE87Hx3qYc1AU1xlIQ rKYvlhkR0AICVj1zv1Iy1HnRzaTnAGpH+VQmK2ykDOUXMC/Fd3ZGHWq9xUZ0XxdgQD9u o6AQ== 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 u32si400280edc.94.2021.01.05.17.55.58; Tue, 05 Jan 2021 17:56:21 -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 S1726278AbhAFBxN (ORCPT + 99 others); Tue, 5 Jan 2021 20:53:13 -0500 Received: from mga12.intel.com ([192.55.52.136]:48791 "EHLO mga12.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725778AbhAFBxM (ORCPT ); Tue, 5 Jan 2021 20:53:12 -0500 IronPort-SDR: NqNqMocYRQmSTUh0fOaa6H8JObvy4fsFQ7/J2rlPsF61aPEc627SpqYo3P9kiFa73tin/I38bI /Je9ou57vFFA== X-IronPort-AV: E=McAfee;i="6000,8403,9855"; a="156402500" X-IronPort-AV: E=Sophos;i="5.78,478,1599548400"; d="scan'208";a="156402500" Received: from orsmga002.jf.intel.com ([10.7.209.21]) by fmsmga106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 05 Jan 2021 17:51:50 -0800 IronPort-SDR: 2lawWk8DpPmKtAWGguAXMAC3Doh3n2EuNPhkgE/S7w1j6ABgFeqoHj8QqCgP7fIQ7/idfo5QPs PO+vC4bsoyFA== X-IronPort-AV: E=Sophos;i="5.78,478,1599548400"; d="scan'208";a="361387914" Received: from km-skylake-client-platform.sc.intel.com ([10.3.52.146]) by orsmga002-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 05 Jan 2021 17:51:50 -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, 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 v4 3/3] iommu/vt-d: Disable SVM in the platform when IOMMUs have inconsistencies Date: Tue, 5 Jan 2021 17:30:35 -0800 Message-Id: <20210106013035.6476-4-kyung.min.park@intel.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20210106013035.6476-1-kyung.min.park@intel.com> References: <20210106013035.6476-1-kyung.min.park@intel.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Some IOMMU Capabilities must be consistent for Shared Virtual Memory (SVM). Audit IOMMU Capability/Extended Capabilities and check if IOMMUs have the consistent value for features as below. When the features are not matched among IOMMUs, disable SVMs in the platform during DMAR initialization. Audit IOMMUs again when a device is hot plugged. Disable Shared Virtual Memory when below features are mistmatched: - First Level Translation Support (FLTS) - Process Address Space ID Support (PASID) - Extended Accessed Flag Support (EAFS) - Supervisor Support (SRS) - Execute Request Support (ERS) - Page Request Support (PRS) Signed-off-by: Kyung Min Park --- drivers/iommu/intel/cap_audit.c | 11 +++++++++++ drivers/iommu/intel/cap_audit.h | 6 ++++++ drivers/iommu/intel/svm.c | 3 ++- 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/drivers/iommu/intel/cap_audit.c b/drivers/iommu/intel/cap_audit.c index cf5326eb1d72..e6f8616edc3d 100644 --- a/drivers/iommu/intel/cap_audit.c +++ b/drivers/iommu/intel/cap_audit.c @@ -130,6 +130,12 @@ static int cap_audit_hotplug(struct intel_iommu *iommu, enum cap_audit_type type MINIMAL_FEATURE_HOTPLUG(iommu, ecap, max_handle_mask, ECAP_MHMV_MASK, mismatch); MINIMAL_FEATURE_HOTPLUG(iommu, ecap, iotlb_offset, ECAP_IRO_MASK, mismatch); + if (IS_ENABLED(CONFIG_INTEL_IOMMU_SVM) && + intel_cap_svm_santiy() && !ecap_svm_sanity(iommu->ecap)) { + pr_warn("Abort Hot Plug IOMMU: SVM inconsistent\n"); + mismatch = true; + } + out: if (mismatch) { intel_iommu_cap_sanity = old_cap; @@ -206,3 +212,8 @@ bool intel_cap_flts_sanity(void) { return ecap_flts(intel_iommu_ecap_sanity); } + +bool intel_cap_svm_santiy(void) +{ + return ecap_svm_sanity(intel_iommu_ecap_sanity); +} diff --git a/drivers/iommu/intel/cap_audit.h b/drivers/iommu/intel/cap_audit.h index 1ce1dc314950..beb2589e97e0 100644 --- a/drivers/iommu/intel/cap_audit.h +++ b/drivers/iommu/intel/cap_audit.h @@ -60,6 +60,11 @@ #define ECAP_QI_MASK BIT_ULL(1) #define ECAP_C_MASK BIT_ULL(0) +#define MINIMAL_SVM_ECAP (ECAP_FLTS_MASK | ECAP_PASID_MASK | ECAP_EAFS_MASK | \ + ECAP_SRS_MASK | ECAP_ERS_MASK | ECAP_PRS_MASK) + +#define ecap_svm_sanity(e) (!(((e) & MINIMAL_SVM_ECAP) ^ MINIMAL_SVM_ECAP)) + #define DO_CHECK_FEATURE_MISMATCH(a, b, cap, feature, MASK) \ do { \ if (cap##_##feature(a) != cap##_##feature(b)) { \ @@ -107,6 +112,7 @@ bool intel_cap_smts_sanity(void); bool intel_cap_pasid_sanity(void); bool intel_cap_nest_sanity(void); bool intel_cap_flts_sanity(void); +bool intel_cap_svm_santiy(void); static inline bool scalable_mode_support(void) { diff --git a/drivers/iommu/intel/svm.c b/drivers/iommu/intel/svm.c index 3242ebd0bca3..7761e40a2d5a 100644 --- a/drivers/iommu/intel/svm.c +++ b/drivers/iommu/intel/svm.c @@ -22,6 +22,7 @@ #include #include "pasid.h" +#include "cap_audit.h" static irqreturn_t prq_event_thread(int irq, void *d); static void intel_svm_drain_prq(struct device *dev, u32 pasid); @@ -98,7 +99,7 @@ static inline bool intel_svm_capable(struct intel_iommu *iommu) void intel_svm_check(struct intel_iommu *iommu) { - if (!pasid_supported(iommu)) + if (!intel_cap_svm_santiy()) return; if (cpu_feature_enabled(X86_FEATURE_GBPAGES) && -- 2.17.1