Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp3402598imm; Tue, 17 Jul 2018 04:22:45 -0700 (PDT) X-Google-Smtp-Source: AAOMgpcywyyZsnvgwuYKkSyNRp7XRzIoSA56jfh+RxgpjnrbLTt14FVK2FT+B77aemg3PTz9/4zu X-Received: by 2002:a17:902:bb8d:: with SMTP id m13-v6mr1242589pls.46.1531826565522; Tue, 17 Jul 2018 04:22:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1531826565; cv=none; d=google.com; s=arc-20160816; b=IdMVZ6b+/YJrE+MFlPJ1D1UYy/a053JEK6FjngwdxdGnMBoHuYTWeuoOmIvRXz8kAj fWA40UoGQXEBzHg43Udu/ALrlxxloocJGoBWWydsTgTyPcveZd04PoUJmMzNNAKpv5Py Y+sFjkTM0QI8GqdEXyJniS361GZBUyJukVzkEcOAslcfehoStfM/MLF9KulbOhGveLlz IfuZVnCh4A20Z/pXpUFl7Lnogjvff5f220W9AhEO1fbLPPMwmhshJFFa5b93H7UTGgQe aI3zkk4rSb5xOlZJ6WFK8F+J+RWj4AikbZKeD7Bgp0tGN9CYpnKX1IyGuxbRmdrHaCcI nIlQ== 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=/M5r6OI5RLXh7B8MYgAFJedVAPLxUBn3YmAGycr8dLQ=; b=oHmaBDX+1rQwY8mLhl0+btNphPvHoIlYrXPdrzMl64rCxR7/DmCoHbVCZwBGNlgyzw W4koSjXZxVdXsAdGUP8d4An8ylCtdYl6ttLAQLPAA0nE6nGop1rNyv2tGL9RUkZOcIwv bVo1Mubus0BK+vvpHbSCJRSSj/m3Y+ZINFt6o0aDySm9CH8jeUfGP5YzTKtsaCe8FRjh BZfHcDd/vTXAsoXktNpdSgUoJzkLT1aGZ6H3D9H7p4jlaiavGFvvuwylsNu6PXjwT1c1 ziuLEsjE47HHjzIT53Xi0HTW0AqHbo2nU68vrDa9GCjMA/TLpPFh2djcQCI7eqSxDNNJ hcTQ== 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 y34-v6si635716plb.317.2018.07.17.04.22.30; Tue, 17 Jul 2018 04:22:45 -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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731523AbeGQLyA (ORCPT + 99 others); Tue, 17 Jul 2018 07:54:00 -0400 Received: from mga01.intel.com ([192.55.52.88]:16951 "EHLO mga01.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730839AbeGQLx7 (ORCPT ); Tue, 17 Jul 2018 07:53:59 -0400 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga006.jf.intel.com ([10.7.209.51]) by fmsmga101.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 17 Jul 2018 04:21:50 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.51,365,1526367600"; d="scan'208";a="58320642" Received: from black.fi.intel.com ([10.237.72.28]) by orsmga006.jf.intel.com with ESMTP; 17 Jul 2018 04:21:45 -0700 Received: by black.fi.intel.com (Postfix, from userid 1000) id 06286476; Tue, 17 Jul 2018 14:21:48 +0300 (EEST) From: "Kirill A. Shutemov" To: Ingo Molnar , x86@kernel.org, Thomas Gleixner , "H. Peter Anvin" , Tom Lendacky Cc: Dave Hansen , Kai Huang , Jacob Pan , linux-kernel@vger.kernel.org, linux-mm@kvack.org, "Kirill A. Shutemov" Subject: [PATCHv5 07/19] x86/mm: Mask out KeyID bits from page table entry pfn Date: Tue, 17 Jul 2018 14:20:17 +0300 Message-Id: <20180717112029.42378-8-kirill.shutemov@linux.intel.com> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180717112029.42378-1-kirill.shutemov@linux.intel.com> References: <20180717112029.42378-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 eb75564f2d25..bf2caf9d52dd 100644 --- a/arch/x86/kernel/cpu/intel.c +++ b/arch/x86/kernel/cpu/intel.c @@ -571,6 +571,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.18.0