xref: /linux/arch/s390/include/asm/entry-common.h (revision 691632f0e86973604678d193ccfa47b9614581aa)
156e62a73SSven Schnelle /* SPDX-License-Identifier: GPL-2.0 */
256e62a73SSven Schnelle #ifndef ARCH_S390_ENTRY_COMMON_H
356e62a73SSven Schnelle #define ARCH_S390_ENTRY_COMMON_H
456e62a73SSven Schnelle 
556e62a73SSven Schnelle #include <linux/sched.h>
656e62a73SSven Schnelle #include <linux/audit.h>
7bae1cd36SSven Schnelle #include <linux/randomize_kstack.h>
856e62a73SSven Schnelle #include <linux/processor.h>
956e62a73SSven Schnelle #include <linux/uaccess.h>
10bae1cd36SSven Schnelle #include <asm/timex.h>
11fd2527f2SHeiko Carstens #include <asm/fpu.h>
1239d62336SThomas Richter #include <asm/pai.h>
1356e62a73SSven Schnelle 
1456e62a73SSven Schnelle #define ARCH_EXIT_TO_USER_MODE_WORK (_TIF_GUARDED_STORAGE | _TIF_PER_TRAP)
1556e62a73SSven Schnelle 
1656e62a73SSven Schnelle void do_per_trap(struct pt_regs *regs);
1756e62a73SSven Schnelle 
arch_enter_from_user_mode(struct pt_regs * regs)186d97af48SSven Schnelle static __always_inline void arch_enter_from_user_mode(struct pt_regs *regs)
1956e62a73SSven Schnelle {
2039d62336SThomas Richter 	if (IS_ENABLED(CONFIG_DEBUG_ENTRY))
2156e62a73SSven Schnelle 		debug_user_asce(0);
2239d62336SThomas Richter 
2339d62336SThomas Richter 	pai_kernel_enter(regs);
2456e62a73SSven Schnelle }
2556e62a73SSven Schnelle 
266d97af48SSven Schnelle #define arch_enter_from_user_mode arch_enter_from_user_mode
2756e62a73SSven Schnelle 
arch_exit_to_user_mode_work(struct pt_regs * regs,unsigned long ti_work)2856e62a73SSven Schnelle static __always_inline void arch_exit_to_user_mode_work(struct pt_regs *regs,
2956e62a73SSven Schnelle 							unsigned long ti_work)
3056e62a73SSven Schnelle {
3156e62a73SSven Schnelle 	if (ti_work & _TIF_PER_TRAP) {
3256e62a73SSven Schnelle 		clear_thread_flag(TIF_PER_TRAP);
3356e62a73SSven Schnelle 		do_per_trap(regs);
3456e62a73SSven Schnelle 	}
3556e62a73SSven Schnelle 
3656e62a73SSven Schnelle 	if (ti_work & _TIF_GUARDED_STORAGE)
3756e62a73SSven Schnelle 		gs_load_bc_cb(regs);
3856e62a73SSven Schnelle }
3956e62a73SSven Schnelle 
4056e62a73SSven Schnelle #define arch_exit_to_user_mode_work arch_exit_to_user_mode_work
4156e62a73SSven Schnelle 
arch_exit_to_user_mode(void)4256e62a73SSven Schnelle static __always_inline void arch_exit_to_user_mode(void)
4356e62a73SSven Schnelle {
44*8c09871aSHeiko Carstens 	load_user_fpu_regs();
4556e62a73SSven Schnelle 
4656e62a73SSven Schnelle 	if (IS_ENABLED(CONFIG_DEBUG_ENTRY))
4756e62a73SSven Schnelle 		debug_user_asce(1);
4839d62336SThomas Richter 
4939d62336SThomas Richter 	pai_kernel_exit(current_pt_regs());
5056e62a73SSven Schnelle }
5156e62a73SSven Schnelle 
5256e62a73SSven Schnelle #define arch_exit_to_user_mode arch_exit_to_user_mode
5356e62a73SSven Schnelle 
arch_exit_to_user_mode_prepare(struct pt_regs * regs,unsigned long ti_work)54bae1cd36SSven Schnelle static inline void arch_exit_to_user_mode_prepare(struct pt_regs *regs,
55bae1cd36SSven Schnelle 						  unsigned long ti_work)
56bae1cd36SSven Schnelle {
57bae1cd36SSven Schnelle 	choose_random_kstack_offset(get_tod_clock_fast());
58bae1cd36SSven Schnelle }
59bae1cd36SSven Schnelle 
60bae1cd36SSven Schnelle #define arch_exit_to_user_mode_prepare arch_exit_to_user_mode_prepare
61bae1cd36SSven Schnelle 
arch_in_rcu_eqs(void)6256e62a73SSven Schnelle static __always_inline bool arch_in_rcu_eqs(void)
63 {
64 	if (IS_ENABLED(CONFIG_KVM))
65 		return current->flags & PF_VCPU;
66 
67 	return false;
68 }
69 
70 #define arch_in_rcu_eqs arch_in_rcu_eqs
71 
72 #endif
73