Received: by 10.223.185.116 with SMTP id b49csp2778814wrg; Mon, 5 Mar 2018 08:32:49 -0800 (PST) X-Google-Smtp-Source: AG47ELst1Mz6Ct3/l7YOxDRd/NkursyEUGqMkHjnecol6gGodrxK56JB5C9bHHDqRTXus2ETMGhq X-Received: by 2002:a17:902:3303:: with SMTP id a3-v6mr13565228plc.399.1520267569817; Mon, 05 Mar 2018 08:32:49 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1520267569; cv=none; d=google.com; s=arc-20160816; b=FRWJ/3jtATdH74ZTAbokZ+AZGWD+a1BjUM2wriKN+Kgpb3jOlwzKUl8dtmJzfwqXL8 SdSiBqLC0Vya26jSmQbFb0dBzfTI3TnUiR+MDa06CsMrQ0wHZUjl4sKfgyWK1UoPMaEb Jw6za9A5NsEGzqTyNaRl//8DbVMP0EGIdLoCs4JeiyUFtpECRJIa4r+0CydyT06jYtV7 jrPMEG0Ri6Rjutn58qoj1V3nJQ4WwVZelNzIo90l62+GWuqsDwOUvynndqqwmPnrBDit DCDQY2BlNNzYiUtK9YQjkyLzgB4JFuW+NGfeY2GJ2Fyh2vXW/uAzCJw/ADR3Cp1gQ2aa kk/g== 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=SkIxX+nIo1elMmXLOR4buJq8KqGLN0okwF7rH5UkcOI=; b=z7MqpLMJ1Ejn9HPo1+bTUWZmcs0CCsPBLi+1PboLjVzpZlNQkjoq9U1ntcOagWIOTU hx0i7ix1zrfmsdxDWf3zV+c5CSnI24O7CYvdiA7da2hZKxHgN4m3PXe9NjLfhJUEcmnz OjU9uhVv5keP/aQrun4rboBJQ3kOY3WAEYlaPmw6V++zCU6k+r8etsoSppa7ZDDEObT+ xsRjzq9ZADpr5KSz5zcELFG5vtdiKffd8PULpXg226Mx4eYQxgFH7OUav/GYPYEvlL1L OJxjXd7AgnGN9Udk2/KD+UzF/g5GR26QbbWbScd77Ufu3ZHYR5jl/OFJIY7n/cUylsB3 FGcA== 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 7-v6si8299731plb.573.2018.03.05.08.32.35; Mon, 05 Mar 2018 08:32:49 -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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752975AbeCEQax (ORCPT + 99 others); Mon, 5 Mar 2018 11:30:53 -0500 Received: from mga17.intel.com ([192.55.52.151]:37468 "EHLO mga17.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752321AbeCEQ01 (ORCPT ); Mon, 5 Mar 2018 11:26:27 -0500 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmsmga107.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 05 Mar 2018 08:26:26 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.47,427,1515484800"; d="scan'208";a="35620816" Received: from black.fi.intel.com ([10.237.72.28]) by fmsmga001.fm.intel.com with ESMTP; 05 Mar 2018 08:26:24 -0800 Received: by black.fi.intel.com (Postfix, from userid 1000) id 30DFD193; Mon, 5 Mar 2018 18:26:20 +0200 (EET) 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: [RFC, PATCH 07/22] x86/mm: Mask out KeyID bits from page table entry pfn Date: Mon, 5 Mar 2018 19:25:55 +0300 Message-Id: <20180305162610.37510-8-kirill.shutemov@linux.intel.com> X-Mailer: git-send-email 2.16.1 In-Reply-To: <20180305162610.37510-1-kirill.shutemov@linux.intel.com> References: <20180305162610.37510-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 | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/arch/x86/kernel/cpu/intel.c b/arch/x86/kernel/cpu/intel.c index c770689490b5..35436bbadd0b 100644 --- a/arch/x86/kernel/cpu/intel.c +++ b/arch/x86/kernel/cpu/intel.c @@ -580,6 +580,30 @@ 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 = 1ULL << c->x86_phys_bits; + keyid_mask -= 1ULL << (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 + /* * Exclude KeyID bits from physical address bits. * -- 2.16.1