diff options
author | Tom Lendacky <thomas.lendacky@amd.com> | 2017-07-17 17:10:03 -0400 |
---|---|---|
committer | Ingo Molnar <mingo@kernel.org> | 2017-07-18 05:37:59 -0400 |
commit | 7744ccdbc16f0ac4adae21b3678af93775b3a386 (patch) | |
tree | 7b30f32f09141cae07a9f07ab4eba1e3e734ed91 | |
parent | 9af9b94068fb1ea3206a700fc222075966fbef14 (diff) |
x86/mm: Add Secure Memory Encryption (SME) support
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 <thomas.lendacky@amd.com>
Reviewed-by: Thomas Gleixner <tglx@linutronix.de>
Reviewed-by: Borislav Petkov <bp@suse.de>
Cc: Alexander Potapenko <glider@google.com>
Cc: Andrey Ryabinin <aryabinin@virtuozzo.com>
Cc: Andy Lutomirski <luto@kernel.org>
Cc: Arnd Bergmann <arnd@arndb.de>
Cc: Borislav Petkov <bp@alien8.de>
Cc: Brijesh Singh <brijesh.singh@amd.com>
Cc: Dave Young <dyoung@redhat.com>
Cc: Dmitry Vyukov <dvyukov@google.com>
Cc: Jonathan Corbet <corbet@lwn.net>
Cc: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
Cc: Larry Woodman <lwoodman@redhat.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Matt Fleming <matt@codeblueprint.co.uk>
Cc: Michael S. Tsirkin <mst@redhat.com>
Cc: Paolo Bonzini <pbonzini@redhat.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Radim Krčmář <rkrcmar@redhat.com>
Cc: Rik van Riel <riel@redhat.com>
Cc: Toshimitsu Kani <toshi.kani@hpe.com>
Cc: kasan-dev@googlegroups.com
Cc: kvm@vger.kernel.org
Cc: linux-arch@vger.kernel.org
Cc: linux-doc@vger.kernel.org
Cc: linux-efi@vger.kernel.org
Cc: linux-mm@kvack.org
Link: http://lkml.kernel.org/r/a6c34d16caaed3bc3e2d6f0987554275bd291554.1500319216.git.thomas.lendacky@amd.com
Signed-off-by: Ingo Molnar <mingo@kernel.org>
-rw-r--r-- | arch/x86/Kconfig | 25 | ||||
-rw-r--r-- | arch/x86/include/asm/mem_encrypt.h | 30 | ||||
-rw-r--r-- | arch/x86/mm/Makefile | 1 | ||||
-rw-r--r-- | arch/x86/mm/mem_encrypt.c | 21 | ||||
-rw-r--r-- | include/linux/mem_encrypt.h | 35 |
5 files changed, 112 insertions, 0 deletions
diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig index 781521b7cf9e..ba7b93d08d00 100644 --- a/arch/x86/Kconfig +++ b/arch/x86/Kconfig | |||
@@ -1415,6 +1415,31 @@ config X86_DIRECT_GBPAGES | |||
1415 | supports them), so don't confuse the user by printing | 1415 | supports them), so don't confuse the user by printing |
1416 | that we have them enabled. | 1416 | that we have them enabled. |
1417 | 1417 | ||
1418 | config ARCH_HAS_MEM_ENCRYPT | ||
1419 | def_bool y | ||
1420 | |||
1421 | config AMD_MEM_ENCRYPT | ||
1422 | bool "AMD Secure Memory Encryption (SME) support" | ||
1423 | depends on X86_64 && CPU_SUP_AMD | ||
1424 | ---help--- | ||
1425 | Say yes to enable support for the encryption of system memory. | ||
1426 | This requires an AMD processor that supports Secure Memory | ||
1427 | Encryption (SME). | ||
1428 | |||
1429 | config AMD_MEM_ENCRYPT_ACTIVE_BY_DEFAULT | ||
1430 | bool "Activate AMD Secure Memory Encryption (SME) by default" | ||
1431 | default y | ||
1432 | depends on AMD_MEM_ENCRYPT | ||
1433 | ---help--- | ||
1434 | Say yes to have system memory encrypted by default if running on | ||
1435 | an AMD processor that supports Secure Memory Encryption (SME). | ||
1436 | |||
1437 | If set to Y, then the encryption of system memory can be | ||
1438 | deactivated with the mem_encrypt=off command line option. | ||
1439 | |||
1440 | If set to N, then the encryption of system memory can be | ||
1441 | activated with the mem_encrypt=on command line option. | ||
1442 | |||
1418 | # Common NUMA Features | 1443 | # Common NUMA Features |
1419 | config NUMA | 1444 | config NUMA |
1420 | bool "Numa Memory Allocation and Scheduler Support" | 1445 | 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 000000000000..a1057961ac46 --- /dev/null +++ b/arch/x86/include/asm/mem_encrypt.h | |||
@@ -0,0 +1,30 @@ | |||
1 | /* | ||
2 | * AMD Memory Encryption Support | ||
3 | * | ||
4 | * Copyright (C) 2016 Advanced Micro Devices, Inc. | ||
5 | * | ||
6 | * Author: Tom Lendacky <thomas.lendacky@amd.com> | ||
7 | * | ||
8 | * This program is free software; you can redistribute it and/or modify | ||
9 | * it under the terms of the GNU General Public License version 2 as | ||
10 | * published by the Free Software Foundation. | ||
11 | */ | ||
12 | |||
13 | #ifndef __X86_MEM_ENCRYPT_H__ | ||
14 | #define __X86_MEM_ENCRYPT_H__ | ||
15 | |||
16 | #ifndef __ASSEMBLY__ | ||
17 | |||
18 | #ifdef CONFIG_AMD_MEM_ENCRYPT | ||
19 | |||
20 | extern unsigned long sme_me_mask; | ||
21 | |||
22 | #else /* !CONFIG_AMD_MEM_ENCRYPT */ | ||
23 | |||
24 | #define sme_me_mask 0UL | ||
25 | |||
26 | #endif /* CONFIG_AMD_MEM_ENCRYPT */ | ||
27 | |||
28 | #endif /* __ASSEMBLY__ */ | ||
29 | |||
30 | #endif /* __X86_MEM_ENCRYPT_H__ */ | ||
diff --git a/arch/x86/mm/Makefile b/arch/x86/mm/Makefile index 0fbdcb64f9f8..a94a7b663d5f 100644 --- a/arch/x86/mm/Makefile +++ b/arch/x86/mm/Makefile | |||
@@ -39,3 +39,4 @@ obj-$(CONFIG_X86_INTEL_MPX) += mpx.o | |||
39 | obj-$(CONFIG_X86_INTEL_MEMORY_PROTECTION_KEYS) += pkeys.o | 39 | obj-$(CONFIG_X86_INTEL_MEMORY_PROTECTION_KEYS) += pkeys.o |
40 | obj-$(CONFIG_RANDOMIZE_MEMORY) += kaslr.o | 40 | obj-$(CONFIG_RANDOMIZE_MEMORY) += kaslr.o |
41 | 41 | ||
42 | 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 000000000000..b99d469c73e7 --- /dev/null +++ b/arch/x86/mm/mem_encrypt.c | |||
@@ -0,0 +1,21 @@ | |||
1 | /* | ||
2 | * AMD Memory Encryption Support | ||
3 | * | ||
4 | * Copyright (C) 2016 Advanced Micro Devices, Inc. | ||
5 | * | ||
6 | * Author: Tom Lendacky <thomas.lendacky@amd.com> | ||
7 | * | ||
8 | * This program is free software; you can redistribute it and/or modify | ||
9 | * it under the terms of the GNU General Public License version 2 as | ||
10 | * published by the Free Software Foundation. | ||
11 | */ | ||
12 | |||
13 | #include <linux/linkage.h> | ||
14 | |||
15 | /* | ||
16 | * Since SME related variables are set early in the boot process they must | ||
17 | * reside in the .data section so as not to be zeroed out when the .bss | ||
18 | * section is later cleared. | ||
19 | */ | ||
20 | unsigned long sme_me_mask __section(.data) = 0; | ||
21 | 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 000000000000..59769f7287e4 --- /dev/null +++ b/include/linux/mem_encrypt.h | |||
@@ -0,0 +1,35 @@ | |||
1 | /* | ||
2 | * AMD Memory Encryption Support | ||
3 | * | ||
4 | * Copyright (C) 2016 Advanced Micro Devices, Inc. | ||
5 | * | ||
6 | * Author: Tom Lendacky <thomas.lendacky@amd.com> | ||
7 | * | ||
8 | * This program is free software; you can redistribute it and/or modify | ||
9 | * it under the terms of the GNU General Public License version 2 as | ||
10 | * published by the Free Software Foundation. | ||
11 | */ | ||
12 | |||
13 | #ifndef __MEM_ENCRYPT_H__ | ||
14 | #define __MEM_ENCRYPT_H__ | ||
15 | |||
16 | #ifndef __ASSEMBLY__ | ||
17 | |||
18 | #ifdef CONFIG_ARCH_HAS_MEM_ENCRYPT | ||
19 | |||
20 | #include <asm/mem_encrypt.h> | ||
21 | |||
22 | #else /* !CONFIG_ARCH_HAS_MEM_ENCRYPT */ | ||
23 | |||
24 | #define sme_me_mask 0UL | ||
25 | |||
26 | #endif /* CONFIG_ARCH_HAS_MEM_ENCRYPT */ | ||
27 | |||
28 | static inline bool sme_active(void) | ||
29 | { | ||
30 | return !!sme_me_mask; | ||
31 | } | ||
32 | |||
33 | #endif /* __ASSEMBLY__ */ | ||
34 | |||
35 | #endif /* __MEM_ENCRYPT_H__ */ | ||