forked from luck/tmp_suning_uos_patched
3cd99ac355
When I had lockdep turned on and dropped into kgdb I got a nice splat on my system. Specifically it hit: DEBUG_LOCKS_WARN_ON(current->hardirq_context) Specifically it looked like this: sysrq: SysRq : DEBUG ------------[ cut here ]------------ DEBUG_LOCKS_WARN_ON(current->hardirq_context) WARNING: CPU: 0 PID: 0 at .../kernel/locking/lockdep.c:2875 lockdep_hardirqs_on+0xf0/0x160 CPU: 0 PID: 0 Comm: swapper/0 Not tainted 4.19.0 #27 pstate: 604003c9 (nZCv DAIF +PAN -UAO) pc : lockdep_hardirqs_on+0xf0/0x160 ... Call trace: lockdep_hardirqs_on+0xf0/0x160 trace_hardirqs_on+0x188/0x1ac kgdb_roundup_cpus+0x14/0x3c kgdb_cpu_enter+0x53c/0x5cc kgdb_handle_exception+0x180/0x1d4 kgdb_compiled_brk_fn+0x30/0x3c brk_handler+0x134/0x178 do_debug_exception+0xfc/0x178 el1_dbg+0x18/0x78 kgdb_breakpoint+0x34/0x58 sysrq_handle_dbg+0x54/0x5c __handle_sysrq+0x114/0x21c handle_sysrq+0x30/0x3c qcom_geni_serial_isr+0x2dc/0x30c ... ... irq event stamp: ...45 hardirqs last enabled at (...44): [...] __do_softirq+0xd8/0x4e4 hardirqs last disabled at (...45): [...] el1_irq+0x74/0x130 softirqs last enabled at (...42): [...] _local_bh_enable+0x2c/0x34 softirqs last disabled at (...43): [...] irq_exit+0xa8/0x100 ---[ end trace adf21f830c46e638 ]--- Looking closely at it, it seems like a really bad idea to be calling local_irq_enable() in kgdb_roundup_cpus(). If nothing else that seems like it could violate spinlock semantics and cause a deadlock. Instead, let's use a private csd alongside smp_call_function_single_async() to round up the other CPUs. Using smp_call_function_single_async() doesn't require interrupts to be enabled so we can remove the offending bit of code. In order to avoid duplicating this across all the architectures that use the default kgdb_roundup_cpus(), we'll add a "weak" implementation to debug_core.c. Looking at all the people who previously had copies of this code, there were a few variants. I've attempted to keep the variants working like they used to. Specifically: * For arch/arc we passed NULL to kgdb_nmicallback() instead of get_irq_regs(). * For arch/mips there was a bit of extra code around kgdb_nmicallback() NOTE: In this patch we will still get into trouble if we try to round up a CPU that failed to round up before. We'll try to round it up again and potentially hang when we try to grab the csd lock. That's not new behavior but we'll still try to do better in a future patch. Suggested-by: Daniel Thompson <daniel.thompson@linaro.org> Signed-off-by: Douglas Anderson <dianders@chromium.org> Cc: Vineet Gupta <vgupta@synopsys.com> Cc: Russell King <linux@armlinux.org.uk> Cc: Catalin Marinas <catalin.marinas@arm.com> Cc: Will Deacon <will.deacon@arm.com> Cc: Richard Kuo <rkuo@codeaurora.org> Cc: Ralf Baechle <ralf@linux-mips.org> Cc: Paul Burton <paul.burton@mips.com> Cc: James Hogan <jhogan@kernel.org> Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org> Cc: Paul Mackerras <paulus@samba.org> Cc: Michael Ellerman <mpe@ellerman.id.au> Cc: Yoshinori Sato <ysato@users.sourceforge.jp> Cc: Rich Felker <dalias@libc.org> Cc: "David S. Miller" <davem@davemloft.net> Cc: Thomas Gleixner <tglx@linutronix.de> Cc: Ingo Molnar <mingo@redhat.com> Cc: Borislav Petkov <bp@alien8.de> Cc: "H. Peter Anvin" <hpa@zytor.com> Acked-by: Will Deacon <will.deacon@arm.com> Signed-off-by: Daniel Thompson <daniel.thompson@linaro.org>
272 lines
6.5 KiB
C
272 lines
6.5 KiB
C
// SPDX-License-Identifier: GPL-2.0
|
|
/*
|
|
* arch/arm/kernel/kgdb.c
|
|
*
|
|
* ARM KGDB support
|
|
*
|
|
* Copyright (c) 2002-2004 MontaVista Software, Inc
|
|
* Copyright (c) 2008 Wind River Systems, Inc.
|
|
*
|
|
* Authors: George Davis <davis_g@mvista.com>
|
|
* Deepak Saxena <dsaxena@plexity.net>
|
|
*/
|
|
#include <linux/irq.h>
|
|
#include <linux/kdebug.h>
|
|
#include <linux/kgdb.h>
|
|
#include <linux/uaccess.h>
|
|
|
|
#include <asm/patch.h>
|
|
#include <asm/traps.h>
|
|
|
|
struct dbg_reg_def_t dbg_reg_def[DBG_MAX_REG_NUM] =
|
|
{
|
|
{ "r0", 4, offsetof(struct pt_regs, ARM_r0)},
|
|
{ "r1", 4, offsetof(struct pt_regs, ARM_r1)},
|
|
{ "r2", 4, offsetof(struct pt_regs, ARM_r2)},
|
|
{ "r3", 4, offsetof(struct pt_regs, ARM_r3)},
|
|
{ "r4", 4, offsetof(struct pt_regs, ARM_r4)},
|
|
{ "r5", 4, offsetof(struct pt_regs, ARM_r5)},
|
|
{ "r6", 4, offsetof(struct pt_regs, ARM_r6)},
|
|
{ "r7", 4, offsetof(struct pt_regs, ARM_r7)},
|
|
{ "r8", 4, offsetof(struct pt_regs, ARM_r8)},
|
|
{ "r9", 4, offsetof(struct pt_regs, ARM_r9)},
|
|
{ "r10", 4, offsetof(struct pt_regs, ARM_r10)},
|
|
{ "fp", 4, offsetof(struct pt_regs, ARM_fp)},
|
|
{ "ip", 4, offsetof(struct pt_regs, ARM_ip)},
|
|
{ "sp", 4, offsetof(struct pt_regs, ARM_sp)},
|
|
{ "lr", 4, offsetof(struct pt_regs, ARM_lr)},
|
|
{ "pc", 4, offsetof(struct pt_regs, ARM_pc)},
|
|
{ "f0", 12, -1 },
|
|
{ "f1", 12, -1 },
|
|
{ "f2", 12, -1 },
|
|
{ "f3", 12, -1 },
|
|
{ "f4", 12, -1 },
|
|
{ "f5", 12, -1 },
|
|
{ "f6", 12, -1 },
|
|
{ "f7", 12, -1 },
|
|
{ "fps", 4, -1 },
|
|
{ "cpsr", 4, offsetof(struct pt_regs, ARM_cpsr)},
|
|
};
|
|
|
|
char *dbg_get_reg(int regno, void *mem, struct pt_regs *regs)
|
|
{
|
|
if (regno >= DBG_MAX_REG_NUM || regno < 0)
|
|
return NULL;
|
|
|
|
if (dbg_reg_def[regno].offset != -1)
|
|
memcpy(mem, (void *)regs + dbg_reg_def[regno].offset,
|
|
dbg_reg_def[regno].size);
|
|
else
|
|
memset(mem, 0, dbg_reg_def[regno].size);
|
|
return dbg_reg_def[regno].name;
|
|
}
|
|
|
|
int dbg_set_reg(int regno, void *mem, struct pt_regs *regs)
|
|
{
|
|
if (regno >= DBG_MAX_REG_NUM || regno < 0)
|
|
return -EINVAL;
|
|
|
|
if (dbg_reg_def[regno].offset != -1)
|
|
memcpy((void *)regs + dbg_reg_def[regno].offset, mem,
|
|
dbg_reg_def[regno].size);
|
|
return 0;
|
|
}
|
|
|
|
void
|
|
sleeping_thread_to_gdb_regs(unsigned long *gdb_regs, struct task_struct *task)
|
|
{
|
|
struct thread_info *ti;
|
|
int regno;
|
|
|
|
/* Just making sure... */
|
|
if (task == NULL)
|
|
return;
|
|
|
|
/* Initialize to zero */
|
|
for (regno = 0; regno < GDB_MAX_REGS; regno++)
|
|
gdb_regs[regno] = 0;
|
|
|
|
/* Otherwise, we have only some registers from switch_to() */
|
|
ti = task_thread_info(task);
|
|
gdb_regs[_R4] = ti->cpu_context.r4;
|
|
gdb_regs[_R5] = ti->cpu_context.r5;
|
|
gdb_regs[_R6] = ti->cpu_context.r6;
|
|
gdb_regs[_R7] = ti->cpu_context.r7;
|
|
gdb_regs[_R8] = ti->cpu_context.r8;
|
|
gdb_regs[_R9] = ti->cpu_context.r9;
|
|
gdb_regs[_R10] = ti->cpu_context.sl;
|
|
gdb_regs[_FP] = ti->cpu_context.fp;
|
|
gdb_regs[_SPT] = ti->cpu_context.sp;
|
|
gdb_regs[_PC] = ti->cpu_context.pc;
|
|
}
|
|
|
|
void kgdb_arch_set_pc(struct pt_regs *regs, unsigned long pc)
|
|
{
|
|
regs->ARM_pc = pc;
|
|
}
|
|
|
|
static int compiled_break;
|
|
|
|
int kgdb_arch_handle_exception(int exception_vector, int signo,
|
|
int err_code, char *remcom_in_buffer,
|
|
char *remcom_out_buffer,
|
|
struct pt_regs *linux_regs)
|
|
{
|
|
unsigned long addr;
|
|
char *ptr;
|
|
|
|
switch (remcom_in_buffer[0]) {
|
|
case 'D':
|
|
case 'k':
|
|
case 'c':
|
|
/*
|
|
* Try to read optional parameter, pc unchanged if no parm.
|
|
* If this was a compiled breakpoint, we need to move
|
|
* to the next instruction or we will just breakpoint
|
|
* over and over again.
|
|
*/
|
|
ptr = &remcom_in_buffer[1];
|
|
if (kgdb_hex2long(&ptr, &addr))
|
|
linux_regs->ARM_pc = addr;
|
|
else if (compiled_break == 1)
|
|
linux_regs->ARM_pc += 4;
|
|
|
|
compiled_break = 0;
|
|
|
|
return 0;
|
|
}
|
|
|
|
return -1;
|
|
}
|
|
|
|
static int kgdb_brk_fn(struct pt_regs *regs, unsigned int instr)
|
|
{
|
|
kgdb_handle_exception(1, SIGTRAP, 0, regs);
|
|
|
|
return 0;
|
|
}
|
|
|
|
static int kgdb_compiled_brk_fn(struct pt_regs *regs, unsigned int instr)
|
|
{
|
|
compiled_break = 1;
|
|
kgdb_handle_exception(1, SIGTRAP, 0, regs);
|
|
|
|
return 0;
|
|
}
|
|
|
|
static struct undef_hook kgdb_brkpt_hook = {
|
|
.instr_mask = 0xffffffff,
|
|
.instr_val = KGDB_BREAKINST,
|
|
.cpsr_mask = MODE_MASK,
|
|
.cpsr_val = SVC_MODE,
|
|
.fn = kgdb_brk_fn
|
|
};
|
|
|
|
static struct undef_hook kgdb_compiled_brkpt_hook = {
|
|
.instr_mask = 0xffffffff,
|
|
.instr_val = KGDB_COMPILED_BREAK,
|
|
.cpsr_mask = MODE_MASK,
|
|
.cpsr_val = SVC_MODE,
|
|
.fn = kgdb_compiled_brk_fn
|
|
};
|
|
|
|
static int __kgdb_notify(struct die_args *args, unsigned long cmd)
|
|
{
|
|
struct pt_regs *regs = args->regs;
|
|
|
|
if (kgdb_handle_exception(1, args->signr, cmd, regs))
|
|
return NOTIFY_DONE;
|
|
return NOTIFY_STOP;
|
|
}
|
|
static int
|
|
kgdb_notify(struct notifier_block *self, unsigned long cmd, void *ptr)
|
|
{
|
|
unsigned long flags;
|
|
int ret;
|
|
|
|
local_irq_save(flags);
|
|
ret = __kgdb_notify(ptr, cmd);
|
|
local_irq_restore(flags);
|
|
|
|
return ret;
|
|
}
|
|
|
|
static struct notifier_block kgdb_notifier = {
|
|
.notifier_call = kgdb_notify,
|
|
.priority = -INT_MAX,
|
|
};
|
|
|
|
|
|
/**
|
|
* kgdb_arch_init - Perform any architecture specific initalization.
|
|
*
|
|
* This function will handle the initalization of any architecture
|
|
* specific callbacks.
|
|
*/
|
|
int kgdb_arch_init(void)
|
|
{
|
|
int ret = register_die_notifier(&kgdb_notifier);
|
|
|
|
if (ret != 0)
|
|
return ret;
|
|
|
|
register_undef_hook(&kgdb_brkpt_hook);
|
|
register_undef_hook(&kgdb_compiled_brkpt_hook);
|
|
|
|
return 0;
|
|
}
|
|
|
|
/**
|
|
* kgdb_arch_exit - Perform any architecture specific uninitalization.
|
|
*
|
|
* This function will handle the uninitalization of any architecture
|
|
* specific callbacks, for dynamic registration and unregistration.
|
|
*/
|
|
void kgdb_arch_exit(void)
|
|
{
|
|
unregister_undef_hook(&kgdb_brkpt_hook);
|
|
unregister_undef_hook(&kgdb_compiled_brkpt_hook);
|
|
unregister_die_notifier(&kgdb_notifier);
|
|
}
|
|
|
|
int kgdb_arch_set_breakpoint(struct kgdb_bkpt *bpt)
|
|
{
|
|
int err;
|
|
|
|
/* patch_text() only supports int-sized breakpoints */
|
|
BUILD_BUG_ON(sizeof(int) != BREAK_INSTR_SIZE);
|
|
|
|
err = probe_kernel_read(bpt->saved_instr, (char *)bpt->bpt_addr,
|
|
BREAK_INSTR_SIZE);
|
|
if (err)
|
|
return err;
|
|
|
|
/* Machine is already stopped, so we can use __patch_text() directly */
|
|
__patch_text((void *)bpt->bpt_addr,
|
|
*(unsigned int *)arch_kgdb_ops.gdb_bpt_instr);
|
|
|
|
return err;
|
|
}
|
|
|
|
int kgdb_arch_remove_breakpoint(struct kgdb_bkpt *bpt)
|
|
{
|
|
/* Machine is already stopped, so we can use __patch_text() directly */
|
|
__patch_text((void *)bpt->bpt_addr, *(unsigned int *)bpt->saved_instr);
|
|
|
|
return 0;
|
|
}
|
|
|
|
/*
|
|
* Register our undef instruction hooks with ARM undef core.
|
|
* We register a hook specifically looking for the KGB break inst
|
|
* and we handle the normal undef case within the do_undefinstr
|
|
* handler.
|
|
*/
|
|
struct kgdb_arch arch_kgdb_ops = {
|
|
#ifndef __ARMEB__
|
|
.gdb_bpt_instr = {0xfe, 0xde, 0xff, 0xe7}
|
|
#else /* ! __ARMEB__ */
|
|
.gdb_bpt_instr = {0xe7, 0xff, 0xde, 0xfe}
|
|
#endif
|
|
};
|