From patchwork Tue Jul 17 11:20:18 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Kirill A . Shutemov" X-Patchwork-Id: 10529011 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 7FB39603ED for ; Tue, 17 Jul 2018 11:22:02 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6C65F28A05 for ; Tue, 17 Jul 2018 11:22:02 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5EF1728968; Tue, 17 Jul 2018 11:22:02 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00, MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DA5E328A05 for ; Tue, 17 Jul 2018 11:22:01 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 686326B0266; Tue, 17 Jul 2018 07:21:50 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 6325F6B0271; Tue, 17 Jul 2018 07:21:50 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 503E86B026A; Tue, 17 Jul 2018 07:21:50 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pg1-f200.google.com (mail-pg1-f200.google.com [209.85.215.200]) by kanga.kvack.org (Postfix) with ESMTP id F13646B0010 for ; Tue, 17 Jul 2018 07:21:49 -0400 (EDT) Received: by mail-pg1-f200.google.com with SMTP id o16-v6so322061pgv.21 for ; Tue, 17 Jul 2018 04:21:49 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-original-authentication-results:x-gm-message-state:from:to:cc :subject:date:message-id:in-reply-to:references; bh=9VqySwQJImLAdaNYXwDhI6AlgFwRVoub/o3twYLSqac=; b=Wk83ZuxWfon8BUz6xsxe7PSVeHzel3YvQFxNQqc7ZbzWQbz36s/bG3f7loJPM/dADC HtWonfspoxMo1czw4IiOQ8bwE6hFKv5JXYq1w7Y/Gp+0jrpKpntaEtbSmxdd1BV4znf5 dlBtkvf/uF+/zpjP690N3hdc3Bjxh3QSdvT7lAlXONzsRw/U4tbmS9ExCiHKweFqSHwD x2T7AL6GDwlBF7JPNJmvCDHyO2+dG3TBHVh+TD8WSCC+B8wJWQzC0iydhTKIhIOTUvpK eNlkaK7/xUNqA5n0fuhAEz/xSKNKxYm3cy3kq5LbdvK18r6QPiFBOB9qsc52F7zutmUq mmJA== X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of kirill.shutemov@linux.intel.com designates 192.55.52.43 as permitted sender) smtp.mailfrom=kirill.shutemov@linux.intel.com; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com X-Gm-Message-State: AOUpUlG1pC56R5CxmvP+oaPt5a/ulPnX+czTbnJqiBhSnMRLdMFuFqcx wh3uoPTzElHxawI2lcGE/FNpajRzBYiubbhrhMEcOx2a3u9Z4AoaaSneGgQmIuHFp4DQv4pSm4n ca9NnvZjU4IJEIyMV70O2EfPfKrMSR9yxglIXXNr5BROaB0w6gu2TZbuIV3zu0pPTSQ== X-Received: by 2002:a63:231a:: with SMTP id j26-v6mr1203148pgj.138.1531826509646; Tue, 17 Jul 2018 04:21:49 -0700 (PDT) X-Google-Smtp-Source: AAOMgpfabRhrY5zdIeNhfsAEuKc830che07/Sqd3/MJRXy7YMeoGXmQvfhvemdS82zbr1Q3A6Cpw X-Received: by 2002:a63:231a:: with SMTP id j26-v6mr1203115pgj.138.1531826508858; Tue, 17 Jul 2018 04:21:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1531826508; cv=none; d=google.com; s=arc-20160816; b=MeKGtpkNUl11sEwyPpMh8mJAoAww2va1z4MK0P1KUBiD9IbvztO5foauZF0Ik1I7Mo D8kWjqqJNXz3EgGAc+XhO05M95fGAqY0FCSn+VSjzfZ4M2C9PgtW6uC7EbC+nte8ZDBn n3/7OYcygl/wEpqeg0Tc2xHPf4WdDN5JyX7MR4P3w+mrEiHmDTqQK8P726Td9l3AfAdr F9WwHHSF0Lfm/QN7b/NjHN6Gsr8eHl51VuSOjyhqTc375ziyytm7qw+12P3kz7jjupcG TPu0Df/Gfl6TopW66YWmBXLq32YWFC+9shjwXHF3FCM2uhaqTzlf3MXF7sf5xC8Zfmby +/Zg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=9VqySwQJImLAdaNYXwDhI6AlgFwRVoub/o3twYLSqac=; b=IIgYWuw0VxLuCKaBHKt/f87LtVW87Ov5HNMxQu+aSPP38VnweCPjYBbX2/7ai6hyvq ILM0zjzjmxcxbWSJ88jyzNMzoUBFfRtLY6ZWC2KXrov/53Sx24wMgurbVjeYY6XqRukj z++JwAgPtL431KHEsSr8MzsAwUMhb/bHiUgZKroSq3x4kIjy88UC5clRrLTx5YYlwUc2 Mm9RUAFOshBsOJSgqfnUMU71FYFlLKzwwYNsAnYTQGka+KxsJ8+Ctt9QKWtL98SDdiXM KRXXsyQCiVpCcwQaHNYUuKzSQ38F3NqBtEGyixVH56bBYgOFg6spzdhCbOC7HuXr6wBr XcSg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of kirill.shutemov@linux.intel.com designates 192.55.52.43 as permitted sender) smtp.mailfrom=kirill.shutemov@linux.intel.com; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from mga05.intel.com (mga05.intel.com. [192.55.52.43]) by mx.google.com with ESMTPS id a4-v6si759513pgl.9.2018.07.17.04.21.48 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 17 Jul 2018 04:21:48 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of kirill.shutemov@linux.intel.com designates 192.55.52.43 as permitted sender) client-ip=192.55.52.43; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of kirill.shutemov@linux.intel.com designates 192.55.52.43 as permitted sender) smtp.mailfrom=kirill.shutemov@linux.intel.com; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by fmsmga105.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 17 Jul 2018 04:21:48 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.51,365,1526367600"; d="scan'208";a="72049658" Received: from black.fi.intel.com ([10.237.72.28]) by fmsmga004.fm.intel.com with ESMTP; 17 Jul 2018 04:21:45 -0700 Received: by black.fi.intel.com (Postfix, from userid 1000) id 0FA4B4EA; Tue, 17 Jul 2018 14:21:49 +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 08/19] x86/mm: Introduce variables to store number, shift and mask of KeyIDs Date: Tue, 17 Jul 2018 14:20:18 +0300 Message-Id: <20180717112029.42378-9-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> X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: X-Virus-Scanned: ClamAV using ClamSMTP mktme_nr_keyids holds number of KeyIDs available for MKTME, excluding KeyID zero which used by TME. MKTME KeyIDs start from 1. mktme_keyid_shift holds shift of KeyID within physical address. mktme_keyid_mask holds mask to extract KeyID from physical address. Signed-off-by: Kirill A. Shutemov --- arch/x86/include/asm/mktme.h | 16 ++++++++++++++++ arch/x86/kernel/cpu/intel.c | 12 ++++++++---- arch/x86/mm/Makefile | 2 ++ arch/x86/mm/mktme.c | 5 +++++ 4 files changed, 31 insertions(+), 4 deletions(-) create mode 100644 arch/x86/include/asm/mktme.h create mode 100644 arch/x86/mm/mktme.c diff --git a/arch/x86/include/asm/mktme.h b/arch/x86/include/asm/mktme.h new file mode 100644 index 000000000000..df31876ec48c --- /dev/null +++ b/arch/x86/include/asm/mktme.h @@ -0,0 +1,16 @@ +#ifndef _ASM_X86_MKTME_H +#define _ASM_X86_MKTME_H + +#include + +#ifdef CONFIG_X86_INTEL_MKTME +extern phys_addr_t mktme_keyid_mask; +extern int mktme_nr_keyids; +extern int mktme_keyid_shift; +#else +#define mktme_keyid_mask ((phys_addr_t)0) +#define mktme_nr_keyids 0 +#define mktme_keyid_shift 0 +#endif + +#endif diff --git a/arch/x86/kernel/cpu/intel.c b/arch/x86/kernel/cpu/intel.c index bf2caf9d52dd..efc9e9fc47d4 100644 --- a/arch/x86/kernel/cpu/intel.c +++ b/arch/x86/kernel/cpu/intel.c @@ -573,6 +573,9 @@ static void detect_tme(struct cpuinfo_x86 *c) #ifdef CONFIG_X86_INTEL_MKTME if (mktme_status == MKTME_ENABLED && nr_keyids) { + mktme_nr_keyids = nr_keyids; + mktme_keyid_shift = c->x86_phys_bits - keyid_bits; + /* * Mask out bits claimed from KeyID from physical address mask. * @@ -580,10 +583,8 @@ static void detect_tme(struct cpuinfo_x86 *c) * 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; + mktme_keyid_mask = GENMASK_ULL(c->x86_phys_bits - 1, mktme_keyid_shift); + physical_mask &= ~mktme_keyid_mask; } else { /* * Reset __PHYSICAL_MASK. @@ -591,6 +592,9 @@ static void detect_tme(struct cpuinfo_x86 *c) * between CPUs. */ physical_mask = (1ULL << __PHYSICAL_MASK_SHIFT) - 1; + mktme_keyid_mask = 0; + mktme_keyid_shift = 0; + mktme_nr_keyids = 0; } #endif diff --git a/arch/x86/mm/Makefile b/arch/x86/mm/Makefile index 4b101dd6e52f..4ebee899c363 100644 --- a/arch/x86/mm/Makefile +++ b/arch/x86/mm/Makefile @@ -53,3 +53,5 @@ obj-$(CONFIG_PAGE_TABLE_ISOLATION) += pti.o obj-$(CONFIG_AMD_MEM_ENCRYPT) += mem_encrypt.o obj-$(CONFIG_AMD_MEM_ENCRYPT) += mem_encrypt_identity.o obj-$(CONFIG_AMD_MEM_ENCRYPT) += mem_encrypt_boot.o + +obj-$(CONFIG_X86_INTEL_MKTME) += mktme.o diff --git a/arch/x86/mm/mktme.c b/arch/x86/mm/mktme.c new file mode 100644 index 000000000000..467f1b26c737 --- /dev/null +++ b/arch/x86/mm/mktme.c @@ -0,0 +1,5 @@ +#include + +phys_addr_t mktme_keyid_mask; +int mktme_nr_keyids; +int mktme_keyid_shift;