Skip to content

Commit

Permalink
Merge tag 'for_linus-3.19-rc4' of git://git.kernel.org/pub/scm/linux/…
Browse files Browse the repository at this point in the history
…kernel/git/jwessel/kgdb

Pull kgdb/kdb fixes from Jason Wessel:
 "These have been around since 3.17 and in kgdb-next for the last 9
  weeks and some will go back to -stable.

  Summary of changes:

  Cleanups
   - kdb: Remove unused command flags, repeat flags and KDB_REPEAT_NONE

  Fixes
   - kgdb/kdb: Allow access on a single core, if a CPU round up is
     deemed impossible, which will allow inspection of the now "trashed"
     kernel
   - kdb: Add enable mask for the command groups
   - kdb: access controls to restrict sensitive commands"

* tag 'for_linus-3.19-rc4' of git://git.kernel.org/pub/scm/linux/kernel/git/jwessel/kgdb:
  kernel/debug/debug_core.c: Logging clean-up
  kgdb: timeout if secondary CPUs ignore the roundup
  kdb: Allow access to sensitive commands to be restricted by default
  kdb: Add enable mask for groups of commands
  kdb: Categorize kdb commands (similar to SysRq categorization)
  kdb: Remove KDB_REPEAT_NONE flag
  kdb: Use KDB_REPEAT_* values as flags
  kdb: Rename kdb_register_repeat() to kdb_register_flags()
  kdb: Rename kdb_repeat_t to kdb_cmdflags_t, cmd_repeat to cmd_flags
  kdb: Remove currently unused kdbtab_t->cmd_flags
  • Loading branch information
torvalds committed Jan 10, 2015
2 parents dc9319f + 0f16996 commit aa92913
Show file tree
Hide file tree
Showing 8 changed files with 306 additions and 148 deletions.
62 changes: 53 additions & 9 deletions include/linux/kdb.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,54 @@
* Copyright (C) 2009 Jason Wessel <[email protected]>
*/

/* Shifted versions of the command enable bits are be used if the command
* has no arguments (see kdb_check_flags). This allows commands, such as
* go, to have different permissions depending upon whether it is called
* with an argument.
*/
#define KDB_ENABLE_NO_ARGS_SHIFT 10

typedef enum {
KDB_REPEAT_NONE = 0, /* Do not repeat this command */
KDB_REPEAT_NO_ARGS, /* Repeat the command without arguments */
KDB_REPEAT_WITH_ARGS, /* Repeat the command including its arguments */
} kdb_repeat_t;
KDB_ENABLE_ALL = (1 << 0), /* Enable everything */
KDB_ENABLE_MEM_READ = (1 << 1),
KDB_ENABLE_MEM_WRITE = (1 << 2),
KDB_ENABLE_REG_READ = (1 << 3),
KDB_ENABLE_REG_WRITE = (1 << 4),
KDB_ENABLE_INSPECT = (1 << 5),
KDB_ENABLE_FLOW_CTRL = (1 << 6),
KDB_ENABLE_SIGNAL = (1 << 7),
KDB_ENABLE_REBOOT = (1 << 8),
/* User exposed values stop here, all remaining flags are
* exclusively used to describe a commands behaviour.
*/

KDB_ENABLE_ALWAYS_SAFE = (1 << 9),
KDB_ENABLE_MASK = (1 << KDB_ENABLE_NO_ARGS_SHIFT) - 1,

KDB_ENABLE_ALL_NO_ARGS = KDB_ENABLE_ALL << KDB_ENABLE_NO_ARGS_SHIFT,
KDB_ENABLE_MEM_READ_NO_ARGS = KDB_ENABLE_MEM_READ
<< KDB_ENABLE_NO_ARGS_SHIFT,
KDB_ENABLE_MEM_WRITE_NO_ARGS = KDB_ENABLE_MEM_WRITE
<< KDB_ENABLE_NO_ARGS_SHIFT,
KDB_ENABLE_REG_READ_NO_ARGS = KDB_ENABLE_REG_READ
<< KDB_ENABLE_NO_ARGS_SHIFT,
KDB_ENABLE_REG_WRITE_NO_ARGS = KDB_ENABLE_REG_WRITE
<< KDB_ENABLE_NO_ARGS_SHIFT,
KDB_ENABLE_INSPECT_NO_ARGS = KDB_ENABLE_INSPECT
<< KDB_ENABLE_NO_ARGS_SHIFT,
KDB_ENABLE_FLOW_CTRL_NO_ARGS = KDB_ENABLE_FLOW_CTRL
<< KDB_ENABLE_NO_ARGS_SHIFT,
KDB_ENABLE_SIGNAL_NO_ARGS = KDB_ENABLE_SIGNAL
<< KDB_ENABLE_NO_ARGS_SHIFT,
KDB_ENABLE_REBOOT_NO_ARGS = KDB_ENABLE_REBOOT
<< KDB_ENABLE_NO_ARGS_SHIFT,
KDB_ENABLE_ALWAYS_SAFE_NO_ARGS = KDB_ENABLE_ALWAYS_SAFE
<< KDB_ENABLE_NO_ARGS_SHIFT,
KDB_ENABLE_MASK_NO_ARGS = KDB_ENABLE_MASK << KDB_ENABLE_NO_ARGS_SHIFT,

