1 // SPDX-License-Identifier: GPL-2.0
3 * Exception handling code
5 * Copyright (C) 2019 ARM Ltd.
8 #include <linux/context_tracking.h>
9 #include <linux/kasan.h>
10 #include <linux/linkage.h>
11 #include <linux/lockdep.h>
12 #include <linux/ptrace.h>
13 #include <linux/resume_user_mode.h>
14 #include <linux/sched.h>
15 #include <linux/sched/debug.h>
16 #include <linux/thread_info.h>
18 #include <asm/cpufeature.h>
19 #include <asm/daifflags.h>
21 #include <asm/exception.h>
22 #include <asm/irq_regs.h>
23 #include <asm/kprobes.h>
25 #include <asm/processor.h>
27 #include <asm/stacktrace.h>
28 #include <asm/sysreg.h>
29 #include <asm/system_misc.h>
32 * Handle IRQ/context state management when entering from kernel mode.
33 * Before this function is called it is not safe to call regular kernel code,
34 * instrumentable code, or any code which may trigger an exception.
36 * This is intended to match the logic in irqentry_enter(), handling the kernel
37 * mode transitions only.
39 static __always_inline void __enter_from_kernel_mode(struct pt_regs *regs)
41 regs->exit_rcu = false;
43 if (!IS_ENABLED(CONFIG_TINY_RCU) && is_idle_task(current)) {
44 lockdep_hardirqs_off(CALLER_ADDR0);
46 trace_hardirqs_off_finish();
48 regs->exit_rcu = true;
52 lockdep_hardirqs_off(CALLER_ADDR0);
53 rcu_irq_enter_check_tick();
54 trace_hardirqs_off_finish();
57 static void noinstr enter_from_kernel_mode(struct pt_regs *regs)
59 __enter_from_kernel_mode(regs);
60 mte_check_tfsr_entry();
61 mte_disable_tco_entry(current);
65 * Handle IRQ/context state management when exiting to kernel mode.
66 * After this function returns it is not safe to call regular kernel code,
67 * instrumentable code, or any code which may trigger an exception.
69 * This is intended to match the logic in irqentry_exit(), handling the kernel
70 * mode transitions only, and with preemption handled elsewhere.
72 static __always_inline void __exit_to_kernel_mode(struct pt_regs *regs)
74 lockdep_assert_irqs_disabled();
76 if (interrupts_enabled(regs)) {
78 trace_hardirqs_on_prepare();
79 lockdep_hardirqs_on_prepare();
81 lockdep_hardirqs_on(CALLER_ADDR0);
92 static void noinstr exit_to_kernel_mode(struct pt_regs *regs)
94 mte_check_tfsr_exit();
95 __exit_to_kernel_mode(regs);
99 * Handle IRQ/context state management when entering from user mode.
100 * Before this function is called it is not safe to call regular kernel code,
101 * instrumentable code, or any code which may trigger an exception.
103 static __always_inline void __enter_from_user_mode(void)
105 lockdep_hardirqs_off(CALLER_ADDR0);
106 CT_WARN_ON(ct_state() != CONTEXT_USER);
108 trace_hardirqs_off_finish();
109 mte_disable_tco_entry(current);
112 static __always_inline void enter_from_user_mode(struct pt_regs *regs)
114 __enter_from_user_mode();
118 * Handle IRQ/context state management when exiting to user mode.
119 * After this function returns it is not safe to call regular kernel code,
120 * instrumentable code, or any code which may trigger an exception.
122 static __always_inline void __exit_to_user_mode(void)
124 trace_hardirqs_on_prepare();
125 lockdep_hardirqs_on_prepare();
127 lockdep_hardirqs_on(CALLER_ADDR0);
130 static void do_notify_resume(struct pt_regs *regs, unsigned long thread_flags)
135 if (thread_flags & _TIF_NEED_RESCHED)
138 if (thread_flags & _TIF_UPROBE)
139 uprobe_notify_resume(regs);
141 if (thread_flags & _TIF_MTE_ASYNC_FAULT) {
142 clear_thread_flag(TIF_MTE_ASYNC_FAULT);
143 send_sig_fault(SIGSEGV, SEGV_MTEAERR,
144 (void __user *)NULL, current);
147 if (thread_flags & (_TIF_SIGPENDING | _TIF_NOTIFY_SIGNAL))
150 if (thread_flags & _TIF_NOTIFY_RESUME)
151 resume_user_mode_work(regs);
153 if (thread_flags & _TIF_FOREIGN_FPSTATE)
154 fpsimd_restore_current_state();
157 thread_flags = read_thread_flags();
158 } while (thread_flags & _TIF_WORK_MASK);
161 static __always_inline void exit_to_user_mode_prepare(struct pt_regs *regs)
167 flags = read_thread_flags();
168 if (unlikely(flags & _TIF_WORK_MASK))
169 do_notify_resume(regs, flags);
176 static __always_inline void exit_to_user_mode(struct pt_regs *regs)
178 exit_to_user_mode_prepare(regs);
179 mte_check_tfsr_exit();
180 __exit_to_user_mode();
183 asmlinkage void noinstr asm_exit_to_user_mode(struct pt_regs *regs)
185 exit_to_user_mode(regs);
189 * Handle IRQ/context state management when entering an NMI from user/kernel
190 * mode. Before this function is called it is not safe to call regular kernel
191 * code, instrumentable code, or any code which may trigger an exception.
193 static void noinstr arm64_enter_nmi(struct pt_regs *regs)
195 regs->lockdep_hardirqs = lockdep_hardirqs_enabled();
198 lockdep_hardirqs_off(CALLER_ADDR0);
199 lockdep_hardirq_enter();
202 trace_hardirqs_off_finish();
207 * Handle IRQ/context state management when exiting an NMI from user/kernel
208 * mode. After this function returns it is not safe to call regular kernel
209 * code, instrumentable code, or any code which may trigger an exception.
211 static void noinstr arm64_exit_nmi(struct pt_regs *regs)
213 bool restore = regs->lockdep_hardirqs;
217 trace_hardirqs_on_prepare();
218 lockdep_hardirqs_on_prepare();
222 lockdep_hardirq_exit();
224 lockdep_hardirqs_on(CALLER_ADDR0);
229 * Handle IRQ/context state management when entering a debug exception from
230 * kernel mode. Before this function is called it is not safe to call regular
231 * kernel code, instrumentable code, or any code which may trigger an exception.
233 static void noinstr arm64_enter_el1_dbg(struct pt_regs *regs)
235 regs->lockdep_hardirqs = lockdep_hardirqs_enabled();
237 lockdep_hardirqs_off(CALLER_ADDR0);
240 trace_hardirqs_off_finish();
244 * Handle IRQ/context state management when exiting a debug exception from
245 * kernel mode. After this function returns it is not safe to call regular
246 * kernel code, instrumentable code, or any code which may trigger an exception.
248 static void noinstr arm64_exit_el1_dbg(struct pt_regs *regs)
250 bool restore = regs->lockdep_hardirqs;
253 trace_hardirqs_on_prepare();
254 lockdep_hardirqs_on_prepare();
259 lockdep_hardirqs_on(CALLER_ADDR0);
262 #ifdef CONFIG_PREEMPT_DYNAMIC
263 DEFINE_STATIC_KEY_TRUE(sk_dynamic_irqentry_exit_cond_resched);
264 #define need_irq_preemption() \
265 (static_branch_unlikely(&sk_dynamic_irqentry_exit_cond_resched))
267 #define need_irq_preemption() (IS_ENABLED(CONFIG_PREEMPTION))
270 static void __sched arm64_preempt_schedule_irq(void)
272 if (!need_irq_preemption())
276 * Note: thread_info::preempt_count includes both thread_info::count
277 * and thread_info::need_resched, and is not equivalent to
280 if (READ_ONCE(current_thread_info()->preempt_count) != 0)
284 * DAIF.DA are cleared at the start of IRQ/FIQ handling, and when GIC
285 * priority masking is used the GIC irqchip driver will clear DAIF.IF
286 * using gic_arch_enable_irqs() for normal IRQs. If anything is set in
287 * DAIF we must have handled an NMI, so skip preemption.
289 if (system_uses_irq_prio_masking() && read_sysreg(daif))
293 * Preempting a task from an IRQ means we leave copies of PSTATE
294 * on the stack. cpufeature's enable calls may modify PSTATE, but
295 * resuming one of these preempted tasks would undo those changes.
297 * Only allow a task to be preempted once cpufeatures have been
300 if (system_capabilities_finalized())
301 preempt_schedule_irq();
304 static void do_interrupt_handler(struct pt_regs *regs,
305 void (*handler)(struct pt_regs *))
307 struct pt_regs *old_regs = set_irq_regs(regs);
309 if (on_thread_stack())
310 call_on_irq_stack(regs, handler);
314 set_irq_regs(old_regs);
317 extern void (*handle_arch_irq)(struct pt_regs *);
318 extern void (*handle_arch_fiq)(struct pt_regs *);
320 static void noinstr __panic_unhandled(struct pt_regs *regs, const char *vector,
323 arm64_enter_nmi(regs);
327 pr_crit("Unhandled %s exception on CPU%d, ESR 0x%016lx -- %s\n",
328 vector, smp_processor_id(), esr,
329 esr_get_class_string(esr));
332 panic("Unhandled exception");
335 #define UNHANDLED(el, regsize, vector) \
336 asmlinkage void noinstr el##_##regsize##_##vector##_handler(struct pt_regs *regs) \
338 const char *desc = #regsize "-bit " #el " " #vector; \
339 __panic_unhandled(regs, desc, read_sysreg(esr_el1)); \
342 #ifdef CONFIG_ARM64_ERRATUM_1463225
343 static DEFINE_PER_CPU(int, __in_cortex_a76_erratum_1463225_wa);
345 static void cortex_a76_erratum_1463225_svc_handler(void)
349 if (!unlikely(test_thread_flag(TIF_SINGLESTEP)))
352 if (!unlikely(this_cpu_has_cap(ARM64_WORKAROUND_1463225)))
355 __this_cpu_write(__in_cortex_a76_erratum_1463225_wa, 1);
356 reg = read_sysreg(mdscr_el1);
357 val = reg | DBG_MDSCR_SS | DBG_MDSCR_KDE;
358 write_sysreg(val, mdscr_el1);
359 asm volatile("msr daifclr, #8");
362 /* We will have taken a single-step exception by this point */
364 write_sysreg(reg, mdscr_el1);
365 __this_cpu_write(__in_cortex_a76_erratum_1463225_wa, 0);
368 static __always_inline bool
369 cortex_a76_erratum_1463225_debug_handler(struct pt_regs *regs)
371 if (!__this_cpu_read(__in_cortex_a76_erratum_1463225_wa))
375 * We've taken a dummy step exception from the kernel to ensure
376 * that interrupts are re-enabled on the syscall path. Return back
377 * to cortex_a76_erratum_1463225_svc_handler() with debug exceptions
378 * masked so that we can safely restore the mdscr and get on with
379 * handling the syscall.
381 regs->pstate |= PSR_D_BIT;
384 #else /* CONFIG_ARM64_ERRATUM_1463225 */
385 static void cortex_a76_erratum_1463225_svc_handler(void) { }
386 static bool cortex_a76_erratum_1463225_debug_handler(struct pt_regs *regs)
390 #endif /* CONFIG_ARM64_ERRATUM_1463225 */
393 * As per the ABI exit SME streaming mode and clear the SVE state not
394 * shared with FPSIMD on syscall entry.
396 static inline void fp_user_discard(void)
399 * If SME is active then exit streaming mode. If ZA is active
400 * then flush the SVE registers but leave userspace access to
401 * both SVE and SME enabled, otherwise disable SME for the
402 * task and fall through to disabling SVE too. This means
403 * that after a syscall we never have any streaming mode
404 * register state to track, if this changes the KVM code will
407 if (system_supports_sme())
410 if (!system_supports_sve())
413 if (test_thread_flag(TIF_SVE)) {
414 unsigned int sve_vq_minus_one;
416 sve_vq_minus_one = sve_vq_from_vl(task_get_sve_vl(current)) - 1;
417 sve_flush_live(true, sve_vq_minus_one);
421 UNHANDLED(el1t, 64, sync)
422 UNHANDLED(el1t, 64, irq)
423 UNHANDLED(el1t, 64, fiq)
424 UNHANDLED(el1t, 64, error)
426 static void noinstr el1_abort(struct pt_regs *regs, unsigned long esr)
428 unsigned long far = read_sysreg(far_el1);
430 enter_from_kernel_mode(regs);
431 local_daif_inherit(regs);
432 do_mem_abort(far, esr, regs);
434 exit_to_kernel_mode(regs);
437 static void noinstr el1_pc(struct pt_regs *regs, unsigned long esr)
439 unsigned long far = read_sysreg(far_el1);
441 enter_from_kernel_mode(regs);
442 local_daif_inherit(regs);
443 do_sp_pc_abort(far, esr, regs);
445 exit_to_kernel_mode(regs);
448 static void noinstr el1_undef(struct pt_regs *regs, unsigned long esr)
450 enter_from_kernel_mode(regs);
451 local_daif_inherit(regs);
452 do_el1_undef(regs, esr);
454 exit_to_kernel_mode(regs);
457 static void noinstr el1_bti(struct pt_regs *regs, unsigned long esr)
459 enter_from_kernel_mode(regs);
460 local_daif_inherit(regs);
461 do_el1_bti(regs, esr);
463 exit_to_kernel_mode(regs);
466 static void noinstr el1_dbg(struct pt_regs *regs, unsigned long esr)
468 unsigned long far = read_sysreg(far_el1);
470 arm64_enter_el1_dbg(regs);
471 if (!cortex_a76_erratum_1463225_debug_handler(regs))
472 do_debug_exception(far, esr, regs);
473 arm64_exit_el1_dbg(regs);
476 static void noinstr el1_fpac(struct pt_regs *regs, unsigned long esr)
478 enter_from_kernel_mode(regs);
479 local_daif_inherit(regs);
480 do_el1_fpac(regs, esr);
482 exit_to_kernel_mode(regs);
485 asmlinkage void noinstr el1h_64_sync_handler(struct pt_regs *regs)
487 unsigned long esr = read_sysreg(esr_el1);
489 switch (ESR_ELx_EC(esr)) {
490 case ESR_ELx_EC_DABT_CUR:
491 case ESR_ELx_EC_IABT_CUR:
492 el1_abort(regs, esr);
495 * We don't handle ESR_ELx_EC_SP_ALIGN, since we will have hit a
496 * recursive exception when trying to push the initial pt_regs.
498 case ESR_ELx_EC_PC_ALIGN:
501 case ESR_ELx_EC_SYS64:
502 case ESR_ELx_EC_UNKNOWN:
503 el1_undef(regs, esr);
508 case ESR_ELx_EC_BREAKPT_CUR:
509 case ESR_ELx_EC_SOFTSTP_CUR:
510 case ESR_ELx_EC_WATCHPT_CUR:
511 case ESR_ELx_EC_BRK64:
514 case ESR_ELx_EC_FPAC:
518 __panic_unhandled(regs, "64-bit el1h sync", esr);
522 static __always_inline void __el1_pnmi(struct pt_regs *regs,
523 void (*handler)(struct pt_regs *))
525 arm64_enter_nmi(regs);
526 do_interrupt_handler(regs, handler);
527 arm64_exit_nmi(regs);
530 static __always_inline void __el1_irq(struct pt_regs *regs,
531 void (*handler)(struct pt_regs *))
533 enter_from_kernel_mode(regs);
536 do_interrupt_handler(regs, handler);
539 arm64_preempt_schedule_irq();
541 exit_to_kernel_mode(regs);
543 static void noinstr el1_interrupt(struct pt_regs *regs,
544 void (*handler)(struct pt_regs *))
546 write_sysreg(DAIF_PROCCTX_NOIRQ, daif);
548 if (IS_ENABLED(CONFIG_ARM64_PSEUDO_NMI) && !interrupts_enabled(regs))
549 __el1_pnmi(regs, handler);
551 __el1_irq(regs, handler);
554 asmlinkage void noinstr el1h_64_irq_handler(struct pt_regs *regs)
556 el1_interrupt(regs, handle_arch_irq);
559 asmlinkage void noinstr el1h_64_fiq_handler(struct pt_regs *regs)
561 el1_interrupt(regs, handle_arch_fiq);
564 asmlinkage void noinstr el1h_64_error_handler(struct pt_regs *regs)
566 unsigned long esr = read_sysreg(esr_el1);
568 local_daif_restore(DAIF_ERRCTX);
569 arm64_enter_nmi(regs);
570 do_serror(regs, esr);
571 arm64_exit_nmi(regs);
574 static void noinstr el0_da(struct pt_regs *regs, unsigned long esr)
576 unsigned long far = read_sysreg(far_el1);
578 enter_from_user_mode(regs);
579 local_daif_restore(DAIF_PROCCTX);
580 do_mem_abort(far, esr, regs);
581 exit_to_user_mode(regs);
584 static void noinstr el0_ia(struct pt_regs *regs, unsigned long esr)
586 unsigned long far = read_sysreg(far_el1);
589 * We've taken an instruction abort from userspace and not yet
590 * re-enabled IRQs. If the address is a kernel address, apply
591 * BP hardening prior to enabling IRQs and pre-emption.
593 if (!is_ttbr0_addr(far))
594 arm64_apply_bp_hardening();
596 enter_from_user_mode(regs);
597 local_daif_restore(DAIF_PROCCTX);
598 do_mem_abort(far, esr, regs);
599 exit_to_user_mode(regs);
602 static void noinstr el0_fpsimd_acc(struct pt_regs *regs, unsigned long esr)
604 enter_from_user_mode(regs);
605 local_daif_restore(DAIF_PROCCTX);
606 do_fpsimd_acc(esr, regs);
607 exit_to_user_mode(regs);
610 static void noinstr el0_sve_acc(struct pt_regs *regs, unsigned long esr)
612 enter_from_user_mode(regs);
613 local_daif_restore(DAIF_PROCCTX);
614 do_sve_acc(esr, regs);
615 exit_to_user_mode(regs);
618 static void noinstr el0_sme_acc(struct pt_regs *regs, unsigned long esr)
620 enter_from_user_mode(regs);
621 local_daif_restore(DAIF_PROCCTX);
622 do_sme_acc(esr, regs);
623 exit_to_user_mode(regs);
626 static void noinstr el0_fpsimd_exc(struct pt_regs *regs, unsigned long esr)
628 enter_from_user_mode(regs);
629 local_daif_restore(DAIF_PROCCTX);
630 do_fpsimd_exc(esr, regs);
631 exit_to_user_mode(regs);
634 static void noinstr el0_sys(struct pt_regs *regs, unsigned long esr)
636 enter_from_user_mode(regs);
637 local_daif_restore(DAIF_PROCCTX);
638 do_el0_sys(esr, regs);
639 exit_to_user_mode(regs);
642 static void noinstr el0_pc(struct pt_regs *regs, unsigned long esr)
644 unsigned long far = read_sysreg(far_el1);
646 if (!is_ttbr0_addr(instruction_pointer(regs)))
647 arm64_apply_bp_hardening();
649 enter_from_user_mode(regs);
650 local_daif_restore(DAIF_PROCCTX);
651 do_sp_pc_abort(far, esr, regs);
652 exit_to_user_mode(regs);
655 static void noinstr el0_sp(struct pt_regs *regs, unsigned long esr)
657 enter_from_user_mode(regs);
658 local_daif_restore(DAIF_PROCCTX);
659 do_sp_pc_abort(regs->sp, esr, regs);
660 exit_to_user_mode(regs);
663 static void noinstr el0_undef(struct pt_regs *regs, unsigned long esr)
665 enter_from_user_mode(regs);
666 local_daif_restore(DAIF_PROCCTX);
667 do_el0_undef(regs, esr);
668 exit_to_user_mode(regs);
671 static void noinstr el0_bti(struct pt_regs *regs)
673 enter_from_user_mode(regs);
674 local_daif_restore(DAIF_PROCCTX);
676 exit_to_user_mode(regs);
679 static void noinstr el0_mops(struct pt_regs *regs, unsigned long esr)
681 enter_from_user_mode(regs);
682 local_daif_restore(DAIF_PROCCTX);
683 do_el0_mops(regs, esr);
684 exit_to_user_mode(regs);
687 static void noinstr el0_inv(struct pt_regs *regs, unsigned long esr)
689 enter_from_user_mode(regs);
690 local_daif_restore(DAIF_PROCCTX);
691 bad_el0_sync(regs, 0, esr);
692 exit_to_user_mode(regs);
695 static void noinstr el0_dbg(struct pt_regs *regs, unsigned long esr)
697 /* Only watchpoints write FAR_EL1, otherwise its UNKNOWN */
698 unsigned long far = read_sysreg(far_el1);
700 enter_from_user_mode(regs);
701 do_debug_exception(far, esr, regs);
702 local_daif_restore(DAIF_PROCCTX);
703 exit_to_user_mode(regs);
706 static void noinstr el0_svc(struct pt_regs *regs)
708 enter_from_user_mode(regs);
709 cortex_a76_erratum_1463225_svc_handler();
711 local_daif_restore(DAIF_PROCCTX);
713 exit_to_user_mode(regs);
716 static void noinstr el0_fpac(struct pt_regs *regs, unsigned long esr)
718 enter_from_user_mode(regs);
719 local_daif_restore(DAIF_PROCCTX);
720 do_el0_fpac(regs, esr);
721 exit_to_user_mode(regs);
724 asmlinkage void noinstr el0t_64_sync_handler(struct pt_regs *regs)
726 unsigned long esr = read_sysreg(esr_el1);
728 switch (ESR_ELx_EC(esr)) {
729 case ESR_ELx_EC_SVC64:
732 case ESR_ELx_EC_DABT_LOW:
735 case ESR_ELx_EC_IABT_LOW:
738 case ESR_ELx_EC_FP_ASIMD:
739 el0_fpsimd_acc(regs, esr);
742 el0_sve_acc(regs, esr);
745 el0_sme_acc(regs, esr);
747 case ESR_ELx_EC_FP_EXC64:
748 el0_fpsimd_exc(regs, esr);
750 case ESR_ELx_EC_SYS64:
754 case ESR_ELx_EC_SP_ALIGN:
757 case ESR_ELx_EC_PC_ALIGN:
760 case ESR_ELx_EC_UNKNOWN:
761 el0_undef(regs, esr);
766 case ESR_ELx_EC_MOPS:
769 case ESR_ELx_EC_BREAKPT_LOW:
770 case ESR_ELx_EC_SOFTSTP_LOW:
771 case ESR_ELx_EC_WATCHPT_LOW:
772 case ESR_ELx_EC_BRK64:
775 case ESR_ELx_EC_FPAC:
783 static void noinstr el0_interrupt(struct pt_regs *regs,
784 void (*handler)(struct pt_regs *))
786 enter_from_user_mode(regs);
788 write_sysreg(DAIF_PROCCTX_NOIRQ, daif);
790 if (regs->pc & BIT(55))
791 arm64_apply_bp_hardening();
794 do_interrupt_handler(regs, handler);
797 exit_to_user_mode(regs);
800 static void noinstr __el0_irq_handler_common(struct pt_regs *regs)
802 el0_interrupt(regs, handle_arch_irq);
805 asmlinkage void noinstr el0t_64_irq_handler(struct pt_regs *regs)
807 __el0_irq_handler_common(regs);
810 static void noinstr __el0_fiq_handler_common(struct pt_regs *regs)
812 el0_interrupt(regs, handle_arch_fiq);
815 asmlinkage void noinstr el0t_64_fiq_handler(struct pt_regs *regs)
817 __el0_fiq_handler_common(regs);
820 static void noinstr __el0_error_handler_common(struct pt_regs *regs)
822 unsigned long esr = read_sysreg(esr_el1);
824 enter_from_user_mode(regs);
825 local_daif_restore(DAIF_ERRCTX);
826 arm64_enter_nmi(regs);
827 do_serror(regs, esr);
828 arm64_exit_nmi(regs);
829 local_daif_restore(DAIF_PROCCTX);
830 exit_to_user_mode(regs);
833 asmlinkage void noinstr el0t_64_error_handler(struct pt_regs *regs)
835 __el0_error_handler_common(regs);
839 static void noinstr el0_cp15(struct pt_regs *regs, unsigned long esr)
841 enter_from_user_mode(regs);
842 local_daif_restore(DAIF_PROCCTX);
843 do_el0_cp15(esr, regs);
844 exit_to_user_mode(regs);
847 static void noinstr el0_svc_compat(struct pt_regs *regs)
849 enter_from_user_mode(regs);
850 cortex_a76_erratum_1463225_svc_handler();
851 local_daif_restore(DAIF_PROCCTX);
852 do_el0_svc_compat(regs);
853 exit_to_user_mode(regs);
856 asmlinkage void noinstr el0t_32_sync_handler(struct pt_regs *regs)
858 unsigned long esr = read_sysreg(esr_el1);
860 switch (ESR_ELx_EC(esr)) {
861 case ESR_ELx_EC_SVC32:
862 el0_svc_compat(regs);
864 case ESR_ELx_EC_DABT_LOW:
867 case ESR_ELx_EC_IABT_LOW:
870 case ESR_ELx_EC_FP_ASIMD:
871 el0_fpsimd_acc(regs, esr);
873 case ESR_ELx_EC_FP_EXC32:
874 el0_fpsimd_exc(regs, esr);
876 case ESR_ELx_EC_PC_ALIGN:
879 case ESR_ELx_EC_UNKNOWN:
880 case ESR_ELx_EC_CP14_MR:
881 case ESR_ELx_EC_CP14_LS:
882 case ESR_ELx_EC_CP14_64:
883 el0_undef(regs, esr);
885 case ESR_ELx_EC_CP15_32:
886 case ESR_ELx_EC_CP15_64:
889 case ESR_ELx_EC_BREAKPT_LOW:
890 case ESR_ELx_EC_SOFTSTP_LOW:
891 case ESR_ELx_EC_WATCHPT_LOW:
892 case ESR_ELx_EC_BKPT32:
900 asmlinkage void noinstr el0t_32_irq_handler(struct pt_regs *regs)
902 __el0_irq_handler_common(regs);
905 asmlinkage void noinstr el0t_32_fiq_handler(struct pt_regs *regs)
907 __el0_fiq_handler_common(regs);
910 asmlinkage void noinstr el0t_32_error_handler(struct pt_regs *regs)
912 __el0_error_handler_common(regs);
914 #else /* CONFIG_COMPAT */
915 UNHANDLED(el0t, 32, sync)
916 UNHANDLED(el0t, 32, irq)
917 UNHANDLED(el0t, 32, fiq)
918 UNHANDLED(el0t, 32, error)
919 #endif /* CONFIG_COMPAT */
921 #ifdef CONFIG_VMAP_STACK
922 asmlinkage void noinstr __noreturn handle_bad_stack(struct pt_regs *regs)
924 unsigned long esr = read_sysreg(esr_el1);
925 unsigned long far = read_sysreg(far_el1);
927 arm64_enter_nmi(regs);
928 panic_bad_stack(regs, esr, far);
930 #endif /* CONFIG_VMAP_STACK */
932 #ifdef CONFIG_ARM_SDE_INTERFACE
933 asmlinkage noinstr unsigned long
934 __sdei_handler(struct pt_regs *regs, struct sdei_registered_event *arg)
939 * We didn't take an exception to get here, so the HW hasn't
940 * set/cleared bits in PSTATE that we may rely on.
942 * The original SDEI spec (ARM DEN 0054A) can be read ambiguously as to
943 * whether PSTATE bits are inherited unchanged or generated from
944 * scratch, and the TF-A implementation always clears PAN and always
945 * clears UAO. There are no other known implementations.
947 * Subsequent revisions (ARM DEN 0054B) follow the usual rules for how
948 * PSTATE is modified upon architectural exceptions, and so PAN is
949 * either inherited or set per SCTLR_ELx.SPAN, and UAO is always
952 * We must explicitly reset PAN to the expected state, including
953 * clearing it when the host isn't using it, in case a VM had it set.
955 if (system_uses_hw_pan())
957 else if (cpu_has_pan())
960 arm64_enter_nmi(regs);
961 ret = do_sdei_event(regs, arg);
962 arm64_exit_nmi(regs);
966 #endif /* CONFIG_ARM_SDE_INTERFACE */