Skip to content

Commit f9b1122

Browse files
ij-intelgregkh
authored andcommitted
serial: 8250: Fix PM usage_count for console handover
When console is enabled, univ8250_console_setup() calls serial8250_console_setup() before .dev is set to uart_port. Therefore, it will not call pm_runtime_get_sync(). Later, when the actual driver is going to take over univ8250_console_exit() is called. As .dev is already set, serial8250_console_exit() makes pm_runtime_put_sync() call with usage count being zero triggering PM usage count warning (extra debug for univ8250_console_setup(), univ8250_console_exit(), and serial8250_register_ports()): [ 0.068987] univ8250_console_setup ttyS0 nodev [ 0.499670] printk: console [ttyS0] enabled [ 0.717955] printk: console [ttyS0] printing thread started [ 1.960163] serial8250_register_ports assigned dev for ttyS0 [ 1.976830] printk: console [ttyS0] disabled [ 1.976888] printk: console [ttyS0] printing thread stopped [ 1.977073] univ8250_console_exit ttyS0 usage:0 [ 1.977075] serial8250 serial8250: Runtime PM usage count underflow! [ 1.977429] dw-apb-uart.6: ttyS0 at MMIO 0x4010006000 (irq = 33, base_baud = 115200) is a 16550A [ 1.977812] univ8250_console_setup ttyS0 usage:2 [ 1.978167] printk: console [ttyS0] printing thread started [ 1.978203] printk: console [ttyS0] enabled To fix the issue, call pm_runtime_get_sync() in serial8250_register_ports() as soon as .dev is set for an uart_port if it has console enabled. This problem became apparent only recently because 82586a7 ("PM: runtime: Avoid device usage count underflows") added the warning printout. I confirmed this problem also occurs with v5.18 (w/o the warning printout, obviously). Fixes: bedb404 ("serial: 8250_port: Don't use power management for kernel console") Cc: stable <[email protected]> Tested-by: Tony Lindgren <[email protected]> Reviewed-by: Andy Shevchenko <[email protected]> Reviewed-by: Tony Lindgren <[email protected]> Signed-off-by: Ilpo Järvinen <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 6e690d5 commit f9b1122

File tree

3 files changed

+9
-5
lines changed

3 files changed

+9
-5
lines changed

drivers/tty/serial/8250/8250_core.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include <linux/sysrq.h>
2424
#include <linux/delay.h>
2525
#include <linux/platform_device.h>
26+
#include <linux/pm_runtime.h>
2627
#include <linux/tty.h>
2728
#include <linux/ratelimit.h>
2829
#include <linux/tty_flip.h>
@@ -559,6 +560,9 @@ serial8250_register_ports(struct uart_driver *drv, struct device *dev)
559560

560561
up->port.dev = dev;
561562

563+
if (uart_console_enabled(&up->port))
564+
pm_runtime_get_sync(up->port.dev);
565+
562566
serial8250_apply_quirks(up);
563567
uart_add_one_port(drv, &up->port);
564568
}

drivers/tty/serial/serial_core.c

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1941,11 +1941,6 @@ static int uart_proc_show(struct seq_file *m, void *v)
19411941
}
19421942
#endif
19431943

1944-
static inline bool uart_console_enabled(struct uart_port *port)
1945-
{
1946-
return uart_console(port) && (port->cons->flags & CON_ENABLED);
1947-
}
1948-
19491944
static void uart_port_spin_lock_init(struct uart_port *port)
19501945
{
19511946
spin_lock_init(&port->lock);

include/linux/serial_core.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -390,6 +390,11 @@ static const bool earlycon_acpi_spcr_enable EARLYCON_USED_OR_UNUSED;
390390
static inline int setup_earlycon(char *buf) { return 0; }
391391
#endif
392392

393+
static inline bool uart_console_enabled(struct uart_port *port)
394+
{
395+
return uart_console(port) && (port->cons->flags & CON_ENABLED);
396+
}
397+
393398
struct uart_port *uart_get_console(struct uart_port *ports, int nr,
394399
struct console *c);
395400
int uart_parse_earlycon(char *p, unsigned char *iotype, resource_size_t *addr,

0 commit comments

Comments
 (0)