Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753348AbcDZW4u (ORCPT ); Tue, 26 Apr 2016 18:56:50 -0400 Received: from mail-bn1on0053.outbound.protection.outlook.com ([157.56.110.53]:12096 "EHLO na01-bn1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1753082AbcDZW4p (ORCPT ); Tue, 26 Apr 2016 18:56:45 -0400 Authentication-Results: vger.kernel.org; dkim=none (message not signed) header.d=none;vger.kernel.org; dmarc=none action=none header.from=amd.com; From: Tom Lendacky Subject: [RFC PATCH v1 03/18] x86: Secure Memory Encryption (SME) support To: , , , , , , , , CC: Radim =?utf-8?b?S3LEjW3DocWZ?= , Arnd Bergmann , Jonathan Corbet , Matt Fleming , Joerg Roedel , "Konrad Rzeszutek Wilk" , Paolo Bonzini , "Ingo Molnar" , Borislav Petkov , "H. Peter Anvin" , Andrey Ryabinin , "Alexander Potapenko" , Thomas Gleixner , "Dmitry Vyukov" Date: Tue, 26 Apr 2016 17:56:26 -0500 Message-ID: <20160426225626.13567.72425.stgit@tlendack-t1.amdoffice.net> In-Reply-To: <20160426225553.13567.19459.stgit@tlendack-t1.amdoffice.net> References: <20160426225553.13567.19459.stgit@tlendack-t1.amdoffice.net> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit X-Originating-IP: [165.204.77.1] X-ClientProxiedBy: SN1PR0701CA0040.namprd07.prod.outlook.com (10.162.96.50) To DM3PR1201MB1120.namprd12.prod.outlook.com (10.164.198.20) X-MS-Office365-Filtering-Correlation-Id: 47119975-7e69-4ee9-e52e-08d36e260175 X-Microsoft-Exchange-Diagnostics: 1;DM3PR1201MB1120;2:EksHkLyaRLv0wprqsSIFJKOL8KUI4L92X5YmsZ+/nl2zVLF+1GVqh0rQYkmXfQLVDxGaEH1su+6Jr58RdO2/KcQOIxIkPQjyBC3wqoupY2xuxIHweIs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blTM/+JAeJjjGC89cSjarEpPm2Ze4vRSv6c7ieFrITXdAcf7uaptWVYNAcbycvAWQJBjmhlLflRku+Abghr0V6buGBTI6Qhhw2yzs6R2OCDjFoun26PcLL7EUtcr42Lh3KEb056FZL+t4MieounzadEO6nI1wYnyPiZUGT+kMB6+eoMjYXA3FbEuIj/ccQMxItfGflpMNGuekUM97RCGetlibvGvDYX75Qq8RLwNWQKnh4FRD3arvh0V9hfE8ZqNtYzAolkqoU1iOh2/dqZlUZOTC+fyosSTxwKZhjvGW9NylmYNsbviDLCpvyP7blFOhH8QTGUrHt34udksFMiTqRaz0ydRgU5cJZnzJASYhllzoQSF07QXbesVA3Jhcq3SBON1j73vQ/RQ0aXqSZf07cAigvjh/cUkgyIBpddteDILKAsZXZbW4N/bJVClCqeisbnYc7U9xcLiOEdcgjVy9YF;4:nNXZXOZctDUuHyP5VS5cQkkqC7bewo8/sREeRfqScNYCSpjHWixRu+BtqgEHiO/onU9FKOfaH0+lSEkQGdUuasCBs1vd7wr8ByX/udBmSjLsKS1kGE30F9seT5YGNb5WNPmTRVgekQR5roR6s7g9nx6GyY1b1pQ5pjEq0LPCJT2MQ4GW3gT23xE89vORsqwf7kvq2zSw87pDkVWvzYpzheLS5Oi3lkXEx5oB63VDvEHdK2XdmmIUBwRH85lA+FoTOmdg3b4/eJLrmxKePO8jX+hr4AxtvvPHELRxfqcc/SipYZpdEtsHTLwPzhKOkwO57hBPx/R8PfwY65XccX+kX6t55jYOI9Ip0GW863aGrj1L2a++Qn8R6E+vrCaBz/+Cy4GVjzz8LsYfhSux6jePRU1pW/fNikr4GSeLt5rS3uc= X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-Exchange-Antispam-Report-CFA-Test: BCL:0;PCL:0;RULEID:(9101521072)(601004)(2401047)(5005006)(8121501046)(3002001)(10201501046)(6055026);SRVR:DM3PR1201MB1120;BCL:0;PCL:0;RULEID:;SRVR:DM3PR1201MB1120; X-Forefront-PRVS: 0924C6A0D5 X-Forefront-Antispam-Report: SFV:NSPM;SFS:(10009020)(4630300001)(6009001)(42186005)(97746001)(81166005)(5008740100001)(5004730100002)(66066001)(47776003)(2201001)(2950100001)(92566002)(103116003)(53416004)(19580395003)(77096005)(19580405001)(50466002)(86362001)(5001770100001)(4326007)(4001350100001)(23676002)(33646002)(230700001)(9686002)(76176999)(50986999)(189998001)(2906002)(1096002)(1076002)(6116002)(586003)(54356999)(229853001)(2004002)(71626007)(217873001);DIR:OUT;SFP:1101;SCL:1;SRVR:DM3PR1201MB1120;H:tlendack-t1.amdoffice.net;FPR:;SPF:None;MLV:sfv;LANG:en; X-Microsoft-Exchange-Diagnostics: =?utf-8?B?MTtETTNQUjEyMDFNQjExMjA7MjM6L2tqUmRybEdOTFpyWTBBbVdLNTg5c1ho?= =?utf-8?B?bWFhT2xvdWpKTDYvN1g3NGZOVzRraVEySlJlaFRmUkpvWk91MStuU29KaVVn?= =?utf-8?B?N2JZZHJTeGtTSlFEWTJRc2tRQ01iU0RtU3hjZlVJdGdkUTB6amhMVS8vVWFZ?= =?utf-8?B?TTVwbzhVbi9zekNXNEpzMnFNNlgzN3FoRVFRQjlaTXd3aVZHbTZyN09ybmNE?= =?utf-8?B?Ni84YU8rRU05ZU1idUFrSjMvbGJFNWozdG01MVRyb0FWbG9EdTQ3S2duV0xI?= =?utf-8?B?eXJzUmVKaklvUkpCNlJEVU40dkZZSytrQzBCbUt1UDZraDloUUJsR0xxSDk4?= =?utf-8?B?ZHpacUVBekJnV21xUzI5MmtsRVdBRmhxWHFFZ1UrQitNam1CWnZQclgxTWtY?= =?utf-8?B?cVFSYituRmd1RW95T3Fic1UvK2dGajY2bVU5eHdkSXNJUTNyUGgwWmJ4S1dB?= =?utf-8?B?Y0NIell6QjBzUnVaRStsRVhrRHJCdlVEWTFrOTk3bUYyOUZISk9meGxSMGxm?= =?utf-8?B?ejdFOTVhUTNJRUlEVXltRWE5eXZDYXhvNkVSTmlwQkhpN1IvZkc5L1J0a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1;DM3PR1201MB1120;5:7aueMZ2JF8lJYeNYna1gN6OheefD21Lyv34GqI1BJoqPJlB5CMRLndmMW6wBpkAxpXEjyObhqjRclKbB6qk1BV9PKg84EGMAJ2IB8k74UXQiO/0khkBGhTNtRwMejcJxfJCq2ZtlHqVd+gCFWX3SYA==;24:fvqRNo9qmgzXgTVRyPyMWXDD8W7jIuV1gE4mtGhGK5eDOG4Pe8qbDkGFuUWUUCTyOEZ3RQXoY0YZ2kz3Dpk4Qd96mfzm0WEb5vrxM2nbFUc=;7:Gm7vFlnoq7fXG5B6gGI9wiSrvs8iHtVzthkbOifBVtE1BuvTPQQaFhNgT+T7Vz2DFGZGvAXnYkq+SmpaCnLfDruEoWQH8adbQBPq/3Kw7KdKWJ3yy1s+7Iz7Mbz1low6Y2qv27M+glvxyn1TjJPuloxeaYdD+ZkgwXUCiw8YZdM=;20:YWJCPfTbZY+bqD3Zrv7UciUmlohEVrA7IuXkybtLHkCxx/sF60HA/L63Vzg/ws1HaTPS77PKx+JSA4LW8kUgwf6mfy1ZDeRBMRJaYLimgWiCVh69GsLJq7xKYvxmzl/W915pCtS1SbXMnCob1uqMlTZ7XK1B9uQlLYEOibkvl2YeyW9mV1D6YcLeGd0FSMI/6Gd9swhXNGVTxZbYPcVd+niWK4OcypFv0JeTxOwYbGLOTxaJhX/i9gdy2RAq4/Zj X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 26 Apr 2016 22:56:29.1218 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM3PR1201MB1120 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 3481 Lines: 127 Provide support for Secure Memory Encryption (SME). This initial support defines the memory encryption mask as a variable for quick access and an accessor for retrieving the number of physical addressing bits lost if SME is enabled. Signed-off-by: Tom Lendacky --- arch/x86/include/asm/mem_encrypt.h | 37 ++++++++++++++++++++++++++++++++++++ arch/x86/kernel/Makefile | 2 ++ arch/x86/kernel/mem_encrypt.S | 29 ++++++++++++++++++++++++++++ arch/x86/kernel/x8664_ksyms_64.c | 6 ++++++ 4 files changed, 74 insertions(+) create mode 100644 arch/x86/include/asm/mem_encrypt.h create mode 100644 arch/x86/kernel/mem_encrypt.S diff --git a/arch/x86/include/asm/mem_encrypt.h b/arch/x86/include/asm/mem_encrypt.h new file mode 100644 index 0000000..747fc52 --- /dev/null +++ b/arch/x86/include/asm/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 __X86_MEM_ENCRYPT_H__ +#define __X86_MEM_ENCRYPT_H__ + +#ifndef __ASSEMBLY__ + +#ifdef CONFIG_AMD_MEM_ENCRYPT + +extern unsigned long sme_me_mask; + +u8 sme_get_me_loss(void); + +#else /* !CONFIG_AMD_MEM_ENCRYPT */ + +#define sme_me_mask 0UL + +static inline u8 sme_get_me_loss(void) +{ + return 0; +} + +#endif /* CONFIG_AMD_MEM_ENCRYPT */ + +#endif /* __ASSEMBLY__ */ + +#endif /* __X86_MEM_ENCRYPT_H__ */ diff --git a/arch/x86/kernel/Makefile b/arch/x86/kernel/Makefile index 9abf855..11536d9 100644 --- a/arch/x86/kernel/Makefile +++ b/arch/x86/kernel/Makefile @@ -126,6 +126,8 @@ obj-$(CONFIG_EFI) += sysfb_efi.o obj-$(CONFIG_PERF_EVENTS) += perf_regs.o obj-$(CONFIG_TRACING) += tracepoint.o +obj-y += mem_encrypt.o + ### # 64 bit specific files ifeq ($(CONFIG_X86_64),y) diff --git a/arch/x86/kernel/mem_encrypt.S b/arch/x86/kernel/mem_encrypt.S new file mode 100644 index 0000000..ef7f325 --- /dev/null +++ b/arch/x86/kernel/mem_encrypt.S @@ -0,0 +1,29 @@ +/* + * 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 + + .text + .code64 +ENTRY(sme_get_me_loss) + xor %rax, %rax + mov sme_me_loss(%rip), %al + ret +ENDPROC(sme_get_me_loss) + + .data + .align 16 +ENTRY(sme_me_mask) + .quad 0x0000000000000000 +sme_me_loss: + .byte 0x00 + .align 8 diff --git a/arch/x86/kernel/x8664_ksyms_64.c b/arch/x86/kernel/x8664_ksyms_64.c index cd05942..72cb689 100644 --- a/arch/x86/kernel/x8664_ksyms_64.c +++ b/arch/x86/kernel/x8664_ksyms_64.c @@ -11,6 +11,7 @@ #include #include #include +#include #ifdef CONFIG_FUNCTION_TRACER /* mcount and __fentry__ are defined in assembly */ @@ -79,3 +80,8 @@ EXPORT_SYMBOL(native_load_gs_index); EXPORT_SYMBOL(___preempt_schedule); EXPORT_SYMBOL(___preempt_schedule_notrace); #endif + +#ifdef CONFIG_AMD_MEM_ENCRYPT +EXPORT_SYMBOL_GPL(sme_me_mask); +EXPORT_SYMBOL_GPL(sme_get_me_loss); +#endif