diff options
3 files changed, 204 insertions, 0 deletions
diff --git a/queue-6.12/serial-sh-sci-clean-sci_ports-after-at-earlycon-exit.patch b/queue-6.12/serial-sh-sci-clean-sci_ports-after-at-earlycon-exit.patch new file mode 100644 index 0000000000..2bfc628e61 --- /dev/null +++ b/queue-6.12/serial-sh-sci-clean-sci_ports-after-at-earlycon-exit.patch @@ -0,0 +1,118 @@ +From 5f1017069933489add0c08659673443c9905659e Mon Sep 17 00:00:00 2001 +From: Claudiu Beznea <claudiu.beznea.uj@bp.renesas.com> +Date: Thu, 16 Jan 2025 20:22:48 +0200 +Subject: serial: sh-sci: Clean sci_ports[0] after at earlycon exit + +From: Claudiu Beznea <claudiu.beznea.uj@bp.renesas.com> + +commit 5f1017069933489add0c08659673443c9905659e upstream. + +The early_console_setup() function initializes sci_ports[0].port with an +object of type struct uart_port obtained from the struct earlycon_device +passed as an argument to early_console_setup(). + +Later, during serial port probing, the serial port used as earlycon +(e.g., port A) might be remapped to a different position in the sci_ports[] +array, and a different serial port (e.g., port B) might be assigned to slot +0. For example: + +sci_ports[0] = port B +sci_ports[X] = port A + +In this scenario, the new port mapped at index zero (port B) retains the +data associated with the earlycon configuration. Consequently, after the +Linux boot process, any access to the serial port now mapped to +sci_ports[0] (port B) will block the original earlycon port (port A). + +To address this, introduce an early_console_exit() function to clean up +sci_ports[0] when earlycon is exited. + +To prevent the cleanup of sci_ports[0] while the serial device is still +being used by earlycon, introduce the struct sci_port::probing flag and +account for it in early_console_exit(). + +Fixes: 0b0cced19ab1 ("serial: sh-sci: Add CONFIG_SERIAL_EARLYCON support") +Cc: stable@vger.kernel.org +Signed-off-by: Claudiu Beznea <claudiu.beznea.uj@bp.renesas.com> +Link: https://lore.kernel.org/r/20250116182249.3828577-5-claudiu.beznea.uj@bp.renesas.com +Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> +--- + drivers/tty/serial/sh-sci.c | 32 ++++++++++++++++++++++++++++++-- + 1 file changed, 30 insertions(+), 2 deletions(-) + +--- a/drivers/tty/serial/sh-sci.c ++++ b/drivers/tty/serial/sh-sci.c +@@ -183,6 +183,7 @@ static struct sci_port sci_ports[SCI_NPO + static unsigned long sci_ports_in_use; + static struct uart_driver sci_uart_driver; + static bool sci_uart_earlycon; ++static bool sci_uart_earlycon_dev_probing; + + static inline struct sci_port * + to_sci_port(struct uart_port *uart) +@@ -3404,7 +3405,8 @@ static struct plat_sci_port *sci_parse_d + static int sci_probe_single(struct platform_device *dev, + unsigned int index, + struct plat_sci_port *p, +- struct sci_port *sciport) ++ struct sci_port *sciport, ++ struct resource *sci_res) + { + int ret; + +@@ -3451,6 +3453,14 @@ static int sci_probe_single(struct platf + sciport->port.flags |= UPF_HARD_FLOW; + } + ++ if (sci_uart_earlycon && sci_ports[0].port.mapbase == sci_res->start) { ++ /* ++ * Skip cleanup the sci_port[0] in early_console_exit(), this ++ * port is the same as the earlycon one. ++ */ ++ sci_uart_earlycon_dev_probing = true; ++ } ++ + return uart_add_one_port(&sci_uart_driver, &sciport->port); + } + +@@ -3509,7 +3519,7 @@ static int sci_probe(struct platform_dev + + platform_set_drvdata(dev, sp); + +- ret = sci_probe_single(dev, dev_id, p, sp); ++ ret = sci_probe_single(dev, dev_id, p, sp, res); + if (ret) + return ret; + +@@ -3666,6 +3676,22 @@ sh_early_platform_init_buffer("earlyprin + #ifdef CONFIG_SERIAL_SH_SCI_EARLYCON + static struct plat_sci_port port_cfg; + ++static int early_console_exit(struct console *co) ++{ ++ struct sci_port *sci_port = &sci_ports[0]; ++ ++ /* ++ * Clean the slot used by earlycon. A new SCI device might ++ * map to this slot. ++ */ ++ if (!sci_uart_earlycon_dev_probing) { ++ memset(sci_port, 0, sizeof(*sci_port)); ++ sci_uart_earlycon = false; ++ } ++ ++ return 0; ++} ++ + static int __init early_console_setup(struct earlycon_device *device, + int type) + { +@@ -3683,6 +3709,8 @@ static int __init early_console_setup(st + SCSCR_RE | SCSCR_TE | port_cfg.scscr); + + device->con->write = serial_console_write; ++ device->con->exit = early_console_exit; ++ + return 0; + } + static int __init sci_early_console_setup(struct earlycon_device *device, diff --git a/queue-6.12/serial-sh-sci-increment-the-runtime-usage-counter-for-the-earlycon-device.patch b/queue-6.12/serial-sh-sci-increment-the-runtime-usage-counter-for-the-earlycon-device.patch new file mode 100644 index 0000000000..ed0bece18a --- /dev/null +++ b/queue-6.12/serial-sh-sci-increment-the-runtime-usage-counter-for-the-earlycon-device.patch @@ -0,0 +1,84 @@ +From 651dee03696e1dfde6d9a7e8664bbdcd9a10ea7f Mon Sep 17 00:00:00 2001 +From: Claudiu Beznea <claudiu.beznea.uj@bp.renesas.com> +Date: Thu, 16 Jan 2025 20:22:49 +0200 +Subject: serial: sh-sci: Increment the runtime usage counter for the earlycon device + +From: Claudiu Beznea <claudiu.beznea.uj@bp.renesas.com> + +commit 651dee03696e1dfde6d9a7e8664bbdcd9a10ea7f upstream. + +In the sh-sci driver, serial ports are mapped to the sci_ports[] array, +with earlycon mapped at index zero. + +The uart_add_one_port() function eventually calls __device_attach(), +which, in turn, calls pm_request_idle(). The identified code path is as +follows: + +uart_add_one_port() -> + serial_ctrl_register_port() -> + serial_core_register_port() -> + serial_core_port_device_add() -> + serial_base_port_add() -> + device_add() -> + bus_probe_device() -> + device_initial_probe() -> + __device_attach() -> + // ... + if (dev->p->dead) { + // ... + } else if (dev->driver) { + // ... + } else { + // ... + pm_request_idle(dev); + // ... + } + +The earlycon device clocks are enabled by the bootloader. However, the +pm_request_idle() call in __device_attach() disables the SCI port clocks +while earlycon is still active. + +The earlycon write function, serial_console_write(), calls +sci_poll_put_char() via serial_console_putchar(). If the SCI port clocks +are disabled, writing to earlycon may sometimes cause the SR.TDFE bit to +remain unset indefinitely, causing the while loop in sci_poll_put_char() +to never exit. On single-core SoCs, this can result in the system being +blocked during boot when this issue occurs. + +To resolve this, increment the runtime PM usage counter for the earlycon +SCI device before registering the UART port. + +Fixes: 0b0cced19ab1 ("serial: sh-sci: Add CONFIG_SERIAL_EARLYCON support") +Cc: stable@vger.kernel.org +Signed-off-by: Claudiu Beznea <claudiu.beznea.uj@bp.renesas.com> +Link: https://lore.kernel.org/r/20250116182249.3828577-6-claudiu.beznea.uj@bp.renesas.com +Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> +--- + drivers/tty/serial/sh-sci.c | 16 ++++++++++++++++ + 1 file changed, 16 insertions(+) + +--- a/drivers/tty/serial/sh-sci.c ++++ b/drivers/tty/serial/sh-sci.c +@@ -3455,6 +3455,22 @@ static int sci_probe_single(struct platf + + if (sci_uart_earlycon && sci_ports[0].port.mapbase == sci_res->start) { + /* ++ * In case: ++ * - this is the earlycon port (mapped on index 0 in sci_ports[]) and ++ * - it now maps to an alias other than zero and ++ * - the earlycon is still alive (e.g., "earlycon keep_bootcon" is ++ * available in bootargs) ++ * ++ * we need to avoid disabling clocks and PM domains through the runtime ++ * PM APIs called in __device_attach(). For this, increment the runtime ++ * PM reference counter (the clocks and PM domains were already enabled ++ * by the bootloader). Otherwise the earlycon may access the HW when it ++ * has no clocks enabled leading to failures (infinite loop in ++ * sci_poll_put_char()). ++ */ ++ pm_runtime_get_noresume(&dev->dev); ++ ++ /* + * Skip cleanup the sci_port[0] in early_console_exit(), this + * port is the same as the earlycon one. + */ diff --git a/queue-6.12/series b/queue-6.12/series index e7936789e5..706f2f3aec 100644 --- a/queue-6.12/series +++ b/queue-6.12/series @@ -395,3 +395,5 @@ net-atm-fix-proc-net-atm-lec-handling.patch edac-amd64-correct-number-of-umcs-for-family-19h-models-70h-7fh.patch dt-bindings-i2c-nvidia-tegra20-i2c-specify-the-required-properties.patch smb-log-an-error-when-close_all_cached_dirs-fails.patch +serial-sh-sci-clean-sci_ports-after-at-earlycon-exit.patch +serial-sh-sci-increment-the-runtime-usage-counter-for-the-earlycon-device.patch |