Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp3404721imm; Tue, 17 Jul 2018 04:25:07 -0700 (PDT) X-Google-Smtp-Source: AAOMgpfQOS4Y38hakiEdCCVSzA00kFJc04IzDcnjzIgH4aURh202mMaQAuOXtAq/LUHqPWt+kCos X-Received: by 2002:a63:5c52:: with SMTP id n18-v6mr1203620pgm.360.1531826707941; Tue, 17 Jul 2018 04:25:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1531826707; cv=none; d=google.com; s=arc-20160816; b=sTGg5JDyhOmkfIWOAH+hJ7n/GlR9iAl6WzVjvDj91Vr8phhey/VSsgRFPmE/hpJWrm 7JsgKNuAeFCrjp16zO2Igq14V04R11S1KfUU83PxzVPNBHgPzi90F7LB0DebMRSM3Hwo rxIzM4voxqHVGZH7MjNA5pfK+KKFvT83QEyTB2HUKxk04q6iTkBBJRamrptrtFO0hNHo lNrgAnG07QLVVNuZ9Go6bsnLeiFxJCtrUGa9VzqtARJqZoddYSHnTyMOEiwqPp6hi96u czdl8SKws+9jeh6TWAknyHjTITXJZzZBoPPnFFYcZYmicQJz/flZpw1eR5+bR+x2a4MU Xhgg== 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=9VqySwQJImLAdaNYXwDhI6AlgFwRVoub/o3twYLSqac=; b=u/IC8/XfA32qczBTqqbxcbjclxqO8onGlzdSuQILE6wZuJmnoaUtbYP8e1DP+3ufhE Eb+mPV16zdsoOyWbUMHJ3BOXIMjfQ/R1zrrHaHGzA4OfW8tNZ5gOkFwb+Fr1LJZi2pmY +ki0Z2FFWV10jx8WDLpC3zbZzmnBFcjmTVdMSQDAh30/YxpRKAioOrj0yzHUr2fl5gac fCsDK+60dBn5b9/T9UBNg0R2F0bm6hbNRrrt9nbd84WIJxPHToeT8a6ukO3NSwjOJ2FG i5uO6elXvFNZDha5oMbdrxuSgyklXUWrtN72Upcc9zMQtkBwMdO7fRpoiZo6o6+b6UbN 6emw== 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 k22-v6si538313pll.118.2018.07.17.04.24.53; Tue, 17 Jul 2018 04:25:07 -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 S1731524AbeGQLzV (ORCPT + 99 others); Tue, 17 Jul 2018 07:55:21 -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 S1731300AbeGQLx5 (ORCPT ); Tue, 17 Jul 2018 07:53:57 -0400 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by fmsmga101.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> 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 | 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; -- 2.18.0