Debian Codegraph @

arch/arm64/include/asm/entry-common.h

raw
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
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
30 static inline bool arch_irqentry_exit_need_resched(void)
31 {
32 if (system_uses_irq_prio_masking()) {
33 /*
34 * DAIF.DA are cleared at the start of IRQ/FIQ handling, and when GIC
35 * priority masking is used the GIC irqchip driver will clear DAIF.IF
36 * using gic_arch_enable_irqs() for normal IRQs. If anything is set in
37 * DAIF we must have handled an NMI, so skip preemption.
38 */
39 if (read_sysreg(daif))
40 return false;
41 } else {
42 if (read_sysreg(daif) & (PSR_D_BIT | PSR_A_BIT))
43 return false;
44 }
45
46 /*
47 * Preempting a task from an IRQ means we leave copies of PSTATE
48 * on the stack. cpufeature's enable calls may modify PSTATE, but
49 * resuming one of these preempted tasks would undo those changes.
50 *
51 * Only allow a task to be preempted once cpufeatures have been
52 * enabled.
53 */
54 if (!system_capabilities_finalized())
55 return false;
56
57 return true;
58 }
59
60 #define arch_irqentry_exit_need_resched arch_irqentry_exit_need_resched
61
62 #endif /* _ASM_ARM64_ENTRY_COMMON_H */