From patchwork Tue Jun 12 14:39:04 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: 10460509 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 3751A602A0 for ; Tue, 12 Jun 2018 14:39:57 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1F9DE287AB for ; Tue, 12 Jun 2018 14:39:57 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 13FDD287E3; Tue, 12 Jun 2018 14:39:57 +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 1EAF9287AB for ; Tue, 12 Jun 2018 14:39:56 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 82E546B026A; Tue, 12 Jun 2018 10:39:29 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 789A76B000D; Tue, 12 Jun 2018 10:39:29 -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 5C25A6B026D; Tue, 12 Jun 2018 10:39:29 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pl0-f69.google.com (mail-pl0-f69.google.com [209.85.160.69]) by kanga.kvack.org (Postfix) with ESMTP id F3E496B0266 for ; Tue, 12 Jun 2018 10:39:28 -0400 (EDT) Received: by mail-pl0-f69.google.com with SMTP id a5-v6so14026418plp.8 for ; Tue, 12 Jun 2018 07:39:28 -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=z+jpSrqQMww+aiNy9vF5/R2lMQFmVLzAsgYlacG41S4=; b=DaK5VvVFK/mZS1kLxSN7dlv+LIiGroepTXxdEViuzlcFynp71TBbySDx1IqeQeUIYv XWVmQ8PJYRBmVB5WEgLDlGjP9zCpYIQQpe3hnjYNqGj/+G82BJl4W8YVCrGQ6O73PoUE bphmp8RgJhns7FNqBzjgk9smtb5XWch79Ku18JF489IfZSWnnumbNERfUhoX3EDXA1W/ 2rpjR7F4zoSsOyzCS0xabiLI5ofiV7a1E24Yjq42T6q2Nh7+xYq7gNr/fIFXmxLIqGHj 5kV/UpgFE4uaumhGpRdZloM42bHK4qqF2rWZSOo4KO6FgZnRVo86H43SnSnUF5MQiV0K ohNQ== X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of kirill.shutemov@linux.intel.com designates 134.134.136.100 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: APt69E2H7ipAenm4lsuxbnt/cGvNWar7U1FJ+fFB7NH8QI9ZOGdQv1Re xUigh6u0OIFyviuQds8fI+FRoUKjpg9WZX7KORHRPXXUDHTTexH1ijf0uRqSF/850zXVaBqOvpW 0dXJcdypdWTcCD9zh976mAaEEjO6DB+Cj0XuA90hy48SqV5yqhd+iCIUYKR8m7N/Eyg== X-Received: by 2002:a63:6e08:: with SMTP id j8-v6mr568791pgc.428.1528814368679; Tue, 12 Jun 2018 07:39:28 -0700 (PDT) X-Google-Smtp-Source: ADUXVKL8KrlpSfruqVa2pk9BIcm6rXOkKxjClz1icoIr++5A+xVkHixtV/mypA8jhsNYX9YoQJaZ X-Received: by 2002:a63:6e08:: with SMTP id j8-v6mr568747pgc.428.1528814367821; Tue, 12 Jun 2018 07:39:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1528814367; cv=none; d=google.com; s=arc-20160816; b=M7iRB6LPv8K72KItWgSaD2gLGOHHhq4DJol0s/hh39YyJw0fcW2QSp4DYuEQljzPtE IHsQFiJTIw1JVcDEQfSxxqbyCvqXr8camWJzlk94pb5PfKOJFXCXeYQJlbrglc9+5T0N eWcJc7tjzLTnsMbMt2WwSEzb47V2YDFrmcDz4nJaO/cyU31VMnnFrAj+qPKhX+fMY/TS LmXxVIssAm3kMLqo3Vf/NLndxwhTwWWEoToluOB4BDf40PuyG4kEvzBBqM2DpDijU2AH YO2Djt4flBXY8QmPImR1sNCeMCYSmGKP9fPx9u8qSg1MwVRNdg7Q/9Tka2CMG6dL8Lvr 6Uug== 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=z+jpSrqQMww+aiNy9vF5/R2lMQFmVLzAsgYlacG41S4=; b=xp15SRf2+Vvyp9opxZreZR7Y8mctKZqzAOjqeT/Liq4j32qZIRAO7Yxt4PlFU/1ZJR ZA4FSuQNugqDtZWRlBRM8HNPFQLutovzZpsag9Xf3nC556KMa4mdgmnLMm/I7HDcEQ9z xEEllWiTXNE4iNBVc+JZ+2VUInACGFZbuspui+TS/x93Kma2ugq0tIJzzcii2Z4iYelC IFE0ZOw9+dG++51nlGL2Sipn+f+K/sGwdCPtTTZXJ0Des/P9bqzm9NwY6W3c+jUi+Ri8 Czpcg6O6t2FUISmfxdJLBGc5w87N4ziKCLDqRK7FfQRysBvMVZZTrbwzETDzG33m5cdI ObcA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of kirill.shutemov@linux.intel.com designates 134.134.136.100 as permitted sender) smtp.mailfrom=kirill.shutemov@linux.intel.com; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from mga07.intel.com (mga07.intel.com. [134.134.136.100]) by mx.google.com with ESMTPS id l5-v6si295495pls.360.2018.06.12.07.39.27 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 12 Jun 2018 07:39:27 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of kirill.shutemov@linux.intel.com designates 134.134.136.100 as permitted sender) client-ip=134.134.136.100; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of kirill.shutemov@linux.intel.com designates 134.134.136.100 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 orsmga004.jf.intel.com ([10.7.209.38]) by orsmga105.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 12 Jun 2018 07:39:27 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.51,215,1526367600"; d="scan'208";a="207428840" Received: from black.fi.intel.com ([10.237.72.28]) by orsmga004.jf.intel.com with ESMTP; 12 Jun 2018 07:39:24 -0700 Received: by black.fi.intel.com (Postfix, from userid 1000) id D243F3C0; Tue, 12 Jun 2018 17:39:20 +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: [PATCHv3 06/17] x86/mm: Introduce variables to store number, shift and mask of KeyIDs Date: Tue, 12 Jun 2018 17:39:04 +0300 Message-Id: <20180612143915.68065-7-kirill.shutemov@linux.intel.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180612143915.68065-1-kirill.shutemov@linux.intel.com> References: <20180612143915.68065-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;