From 3f8482c472afd268769889147fd2c6d53f18758d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Duval?= Date: Tue, 5 Oct 2021 20:59:01 +0200 Subject: [PATCH] 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 84f6e2d39f55a1eeac8387e9cb456018d522afbd 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 Reviewed-by: Fredrik Holmqvist Reviewed-by: Adrien Destugues --- src/system/kernel/arch/x86/64/entry_compat.S | 2 -- src/system/kernel/arch/x86/64/interrupts.S | 7 ------- 2 files changed, 9 deletions(-) diff --git a/src/system/kernel/arch/x86/64/entry_compat.S b/src/system/kernel/arch/x86/64/entry_compat.S index 1e58379183..855044ae9c 100644 --- a/src/system/kernel/arch/x86/64/entry_compat.S +++ b/src/system/kernel/arch/x86/64/entry_compat.S @@ -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 diff --git a/src/system/kernel/arch/x86/64/interrupts.S b/src/system/kernel/arch/x86/64/interrupts.S index 124fe061a3..0040f2d39c 100644 --- a/src/system/kernel/arch/x86/64/interrupts.S +++ b/src/system/kernel/arch/x86/64/interrupts.S @@ -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