From patchwork Tue Jun 12 14:39:10 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: 10460525 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 65A26602A0 for ; Tue, 12 Jun 2018 14:40:21 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 60CA4287FE for ; Tue, 12 Jun 2018 14:40:21 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 558A52882E; Tue, 12 Jun 2018 14:40:21 +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 C8FDB287FE for ; Tue, 12 Jun 2018 14:40:20 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 9E0346B026E; Tue, 12 Jun 2018 10:39:35 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 9168C6B0270; Tue, 12 Jun 2018 10:39:35 -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 677FB6B0271; Tue, 12 Jun 2018 10:39:35 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pl0-f71.google.com (mail-pl0-f71.google.com [209.85.160.71]) by kanga.kvack.org (Postfix) with ESMTP id 25E876B026E for ; Tue, 12 Jun 2018 10:39:35 -0400 (EDT) Received: by mail-pl0-f71.google.com with SMTP id 31-v6so14147748plf.19 for ; Tue, 12 Jun 2018 07:39:35 -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=EAbwDX30q7YjpIxvRLDRgim5uU7BDVU3/OwF9iSqdVg=; b=KrsfeD+4TZvmCgilptHZ+b0FzD+B+D/e1QlLbgEz26wDdS0d4kicfLBAEb2CcqHe0/ gBHR7P162kUOD82hS5JZGqWYxsK7EN1PuGIjq4NXqZmpT5qZZY2qIJUsTqOA+NGJC6r6 3Xwvpp+PVW8fgObZcfv9PcXc8Rt8rzKgwv+QQalvv+uW9QrjkFWsGxE2yT4n2cT96zz3 Kmabg8RTBqhaH38Tw1fE0JTyELIkrgctdZVZAmPB1X2zvEgtoH4jib8KlVJTXfyY8sxV wn04Vt3F8F6kzwPIhdYMZKcuABmRlP2uzAYrDqqJkwShEoGIT4Y8EV29frGT2oV8n6qD VC6Q== 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.115 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: APt69E16HxDde18Z8LfCsq2LToAEKPRNOzjJFcSkluHYeXK4aWg2sgHo d2O1FUfibbLMKNSrw+CM/TlgsiIiazB1VsBjhTbIFWCf8MgBeKRhB6pOT9ldvBTpxUvrEBjlkxm O2qYz7toc+nwcczDutuzEAJkiqu1HrZqHs47ix2URLPaUlZWWgXyq7NOcrN0rPNIsKw== X-Received: by 2002:a63:6b84:: with SMTP id g126-v6mr551199pgc.139.1528814374833; Tue, 12 Jun 2018 07:39:34 -0700 (PDT) X-Google-Smtp-Source: ADUXVKI8sdZ8PXznYHqpYMzxUmFjdOdRaJF4h/NDoGUrVrfAYTo0wGHkKc6Zr4L/gfurnkdsQ4uz X-Received: by 2002:a63:6b84:: with SMTP id g126-v6mr550859pgc.139.1528814368098; Tue, 12 Jun 2018 07:39:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1528814368; cv=none; d=google.com; s=arc-20160816; b=LPm6+lPEIluczHHjYq9z+3yzXjBzS5aP9fnVVfeRfIMQPeLSG1mvXkJyjEfY0ukfSI JC4h4ym9n7eSn/nysiLSwOL49zOBAPUpS0cUobYBHxEfZ0XnheVzwPQH2m2xWBuGKTfH gWYIkDfRc2lihtQjCZOCONKmxb2/LoGAFuvdaOBjIeb5bShmO2luoMhJS9YG0inB/Nyi Wro3rPhBwU869VdzluYyY/2bCegQwXYIGvmVqldhRk0pxA8qs9ow4TxeSiA/uJreiKAQ vpeVXmJQdf1JdGZ/GvrU/7fr2BlePuAmNKj2/DlM2V3NuPZtFNMl9C4xvwOn0M28ekd6 Y39g== 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=EAbwDX30q7YjpIxvRLDRgim5uU7BDVU3/OwF9iSqdVg=; b=O4HEaMbgBtKg7Qd4tat2CPuUCZmozTonChBx+GIT4IBs/+mzkHii0qUDgzw64BaDZv b66RIC3bMix/KTOnVmrjKvAtJ93yMuCr32rDghIwfJ01Q7Uv5RP4BU5Acu/eYfSVat3o cU9F5BKcZ0xuKaU6NhLhQybij2R1yNNhAMlpmhK/wSK87zouIzjKGMql6n7B0WjPsMwK kWRLz15hdfUHEH3FJoTs/1vRSigjWo8ZRaV/2Ybsv8sJwYwpRtd+nQYhHDBv3mspo4sR SNodiV90sqSYc0HUl5f8OYSWC8cIW56oiIX8CGGnOYzbds+KW7txu4VbzwXZF4zJwNd3 05Sg== 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.115 as permitted sender) smtp.mailfrom=kirill.shutemov@linux.intel.com; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from mga14.intel.com (mga14.intel.com. [192.55.52.115]) by mx.google.com with ESMTPS id x4-v6si213451pgv.592.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:28 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of kirill.shutemov@linux.intel.com designates 192.55.52.115 as permitted sender) client-ip=192.55.52.115; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of kirill.shutemov@linux.intel.com designates 192.55.52.115 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 orsmga006.jf.intel.com ([10.7.209.51]) by fmsmga103.fm.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="49279031" Received: from black.fi.intel.com ([10.237.72.28]) by orsmga006.jf.intel.com with ESMTP; 12 Jun 2018 07:39:24 -0700 Received: by black.fi.intel.com (Postfix, from userid 1000) id 25AC44C9; Tue, 12 Jun 2018 17:39:21 +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 12/17] x86/mm: Allow to disable MKTME after enumeration Date: Tue, 12 Jun 2018 17:39:10 +0300 Message-Id: <20180612143915.68065-13-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 Separate MKTME enumaration from enabling. We need to postpone enabling until initialization is complete. The new helper mktme_disable() allows to disable MKTME even if it's enumerated successfully. MKTME initialization may fail and this functionallity allows system to boot regardless of the failure. Signed-off-by: Kirill A. Shutemov --- arch/x86/include/asm/mktme.h | 12 ++++++++++++ arch/x86/kernel/cpu/intel.c | 15 ++++----------- arch/x86/mm/mktme.c | 9 +++++++++ 3 files changed, 25 insertions(+), 11 deletions(-) diff --git a/arch/x86/include/asm/mktme.h b/arch/x86/include/asm/mktme.h index ec7036abdb3f..9363b989a021 100644 --- a/arch/x86/include/asm/mktme.h +++ b/arch/x86/include/asm/mktme.h @@ -6,11 +6,21 @@ struct vm_area_struct; +/* Values for mktme_status */ +#define MKTME_DISABLED 0 +#define MKTME_ENUMERATED 1 +#define MKTME_ENABLED 2 +#define MKTME_UNINITIALIZED 3 + +extern int mktme_status; + #ifdef CONFIG_X86_INTEL_MKTME extern phys_addr_t mktme_keyid_mask; extern int mktme_nr_keyids; extern int mktme_keyid_shift; +void mktme_disable(void); + #define prep_encrypted_page prep_encrypted_page void prep_encrypted_page(struct page *page, int order, int keyid, bool zero); @@ -28,6 +38,8 @@ extern struct page_ext_operations page_mktme_ops; #define page_keyid page_keyid int page_keyid(const struct page *page); +void mktme_disable(void); + #else #define mktme_keyid_mask ((phys_addr_t)0) #define mktme_nr_keyids 0 diff --git a/arch/x86/kernel/cpu/intel.c b/arch/x86/kernel/cpu/intel.c index efc9e9fc47d4..fb58776513e6 100644 --- a/arch/x86/kernel/cpu/intel.c +++ b/arch/x86/kernel/cpu/intel.c @@ -508,11 +508,7 @@ static void detect_vmx_virtcap(struct cpuinfo_x86 *c) #define TME_ACTIVATE_CRYPTO_ALGS(x) ((x >> 48) & 0xffff) /* Bits 63:48 */ #define TME_ACTIVATE_CRYPTO_AES_XTS_128 1 -/* Values for mktme_status (SW only construct) */ -#define MKTME_ENABLED 0 -#define MKTME_DISABLED 1 -#define MKTME_UNINITIALIZED 2 -static int mktme_status = MKTME_UNINITIALIZED; +int mktme_status __ro_after_init = MKTME_UNINITIALIZED; static void detect_tme(struct cpuinfo_x86 *c) { @@ -568,11 +564,11 @@ static void detect_tme(struct cpuinfo_x86 *c) if (mktme_status == MKTME_UNINITIALIZED) { /* MKTME is usable */ - mktme_status = MKTME_ENABLED; + mktme_status = MKTME_ENUMERATED; } #ifdef CONFIG_X86_INTEL_MKTME - if (mktme_status == MKTME_ENABLED && nr_keyids) { + if (mktme_status == MKTME_ENUMERATED && nr_keyids) { mktme_nr_keyids = nr_keyids; mktme_keyid_shift = c->x86_phys_bits - keyid_bits; @@ -591,10 +587,7 @@ static void detect_tme(struct cpuinfo_x86 *c) * Maybe needed if there's inconsistent configuation * between CPUs. */ - physical_mask = (1ULL << __PHYSICAL_MASK_SHIFT) - 1; - mktme_keyid_mask = 0; - mktme_keyid_shift = 0; - mktme_nr_keyids = 0; + mktme_disable(); } #endif diff --git a/arch/x86/mm/mktme.c b/arch/x86/mm/mktme.c index 1821b87abb2f..43a44f0f2a2d 100644 --- a/arch/x86/mm/mktme.c +++ b/arch/x86/mm/mktme.c @@ -6,6 +6,15 @@ phys_addr_t mktme_keyid_mask; int mktme_nr_keyids; int mktme_keyid_shift; +void mktme_disable(void) +{ + physical_mask = (1ULL << __PHYSICAL_MASK_SHIFT) - 1; + mktme_keyid_mask = 0; + mktme_keyid_shift = 0; + mktme_nr_keyids = 0; + mktme_status = MKTME_DISABLED; +} + int page_keyid(const struct page *page) { if (mktme_status != MKTME_ENABLED)