[PATCH] x86/entry: remove SYSENTER_stack naming

From: Dave Hansen
Date: Mon Dec 04 2017 - 20:27:10 EST



This is on top of c7ddf30cab55 which is WIP.x86/mm as of now.

---

From: Dave Hansen <dave.hansen@xxxxxxxxxxxxxxx>

If the kernel oopses while on the trampoline stack, it will say
"<SYSENTER>" even if SYSENTER is not involved. That is rather
confusing.

The "SYSENTER" stack is used for a lot more than SYSENTER now.
Give it a better string to display in stack dumps, and rename
the kernel code to match.

We also move the 32-bit code over to the new naming even though
it still uses the entry stack only for SYSENTER.

Signed-off-by: Dave Hansen <dave.hansen@xxxxxxxxxxxxxxx>
Cc: Thomas Gleixner <tglx@xxxxxxxxxxxxx>
Cc: x86@xxxxxxxxxx
Cc: Andy Lutomirski <luto@xxxxxxxxxx>
Cc: Josh Poimboeuf <jpoimboe@xxxxxxxxxx>
Cc: Borislav Petkov <bp@xxxxxxx>
Cc: Peter Zijlstra <peterz@xxxxxxxxxxxxx>
---

b/arch/x86/entry/entry_32.S | 12 ++++++------
b/arch/x86/entry/entry_64.S | 4 ++--
b/arch/x86/include/asm/fixmap.h | 8 ++++----
b/arch/x86/include/asm/processor.h | 6 +++---
b/arch/x86/include/asm/stacktrace.h | 4 ++--
b/arch/x86/kernel/asm-offsets.c | 4 ++--
b/arch/x86/kernel/asm-offsets_32.c | 2 +-
b/arch/x86/kernel/cpu/common.c | 14 +++++++-------
b/arch/x86/kernel/dumpstack.c | 10 +++++-----
b/arch/x86/kernel/dumpstack_32.c | 6 +++---
b/arch/x86/kernel/dumpstack_64.c | 12 +++++++++---
11 files changed, 44 insertions(+), 38 deletions(-)

