Commit f1e45535 authored by Linus Torvalds's avatar Linus Torvalds

Merge tag 'kgdb-5.8-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/danielt/linux

Pull kgdb updates from Daniel Thompson:
 "By far the biggest change in this cycle are the changes that allow
  much earlier debug of systems that are hooked up via UART by taking
  advantage of the earlycon framework to implement the kgdb I/O hooks
  before handing over to the regular polling I/O drivers once they are
  available. When discussing Doug's work we also found and fixed an
  broken raw_smp_processor_id() sequence in in_dbg_master().

  Also included are a collection of much smaller fixes and tweaks: a
  couple of tweaks to ged rid of doc gen or coccicheck warnings, future
  proof some internal calculations that made implicit power-of-2
  assumptions and eliminate some rather weird handling of magic
  environment variables in kdb"

* tag 'kgdb-5.8-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/danielt/linux:
  kdb: Remove the misfeature 'KDBFLAGS'
  kdb: Cleanup math with KDB_CMD_HISTORY_COUNT
  serial: amba-pl011: Support kgdboc_earlycon
  serial: 8250_early: Support kgdboc_earlycon
  serial: qcom_geni_serial: Support kgdboc_earlycon
  serial: kgdboc: Allow earlycon initialization to be deferred
  Documentation: kgdboc: Document new kgdboc_earlycon parameter
  kgdb: Don't call the deinit under spinlock
  kgdboc: Disable all the early code when kgdboc is a module
  kgdboc: Add kgdboc_earlycon to support early kgdb using boot consoles
  kgdboc: Remove useless #ifdef CONFIG_KGDB_SERIAL_CONSOLE in kgdboc
  kgdb: Prevent infinite recursive entries to the debugger
  kgdb: Delay "kgdbwait" to dbg_late_init() by default
  kgdboc: Use a platform device to handle tty drivers showing up late
  Revert "kgdboc: disable the console lock when in kgdb"
  kgdb: Disable WARN_CONSOLE_UNLOCKED for all kgdb
  kgdb: Return true in kgdb_nmi_poll_knock()
  kgdb: Drop malformed kernel doc comment
  kgdb: Fix spurious true from in_dbg_master()
