Skip to content

Commit ed3768d

Browse files
mrutland-armctmarinas
authored andcommitted
arm64: entry: convert el1_sync to C
This patch converts the EL1 sync entry assembly logic to C code. Doing this will allow us to make changes in a slightly more readable way. A case in point is supporting kernel-first RAS. do_sea() should be called on the CPU that took the fault. Largely the assembly code is converted to C in a relatively straightforward manner. Since all sync sites share a common asm entry point, the ASM_BUG() instances are no longer required for effective backtraces back to assembly, and we don't need similar BUG() entries. The ESR_ELx.EC codes for all (supported) debug exceptions are now checked in the el1_sync_handler's switch statement, which renders the check in el1_dbg redundant. This both simplifies the el1_dbg handler, and makes the EL1 exception handling more robust to currently-unallocated ESR_ELx.EC encodings. Signed-off-by: Mark Rutland <mark.rutland@arm.com> [split out of a bigger series, added nokprobes, moved prototypes] Signed-off-by: James Morse <james.morse@arm.com> Reviewed-by: Mark Rutland <mark.rutland@arm.com> Cc: Julien Thierry <julien.thierry.kdev@gmail.com> Signed-off-by: Catalin Marinas <catalin.marinas@arm.com>
1 parent 51077e0 commit ed3768d

3 files changed

Lines changed: 102 additions & 71 deletions

File tree

‎arch/arm64/kernel/Makefile‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ CFLAGS_REMOVE_return_address.o = $(CC_FLAGS_FTRACE)
1313

1414
# Object file lists.
1515
obj-y := debug-monitors.o entry.o irq.o fpsimd.o \
16-
entry-fpsimd.o process.o ptrace.o setup.o signal.o \
17-
sys.o stacktrace.o time.o traps.o io.o vdso.o \
18-
hyp-stub.o psci.o cpu_ops.o insn.o \
16+
entry-common.o entry-fpsimd.o process.o ptrace.o \
17+
setup.o signal.o sys.o stacktrace.o time.o traps.o \
18+
io.o vdso.o hyp-stub.o psci.o cpu_ops.o insn.o \
1919
return_address.o cpuinfo.o cpu_errata.o \
2020
cpufeature.o alternative.o cacheinfo.o \
2121
smp.o smp_spin_table.o topology.o smccc-call.o \

‎arch/arm64/kernel/entry-common.c‎

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
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/ptrace.h>
10+
#include <linux/thread_info.h>
11+
12+
#include <asm/cpufeature.h>
13+
#include <asm/daifflags.h>
14+
#include <asm/esr.h>
15+
#include <asm/exception.h>
16+
#include <asm/kprobes.h>
17+
#include <asm/sysreg.h>
18+
19+
static void notrace el1_abort(struct pt_regs *regs, unsigned long esr)
20+
{
21+
unsigned long far = read_sysreg(far_el1);
22+
23+
local_daif_inherit(regs);
24+
far = untagged_addr(far);
25+
do_mem_abort(far, esr, regs);
26+
}
27+
NOKPROBE_SYMBOL(el1_abort);
28+
29+
static void notrace el1_pc(struct pt_regs *regs, unsigned long esr)
30+
{
31+
unsigned long far = read_sysreg(far_el1);
32+
33+
local_daif_inherit(regs);
34+
do_sp_pc_abort(far, esr, regs);
35+
}
36+
NOKPROBE_SYMBOL(el1_pc);
37+
38+
static void el1_undef(struct pt_regs *regs)
39+
{
40+
local_daif_inherit(regs);
41+
do_undefinstr(regs);
42+
}
43+
NOKPROBE_SYMBOL(el1_undef);
44+
45+
static void el1_inv(struct pt_regs *regs, unsigned long esr)
46+
{
47+
local_daif_inherit(regs);
48+
bad_mode(regs, 0, esr);
49+
}
50+
NOKPROBE_SYMBOL(el1_inv);
51+
52+
static void notrace el1_dbg(struct pt_regs *regs, unsigned long esr)
53+
{
54+
unsigned long far = read_sysreg(far_el1);
55+
56+
/*
57+
* The CPU masked interrupts, and we are leaving them masked during
58+
* do_debug_exception(). Update PMR as if we had called
59+
* local_mask_daif().
60+
*/
61+
if (system_uses_irq_prio_masking())
62+
gic_write_pmr(GIC_PRIO_IRQON | GIC_PRIO_PSR_I_SET);
63+
64+
do_debug_exception(far, esr, regs);
65+
}
66+
NOKPROBE_SYMBOL(el1_dbg);
67+
68+
asmlinkage void notrace el1_sync_handler(struct pt_regs *regs)
69+
{
70+
unsigned long esr = read_sysreg(esr_el1);
71+
72+
switch (ESR_ELx_EC(esr)) {
73+
case ESR_ELx_EC_DABT_CUR:
74+
case ESR_ELx_EC_IABT_CUR:
75+
el1_abort(regs, esr);
76+
break;
77+
/*
78+
* We don't handle ESR_ELx_EC_SP_ALIGN, since we will have hit a
79+
* recursive exception when trying to push the initial pt_regs.
80+
*/
81+
case ESR_ELx_EC_PC_ALIGN:
82+
el1_pc(regs, esr);
83+
break;
84+
case ESR_ELx_EC_SYS64:
85+
case ESR_ELx_EC_UNKNOWN:
86+
el1_undef(regs);
87+
break;
88+
case ESR_ELx_EC_BREAKPT_CUR:
89+
case ESR_ELx_EC_SOFTSTP_CUR:
90+
case ESR_ELx_EC_WATCHPT_CUR:
91+
case ESR_ELx_EC_BRK64:
92+
el1_dbg(regs, esr);
93+
break;
94+
default:
95+
el1_inv(regs, esr);
96+
};
97+
}
98+
NOKPROBE_SYMBOL(el1_sync_handler);

