Received: by 10.213.65.68 with SMTP id h4csp638553imn; Wed, 28 Mar 2018 09:59:01 -0700 (PDT) X-Google-Smtp-Source: AIpwx49nMUDNupWvHTxTVU4s0FPALj8gXWh1XvTdDOquPsEF+w+bn0AkYmm6Zt9v5p7F0khxTj7R X-Received: by 2002:a17:902:322:: with SMTP id 31-v6mr4633685pld.122.1522256341089; Wed, 28 Mar 2018 09:59:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1522256341; cv=none; d=google.com; s=arc-20160816; b=JEKudy6nSfGFTdraEaNVAQk60cknWKs4bSnJyQ721n0zIm/6OchhptOlqqawcx1aaA jYoGmDXrkFInvMNrRGhE0/hg0Cx+Rb7fZvKvmw3xgNHX1Ije1ak9zJqIY42fYjHSFI68 pdC7C+j0Aj3R4HDx+XwVrSJjutT4zDNpT9oG+Dj0BlT7Upcn36ww+gbEspc6rglxHrc8 JpRN0anRlHU0sAs6HEq32n6FbzOFlbPO3AKPXyWuYIFVp3wR38M1gypKFa/UQaWABQAu zacZFdFFuOHfaUpUm9jurrhBL9UwwpS16jrV8hgs6gv9V6y4vIHWR/BYClyKZXSj5WTV 7OHQ== 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=9rD0+DddGh5Dzo3p1sAZkEjC9qs+8e/k54Tm0rhZQXQ=; b=cFw2yG5Vj9AEJB+0mv/lN08Ocq8QPzLZ01vDCyI+xA8j/cAZ2iOCsjf/jkUdaOHjlx R1G08EcEo2/XLG2tZRMpgkbEe1/jFI0RFIY8Lot+kq59/dk2PidNlR7MzLbOf7k9nJTl byBzXwGxE05c0QPcseUjIwtn4QMkrhUs8cZSzpi1l3VwS3Fv8q/OFzJFyNmoayV9zo23 oNJLzziA/kry4kxLrM/w213WtGCuQ0xdUlPr75Z0N9433EVe4FwvTkrM0uh31qbksGfi 3bve+aFzQhLh5G4w07e+lz9xAtVhWovjHs7dGtlsKluYDM5iIL6v7QN6wJbBZ0xt8Bqq eYkw== 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 r6-v6si4299816plj.743.2018.03.28.09.58.46; Wed, 28 Mar 2018 09:59:01 -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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753195AbeC1Q5L (ORCPT + 99 others); Wed, 28 Mar 2018 12:57:11 -0400 Received: from mga03.intel.com ([134.134.136.65]:53922 "EHLO mga03.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752457AbeC1Qzv (ORCPT ); Wed, 28 Mar 2018 12:55:51 -0400 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga004.jf.intel.com ([10.7.209.38]) by orsmga103.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 28 Mar 2018 09:55:50 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.48,372,1517904000"; d="scan'208";a="186788759" Received: from black.fi.intel.com ([10.237.72.28]) by orsmga004.jf.intel.com with ESMTP; 28 Mar 2018 09:55:47 -0700 Received: by black.fi.intel.com (Postfix, from userid 1000) id 8ACD344A; Wed, 28 Mar 2018 19:55:43 +0300 (EEST) 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: [PATCHv2 09/14] x86/mm: Introduce variables to store number, shift and mask of KeyIDs Date: Wed, 28 Mar 2018 19:55:35 +0300 Message-Id: <20180328165540.648-10-kirill.shutemov@linux.intel.com> X-Mailer: git-send-email 2.16.2 In-Reply-To: <20180328165540.648-1-kirill.shutemov@linux.intel.com> References: <20180328165540.648-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 a5b9d3dfa0c1..5de02451c29b 100644 --- a/arch/x86/kernel/cpu/intel.c +++ b/arch/x86/kernel/cpu/intel.c @@ -588,6 +588,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. * @@ -595,10 +598,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. @@ -606,6 +607,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.2