parents 38696e33 c893de12
......@@ -1190,6 +1190,11 @@
This is designed to be used in conjunction with
the boot argument: earlyprintk=vga
This parameter works in place of the kgdboc parameter
but can only be used if the backing tty is available
very early in the boot process. For early debugging
via a serial port see kgdboc_earlycon instead.
edd= [EDD]
Format: {"off" | "on" | "skip[mbr]"}
......@@ -2112,6 +2117,21 @@
kms, kbd format: kms,kbd
kms, kbd and serial format: kms,kbd,<ser_dev>[,baud]
kgdboc_earlycon= [KGDB,HW]
If the boot console provides the ability to read
characters and can work in polling mode, you can use
this parameter to tell kgdb to use it as a backend
until the normal console is registered. Intended to
be used together with the kgdboc parameter which
specifies the normal console to transition to.
The name of the early console should be specified
as the value of this parameter. Note that the name of
the early console might be different than the tty
name passed to kgdboc. It's OK to leave the value
blank and the first boot console that implements
read() will be picked.
kgdbwait [KGDB] Stop kernel execution and enter the
kernel debugger at the earliest opportunity.
......
......@@ -274,6 +274,30 @@ don't like this are to hack gdb to send the :kbd:`SysRq-G` for you as well as
on the initial connect, or to use a debugger proxy that allows an
unmodified gdb to do the debugging.
Kernel parameter: ``kgdboc_earlycon``
-------------------------------------
If you specify the kernel parameter ``kgdboc_earlycon`` and your serial
driver registers a boot console that supports polling (doesn't need
interrupts and implements a nonblocking read() function) kgdb will attempt
to work using the boot console until it can transition to the regular
tty driver specified by the ``kgdboc`` parameter.
Normally there is only one boot console (especially that implements the
read() function) so just adding ``kgdboc_earlycon`` on its own is
sufficient to make this work. If you have more than one boot console you
can add the boot console's name to differentiate. Note that names that
are registered through the boot console layer and the tty layer are not
the same for the same port.
For instance, on one board to be explicit you might do::
kgdboc_earlycon=qcom_geni kgdboc=ttyMSM0
If the only boot console on the device was "qcom_geni", you could simplify::
kgdboc_earlycon kgdboc=ttyMSM0
Kernel parameter: ``kgdbwait``
------------------------------
......
......@@ -60,6 +60,7 @@ config X86
select ARCH_HAS_ACPI_TABLE_UPGRADE if ACPI
select ARCH_HAS_DEBUG_VIRTUAL
select ARCH_HAS_DEVMEM_IS_ALLOWED
select ARCH_HAS_EARLY_DEBUG if KGDB
select ARCH_HAS_ELF_RANDOMIZE
select ARCH_HAS_FAST_MULTIPLIER
select ARCH_HAS_FILTER_PGPROT
......
......@@ -109,6 +109,28 @@ static void early_serial8250_write(struct console *console,
uart_console_write(port, s, count, serial_putc);
}
#ifdef CONFIG_CONSOLE_POLL
static int early_serial8250_read(struct console *console,
char *s, unsigned int count)
{
struct earlycon_device *device = console->data;
struct uart_port *port = &device->port;
unsigned int status;
int num_read = 0;
while (num_read < count) {
status = serial8250_early_in(port, UART_LSR);
if (!(status & UART_LSR_DR))
break;
s[num_read++] = serial8250_early_in(port, UART_RX);
}
return num_read;
}
#else
#define early_serial8250_read NULL
#endif
static void __init init_port(struct earlycon_device *device)
{
struct uart_port *port = &device->port;
......@@ -149,6 +171,7 @@ int __init early_serial8250_setup(struct earlycon_device *device,
init_port(device);
device->con->write = early_serial8250_write;
device->con->read = early_serial8250_read;
return 0;
}
EARLYCON_DECLARE(uart8250, early_serial8250_setup);
......
......@@ -2435,6 +2435,37 @@ static void pl011_early_write(struct console *con, const char *s, unsigned n)
uart_console_write(&dev->port, s, n, pl011_putc);
}
#ifdef CONFIG_CONSOLE_POLL
static int pl011_getc(struct uart_port *port)
{
if (readl(port->membase + UART01x_FR) & UART01x_FR_RXFE)
return NO_POLL_CHAR;
if (port->iotype == UPIO_MEM32)
return readl(port->membase + UART01x_DR);
else
return readb(port->membase + UART01x_DR);
}
static int pl011_early_read(struct console *con, char *s, unsigned int n)
{
struct earlycon_device *dev = con->data;
int ch, num_read = 0;
while (num_read < n) {
ch = pl011_getc(&dev->port);
if (ch == NO_POLL_CHAR)
break;
s[num_read++] = ch;
}
return num_read;
}
#else
#define pl011_early_read NULL
#endif
/*
* On non-ACPI systems, earlycon is enabled by specifying
* "earlycon=pl011,<address>" on the kernel command line.
......@@ -2454,6 +2485,7 @@ static int __init pl011_early_console_setup(struct earlycon_device *device,
return -ENODEV;
device->con->write = pl011_early_write;
device->con->read = pl011_early_read;
return 0;
}
......
......@@ -20,6 +20,8 @@
#include <linux/vt_kern.h>
#include <linux/input.h>
#include <linux/module.h>
#include <linux/platform_device.h>
#include <linux/serial_core.h>
#define MAX_CONFIG_LEN 40
......@@ -27,6 +29,7 @@ static struct kgdb_io kgdboc_io_ops;
/* -1 = init not run yet, 0 = unconfigured, 1 = configured. */
static int configured = -1;
static DEFINE_MUTEX(config_mutex);
static char config[MAX_CONFIG_LEN];
static struct kparam_string kps = {
......@@ -38,6 +41,14 @@ static int kgdboc_use_kms; /* 1 if we use kernel mode switching */
static struct tty_driver *kgdb_tty_driver;
static int kgdb_tty_line;
static struct platform_device *kgdboc_pdev;
#if IS_BUILTIN(CONFIG_KGDB_SERIAL_CONSOLE)
static struct kgdb_io kgdboc_earlycon_io_ops;
static struct console *earlycon;
static int (*earlycon_orig_exit)(struct console *con);
#endif /* IS_BUILTIN(CONFIG_KGDB_SERIAL_CONSOLE) */
#ifdef CONFIG_KDB_KEYBOARD
static int kgdboc_reset_connect(struct input_handler *handler,
struct input_dev *dev,
......@@ -131,12 +142,26 @@ static void kgdboc_unregister_kbd(void)
#define kgdboc_restore_input()
#endif /* ! CONFIG_KDB_KEYBOARD */
#if IS_BUILTIN(CONFIG_KGDB_SERIAL_CONSOLE)
static void cleanup_earlycon(void)
{
if (earlycon)
kgdb_unregister_io_module(&kgdboc_earlycon_io_ops);
}
#else /* !IS_BUILTIN(CONFIG_KGDB_SERIAL_CONSOLE) */
static inline void cleanup_earlycon(void) { }
#endif /* !IS_BUILTIN(CONFIG_KGDB_SERIAL_CONSOLE) */
static void cleanup_kgdboc(void)
{
cleanup_earlycon();
if (configured != 1)
return;
if (kgdb_unregister_nmi_console())
return;
kgdboc_unregister_kbd();
if (configured == 1)
kgdb_unregister_io_module(&kgdboc_io_ops);
}
......@@ -198,20 +223,79 @@ static int configure_kgdboc(void)
kgdb_unregister_io_module(&kgdboc_io_ops);
noconfig:
kgdboc_unregister_kbd();
config[0] = 0;
configured = 0;
cleanup_kgdboc();
return err;
}
static int kgdboc_probe(struct platform_device *pdev)
{
int ret = 0;
mutex_lock(&config_mutex);
if (configured != 1) {
ret = configure_kgdboc();
/* Convert "no device" to "defer" so we'll keep trying */
if (ret == -ENODEV)
ret = -EPROBE_DEFER;
}
mutex_unlock(&config_mutex);
return ret;
}
static struct platform_driver kgdboc_platform_driver = {
.probe = kgdboc_probe,
.driver = {
.name = "kgdboc",
.suppress_bind_attrs = true,
},
};
static int __init init_kgdboc(void)
{
/* Already configured? */
if (configured == 1)
int ret;
/*
* kgdboc is a little bit of an odd "platform_driver". It can be
* up and running long before the platform_driver object is
* created and thus doesn't actually store anything in it. There's
* only one instance of kgdb so anything is stored as global state.
* The platform_driver is only created so that we can leverage the
* kernel's mechanisms (like -EPROBE_DEFER) to call us when our
* underlying tty is ready. Here we init our platform driver and
* then create the single kgdboc instance.
*/
ret = platform_driver_register(&kgdboc_platform_driver);
if (ret)
return ret;
kgdboc_pdev = platform_device_alloc("kgdboc", PLATFORM_DEVID_NONE);
if (!kgdboc_pdev) {
ret = -ENOMEM;
goto err_did_register;
}
ret = platform_device_add(kgdboc_pdev);
if (!ret)
return 0;
return configure_kgdboc();
platform_device_put(kgdboc_pdev);
err_did_register:
platform_driver_unregister(&kgdboc_platform_driver);
return ret;
}
static void exit_kgdboc(void)
{
mutex_lock(&config_mutex);
cleanup_kgdboc();
mutex_unlock(&config_mutex);
platform_device_unregister(kgdboc_pdev);
platform_driver_unregister(&kgdboc_platform_driver);
}
static int kgdboc_get_char(void)
......@@ -234,24 +318,20 @@ static int param_set_kgdboc_var(const char *kmessage,
const struct kernel_param *kp)
{
size_t len = strlen(kmessage);
int ret = 0;
if (len >= MAX_CONFIG_LEN) {
pr_err("config string too long\n");
return -ENOSPC;
}
/* Only copy in the string if the init function has not run yet */
if (configured < 0) {
strcpy(config, kmessage);
return 0;
}
if (kgdb_connected) {
pr_err("Cannot reconfigure while KGDB is connected.\n");
return -EBUSY;
}
mutex_lock(&config_mutex);
strcpy(config, kmessage);
/* Chop out \n char as a result of echo */
if (len && config[len - 1] == '\n')
......@@ -260,8 +340,30 @@ static int param_set_kgdboc_var(const char *kmessage,
if (configured == 1)
cleanup_kgdboc();
/* Go and configure with the new params. */
return configure_kgdboc();
/*
* Configure with the new params as long as init already ran.
* Note that we can get called before init if someone loads us
* with "modprobe kgdboc kgdboc=..." or if they happen to use the
* the odd syntax of "kgdboc.kgdboc=..." on the kernel command.
*/
if (configured >= 0)
ret = configure_kgdboc();
/*
* If we couldn't configure then clear out the config. Note that
* specifying an invalid config on the kernel command line vs.
* through sysfs have slightly different behaviors. If we fail
* to configure what was specified on the kernel command line
* we'll leave it in the 'config' and return -EPROBE_DEFER from
* our probe. When specified through sysfs userspace is
* responsible for loading the tty driver before setting up.
*/
if (ret)
config[0] = '\0';
mutex_unlock(&config_mutex);
return ret;
}
static int dbg_restore_graphics;
......@@ -275,14 +377,10 @@ static void kgdboc_pre_exp_handler(void)
/* Increment the module count when the debugger is active */
if (!kgdb_connected)
try_module_get(THIS_MODULE);
atomic_inc(&ignore_console_lock_warning);
}
static void kgdboc_post_exp_handler(void)
{
atomic_dec(&ignore_console_lock_warning);
/* decrement the module count when the debugger detaches */
if (!kgdb_connected)
module_put(THIS_MODULE);
......@@ -301,7 +399,7 @@ static struct kgdb_io kgdboc_io_ops = {
.post_exception = kgdboc_post_exp_handler,
};
#ifdef CONFIG_KGDB_SERIAL_CONSOLE
#if IS_BUILTIN(CONFIG_KGDB_SERIAL_CONSOLE)
static int kgdboc_option_setup(char *opt)
{
if (!opt) {
......@@ -324,23 +422,181 @@ __setup("kgdboc=", kgdboc_option_setup);
/* This is only available if kgdboc is a built in for early debugging */
static int __init kgdboc_early_init(char *opt)
{
/* save the first character of the config string because the
* init routine can destroy it.
*/
char save_ch;
kgdboc_option_setup(opt);
save_ch = config[0];
init_kgdboc();
config[0] = save_ch;
configure_kgdboc();
return 0;
}
early_param("ekgdboc", kgdboc_early_init);
#endif /* CONFIG_KGDB_SERIAL_CONSOLE */
static int kgdboc_earlycon_get_char(void)
{
char c;
if (!earlycon->read(earlycon, &c, 1))
return NO_POLL_CHAR;
return c;
}
static void kgdboc_earlycon_put_char(u8 chr)
{
earlycon->write(earlycon, &chr, 1);
}
static void kgdboc_earlycon_pre_exp_handler(void)
{
struct console *con;
static bool already_warned;
if (already_warned)
return;
/*
* When the first normal console comes up the kernel will take all
* the boot consoles out of the list. Really, we should stop using
* the boot console when it does that but until a TTY is registered
* we have no other choice so we keep using it. Since not all
* serial drivers might be OK with this, print a warning once per
* boot if we detect this case.
*/
for_each_console(con)
if (con == earlycon)
return;
already_warned = true;
pr_warn("kgdboc_earlycon is still using bootconsole\n");
}
static int kgdboc_earlycon_deferred_exit(struct console *con)
{
/*
* If we get here it means the boot console is going away but we
* don't yet have a suitable replacement. Don't pass through to
* the original exit routine. We'll call it later in our deinit()
* function. For now, restore the original exit() function pointer
* as a sentinal that we've hit this point.
*/
con->exit = earlycon_orig_exit;
return 0;
}
static void kgdboc_earlycon_deinit(void)
{
if (!earlycon)
return;
if (earlycon->exit == kgdboc_earlycon_deferred_exit)
/*
* kgdboc_earlycon is exiting but original boot console exit
* was never called (AKA kgdboc_earlycon_deferred_exit()
* didn't ever run). Undo our trap.
*/
earlycon->exit = earlycon_orig_exit;
else if (earlycon->exit)
/*
* We skipped calling the exit() routine so we could try to
* keep using the boot console even after it went away. We're
* finally done so call the function now.
*/
earlycon->exit(earlycon);
earlycon = NULL;
}
static struct kgdb_io kgdboc_earlycon_io_ops = {
.name = "kgdboc_earlycon",
.read_char = kgdboc_earlycon_get_char,
.write_char = kgdboc_earlycon_put_char,
.pre_exception = kgdboc_earlycon_pre_exp_handler,
.deinit = kgdboc_earlycon_deinit,
.is_console = true,
};
#define MAX_CONSOLE_NAME_LEN (sizeof((struct console *) 0)->name)
static char kgdboc_earlycon_param[MAX_CONSOLE_NAME_LEN] __initdata;
static bool kgdboc_earlycon_late_enable __initdata;
static int __init kgdboc_earlycon_init(char *opt)
{
struct console *con;
kdb_init(KDB_INIT_EARLY);
/*
* Look for a matching console, or if the name was left blank just
* pick the first one we find.
*/
console_lock();
for_each_console(con) {
if (con->write && con->read &&
(con->flags & (CON_BOOT | CON_ENABLED)) &&
(!opt || !opt[0] || strcmp(con->name, opt) == 0))
break;
}
if (!con) {
/*
* Both earlycon and kgdboc_earlycon are initialized during * early parameter parsing. We cannot guarantee earlycon gets
* in first and, in any case, on ACPI systems earlycon may
* defer its own initialization (usually to somewhere within
* setup_arch() ). To cope with either of these situations
* we can defer our own initialization to a little later in
* the boot.
*/
if (!kgdboc_earlycon_late_enable) {
pr_info("No suitable earlycon yet, will try later\n");
if (opt)
strscpy(kgdboc_earlycon_param, opt,
sizeof(kgdboc_earlycon_param));
kgdboc_earlycon_late_enable = true;
} else {
pr_info("Couldn't find kgdb earlycon\n");
}
goto unlock;
}
earlycon = con;
pr_info("Going to register kgdb with earlycon '%s'\n", con->name);
if (kgdb_register_io_module(&kgdboc_earlycon_io_ops) != 0) {
earlycon = NULL;
pr_info("Failed to register kgdb with earlycon\n");
} else {
/* Trap exit so we can keep earlycon longer if needed. */
earlycon_orig_exit = con->exit;
con->exit = kgdboc_earlycon_deferred_exit;
}
unlock:
console_unlock();
/* Non-zero means malformed option so we always return zero */
return 0;
}
early_param("kgdboc_earlycon", kgdboc_earlycon_init);
/*
* This is only intended for the late adoption of an early console.
*
* It is not a reliable way to adopt regular consoles because we can not
* control what order console initcalls are made and, in any case, many
* regular consoles are registered much later in the boot process than
* the console initcalls!
*/
static int __init kgdboc_earlycon_late_init(void)
{
if (kgdboc_earlycon_late_enable)
kgdboc_earlycon_init(kgdboc_earlycon_param);
return 0;
}
console_initcall(kgdboc_earlycon_late_init);
#endif /* IS_BUILTIN(CONFIG_KGDB_SERIAL_CONSOLE) */
module_init(init_kgdboc);
module_exit(cleanup_kgdboc);
module_exit(exit_kgdboc);
module_param_call(kgdboc, param_set_kgdboc_var, param_get_string, &kps, 0644);
MODULE_PARM_DESC(kgdboc, "<serial_device>[,baud]");
MODULE_DESCRIPTION("KGDB Console TTY Driver");
......
......@@ -1090,6 +1090,36 @@ static void qcom_geni_serial_earlycon_write(struct console *con,
__qcom_geni_serial_console_write(&dev->port, s, n);
}
#ifdef CONFIG_CONSOLE_POLL
static int qcom_geni_serial_earlycon_read(struct console *con,
char *s, unsigned int n)
{
struct earlycon_device *dev = con->data;
struct uart_port *uport = &dev->port;
int num_read = 0;
int ch;
while (num_read < n) {
ch = qcom_geni_serial_get_char(uport);
if (ch == NO_POLL_CHAR)
break;
s[num_read++] = ch;
}
return num_read;
}
static void __init qcom_geni_serial_enable_early_read(struct geni_se *se,
struct console *con)
{
geni_se_setup_s_cmd(se, UART_START_READ, 0);
con->read = qcom_geni_serial_earlycon_read;
}
#else
static inline void qcom_geni_serial_enable_early_read(struct geni_se *se,
struct console *con) { }
#endif
static int __init qcom_geni_serial_earlycon_setup(struct earlycon_device *dev,
const char *opt)
{
......@@ -1136,6 +1166,8 @@ static int __init qcom_geni_serial_earlycon_setup(struct earlycon_device *dev,
dev->con->write = qcom_geni_serial_earlycon_write;
dev->con->setup = NULL;
qcom_geni_serial_enable_early_read(&se, dev->con);
return 0;
}
OF_EARLYCON_DECLARE(qcom_geni, "qcom,geni-debug-uart",
......
......@@ -125,7 +125,7 @@ extern const char *kdb_diemsg;
#define KDB_FLAG_NO_I8042 (1 << 7) /* No i8042 chip is available, do
* not use keyboard */
extern int kdb_flags; /* Global flags, see kdb_state for per cpu state */
extern unsigned int kdb_flags; /* Global flags, see kdb_state for per cpu state */
extern void kdb_save_flags(void);
extern void kdb_restore_flags(void);
......
......@@ -269,6 +269,9 @@ struct kgdb_arch {
* @write_char: Pointer to a function that will write one char.
* @flush: Pointer to a function that will flush any pending writes.
* @init: Pointer to a function that will initialize the device.
* @deinit: Pointer to a function that will deinit the device. Implies that
* this I/O driver is temporary and expects to be replaced. Called when
* an I/O driver is replaced or explicitly unregistered.
* @pre_exception: Pointer to a function that will do any prep work for
* the I/O driver.
* @post_exception: Pointer to a function that will do any cleanup work
......@@ -282,6 +285,7 @@ struct kgdb_io {
void (*write_char) (u8);
void (*flush) (void);
int (*init) (void);
void (*deinit) (void);
void (*pre_exception) (void);
void (*post_exception) (void);
int is_console;
......@@ -298,7 +302,7 @@ extern bool kgdb_nmi_poll_knock(void);
#else
static inline int kgdb_register_nmi_console(void) { return 0; }
static inline int kgdb_unregister_nmi_console(void) { return 0; }
static inline bool kgdb_nmi_poll_knock(void) { return 1; }
static inline bool kgdb_nmi_poll_knock(void) { return true; }
#endif
extern int kgdb_register_io_module(struct kgdb_io *local_kgdb_io_ops);
......@@ -323,7 +327,7 @@ extern void gdbstub_exit(int status);
extern int kgdb_single_step;
extern atomic_t kgdb_active;
#define in_dbg_master() \
(raw_smp_processor_id() == atomic_read(&kgdb_active))
(irqs_disabled() && (smp_processor_id() == atomic_read(&kgdb_active)))
extern bool dbg_is_early;
extern void __init dbg_late_init(void);
extern void kgdb_panic(const char *msg);
......
......@@ -67,9 +67,7 @@ static int kgdb_break_asap;
struct debuggerinfo_struct kgdb_info[NR_CPUS];
/**
* kgdb_connected - Is a host GDB connected to us?
*/
/* kgdb_connected - Is a host GDB connected to us? */
int kgdb_connected;
EXPORT_SYMBOL_GPL(kgdb_connected);
......@@ -532,6 +530,7 @@ static int kgdb_reenter_check(struct kgdb_state *ks)
if (exception_level > 1) {
dump_stack();
kgdb_io_module_registered = false;
panic("Recursive entry to debugger");
}
......@@ -668,6 +667,8 @@ static int kgdb_cpu_enter(struct kgdb_state *ks, struct pt_regs *regs,
if (kgdb_skipexception(ks->ex_vector, ks->linux_regs))
goto kgdb_restore;
atomic_inc(&ignore_console_lock_warning);
/* Call the I/O driver's pre_exception routine */
if (dbg_io_ops->pre_exception)
dbg_io_ops->pre_exception();
......@@ -740,6 +741,8 @@ static int kgdb_cpu_enter(struct kgdb_state *ks, struct pt_regs *regs,
if (dbg_io_ops->post_exception)
dbg_io_ops->post_exception();
atomic_dec(&ignore_console_lock_warning);
if (!kgdb_single_step) {
raw_spin_unlock(&dbg_slave_lock);
/* Wait till all the CPUs have quit from the debugger. */
......@@ -946,6 +949,14 @@ void kgdb_panic(const char *msg)
kgdb_breakpoint();
}
static void kgdb_initial_breakpoint(void)
{
kgdb_break_asap = 0;
pr_crit("Waiting for connection from remote gdb...\n");
kgdb_breakpoint();
}
void __weak kgdb_arch_late(void)
{
}
......@@ -956,6 +967,9 @@ void __init dbg_late_init(void)
if (kgdb_io_module_registered)
kgdb_arch_late();
kdb_init(KDB_INIT_FULL);
if (kgdb_io_module_registered && kgdb_break_asap)
kgdb_initial_breakpoint();
}
static int
......@@ -1051,14 +1065,6 @@ void kgdb_schedule_breakpoint(void)
}
EXPORT_SYMBOL_GPL(kgdb_schedule_breakpoint);
static void kgdb_initial_breakpoint(void)
{
kgdb_break_asap = 0;
pr_crit("Waiting for connection from remote gdb...\n");
kgdb_breakpoint();
}
/**
* kgdb_register_io_module - register KGDB IO module
* @new_dbg_io_ops: the io ops vector
......@@ -1067,16 +1073,23 @@ static void kgdb_initial_breakpoint(void)
*/
int kgdb_register_io_module(struct kgdb_io *new_dbg_io_ops)
{
struct kgdb_io *old_dbg_io_ops;
int err;
spin_lock(&kgdb_registration_lock);
if (dbg_io_ops) {
old_dbg_io_ops = dbg_io_ops;
if (old_dbg_io_ops) {
if (!old_dbg_io_ops->deinit) {
spin_unlock(&kgdb_registration_lock);
pr_err("Another I/O driver is already registered with KGDB\n");
pr_err("KGDB I/O driver %s can't replace %s.\n",
new_dbg_io_ops->name, old_dbg_io_ops->name);
return -EBUSY;
}
pr_info("Replacing I/O driver %s with %s\n",
old_dbg_io_ops->name, new_dbg_io_ops->name);
}
if (new_dbg_io_ops->init) {
err = new_dbg_io_ops->init();
......@@ -1090,12 +1103,18 @@ int kgdb_register_io_module(struct kgdb_io *new_dbg_io_ops)
spin_unlock(&kgdb_registration_lock);
if (old_dbg_io_ops) {
old_dbg_io_ops->deinit();
return 0;
}
pr_info("Registered I/O driver %s\n", new_dbg_io_ops->name);
/* Arm KGDB now. */
kgdb_register_callbacks();
if (kgdb_break_asap)
if (kgdb_break_asap &&
(!dbg_is_early || IS_ENABLED(CONFIG_ARCH_HAS_EARLY_DEBUG)))
kgdb_initial_breakpoint();
return 0;
......@@ -1125,6 +1144,9 @@ void kgdb_unregister_io_module(struct kgdb_io *old_dbg_io_ops)
spin_unlock(&kgdb_registration_lock);
if (old_dbg_io_ops->deinit)
old_dbg_io_ops->deinit();
pr_info("Unregistered I/O driver %s, debugger disabled\n",
old_dbg_io_ops->name);
}
......@@ -1165,7 +1187,8 @@ static int __init opt_kgdb_wait(char *str)
kgdb_break_asap = 1;
kdb_init(KDB_INIT_EARLY);
if (kgdb_io_module_registered)
if (kgdb_io_module_registered &&
IS_ENABLED(CONFIG_ARCH_HAS_EARLY_DEBUG))
kgdb_initial_breakpoint();
return 0;
......
......@@ -62,7 +62,7 @@ int kdb_grep_trailing;
/*
* Kernel debugger state flags
*/
int kdb_flags;
unsigned int kdb_flags;
/*
* kdb_lock protects updates to kdb_initial_cpu. Used to
......@@ -418,8 +418,7 @@ int kdb_set(int argc, const char **argv)
argv[2]);
return 0;
}
kdb_flags = (kdb_flags &
~(KDB_DEBUG_FLAG_MASK << KDB_DEBUG_FLAG_SHIFT))
kdb_flags = (kdb_flags & ~KDB_DEBUG(MASK))
| (debugflags << KDB_DEBUG_FLAG_SHIFT);
return 0;
......@@ -1108,7 +1107,8 @@ static int handle_ctrl_cmd(char *cmd)
switch (*cmd) {
case CTRL_P:
if (cmdptr != cmd_tail)
cmdptr = (cmdptr-1) % KDB_CMD_HISTORY_COUNT;
cmdptr = (cmdptr + KDB_CMD_HISTORY_COUNT - 1) %
KDB_CMD_HISTORY_COUNT;
strscpy(cmd_cur, cmd_hist[cmdptr], CMD_BUFLEN);
return 1;
case CTRL_N:
......@@ -2081,7 +2081,8 @@ static int kdb_env(int argc, const char **argv)
}
if (KDB_DEBUG(MASK))
kdb_printf("KDBFLAGS=0x%x\n", kdb_flags);
kdb_printf("KDBDEBUG=0x%x\n",
(kdb_flags & KDB_DEBUG(MASK)) >> KDB_DEBUG_FLAG_SHIFT);
return 0;
}
......
......@@ -124,4 +124,22 @@ config KDB_CONTINUE_CATASTROPHIC
CONFIG_KDB_CONTINUE_CATASTROPHIC == 2. KDB forces a reboot.
If you are not sure, say 0.
config ARCH_HAS_EARLY_DEBUG
bool
default n
help
If an architecture can definitely handle entering the debugger
when early_param's are parsed then it select this config.
Otherwise, if "kgdbwait" is passed on the kernel command line it
won't actually be processed until dbg_late_init() just after the
call to kgdb_arch_late() is made.
NOTE: Even if this isn't selected by an architecture we will
still try to register kgdb to handle breakpoints and crashes
when early_param's are parsed, we just won't act on the
"kgdbwait" parameter until dbg_late_init(). If you get a
crash and try to drop into kgdb somewhere between these two
places you might or might not end up being able to use kgdb
depending on exactly how far along the architecture has initted.
endif # KGDB
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