Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
sysenter: use the percpu->tss.rsp0 kernel stack
Browse files Browse the repository at this point in the history
Instead of allocating a new kernel stack just for sysenters, use the
already-allocated kernel stack.

Signed-off-by: Johannes Wikner <johannes.wikner@gmail.com>
sktt committed Aug 28, 2023
1 parent ca6b946 commit b60cec7
Showing 2 changed files with 5 additions and 4 deletions.
3 changes: 2 additions & 1 deletion arch/x86/entry.S
Original file line number Diff line number Diff line change
@@ -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 */
6 changes: 3 additions & 3 deletions common/usermode.c
Original file line number Diff line number Diff line change
@@ -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);
}

0 comments on commit b60cec7

Please sign in to comment.