KDB_REPEAT_NO_ARGS = 0x40000000, /* Repeat the command w/o arguments */
KDB_REPEAT_WITH_ARGS = 0x80000000, /* Repeat the command with args */
} kdb_cmdflags_t;

typedef int (*kdb_func_t)(int, const char **);

Expand Down Expand Up @@ -62,6 +105,7 @@ extern atomic_t kdb_event;
#define KDB_BADLENGTH (-19)
#define KDB_NOBP (-20)
#define KDB_BADADDR (-21)
#define KDB_NOPERM (-22)

/*
* kdb_diemsg
Expand Down Expand Up @@ -146,17 +190,17 @@ static inline const char *kdb_walk_kallsyms(loff_t *pos)

/* Dynamic kdb shell command registration */
extern int kdb_register(char *, kdb_func_t, char *, char *, short);
extern int kdb_register_repeat(char *, kdb_func_t, char *, char *,
short, kdb_repeat_t);
extern int kdb_register_flags(char *, kdb_func_t, char *, char *,
short, kdb_cmdflags_t);
extern int kdb_unregister(char *);
#else /* ! CONFIG_KGDB_KDB */
static inline __printf(1, 2) int kdb_printf(const char *fmt, ...) { return 0; }
static inline void kdb_init(int level) {}
static inline int kdb_register(char *cmd, kdb_func_t func, char *usage,
char *help, short minlen) { return 0; }
static inline int kdb_register_repeat(char *cmd, kdb_func_t func, char *usage,
char *help, short minlen,
kdb_repeat_t repeat) { return 0; }
static inline int kdb_register_flags(char *cmd, kdb_func_t func, char *usage,
char *help, short minlen,
kdb_cmdflags_t flags) { return 0; }
static inline int kdb_unregister(char *cmd) { return 0; }
#endif /* CONFIG_KGDB_KDB */
enum {
Expand Down
52 changes: 28 additions & 24 deletions kernel/debug/debug_core.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@
* version 2. This program is licensed "as is" without any warranty of any
* kind, whether express or implied.
*/

#define pr_fmt(fmt) "KGDB: " fmt

#include <linux/pid_namespace.h>
#include <linux/clocksource.h>
#include <linux/serial_core.h>
Expand Down Expand Up @@ -196,8 +199,8 @@ int __weak kgdb_validate_break_address(unsigned long addr)
return err;
err = kgdb_arch_remove_breakpoint(&tmp);
if (err)
printk(KERN_ERR "KGDB: Critical breakpoint error, kernel "
"memory destroyed at: %lx", addr);
pr_err("Critical breakpoint error, kernel memory destroyed at: %lx\n",
addr);
return err;
}

Expand Down Expand Up @@ -256,8 +259,8 @@ int dbg_activate_sw_breakpoints(void)
error = kgdb_arch_set_breakpoint(&kgdb_break[i]);
if (error) {
ret = error;
printk(KERN_INFO "KGDB: BP install failed: %lx",
kgdb_break[i].bpt_addr);
pr_info("BP install failed: %lx\n",
kgdb_break[i].bpt_addr);
continue;
}

Expand Down Expand Up @@ -319,8 +322,8 @@ int dbg_deactivate_sw_breakpoints(void)
continue;
error = kgdb_arch_remove_breakpoint(&kgdb_break[i]);
if (error) {
printk(KERN_INFO "KGDB: BP remove failed: %lx\n",
kgdb_break[i].bpt_addr);
pr_info("BP remove failed: %lx\n",
kgdb_break[i].bpt_addr);
ret = error;
}

