arm64: entry: clarify entry/exit helpers
[linux-2.6-microblaze.git] / arch / arm64 / kernel / entry-common.c
1 // SPDX-License-Identifier: GPL-2.0
2 /*
3  * Exception handling code
4  *
5  * Copyright (C) 2019 ARM Ltd.
6  */
7
8 #include <linux/context_tracking.h>
9 #include <linux/linkage.h>
10 #include <linux/lockdep.h>
11 #include <linux/ptrace.h>
12 #include <linux/sched.h>
13 #include <linux/sched/debug.h>
14 #include <linux/thread_info.h>
15
16 #include <asm/cpufeature.h>
17 #include <asm/daifflags.h>
18 #include <asm/esr.h>
19 #include <asm/exception.h>
20 #include <asm/kprobes.h>
21 #include <asm/mmu.h>
22 #include <asm/processor.h>
23 #include <asm/sdei.h>
24 #include <asm/stacktrace.h>
25 #include <asm/sysreg.h>
26 #include <asm/system_misc.h>
27
28 /*
29  * Handle IRQ/context state management when entering from kernel mode.
30  * Before this function is called it is not safe to call regular kernel code,
31  * intrumentable code, or any code which may trigger an exception.
32  *
33  * This is intended to match the logic in irqentry_enter(), handling the kernel
34  * mode transitions only.
35  */
36 static __always_inline void __enter_from_kernel_mode(struct pt_regs *regs)
37 {
38         regs->exit_rcu = false;
39
40         if (!IS_ENABLED(CONFIG_TINY_RCU) && is_idle_task(current)) {
41                 lockdep_hardirqs_off(CALLER_ADDR0);
42                 rcu_irq_enter();
43                 trace_hardirqs_off_finish();
44
45                 regs->exit_rcu = true;
46                 return;
47         }
48
49         lockdep_hardirqs_off(CALLER_ADDR0);
50         rcu_irq_enter_check_tick();
51         trace_hardirqs_off_finish();
52 }
53
54 static void noinstr enter_from_kernel_mode(struct pt_regs *regs)
55 {
56         __enter_from_kernel_mode(regs);
57         mte_check_tfsr_entry();
58 }
59
60 /*
61  * Handle IRQ/context state management when exiting to kernel mode.
62  * After this function returns it is not safe to call regular kernel code,
63  * intrumentable code, or any code which may trigger an exception.
64  *
65  * This is intended to match the logic in irqentry_exit(), handling the kernel
66  * mode transitions only, and with preemption handled elsewhere.
67  */
68 static __always_inline void __exit_to_kernel_mode(struct pt_regs *regs)
69 {
70         lockdep_assert_irqs_disabled();
71
72         if (interrupts_enabled(regs)) {
73                 if (regs->exit_rcu) {
74                         trace_hardirqs_on_prepare();
75                         lockdep_hardirqs_on_prepare(CALLER_ADDR0);
76                         rcu_irq_exit();
77                         lockdep_hardirqs_on(CALLER_ADDR0);
78                         return;
79                 }
80
81                 trace_hardirqs_on();
82         } else {
83                 if (regs->exit_rcu)
84                         rcu_irq_exit();
85         }
86 }
87
88 static void noinstr exit_to_kernel_mode(struct pt_regs *regs)
89 {
90         mte_check_tfsr_exit();
91         __exit_to_kernel_mode(regs);
92 }
93
94 /*
95  * Handle IRQ/context state management when entering from user mode.
96  * Before this function is called it is not safe to call regular kernel code,
97  * intrumentable code, or any code which may trigger an exception.
98  */
99 static __always_inline void __enter_from_user_mode(void)
100 {
101         lockdep_hardirqs_off(CALLER_ADDR0);
102         CT_WARN_ON(ct_state() != CONTEXT_USER);
103         user_exit_irqoff();
104         trace_hardirqs_off_finish();
105 }
106
107 asmlinkage void noinstr enter_from_user_mode(void)
108 {
109         __enter_from_user_mode();
110 }
111
112 /*
113  * Handle IRQ/context state management when exiting to user mode.
114  * After this function returns it is not safe to call regular kernel code,
115  * intrumentable code, or any code which may trigger an exception.
116  */
117 static __always_inline void __exit_to_user_mode(void)
118 {
119
120         trace_hardirqs_on_prepare();
121         lockdep_hardirqs_on_prepare(CALLER_ADDR0);
122         user_enter_irqoff();
123         lockdep_hardirqs_on(CALLER_ADDR0);
124 }
125
126 asmlinkage void noinstr exit_to_user_mode(void)
127 {
128         mte_check_tfsr_exit();
129         __exit_to_user_mode();
130 }
131
132 /*
133  * Handle IRQ/context state management when entering an NMI from user/kernel
134  * mode. Before this function is called it is not safe to call regular kernel
135  * code, intrumentable code, or any code which may trigger an exception.
136  */
137 static void noinstr arm64_enter_nmi(struct pt_regs *regs)
138 {
139         regs->lockdep_hardirqs = lockdep_hardirqs_enabled();
140
141         __nmi_enter();
142         lockdep_hardirqs_off(CALLER_ADDR0);
143         lockdep_hardirq_enter();
144         rcu_nmi_enter();
145
146         trace_hardirqs_off_finish();
147         ftrace_nmi_enter();
148 }
149
150 /*
151  * Handle IRQ/context state management when exiting an NMI from user/kernel
152  * mode. After this function returns it is not safe to call regular kernel
153  * code, intrumentable code, or any code which may trigger an exception.
154  */
155 static void noinstr arm64_exit_nmi(struct pt_regs *regs)
156 {
157         bool restore = regs->lockdep_hardirqs;
158
159         ftrace_nmi_exit();
160         if (restore) {
161                 trace_hardirqs_on_prepare();
162                 lockdep_hardirqs_on_prepare(CALLER_ADDR0);
163         }
164
165         rcu_nmi_exit();
166         lockdep_hardirq_exit();
167         if (restore)
168                 lockdep_hardirqs_on(CALLER_ADDR0);
169         __nmi_exit();
170 }
171
172 /*
173  * Handle IRQ/context state management when entering a debug exception from
174  * kernel mode. Before this function is called it is not safe to call regular
175  * kernel code, intrumentable code, or any code which may trigger an exception.
176  */
177 static void noinstr arm64_enter_el1_dbg(struct pt_regs *regs)
178 {
179         regs->lockdep_hardirqs = lockdep_hardirqs_enabled();
180
181         lockdep_hardirqs_off(CALLER_ADDR0);
182         rcu_nmi_enter();
183
184         trace_hardirqs_off_finish();
185 }
186
187 /*
188  * Handle IRQ/context state management when exiting a debug exception from
189  * kernel mode. After this function returns it is not safe to call regular
190  * kernel code, intrumentable code, or any code which may trigger an exception.
191  */
192 static void noinstr arm64_exit_el1_dbg(struct pt_regs *regs)
193 {
194         bool restore = regs->lockdep_hardirqs;
195
196         if (restore) {
197                 trace_hardirqs_on_prepare();
198                 lockdep_hardirqs_on_prepare(CALLER_ADDR0);
199         }
200
201         rcu_nmi_exit();
202         if (restore)
203                 lockdep_hardirqs_on(CALLER_ADDR0);
204 }
205
206 static void noinstr enter_el1_irq_or_nmi(struct pt_regs *regs)
207 {
208         if (IS_ENABLED(CONFIG_ARM64_PSEUDO_NMI) && !interrupts_enabled(regs))
209                 arm64_enter_nmi(regs);
210         else
211                 enter_from_kernel_mode(regs);
212 }
213
214 static void noinstr exit_el1_irq_or_nmi(struct pt_regs *regs)
215 {
216         if (IS_ENABLED(CONFIG_ARM64_PSEUDO_NMI) && !interrupts_enabled(regs))
217                 arm64_exit_nmi(regs);
218         else
219                 exit_to_kernel_mode(regs);
220 }
221
222 static void __sched arm64_preempt_schedule_irq(void)
223 {
224         lockdep_assert_irqs_disabled();
225
226         /*
227          * DAIF.DA are cleared at the start of IRQ/FIQ handling, and when GIC
228          * priority masking is used the GIC irqchip driver will clear DAIF.IF
229          * using gic_arch_enable_irqs() for normal IRQs. If anything is set in
230          * DAIF we must have handled an NMI, so skip preemption.
231          */
232         if (system_uses_irq_prio_masking() && read_sysreg(daif))
233                 return;
234
235         /*
236          * Preempting a task from an IRQ means we leave copies of PSTATE
237          * on the stack. cpufeature's enable calls may modify PSTATE, but
238          * resuming one of these preempted tasks would undo those changes.
239          *
240          * Only allow a task to be preempted once cpufeatures have been
241          * enabled.
242          */
243         if (system_capabilities_finalized())
244                 preempt_schedule_irq();
245 }
246
247 static void do_interrupt_handler(struct pt_regs *regs,
248                                  void (*handler)(struct pt_regs *))
249 {
250         if (on_thread_stack())
251                 call_on_irq_stack(regs, handler);
252         else
253                 handler(regs);
254 }
255
256 extern void (*handle_arch_irq)(struct pt_regs *);
257 extern void (*handle_arch_fiq)(struct pt_regs *);
258
259 static void noinstr __panic_unhandled(struct pt_regs *regs, const char *vector,
260                                       unsigned int esr)
261 {
262         arm64_enter_nmi(regs);
263
264         console_verbose();
265
266         pr_crit("Unhandled %s exception on CPU%d, ESR 0x%08x -- %s\n",
267                 vector, smp_processor_id(), esr,
268                 esr_get_class_string(esr));
269
270         __show_regs(regs);
271         panic("Unhandled exception");
272 }
273
274 #define UNHANDLED(el, regsize, vector)                                                  \
275 asmlinkage void noinstr el##_##regsize##_##vector##_handler(struct pt_regs *regs)       \
276 {                                                                                       \
277         const char *desc = #regsize "-bit " #el " " #vector;                            \
278         __panic_unhandled(regs, desc, read_sysreg(esr_el1));                            \
279 }
280
281 #ifdef CONFIG_ARM64_ERRATUM_1463225
282 static DEFINE_PER_CPU(int, __in_cortex_a76_erratum_1463225_wa);
283
284 static void cortex_a76_erratum_1463225_svc_handler(void)
285 {
286         u32 reg, val;
287
288         if (!unlikely(test_thread_flag(TIF_SINGLESTEP)))
289                 return;
290
291         if (!unlikely(this_cpu_has_cap(ARM64_WORKAROUND_1463225)))
292                 return;
293
294         __this_cpu_write(__in_cortex_a76_erratum_1463225_wa, 1);
295         reg = read_sysreg(mdscr_el1);
296         val = reg | DBG_MDSCR_SS | DBG_MDSCR_KDE;
297         write_sysreg(val, mdscr_el1);
298         asm volatile("msr daifclr, #8");
299         isb();
300
301         /* We will have taken a single-step exception by this point */
302
303         write_sysreg(reg, mdscr_el1);
304         __this_cpu_write(__in_cortex_a76_erratum_1463225_wa, 0);
305 }
306
307 static bool cortex_a76_erratum_1463225_debug_handler(struct pt_regs *regs)
308 {
309         if (!__this_cpu_read(__in_cortex_a76_erratum_1463225_wa))
310                 return false;
311
312         /*
313          * We've taken a dummy step exception from the kernel to ensure
314          * that interrupts are re-enabled on the syscall path. Return back
315          * to cortex_a76_erratum_1463225_svc_handler() with debug exceptions
316          * masked so that we can safely restore the mdscr and get on with
317          * handling the syscall.
318          */
319         regs->pstate |= PSR_D_BIT;
320         return true;
321 }
322 #else /* CONFIG_ARM64_ERRATUM_1463225 */
323 static void cortex_a76_erratum_1463225_svc_handler(void) { }
324 static bool cortex_a76_erratum_1463225_debug_handler(struct pt_regs *regs)
325 {
326         return false;
327 }
328 #endif /* CONFIG_ARM64_ERRATUM_1463225 */
329
330 UNHANDLED(el1t, 64, sync)
331 UNHANDLED(el1t, 64, irq)
332 UNHANDLED(el1t, 64, fiq)
333 UNHANDLED(el1t, 64, error)
334
335 static void noinstr el1_abort(struct pt_regs *regs, unsigned long esr)
336 {
337         unsigned long far = read_sysreg(far_el1);
338
339         enter_from_kernel_mode(regs);
340         local_daif_inherit(regs);
341         do_mem_abort(far, esr, regs);
342         local_daif_mask();
343         exit_to_kernel_mode(regs);
344 }
345
346 static void noinstr el1_pc(struct pt_regs *regs, unsigned long esr)
347 {
348         unsigned long far = read_sysreg(far_el1);
349
350         enter_from_kernel_mode(regs);
351         local_daif_inherit(regs);
352         do_sp_pc_abort(far, esr, regs);
353         local_daif_mask();
354         exit_to_kernel_mode(regs);
355 }
356
357 static void noinstr el1_undef(struct pt_regs *regs)
358 {
359         enter_from_kernel_mode(regs);
360         local_daif_inherit(regs);
361         do_undefinstr(regs);
362         local_daif_mask();
363         exit_to_kernel_mode(regs);
364 }
365
366 static void noinstr el1_dbg(struct pt_regs *regs, unsigned long esr)
367 {
368         unsigned long far = read_sysreg(far_el1);
369
370         arm64_enter_el1_dbg(regs);
371         if (!cortex_a76_erratum_1463225_debug_handler(regs))
372                 do_debug_exception(far, esr, regs);
373         arm64_exit_el1_dbg(regs);
374 }
375
376 static void noinstr el1_fpac(struct pt_regs *regs, unsigned long esr)
377 {
378         enter_from_kernel_mode(regs);
379         local_daif_inherit(regs);
380         do_ptrauth_fault(regs, esr);
381         local_daif_mask();
382         exit_to_kernel_mode(regs);
383 }
384
385 asmlinkage void noinstr el1h_64_sync_handler(struct pt_regs *regs)
386 {
387         unsigned long esr = read_sysreg(esr_el1);
388
389         switch (ESR_ELx_EC(esr)) {
390         case ESR_ELx_EC_DABT_CUR:
391         case ESR_ELx_EC_IABT_CUR:
392                 el1_abort(regs, esr);
393                 break;
394         /*
395          * We don't handle ESR_ELx_EC_SP_ALIGN, since we will have hit a
396          * recursive exception when trying to push the initial pt_regs.
397          */
398         case ESR_ELx_EC_PC_ALIGN:
399                 el1_pc(regs, esr);
400                 break;
401         case ESR_ELx_EC_SYS64:
402         case ESR_ELx_EC_UNKNOWN:
403                 el1_undef(regs);
404                 break;
405         case ESR_ELx_EC_BREAKPT_CUR:
406         case ESR_ELx_EC_SOFTSTP_CUR:
407         case ESR_ELx_EC_WATCHPT_CUR:
408         case ESR_ELx_EC_BRK64:
409                 el1_dbg(regs, esr);
410                 break;
411         case ESR_ELx_EC_FPAC:
412                 el1_fpac(regs, esr);
413                 break;
414         default:
415                 __panic_unhandled(regs, "64-bit el1h sync", esr);
416         }
417 }
418
419 static void noinstr el1_interrupt(struct pt_regs *regs,
420                                   void (*handler)(struct pt_regs *))
421 {
422         write_sysreg(DAIF_PROCCTX_NOIRQ, daif);
423
424         enter_el1_irq_or_nmi(regs);
425         do_interrupt_handler(regs, handler);
426
427         /*
428          * Note: thread_info::preempt_count includes both thread_info::count
429          * and thread_info::need_resched, and is not equivalent to
430          * preempt_count().
431          */
432         if (IS_ENABLED(CONFIG_PREEMPTION) &&
433             READ_ONCE(current_thread_info()->preempt_count) == 0)
434                 arm64_preempt_schedule_irq();
435
436         exit_el1_irq_or_nmi(regs);
437 }
438
439 asmlinkage void noinstr el1h_64_irq_handler(struct pt_regs *regs)
440 {
441         el1_interrupt(regs, handle_arch_irq);
442 }
443
444 asmlinkage void noinstr el1h_64_fiq_handler(struct pt_regs *regs)
445 {
446         el1_interrupt(regs, handle_arch_fiq);
447 }
448
449 asmlinkage void noinstr el1h_64_error_handler(struct pt_regs *regs)
450 {
451         unsigned long esr = read_sysreg(esr_el1);
452
453         local_daif_restore(DAIF_ERRCTX);
454         arm64_enter_nmi(regs);
455         do_serror(regs, esr);
456         arm64_exit_nmi(regs);
457 }
458
459 static void noinstr el0_da(struct pt_regs *regs, unsigned long esr)
460 {
461         unsigned long far = read_sysreg(far_el1);
462
463         enter_from_user_mode();
464         local_daif_restore(DAIF_PROCCTX);
465         do_mem_abort(far, esr, regs);
466 }
467
468 static void noinstr el0_ia(struct pt_regs *regs, unsigned long esr)
469 {
470         unsigned long far = read_sysreg(far_el1);
471
472         /*
473          * We've taken an instruction abort from userspace and not yet
474          * re-enabled IRQs. If the address is a kernel address, apply
475          * BP hardening prior to enabling IRQs and pre-emption.
476          */
477         if (!is_ttbr0_addr(far))
478                 arm64_apply_bp_hardening();
479
480         enter_from_user_mode();
481         local_daif_restore(DAIF_PROCCTX);
482         do_mem_abort(far, esr, regs);
483 }
484
485 static void noinstr el0_fpsimd_acc(struct pt_regs *regs, unsigned long esr)
486 {
487         enter_from_user_mode();
488         local_daif_restore(DAIF_PROCCTX);
489         do_fpsimd_acc(esr, regs);
490 }
491
492 static void noinstr el0_sve_acc(struct pt_regs *regs, unsigned long esr)
493 {
494         enter_from_user_mode();
495         local_daif_restore(DAIF_PROCCTX);
496         do_sve_acc(esr, regs);
497 }
498
499 static void noinstr el0_fpsimd_exc(struct pt_regs *regs, unsigned long esr)
500 {
501         enter_from_user_mode();
502         local_daif_restore(DAIF_PROCCTX);
503         do_fpsimd_exc(esr, regs);
504 }
505
506 static void noinstr el0_sys(struct pt_regs *regs, unsigned long esr)
507 {
508         enter_from_user_mode();
509         local_daif_restore(DAIF_PROCCTX);
510         do_sysinstr(esr, regs);
511 }
512
513 static void noinstr el0_pc(struct pt_regs *regs, unsigned long esr)
514 {
515         unsigned long far = read_sysreg(far_el1);
516
517         if (!is_ttbr0_addr(instruction_pointer(regs)))
518                 arm64_apply_bp_hardening();
519
520         enter_from_user_mode();
521         local_daif_restore(DAIF_PROCCTX);
522         do_sp_pc_abort(far, esr, regs);
523 }
524
525 static void noinstr el0_sp(struct pt_regs *regs, unsigned long esr)
526 {
527         enter_from_user_mode();
528         local_daif_restore(DAIF_PROCCTX);
529         do_sp_pc_abort(regs->sp, esr, regs);
530 }
531
532 static void noinstr el0_undef(struct pt_regs *regs)
533 {
534         enter_from_user_mode();
535         local_daif_restore(DAIF_PROCCTX);
536         do_undefinstr(regs);
537 }
538
539 static void noinstr el0_bti(struct pt_regs *regs)
540 {
541         enter_from_user_mode();
542         local_daif_restore(DAIF_PROCCTX);
543         do_bti(regs);
544 }
545
546 static void noinstr el0_inv(struct pt_regs *regs, unsigned long esr)
547 {
548         enter_from_user_mode();
549         local_daif_restore(DAIF_PROCCTX);
550         bad_el0_sync(regs, 0, esr);
551 }
552
553 static void noinstr el0_dbg(struct pt_regs *regs, unsigned long esr)
554 {
555         /* Only watchpoints write FAR_EL1, otherwise its UNKNOWN */
556         unsigned long far = read_sysreg(far_el1);
557
558         enter_from_user_mode();
559         do_debug_exception(far, esr, regs);
560         local_daif_restore(DAIF_PROCCTX);
561 }
562
563 static void noinstr el0_svc(struct pt_regs *regs)
564 {
565         enter_from_user_mode();
566         cortex_a76_erratum_1463225_svc_handler();
567         do_el0_svc(regs);
568 }
569
570 static void noinstr el0_fpac(struct pt_regs *regs, unsigned long esr)
571 {
572         enter_from_user_mode();
573         local_daif_restore(DAIF_PROCCTX);
574         do_ptrauth_fault(regs, esr);
575 }
576
577 asmlinkage void noinstr el0t_64_sync_handler(struct pt_regs *regs)
578 {
579         unsigned long esr = read_sysreg(esr_el1);
580
581         switch (ESR_ELx_EC(esr)) {
582         case ESR_ELx_EC_SVC64:
583                 el0_svc(regs);
584                 break;
585         case ESR_ELx_EC_DABT_LOW:
586                 el0_da(regs, esr);
587                 break;
588         case ESR_ELx_EC_IABT_LOW:
589                 el0_ia(regs, esr);
590                 break;
591         case ESR_ELx_EC_FP_ASIMD:
592                 el0_fpsimd_acc(regs, esr);
593                 break;
594         case ESR_ELx_EC_SVE:
595                 el0_sve_acc(regs, esr);
596                 break;
597         case ESR_ELx_EC_FP_EXC64:
598                 el0_fpsimd_exc(regs, esr);
599                 break;
600         case ESR_ELx_EC_SYS64:
601         case ESR_ELx_EC_WFx:
602                 el0_sys(regs, esr);
603                 break;
604         case ESR_ELx_EC_SP_ALIGN:
605                 el0_sp(regs, esr);
606                 break;
607         case ESR_ELx_EC_PC_ALIGN:
608                 el0_pc(regs, esr);
609                 break;
610         case ESR_ELx_EC_UNKNOWN:
611                 el0_undef(regs);
612                 break;
613         case ESR_ELx_EC_BTI:
614                 el0_bti(regs);
615                 break;
616         case ESR_ELx_EC_BREAKPT_LOW:
617         case ESR_ELx_EC_SOFTSTP_LOW:
618         case ESR_ELx_EC_WATCHPT_LOW:
619         case ESR_ELx_EC_BRK64:
620                 el0_dbg(regs, esr);
621                 break;
622         case ESR_ELx_EC_FPAC:
623                 el0_fpac(regs, esr);
624                 break;
625         default:
626                 el0_inv(regs, esr);
627         }
628 }
629
630 static void noinstr el0_interrupt(struct pt_regs *regs,
631                                   void (*handler)(struct pt_regs *))
632 {
633         enter_from_user_mode();
634
635         write_sysreg(DAIF_PROCCTX_NOIRQ, daif);
636
637         if (regs->pc & BIT(55))
638                 arm64_apply_bp_hardening();
639
640         do_interrupt_handler(regs, handler);
641 }
642
643 static void noinstr __el0_irq_handler_common(struct pt_regs *regs)
644 {
645         el0_interrupt(regs, handle_arch_irq);
646 }
647
648 asmlinkage void noinstr el0t_64_irq_handler(struct pt_regs *regs)
649 {
650         __el0_irq_handler_common(regs);
651 }
652
653 static void noinstr __el0_fiq_handler_common(struct pt_regs *regs)
654 {
655         el0_interrupt(regs, handle_arch_fiq);
656 }
657
658 asmlinkage void noinstr el0t_64_fiq_handler(struct pt_regs *regs)
659 {
660         __el0_fiq_handler_common(regs);
661 }
662
663 static void noinstr __el0_error_handler_common(struct pt_regs *regs)
664 {
665         unsigned long esr = read_sysreg(esr_el1);
666
667         enter_from_user_mode();
668         local_daif_restore(DAIF_ERRCTX);
669         arm64_enter_nmi(regs);
670         do_serror(regs, esr);
671         arm64_exit_nmi(regs);
672         local_daif_restore(DAIF_PROCCTX);
673 }
674
675 asmlinkage void noinstr el0t_64_error_handler(struct pt_regs *regs)
676 {
677         __el0_error_handler_common(regs);
678 }
679
680 #ifdef CONFIG_COMPAT
681 static void noinstr el0_cp15(struct pt_regs *regs, unsigned long esr)
682 {
683         enter_from_user_mode();
684         local_daif_restore(DAIF_PROCCTX);
685         do_cp15instr(esr, regs);
686 }
687
688 static void noinstr el0_svc_compat(struct pt_regs *regs)
689 {
690         enter_from_user_mode();
691         cortex_a76_erratum_1463225_svc_handler();
692         do_el0_svc_compat(regs);
693 }
694
695 asmlinkage void noinstr el0t_32_sync_handler(struct pt_regs *regs)
696 {
697         unsigned long esr = read_sysreg(esr_el1);
698
699         switch (ESR_ELx_EC(esr)) {
700         case ESR_ELx_EC_SVC32:
701                 el0_svc_compat(regs);
702                 break;
703         case ESR_ELx_EC_DABT_LOW:
704                 el0_da(regs, esr);
705                 break;
706         case ESR_ELx_EC_IABT_LOW:
707                 el0_ia(regs, esr);
708                 break;
709         case ESR_ELx_EC_FP_ASIMD:
710                 el0_fpsimd_acc(regs, esr);
711                 break;
712         case ESR_ELx_EC_FP_EXC32:
713                 el0_fpsimd_exc(regs, esr);
714                 break;
715         case ESR_ELx_EC_PC_ALIGN:
716                 el0_pc(regs, esr);
717                 break;
718         case ESR_ELx_EC_UNKNOWN:
719         case ESR_ELx_EC_CP14_MR:
720         case ESR_ELx_EC_CP14_LS:
721         case ESR_ELx_EC_CP14_64:
722                 el0_undef(regs);
723                 break;
724         case ESR_ELx_EC_CP15_32:
725         case ESR_ELx_EC_CP15_64:
726                 el0_cp15(regs, esr);
727                 break;
728         case ESR_ELx_EC_BREAKPT_LOW:
729         case ESR_ELx_EC_SOFTSTP_LOW:
730         case ESR_ELx_EC_WATCHPT_LOW:
731         case ESR_ELx_EC_BKPT32:
732                 el0_dbg(regs, esr);
733                 break;
734         default:
735                 el0_inv(regs, esr);
736         }
737 }
738
739 asmlinkage void noinstr el0t_32_irq_handler(struct pt_regs *regs)
740 {
741         __el0_irq_handler_common(regs);
742 }
743
744 asmlinkage void noinstr el0t_32_fiq_handler(struct pt_regs *regs)
745 {
746         __el0_fiq_handler_common(regs);
747 }
748
749 asmlinkage void noinstr el0t_32_error_handler(struct pt_regs *regs)
750 {
751         __el0_error_handler_common(regs);
752 }
753 #else /* CONFIG_COMPAT */
754 UNHANDLED(el0t, 32, sync)
755 UNHANDLED(el0t, 32, irq)
756 UNHANDLED(el0t, 32, fiq)
757 UNHANDLED(el0t, 32, error)
758 #endif /* CONFIG_COMPAT */
759
760 #ifdef CONFIG_VMAP_STACK
761 asmlinkage void noinstr handle_bad_stack(struct pt_regs *regs)
762 {
763         unsigned int esr = read_sysreg(esr_el1);
764         unsigned long far = read_sysreg(far_el1);
765
766         arm64_enter_nmi(regs);
767         panic_bad_stack(regs, esr, far);
768 }
769 #endif /* CONFIG_VMAP_STACK */
770
771 #ifdef CONFIG_ARM_SDE_INTERFACE
772 asmlinkage noinstr unsigned long
773 __sdei_handler(struct pt_regs *regs, struct sdei_registered_event *arg)
774 {
775         unsigned long ret;
776
777         /*
778          * We didn't take an exception to get here, so the HW hasn't
779          * set/cleared bits in PSTATE that we may rely on.
780          *
781          * The original SDEI spec (ARM DEN 0054A) can be read ambiguously as to
782          * whether PSTATE bits are inherited unchanged or generated from
783          * scratch, and the TF-A implementation always clears PAN and always
784          * clears UAO. There are no other known implementations.
785          *
786          * Subsequent revisions (ARM DEN 0054B) follow the usual rules for how
787          * PSTATE is modified upon architectural exceptions, and so PAN is
788          * either inherited or set per SCTLR_ELx.SPAN, and UAO is always
789          * cleared.
790          *
791          * We must explicitly reset PAN to the expected state, including
792          * clearing it when the host isn't using it, in case a VM had it set.
793          */
794         if (system_uses_hw_pan())
795                 set_pstate_pan(1);
796         else if (cpu_has_pan())
797                 set_pstate_pan(0);
798
799         arm64_enter_nmi(regs);
800         ret = do_sdei_event(regs, arg);
801         arm64_exit_nmi(regs);
802
803         return ret;
804 }
805 #endif /* CONFIG_ARM_SDE_INTERFACE */