Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp6107438ybi; Wed, 31 Jul 2019 08:27:40 -0700 (PDT) X-Google-Smtp-Source: APXvYqzWeFBB/27KYxnFj82p7E+XbUz6BhFbH5ZbTSRT/xUw7W7v0PVTrtEDzHB848htaIb2X5ru X-Received: by 2002:a63:fe17:: with SMTP id p23mr16259096pgh.103.1564586860431; Wed, 31 Jul 2019 08:27:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1564586860; cv=none; d=google.com; s=arc-20160816; b=eZrksQnURxhd/zNr7/QpGCByabKkej9s1K2EP7UX+05Ve02nLaODG+Y5qzCFpiW2Gn xmsTMrWhqCSxYEF5Y2y31tN2uPRlE2NiVftXUBRJ6ZqDMFf/e1y9WGyIN/eAspZ/Ptq5 HA8LqgjFoJf6ylUDVlRkPqrq/g6EEVkJGl9a608jmKnYFFOzT9hnSx8Vv+xqovFKQyVD i70rozL5iC9JGfIzpgpXLq+tWDEEsdQWcm2PzHQnjs5MF7X6xpjRY2ZvegrBq0cPl9en DqyBOeNFTk7NTy6s2plgd+7UUrcOmvHs6eEFHkve2zpDoR9Uk89yePMnxT/rewpwyhuF mpLg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=mtVfWkAA6f5+WVvylDNJC/YjX6VpSH295mUWXLakGJs=; b=WI/HKAI9XH+pGz8dNvWkADZH9VVqTRE0ViuhzRytai3VLXvO/ZuNaA15jaFO+alvoF Xxrn7t0bvgj0eUOtnLgqEZHdE7UjJSlLlF7ntWf7Okl5XFb8wvSSIk4XuyXykbu+WQ/5 kZkKPeGT24rALOfRfIipNAviiowh+YJKUaQ+czh1XLNO/uQpyn497o6NRzPvrRVPnfHO qsSnVTg/y8UlAiVel8HpRra8PVrtUmavnZspx8ZybY55abmNsjgc7xo0DMVrKzU2Mi0V l7PM3/eUTwIssF394GBwkFu2siUh0mXEpLFY2f8Uy5i5Lhf5dcb+0BTrPiFS3so4o/mj hOfw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@shutemov-name.20150623.gappssmtp.com header.s=20150623 header.b=F6Gayf2v; 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 u9si21267749pgr.196.2019.07.31.08.27.24; Wed, 31 Jul 2019 08:27:40 -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; dkim=pass header.i=@shutemov-name.20150623.gappssmtp.com header.s=20150623 header.b=F6Gayf2v; 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 S1729506AbfGaPKd (ORCPT + 99 others); Wed, 31 Jul 2019 11:10:33 -0400 Received: from mail-ed1-f67.google.com ([209.85.208.67]:41211 "EHLO mail-ed1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388470AbfGaPIW (ORCPT ); Wed, 31 Jul 2019 11:08:22 -0400 Received: by mail-ed1-f67.google.com with SMTP id p15so65977310eds.8 for ; Wed, 31 Jul 2019 08:08:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=shutemov-name.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=mtVfWkAA6f5+WVvylDNJC/YjX6VpSH295mUWXLakGJs=; b=F6Gayf2vpoXGYJV1uYsSi1oz9m/Dzpd5ss3IOuggi2htSc6htYXpy88IVTNHrSo5Kq hWpzEyAGHC2mXZ2wjIjArOS3WPtQuYHcn8nT+/O5W6T39U8KBhjxYitFwEIaU42F/UUZ MNDJaDmYDJ2rhvFYveEcpSA76sB3cuT4BXBPtSCQ2kN740Cc3sAloiWNwrNa1DM5fuLc QNavgnJR+irD1X17yEJ886mr2816CG2BFT/M05u0Cg9IRy9uHdqMz7DhseDkDzn7Vz3t VhUu8iRxDz4AskPYJARFdivUJOn42HuHlC1NNjkGej7JPSPdAEioY0xwz3pfTdTU9bkn rRzQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=mtVfWkAA6f5+WVvylDNJC/YjX6VpSH295mUWXLakGJs=; b=YWA4cM8wvNFfdqfvJQE4Ylb2XMYmQ84v9g9QbGJ7cReQWsdXXKm3e9PUGNSK2Ydhtn cAOIqEhSN4nJQTWlQ1og+f3meL2NcEyadn8/V6B3jupXU2KLEmm0GuHLokSCT4HgIXsn pVjcQy7Qw/HqmevjhkYjUhd40CvlMx0AsMIQojiiJhXFBbLztTNHGUhPelhyIM5WNU/W Nvoh9ZbYZCyqkyLMilPD7K8K1UzFBOzeNA+iQowniNwf1AzgO3OS0nPC4LWVtyGD55xG H6UjA3uWe7tkDLUa8a1O5YTLDtKbjACehFS9ohIxhXu7LSKUHegfcCnTiqg0nado8/Vx 36ZQ== X-Gm-Message-State: APjAAAWNeh94bgk6RO6JkZunkJ0CIivhDM2wodjNUujPaWhOSVIOsiKo 3tJEHaCZJPruD2wKjjbuhUc= X-Received: by 2002:a17:906:7f16:: with SMTP id d22mr95105774ejr.17.1564585700959; Wed, 31 Jul 2019 08:08:20 -0700 (PDT) Received: from box.localdomain ([86.57.175.117]) by smtp.gmail.com with ESMTPSA id d7sm16505352edr.39.2019.07.31.08.08.18 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 31 Jul 2019 08:08:19 -0700 (PDT) From: "Kirill A. Shutemov" X-Google-Original-From: "Kirill A. Shutemov" Received: by box.localdomain (Postfix, from userid 1000) id 1E8B210131E; Wed, 31 Jul 2019 18:08:16 +0300 (+03) To: Andrew Morton , x86@kernel.org, Thomas Gleixner , Ingo Molnar , "H. Peter Anvin" , Borislav Petkov , Peter Zijlstra , Andy Lutomirski , David Howells Cc: Kees Cook , Dave Hansen , Kai Huang , Jacob Pan , Alison Schofield , linux-mm@kvack.org, kvm@vger.kernel.org, keyrings@vger.kernel.org, linux-kernel@vger.kernel.org, "Kirill A. Shutemov" Subject: [PATCHv2 07/59] x86/mm: Mask out KeyID bits from page table entry pfn Date: Wed, 31 Jul 2019 18:07:21 +0300 Message-Id: <20190731150813.26289-8-kirill.shutemov@linux.intel.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190731150813.26289-1-kirill.shutemov@linux.intel.com> References: <20190731150813.26289-1-kirill.shutemov@linux.intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 8d6d92ebeb54..f03eee666761 100644 --- a/arch/x86/kernel/cpu/intel.c +++ b/arch/x86/kernel/cpu/intel.c @@ -616,6 +616,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.21.0