Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

entry: disable interrupts during usermode transition #316

Merged
merged 2 commits into from
Nov 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions arch/x86/entry.S
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,10 @@ ENTRY(syscall_exit)
SWITCH_STACK
POPF

/* Restore default GS (PERCPU) segment selector */
mov $__KERN_PERCPU, %_ASM_AX
mov %_ASM_AX, %gs

/* Save exit code to return value register (AX) */
mov %_ASM_SI, cpu_regs_ax(%_ASM_SP)
RESTORE_ALL_REGS
Expand All @@ -196,6 +200,9 @@ ENTRY(enter_usermode)
SAVE_ALL_REGS
PUSHF

/* Disable interrupts for stack switch and swapgs */
cli

/* Save user stack pointer onto per-cpu */
mov %_ASM_DX, %gs:(usermode_private)

Expand All @@ -208,8 +215,8 @@ ENTRY(enter_usermode)

/* EFLAGS */
PUSHF

orl $X86_EFLAGS_IOPL, (%_ASM_SP)
/* Set IOPL=3 and re-enable interrupts via IRET */
orl $(X86_EFLAGS_IOPL | X86_EFLAGS_IF), (%_ASM_SP)

/* CS + IP */
push $__USER_CS
Expand Down
2 changes: 1 addition & 1 deletion arch/x86/traps.c
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ static void init_gdt(percpu_t *percpu) {
lgdt(&percpu->gdt_ptr);

write_ss(__KERN_DS);
write_gs(GDT_PERCPU << 3);
write_gs(__KERN_PERCPU);
wrmsr(MSR_KERNEL_GS_BASE, 0x0);

init_tss(percpu);
Expand Down
2 changes: 2 additions & 0 deletions include/arch/x86/segment.h
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,8 @@
#define __USER_DS __USER_DS64
#endif

#define __KERN_PERCPU (GDT_PERCPU << 3)

#define _GDT_ENTRY(flags, base, limit) \
((((base) &_U64(0xff000000)) << (56 - 24)) | (((flags) &_U64(0x0000f0ff)) << 40) | \
(((limit) &_U64(0x000f0000)) << (48 - 16)) | (((base) &_U64(0x00ffffff)) << 16) | \
Expand Down
Loading