Commit 7a928b32 authored by Pierre-Clément Tosi's avatar Pierre-Clément Tosi Committed by Oliver Upton

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: default avatarPierre-Clément Tosi <ptosi@google.com>
Acked-by: default avatarWill Deacon <will@kernel.org>
Link: https://lore.kernel.org/r/20240610063244.2828978-7-ptosi@google.comSigned-off-by: default avatarOliver Upton <oliver.upton@linux.dev>
parent 3c6eb648
...@@ -379,6 +379,11 @@ ...@@ -379,6 +379,11 @@
#ifndef __ASSEMBLY__ #ifndef __ASSEMBLY__
#include <asm/types.h> #include <asm/types.h>
static inline unsigned long esr_brk_comment(unsigned long esr)
{
return esr & ESR_ELx_BRK64_ISS_COMMENT_MASK;
}
static inline bool esr_is_data_abort(unsigned long esr) static inline bool esr_is_data_abort(unsigned long esr)
{ {
const unsigned long ec = ESR_ELx_EC(esr); const unsigned long ec = ESR_ELx_EC(esr);
...@@ -386,6 +391,12 @@ static inline bool esr_is_data_abort(unsigned long esr) ...@@ -386,6 +391,12 @@ static inline bool esr_is_data_abort(unsigned long esr)
return ec == ESR_ELx_EC_DABT_LOW || ec == ESR_ELx_EC_DABT_CUR; return ec == ESR_ELx_EC_DABT_LOW || ec == ESR_ELx_EC_DABT_CUR;
} }
static inline bool esr_is_cfi_brk(unsigned long esr)
{
return ESR_ELx_EC(esr) == ESR_ELx_EC_BRK64 &&
(esr_brk_comment(esr) & ~CFI_BRK_IMM_MASK) == CFI_BRK_IMM_BASE;
}
static inline bool esr_fsc_is_translation_fault(unsigned long esr) static inline bool esr_fsc_is_translation_fault(unsigned long esr)
{ {
/* Translation fault, level -1 */ /* Translation fault, level -1 */
......
...@@ -312,9 +312,7 @@ static int call_break_hook(struct pt_regs *regs, unsigned long esr) ...@@ -312,9 +312,7 @@ static int call_break_hook(struct pt_regs *regs, unsigned long esr)
* entirely not preemptible, and we can use rcu list safely here. * entirely not preemptible, and we can use rcu list safely here.
*/ */
list_for_each_entry_rcu(hook, list, node) { list_for_each_entry_rcu(hook, list, node) {
unsigned long comment = esr & ESR_ELx_BRK64_ISS_COMMENT_MASK; if ((esr_brk_comment(esr) & ~hook->mask) == hook->imm)
if ((comment & ~hook->mask) == hook->imm)
fn = hook->fn; fn = hook->fn;
} }
......
...@@ -1105,8 +1105,6 @@ static struct break_hook ubsan_break_hook = { ...@@ -1105,8 +1105,6 @@ static struct break_hook ubsan_break_hook = {
}; };
#endif #endif
#define esr_comment(esr) ((esr) & ESR_ELx_BRK64_ISS_COMMENT_MASK)
/* /*
* Initial handler for AArch64 BRK exceptions * Initial handler for AArch64 BRK exceptions
* This handler only used until debug_traps_init(). * This handler only used until debug_traps_init().
...@@ -1115,15 +1113,15 @@ int __init early_brk64(unsigned long addr, unsigned long esr, ...@@ -1115,15 +1113,15 @@ int __init early_brk64(unsigned long addr, unsigned long esr,
struct pt_regs *regs) struct pt_regs *regs)
{ {
#ifdef CONFIG_CFI_CLANG #ifdef CONFIG_CFI_CLANG
if ((esr_comment(esr) & ~CFI_BRK_IMM_MASK) == CFI_BRK_IMM_BASE) if (esr_is_cfi_brk(esr))
return cfi_handler(regs, esr) != DBG_HOOK_HANDLED; return cfi_handler(regs, esr) != DBG_HOOK_HANDLED;
#endif #endif
#ifdef CONFIG_KASAN_SW_TAGS #ifdef CONFIG_KASAN_SW_TAGS
if ((esr_comment(esr) & ~KASAN_BRK_MASK) == KASAN_BRK_IMM) if ((esr_brk_comment(esr) & ~KASAN_BRK_MASK) == KASAN_BRK_IMM)
return kasan_handler(regs, esr) != DBG_HOOK_HANDLED; return kasan_handler(regs, esr) != DBG_HOOK_HANDLED;
#endif #endif
#ifdef CONFIG_UBSAN_TRAP #ifdef CONFIG_UBSAN_TRAP
if ((esr_comment(esr) & ~UBSAN_BRK_MASK) == UBSAN_BRK_IMM) if ((esr_brk_comment(esr) & ~UBSAN_BRK_MASK) == UBSAN_BRK_IMM)
return ubsan_handler(regs, esr) != DBG_HOOK_HANDLED; return ubsan_handler(regs, esr) != DBG_HOOK_HANDLED;
#endif #endif
return bug_handler(regs, esr) != DBG_HOOK_HANDLED; return bug_handler(regs, esr) != DBG_HOOK_HANDLED;
......
...@@ -423,7 +423,7 @@ void __noreturn __cold nvhe_hyp_panic_handler(u64 esr, u64 spsr, ...@@ -423,7 +423,7 @@ void __noreturn __cold nvhe_hyp_panic_handler(u64 esr, u64 spsr,
if (mode != PSR_MODE_EL2t && mode != PSR_MODE_EL2h) { if (mode != PSR_MODE_EL2t && mode != PSR_MODE_EL2h) {
kvm_err("Invalid host exception to nVHE hyp!\n"); kvm_err("Invalid host exception to nVHE hyp!\n");
} else if (ESR_ELx_EC(esr) == ESR_ELx_EC_BRK64 && } else if (ESR_ELx_EC(esr) == ESR_ELx_EC_BRK64 &&
(esr & ESR_ELx_BRK64_ISS_COMMENT_MASK) == BUG_BRK_IMM) { esr_brk_comment(esr) == BUG_BRK_IMM) {
const char *file = NULL; const char *file = NULL;
unsigned int line = 0; unsigned int line = 0;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment