Skip to content

Commit 7744ccd

Browse files
tlendackyIngo Molnar
authored andcommitted
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 <[email protected]> Reviewed-by: Thomas Gleixner <[email protected]> Reviewed-by: Borislav Petkov <[email protected]> Cc: Alexander Potapenko <[email protected]> Cc: Andrey Ryabinin <[email protected]> Cc: Andy Lutomirski <[email protected]> Cc: Arnd Bergmann <[email protected]> Cc: Borislav Petkov <[email protected]> Cc: Brijesh Singh <[email protected]> Cc: Dave Young <[email protected]> Cc: Dmitry Vyukov <[email protected]> Cc: Jonathan Corbet <[email protected]> Cc: Konrad Rzeszutek Wilk <[email protected]> Cc: Larry Woodman <[email protected]> Cc: Linus Torvalds <[email protected]> Cc: Matt Fleming <[email protected]> Cc: Michael S. Tsirkin <[email protected]> Cc: Paolo Bonzini <[email protected]> Cc: Peter Zijlstra <[email protected]> Cc: Radim Krčmář <[email protected]> Cc: Rik van Riel <[email protected]> Cc: Toshimitsu Kani <[email protected]> Cc: [email protected] Cc: [email protected] Cc: [email protected] Cc: [email protected] Cc: [email protected] Cc: [email protected] Link: http://lkml.kernel.org/r/a6c34d16caaed3bc3e2d6f0987554275bd291554.1500319216.git.thomas.lendacky@amd.com Signed-off-by: Ingo Molnar <[email protected]>
1 parent 9af9b94 commit 7744ccd

File tree

5 files changed

+112
-0
lines changed

5 files changed

+112
-0
lines changed

arch/x86/Kconfig

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1415,6 +1415,31 @@ config X86_DIRECT_GBPAGES
14151415
supports them), so don't confuse the user by printing
14161416
that we have them enabled.
14171417

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+
14181443
# Common NUMA Features
14191444
config NUMA
14201445
bool "Numa Memory Allocation and Scheduler Support"

arch/x86/include/asm/mem_encrypt.h

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/*
2+
* AMD Memory Encryption Support
3+
*
4+
* Copyright (C) 2016 Advanced Micro Devices, Inc.
5+
*
6+
* Author: Tom Lendacky <[email protected]>
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__ */

arch/x86/mm/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,3 +39,4 @@ obj-$(CONFIG_X86_INTEL_MPX) += mpx.o
3939
obj-$(CONFIG_X86_INTEL_MEMORY_PROTECTION_KEYS) += pkeys.o
4040
obj-$(CONFIG_RANDOMIZE_MEMORY) += kaslr.o
4141

42+
obj-$(CONFIG_AMD_MEM_ENCRYPT) += mem_encrypt.o

arch/x86/mm/mem_encrypt.c

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/*
2+
* AMD Memory Encryption Support
3+
*
4+
* Copyright (C) 2016 Advanced Micro Devices, Inc.
5+
*
6+
* Author: Tom Lendacky <[email protected]>
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);

include/linux/mem_encrypt.h

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/*
2+
* AMD Memory Encryption Support
3+
*
4+
* Copyright (C) 2016 Advanced Micro Devices, Inc.
5+
*
6+
* Author: Tom Lendacky <[email protected]>
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__ */

0 commit comments

Comments
 (0)