Skip to content

Commit

Permalink
Merge tag 'kgdb-4.21-rc1' of git://git.kernel.org/pub/scm/linux/kerne…
Browse files Browse the repository at this point in the history
…l/git/danielt/linux

Pull kgdb updates from Daniel Thompson:
 "Mostly clean ups although while Doug's was chasing down a odd lockdep
  warning he also did some work to improved debugger resilience when
  some CPUs fail to respond to the round up request.

  The main changes are:

   - Fixing a lockdep warning on architectures that cannot use an NMI
     for the round up plus related changes to make CPU round up and all
     CPU backtrace more resilient.

   - Constify the arch ops tables

   - A couple of other small clean ups

  Two of the three patchsets here include changes that spill over into
  arch/. Changes in the arch space are relatively narrow in scope (and
  directly related to kgdb). Didn't get comprehensive acks but all
  impacted maintainers were Cc:ed in good time"

* tag 'kgdb-4.21-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/danielt/linux:
  kgdb/treewide: constify struct kgdb_arch arch_kgdb_ops
  mips/kgdb: prepare arch_kgdb_ops for constness
  kdb: use bool for binary state indicators
  kdb: Don't back trace on a cpu that didn't round up
  kgdb: Don't round up a CPU that failed rounding up before
  kgdb: Fix kgdb_roundup_cpus() for arches who used smp_call_function()
  kgdb: Remove irq flags from roundup
  • Loading branch information
torvalds committed Jan 1, 2019
2 parents fbea8c7 + cc02829 commit fcf0104
Show file tree
Hide file tree
Showing 20 changed files with 125 additions and 141 deletions.
12 changes: 3 additions & 9 deletions arch/arc/kernel/kgdb.c
Original file line number Diff line number Diff line change
Expand Up @@ -192,19 +192,13 @@ void kgdb_arch_set_pc(struct pt_regs *regs, unsigned long ip)
instruction_pointer(regs) = ip;
}

static void kgdb_call_nmi_hook(void *ignored)
void kgdb_call_nmi_hook(void *ignored)
{
/* Default implementation passes get_irq_regs() but we don't */
kgdb_nmicallback(raw_smp_processor_id(), NULL);
}

void kgdb_roundup_cpus(unsigned long flags)
{
local_irq_enable();
smp_call_function(kgdb_call_nmi_hook, NULL, 0);
local_irq_disable();
}

