Re: [PATCH 20/43] x86/entry: Clean up SYSENTER_stack code

From: Borislav Petkov
Date: Sat Nov 25 2017 - 11:40:12 EST


On Fri, Nov 24, 2017 at 06:23:48PM +0100, Ingo Molnar wrote:
> From: Andy Lutomirski <luto@xxxxxxxxxx>
>
> The existing code was a mess, mainly because C arrays are nasty.
> Turn SYSENTER_stack into a struct, add a helper to find it, and do
> all the obvious cleanups this enables.
>
> Signed-off-by: Andy Lutomirski <luto@xxxxxxxxxx>
> Signed-off-by: Thomas Gleixner <tglx@xxxxxxxxxxxxx>
> Cc: Borislav Petkov <bpetkov@xxxxxxx>
> Cc: Brian Gerst <brgerst@xxxxxxxxx>
> Cc: Dave Hansen <dave.hansen@xxxxxxxxx>
> Cc: Josh Poimboeuf <jpoimboe@xxxxxxxxxx>
> Cc: Linus Torvalds <torvalds@xxxxxxxxxxxxxxxxxxxx>
> Cc: Peter Zijlstra <peterz@xxxxxxxxxxxxx>
> Link: https://lkml.kernel.org/r/38ff640712c9b591b32de24a080daf13afaba234.1511497875.git.luto@xxxxxxxxxx
> Signed-off-by: Ingo Molnar <mingo@xxxxxxxxxx>
> ---

...

> diff --git a/arch/x86/kernel/asm-offsets.c b/arch/x86/kernel/asm-offsets.c
> index 61b1af88ac07..46c0995344aa 100644
> --- a/arch/x86/kernel/asm-offsets.c
> +++ b/arch/x86/kernel/asm-offsets.c
> @@ -94,10 +94,8 @@ void common(void) {
> BLANK();
> DEFINE(PTREGS_SIZE, sizeof(struct pt_regs));
>
> - /* Offset from cpu_tss to SYSENTER_stack */
> - OFFSET(CPU_TSS_SYSENTER_stack, tss_struct, SYSENTER_stack);
> - /* Size of SYSENTER_stack */
> - DEFINE(SIZEOF_SYSENTER_stack, sizeof(((struct tss_struct *)0)->SYSENTER_stack));
> + OFFSET(TSS_STRUCT_SYSENTER_stack, tss_struct, SYSENTER_stack);
> + DEFINE(SIZEOF_SYSENTER_stack, sizeof(struct SYSENTER_stack));
>
> /* Layout info for cpu_entry_area */
> OFFSET(CPU_ENTRY_AREA_tss, cpu_entry_area, tss);
> diff --git a/arch/x86/kernel/cpu/common.c b/arch/x86/kernel/cpu/common.c
> index 6b949e6ea0f9..f9c7e6852874 100644
> --- a/arch/x86/kernel/cpu/common.c
> +++ b/arch/x86/kernel/cpu/common.c
> @@ -1332,12 +1332,7 @@ void enable_sep_cpu(void)
>
> tss->x86_tss.ss1 = __KERNEL_CS;
> wrmsr(MSR_IA32_SYSENTER_CS, tss->x86_tss.ss1, 0);
> -
> - wrmsr(MSR_IA32_SYSENTER_ESP,
> - (unsigned long)&get_cpu_entry_area(cpu)->tss +
> - offsetofend(struct tss_struct, SYSENTER_stack),
> - 0);
> -
> + wrmsr(MSR_IA32_SYSENTER_ESP, (unsigned long)(cpu_SYSENTER_stack(cpu) + 1), 0);
> wrmsr(MSR_IA32_SYSENTER_EIP, (unsigned long)entry_SYSENTER_32, 0);

Right, so we have now two TSS thingies, AFAICT:

tss = &per_cpu(cpu_tss, cpu);

which is cpu_tss and then indirectly, we have also:

&get_cpu_entry_area((cpu))->tss

And those are two different things in my guest here:

[ 0.044002] tss: 0xf5747000
[ 0.044706] entry area tss: 0xffef1000

What is the logic here? We carry two TSSs per CPU - one which is RO
for the entry area and the other is the actual cpu_tss thing? Or am I
misreading it?

Thx.

--
Regards/Gruss,
Boris.

Good mailing practices for 400: avoid top-posting and trim the reply.