From fef814f8c85bc9ed7848aaf155dbf9c74de449ad Mon Sep 17 00:00:00 2001 From: Huibin Hong Date: Mon, 15 Nov 2021 03:09:59 +0000 Subject: [PATCH] fiq_debugger: fix bt bug when EL0_SP is 0xffffff8000000000 Bt command think if EL0_SP is less than 0xffffffcxxxxxxxxx it is user mode, but EL0_SP may be 0xffffff8xxxxxxxxx. According to ARM-V8, the virtual address bit63 determine TTBR0 OR TTBR1. So if EL0_SP is less than 0x8000000000000000, it is user mode. Signed-off-by: Huibin Hong Change-Id: Ib97b405df6e669e3806161c97801847e2f5d247a --- .../staging/android/fiq_debugger/fiq_debugger.c | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/drivers/staging/android/fiq_debugger/fiq_debugger.c b/drivers/staging/android/fiq_debugger/fiq_debugger.c index 079b9e442e21..66605f62bdb2 100644 --- a/drivers/staging/android/fiq_debugger/fiq_debugger.c +++ b/drivers/staging/android/fiq_debugger/fiq_debugger.c @@ -632,13 +632,7 @@ static bool fiq_debugger_fiq_exec(struct fiq_debugger_state *state, void *svc_sp) { bool signal_helper = false; - unsigned long va_start; -#ifdef CONFIG_ARM64 - va_start = PAGE_END; -#else - va_start = PAGE_OFFSET; -#endif if (!strcmp(cmd, "help") || !strcmp(cmd, "?")) { fiq_debugger_help(state); } else if (!strcmp(cmd, "pc")) { @@ -649,9 +643,14 @@ static bool fiq_debugger_fiq_exec(struct fiq_debugger_state *state, fiq_debugger_dump_allregs(&state->output, regs); #ifndef CONFIG_FIQ_DEBUGGER_MODULE } else if (!strcmp(cmd, "bt")) { + /* + * ARM64: + * Cpu is at ELx(1 or 2), but EL0_SP(svc_sp) may be user space. + * If EL0_SP.63 is 0, use TTBR0. + */ if (user_mode((struct pt_regs *)regs) || - ((unsigned long)svc_sp < va_start) || - ((unsigned long)svc_sp > -256UL)) + (IS_ENABLED(CONFIG_ARM64) && (((unsigned long)svc_sp & 0x8000000000000000) == 0)) || + (IS_ENABLED(CONFIG_ARM) && (((unsigned long)svc_sp < PAGE_OFFSET) || ((unsigned long)svc_sp > -256UL)))) fiq_debugger_printf(&state->output, "User mode\n"); else fiq_debugger_dump_stacktrace(&state->output, regs,