kernel %rsp code at sysenter PTI vs no-PTI

From: Dave Hansen
Date: Thu Jul 05 2018 - 13:14:24 EST


The PTI path does this:

...
SWITCH_TO_KERNEL_CR3 scratch_reg=%rsp
/* Load the top of the task stack into RSP */
movq CPU_ENTRY_AREA_tss + TSS_sp1 + CPU_ENTRY_AREA, %rsp

And the non-PTI entry path does this:

...
movq %rsp, PER_CPU_VAR(rsp_scratch)
movq PER_CPU_VAR(cpu_current_top_of_stack), %rsp

Both "mov ___, %rsp" instructions have the kernel %GS value in place and
both are running on a good kernel CR3. Does anybody remember why we
don't use cpu_current_top_of_stack in the PTI-on case?

I'm wondering if it was because we, at some point, did the mov ...,
%rsp before CR3 was good. But it doesn't look like we do that now, so
should we maybe make both copies do:

movq PER_CPU_VAR(cpu_current_top_of_stack), %rsp

for consistency?