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/ptrace.h>
10 #include <linux/thread_info.h>
12 #include <asm/cpufeature.h>
13 #include <asm/daifflags.h>
15 #include <asm/exception.h>
16 #include <asm/kprobes.h>
18 #include <asm/sysreg.h>
20 static void notrace
el1_abort(struct pt_regs
*regs
, unsigned long esr
)
22 unsigned long far
= read_sysreg(far_el1
);
24 local_daif_inherit(regs
);
25 far
= untagged_addr(far
);
26 do_mem_abort(far
, esr
, regs
);
28 NOKPROBE_SYMBOL(el1_abort
);
30 static void notrace
el1_pc(struct pt_regs
*regs
, unsigned long esr
)
32 unsigned long far
= read_sysreg(far_el1
);
34 local_daif_inherit(regs
);
35 do_sp_pc_abort(far
, esr
, regs
);
37 NOKPROBE_SYMBOL(el1_pc
);
39 static void notrace
el1_undef(struct pt_regs
*regs
)
41 local_daif_inherit(regs
);
44 NOKPROBE_SYMBOL(el1_undef
);
46 static void notrace
el1_inv(struct pt_regs
*regs
, unsigned long esr
)
48 local_daif_inherit(regs
);
49 bad_mode(regs
, 0, esr
);
51 NOKPROBE_SYMBOL(el1_inv
);
53 static void notrace
el1_dbg(struct pt_regs
*regs
, unsigned long esr
)
55 unsigned long far
= read_sysreg(far_el1
);
58 * The CPU masked interrupts, and we are leaving them masked during
59 * do_debug_exception(). Update PMR as if we had called
62 if (system_uses_irq_prio_masking())
63 gic_write_pmr(GIC_PRIO_IRQON
| GIC_PRIO_PSR_I_SET
);
65 do_debug_exception(far
, esr
, regs
);
67 NOKPROBE_SYMBOL(el1_dbg
);
69 asmlinkage
void notrace
el1_sync_handler(struct pt_regs
*regs
)
71 unsigned long esr
= read_sysreg(esr_el1
);
73 switch (ESR_ELx_EC(esr
)) {
74 case ESR_ELx_EC_DABT_CUR
:
75 case ESR_ELx_EC_IABT_CUR
:
79 * We don't handle ESR_ELx_EC_SP_ALIGN, since we will have hit a
80 * recursive exception when trying to push the initial pt_regs.
82 case ESR_ELx_EC_PC_ALIGN
:
85 case ESR_ELx_EC_SYS64
:
86 case ESR_ELx_EC_UNKNOWN
:
89 case ESR_ELx_EC_BREAKPT_CUR
:
90 case ESR_ELx_EC_SOFTSTP_CUR
:
91 case ESR_ELx_EC_WATCHPT_CUR
:
92 case ESR_ELx_EC_BRK64
:
99 NOKPROBE_SYMBOL(el1_sync_handler
);
101 static void notrace
el0_da(struct pt_regs
*regs
, unsigned long esr
)
103 unsigned long far
= read_sysreg(far_el1
);
106 local_daif_restore(DAIF_PROCCTX
);
107 far
= untagged_addr(far
);
108 do_mem_abort(far
, esr
, regs
);
110 NOKPROBE_SYMBOL(el0_da
);
112 static void notrace
el0_ia(struct pt_regs
*regs
, unsigned long esr
)
114 unsigned long far
= read_sysreg(far_el1
);
117 * We've taken an instruction abort from userspace and not yet
118 * re-enabled IRQs. If the address is a kernel address, apply
119 * BP hardening prior to enabling IRQs and pre-emption.
121 if (!is_ttbr0_addr(far
))
122 arm64_apply_bp_hardening();
125 local_daif_restore(DAIF_PROCCTX
);
126 do_mem_abort(far
, esr
, regs
);
128 NOKPROBE_SYMBOL(el0_ia
);
130 static void notrace
el0_fpsimd_acc(struct pt_regs
*regs
, unsigned long esr
)
133 local_daif_restore(DAIF_PROCCTX
);
134 do_fpsimd_acc(esr
, regs
);
136 NOKPROBE_SYMBOL(el0_fpsimd_acc
);
138 static void notrace
el0_sve_acc(struct pt_regs
*regs
, unsigned long esr
)
141 local_daif_restore(DAIF_PROCCTX
);
142 do_sve_acc(esr
, regs
);
144 NOKPROBE_SYMBOL(el0_sve_acc
);
146 static void notrace
el0_fpsimd_exc(struct pt_regs
*regs
, unsigned long esr
)
149 local_daif_restore(DAIF_PROCCTX
);
150 do_fpsimd_exc(esr
, regs
);
152 NOKPROBE_SYMBOL(el0_fpsimd_exc
);
154 static void notrace
el0_sys(struct pt_regs
*regs
, unsigned long esr
)
157 local_daif_restore(DAIF_PROCCTX
);
158 do_sysinstr(esr
, regs
);
160 NOKPROBE_SYMBOL(el0_sys
);
162 static void notrace
el0_pc(struct pt_regs
*regs
, unsigned long esr
)
164 unsigned long far
= read_sysreg(far_el1
);
166 if (!is_ttbr0_addr(instruction_pointer(regs
)))
167 arm64_apply_bp_hardening();
170 local_daif_restore(DAIF_PROCCTX
);
171 do_sp_pc_abort(far
, esr
, regs
);
173 NOKPROBE_SYMBOL(el0_pc
);
175 static void notrace
el0_sp(struct pt_regs
*regs
, unsigned long esr
)
178 local_daif_restore(DAIF_PROCCTX
);
179 do_sp_pc_abort(regs
->sp
, esr
, regs
);
181 NOKPROBE_SYMBOL(el0_sp
);
183 static void notrace
el0_undef(struct pt_regs
*regs
)
186 local_daif_restore(DAIF_PROCCTX
);
189 NOKPROBE_SYMBOL(el0_undef
);
191 static void notrace
el0_inv(struct pt_regs
*regs
, unsigned long esr
)
194 local_daif_restore(DAIF_PROCCTX
);
195 bad_el0_sync(regs
, 0, esr
);
197 NOKPROBE_SYMBOL(el0_inv
);
199 static void notrace
el0_dbg(struct pt_regs
*regs
, unsigned long esr
)
201 /* Only watchpoints write FAR_EL1, otherwise its UNKNOWN */
202 unsigned long far
= read_sysreg(far_el1
);
204 if (system_uses_irq_prio_masking())
205 gic_write_pmr(GIC_PRIO_IRQON
| GIC_PRIO_PSR_I_SET
);
208 do_debug_exception(far
, esr
, regs
);
209 local_daif_restore(DAIF_PROCCTX_NOIRQ
);
211 NOKPROBE_SYMBOL(el0_dbg
);
213 static void notrace
el0_svc(struct pt_regs
*regs
)
215 if (system_uses_irq_prio_masking())
216 gic_write_pmr(GIC_PRIO_IRQON
| GIC_PRIO_PSR_I_SET
);
220 NOKPROBE_SYMBOL(el0_svc
);
222 asmlinkage
void notrace
el0_sync_handler(struct pt_regs
*regs
)
224 unsigned long esr
= read_sysreg(esr_el1
);
226 switch (ESR_ELx_EC(esr
)) {
227 case ESR_ELx_EC_SVC64
:
230 case ESR_ELx_EC_DABT_LOW
:
233 case ESR_ELx_EC_IABT_LOW
:
236 case ESR_ELx_EC_FP_ASIMD
:
237 el0_fpsimd_acc(regs
, esr
);
240 el0_sve_acc(regs
, esr
);
242 case ESR_ELx_EC_FP_EXC64
:
243 el0_fpsimd_exc(regs
, esr
);
245 case ESR_ELx_EC_SYS64
:
249 case ESR_ELx_EC_SP_ALIGN
:
252 case ESR_ELx_EC_PC_ALIGN
:
255 case ESR_ELx_EC_UNKNOWN
:
258 case ESR_ELx_EC_BREAKPT_LOW
:
259 case ESR_ELx_EC_SOFTSTP_LOW
:
260 case ESR_ELx_EC_WATCHPT_LOW
:
261 case ESR_ELx_EC_BRK64
:
268 NOKPROBE_SYMBOL(el0_sync_handler
);
271 static void notrace
el0_cp15(struct pt_regs
*regs
, unsigned long esr
)
274 local_daif_restore(DAIF_PROCCTX
);
275 do_cp15instr(esr
, regs
);
277 NOKPROBE_SYMBOL(el0_cp15
);
279 static void notrace
el0_svc_compat(struct pt_regs
*regs
)
281 if (system_uses_irq_prio_masking())
282 gic_write_pmr(GIC_PRIO_IRQON
| GIC_PRIO_PSR_I_SET
);
284 do_el0_svc_compat(regs
);
286 NOKPROBE_SYMBOL(el0_svc_compat
);
288 asmlinkage
void notrace
el0_sync_compat_handler(struct pt_regs
*regs
)
290 unsigned long esr
= read_sysreg(esr_el1
);
292 switch (ESR_ELx_EC(esr
)) {
293 case ESR_ELx_EC_SVC32
:
294 el0_svc_compat(regs
);
296 case ESR_ELx_EC_DABT_LOW
:
299 case ESR_ELx_EC_IABT_LOW
:
302 case ESR_ELx_EC_FP_ASIMD
:
303 el0_fpsimd_acc(regs
, esr
);
305 case ESR_ELx_EC_FP_EXC32
:
306 el0_fpsimd_exc(regs
, esr
);
308 case ESR_ELx_EC_PC_ALIGN
:
311 case ESR_ELx_EC_UNKNOWN
:
312 case ESR_ELx_EC_CP14_MR
:
313 case ESR_ELx_EC_CP14_LS
:
314 case ESR_ELx_EC_CP14_64
:
317 case ESR_ELx_EC_CP15_32
:
318 case ESR_ELx_EC_CP15_64
:
321 case ESR_ELx_EC_BREAKPT_LOW
:
322 case ESR_ELx_EC_SOFTSTP_LOW
:
323 case ESR_ELx_EC_WATCHPT_LOW
:
324 case ESR_ELx_EC_BKPT32
:
331 NOKPROBE_SYMBOL(el0_sync_compat_handler
);
332 #endif /* CONFIG_COMPAT */