Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1671420 > unrolled thread
| Started by | Thomas Gleixner <tglx@linutronix.de> |
|---|---|
| First post | 2017-06-21 09:20 +0200 |
| Last post | 2017-06-21 21:00 +0200 |
| Articles | 3 — 1 participant |
Back to article view | Back to linux.kernel
This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by
below is the oldest one visible, not the original post.
Re: [PATCH v7 08/36] x86/mm: Add support to enable SME in early boot processing Thomas Gleixner <tglx@linutronix.de> - 2017-06-21 09:20 +0200
Re: [PATCH v7 08/36] x86/mm: Add support to enable SME in early boot processing Thomas Gleixner <tglx@linutronix.de> - 2017-06-21 18:40 +0200
Re: [PATCH v7 08/36] x86/mm: Add support to enable SME in early boot processing Thomas Gleixner <tglx@linutronix.de> - 2017-06-21 21:00 +0200
| From | Thomas Gleixner <tglx@linutronix.de> |
|---|---|
| Date | 2017-06-21 09:20 +0200 |
| Subject | Re: [PATCH v7 08/36] x86/mm: Add support to enable SME in early boot processing |
| Message-ID | <tUI5I-31b-15@gated-at.bofh.it> |
On Fri, 16 Jun 2017, Tom Lendacky wrote:
> diff --git a/arch/x86/include/asm/mem_encrypt.h b/arch/x86/include/asm/mem_encrypt.h
> index a105796..988b336 100644
> --- a/arch/x86/include/asm/mem_encrypt.h
> +++ b/arch/x86/include/asm/mem_encrypt.h
> @@ -15,16 +15,24 @@
>
> #ifndef __ASSEMBLY__
>
> +#include <linux/init.h>
> +
> #ifdef CONFIG_AMD_MEM_ENCRYPT
>
> extern unsigned long sme_me_mask;
>
> +void __init sme_enable(void);
> +
> #else /* !CONFIG_AMD_MEM_ENCRYPT */
>
> #define sme_me_mask 0UL
>
> +static inline void __init sme_enable(void) { }
> +
> #endif /* CONFIG_AMD_MEM_ENCRYPT */
>
> +unsigned long sme_get_me_mask(void);
Why is this an unconditional function? Isn't the mask simply 0 when the MEM
ENCRYPT support is disabled?
> diff --git a/arch/x86/kernel/head_64.S b/arch/x86/kernel/head_64.S
> index 6225550..ef12729 100644
> --- a/arch/x86/kernel/head_64.S
> +++ b/arch/x86/kernel/head_64.S
> @@ -78,7 +78,29 @@ startup_64:
> call __startup_64
> popq %rsi
>
> - movq $(early_top_pgt - __START_KERNEL_map), %rax
> + /*
> + * Encrypt the kernel if SME is active.
> + * The real_mode_data address is in %rsi and that register can be
> + * clobbered by the called function so be sure to save it.
> + */
> + push %rsi
> + call sme_encrypt_kernel
> + pop %rsi
That does not make any sense. Neither the call to sme_encrypt_kernel() nor
the following call to sme_get_me_mask().
__startup_64() is already C code, so why can't you simply call that from
__startup_64() in C and return the mask from there?
> @@ -98,7 +120,20 @@ ENTRY(secondary_startup_64)
> /* Sanitize CPU configuration */
> call verify_cpu
>
> - movq $(init_top_pgt - __START_KERNEL_map), %rax
> + /*
> + * Get the SME encryption mask.
> + * The encryption mask will be returned in %rax so we do an ADD
> + * below to be sure that the encryption mask is part of the
> + * value that will stored in %cr3.
> + *
> + * The real_mode_data address is in %rsi and that register can be
> + * clobbered by the called function so be sure to save it.
> + */
> + push %rsi
> + call sme_get_me_mask
> + pop %rsi
Do we really need a call here? The mask is established at this point, so
it's either 0 when the encryption stuff is not compiled in or it can be
retrieved from a variable which is accessible at this point.
> +
> + addq $(init_top_pgt - __START_KERNEL_map), %rax
> 1:
>
> /* Enable PAE mode, PGE and LA57 */
Thanks,
tglx
[toc] | [next] | [standalone]
| From | Thomas Gleixner <tglx@linutronix.de> |
|---|---|
| Date | 2017-06-21 18:40 +0200 |
| Message-ID | <tUQPE-6J-27@gated-at.bofh.it> |
| In reply to | #1671420 |
On Wed, 21 Jun 2017, Tom Lendacky wrote:
> On 6/21/2017 2:16 AM, Thomas Gleixner wrote:
> > Why is this an unconditional function? Isn't the mask simply 0 when the MEM
> > ENCRYPT support is disabled?
>
> I made it unconditional because of the call from head_64.S. I can't make
> use of the C level static inline function and since the mask is not a
> variable if CONFIG_AMD_MEM_ENCRYPT is not configured (#defined to 0) I
> can't reference the variable directly.
>
> I could create a #define in head_64.S that changes this to load rax with
> the variable if CONFIG_AMD_MEM_ENCRYPT is configured or a zero if it's
> not or add a #ifdef at that point in the code directly. Thoughts on
> that?
See below.
> > That does not make any sense. Neither the call to sme_encrypt_kernel() nor
> > the following call to sme_get_me_mask().
> >
> > __startup_64() is already C code, so why can't you simply call that from
> > __startup_64() in C and return the mask from there?
>
> I was trying to keep it explicit as to what was happening, but I can
> move those calls into __startup_64().
That's much preferred. And the return value wants to be documented in both
C and ASM code.
> I'll still need the call to sme_get_me_mask() in the secondary_startup_64
> path, though (depending on your thoughts to the above response).
call verify_cpu
movq $(init_top_pgt - __START_KERNEL_map), %rax
So if you make that:
/*
* Sanitize CPU configuration and retrieve the modifier
* for the initial pgdir entry which will be programmed
* into CR3. Depends on enabled SME encryption, normally 0.
*/
call __startup_secondary_64
addq $(init_top_pgt - __START_KERNEL_map), %rax
You can hide that stuff in C-code nicely without adding any cruft to the
ASM code.
Thanks,
tglx
[toc] | [prev] | [next] | [standalone]
| From | Thomas Gleixner <tglx@linutronix.de> |
|---|---|
| Date | 2017-06-21 21:00 +0200 |
| Message-ID | <tUT18-1FF-29@gated-at.bofh.it> |
| In reply to | #1671787 |
On Wed, 21 Jun 2017, Tom Lendacky wrote: > On 6/21/2017 10:38 AM, Thomas Gleixner wrote: > > /* > > * Sanitize CPU configuration and retrieve the modifier > > * for the initial pgdir entry which will be programmed > > * into CR3. Depends on enabled SME encryption, normally 0. > > */ > > call __startup_secondary_64 > > > > addq $(init_top_pgt - __START_KERNEL_map), %rax > > > > You can hide that stuff in C-code nicely without adding any cruft to the > > ASM code. > > > > Moving the call to verify_cpu into the C-code might be quite a bit of > change. Currently, the verify_cpu code is included code and not a > global function. Ah. Ok. I missed that. > I can still do the __startup_secondary_64() function and then look to > incorporate verify_cpu into both __startup_64() and > __startup_secondary_64() as a post-patch to this series. Yes, just having __startup_secondary_64() for now and there the extra bits for that encryption stuff is fine. > At least the secondary path will have a base C routine to which > modifications can be made in the future if needed. How does that sound? Sounds like a plan.
[toc] | [prev] | [standalone]
Back to top | Article view | linux.kernel
csiph-web