Message ID | 20160822223610.29880.21739.stgit@tlendack-t1.amdoffice.net (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
On Mon, 22 Aug 2016, Tom Lendacky wrote: > 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. What is the reason that this needs to live in assembly code? Thanks, tglx -- To unsubscribe from this list: send the line "unsubscribe kvm" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
On 08/25/2016 08:04 AM, Thomas Gleixner wrote: > On Mon, 22 Aug 2016, Tom Lendacky wrote: > >> 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. > > What is the reason that this needs to live in assembly code? In later patches this code is expanded and deals with a lot of page table manipulation, cpuid/rdmsr instructions, etc. and so I thought it was best to do it this way. Thanks, Tom > > Thanks, > > tglx > -- To unsubscribe from this list: send the line "unsubscribe kvm" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
On Aug 30, 2016 6:34 AM, "Tom Lendacky" <thomas.lendacky@amd.com> wrote: > > On 08/25/2016 08:04 AM, Thomas Gleixner wrote: > > On Mon, 22 Aug 2016, Tom Lendacky wrote: > > > >> 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. > > > > What is the reason that this needs to live in assembly code? > > In later patches this code is expanded and deals with a lot of page > table manipulation, cpuid/rdmsr instructions, etc. and so I thought it > was best to do it this way. None of that sounds like it needs to be in asm, though. I, at least, have a strong preference for minimizing the amount of asm in the low-level arch code. --Andy -- To unsubscribe from this list: send the line "unsubscribe kvm" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
On 08/30/2016 09:57 AM, Andy Lutomirski wrote: > On Aug 30, 2016 6:34 AM, "Tom Lendacky" <thomas.lendacky@amd.com> wrote: >> >> On 08/25/2016 08:04 AM, Thomas Gleixner wrote: >>> On Mon, 22 Aug 2016, Tom Lendacky wrote: >>> >>>> 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. >>> >>> What is the reason that this needs to live in assembly code? >> >> In later patches this code is expanded and deals with a lot of page >> table manipulation, cpuid/rdmsr instructions, etc. and so I thought it >> was best to do it this way. > > None of that sounds like it needs to be in asm, though. > > I, at least, have a strong preference for minimizing the amount of asm > in the low-level arch code. I can take a look at converting it over to C code. Thanks, Tom > > --Andy > -- To unsubscribe from this list: send the line "unsubscribe kvm" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
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 <thomas.lendacky@amd.com> + * + * 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 <thomas.lendacky@amd.com> + * + * 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 <linux/linkage.h> + + .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 <asm/uaccess.h> #include <asm/desc.h> #include <asm/ftrace.h> +#include <asm/mem_encrypt.h> #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
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 <thomas.lendacky@amd.com> --- 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 -- To unsubscribe from this list: send the line "unsubscribe kvm" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html