diff -puN arch/x86/kernel/dumpstack_64.c~SYSENTER-rename arch/x86/kernel/dumpstack_64.c
--- a/arch/x86/kernel/dumpstack_64.c~SYSENTER-rename 2017-12-04 12:21:09.149064609 -0800
+++ b/arch/x86/kernel/dumpstack_64.c 2017-12-04 12:21:09.177064609 -0800
@@ -37,8 +37,14 @@ const char *stack_type_name(enum stack_t
if (type == STACK_TYPE_IRQ)
return "IRQ";

- if (type == STACK_TYPE_SYSENTER)
- return "SYSENTER";
+ if (type == STACK_TYPE_ENTRY) {
+ /*
+ * On 64-bit, we have a generic entry stack that we
+ * use for all the kernel entry points, including
+ * SYSENTER.
+ */
+ return "ENTRY_TRAMPOLINE";
+ }

if (type >= STACK_TYPE_EXCEPTION && type <= STACK_TYPE_EXCEPTION_LAST)
return exception_stack_names[type - STACK_TYPE_EXCEPTION];
@@ -118,7 +124,7 @@ int get_stack_info(unsigned long *stack,
if (in_irq_stack(stack, info))
goto recursion_check;

- if (in_sysenter_stack(stack, info))
+ if (in_entry_stack(stack, info))
goto recursion_check;

goto unknown;
diff -puN arch/x86/include/asm/fixmap.h~SYSENTER-rename arch/x86/include/asm/fixmap.h
--- a/arch/x86/include/asm/fixmap.h~SYSENTER-rename 2017-12-04 12:21:09.151064609 -0800
+++ b/arch/x86/include/asm/fixmap.h 2017-12-04 12:21:09.177064609 -0800
@@ -58,10 +58,10 @@ struct cpu_entry_area {
char gdt[PAGE_SIZE];

/*
- * The GDT is just below SYSENTER_stack and thus serves (on x86_64) as
+ * The GDT is just below entry_stack and thus serves (on x86_64) as
* a a read-only guard page.
*/
- struct SYSENTER_stack_page SYSENTER_stack_page;
+ struct entry_stack_page entry_stack_page;

/*
* On x86_64, the TSS is mapped RO. On x86_32, it's mapped RW because
@@ -266,9 +266,9 @@ static inline struct cpu_entry_area *get
return (struct cpu_entry_area *)__fix_to_virt(__get_cpu_entry_area_page_index(cpu, 0));
}

-static inline struct SYSENTER_stack *cpu_SYSENTER_stack(int cpu)
+static inline struct entry_stack *cpu_entry_stack(int cpu)
{
- return &get_cpu_entry_area(cpu)->SYSENTER_stack_page.stack;
+ return &get_cpu_entry_area(cpu)->entry_stack_page.stack;
}

#endif /* !__ASSEMBLY__ */
diff -puN arch/x86/include/asm/processor.h~SYSENTER-rename arch/x86/include/asm/processor.h
--- a/arch/x86/include/asm/processor.h~SYSENTER-rename 2017-12-04 12:21:09.153064609 -0800
+++ b/arch/x86/include/asm/processor.h 2017-12-04 12:21:09.178064609 -0800
@@ -337,12 +337,12 @@ struct x86_hw_tss {
#define IO_BITMAP_OFFSET (offsetof(struct tss_struct, io_bitmap) - offsetof(struct tss_struct, x86_tss))
#define INVALID_IO_BITMAP_OFFSET 0x8000

-struct SYSENTER_stack {
+struct entry_stack {
unsigned long words[64];
};

-struct SYSENTER_stack_page {
- struct SYSENTER_stack stack;
+struct entry_stack_page {
+ struct entry_stack stack;
} __aligned(PAGE_SIZE);

struct tss_struct {
diff -puN arch/x86/include/asm/stacktrace.h~SYSENTER-rename arch/x86/include/asm/stacktrace.h
--- a/arch/x86/include/asm/stacktrace.h~SYSENTER-rename 2017-12-04 12:21:09.155064609 -0800
+++ b/arch/x86/include/asm/stacktrace.h 2017-12-04 12:21:09.178064609 -0800
@@ -16,7 +16,7 @@ enum stack_type {
STACK_TYPE_TASK,
STACK_TYPE_IRQ,
STACK_TYPE_SOFTIRQ,
- STACK_TYPE_SYSENTER,
+ STACK_TYPE_ENTRY,
STACK_TYPE_EXCEPTION,
STACK_TYPE_EXCEPTION_LAST = STACK_TYPE_EXCEPTION + N_EXCEPTION_STACKS-1,
};
@@ -29,7 +29,7 @@ struct stack_info {
bool in_task_stack(unsigned long *stack, struct task_struct *task,
struct stack_info *info);

-bool in_sysenter_stack(unsigned long *stack, struct stack_info *info);
+bool in_entry_stack(unsigned long *stack, struct stack_info *info);

int get_stack_info(unsigned long *stack, struct task_struct *task,
struct stack_info *info, unsigned long *visit_mask);
diff -puN arch/x86/kernel/cpu/common.c~SYSENTER-rename arch/x86/kernel/cpu/common.c
--- a/arch/x86/kernel/cpu/common.c~SYSENTER-rename 2017-12-04 12:21:09.157064609 -0800
+++ b/arch/x86/kernel/cpu/common.c 2017-12-04 12:21:09.179064609 -0800
@@ -512,8 +512,8 @@ static DEFINE_PER_CPU_PAGE_ALIGNED(char,
[(N_EXCEPTION_STACKS - 1) * EXCEPTION_STKSZ + DEBUG_STKSZ]);
#endif

-static DEFINE_PER_CPU_PAGE_ALIGNED(struct SYSENTER_stack_page,
- SYSENTER_stack_storage);
+static DEFINE_PER_CPU_PAGE_ALIGNED(struct entry_stack_page,
+ entry_stack_storage);

/*
* Force the population of PMDs for not yet allocated per cpu
@@ -558,8 +558,8 @@ static void __init setup_cpu_entry_area(
#endif

__set_fixmap(get_cpu_entry_area_index(cpu, gdt), get_cpu_gdt_paddr(cpu), gdt_prot);
- set_percpu_fixmap_pages(get_cpu_entry_area_index(cpu, SYSENTER_stack_page),
- per_cpu_ptr(&SYSENTER_stack_storage, cpu), 1,
+ set_percpu_fixmap_pages(get_cpu_entry_area_index(cpu, entry_stack_page),
+ per_cpu_ptr(&entry_stack_storage, cpu), 1,
PAGE_KERNEL);

/*
@@ -1375,7 +1375,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)(cpu_SYSENTER_stack(cpu) + 1), 0);
+ wrmsr(MSR_IA32_SYSENTER_ESP, (unsigned long)(cpu_entry_stack(cpu) + 1), 0);
wrmsr(MSR_IA32_SYSENTER_EIP, (unsigned long)entry_SYSENTER_32, 0);

put_cpu();
@@ -1495,7 +1495,7 @@ void syscall_init(void)
* AMD doesn't allow SYSENTER in long mode (either 32- or 64-bit).
*/
wrmsrl_safe(MSR_IA32_SYSENTER_CS, (u64)__KERNEL_CS);
- wrmsrl_safe(MSR_IA32_SYSENTER_ESP, (unsigned long)(cpu_SYSENTER_stack(cpu) + 1));
+ wrmsrl_safe(MSR_IA32_SYSENTER_ESP, (unsigned long)(cpu_entry_stack(cpu) + 1));
wrmsrl_safe(MSR_IA32_SYSENTER_EIP, (u64)entry_SYSENTER_compat);
#else
wrmsrl(MSR_CSTAR, (unsigned long)ignore_sysret);
@@ -1710,7 +1710,7 @@ void cpu_init(void)
*/
set_tss_desc(cpu, &get_cpu_entry_area(cpu)->tss.x86_tss);
load_TR_desc();
- load_sp0((unsigned long)(cpu_SYSENTER_stack(cpu) + 1));
+ load_sp0((unsigned long)(cpu_entry_stack(cpu) + 1));

load_mm_ldt(&init_mm);

diff -puN arch/x86/entry/entry_32.S~SYSENTER-rename arch/x86/entry/entry_32.S
--- a/arch/x86/entry/entry_32.S~SYSENTER-rename 2017-12-04 12:21:09.159064609 -0800
+++ b/arch/x86/entry/entry_32.S 2017-12-04 12:21:09.179064609 -0800
@@ -942,9 +942,9 @@ ENTRY(debug)

/* Are we currently on the SYSENTER stack? */
movl PER_CPU_VAR(cpu_entry_area), %ecx
- addl $CPU_ENTRY_AREA_SYSENTER_stack + SIZEOF_SYSENTER_stack, %ecx
- subl %eax, %ecx /* ecx = (end of SYSENTER_stack) - esp */
- cmpl $SIZEOF_SYSENTER_stack, %ecx
+ addl $CPU_ENTRY_AREA_entry_stack + SIZEOF_entry_stack, %ecx
+ subl %eax, %ecx /* ecx = (end of entry_stack) - esp */
+ cmpl $SIZEOF_entry_stack, %ecx
jb .Ldebug_from_sysenter_stack

TRACE_IRQS_OFF
@@ -986,9 +986,9 @@ ENTRY(nmi)

/* Are we currently on the SYSENTER stack? */
movl PER_CPU_VAR(cpu_entry_area), %ecx
- addl $CPU_ENTRY_AREA_SYSENTER_stack + SIZEOF_SYSENTER_stack, %ecx
- subl %eax, %ecx /* ecx = (end of SYSENTER_stack) - esp */
- cmpl $SIZEOF_SYSENTER_stack, %ecx
+ addl $CPU_ENTRY_AREA_entry_stack + SIZEOF_entry_stack, %ecx
+ subl %eax, %ecx /* ecx = (end of entry_stack) - esp */
+ cmpl $SIZEOF_entry_stack, %ecx
jb .Lnmi_from_sysenter_stack

/* Not on SYSENTER stack. */
diff -puN arch/x86/kernel/asm-offsets.c~SYSENTER-rename arch/x86/kernel/asm-offsets.c
--- a/arch/x86/kernel/asm-offsets.c~SYSENTER-rename 2017-12-04 12:21:09.161064609 -0800
+++ b/arch/x86/kernel/asm-offsets.c 2017-12-04 12:21:09.180064609 -0800
@@ -99,6 +99,6 @@ void common(void) {
OFFSET(CPU_ENTRY_AREA_tss, cpu_entry_area, tss);
OFFSET(CPU_ENTRY_AREA_entry_trampoline, cpu_entry_area, entry_trampoline);
OFFSET(TLB_STATE_user_pcid_flush_mask, tlb_state, user_pcid_flush_mask);
- OFFSET(CPU_ENTRY_AREA_SYSENTER_stack, cpu_entry_area, SYSENTER_stack_page);
- DEFINE(SIZEOF_SYSENTER_stack, sizeof(struct SYSENTER_stack));
+ OFFSET(CPU_ENTRY_AREA_entry_stack, cpu_entry_area, entry_stack_page);
+ DEFINE(SIZEOF_entry_stack, sizeof(struct entry_stack));
}
diff -puN arch/x86/kernel/asm-offsets_32.c~SYSENTER-rename arch/x86/kernel/asm-offsets_32.c
--- a/arch/x86/kernel/asm-offsets_32.c~SYSENTER-rename 2017-12-04 12:21:09.162064609 -0800
+++ b/arch/x86/kernel/asm-offsets_32.c 2017-12-04 12:21:09.180064609 -0800
@@ -48,7 +48,7 @@ void foo(void)

/* Offset from the sysenter stack to tss.sp0 */
DEFINE(TSS_sysenter_sp0, offsetof(struct cpu_entry_area, tss.x86_tss.sp0) -
- offsetofend(struct cpu_entry_area, SYSENTER_stack_page.stack));
+ offsetofend(struct cpu_entry_area, entry_stack_page.stack));

#ifdef CONFIG_CC_STACKPROTECTOR
BLANK();
diff -puN arch/x86/kernel/dumpstack.c~SYSENTER-rename arch/x86/kernel/dumpstack.c
--- a/arch/x86/kernel/dumpstack.c~SYSENTER-rename 2017-12-04 12:21:09.164064609 -0800
+++ b/arch/x86/kernel/dumpstack.c 2017-12-04 12:21:09.180064609 -0800
@@ -43,9 +43,9 @@ bool in_task_stack(unsigned long *stack,
return true;
}

-bool in_sysenter_stack(unsigned long *stack, struct stack_info *info)
+bool in_entry_stack(unsigned long *stack, struct stack_info *info)
{
- struct SYSENTER_stack *ss = cpu_SYSENTER_stack(smp_processor_id());
+ struct entry_stack *ss = cpu_entry_stack(smp_processor_id());

void *begin = ss;
void *end = ss + 1;
@@ -53,7 +53,7 @@ bool in_sysenter_stack(unsigned long *st
if ((void *)stack < begin || (void *)stack >= end)
return false;

- info->type = STACK_TYPE_SYSENTER;
+ info->type = STACK_TYPE_ENTRY;
info->begin = begin;
info->end = end;
info->next_sp = NULL;
@@ -111,13 +111,13 @@ void show_trace_log_lvl(struct task_stru
* - task stack
* - interrupt stack
* - HW exception stacks (double fault, nmi, debug, mce)
- * - SYSENTER stack
+ * - entry stack
*
* x86-32 can have up to four stacks:
* - task stack
* - softirq stack
* - hardirq stack
- * - SYSENTER stack
+ * - entry stack
*/
for (regs = NULL; stack; stack = PTR_ALIGN(stack_info.next_sp, sizeof(long))) {
const char *stack_name;
diff -puN arch/x86/kernel/dumpstack_32.c~SYSENTER-rename arch/x86/kernel/dumpstack_32.c
--- a/arch/x86/kernel/dumpstack_32.c~SYSENTER-rename 2017-12-04 12:21:09.166064609 -0800
+++ b/arch/x86/kernel/dumpstack_32.c 2017-12-04 12:21:09.180064609 -0800
@@ -26,8 +26,8 @@ const char *stack_type_name(enum stack_t
if (type == STACK_TYPE_SOFTIRQ)
return "SOFTIRQ";

- if (type == STACK_TYPE_SYSENTER)
- return "SYSENTER";
+ if (type == STACK_TYPE_ENTRY)
+ return "ENTRY_TRAMPOLINE";

return NULL;
}
@@ -96,7 +96,7 @@ int get_stack_info(unsigned long *stack,
if (task != current)
goto unknown;

- if (in_sysenter_stack(stack, info))
+ if (in_entry_stack(stack, info))
goto recursion_check;

if (in_hardirq_stack(stack, info))
diff -puN arch/x86/entry/entry_64.S~SYSENTER-rename arch/x86/entry/entry_64.S
--- a/arch/x86/entry/entry_64.S~SYSENTER-rename 2017-12-04 12:21:09.170064609 -0800
+++ b/arch/x86/entry/entry_64.S 2017-12-04 12:21:09.181064609 -0800
@@ -159,8 +159,8 @@ END(native_usergs_sysret64)
_entry_trampoline - CPU_ENTRY_AREA_entry_trampoline(%rip)

/* The top word of the SYSENTER stack is hot and is usable as scratch space. */
-#define RSP_SCRATCH CPU_ENTRY_AREA_SYSENTER_stack + \
- SIZEOF_SYSENTER_stack - 8 + CPU_ENTRY_AREA
+#define RSP_SCRATCH CPU_ENTRY_AREA_entry_stack + \
+ SIZEOF_entry_stack - 8 + CPU_ENTRY_AREA

ENTRY(entry_SYSCALL_64_trampoline)
UNWIND_HINT_EMPTY
_