0001
0002 #ifndef _ASM_X86_ENTRY_COMMON_H
0003 #define _ASM_X86_ENTRY_COMMON_H
0004
0005 #include <linux/randomize_kstack.h>
0006 #include <linux/user-return-notifier.h>
0007
0008 #include <asm/nospec-branch.h>
0009 #include <asm/io_bitmap.h>
0010 #include <asm/fpu/api.h>
0011
0012
0013 static __always_inline void arch_enter_from_user_mode(struct pt_regs *regs)
0014 {
0015 if (IS_ENABLED(CONFIG_DEBUG_ENTRY)) {
0016
0017
0018
0019
0020
0021 unsigned long flags = native_save_fl();
0022 unsigned long mask = X86_EFLAGS_DF | X86_EFLAGS_NT;
0023
0024
0025
0026
0027 if (boot_cpu_has(X86_FEATURE_SMAP) ||
0028 (IS_ENABLED(CONFIG_64BIT) && boot_cpu_has(X86_FEATURE_XENPV)))
0029 mask |= X86_EFLAGS_AC;
0030
0031 WARN_ON_ONCE(flags & mask);
0032
0033
0034 WARN_ON_ONCE(!user_mode(regs));
0035
0036
0037
0038
0039
0040
0041 WARN_ON_ONCE(!on_thread_stack());
0042 WARN_ON_ONCE(regs != task_pt_regs(current));
0043 }
0044 }
0045 #define arch_enter_from_user_mode arch_enter_from_user_mode
0046
0047 static inline void arch_exit_to_user_mode_prepare(struct pt_regs *regs,
0048 unsigned long ti_work)
0049 {
0050 if (ti_work & _TIF_USER_RETURN_NOTIFY)
0051 fire_user_return_notifiers();
0052
0053 if (unlikely(ti_work & _TIF_IO_BITMAP))
0054 tss_update_io_bitmap();
0055
0056 fpregs_assert_state_consistent();
0057 if (unlikely(ti_work & _TIF_NEED_FPU_LOAD))
0058 switch_fpu_return();
0059
0060 #ifdef CONFIG_COMPAT
0061
0062
0063
0064
0065
0066
0067
0068
0069
0070
0071
0072 current_thread_info()->status &= ~(TS_COMPAT | TS_I386_REGS_POKED);
0073 #endif
0074
0075
0076
0077
0078
0079
0080
0081
0082
0083
0084
0085
0086
0087
0088 choose_random_kstack_offset(rdtsc() & 0xFF);
0089 }
0090 #define arch_exit_to_user_mode_prepare arch_exit_to_user_mode_prepare
0091
0092 static __always_inline void arch_exit_to_user_mode(void)
0093 {
0094 mds_user_clear_cpu_buffers();
0095 }
0096 #define arch_exit_to_user_mode arch_exit_to_user_mode
0097
0098 #endif