Received: by 2002:a25:7ec1:0:0:0:0:0 with SMTP id z184csp828558ybc; Tue, 19 Nov 2019 09:55:05 -0800 (PST) X-Google-Smtp-Source: APXvYqweCSRfYpSbO1jgeri/qcux/k+cqRg/W1Kn5E03s1dytHrU9Jq2308JFkJt6MNTFjwcw27z X-Received: by 2002:a17:906:5397:: with SMTP id g23mr35217845ejo.93.1574186105238; Tue, 19 Nov 2019 09:55:05 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1574186105; cv=none; d=google.com; s=arc-20160816; b=zskcDEiBvn4n8PIXQQ8758FSHmK11r7pLmx3IYjmdvKWPE/BKaWbIIsG5/LYg9rz/1 EnZdJwZPljTg1LoTeJDlmv9ZbFo0+vlHiUZrRpmkwN7xDzoDFM38oDemH0JBYZMrSZse /gQ33/Vh700cw61wfJ+jp0Ct6JVjmbaiw0PYVLnfCDo2OE1R1qTAba+wyiXAxrohoJ6g QsLcLi+XQx/pNwwV5y/z5Mr8I/VsXF4zqa+c1GlYqJrzxoM8DHsr630OLclv62DELL7P zmPorZflM0Wevo/kK309Yyw8UhHQHkkRNxhZ9BvMfOxStt8aacCM/2/j9mDN2mlWf/CD os7A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from; bh=pxdssK44dbCfXGiFCNbBF5WaPS1IyU8Z7ZBcNKU7E7w=; b=YjxATflHMOhF+ulI2gtgRsZ9CtKT7l07+cvpfcUK5SgXSSpXZku1qvFtNACm7TpXhc 2LCCgwsmn/aKPSlSfz5AlOynCg+7LHiGVIXyLCKre/+sd3BPTIgJ+SRwTZfYAgg3RyQ6 39p0ih/KvNrJF8xh2jCXLTUC4CDtwzWHeiDUMo28CEtuyzH+icq4cZ4GnTLLCfLq17LA 8ZVFeDkVca9qoCGt2tekktOsTBSzBqBhXnM4ZTTaFqXGz+6D+/YXTY63qH7IsTwWAc13 TSuie8bEDSp3BUwISIdyPmmS+PVdeVzegMItO4fXLIf9tHzTcmDV3W8vdSQnxMOSJu8u FixA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 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. [209.132.180.67]) by mx.google.com with ESMTP id z33si15318569edz.114.2019.11.19.09.54.41; Tue, 19 Nov 2019 09:55:05 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 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 S1727503AbfKSRwY (ORCPT + 99 others); Tue, 19 Nov 2019 12:52:24 -0500 Received: from mga07.intel.com ([134.134.136.100]:14025 "EHLO mga07.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726833AbfKSRwA (ORCPT ); Tue, 19 Nov 2019 12:52:00 -0500 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga006.jf.intel.com ([10.7.209.51]) by orsmga105.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 19 Nov 2019 09:52:00 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.69,218,1571727600"; d="scan'208";a="209488272" Received: from jacob-builder.jf.intel.com ([10.7.199.155]) by orsmga006.jf.intel.com with ESMTP; 19 Nov 2019 09:51:58 -0800 From: Jacob Pan To: iommu@lists.linux-foundation.org, LKML , Joerg Roedel , "Lu Baolu" , David Woodhouse Cc: "Tian, Kevin" , Raj Ashok , "Yi Liu" , Eric Auger , "Mehta, Sohil" , Jacob Pan Subject: [PATCH v3 2/8] iommu/vt-d: Match CPU and IOMMU paging mode Date: Tue, 19 Nov 2019 09:56:26 -0800 Message-Id: <1574186193-30457-3-git-send-email-jacob.jun.pan@linux.intel.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1574186193-30457-1-git-send-email-jacob.jun.pan@linux.intel.com> References: <1574186193-30457-1-git-send-email-jacob.jun.pan@linux.intel.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org When setting up first level page tables for sharing with CPU, we need to ensure IOMMU can support no less than the levels supported by the CPU. It is not adequate, as in the current code, to set up 5-level paging in PASID entry First Level Paging Mode(FLPM) solely based on CPU. Currently, intel_pasid_setup_first_level() is only used by native SVM code which already checks paging mode matches. However, future use of this helper function may not be limited to native SVM. https://lkml.org/lkml/2019/11/18/1037 Fixes: 437f35e1cd4c8 ("iommu/vt-d: Add first level page table interface") Signed-off-by: Jacob Pan Acked-by: Lu Baolu --- drivers/iommu/intel-pasid.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/drivers/iommu/intel-pasid.c b/drivers/iommu/intel-pasid.c index 040a445be300..e7cb0b8a7332 100644 --- a/drivers/iommu/intel-pasid.c +++ b/drivers/iommu/intel-pasid.c @@ -499,8 +499,16 @@ int intel_pasid_setup_first_level(struct intel_iommu *iommu, } #ifdef CONFIG_X86 - if (cpu_feature_enabled(X86_FEATURE_LA57)) - pasid_set_flpm(pte, 1); + /* Both CPU and IOMMU paging mode need to match */ + if (cpu_feature_enabled(X86_FEATURE_LA57)) { + if (cap_5lp_support(iommu->cap)) { + pasid_set_flpm(pte, 1); + } else { + pr_err("VT-d has no 5-level paging support for CPU\n"); + pasid_clear_entry(pte); + return -EINVAL; + } + } #endif /* CONFIG_X86 */ pasid_set_domain_id(pte, did); -- 2.7.4