Skip to content

Commit 0f2cb92

Browse files
mrutland-armctmarinas
authored andcommitted
arm64: consistently pass ESR_ELx to die()
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>
1 parent 18906ff commit 0f2cb92

File tree

3 files changed

+15
-15
lines changed

3 files changed

+15
-15
lines changed

arch/arm64/include/asm/exception.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ asmlinkage void call_on_irq_stack(struct pt_regs *regs,
5858
asmlinkage void asm_exit_to_user_mode(struct pt_regs *regs);
5959

6060
void do_mem_abort(unsigned long far, unsigned long esr, struct pt_regs *regs);
61-
void do_undefinstr(struct pt_regs *regs);
61+
void do_undefinstr(struct pt_regs *regs, unsigned long esr);
6262
void do_bti(struct pt_regs *regs);
6363
void do_debug_exception(unsigned long addr_if_watchpoint, unsigned long esr,
6464
struct pt_regs *regs);

arch/arm64/kernel/entry-common.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -379,11 +379,11 @@ static void noinstr el1_pc(struct pt_regs *regs, unsigned long esr)
379379
exit_to_kernel_mode(regs);
380380
}
381381

382-
static void noinstr el1_undef(struct pt_regs *regs)
382+
static void noinstr el1_undef(struct pt_regs *regs, unsigned long esr)
383383
{
384384
enter_from_kernel_mode(regs);
385385
local_daif_inherit(regs);
386-
do_undefinstr(regs);
386+
do_undefinstr(regs, esr);
387387
local_daif_mask();
388388
exit_to_kernel_mode(regs);
389389
}
@@ -425,7 +425,7 @@ asmlinkage void noinstr el1h_64_sync_handler(struct pt_regs *regs)
425425
break;
426426
case ESR_ELx_EC_SYS64:
427427
case ESR_ELx_EC_UNKNOWN:
428-
el1_undef(regs);
428+
el1_undef(regs, esr);
429429
break;
430430
case ESR_ELx_EC_BREAKPT_CUR:
431431
case ESR_ELx_EC_SOFTSTP_CUR:
@@ -582,11 +582,11 @@ static void noinstr el0_sp(struct pt_regs *regs, unsigned long esr)
582582
exit_to_user_mode(regs);
583583
}
584584

585-
static void noinstr el0_undef(struct pt_regs *regs)
585+
static void noinstr el0_undef(struct pt_regs *regs, unsigned long esr)
586586
{
587587
enter_from_user_mode(regs);
588588
local_daif_restore(DAIF_PROCCTX);
589-
do_undefinstr(regs);
589+
do_undefinstr(regs, esr);
590590
exit_to_user_mode(regs);
591591
}
592592

@@ -670,7 +670,7 @@ asmlinkage void noinstr el0t_64_sync_handler(struct pt_regs *regs)
670670
el0_pc(regs, esr);
671671
break;
672672
case ESR_ELx_EC_UNKNOWN:
673-
el0_undef(regs);
673+
el0_undef(regs, esr);
674674
break;
675675
case ESR_ELx_EC_BTI:
676676
el0_bti(regs);
@@ -788,7 +788,7 @@ asmlinkage void noinstr el0t_32_sync_handler(struct pt_regs *regs)
788788
case ESR_ELx_EC_CP14_MR:
789789
case ESR_ELx_EC_CP14_LS:
790790
case ESR_ELx_EC_CP14_64:
791-
el0_undef(regs);
791+
el0_undef(regs, esr);
792792
break;
793793
case ESR_ELx_EC_CP15_32:
794794
case ESR_ELx_EC_CP15_64:

arch/arm64/kernel/traps.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -485,7 +485,7 @@ void arm64_notify_segfault(unsigned long addr)
485485
force_signal_inject(SIGSEGV, code, addr, 0);
486486
}
487487

488-
void do_undefinstr(struct pt_regs *regs)
488+
void do_undefinstr(struct pt_regs *regs, unsigned long esr)
489489
{
490490
/* check for AArch32 breakpoint instructions */
491491
if (!aarch32_break_handler(regs))
@@ -495,7 +495,7 @@ void do_undefinstr(struct pt_regs *regs)
495495
return;
496496

497497
if (!user_mode(regs))
498-
die("Oops - Undefined instruction", regs, 0);
498+
die("Oops - Undefined instruction", regs, esr);
499499

500500
force_signal_inject(SIGILL, ILL_ILLOPC, regs->pc, 0);
501501
}
@@ -760,7 +760,7 @@ void do_cp15instr(unsigned long esr, struct pt_regs *regs)
760760
hook_base = cp15_64_hooks;
761761
break;
762762
default:
763-
do_undefinstr(regs);
763+
do_undefinstr(regs, esr);
764764
return;
765765
}
766766

@@ -775,7 +775,7 @@ void do_cp15instr(unsigned long esr, struct pt_regs *regs)
775775
* EL0. Fall back to our usual undefined instruction handler
776776
* so that we handle these consistently.
777777
*/
778-
do_undefinstr(regs);
778+
do_undefinstr(regs, esr);
779779
}
780780
NOKPROBE_SYMBOL(do_cp15instr);
781781
#endif
@@ -795,7 +795,7 @@ void do_sysinstr(unsigned long esr, struct pt_regs *regs)
795795
* back to our usual undefined instruction handler so that we handle
796796
* these consistently.
797797
*/
798-
do_undefinstr(regs);
798+
do_undefinstr(regs, esr);
799799
}
800800
NOKPROBE_SYMBOL(do_sysinstr);
801801

@@ -972,7 +972,7 @@ static int bug_handler(struct pt_regs *regs, unsigned long esr)
972972
{
973973
switch (report_bug(regs->pc, regs)) {
974974
case BUG_TRAP_TYPE_BUG:
975-
die("Oops - BUG", regs, 0);
975+
die("Oops - BUG", regs, esr);
976976
break;
977977

978978
case BUG_TRAP_TYPE_WARN:
@@ -1040,7 +1040,7 @@ static int kasan_handler(struct pt_regs *regs, unsigned long esr)
10401040
* This is something that might be fixed at some point in the future.
10411041
*/
10421042
if (!recover)
1043-
die("Oops - KASAN", regs, 0);
1043+
die("Oops - KASAN", regs, esr);
10441044

10451045
/* If thread survives, skip over the brk instruction and continue: */
10461046
arm64_skip_faulting_instruction(regs, AARCH64_INSN_SIZE);

0 commit comments

Comments
 (0)