]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
arm64: consistently pass ESR_ELx to die()
authorMark Rutland <mark.rutland@arm.com>
Wed, 11 Oct 2023 10:06:43 +0000 (10:06 +0000)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 19 Oct 2023 21:05:38 +0000 (23:05 +0200)
commit 0f2cb928a1547ae8f89e80a4b8df2c6c02ae5f96 upstream.

Currently, bug_handler() and kasan_handler() call die() with '0' as the
'err' value, whereas die_kernel_fault() passes the ESR_ELx value.

For consistency, this patch ensures we always pass the ESR_ELx value to
die(). As this is only called for exceptions taken from kernel mode,
there should be no user-visible change as a result of this patch.

For UNDEFINED exceptions, I've had to modify do_undefinstr() and its
callers to pass the ESR_ELx value. In all cases the ESR_ELx value had
already been read and was available.

Signed-off-by: Mark Rutland <mark.rutland@arm.com>
Cc: Mark Brown <broonie@kernel.org>
Cc: Alexandru Elisei <alexandru.elisei@arm.com>
Cc: Amit Daniel Kachhap <amit.kachhap@arm.com>
Cc: James Morse <james.morse@arm.com>
Cc: Will Deacon <will@kernel.org>
Reviewed-by: Anshuman Khandual <anshuman.khandual@arm.com>
Reviewed-by: Mark Brown <broonie@kernel.org>
Link: https://lore.kernel.org/r/20220913101732.3925290-4-mark.rutland@arm.com
Signed-off-by: Catalin Marinas <catalin.marinas@arm.com>
Signed-off-by: Jinjie Ruan <ruanjinjie@huawei.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
arch/arm64/include/asm/exception.h
arch/arm64/kernel/entry-common.c
arch/arm64/kernel/traps.c

index 0e6535aa78c2f047914008bc9d12889bf55c1557..babbe2db8010a94a2f0a87f412f90f406830a1f3 100644 (file)
@@ -58,7 +58,7 @@ asmlinkage void call_on_irq_stack(struct pt_regs *regs,
 asmlinkage void asm_exit_to_user_mode(struct pt_regs *regs);
 
 void do_mem_abort(unsigned long far, unsigned long esr, struct pt_regs *regs);
-void do_undefinstr(struct pt_regs *regs);
+void do_undefinstr(struct pt_regs *regs, unsigned long esr);
 void do_bti(struct pt_regs *regs);
 void do_debug_exception(unsigned long addr_if_watchpoint, unsigned long esr,
                        struct pt_regs *regs);
index fc91dad1579abc1bd884384d422d63d72725dcc1..4dbdadc5daa1639166b3a6a07edd874b8ba7ba53 100644 (file)
@@ -371,11 +371,11 @@ static void noinstr el1_pc(struct pt_regs *regs, unsigned long esr)
        exit_to_kernel_mode(regs);
 }
 
-static void noinstr el1_undef(struct pt_regs *regs)
+static void noinstr el1_undef(struct pt_regs *regs, unsigned long esr)
 {
        enter_from_kernel_mode(regs);
        local_daif_inherit(regs);
-       do_undefinstr(regs);
+       do_undefinstr(regs, esr);
        local_daif_mask();
        exit_to_kernel_mode(regs);
 }
@@ -417,7 +417,7 @@ asmlinkage void noinstr el1h_64_sync_handler(struct pt_regs *regs)
                break;
        case ESR_ELx_EC_SYS64:
        case ESR_ELx_EC_UNKNOWN:
-               el1_undef(regs);
+               el1_undef(regs, esr);
                break;
        case ESR_ELx_EC_BREAKPT_CUR:
        case ESR_ELx_EC_SOFTSTP_CUR:
@@ -554,11 +554,11 @@ static void noinstr el0_sp(struct pt_regs *regs, unsigned long esr)
        exit_to_user_mode(regs);
 }
 
