From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753733AbcHVWvV (ORCPT ); Mon, 22 Aug 2016 18:51:21 -0400 Received: from mail-bn3nam01on0083.outbound.protection.outlook.com ([104.47.33.83]:49664 "EHLO NAM01-BN3-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751168AbcHVWvR (ORCPT ); Mon, 22 Aug 2016 18:51:17 -0400 X-Greylist: delayed 816 seconds by postgrey-1.27 at vger.kernel.org; Mon, 22 Aug 2016 18:51:16 EDT Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=Thomas.Lendacky@amd.com; From: Tom Lendacky Subject: [RFC PATCH v2 04/20] x86: Secure Memory Encryption (SME) support To: , , , , , , , , CC: Radim =?utf-8?b?S3LEjW3DocWZ?= , Arnd Bergmann , Jonathan Corbet , Matt Fleming , Joerg Roedel , "Konrad Rzeszutek Wilk" , Andrey Ryabinin , Ingo Molnar , Borislav Petkov , "Andy Lutomirski" , "H. Peter Anvin" , Paolo Bonzini , Alexander Potapenko , "Thomas Gleixner" , Dmitry Vyukov Date: Mon, 22 Aug 2016 17:36:10 -0500 Message-ID: <20160822223610.29880.21739.stgit@tlendack-t1.amdoffice.net> In-Reply-To: <20160822223529.29880.50884.stgit@tlendack-t1.amdoffice.net> References: <20160822223529.29880.50884.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: SN1PR0501CA0011.namprd05.prod.outlook.com (10.163.126.149) To MWHPR12MB1151.namprd12.prod.outlook.com (10.169.204.15) X-MS-Office365-Filtering-Correlation-Id: 499a86bb-adbe-4b71-3b70-08d3cadcba49 X-Microsoft-Exchange-Diagnostics: 1;MWHPR12MB1151;2:jzujrQdO1z5u7zBOfGsok5wptzt+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F7u5KwQkkxez9N5auNsjHRN5004il8ScF7uSKjf+LP4gOY7MKT3n7004zOkGZrm7SLMCLRwTF X-Microsoft-Exchange-Diagnostics: 1;MWHPR12MB1151;31:ei35NOqETbg+XC1/G1c6nCj0Okujce1IhERJGMKXC3/bJCQwBnZQ1upnW4sOfO9E7h87V60s07YmAcgbK0aabn/sbW/rCxNv8gu19rQ8UY9yoibuKoZt4xmL57PrusQ+eViKXaDfhJrKCgN8LoKChMdyJVkGI8ugizLOIuDbYYtW5dzNeOwVgd7P9/kmFqgZ7S2rPPbPsLuXRa1vWtQhXjahtBMRlZC2UM4KY988exk=;20:/vNV28q7mUhLbp5W5YyjiTfPVSqJjjp6aBWWevtNSuW4hIwXZshcxnmIEpnZlgicF3SqY3TPO2lGro2b7qcZpLleNYj2wwTGzjRFevVOeLxXMODcpB22bOpYCA8aWwVifyw1qsEtdEhvK68rKS1nY7SL2qDwwUmBiar8mtE3XFarpKEqyuSZhFP0U0pfOk1r6VFlIrwnufNA7j6LVn9XNZeqK12FDf++kup+W3+afpHhWfSQ5/ZkXa8SOg0tzfGOxrDl3hU5qAqnJkuv7Yv4WJ420cXd5NqVQ8B6i5kJ7xkmiVcOOIaSkjSGk3nqjypStPqR9PCqhhY17RP8EyfSfsKDjFm8jijfkI/iSGISIehy1Tls1bPNv8wdmDrVT9ISJ285CEuAhJktvVs2HmBkmQD18dUKv6+Jinbxxqy4nOe9z0gvuqkulxC5mY57zmWlb3AW3coSWKTyZi8rjLDdspcgqA7MGTZcyz3TgUqCFG8i8b8laNJ9NWvK0bUa6BCw X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(767451399110); X-Exchange-Antispam-Report-CFA-Test: BCL:0;PCL:0;RULEID:(6040176)(601004)(2401047)(5005006)(8121501046)(3002001)(10201501046)(6055026);SRVR:MWHPR12MB1151;BCL:0;PCL:0;RULEID:;SRVR:MWHPR12MB1151; X-Microsoft-Exchange-Diagnostics: 1;MWHPR12MB1151;4:1NBqaGNYUNVAz0UmN+MEr9BCwaKvyuBO2XPVfO9OMA00b75eMTnqo1JS+C+tIA3jTuaHWLoOF7zAGUHRe9N5G9zqFXg3kuHgNqqxsNfw5csGCS5ysT+7NY1xvpVbDfGmLGPwTahZrPhB2QIv4Ukp3o1vdTwn5oUNg157yq9wxQvHV7O2Z/J/2AWAEi1fFy/St3T7QORfJgqK0IPsnuC8aulGD86RDG3MCVDPVBNNxCNUvDoFhV3DDVI0xfh3pmsV1VE/93w9FB25dwViG/gE4O3P9jmy9VT0Gqy9FWJQ53y2ZwJTkZSKlh410Kgc/IyIQM912cafDtuubuEKz8FJ4f6GEMPpMttiCy453WBLpxjyM+Bu4CuSUj1ZgASIhMbU4UBr6kpyTyQOZR6LCVVQnqWtd0fzFDohSbxXjNOuDM4p39E8BmvOaB+Syzg/IDpg X-Forefront-PRVS: 00429279BA X-Forefront-Antispam-Report: SFV:NSPM;SFS:(10009020)(4630300001)(6009001)(7916002)(189002)(199003)(8676002)(81166006)(81156014)(189998001)(4001350100001)(66066001)(5001770100001)(97736004)(92566002)(47776003)(97746001)(42186005)(83506001)(105586002)(68736007)(230700001)(69596002)(53416004)(33646002)(5660300001)(229853001)(2950100001)(77096005)(7846002)(305945005)(7736002)(2201001)(586003)(19580405001)(106356001)(23676002)(3846002)(6116002)(7416002)(50466002)(4326007)(19580395003)(1076002)(50986999)(9686002)(2906002)(103116003)(101416001)(76176999)(86362001)(54356999)(71626007)(2004002)(217873001);DIR:OUT;SFP:1101;SCL:1;SRVR:MWHPR12MB1151;H:tlendack-t1.amdoffice.net;FPR:;SPF:None;PTR:InfoNoRecords;MX:1;A:1;LANG:en; X-Microsoft-Exchange-Diagnostics: =?utf-8?B?MTtNV0hQUjEyTUIxMTUxOzIzOnRrdmJrUk1wM01wZzVrNVJJRXpQa2cwSFFv?= =?utf-8?B?dzQ5M3haZWZTRW5rOWRUYkYvK1VNOVhXSWFSWE5aM2JDSVV4MGxWLytkdGx4?= =?utf-8?B?RXFuW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CPT5ns/r5u1EXMwplcMUZzfKdM7rLvXlMgrBroN1NAuZEyTIcpMoxuQ3CUZg4eSNpbcrzj X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 22 Aug 2016 22:36:13.9625 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: MWHPR12MB1151 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 0503f5b..bda997f 100644 --- a/arch/x86/kernel/Makefile +++ b/arch/x86/kernel/Makefile @@ -125,6 +125,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 95e49f6..651c4c8 100644 --- a/arch/x86/kernel/x8664_ksyms_64.c +++ b/arch/x86/kernel/x8664_ksyms_64.c @@ -12,6 +12,7 @@ #include #include #include +#include #ifdef CONFIG_FUNCTION_TRACER /* mcount and __fentry__ are defined in assembly */ @@ -83,3 +84,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 From mboxrd@z Thu Jan 1 00:00:00 1970 From: Tom Lendacky Subject: [RFC PATCH v2 04/20] x86: Secure Memory Encryption (SME) support Date: Mon, 22 Aug 2016 17:36:10 -0500 Message-ID: <20160822223610.29880.21739.stgit@tlendack-t1.amdoffice.net> References: <20160822223529.29880.50884.stgit@tlendack-t1.amdoffice.net> Mime-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Return-path: In-Reply-To: <20160822223529.29880.50884.stgit@tlendack-t1.amdoffice.net> Sender: owner-linux-mm@kvack.org To: linux-arch@vger.kernel.org, linux-efi@vger.kernel.org, kvm@vger.kernel.org, linux-doc@vger.kernel.org, x86@kernel.org, linux-kernel@vger.kernel.org, kasan-dev@googlegroups.com, linux-mm@kvack.org, iommu@lists.linux-foundation.org Cc: Radim =?utf-8?b?S3LEjW3DocWZ?= , Arnd Bergmann , Jonathan Corbet , Matt Fleming , Joerg Roedel , Konrad Rzeszutek Wilk , Andrey Ryabinin , Ingo Molnar , Borislav Petkov , Andy Lutomirski , "H. Peter Anvin" , Paolo Bonzini , Alexander Potapenko , Thomas Gleixner , Dmitry Vyukov List-Id: linux-efi@vger.kernel.org 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 0503f5b..bda997f 100644 --- a/arch/x86/kernel/Makefile +++ b/arch/x86/kernel/Makefile @@ -125,6 +125,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 95e49f6..651c4c8 100644 --- a/arch/x86/kernel/x8664_ksyms_64.c +++ b/arch/x86/kernel/x8664_ksyms_64.c @@ -12,6 +12,7 @@ #include #include #include +#include #ifdef CONFIG_FUNCTION_TRACER /* mcount and __fentry__ are defined in assembly */ @@ -83,3 +84,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 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to majordomo@kvack.org. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: email@kvack.org From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-bn3nam01on0083.outbound.protection.outlook.com ([104.47.33.83]:49664 "EHLO NAM01-BN3-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751168AbcHVWvR (ORCPT ); Mon, 22 Aug 2016 18:51:17 -0400 From: Tom Lendacky Subject: [RFC PATCH v2 04/20] x86: Secure Memory Encryption (SME) support Date: Mon, 22 Aug 2016 17:36:10 -0500 Message-ID: <20160822223610.29880.21739.stgit@tlendack-t1.amdoffice.net> In-Reply-To: <20160822223529.29880.50884.stgit@tlendack-t1.amdoffice.net> References: <20160822223529.29880.50884.stgit@tlendack-t1.amdoffice.net> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Sender: linux-arch-owner@vger.kernel.org List-ID: To: linux-arch@vger.kernel.org, linux-efi@vger.kernel.org, kvm@vger.kernel.org, linux-doc@vger.kernel.org, x86@kernel.org, linux-kernel@vger.kernel.org, kasan-dev@googlegroups.com, linux-mm@kvack.org, iommu@lists.linux-foundation.org Cc: Radim =?utf-8?b?S3LEjW3DocWZ?= , Arnd Bergmann , Jonathan Corbet , Matt Fleming , Joerg Roedel , Konrad Rzeszutek Wilk , Andrey Ryabinin , Ingo Molnar , Borislav Petkov , Andy Lutomirski , "H. Peter Anvin" , Paolo Bonzini , Alexander Potapenko , Thomas Gleixner , Dmitry Vyukov Message-ID: <20160822223610.kztP7lf7vDEsJu6UVFvvgXYsnSapvRkf9gEIbo7bYXA@z> 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 0503f5b..bda997f 100644 --- a/arch/x86/kernel/Makefile +++ b/arch/x86/kernel/Makefile @@ -125,6 +125,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 95e49f6..651c4c8 100644 --- a/arch/x86/kernel/x8664_ksyms_64.c +++ b/arch/x86/kernel/x8664_ksyms_64.c @@ -12,6 +12,7 @@ #include #include #include +#include #ifdef CONFIG_FUNCTION_TRACER /* mcount and __fentry__ are defined in assembly */ @@ -83,3 +84,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 From mboxrd@z Thu Jan 1 00:00:00 1970 From: Tom Lendacky Subject: [RFC PATCH v2 04/20] x86: Secure Memory Encryption (SME) support Date: Mon, 22 Aug 2016 17:36:10 -0500 Message-ID: <20160822223610.29880.21739.stgit@tlendack-t1.amdoffice.net> References: <20160822223529.29880.50884.stgit@tlendack-t1.amdoffice.net> Mime-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Cc: Radim =?utf-8?b?S3LEjW3DocWZ?= , Arnd Bergmann , Jonathan Corbet , Matt Fleming , Joerg Roedel , "Konrad Rzeszutek Wilk" , Andrey Ryabinin , Ingo Molnar , Borislav Petkov , "Andy Lutomirski" , "H. Peter Anvin" , Paolo Bonzini , Alexander Potapenko , "Thomas Gleixner" , Dmitry Vyukov To: , , , , , , , , Return-path: In-Reply-To: <20160822223529.29880.50884.stgit@tlendack-t1.amdoffice.net> Sender: owner-linux-mm@kvack.org List-Id: kvm.vger.kernel.org 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 0503f5b..bda997f 100644 --- a/arch/x86/kernel/Makefile +++ b/arch/x86/kernel/Makefile @@ -125,6 +125,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 95e49f6..651c4c8 100644 --- a/arch/x86/kernel/x8664_ksyms_64.c +++ b/arch/x86/kernel/x8664_ksyms_64.c @@ -12,6 +12,7 @@ #include #include #include +#include #ifdef CONFIG_FUNCTION_TRACER /* mcount and __fentry__ are defined in assembly */ @@ -83,3 +84,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 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to majordomo@kvack.org. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: email@kvack.org