Skip to content

Commit 7a928b3

Browse files
ptosioupton
authored andcommitted
arm64: Introduce esr_brk_comment, esr_is_cfi_brk
As it is already used in two places, move esr_comment() to a header for re-use, with a clearer name. Introduce esr_is_cfi_brk() to detect kCFI BRK syndromes, currently used by early_brk64() but soon to also be used by hypervisor code. Signed-off-by: Pierre-Clément Tosi <[email protected]> Acked-by: Will Deacon <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Oliver Upton <[email protected]>
1 parent 3c6eb64 commit 7a928b3

File tree

4 files changed

+16
-9
lines changed

4 files changed

+16
-9
lines changed

arch/arm64/include/asm/esr.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -379,13 +379,24 @@
379379
#ifndef __ASSEMBLY__
380380
#include <asm/types.h>
381381

382+
static inline unsigned long esr_brk_comment(unsigned long esr)
383+
{
384+
return esr & ESR_ELx_BRK64_ISS_COMMENT_MASK;
385+
}
386+
382387
static inline bool esr_is_data_abort(unsigned long esr)
383388
{
384389
const unsigned long ec = ESR_ELx_EC(esr);
385390

386391
return ec == ESR_ELx_EC_DABT_LOW || ec == ESR_ELx_EC_DABT_CUR;
387392
}
388393

394+
static inline bool esr_is_cfi_brk(unsigned long esr)
395+
{
396+
return ESR_ELx_EC(esr) == ESR_ELx_EC_BRK64 &&
397+
(esr_brk_comment(esr) & ~CFI_BRK_IMM_MASK) == CFI_BRK_IMM_BASE;
398+
}
399+
389400
static inline bool esr_fsc_is_translation_fault(unsigned long esr)
390401
{
391402
/* Translation fault, level -1 */

arch/arm64/kernel/debug-monitors.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -312,9 +312,7 @@ static int call_break_hook(struct pt_regs *regs, unsigned long esr)
312312
* entirely not preemptible, and we can use rcu list safely here.
313313
*/
314314
list_for_each_entry_rcu(hook, list, node) {
315-
unsigned long comment = esr & ESR_ELx_BRK64_ISS_COMMENT_MASK;
316-
317-
if ((comment & ~hook->mask) == hook->imm)
315+
if ((esr_brk_comment(esr) & ~hook->mask) == hook->imm)
318316
fn = hook->fn;
319317
}
320318

arch/arm64/kernel/traps.c

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1105,8 +1105,6 @@ static struct break_hook ubsan_break_hook = {
11051105
};
11061106
#endif
11071107

1108-
#define esr_comment(esr) ((esr) & ESR_ELx_BRK64_ISS_COMMENT_MASK)
1109-
11101108
/*
11111109
* Initial handler for AArch64 BRK exceptions
11121110
* This handler only used until debug_traps_init().
@@ -1115,15 +1113,15 @@ int __init early_brk64(unsigned long addr, unsigned long esr,
11151113
struct pt_regs *regs)
11161114
{
11171115
#ifdef CONFIG_CFI_CLANG
1118-
if ((esr_comment(esr) & ~CFI_BRK_IMM_MASK) == CFI_BRK_IMM_BASE)
1116+
if (esr_is_cfi_brk(esr))
11191117
return cfi_handler(regs, esr) != DBG_HOOK_HANDLED;
11201118
#endif
11211119
#ifdef CONFIG_KASAN_SW_TAGS
1122-
if ((esr_comment(esr) & ~KASAN_BRK_MASK) == KASAN_BRK_IMM)
1120+
if ((esr_brk_comment(esr) & ~KASAN_BRK_MASK) == KASAN_BRK_IMM)
11231121
return kasan_handler(regs, esr) != DBG_HOOK_HANDLED;
11241122
#endif
11251123
#ifdef CONFIG_UBSAN_TRAP
1126-
if ((esr_comment(esr) & ~UBSAN_BRK_MASK) == UBSAN_BRK_IMM)
1124+
if ((esr_brk_comment(esr) & ~UBSAN_BRK_MASK) == UBSAN_BRK_IMM)
11271125
return ubsan_handler(regs, esr) != DBG_HOOK_HANDLED;
11281126
#endif
11291127
return bug_handler(regs, esr) != DBG_HOOK_HANDLED;

arch/arm64/kvm/handle_exit.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -423,7 +423,7 @@ void __noreturn __cold nvhe_hyp_panic_handler(u64 esr, u64 spsr,
423423
if (mode != PSR_MODE_EL2t && mode != PSR_MODE_EL2h) {
424424
kvm_err("Invalid host exception to nVHE hyp!\n");
425425
} else if (ESR_ELx_EC(esr) == ESR_ELx_EC_BRK64 &&
426-
(esr & ESR_ELx_BRK64_ISS_COMMENT_MASK) == BUG_BRK_IMM) {
426+
esr_brk_comment(esr) == BUG_BRK_IMM) {
427427
const char *file = NULL;
428428
unsigned int line = 0;
429429

0 commit comments

Comments
 (0)