xref: /linux/arch/arm64/include/asm/entry-common.h (revision feafee284579d29537a5a56ba8f23894f0463f3d)
1 /* SPDX-License-Identifier: GPL-2.0 */
2 
3 #ifndef _ASM_ARM64_ENTRY_COMMON_H
4 #define _ASM_ARM64_ENTRY_COMMON_H
5 
6 #include <linux/thread_info.h>
7 
8 #include <asm/cpufeature.h>
9 #include <asm/daifflags.h>
10 #include <asm/fpsimd.h>
11 #include <asm/mte.h>
12 #include <asm/stacktrace.h>
13 
14 #define ARCH_EXIT_TO_USER_MODE_WORK (_TIF_MTE_ASYNC_FAULT | _TIF_FOREIGN_FPSTATE)
15 
arch_exit_to_user_mode_work(struct pt_regs * regs,unsigned long ti_work)16 static __always_inline void arch_exit_to_user_mode_work(struct pt_regs *regs,
17 							unsigned long ti_work)
18 {
19 	if (ti_work & _TIF_MTE_ASYNC_FAULT) {
20 		clear_thread_flag(TIF_MTE_ASYNC_FAULT);
21 		send_sig_fault(SIGSEGV, SEGV_MTEAERR, (void __user *)NULL, current);
22 	}
23 
24 	if (ti_work & _TIF_FOREIGN_FPSTATE)
25 		fpsimd_restore_current_state();
26 }
27 
28 #define arch_exit_to_user_mode_work arch_exit_to_user_mode_work
29 
arch_irqentry_exit_need_resched(void)30 static inline bool arch_irqentry_exit_need_resched(void)
31 {
32 	/*
33 	 * DAIF.DA are cleared at the start of IRQ/FIQ handling, and when GIC
34 	 * priority masking is used the GIC irqchip driver will clear DAIF.IF
35 	 * using gic_arch_enable_irqs() for normal IRQs. If anything is set in
36 	 * DAIF we must have handled an NMI, so skip preemption.
37 	 */
38 	if (system_uses_irq_prio_masking() && read_sysreg(daif))
39 		return false;
40 
41 	/*
42 	 * Preempting a task from an IRQ means we leave copies of PSTATE
43 	 * on the stack. cpufeature's enable calls may modify PSTATE, but
44 	 * resuming one of these preempted tasks would undo those changes.
45 	 *
46 	 * Only allow a task to be preempted once cpufeatures have been
47 	 * enabled.
48 	 */
49 	if (!system_capabilities_finalized())
50 		return false;
51 
52 	return true;
53 }
54 
55 #define arch_irqentry_exit_need_resched arch_irqentry_exit_need_resched
56 
57 #endif /* _ASM_ARM64_ENTRY_COMMON_H */
58