From patchwork Tue Apr 18 21:15:04 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Lendacky X-Patchwork-Id: 9686327 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 CA6DE602C2 for ; Tue, 18 Apr 2017 21:15:58 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BB77E201BC for ; Tue, 18 Apr 2017 21:15:58 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id AF58D2582C; Tue, 18 Apr 2017 21:15:58 +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=unavailable 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 2EE6C201BC for ; Tue, 18 Apr 2017 21:15:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1757218AbdDRVPY (ORCPT ); Tue, 18 Apr 2017 17:15:24 -0400 Received: from mail-dm3nam03on0076.outbound.protection.outlook.com ([104.47.41.76]:12475 "EHLO NAM03-DM3-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1753360AbdDRVPQ (ORCPT ); Tue, 18 Apr 2017 17:15:16 -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=xmOnCb2yfjkydeNTDSpv8ZTed6Ru+cPoBzsTbu8VNOWptDdhgR/7/TpcvukJ9+7btnRBTDyEadLnXxlqVaMXnkIztyQumUAAQimUrHhWlg+qquYVxpB9a/9VbQw6VMlE0WOhGnKHpvrC1g3dlIcyYSbYLlZOg8uNf6OxII8RRTs= 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 CY4PR12MB1141.namprd12.prod.outlook.com (10.168.163.149) 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:15:07 +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:15:04 -0500 Message-ID: <20170418211504.9689.12900.stgit@tlendack-t1.amdoffice.net> In-Reply-To: <20170418211400.9689.10175.stgit@tlendack-t1.amdoffice.net> References: <20170418211400.9689.10175.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: CY4PR19CA0041.namprd19.prod.outlook.com (10.172.173.155) To CY4PR12MB1141.namprd12.prod.outlook.com (10.168.163.149) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: aa7150bf-2053-42c2-976f-08d4869ffe47 X-MS-Office365-Filtering-HT: Tenant X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(22001)(48565401081)(201703131423075)(201703031133081); SRVR:CY4PR12MB1141; X-Microsoft-Exchange-Diagnostics: 1; CY4PR12MB1141; 3:JRMgTBAh7ldQhP1XAbkeJ4qzQqe8ILZnUabVsQFv9VplX6/3vxuA9wXOpsikj13CYLlFi1K/Ht1hjkTPIzDpr939WlB8ccEiGvcEAzggDi/0xb9C841v3yYYqoEqs3JInABE1tUViIIi3pv5Z6xgoZNQa0fsaJSplYrMnF9FcZJq1tN3FPtc0e2zF+2CDkrV6SnyTugh7MfvWBcsp9AA7VIeaT7XNbhUyVs88EDIbnUMVJUiI/OvjlO5fEOOo9HR/wC6xaBFxwfGJCyD9RRkzZj+/xYtDdfu5LHCwuaRg3IZrNUbr4cAUpa3m/MECJMMjKaLF9nMkI71SB4m7gLshlACLFVeEy2C9nxsui2pPZY=; 25:+b9HROU/pErLQFhWIAg92j+7kdYArS8UNJ+dcgJAF85FxZD/mz0Pu+vMECG+y8Hr79bXGIE3hCaNj7T6EO75ukPGMWJDZn2ePKnScm+s3NFAuptSRDj+gg1kArzr/Gqonb7ABcpFY7nuqoc2r8F34nVZwc/U7FbxHDPJLfFcVl38/LYLrWEuxq1CpSXoCiXTpl7JvkDTUWjctP21M67tPp/fFJOWiw9LYVI4c4lfyEwYzh6xt7vzqjlPNJeGsrtUyT3uxHwTeQX8qMuFVVTz+ypfNRAGup2yn1M1SGzFgWOWNiD6zB8Iv4bWnyMdCXP1KpdbqYRWf0Bl2hyPnVRUo0CCgB6gVV77qHHlzHggwSupv3KQClZ0eGpAFv0X+p0+OVFrEYwXO4OW5B9rzYN+ANMq1iIhXBrW+D/9LrdUj6vXG/sU8rNEDeLthW/l2UP4At9d7v9BpN8134h87GCbWA== X-Microsoft-Exchange-Diagnostics: 1; CY4PR12MB1141; 31:Km6fPmr9mxe70e3D/XhyJr5KzF1p77t8bk7ZgM8fS/h+hKPTuwKimAQybsMsVio7Wgdv7nidlrDSpyAlJyACMQg+UgpXrV2h2Yb7F19OrczwD7+uoXoajb7uTyfOJo+26wpP/xyS0BwpHRWhV+cgnjkQayJcUzHvMN4t87Nho53YcfCwnTl8z+BUkJH36ePKqAElyx5HdescIpKYE3V0nmGEhoMnGjMVXcA1G4dcjNQ=; 20:6ezEQJVuNXLX4rg6jaCAZnzdntS8yog9zY3IVdKJ13AQw2pPaArlWdEV7hBXR2VtcC/HRLLTqwVnhJBNhhzLcShyDRwCeULd1h3dSIrzULxopZ8z0roIwu/STPqJPIAYnfLDvFLqWdmu0VRiq1HK/WddomEAGl3fan7axjYmPfPo2rNnu6Cwhq8DMeNh7NMHXPUTEogbee4ndpSozFOJ1lJRC/eTZRxJO4JQYfyiQHE8V7LHhivzj6QJIpMmzuQ+fhjg7T4o9LrxUNRF14d5atiS1o4Al4nXnAry5kb4K99L+gFTHYqjPbDg1V6J9tbPrZJBU8+QQ/dDqU+GDnVORIHgHvCH+Yb/MPs3ykR5H1PTUeI+L5dhWMoNo7AucxZsppH23Rk9295R1ZsMu9jpd1yp6E8MtxNj2xvVZZ1eDwR8SgDJ0HlUlJXrU0WHsezY4UTtci3IRcwmNwMgAKSi+2+AOG3ekuggn9CURKRbPQVM5q7I94yJBFOE/vRA+rD4 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)(8121501046)(5005006)(10201501046)(93006095)(93001095)(3002001)(6055026)(6041248)(20161123562025)(20161123564025)(20161123560025)(201703131423075)(201702281528075)(201703061421075)(20161123555025)(6072148); SRVR:CY4PR12MB1141; BCL:0; PCL:0; RULEID:; SRVR:CY4PR12MB1141; X-Microsoft-Exchange-Diagnostics: 1; CY4PR12MB1141; 4:+YMbFUCtTPRkMwtOifTswf9Q+ugBL/F+GPP+vVvLcfi0EqaFhW59g4N9ZrtYCkXjZDFfveTgwP8ZwEsBGtgGXdkn/xOSJwK8M147MUiY/Hn6yHfJW7He6VHxjo5aoH/b0bRqQoVkyKTbpq3LE5lMY9UCzhUaVYrvJbEPA8pDs++glknp8dFtOw0TX1ckarnRZfH7MqMW8ncY2zZYjiGjzAIk9YLLhcwfxJBXM94viKEnHQ7Ix/WjpfORlSs8Yw26b/UnsJsyVNedMq82+t+cjQ0qrGK364shzkPEVZ5FrYLl6YrsfSbMjRNk69H8MLWtdMPTFSSCIe69SCeYsR2Fz0deTdHJi4KOhPoncpVG3v+zhw44ZpiJHPMWzOf02nqsZMuznwHa2hETR/l6dhS1iji/6IYrc5wxNE5DoOKBtdbskoIeK3Poqd3WgCiupey1RiQANPFmYG9x5LHQP13sv43AN+n86G6IxDNnM8uUnu6kfBP8tXa+0VkIzeTIut8X6ijbu9Uzsz3ZWaeLcL9Vr+rBpssZGaNmGqldCKaPrCiu62lhSZV4+5z880fpbSlZosRk5HITVXYBOrKDnGFgUqAv3uCTdeLXLDH1q8NmFBZ/F1KbWBXDIY5kb1vv0QL027149OsJP4pRZ3WRwxHtiOUvRJ2iPsW/m10hKW2MH3JmTri5kJ+1YvFsa+UIAvVWxHSESfb4Y7Fp6Esv6dLM3WRxH0EJqKLE+YmeoT0ydwxJtZ9aALNXR2dePO+fhOJznfJiw8qtEvLxYMQCUa5kow== X-Forefront-PRVS: 028166BF91 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(4630300001)(6009001)(39450400003)(39860400002)(39850400002)(39840400002)(39400400002)(39410400002)(42186005)(3846002)(305945005)(25786009)(7406005)(50466002)(7736002)(38730400002)(2906002)(4001350100001)(575784001)(230700001)(53416004)(86362001)(2950100002)(5660300001)(103116003)(23676002)(6116002)(7416002)(2201001)(33646002)(1076002)(50986999)(54356999)(81156014)(81166006)(6666003)(69596002)(55016002)(76176999)(97746001)(83506001)(66066001)(189998001)(9686003)(4326008)(6506006)(47776003)(53936002)(54906002)(8676002)(921003)(71626007)(2004002)(1121003)(309714004); DIR:OUT; S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mV3BZa3pHUEI1VmljWFFJb2tLV3JPaTJRMFl6eGptU3hmOUN0TW9weEor?= =?utf-8?B?Y2JnOEZsSUJ1T1RiY3VLdUs3TjZpTkc4Qi9XR21EdnQvRUVvQS9RaWxOVWtx?= =?utf-8?Q?Y8VYedj28zbKw?= X-Microsoft-Exchange-Diagnostics: 1; CY4PR12MB1141; 6:X8lfgxl1n6kIsuyWdiSu0NjX9LfGtIerI/PsHULtQv4ij2CMa+YOi4E2ciqfVeNeXO5oPrnS0J5M1kqV+oMofphdq2OywRXVyUKYdeKj+iajEzA7nBiC0nEoCiQPp0FHyCUi0MY0VyUhsYLD96ep9KRk9vDbAJlNVRHzVixswqO2c4zH3RZhjpFdmL0xyowwwUB7aMBF8ZIgL9wtFo3YKuwhfXS+2t7hJJJnS8UsvGW95N1S0ocfoGxDz8wOApQxiFgkyIeRcIRoxnHTiBJF5WsBlJfTWcK3YSuDY41CvFZQ0lKo+f2T9DC0fq/YVPqe7ikuhl1y4/AWfi/aF6YplZdW94SIpDGGqbGiL/3wkxpNEfgwfesc8DzBd3SLEIRmHr0LrWU0MpVebOeDzhQCI2OM2dmLLP9xzcNZcBlIteZmudyFDI7U/i1fxQx1TAiLW+L+1V7T/gDLTJ/PeQtOJOrhv8g+qqDj70XkS1XQ6zA=; 5:GzIHokeGFbKK09okUq2Q+EFXCClr/YuqcLbAvEkm8DC4RggXx6l7ZHkEfZNFVy0Qz87bY/mmIuXctBDOtc2BwSTZoZTuvKBE//a0oqgccRpZeeHi+s4sH44rgCvhfvN40jroZfDuQA0sX6/RFdWYtw==; 24:myR9mEgyPULzyxQdmeycF/VG8e6ZToA/adOazRzShPwvFCdTCKx1j5YxZKB+SKhovyht4ASQ8W1n8zjYkxiU85lO6TDx9Px4UA2McVCSbD4= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; CY4PR12MB1141; 7:ABC88/TtuTbPPE/b3peudGOuugob9wptw4fdeT719D94vgH8RpxNlRdHVHcJdksS1cS2Drq5cAvqVGVHtpfVV7haYrqlDaZnXIgCRoVLlsU6d6yeF+gfWF3mKMW0s4oG8NJGlmnADIVbOSHFCVIUkKmMCK17ucypGM7XirytexMJbe6Jle8BZo/MPTwJjfAWwuocctw4p4dg7nGsoYe+d6aC3xVLJcfJvdcfTuRduiJi3Z6X3e5a80Iw3s+puQRsqoOKPY+wFX5UVNnLuZOJVU3ug6zZkSb0Cy2KZGbnu5OGDk6kq65JcuUAShAjZwz85dwfAKhGF4at+4wgRpPGbg==; 20:LPHyrSnXvgQJptyscd+UMzUQNX9ruCqPCunZKDscXqt1NxdX2ZNyP1c93uyS2HizaLkOGlbUKZtQgqq1qGozlWR+w4IOpUXdpKqUixnh4m1G5uk7jpUDswQFFyVRlHls4ePMWWLUZj/6naRT2uR9lFqDFrbASXuHlynwYSUrzcsxQbIU05mdc4Vm5ytIRRi6wD4ZoY0b7IEqzATZH6wBfBy0cEG+cpzoL0vlMj1FH9Ml68DpNObWFOyJqMNGU51m X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 18 Apr 2017 21:15:07.8659 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY4PR12MB1141 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__ */