From 9f8e9c232eaa4068f987c0283db97a6739ae4384 Mon Sep 17 00:00:00 2001 From: Johannes Wikner Date: Mon, 28 Aug 2023 12:36:46 +0200 Subject: [PATCH] sysenter: use the percpu->tss.rsp0 kernel stack Instead of allocating a new kernel stack just for sysenters, use the already-allocated kernel stack. Signed-off-by: Johannes Wikner --- arch/x86/entry.S | 3 ++- common/usermode.c | 6 +++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/arch/x86/entry.S b/arch/x86/entry.S index 90bb6ede..6ffd56c8 100644 --- a/arch/x86/entry.S +++ b/arch/x86/entry.S @@ -180,9 +180,10 @@ ENTRY(enter_usermode) SAVE_ALL_REGS PUSHF - /* Save stack pointer onto per-cpu */ + /* Save user stack pointer onto per-cpu */ mov %_ASM_DX, %gs:(usermode_private) + /* Now switch stack and address space */ syscall_to_usermode /* SS + SP */ diff --git a/common/usermode.c b/common/usermode.c index 64e252c0..088b8169 100644 --- a/common/usermode.c +++ b/common/usermode.c @@ -93,9 +93,9 @@ static void init_syscall(void) { wrmsr(MSR_EFER, rdmsr(MSR_EFER) | EFER_SCE); } -static void init_sysenter(void) { +static void init_sysenter(percpu_t *percpu) { wrmsr(MSR_SYSENTER_CS, _ul(__KERN_CS)); - wrmsr(MSR_SYSENTER_ESP, _ul(get_free_page_top(GFP_KERNEL | GFP_USER))); + wrmsr(MSR_SYSENTER_ESP, _ul(percpu->tss.rsp0)); wrmsr(MSR_SYSENTER_EIP, _ul(&sysenter_handler_entry)); } @@ -113,7 +113,7 @@ void init_usermode(percpu_t *percpu) { vmap_user_4k(usermode_helpers, virt_to_mfn(usermode_helpers), L1_PROT); init_syscall(); - init_sysenter(); + init_sysenter(percpu); set_intr_gate(&percpu->idt[SYSCALL_INT], __KERN_CS, _ul(int80_handler_entry), GATE_DPL3, GATE_PRESENT, 0); }