Expand Down Expand Up @@ -367,7 +370,7 @@ int dbg_remove_all_break(void)
goto setundefined;
error = kgdb_arch_remove_breakpoint(&kgdb_break[i]);
if (error)
printk(KERN_ERR "KGDB: breakpoint remove failed: %lx\n",
pr_err("breakpoint remove failed: %lx\n",
kgdb_break[i].bpt_addr);
setundefined:
kgdb_break[i].state = BP_UNDEFINED;
Expand Down Expand Up @@ -400,9 +403,9 @@ static int kgdb_io_ready(int print_wait)
if (print_wait) {
#ifdef CONFIG_KGDB_KDB
if (!dbg_kdb_mode)
printk(KERN_CRIT "KGDB: waiting... or $3#33 for KDB\n");
pr_crit("waiting... or $3#33 for KDB\n");
#else
printk(KERN_CRIT "KGDB: Waiting for remote debugger\n");
pr_crit("Waiting for remote debugger\n");
#endif
}
return 1;
Expand Down Expand Up @@ -430,8 +433,7 @@ static int kgdb_reenter_check(struct kgdb_state *ks)
exception_level = 0;
kgdb_skipexception(ks->ex_vector, ks->linux_regs);
dbg_activate_sw_breakpoints();
printk(KERN_CRIT "KGDB: re-enter error: breakpoint removed %lx\n",
addr);
pr_crit("re-enter error: breakpoint removed %lx\n", addr);
WARN_ON_ONCE(1);

return 1;
Expand All @@ -444,7 +446,7 @@ static int kgdb_reenter_check(struct kgdb_state *ks)
panic("Recursive entry to debugger");
}

