[PATCH] serial: qcom-geni: keep registered console runtime active

Konrad Dybcio posted 1 patch 1 month, 1 week ago
drivers/tty/serial/qcom_geni_serial.c | 26 ++++++++++++++++++++++++--
1 file changed, 24 insertions(+), 2 deletions(-)
[PATCH] serial: qcom-geni: keep registered console runtime active
Posted by Konrad Dybcio 1 month, 1 week ago
From: Konrad Dybcio <konrad.dybcio@oss.qualcomm.com>

Commit aee1f94dab13 ("serial: qcom-geni: remove .pm callback, use
runtime PM in startup/shutdown") moved runtime PM references from the
serial-core PM callback to the port startup and shutdown callbacks.

The serial core used to leave the console port powered after
registration, but after the callback was removed the temporary probe
reference is always released. Console writes are not tied to an open TTY
and can run from contexts which cannot resume the device, so a
runtime-suspended console can stall. This was observed on a Qualcomm
X1E80100 CRD device, as the boot console became flakey across boots.

Acquire a runtime PM reference when the console is set up and release it
through the console exit callback. This keeps the device active only
while the console is registered and balances the reference when the
console is disabled or re-enabled through sysfs.

Fixes: aee1f94dab13 ("serial: qcom-geni: remove .pm callback, use runtime PM in startup/shutdown")
Assisted-by: LLM
Signed-off-by: Konrad Dybcio <konrad.dybcio@oss.qualcomm.com>
---
 drivers/tty/serial/qcom_geni_serial.c | 26 ++++++++++++++++++++++++--
 1 file changed, 24 insertions(+), 2 deletions(-)

diff --git a/drivers/tty/serial/qcom_geni_serial.c b/drivers/tty/serial/qcom_geni_serial.c
index 3633723acef8..92858bcdebc7 100644
--- a/drivers/tty/serial/qcom_geni_serial.c
+++ b/drivers/tty/serial/qcom_geni_serial.c
@@ -1625,16 +1625,37 @@ static int qcom_geni_console_setup(struct console *co, char *options)
 	if (unlikely(!uport->membase))
 		return -ENXIO;
 
+	ret = pm_runtime_resume_and_get(uport->dev);
+	if (ret < 0)
+		return ret;
+
 	if (!port->setup) {
 		ret = qcom_geni_serial_port_setup(uport);
-		if (ret)
+		if (ret) {
+			pm_runtime_put_sync(uport->dev);
 			return ret;
+		}
 	}
 
 	if (options)
 		uart_parse_options(options, &baud, &parity, &bits, &flow);
 
-	return uart_set_options(uport, co, baud, parity, bits, flow);
+	ret = uart_set_options(uport, co, baud, parity, bits, flow);
+	if (ret)
+		pm_runtime_put_sync(uport->dev);
+
+	return ret;
+}
+
+static int qcom_geni_console_exit(struct console *co)
+{
+	struct qcom_geni_serial_port *port;
+
+	port = get_port_from_line(co->index, true, NULL);
+	if (IS_ERR(port))
+		return PTR_ERR(port);
+
+	return pm_runtime_put_sync(port->uport.dev);
 }
 
 static void qcom_geni_serial_earlycon_write(struct console *con,
@@ -1751,6 +1772,7 @@ static struct console cons_ops = {
 	.device_unlock = qcom_geni_serial_console_device_unlock,
 	.device = uart_console_device,
 	.setup = qcom_geni_console_setup,
+	.exit = qcom_geni_console_exit,
 	.flags = CON_PRINTBUFFER | CON_NBCON,
 	.index = -1,
 	.data = &qcom_geni_console_driver,

---
base-commit: 6a746cd265aed59107ebdaa9ce039bb832922969
change-id: 20260819-topic-geni_console_poweredoff-f73b4815820e

Best regards,
--  
Konrad Dybcio <konrad.dybcio@oss.qualcomm.com>
Re: [PATCH] serial: qcom-geni: keep registered console runtime active
Posted by David Heidelberg 1 week, 3 days ago
On 19/08/2026 18:46, Konrad Dybcio wrote:
> From: Konrad Dybcio <konrad.dybcio@oss.qualcomm.com>
> 
> Commit aee1f94dab13 ("serial: qcom-geni: remove .pm callback, use
> runtime PM in startup/shutdown") moved runtime PM references from the
> serial-core PM callback to the port startup and shutdown callbacks.
> 
> The serial core used to leave the console port powered after
> registration, but after the callback was removed the temporary probe
> reference is always released. Console writes are not tied to an open TTY
> and can run from contexts which cannot resume the device, so a
> runtime-suspended console can stall. This was observed on a Qualcomm
> X1E80100 CRD device, as the boot console became flakey across boots.
> 
> Acquire a runtime PM reference when the console is set up and release it
> through the console exit callback. This keeps the device active only
> while the console is registered and balances the reference when the
> console is disabled or re-enabled through sysfs.
> 
> Fixes: aee1f94dab13 ("serial: qcom-geni: remove .pm callback, use runtime PM in startup/shutdown")
> Assisted-by: LLM
> Signed-off-by: Konrad Dybcio <konrad.dybcio@oss.qualcomm.com>
> ---
>   drivers/tty/serial/qcom_geni_serial.c | 26 ++++++++++++++++++++++++--
>   1 file changed, 24 insertions(+), 2 deletions(-)
> 
This also fixes a regression on sdm845: since v7.3-rc1 (or on next-20260820), 
OnePlus 6 and 6T crash into the Qualcomm crash dump mode on every s2idle suspend 
attempt (no kernel output, warm reset via PS_HOLD with the TZ download cookie 
set, no panic in ramoops).

Tested-by: David Heidelberg <david@ixit.cz> # OnePlus 6T (sdm845)

One thing this leaves open: with the console holding a single reference,
pm_runtime_force_suspend() goes through pm_runtime_need_not_resume() and
pm_runtime_force_resume() does not power the port back up, so
uart_resume_port() programs the termios and resumes the console on a
powered-down port; it only comes back through startup() if the tty was
open. I'll send a patch on top for that.

Thank you
David
Re: [PATCH] serial: qcom-geni: keep registered console runtime active
Posted by Abel Vesa 1 month, 1 week ago
On 26-08-19 18:46:47, Konrad Dybcio wrote:
> From: Konrad Dybcio <konrad.dybcio@oss.qualcomm.com>
> 
> Commit aee1f94dab13 ("serial: qcom-geni: remove .pm callback, use
> runtime PM in startup/shutdown") moved runtime PM references from the
> serial-core PM callback to the port startup and shutdown callbacks.
> 
> The serial core used to leave the console port powered after
> registration, but after the callback was removed the temporary probe
> reference is always released. Console writes are not tied to an open TTY
> and can run from contexts which cannot resume the device, so a
> runtime-suspended console can stall. This was observed on a Qualcomm
> X1E80100 CRD device, as the boot console became flakey across boots.
> 
> Acquire a runtime PM reference when the console is set up and release it
> through the console exit callback. This keeps the device active only
> while the console is registered and balances the reference when the
> console is disabled or re-enabled through sysfs.
> 
> Fixes: aee1f94dab13 ("serial: qcom-geni: remove .pm callback, use runtime PM in startup/shutdown")
> Assisted-by: LLM
> Signed-off-by: Konrad Dybcio <konrad.dybcio@oss.qualcomm.com>

Reviewed-by: Abel Vesa <abel.vesa@oss.qualcomm.com>