From patchwork Tue Apr 18 21:17:27 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Lendacky X-Patchwork-Id: 9686345 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 924A8602C2 for ; Tue, 18 Apr 2017 21:17:50 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 82D0126E4D for ; Tue, 18 Apr 2017 21:17:50 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7627427816; Tue, 18 Apr 2017 21:17:50 +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=-6.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D5F3126E4D for ; Tue, 18 Apr 2017 21:17:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1757938AbdDRVRr (ORCPT ); Tue, 18 Apr 2017 17:17:47 -0400 Received: from mail-bn3nam01on0047.outbound.protection.outlook.com ([104.47.33.47]:56736 "EHLO NAM01-BN3-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1756856AbdDRVRe (ORCPT ); Tue, 18 Apr 2017 17:17:34 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amdcloud.onmicrosoft.com; s=selector1-amd-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=Ck9q3tbI9Mi70tQeghAN87IfEZzuKrMIUZLQdAxzJKc=; b=3Nyf6Q4bIL2U+rBXBxgxzJh2V+4XGpsfcrQQsJTifTHJss4FPBLWYT+iYcaBv6j9PbueJ0eb+cviMAd6dQwxkPHkPcbq+HqM52M5VMhqMJ1jOZY7BeuiPM3p/WxO7fZMJxh1XwX0fLcsEIpSe2M/8AIbqd4e46FB9tJEUxvqk+o= Authentication-Results: vger.kernel.org; dkim=none (message not signed) header.d=none; vger.kernel.org; dmarc=none action=none header.from=amd.com; Received: from tlendack-t1.amdoffice.net (165.204.77.1) by DM5PR12MB1146.namprd12.prod.outlook.com (10.168.236.141) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1034.10; Tue, 18 Apr 2017 21:17:29 +0000 From: Tom Lendacky Subject: [PATCH v5 06/32] x86/mm: Add Secure Memory Encryption (SME) support To: , , , , , , , , , CC: Rik van Riel , Radim =?utf-8?b?S3LEjW3DocWZ?= , Toshimitsu Kani , Arnd Bergmann , Jonathan Corbet , Matt Fleming , "Michael S. Tsirkin" , Joerg Roedel , Konrad Rzeszutek Wilk , Paolo Bonzini , Larry Woodman , Brijesh Singh , Ingo Molnar , Borislav Petkov , Andy Lutomirski , "H. Peter Anvin" , Andrey Ryabinin , Alexander Potapenko , Dave Young , Thomas Gleixner , Dmitry Vyukov Date: Tue, 18 Apr 2017 16:17:27 -0500 Message-ID: <20170418211727.10190.18774.stgit@tlendack-t1.amdoffice.net> In-Reply-To: <20170418211612.10190.82788.stgit@tlendack-t1.amdoffice.net> References: <20170418211612.10190.82788.stgit@tlendack-t1.amdoffice.net> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 X-Originating-IP: [165.204.77.1] X-ClientProxiedBy: DM5PR20CA0034.namprd20.prod.outlook.com (10.171.161.148) To DM5PR12MB1146.namprd12.prod.outlook.com (10.168.236.141) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 6712002a-1bfe-4c95-a457-08d486a052a9 X-MS-Office365-Filtering-HT: Tenant X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(22001)(48565401081)(201703131423075)(201703031133081); SRVR:DM5PR12MB1146; X-Microsoft-Exchange-Diagnostics: 1; DM5PR12MB1146; 3:If618BXKCpdPBajsO9T40hLvrpYk8h2L6etNcszIBc4/U112BWyd7ioBvn2KKE2J6hLfNXqPg5hri2NXwEw9zhso/tVHhoIEmO2GNN6oQ9TVavxjL7J/g/OpfMo7nh0o43/lm+wvzIWMYL91iO9LFYFuIvexE4kIh9W3Adr1f4DeDasl6QtqQ1DVnZW8NJUOgHloojDxadzzZ5gxwE/cqyU/UF15+sex70/tDzl+FRgYnD+ukialFvQW8YPyhZEKHs6v2I60qU0zQpmOpj1e6+s+q6w3yCoV6YsE189M772OTJBcM8IXvsmcteiw1jqOGc6SwAl03vmLPUcWrQXq3eWsKCW/zVjUT4Gceabz3To=; 25:i5F/P+0/NzleAmSiYB8lVtQGH39H+0HPuSQ48Q6DWdKZD8IKiKwW0eApQTYSc0Yc2EYAy/3ODf/8/OfYo+MgHjukGDj9kflmZayjC4PfWvIqrs+hUeqTuUcKYQ8CjcX84qPStFflGRQ49GU9+tZ1wHHjQvetTteaW+vBz5qYdyTprUzIVY6ou9+o/GAtWAGiOIT6bxH/Xtq8BCpc7zmRUv6JgG+HmqKAAeixUWAa5XFPA/Zr+leKYsamtvoPNplLDpUkaEaAwrhlsHggRkCryMY2t1RHT8d20PKZzQdJxMB/NT7xhudyb0yi8IhWcfkVS7QSz5g+x3AFHznx046HqDYWgiQWKCPP0o9/MiUZnDIaZXKSpcapqTWPaCRZTKnzIibnBRWC+9aXSOSjaDIaPkLL0vgIDj0hiJApyICE9gF6SDtDwjHq5QofZRLdARJ1AdUoL0rNUzsO+cbxTBeXVw== X-Microsoft-Exchange-Diagnostics: 1; DM5PR12MB1146; 31:LrwiB1mp09qjPhMvitp46D/gl11GOWqbvYD6ryRE3UDjzsQAsChU4dM80IikVpewnQ5Fb1KGAgbudHOYR01aE4DcFT73/0afzIb8hRWabKiChR7YBos4kw7pScnyod6Yc6hYbcWIe0dbl4WRZSa+PVRFMVw2pLHSGRAimW/cIzqsHP3YaaXwvZcYN0WXJZ+cbjoA7YyMSeBxi4YJTvZMB8XOspQqvSI6D7geS/jwE20=; 20:p3phfOpkj8JZqKMljYUowSHyXZ4I0e+YGkrmqtInCQk9KNguYKrQqShhFnwo+FRrFHh4+1udDDVeRkzkkLBs196wbf2fiTsK0A9Kky0lIirLmMAn3N70aObcsLbjD7J++DiArEKu41vbFNmoaop32axzMNaCfzEt8OU+eH2kpVQczzWtRFQWBlGdlCAa1x4rbXCfzN4NJoxDIXikXGeg+ADEF9+XOHNIHLSS4BF1dnH6IcH8DM0NMdA0LUdnQ2b4ksYop0hoX3QUrzGMA5yec43/WIZLrfI6gHx5WdgYG5l78nTK4a0lSxNHfR+Lyi5sG219JcHRHMo5Yi2Hmajz4UB9+VmEx/SUmm6X4aSfWuvlWLaM8oRaoTfxiMSm68ppV1bUCPxy+37XY5yTo/nSczoQFC0wwNNrULn8rUXmnjUmzCbtBLiRTxqlLb+AoWJCxJoAPOL4N3R3YmBFbYR7EiKAnIEjSQvFasxDxYBRt1EKPSXM0S1C2Qch1O65KviN X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(767451399110); X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(6040450)(601004)(2401047)(5005006)(8121501046)(93006095)(93001095)(3002001)(10201501046)(6055026)(6041248)(20161123560025)(20161123564025)(201703131423075)(201702281528075)(201703061421075)(20161123555025)(20161123562025)(6072148); SRVR:DM5PR12MB1146; BCL:0; PCL:0; RULEID:; SRVR:DM5PR12MB1146; X-Microsoft-Exchange-Diagnostics: 1; DM5PR12MB1146; 4:Jpj+HDkxg/qo58WKOmpmsodlKPIbS145W2pQBRVnk0VEj6wyUFfRXBInGOOEeaRDkeDK/g4YQB2ZEUqUGZvWkhIKIeDfDNjV26YexDyLp/13rgmb3+Q+EAQSv1qTN8jN/I4oUdkJiPAvZfj8UjqpOgOpa/An8mMyHABUNz1w8dx0Oao535vxgBAnk5CLbq6OLccJkvQQcHbXWTvtLVexGswF1sQsVhto37xqxJCY3FehxG8jENy4onwyTZunR+9xkeIo9tfuj8xQGx9i+EERQZgwFkOvkbQzQd0cig6cBuU5fsXAz1EHyoC8QqKriMW33fJ4bzeNl7gw5zsxsmOdfYhwcXXWWGdRxa2LeMyG+P/oJyBIjYQ2S7YBMAZQQOS2F4EoIQ5nLEoTjg/ZcRRwlSEQ8jKxkac+45m7wkrj09TQGwFSC9Imb7ud7LdeQttN28Xy/bq6SWYjBRvIGNQd/vqDvCyNTS55DIwd+zwRDw0TRnh5WuM2Gn7vBqBHHLE2NgJUCxx+6t/rCqRsrP6cxEV6SZoh3geiFbfTnCT7yU0MoDxGQ56UdvbM3p/0tfZ/EUwuGhHqZQZnBeKFk4mlQbvabj194/QfbLFHeCXIiJhSmwZOgM515uCEWD2rr+iT9zrjW58GnFN3Zh6Iu62B7jbFjvdFHbKEd1NEKhCPfJpoyXZgwySAsLTZ1zl13d+biXWE8ZEPVFVvR/9dHQqST9qr/IelCipweVCGd+qWgnRoPgCwCKWZ+cyPLLy98Yjx+GcBy9tGFubslLkc9S9PRA== X-Forefront-PRVS: 028166BF91 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(4630300001)(6009001)(39410400002)(39450400003)(39860400002)(39400400002)(39840400002)(39850400002)(97746001)(23676002)(47776003)(2906002)(1076002)(7416002)(189998001)(9686003)(54906002)(6506006)(7736002)(305945005)(76176999)(2201001)(54356999)(55016002)(4001350100001)(53936002)(50986999)(575784001)(86362001)(7406005)(66066001)(8676002)(3846002)(25786009)(50466002)(5660300001)(4326008)(6116002)(83506001)(230700001)(2950100002)(81166006)(53416004)(103116003)(38730400002)(69596002)(81156014)(33646002)(42186005)(2004002)(921003)(71626007)(1121003)(309714004); DIR:OUT; SFP:1101; SCL:1; SRVR:DM5PR12MB1146; H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rSEpNMFBDZVpsdXRQcGdmNHFpNTh4SnBY?= =?utf-8?B?N1kxeGxlMnJ1c3MzY3RhMm9FQ3hnOHdzUWVNWWRtMGNaaTZFbjJFZEtHaHN4?= =?utf-8?Q?eY+jrSVO3wiPI?= X-Microsoft-Exchange-Diagnostics: 1; DM5PR12MB1146; 6:P4IITwiSNI3fFaZugREjzoS28/PPyA14DgfywEgjA0xDvhMp8is8ATOifeInUnyjBjj3NmRLHwB3vK845WAib3XC+qgvrUiNegARR5VOQc6E2QPdc7COBJJRjuMsIGY4oJee0dRPton63C7tRGml8apOWg0dz5TYfleDAOwS8TlNnqecvNx/19kcwko2x2lMyCsrPApapUxZKz3U0zGmNpeoJtibSGoe4KRBM5cZHencnrRPEohq2S7M/oe2TmgGvmewoZFrLV+Uzg2x3xAgeL5SBOV+Dd1Z6ILMT+p/2ZJ/IjSNMOGX0XODvnjGdqvH1XleZFiveXmcPCpd+IKHs3HssuF3VKZ1dgCn+uIhgdSAjes62M3tKjTIxDFqj0fmAemdTtjoOMcHP0c1byAc0jiFr/tCVg/JaBdWkPI/dVpWopmdMLWaMkP6qukN3U4kfykxB/EeKE/uRqCMh3N2dSwwWHkR/9PKxjXLobMKLQtKnaV0mHt5lh0BCvTb5EGgcvflBg7tC2LjzN2KHlNhxDH6RvIfRcjOjPshUnGKnxg=; 5:yqr+M1aRASkKzzB8BxzEDkICmqoycZL/kXcEkuNIiphZfIaCTy/ksZLUdik4g0R/xiIvKzBAcywQ6Bddp2ym0Df/ODe4TdR3f1jiNvoy7xrHvS9QYkPTGJtbko0YFNxIGtuSt99zb6F5jOh0DVjfaw==; 24:mrkwRu7osj5bmkHNN3Nva/hfw8HAwBxz9gDjhKSmyjfIh3uvv0RTO2O1bcrvSwrfR41b0qk+D/jiOc5G6AK4AH1xy1UJhcNr+V+0SRU3rXI= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; DM5PR12MB1146; 7:hhrO5raZNlOBGFGgwulkKKb+oAELCv4g8sgYj2rf7cq7sLn9TGsL50KzP3JOqutHuswZ/F2FHM9Mt6OgGJIZ47uLyyGHJm2liiHvBVV4EQtsQAqu/lVcUuipGMiTo1NhXQ+plk+hRQsu4QetN7rDHI1p3ln5+pC8q2fEYwlIDtPvAVDva56XuyrQbdR/Sl955gfnP7l7jb+tJchelI5BxZgSCHu6IKw2jzc7Hp1pekngVZtEXt7RbBTHyIAc7UqwZm1iCFcxvJD+Wq657nJdwIrweCi/UVGEwNQQv7qgQO8wBbRAXGqQvBQ0QdWBj/ICMZzfiq+MIIQO1E9VmVWjoQ==; 20:B2VRvmvP3/UZVjPTacp5YsWMxX9JaEsyXT3PGejEs60cNFsXDzEZcQPyhNVcj7zh/9ysV+byK9eU36YjdEMPfIoqbW/fC1pC0OKZgnwdjEKIY3R45SBIbUGq9R42iXU0ktZ4RHr2IiDsFMrcMVp/Wq5iM/MCSohL1xB2dJmZQpRYRjPe9VLiQIUF2jtfHIuurzmaTHFsWp9WPH/LWfRcDUT0o9fh4cI0ZN5RHd6A1c7mL6msjtgRyuuZhLR0JLMx X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 18 Apr 2017 21:17:29.5332 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR12MB1146 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Add support for Secure Memory Encryption (SME). This initial support provides a Kconfig entry to build the SME support into the kernel and defines the memory encryption mask that will be used in subsequent patches to mark pages as encrypted. Signed-off-by: Tom Lendacky --- arch/x86/Kconfig | 22 +++++++++++++++++++ arch/x86/include/asm/mem_encrypt.h | 42 ++++++++++++++++++++++++++++++++++++ arch/x86/mm/Makefile | 1 + arch/x86/mm/mem_encrypt.c | 21 ++++++++++++++++++ include/linux/mem_encrypt.h | 37 ++++++++++++++++++++++++++++++++ 5 files changed, 123 insertions(+) create mode 100644 arch/x86/include/asm/mem_encrypt.h create mode 100644 arch/x86/mm/mem_encrypt.c create mode 100644 include/linux/mem_encrypt.h diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig index 4e153e9..cf0cbe8 100644 --- a/arch/x86/Kconfig +++ b/arch/x86/Kconfig @@ -1407,6 +1407,28 @@ config X86_DIRECT_GBPAGES supports them), so don't confuse the user by printing that we have them enabled. +config AMD_MEM_ENCRYPT + bool "AMD Secure Memory Encryption (SME) support" + depends on X86_64 && CPU_SUP_AMD + ---help--- + Say yes to enable support for the encryption of system memory. + This requires an AMD processor that supports Secure Memory + Encryption (SME). + +config AMD_MEM_ENCRYPT_ACTIVE_BY_DEFAULT + bool "Activate AMD Secure Memory Encryption (SME) by default" + default y + depends on AMD_MEM_ENCRYPT + ---help--- + Say yes to have system memory encrypted by default if running on + an AMD processor that supports Secure Memory Encryption (SME). + + If set to Y, then the encryption of system memory can be + deactivated with the mem_encrypt=off command line option. + + If set to N, then the encryption of system memory can be + activated with the mem_encrypt=on command line option. + # Common NUMA Features config NUMA bool "Numa Memory Allocation and Scheduler Support" diff --git a/arch/x86/include/asm/mem_encrypt.h b/arch/x86/include/asm/mem_encrypt.h new file mode 100644 index 0000000..d5c4a2b --- /dev/null +++ b/arch/x86/include/asm/mem_encrypt.h @@ -0,0 +1,42 @@ +/* + * AMD Memory Encryption Support + * + * Copyright (C) 2016 Advanced Micro Devices, Inc. + * + * Author: Tom Lendacky + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + */ + +#ifndef __X86_MEM_ENCRYPT_H__ +#define __X86_MEM_ENCRYPT_H__ + +#ifndef __ASSEMBLY__ + +#ifdef CONFIG_AMD_MEM_ENCRYPT + +extern unsigned long sme_me_mask; + +static inline bool sme_active(void) +{ + return !!sme_me_mask; +} + +#else /* !CONFIG_AMD_MEM_ENCRYPT */ + +#ifndef sme_me_mask +#define sme_me_mask 0UL + +static inline bool sme_active(void) +{ + return false; +} +#endif + +#endif /* CONFIG_AMD_MEM_ENCRYPT */ + +#endif /* __ASSEMBLY__ */ + +#endif /* __X86_MEM_ENCRYPT_H__ */ diff --git a/arch/x86/mm/Makefile b/arch/x86/mm/Makefile index 0fbdcb6..a94a7b6 100644 --- a/arch/x86/mm/Makefile +++ b/arch/x86/mm/Makefile @@ -39,3 +39,4 @@ obj-$(CONFIG_X86_INTEL_MPX) += mpx.o obj-$(CONFIG_X86_INTEL_MEMORY_PROTECTION_KEYS) += pkeys.o obj-$(CONFIG_RANDOMIZE_MEMORY) += kaslr.o +obj-$(CONFIG_AMD_MEM_ENCRYPT) += mem_encrypt.o diff --git a/arch/x86/mm/mem_encrypt.c b/arch/x86/mm/mem_encrypt.c new file mode 100644 index 0000000..b99d469 --- /dev/null +++ b/arch/x86/mm/mem_encrypt.c @@ -0,0 +1,21 @@ +/* + * AMD Memory Encryption Support + * + * Copyright (C) 2016 Advanced Micro Devices, Inc. + * + * Author: Tom Lendacky + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + */ + +#include + +/* + * 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. + */ +unsigned long sme_me_mask __section(.data) = 0; +EXPORT_SYMBOL_GPL(sme_me_mask); diff --git a/include/linux/mem_encrypt.h b/include/linux/mem_encrypt.h new file mode 100644 index 0000000..14a7b9f --- /dev/null +++ b/include/linux/mem_encrypt.h @@ -0,0 +1,37 @@ +/* + * AMD Memory Encryption Support + * + * Copyright (C) 2016 Advanced Micro Devices, Inc. + * + * Author: Tom Lendacky + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + */ + +#ifndef __MEM_ENCRYPT_H__ +#define __MEM_ENCRYPT_H__ + +#ifndef __ASSEMBLY__ + +#ifdef CONFIG_AMD_MEM_ENCRYPT + +#include + +#else /* !CONFIG_AMD_MEM_ENCRYPT */ + +#ifndef sme_me_mask +#define sme_me_mask 0UL + +static inline bool sme_active(void) +{ + return false; +} +#endif + +#endif /* CONFIG_AMD_MEM_ENCRYPT */ + +#endif /* __ASSEMBLY__ */ + +#endif /* __MEM_ENCRYPT_H__ */