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