Received: by 10.213.65.68 with SMTP id h4csp637023imn; Wed, 28 Mar 2018 09:57:03 -0700 (PDT) X-Google-Smtp-Source: AIpwx4/I3slxinI0G8HDxQHUsk/yMYo7BHzKWfIRk+5XmpHEB7K7mk3mpRSZH8eb886luvcDOisz X-Received: by 2002:a17:902:2468:: with SMTP id m37-v6mr4474394plg.388.1522256223521; Wed, 28 Mar 2018 09:57:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1522256223; cv=none; d=google.com; s=arc-20160816; b=sMNanSpl431yek1aGw2H6qw7PjgNXP7Kl/hFHrXb+lUPeuZGNrJ/prF/BCnlxcBsjp M3R70ifqJwJPScvn4sBf7OwSJMLpi391PiouvgQevQFBwKwLeyth1MLfqLaGEHi+mx+Y CrPzuwX1mDw4H6er2H/1Q+HLn54K6kqHbEs2L7ExVJsteYxzPpCbZsQIle9sUgpdr0nz t5Vt7k6jCwzC4QE2zXinGYC/x6HtwTjwKQm+DWk+1sgKAiVUtidEaUngTwfMyKoIlouZ J6wocKnre9HDb3d1Y7hN3yR/Vyg8b3i63ZR9ZUAY9SO3VsMQ4k3jl/VwwjPTLknSqzPa +wfQ== 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:arc-authentication-results; bh=hCAKm4lYhwKs2csrmR7sD9WWQz1xiseKAkNeGtPq9xY=; b=xhKtuxYIH+TIfx6XFc1EBrDma0Hfy5+uSueOht3uvbT5K3iEFf9GGuf0T2GuzmktSM 9RPnJYvh1/H34JPkVnSiXaxJrhnJttMYGSNmWHxMR2tyGaejABS3aV2sNapMtIa0wFkr tUvSmRaItelDhsAa+rKnnphT7SU0aNxRMY2LRWdihw3Qm+JtxJrY2DA986v1djqFdeRE 9c+FHSMfjkXosMY5o5omP2IvS2Kn/mhuXq2x28oxSKeUp61px+u9Kds+jt04eBg4gzDB bNWmlvFHVbbnHUu2z37S5DyZjvWTzEEluPYz3zK9pJgy321V5Y/b87Qlm5oSTnNP8840 N8dw== 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id p2si2696033pgv.741.2018.03.28.09.56.48; Wed, 28 Mar 2018 09:57:03 -0700 (PDT) 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752881AbeC1Qz5 (ORCPT + 99 others); Wed, 28 Mar 2018 12:55:57 -0400 Received: from mga02.intel.com ([134.134.136.20]:53107 "EHLO mga02.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752070AbeC1Qzr (ORCPT ); Wed, 28 Mar 2018 12:55:47 -0400 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by orsmga101.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 28 Mar 2018 09:55:46 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.48,372,1517904000"; d="scan'208";a="42043574" Received: from black.fi.intel.com ([10.237.72.28]) by fmsmga001.fm.intel.com with ESMTP; 28 Mar 2018 09:55:44 -0700 Received: by black.fi.intel.com (Postfix, from userid 1000) id 38878119; Wed, 28 Mar 2018 19:55:43 +0300 (EEST) From: "Kirill A. Shutemov" To: Ingo Molnar , x86@kernel.org, Thomas Gleixner , "H. Peter Anvin" , Tom Lendacky Cc: Dave Hansen , Kai Huang , linux-kernel@vger.kernel.org, linux-mm@kvack.org, "Kirill A. Shutemov" Subject: [PATCHv2 02/14] x86/mm: Mask out KeyID bits from page table entry pfn Date: Wed, 28 Mar 2018 19:55:28 +0300 Message-Id: <20180328165540.648-3-kirill.shutemov@linux.intel.com> X-Mailer: git-send-email 2.16.2 In-Reply-To: <20180328165540.648-1-kirill.shutemov@linux.intel.com> References: <20180328165540.648-1-kirill.shutemov@linux.intel.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org MKTME claims several upper bits of the physical address in a page table entry to encode KeyID. It effectively shrinks number of bits for physical address. We should exclude KeyID bits from physical addresses. For instance, if CPU enumerates 52 physical address bits and number of bits claimed for KeyID is 6, bits 51:46 must not be threated as part physical address. This patch adjusts __PHYSICAL_MASK during MKTME enumeration. Signed-off-by: Kirill A. Shutemov --- arch/x86/kernel/cpu/intel.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/arch/x86/kernel/cpu/intel.c b/arch/x86/kernel/cpu/intel.c index 6106d11ceb6b..a5b9d3dfa0c1 100644 --- a/arch/x86/kernel/cpu/intel.c +++ b/arch/x86/kernel/cpu/intel.c @@ -586,6 +586,29 @@ static void detect_tme(struct cpuinfo_x86 *c) mktme_status = MKTME_ENABLED; } +#ifdef CONFIG_X86_INTEL_MKTME + if (mktme_status == MKTME_ENABLED && nr_keyids) { + /* + * Mask out bits claimed from KeyID from physical address mask. + * + * For instance, if a CPU enumerates 52 physical address bits + * and number of bits claimed for KeyID is 6, bits 51:46 of + * physical address is unusable. + */ + phys_addr_t keyid_mask; + + keyid_mask = GENMASK_ULL(c->x86_phys_bits - 1, c->x86_phys_bits - keyid_bits); + physical_mask &= ~keyid_mask; + } else { + /* + * Reset __PHYSICAL_MASK. + * Maybe needed if there's inconsistent configuation + * between CPUs. + */ + physical_mask = (1ULL << __PHYSICAL_MASK_SHIFT) - 1; + } +#endif + /* * KeyID bits effectively lower the number of physical address * bits. Update cpuinfo_x86::x86_phys_bits accordingly. -- 2.16.2