0001
0002 #ifndef ARCH_S390_ENTRY_COMMON_H
0003 #define ARCH_S390_ENTRY_COMMON_H
0004
0005 #include <linux/sched.h>
0006 #include <linux/audit.h>
0007 #include <linux/randomize_kstack.h>
0008 #include <linux/processor.h>
0009 #include <linux/uaccess.h>
0010 #include <asm/timex.h>
0011 #include <asm/fpu/api.h>
0012 #include <asm/pai.h>
0013
0014 #define ARCH_EXIT_TO_USER_MODE_WORK (_TIF_GUARDED_STORAGE | _TIF_PER_TRAP)
0015
0016 void do_per_trap(struct pt_regs *regs);
0017
0018 static __always_inline void arch_enter_from_user_mode(struct pt_regs *regs)
0019 {
0020 if (IS_ENABLED(CONFIG_DEBUG_ENTRY))
0021 debug_user_asce(0);
0022
0023 pai_kernel_enter(regs);
0024 }
0025
0026 #define arch_enter_from_user_mode arch_enter_from_user_mode
0027
0028 static __always_inline void arch_exit_to_user_mode_work(struct pt_regs *regs,
0029 unsigned long ti_work)
0030 {
0031 if (ti_work & _TIF_PER_TRAP) {
0032 clear_thread_flag(TIF_PER_TRAP);
0033 do_per_trap(regs);
0034 }
0035
0036 if (ti_work & _TIF_GUARDED_STORAGE)
0037 gs_load_bc_cb(regs);
0038 }
0039
0040 #define arch_exit_to_user_mode_work arch_exit_to_user_mode_work
0041
0042 static __always_inline void arch_exit_to_user_mode(void)
0043 {
0044 if (test_cpu_flag(CIF_FPU))
0045 __load_fpu_regs();
0046
0047 if (IS_ENABLED(CONFIG_DEBUG_ENTRY))
0048 debug_user_asce(1);
0049
0050 pai_kernel_exit(current_pt_regs());
0051 }
0052
0053 #define arch_exit_to_user_mode arch_exit_to_user_mode
0054
0055 static inline void arch_exit_to_user_mode_prepare(struct pt_regs *regs,
0056 unsigned long ti_work)
0057 {
0058 choose_random_kstack_offset(get_tod_clock_fast() & 0xff);
0059 }
0060
0061 #define arch_exit_to_user_mode_prepare arch_exit_to_user_mode_prepare
0062
0063 static inline bool on_thread_stack(void)
0064 {
0065 return !(((unsigned long)(current->stack) ^ current_stack_pointer) & ~(THREAD_SIZE - 1));
0066 }
0067
0068 #endif