entry-common.h 1.6 KB

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