Skip to content

Commit a491230

Browse files
author
Daniel Thompson
committed
serial: kgdboc: Allow earlycon initialization to be deferred
Currently there is no guarantee that an earlycon will be initialized before kgdboc tries to adopt it. Almost the opposite: on systems with ACPI then if earlycon has no arguments then it is guaranteed that earlycon will not be initialized. This patch mitigates the problem by giving kgdboc_earlycon a second chance during console_init(). This isn't quite as good as stopping during early parameter parsing but it is still early in the kernel boot. Signed-off-by: Daniel Thompson <[email protected]> Link: https://lore.kernel.org/r/[email protected] Reviewed-by: Douglas Anderson <[email protected]>
1 parent f71fc3b commit a491230

File tree

1 file changed

+38
-1
lines changed

1 file changed

+38
-1
lines changed

drivers/tty/serial/kgdboc.c

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -514,6 +514,10 @@ static struct kgdb_io kgdboc_earlycon_io_ops = {
514514
.is_console = true,
515515
};
516516

517+
#define MAX_CONSOLE_NAME_LEN (sizeof((struct console *) 0)->name)
518+
static char kgdboc_earlycon_param[MAX_CONSOLE_NAME_LEN] __initdata;
519+
static bool kgdboc_earlycon_late_enable __initdata;
520+
517521
static int __init kgdboc_earlycon_init(char *opt)
518522
{
519523
struct console *con;
@@ -533,7 +537,23 @@ static int __init kgdboc_earlycon_init(char *opt)
533537
}
534538

535539
if (!con) {
536-
pr_info("Couldn't find kgdb earlycon\n");
540+
/*
541+
* Both earlycon and kgdboc_earlycon are initialized during * early parameter parsing. We cannot guarantee earlycon gets
542+
* in first and, in any case, on ACPI systems earlycon may
543+
* defer its own initialization (usually to somewhere within
544+
* setup_arch() ). To cope with either of these situations
545+
* we can defer our own initialization to a little later in
546+
* the boot.
547+
*/
548+
if (!kgdboc_earlycon_late_enable) {
549+
pr_info("No suitable earlycon yet, will try later\n");
550+
if (opt)
551+
strscpy(kgdboc_earlycon_param, opt,
552+
sizeof(kgdboc_earlycon_param));
553+
kgdboc_earlycon_late_enable = true;
554+
} else {
555+
pr_info("Couldn't find kgdb earlycon\n");
556+
}
537557
goto unlock;
538558
}
539559

@@ -556,6 +576,23 @@ static int __init kgdboc_earlycon_init(char *opt)
556576
}
557577

558578
early_param("kgdboc_earlycon", kgdboc_earlycon_init);
579+
580+
/*
581+
* This is only intended for the late adoption of an early console.
582+
*
583+
* It is not a reliable way to adopt regular consoles because we can not
584+
* control what order console initcalls are made and, in any case, many
585+
* regular consoles are registered much later in the boot process than
586+
* the console initcalls!
587+
*/
588+
static int __init kgdboc_earlycon_late_init(void)
589+
{
590+
if (kgdboc_earlycon_late_enable)
591+
kgdboc_earlycon_init(kgdboc_earlycon_param);
592+
return 0;
593+
}
594+
console_initcall(kgdboc_earlycon_late_init);
595+
559596
#endif /* IS_BUILTIN(CONFIG_KGDB_SERIAL_CONSOLE) */
560597

561598
module_init(init_kgdboc);

0 commit comments

Comments
 (0)