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