struct kgdb_arch arch_kgdb_ops = {
const struct kgdb_arch arch_kgdb_ops = {
/* breakpoint instruction: TRAP_S 0x3 */
#ifdef CONFIG_CPU_BIG_ENDIAN
.gdb_bpt_instr = {0x78, 0x7e},
Expand Down
14 changes: 1 addition & 13 deletions arch/arm/kernel/kgdb.c
Original file line number Diff line number Diff line change
Expand Up @@ -170,18 +170,6 @@ static struct undef_hook kgdb_compiled_brkpt_hook = {
.fn = kgdb_compiled_brk_fn
};

static void kgdb_call_nmi_hook(void *ignored)
{
kgdb_nmicallback(raw_smp_processor_id(), get_irq_regs());
}

void kgdb_roundup_cpus(unsigned long flags)
{
local_irq_enable();
smp_call_function(kgdb_call_nmi_hook, NULL, 0);
local_irq_disable();
}

static int __kgdb_notify(struct die_args *args, unsigned long cmd)
{
struct pt_regs *regs = args->regs;
Expand Down Expand Up @@ -274,7 +262,7 @@ int kgdb_arch_remove_breakpoint(struct kgdb_bkpt *bpt)
* and we handle the normal undef case within the do_undefinstr
* handler.
*/
struct kgdb_arch arch_kgdb_ops = {
const struct kgdb_arch arch_kgdb_ops = {
#ifndef __ARMEB__
.gdb_bpt_instr = {0xfe, 0xde, 0xff, 0xe7}
#else /* ! __ARMEB__ */
Expand Down
14 changes: 1 addition & 13 deletions arch/arm64/kernel/kgdb.c
Original file line number Diff line number Diff line change
Expand Up @@ -284,18 +284,6 @@ static struct step_hook kgdb_step_hook = {
.fn = kgdb_step_brk_fn
};

static void kgdb_call_nmi_hook(void *ignored)
{
kgdb_nmicallback(raw_smp_processor_id(), get_irq_regs());
}

void kgdb_roundup_cpus(unsigned long flags)
{
local_irq_enable();
smp_call_function(kgdb_call_nmi_hook, NULL, 0);
local_irq_disable();
}

static int __kgdb_notify(struct die_args *args, unsigned long cmd)
{
struct pt_regs *regs = args->regs;
Expand Down Expand Up @@ -357,7 +345,7 @@ void kgdb_arch_exit(void)
unregister_die_notifier(&kgdb_notifier);
}

struct kgdb_arch arch_kgdb_ops;
const struct kgdb_arch arch_kgdb_ops;

int kgdb_arch_set_breakpoint(struct kgdb_bkpt *bpt)
{
Expand Down
2 changes: 1 addition & 1 deletion arch/h8300/kernel/kgdb.c
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ void kgdb_arch_exit(void)
/* Nothing to do */
}

struct kgdb_arch arch_kgdb_ops = {
const struct kgdb_arch arch_kgdb_ops = {
/* Breakpoint instruction: trapa #2 */
.gdb_bpt_instr = { 0x57, 0x20 },
};
34 changes: 1 addition & 33 deletions arch/hexagon/kernel/kgdb.c
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ struct dbg_reg_def_t dbg_reg_def[DBG_MAX_REG_NUM] = {
{ "syscall_nr", GDB_SIZEOF_REG, offsetof(struct pt_regs, syscall_nr)},
};

struct kgdb_arch arch_kgdb_ops = {
const struct kgdb_arch arch_kgdb_ops = {
/* trap0(#0xDB) 0x0cdb0054 */
.gdb_bpt_instr = {0x54, 0x00, 0xdb, 0x0c},
};
Expand Down Expand Up @@ -115,38 +115,6 @@ void kgdb_arch_set_pc(struct pt_regs *regs, unsigned long pc)
instruction_pointer(regs) = pc;
}

#ifdef CONFIG_SMP

/**
* kgdb_roundup_cpus - Get other CPUs into a holding pattern
* @flags: Current IRQ state
*
* On SMP systems, we need to get the attention of the other CPUs
* and get them be in a known state. This should do what is needed
* to get the other CPUs to call kgdb_wait(). Note that on some arches,
* the NMI approach is not used for rounding up all the CPUs. For example,
* in case of MIPS, smp_call_function() is used to roundup CPUs. In
* this case, we have to make sure that interrupts are enabled before
* calling smp_call_function(). The argument to this function is
* the flags that will be used when restoring the interrupts. There is
* local_irq_save() call before kgdb_roundup_cpus().
*
* On non-SMP systems, this is not called.
*/

static void hexagon_kgdb_nmi_hook(void *ignored)
{
kgdb_nmicallback(raw_smp_processor_id(), get_irq_regs());
}

void kgdb_roundup_cpus(unsigned long flags)
{
local_irq_enable();
smp_call_function(hexagon_kgdb_nmi_hook, NULL, 0);
local_irq_disable();
}
#endif


/* Not yet working */
void sleeping_thread_to_gdb_regs(unsigned long *gdb_regs,
Expand Down
2 changes: 1 addition & 1 deletion arch/microblaze/kernel/kgdb.c
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ void kgdb_arch_exit(void)
/*
* Global data
*/
struct kgdb_arch arch_kgdb_ops = {
const struct kgdb_arch arch_kgdb_ops = {
#ifdef __MICROBLAZEEL__
.gdb_bpt_instr = {0x18, 0x00, 0x0c, 0xba}, /* brki r16, 0x18 */
#else
Expand Down
25 changes: 8 additions & 17 deletions arch/mips/kernel/kgdb.c
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ void arch_kgdb_breakpoint(void)
".set\treorder");
}

static void kgdb_call_nmi_hook(void *ignored)
void kgdb_call_nmi_hook(void *ignored)
{
mm_segment_t old_fs;

Expand All @@ -219,13 +219,6 @@ static void kgdb_call_nmi_hook(void *ignored)
set_fs(old_fs);
}

void kgdb_roundup_cpus(unsigned long flags)
{
local_irq_enable();
smp_call_function(kgdb_call_nmi_hook, NULL, 0);
local_irq_disable();
}

static int compute_signal(int tt)
{
struct hard_trap_info *ht;
Expand Down Expand Up @@ -394,18 +387,16 @@ int kgdb_arch_handle_exception(int vector, int signo, int err_code,
return -1;
}

struct kgdb_arch arch_kgdb_ops;
const struct kgdb_arch arch_kgdb_ops = {
#ifdef CONFIG_CPU_BIG_ENDIAN
.gdb_bpt_instr = { spec_op << 2, 0x00, 0x00, break_op },
#else
.gdb_bpt_instr = { break_op, 0x00, 0x00, spec_op << 2 },
#endif
};

int kgdb_arch_init(void)
{
union mips_instruction insn = {
.r_format = {
.opcode = spec_op,
.func = break_op,
}
};
memcpy(arch_kgdb_ops.gdb_bpt_instr, insn.byte, BREAK_INSTR_SIZE);

register_die_notifier(&kgdb_notifier);

return 0;
Expand Down
2 changes: 1 addition & 1 deletion arch/nios2/kernel/kgdb.c
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ void kgdb_arch_exit(void)
/* Nothing to do */
}

struct kgdb_arch arch_kgdb_ops = {
const struct kgdb_arch arch_kgdb_ops = {
/* Breakpoint instruction: trap 30 */
.gdb_bpt_instr = { 0xba, 0x6f, 0x3b, 0x00 },
};
8 changes: 4 additions & 4 deletions arch/powerpc/kernel/kgdb.c
Original file line number Diff line number Diff line change
Expand Up @@ -117,14 +117,14 @@ int kgdb_skipexception(int exception, struct pt_regs *regs)
return kgdb_isremovedbreak(regs->nip);
}

static int kgdb_call_nmi_hook(struct pt_regs *regs)
static int kgdb_debugger_ipi(struct pt_regs *regs)
{
kgdb_nmicallback(raw_smp_processor_id(), regs);
return 0;
}

#ifdef CONFIG_SMP
void kgdb_roundup_cpus(unsigned long flags)
void kgdb_roundup_cpus(void)
{
smp_send_debugger_break();
}
Expand Down Expand Up @@ -477,7 +477,7 @@ int kgdb_arch_remove_breakpoint(struct kgdb_bkpt *bpt)
/*
* Global data
*/
struct kgdb_arch arch_kgdb_ops;
const struct kgdb_arch arch_kgdb_ops;

static int kgdb_not_implemented(struct pt_regs *regs)
{
Expand All @@ -502,7 +502,7 @@ int kgdb_arch_init(void)
old__debugger_break_match = __debugger_break_match;
old__debugger_fault_handler = __debugger_fault_handler;

__debugger_ipi = kgdb_call_nmi_hook;
__debugger_ipi = kgdb_debugger_ipi;
__debugger = kgdb_debugger;
__debugger_bpt = kgdb_handle_breakpoint;
__debugger_sstep = kgdb_singlestep;
Expand Down
14 changes: 1 addition & 13 deletions arch/sh/kernel/kgdb.c
Original file line number Diff line number Diff line change
Expand Up @@ -311,18 +311,6 @@ BUILD_TRAP_HANDLER(singlestep)
local_irq_restore(flags);
}

static void kgdb_call_nmi_hook(void *ignored)
{
kgdb_nmicallback(raw_smp_processor_id(), get_irq_regs());
}

void kgdb_roundup_cpus(unsigned long flags)
{
local_irq_enable();
smp_call_function(kgdb_call_nmi_hook, NULL, 0);
local_irq_disable();
}

static int __kgdb_notify(struct die_args *args, unsigned long cmd)
{
int ret;
Expand Down Expand Up @@ -379,7 +367,7 @@ void kgdb_arch_exit(void)
unregister_die_notifier(&kgdb_notifier);
}

struct kgdb_arch arch_kgdb_ops = {
const struct kgdb_arch arch_kgdb_ops = {
/* Breakpoint instruction: trapa #0x3c */
#ifdef CONFIG_CPU_LITTLE_ENDIAN
.gdb_bpt_instr = { 0x3c, 0xc3 },
Expand Down
2 changes: 1 addition & 1 deletion arch/sparc/kernel/kgdb_32.c
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ void kgdb_arch_set_pc(struct pt_regs *regs, unsigned long ip)
regs->npc = regs->pc + 4;
}

struct kgdb_arch arch_kgdb_ops = {
const struct kgdb_arch arch_kgdb_ops = {
/* Breakpoint instruction: ta 0x7d */
.gdb_bpt_instr = { 0x91, 0xd0, 0x20, 0x7d },
};
2 changes: 1 addition & 1 deletion arch/sparc/kernel/kgdb_64.c
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ void kgdb_arch_set_pc(struct pt_regs *regs, unsigned long ip)
regs->tnpc = regs->tpc + 4;
}

struct kgdb_arch arch_kgdb_ops = {
const struct kgdb_arch arch_kgdb_ops = {
/* Breakpoint instruction: ta 0x72 */
.gdb_bpt_instr = { 0x91, 0xd0, 0x20, 0x72 },
};
2 changes: 1 addition & 1 deletion arch/sparc/kernel/smp_64.c
Original file line number Diff line number Diff line change
Expand Up @@ -1014,7 +1014,7 @@ void flush_dcache_page_all(struct mm_struct *mm, struct page *page)
}

#ifdef CONFIG_KGDB
void kgdb_roundup_cpus(unsigned long flags)
void kgdb_roundup_cpus(void)
{
smp_cross_call(&xcall_kgdb_capture, 0, 0, 0);
}
Expand Down
11 changes: 3 additions & 8 deletions arch/x86/kernel/kgdb.c
Original file line number Diff line number Diff line change
Expand Up @@ -422,21 +422,16 @@ static void kgdb_disable_hw_debug(struct pt_regs *regs)
#ifdef CONFIG_SMP
/**
* kgdb_roundup_cpus - Get other CPUs into a holding pattern
* @flags: Current IRQ state
*
* On SMP systems, we need to get the attention of the other CPUs
* and get them be in a known state. This should do what is needed
* to get the other CPUs to call kgdb_wait(). Note that on some arches,
* the NMI approach is not used for rounding up all the CPUs. For example,
* in case of MIPS, smp_call_function() is used to roundup CPUs. In
* this case, we have to make sure that interrupts are enabled before
* calling smp_call_function(). The argument to this function is
* the flags that will be used when restoring the interrupts. There is
* local_irq_save() call before kgdb_roundup_cpus().
* in case of MIPS, smp_call_function() is used to roundup CPUs.
*
* On non-SMP systems, this is not called.
*/
void kgdb_roundup_cpus(unsigned long flags)
void kgdb_roundup_cpus(void)
{
apic->send_IPI_allbutself(APIC_DM_NMI);
}
Expand Down Expand Up @@ -804,7 +799,7 @@ int kgdb_arch_remove_breakpoint(struct kgdb_bkpt *bpt)
(char *)bpt->saved_instr, BREAK_INSTR_SIZE);
}

struct kgdb_arch arch_kgdb_ops = {
const struct kgdb_arch arch_kgdb_ops = {
/* Breakpoint instruction: */
.gdb_bpt_instr = { 0xcc },
.flags = KGDB_HW_BREAKPOINT,
Expand Down
24 changes: 15 additions & 9 deletions include/linux/kgdb.h
Original file line number Diff line number Diff line change
Expand Up @@ -176,23 +176,29 @@ kgdb_arch_handle_exception(int vector, int signo, int err_code,
char *remcom_out_buffer,
struct pt_regs *regs);

/**
* kgdb_call_nmi_hook - Call kgdb_nmicallback() on the current CPU
* @ignored: This parameter is only here to match the prototype.
*
* If you're using the default implementation of kgdb_roundup_cpus()
* this function will be called per CPU. If you don't implement
* kgdb_call_nmi_hook() a default will be used.
*/

extern void kgdb_call_nmi_hook(void *ignored);

/**
* kgdb_roundup_cpus - Get other CPUs into a holding pattern
* @flags: Current IRQ state
*
* On SMP systems, we need to get the attention of the other CPUs
* and get them into a known state. This should do what is needed
* to get the other CPUs to call kgdb_wait(). Note that on some arches,
* the NMI approach is not used for rounding up all the CPUs. For example,
* in case of MIPS, smp_call_function() is used to roundup CPUs. In
* this case, we have to make sure that interrupts are enabled before
* calling smp_call_function(). The argument to this function is
* the flags that will be used when restoring the interrupts. There is
* local_irq_save() call before kgdb_roundup_cpus().
* the NMI approach is not used for rounding up all the CPUs. Normally
* those architectures can just not implement this and get the default.
*
* On non-SMP systems, this is not called.
*/
extern void kgdb_roundup_cpus(unsigned long flags);
extern void kgdb_roundup_cpus(void);

/**
* kgdb_arch_set_pc - Generic call back to the program counter
Expand Down Expand Up @@ -281,7 +287,7 @@ struct kgdb_io {
int is_console;
};

extern struct kgdb_arch arch_kgdb_ops;
extern const struct kgdb_arch arch_kgdb_ops;

extern unsigned long kgdb_arch_pc(int exception, struct pt_regs *regs);

Expand Down
Loading

0 comments on commit fcf0104

Please sign in to comment.