Received: by 10.223.176.5 with SMTP id f5csp750379wra; Wed, 7 Feb 2018 07:00:40 -0800 (PST) X-Google-Smtp-Source: AH8x226riQqkKM5yCpWwhE7Gomt/QSzGXdkaexHayopyBG3mZbmHB66y+TOmvDDhnbUWrQ4SBbZX X-Received: by 10.98.26.143 with SMTP id a137mr6413784pfa.100.1518015640008; Wed, 07 Feb 2018 07:00:40 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1518015639; cv=none; d=google.com; s=arc-20160816; b=c9cvB6YrJur9XiN0FMBNjVUaeIami2PM69p2LGfgAKuYFokiKSHOF88Fb1SsijqQhF qQwHXzkxfP2FLcRU46D1VTf/FbWDOPnChh6Xv+xS41aJNKxtoVCHa0v4mJm3zwvqYof/ Ok+6cp9FlXJrLJev2cy/Rqs/I66+LuMzz4hXcCOwI0hUwZseW5bduygS/nm0qgsK/eLQ q6igR9kXBHLva4TYQ7Mkcpm8z8hS90pbET0IGt7PuY0HoV5ksDdXK3oZewRDgxCJ1Gyn Jz2LHwl0Ccx1o3RIKcv7ttwUqVs5/CPzepKI6fWduXcUiepkqPd//LGWFoo8vC2H07/A Ru0A== 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=ImEb4iVq98UAsfF+eyKA1VU/lLycXTkB6q8TnO1m+QM=; b=bmwxwiugEfWUHDtnK1iO2OFw3TjMLXbVZei3FuIrgHiBu9AeYHaeI+94qNR12AYlX/ YrYdJdXMjDm1zGBsKoVGsN+FGd6VPMwJEObl8tKxFiXu1dZkOjbcrvh1+9aSVs3nZsKh 2VAJrJ8wEmGzkkgZQnJK+yumY1o9+BdLs4qIbi84TMlqO0RbJb9qdcOmo5Sa3kB2zEnb PbzwJbnRzd5tWjWaW6xadxEjvyLlZ53tI97/AilwKszxoXA+AqtMr90ZRWlOweWezRmN aAI8SjPQ8Ay/mx0E8EffQT07a888RK5U/A8Qi8UCGlcnpZMR+fmmpqkScF3p7Fh+eUVa 7SeQ== 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 g66si1239069pfa.84.2018.02.07.07.00.25; Wed, 07 Feb 2018 07:00:39 -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 S1754509AbeBGO7c (ORCPT + 99 others); Wed, 7 Feb 2018 09:59:32 -0500 Received: from mga03.intel.com ([134.134.136.65]:6211 "EHLO mga03.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754151AbeBGO72 (ORCPT ); Wed, 7 Feb 2018 09:59:28 -0500 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by orsmga103.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 07 Feb 2018 06:59:28 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.46,473,1511856000"; d="scan'208";a="28890326" Received: from black.fi.intel.com ([10.237.72.28]) by fmsmga001.fm.intel.com with ESMTP; 07 Feb 2018 06:59:24 -0800 Received: by black.fi.intel.com (Postfix, from userid 1000) id B3C336C9; Wed, 7 Feb 2018 16:59:24 +0200 (EET) From: "Kirill A. Shutemov" To: Linus Torvalds , x86@kernel.org, Tom Lendacky , Peter Zijlstra Cc: Dave Hansen , Andy Lutomirski , Borislav Petkov , linux-mm@kvack.org, linux-kernel@vger.kernel.org, "Kirill A. Shutemov" Subject: [RFC 3/3] x86/mm/encrypt: Convert sme_me_mask to patchable constant Date: Wed, 7 Feb 2018 17:59:13 +0300 Message-Id: <20180207145913.2703-4-kirill.shutemov@linux.intel.com> X-Mailer: git-send-email 2.15.1 In-Reply-To: <20180207145913.2703-1-kirill.shutemov@linux.intel.com> References: <20180207145913.2703-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 We only change sme_me_mask very early in boot. It may be a candidate for conversion to patchable constant. Signed-off-by: Kirill A. Shutemov --- arch/x86/include/asm/mem_encrypt.h | 5 ++++- arch/x86/kernel/patchable_const.c | 2 ++ arch/x86/mm/mem_encrypt.c | 15 ++++----------- 3 files changed, 10 insertions(+), 12 deletions(-) diff --git a/arch/x86/include/asm/mem_encrypt.h b/arch/x86/include/asm/mem_encrypt.h index 22c5f3e6f820..4131ddf262f3 100644 --- a/arch/x86/include/asm/mem_encrypt.h +++ b/arch/x86/include/asm/mem_encrypt.h @@ -18,10 +18,13 @@ #include #include +#include #ifdef CONFIG_AMD_MEM_ENCRYPT -extern u64 sme_me_mask; +#define sme_me_mask_DEFAULT 0 +DECLARE_PATCHABLE_CONST_U64(sme_me_mask); +#define sme_me_mask sme_me_mask_READ() void sme_encrypt_execute(unsigned long encrypted_kernel_vaddr, unsigned long decrypted_kernel_vaddr, diff --git a/arch/x86/kernel/patchable_const.c b/arch/x86/kernel/patchable_const.c index 8d48c4c101ca..1bf2980d91b4 100644 --- a/arch/x86/kernel/patchable_const.c +++ b/arch/x86/kernel/patchable_const.c @@ -90,11 +90,13 @@ int patch_const_u64(unsigned long **start, unsigned long **stop, } PATCHABLE_CONST_U64(__PHYSICAL_MASK); +PATCHABLE_CONST_U64(sme_me_mask); #ifdef CONFIG_MODULES /* Add an entry for a constant here if it expected to be seen in the modules */ static const struct const_u64_table const_u64_table[] = { {"__PHYSICAL_MASK", __PHYSICAL_MASK_DEFAULT, &__PHYSICAL_MASK_CURRENT}, + {"sme_me_mask", sme_me_mask_DEFAULT, &sme_me_mask_CURRENT}, }; __init_or_module __nostackprotector diff --git a/arch/x86/mm/mem_encrypt.c b/arch/x86/mm/mem_encrypt.c index 5135b59ce6a5..c93b5c5eeccf 100644 --- a/arch/x86/mm/mem_encrypt.c +++ b/arch/x86/mm/mem_encrypt.c @@ -36,13 +36,6 @@ static char sme_cmdline_arg[] __initdata = "mem_encrypt"; static char sme_cmdline_on[] __initdata = "on"; static char sme_cmdline_off[] __initdata = "off"; -/* - * Since SME related variables are set early in the boot process they must - * reside in the .data section so as not to be zeroed out when the .bss - * section is later cleared. - */ -u64 sme_me_mask __section(.data) = 0; -EXPORT_SYMBOL(sme_me_mask); DEFINE_STATIC_KEY_FALSE(sev_enable_key); EXPORT_SYMBOL_GPL(sev_enable_key); @@ -997,7 +990,7 @@ void __init __nostackprotector sme_enable(struct boot_params *bp) return; /* SEV state cannot be controlled by a command line option */ - sme_me_mask = me_mask; + sme_me_mask_SET(me_mask); sev_enabled = true; return; } @@ -1028,11 +1021,11 @@ void __init __nostackprotector sme_enable(struct boot_params *bp) cmdline_find_option(cmdline_ptr, cmdline_arg, buffer, sizeof(buffer)); if (!strncmp(buffer, cmdline_on, sizeof(buffer))) - sme_me_mask = me_mask; + sme_me_mask_SET(me_mask); else if (!strncmp(buffer, cmdline_off, sizeof(buffer))) - sme_me_mask = 0; + sme_me_mask_SET(0); else - sme_me_mask = active_by_default ? me_mask : 0; + sme_me_mask_SET(active_by_default ? me_mask : 0); if (__PHYSICAL_MASK_SET(__PHYSICAL_MASK & ~sme_me_mask)) { /* Can we handle it? */ -- 2.15.1