‎arch/arm64/kernel/entry.S‎

Lines changed: 1 addition & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -578,76 +578,9 @@ ENDPROC(el1_error_invalid)
578578
.align 6
579579
el1_sync:
580580
kernel_entry 1
581-
mrs x1, esr_el1 // read the syndrome register
582-
lsr x24, x1, #ESR_ELx_EC_SHIFT // exception class
583-
cmp x24, #ESR_ELx_EC_DABT_CUR // data abort in EL1
584-
b.eq el1_da
585-
cmp x24, #ESR_ELx_EC_IABT_CUR // instruction abort in EL1
586-
b.eq el1_ia
587-
cmp x24, #ESR_ELx_EC_SYS64 // configurable trap
588-
b.eq el1_undef
589-
cmp x24, #ESR_ELx_EC_PC_ALIGN // pc alignment exception
590-
b.eq el1_pc
591-
cmp x24, #ESR_ELx_EC_UNKNOWN // unknown exception in EL1
592-
b.eq el1_undef
593-
cmp x24, #ESR_ELx_EC_BREAKPT_CUR // debug exception in EL1
594-
b.ge el1_dbg
595-
b el1_inv
596-
597-
el1_ia:
598-
/*
599-
* Fall through to the Data abort case
600-
*/
601-
el1_da:
602-
/*
603-
* Data abort handling
604-
*/
605-
mrs x3, far_el1
606-
inherit_daif pstate=x23, tmp=x2
607-
clear_address_tag x0, x3
608-
mov x2, sp // struct pt_regs
609-
bl do_mem_abort
610-
611-
kernel_exit 1
612-
el1_pc:
613-
/*
614-
* PC alignment exception handling. We don't handle SP alignment faults,
615-
* since we will have hit a recursive exception when trying to push the
616-
* initial pt_regs.
617-
*/
618-
mrs x0, far_el1
619-
inherit_daif pstate=x23, tmp=x2
620-
mov x2, sp
621-
bl do_sp_pc_abort
622-
ASM_BUG()
623-
el1_undef:
624-
/*
625-
* Undefined instruction
626-
*/
627-
inherit_daif pstate=x23, tmp=x2
628581
mov x0, sp
629-
bl do_undefinstr
630-
kernel_exit 1
631-
el1_dbg:
632-
/*
633-
* Debug exception handling
634-
*/
635-
cmp x24, #ESR_ELx_EC_BRK64 // if BRK64
636-
cinc x24, x24, eq // set bit '0'
637-
tbz x24, #0, el1_inv // EL1 only
638-
gic_prio_kentry_setup tmp=x3
639-
mrs x0, far_el1
640-
mov x2, sp // struct pt_regs
641-
bl do_debug_exception
582+
bl el1_sync_handler
642583
kernel_exit 1
643-
el1_inv:
644-
// TODO: add support for undefined instructions in kernel mode
645-
inherit_daif pstate=x23, tmp=x2
646-
mov x0, sp
647-
mov x2, x1
648-
mov x1, #BAD_SYNC
649-
bl bad_mode
650-
ASM_BUG()
651584
ENDPROC(el1_sync)
652585

653586
.align 6

0 commit comments

Comments
 (0)