printk(KERN_CRIT "KGDB: re-enter exception: ALL breakpoints killed\n");
pr_crit("re-enter exception: ALL breakpoints killed\n");
#ifdef CONFIG_KGDB_KDB
/* Allow kdb to debug itself one level */
return 0;
Expand All @@ -471,6 +473,7 @@ static int kgdb_cpu_enter(struct kgdb_state *ks, struct pt_regs *regs,
int cpu;
int trace_on = 0;
int online_cpus = num_online_cpus();
u64 time_left;

kgdb_info[ks->cpu].enter_kgdb++;
kgdb_info[ks->cpu].exception_state |= exception_state;
Expand Down Expand Up @@ -595,9 +598,13 @@ static int kgdb_cpu_enter(struct kgdb_state *ks, struct pt_regs *regs,
/*
* Wait for the other CPUs to be notified and be waiting for us:
*/
while (kgdb_do_roundup && (atomic_read(&masters_in_kgdb) +
atomic_read(&slaves_in_kgdb)) != online_cpus)
time_left = loops_per_jiffy * HZ;
while (kgdb_do_roundup && --time_left &&
(atomic_read(&masters_in_kgdb) + atomic_read(&slaves_in_kgdb)) !=
online_cpus)
cpu_relax();
if (!time_left)
pr_crit("KGDB: Timed out waiting for secondary CPUs.\n");

/*
* At this point the primary processor is completely
Expand Down Expand Up @@ -795,15 +802,15 @@ static struct console kgdbcons = {
static void sysrq_handle_dbg(int key)
{
if (!dbg_io_ops) {
printk(KERN_CRIT "ERROR: No KGDB I/O module available\n");
pr_crit("ERROR: No KGDB I/O module available\n");
return;
}
if (!kgdb_connected) {
#ifdef CONFIG_KGDB_KDB
if (!dbg_kdb_mode)
printk(KERN_CRIT "KGDB or $3#33 for KDB\n");
pr_crit("KGDB or $3#33 for KDB\n");
#else
printk(KERN_CRIT "Entering KGDB\n");
pr_crit("Entering KGDB\n");
#endif
}

Expand Down Expand Up @@ -945,7 +952,7 @@ static void kgdb_initial_breakpoint(void)
{
kgdb_break_asap = 0;

printk(KERN_CRIT "kgdb: Waiting for connection from remote gdb...\n");
pr_crit("Waiting for connection from remote gdb...\n");
kgdb_breakpoint();
}

Expand All @@ -964,8 +971,7 @@ int kgdb_register_io_module(struct kgdb_io *new_dbg_io_ops)
if (dbg_io_ops) {
spin_unlock(&kgdb_registration_lock);

printk(KERN_ERR "kgdb: Another I/O driver is already "
"registered with KGDB.\n");
pr_err("Another I/O driver is already registered with KGDB\n");
return -EBUSY;
}

Expand All @@ -981,8 +987,7 @@ int kgdb_register_io_module(struct kgdb_io *new_dbg_io_ops)

spin_unlock(&kgdb_registration_lock);

printk(KERN_INFO "kgdb: Registered I/O driver %s.\n",
new_dbg_io_ops->name);
pr_info("Registered I/O driver %s\n", new_dbg_io_ops->name);

/* Arm KGDB now. */
kgdb_register_callbacks();
Expand Down Expand Up @@ -1017,8 +1022,7 @@ void kgdb_unregister_io_module(struct kgdb_io *old_dbg_io_ops)

spin_unlock(&kgdb_registration_lock);

printk(KERN_INFO
"kgdb: Unregistered I/O driver %s, debugger disabled.\n",
pr_info("Unregistered I/O driver %s, debugger disabled\n",
old_dbg_io_ops->name);
}
EXPORT_SYMBOL_GPL(kgdb_unregister_io_module);
Expand Down
37 changes: 22 additions & 15 deletions kernel/debug/kdb/kdb_bp.c
Original file line number Diff line number Diff line change
Expand Up @@ -531,22 +531,29 @@ void __init kdb_initbptab(void)
for (i = 0, bp = kdb_breakpoints; i < KDB_MAXBPT; i++, bp++)
bp->bp_free = 1;

kdb_register_repeat("bp", kdb_bp, "[<vaddr>]",
"Set/Display breakpoints", 0, KDB_REPEAT_NO_ARGS);
kdb_register_repeat("bl", kdb_bp, "[<vaddr>]",
"Display breakpoints", 0, KDB_REPEAT_NO_ARGS);
kdb_register_flags("bp", kdb_bp, "[<vaddr>]",
"Set/Display breakpoints", 0,
KDB_ENABLE_FLOW_CTRL | KDB_REPEAT_NO_ARGS);
kdb_register_flags("bl", kdb_bp, "[<vaddr>]",
"Display breakpoints", 0,
KDB_ENABLE_FLOW_CTRL | KDB_REPEAT_NO_ARGS);
if (arch_kgdb_ops.flags & KGDB_HW_BREAKPOINT)
kdb_register_repeat("bph", kdb_bp, "[<vaddr>]",
"[datar [length]|dataw [length]] Set hw brk", 0, KDB_REPEAT_NO_ARGS);
kdb_register_repeat("bc", kdb_bc, "<bpnum>",
"Clear Breakpoint", 0, KDB_REPEAT_NONE);
kdb_register_repeat("be", kdb_bc, "<bpnum>",
"Enable Breakpoint", 0, KDB_REPEAT_NONE);
kdb_register_repeat("bd", kdb_bc, "<bpnum>",
"Disable Breakpoint", 0, KDB_REPEAT_NONE);

kdb_register_repeat("ss", kdb_ss, "",
"Single Step", 1, KDB_REPEAT_NO_ARGS);
kdb_register_flags("bph", kdb_bp, "[<vaddr>]",
"[datar [length]|dataw [length]] Set hw brk", 0,
KDB_ENABLE_FLOW_CTRL | KDB_REPEAT_NO_ARGS);
kdb_register_flags("bc", kdb_bc, "<bpnum>",
"Clear Breakpoint", 0,
KDB_ENABLE_FLOW_CTRL);
kdb_register_flags("be", kdb_bc, "<bpnum>",
"Enable Breakpoint", 0,
KDB_ENABLE_FLOW_CTRL);
kdb_register_flags("bd", kdb_bc, "<bpnum>",
"Disable Breakpoint", 0,
KDB_ENABLE_FLOW_CTRL);

kdb_register_flags("ss", kdb_ss, "",
"Single Step", 1,
KDB_ENABLE_FLOW_CTRL | KDB_REPEAT_NO_ARGS);
/*
* Architecture dependent initialization.
*/
Expand Down
4 changes: 4 additions & 0 deletions kernel/debug/kdb/kdb_debugger.c
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,10 @@ int kdb_stub(struct kgdb_state *ks)
ks->pass_exception = 1;
KDB_FLAG_SET(CATASTROPHIC);
}
/* set CATASTROPHIC if the system contains unresponsive processors */
for_each_online_cpu(i)
if (!kgdb_info[i].enter_kgdb)
KDB_FLAG_SET(CATASTROPHIC);
if (KDB_STATE(SSBPT) && reason == KDB_REASON_SSTEP) {
KDB_STATE_CLEAR(SSBPT);
KDB_STATE_CLEAR(DOING_SS);
Expand Down
Loading

0 comments on commit aa92913

Please sign in to comment.