-static void noinstr el0_undef(struct pt_regs *regs)
+static void noinstr el0_undef(struct pt_regs *regs, unsigned long esr)
 {
        enter_from_user_mode(regs);
        local_daif_restore(DAIF_PROCCTX);
-       do_undefinstr(regs);
+       do_undefinstr(regs, esr);
        exit_to_user_mode(regs);
 }
 
@@ -639,7 +639,7 @@ asmlinkage void noinstr el0t_64_sync_handler(struct pt_regs *regs)
                el0_pc(regs, esr);
                break;
        case ESR_ELx_EC_UNKNOWN:
-               el0_undef(regs);
+               el0_undef(regs, esr);
                break;
        case ESR_ELx_EC_BTI:
                el0_bti(regs);
@@ -755,7 +755,7 @@ asmlinkage void noinstr el0t_32_sync_handler(struct pt_regs *regs)
        case ESR_ELx_EC_CP14_MR:
        case ESR_ELx_EC_CP14_LS:
        case ESR_ELx_EC_CP14_64:
-               el0_undef(regs);
+               el0_undef(regs, esr);
                break;
        case ESR_ELx_EC_CP15_32:
        case ESR_ELx_EC_CP15_64:
index fcf1a306e09491339a0c253a90c5c9078e9b6c4d..591eb1a44d30aa562db58be2c1a1c423c9315b73 100644 (file)
@@ -486,7 +486,7 @@ void arm64_notify_segfault(unsigned long addr)
        force_signal_inject(SIGSEGV, code, addr, 0);
 }
 
-void do_undefinstr(struct pt_regs *regs)
+void do_undefinstr(struct pt_regs *regs, unsigned long esr)
 {
        /* check for AArch32 breakpoint instructions */
        if (!aarch32_break_handler(regs))
@@ -496,7 +496,7 @@ void do_undefinstr(struct pt_regs *regs)
                return;
 
        if (!user_mode(regs))
-               die("Oops - Undefined instruction", regs, 0);
+               die("Oops - Undefined instruction", regs, esr);
 
        force_signal_inject(SIGILL, ILL_ILLOPC, regs->pc, 0);
 }
@@ -755,7 +755,7 @@ void do_cp15instr(unsigned long esr, struct pt_regs *regs)
                hook_base = cp15_64_hooks;
                break;
        default:
-               do_undefinstr(regs);
+               do_undefinstr(regs, esr);
                return;
        }
 
@@ -770,7 +770,7 @@ void do_cp15instr(unsigned long esr, struct pt_regs *regs)
         * EL0. Fall back to our usual undefined instruction handler
         * so that we handle these consistently.
         */
-       do_undefinstr(regs);
+       do_undefinstr(regs, esr);
 }
 NOKPROBE_SYMBOL(do_cp15instr);
 #endif
@@ -790,7 +790,7 @@ void do_sysinstr(unsigned long esr, struct pt_regs *regs)
         * back to our usual undefined instruction handler so that we handle
         * these consistently.
         */
-       do_undefinstr(regs);
+       do_undefinstr(regs, esr);
 }
 NOKPROBE_SYMBOL(do_sysinstr);
 
@@ -966,7 +966,7 @@ static int bug_handler(struct pt_regs *regs, unsigned long esr)
 {
        switch (report_bug(regs->pc, regs)) {
        case BUG_TRAP_TYPE_BUG:
-               die("Oops - BUG", regs, 0);
+               die("Oops - BUG", regs, esr);
                break;
 
        case BUG_TRAP_TYPE_WARN:
@@ -1034,7 +1034,7 @@ static int kasan_handler(struct pt_regs *regs, unsigned long esr)
         * This is something that might be fixed at some point in the future.
         */
        if (!recover)
-               die("Oops - KASAN", regs, 0);
+               die("Oops - KASAN", regs, esr);
 
        /* If thread survives, skip over the brk instruction and continue: */
        arm64_skip_faulting_instruction(regs, AARCH64_INSN_SIZE);