1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef ARCH_S390_ENTRY_COMMON_H
3 #define ARCH_S390_ENTRY_COMMON_H
4 
5 #include <linux/sched.h>
6 #include <linux/audit.h>
7 #include <linux/randomize_kstack.h>
8 #include <linux/tracehook.h>
9 #include <linux/processor.h>
10 #include <linux/uaccess.h>
11 #include <asm/timex.h>
12 #include <asm/fpu/api.h>
13 
14 #define ARCH_EXIT_TO_USER_MODE_WORK (_TIF_GUARDED_STORAGE | _TIF_PER_TRAP)
15 
16 void do_per_trap(struct pt_regs *regs);
17 void do_syscall(struct pt_regs *regs);
18 
19 #ifdef CONFIG_DEBUG_ENTRY
20 static __always_inline void arch_check_user_regs(struct pt_regs *regs)
21 {
22 	debug_user_asce(0);
23 }
24 
25 #define arch_check_user_regs arch_check_user_regs
26 #endif /* CONFIG_DEBUG_ENTRY */
27 
28 static __always_inline void arch_exit_to_user_mode_work(struct pt_regs *regs,
29 							unsigned long ti_work)
30 {
31 	if (ti_work & _TIF_PER_TRAP) {
32 		clear_thread_flag(TIF_PER_TRAP);
33 		do_per_trap(regs);
34 	}
35 
36 	if (ti_work & _TIF_GUARDED_STORAGE)
37 		gs_load_bc_cb(regs);
38 }
39 
40 #define arch_exit_to_user_mode_work arch_exit_to_user_mode_work
41 
42 static __always_inline void arch_exit_to_user_mode(void)
43 {
44 	if (test_cpu_flag(CIF_FPU))
45 		__load_fpu_regs();
46 
47 	if (IS_ENABLED(CONFIG_DEBUG_ENTRY))
48 		debug_user_asce(1);
49 }
50 
51 #define arch_exit_to_user_mode arch_exit_to_user_mode
52 
53 static inline void arch_exit_to_user_mode_prepare(struct pt_regs *regs,
54 						  unsigned long ti_work)
55 {
56 	choose_random_kstack_offset(get_tod_clock_fast() & 0xff);
57 }
58 
59 #define arch_exit_to_user_mode_prepare arch_exit_to_user_mode_prepare
60 
61 static inline bool on_thread_stack(void)
62 {
63 	return !(((unsigned long)(current->stack) ^ current_stack_pointer()) & ~(THREAD_SIZE - 1));
64 }
65 
66 #endif
67