kernel/x86_64: remove lfence after swapgs on syscall entry and exit

in a syscall, swapgs is always executed and can't be speculatively executed or bypassed.
it's also not needed on exception/interrupt exit, only on exception/interrupt entry.
follow-up on commit 84f6e2d39f by waddlesplash

(https://github.com/freebsd/freebsd-src/commit/7aa47cace14948a7b8277a4b24a0ca9e0308990a)

Change-Id: I56de9526a1acd0075c4a12147ae782f0366dec52
Reviewed-on: https://review.haiku-os.org/c/haiku/+/4557
Tested-by: Commit checker robot <[email protected]>
Reviewed-by: Fredrik Holmqvist <[email protected]>
Reviewed-by: Adrien Destugues <[email protected]>
This commit is contained in:
Jérôme Duval
2021-10-09 18:54:16 +00:00
parent 98193d2688
commit 3f8482c472
2 changed files with 0 additions and 9 deletions
@@ -152,7 +152,6 @@ FUNCTION_END(x86_64_syscall32_entry)
// ecx - user esp
FUNCTION(x86_64_sysenter32_entry):
swapgs
lfence
// Set up an iframe on the stack (ECX = saved ESP).
push $USER_DATA_SELECTOR // ss
@@ -315,7 +314,6 @@ FUNCTION(x86_64_sysenter32_entry):
// Restore previous GS base and return.
swapgs
lfence
sti
sysexit
@@ -328,7 +328,6 @@ STATIC_FUNCTION(int_bottom_user):
// Restore the previous GS base and return.
swapgs
lfence
iretq
.Lkernel_exit_work:
@@ -362,7 +361,6 @@ STATIC_FUNCTION(int_bottom_user):
// Restore the previous GS base and return.
swapgs
lfence
iretq
.Lkernel_exit_handle_signals:
@@ -382,7 +380,6 @@ FUNCTION(x86_64_syscall_entry):
// scratch space to store the user stack pointer in before we can push it
// to the stack.
swapgs
lfence
movq %rsp, %gs:ARCH_THREAD_user_rsp
movq %gs:ARCH_THREAD_syscall_rsp, %rsp
@@ -495,7 +492,6 @@ FUNCTION(x86_64_syscall_entry):
// Restore previous GS base and return.
swapgs
lfence
sysretq
.Lpre_syscall_debug:
@@ -574,7 +570,6 @@ FUNCTION(x86_64_syscall_entry):
// Restore the previous GS base and return.
swapgs
lfence
iretq
.Lpost_syscall_handle_signals:
@@ -651,7 +646,6 @@ FUNCTION(x86_return_to_userland):
// Restore the frame and return.
RESTORE_IFRAME()
swapgs
lfence
iretq
.Luserland_return_work:
// Slow path for return to userland.
@@ -676,7 +670,6 @@ FUNCTION(x86_return_to_userland):
// Restore the previous GS base and return.
swapgs
lfence
iretq
.Luserland_return_handle_signals:
// thread_at_kernel_exit requires interrupts to be enabled, it will disable