Received: by 10.223.185.116 with SMTP id b49csp2776714wrg; Mon, 5 Mar 2018 08:31:03 -0800 (PST) X-Google-Smtp-Source: AG47ELs2EQDVFU9yGlb8D0yubgedoEuP5IOjGuvT3btmT9FZAO0FqU8uX0aXbtUosj8dIOH5vstH X-Received: by 2002:a17:902:7088:: with SMTP id z8-v6mr14130501plk.174.1520267462959; Mon, 05 Mar 2018 08:31:02 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1520267462; cv=none; d=google.com; s=arc-20160816; b=mk8ZCLXAie1nsP2OYYwFOFRg9bw1uX7keDocx9OahMMNX/eQvFlswUemttHC/WReJO 7t4HHZjULxyBREjsAn0/R3pU/Wifrz4L526AgnC+JiMDWb9SBoFsqoUHcGT6Lgjj8F70 Td1JMgZhPxClHNCMEXnfUp3rXJUvTNf6kZ3mHKCtOQgGMAgm+YHZXgjDXfYeEEzBRki2 FIEFawyZIyo9MfctRDsZZHk6lyM8TJvj28DBc1hcAly0m6G0rzRUH07sTcMrOBzNq4HV 0+q6D01rA/Tg8nWAaRBFhT/o5jgOmdJUn/lSA2ZSqr/z0NBEBcOHsGEnl340B2ubgioV oYDA== 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=lWWl24JXyetiNknZKgBVYdEB/6lmZ9YHt3u0/KtV9IY=; b=ZnnUce0NlUkE94KSdL0dWm6IIEIFL6ytTHQzN7NKyTf2R271Fdo3nce82XW5hC7TKN 0olF/yGsose0BD39urT4Jqe2QDD+XCfFwbVX149QXQfQ45yI9Tv+0iVvxjowZ7xw0iqa 2yr4KC/giWGJyhC/2mzi8ZD2DLpHA9At3gdN1yCSiK7Ji7iNO+VBWVhmknN97I9ll40H VXcQg4JzOL/HwMUBB5+3rnESh+niHvvmOVkAJgVgHK//kko5T73oVO7fgmP1d0UJb89N Ua2nOHAfLy0adJRhh0YxoZ4s80EP1eGE3HD67jpcUJ0k5JwJI2Qd+GrGMFqBwzmNVneF 9ZTw== 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 s187si10307528pfs.1.2018.03.05.08.30.49; Mon, 05 Mar 2018 08:31:02 -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 S1752904AbeCEQ2O (ORCPT + 99 others); Mon, 5 Mar 2018 11:28:14 -0500 Received: from mga05.intel.com ([192.55.52.43]:31633 "EHLO mga05.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752639AbeCEQ0a (ORCPT ); Mon, 5 Mar 2018 11:26:30 -0500 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by fmsmga105.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 05 Mar 2018 08:26:29 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.47,427,1515484800"; d="scan'208";a="25328730" Received: from black.fi.intel.com ([10.237.72.28]) by fmsmga002.fm.intel.com with ESMTP; 05 Mar 2018 08:26:27 -0800 Received: by black.fi.intel.com (Postfix, from userid 1000) id 8A6545E0; 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 15/22] x86/mm: Introduce variables to store number, shift and mask of KeyIDs Date: Mon, 5 Mar 2018 19:26:03 +0300 Message-Id: <20180305162610.37510-16-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_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 | 13 +++++++++---- arch/x86/mm/Makefile | 2 ++ arch/x86/mm/mktme.c | 5 +++++ 4 files changed, 32 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 35436bbadd0b..77b5dc937ac6 100644 --- a/arch/x86/kernel/cpu/intel.c +++ b/arch/x86/kernel/cpu/intel.c @@ -589,11 +589,13 @@ 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; + mktme_keyid_mask = 1ULL << c->x86_phys_bits; + mktme_keyid_mask -= 1ULL << (c->x86_phys_bits - keyid_bits); + physical_mask &= ~mktme_keyid_mask; - keyid_mask = 1ULL << c->x86_phys_bits; - keyid_mask -= 1ULL << (c->x86_phys_bits - keyid_bits); - physical_mask &= ~keyid_mask; + + mktme_nr_keyids = nr_keyids; + mktme_keyid_shift = c->x86_phys_bits - keyid_bits; } else { /* * Reset __PHYSICAL_MASK. @@ -601,6 +603,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; -- 2.16.1