Skip to contentSkip to conversation

Add back DEVNAME:0.0 console handling

PATCH In review Tony Lindgren 3 participants 7 messages Jul 3, 2024 – Jul 4, 2024

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

cover Add back DEVNAME:0.0 console handling

Hi all,

Here are the changes to add back the DEVNAME:0.0 style kernel command line console handling.

The earlier attempt to add DEVNAME:0.0 style console handling caused a regression to the kernel command line console ordering, and we reverted the whole series. The fixes would have been too intrusive for the v6.10-rc series as discussed in [0] below.

These patches are based on v6.10-rc6, and essentially the same as in [0]. Because of the rebase, I've left out Petr's Reviewed-by and Tested-by tags.

Compared to the original DEVNAME:0.0 patch series [1], things are much simplified. We now have rewritten the printk deferred console handling thanks to Petr, and have renamed the serial functions accordingly. And as we are not deferring ttyS named consoles, the serial core console quirk handling been been left out.

Regards,

Tony

[0] https://lore.kernel.org/linux-serial/[email protected]/
[1] https://lore.kernel.org/linux-serial/[email protected]/

Tony Lindgren (3):
printk: Add match_devname_and_update_preferred_console()
serial: core: Add serial_base_match_and_update_preferred_console()
Documentation: kernel-parameters: Add DEVNAME:0.0 format for serial
ports

 .../admin-guide/kernel-parameters.txt         |  19 ++++
 drivers/tty/serial/serial_base.h              |  16 +++
 drivers/tty/serial/serial_base_bus.c          |  37 +++++++
 drivers/tty/serial/serial_core.c              |   4 +
 include/linux/printk.h                        |   4 +
 kernel/printk/console_cmdline.h               |   1 +
 kernel/printk/printk.c                        | 103 +++++++++++++++---
 7 files changed, 169 insertions(+), 15 deletions(-)

base-commit: 22a40d14b572deb80c0648557f4bd502d7e83826

Signature · 1 line
2.45.2
#1 lore raw

PATCH 1/3 printk: Add match_devname_and_update_preferred_console()

Let's add match_devname_and_update_preferred_console() for driver subsystems to call during init when the console is ready, and it's character device name is known. For now, we use it only for the serial layer to allow console=DEVNAME:0.0 style hardware based addressing for consoles.

The earlier attempt on doing this caused a regression with the kernel command line console order as it added calling __add_preferred_console() again later on during init. A better approach was suggested by Petr where we add the deferred console to the console_cmdline[] and update it later on when the console is ready.

---
 include/linux/printk.h          |   4 ++
 kernel/printk/console_cmdline.h |   1 +
 kernel/printk/printk.c          | 103 +++++++++++++++++++++++++++-----
 3 files changed, 93 insertions(+), 15 deletions(-)
include/linux/printk.h +4 -0
index 65c5184470f1..7239976698e4 100644
@@ -60,6 +60,10 @@ static inline const char *printk_skip_headers(const char *buffer)
 #define CONSOLE_LOGLEVEL_DEFAULT CONFIG_CONSOLE_LOGLEVEL_DEFAULT
 #define CONSOLE_LOGLEVEL_QUIET	 CONFIG_CONSOLE_LOGLEVEL_QUIET
 
+int match_devname_and_update_preferred_console(const char *match,
+					       const char *name,
+					       const short idx);
+
 extern int console_printk[];
 
 #define console_loglevel (console_printk[0])
kernel/printk/console_cmdline.h +1 -0
index 3ca74ad391d6..0ab573b6d4dc 100644
@@ -6,6 +6,7 @@ struct console_cmdline
 {
 	char	name[16];			/* Name of the driver	    */
 	int	index;				/* Minor dev. to use	    */
+	char	devname[32];			/* DEVNAME:0.0 style device name */
 	bool	user_specified;			/* Specified by command line vs. platform */
 	char	*options;			/* Options for the driver   */
 #ifdef CONFIG_A11Y_BRAILLE_CONSOLE
kernel/printk/printk.c +88 -15

174 lines not on this page · raw message

Signature · 1 line
2.45.2
maintainer Reviewed-by on v1 1/3
#2 lore raw

Re: [PATCH 1/3] printk: Add match_devname_and_update_preferred_console()

Quoted 12 lines · Tony Lindgren

Let's add match_devname_and_update_preferred_console() for driver subsystems to call during init when the console is ready, and it's character device name is known. For now, we use it only for the serial layer to allow console=DEVNAME:0.0 style hardware based addressing for consoles.

The earlier attempt on doing this caused a regression with the kernel command line console order as it added calling __add_preferred_console() again later on during init. A better approach was suggested by Petr where we add the deferred console to the console_cmdline[] and update it later on when the console is ready.

Quoted 3 lines

Best Regards,
Petr

#3 lore raw

Re: [PATCH 1/3] printk: Add match_devname_and_update_preferred_console()

Quoted 13 lines · Petr Mladek
Quoted 12 lines · Tony Lindgren

Let's add match_devname_and_update_preferred_console() for driver subsystems to call during init when the console is ready, and it's character device name is known. For now, we use it only for the serial layer to allow console=DEVNAME:0.0 style hardware based addressing for consoles.

The earlier attempt on doing this caused a regression with the kernel command line console order as it added calling __add_preferred_console() again later on during init. A better approach was suggested by Petr where we add the deferred console to the console_cmdline[] and update it later on when the console is ready.

Quoted 5 lines
Quoted 3 lines

Thanks for the review, I'll take this through the tty tree now.

greg k-h

#4 lore raw

PATCH 2/3 serial: core: Add serial_base_match_and_update_preferred_console()

In reply to Tony Lindgren

Let's add serial_base_match_and_update_preferred_console() for consoles using DEVNAME:0.0 style naming.

The earlier approach to add it caused issues in the kernel command line ordering as we were calling __add_preferred_console() again for the deferred consoles.

---
 drivers/tty/serial/serial_base.h     | 16 ++++++++++++
 drivers/tty/serial/serial_base_bus.c | 37 ++++++++++++++++++++++++++++
 drivers/tty/serial/serial_core.c     |  4 +++
 3 files changed, 57 insertions(+)
drivers/tty/serial/serial_base.h +16 -0
index b6c38d2edfd4..0d50db5b660b 100644
@@ -49,3 +49,19 @@ void serial_ctrl_unregister_port(struct uart_driver *drv, struct uart_port *port
 
 int serial_core_register_port(struct uart_driver *drv, struct uart_port *port);
 void serial_core_unregister_port(struct uart_driver *drv, struct uart_port *port);
+
+#ifdef CONFIG_SERIAL_CORE_CONSOLE
+
+int serial_base_match_and_update_preferred_console(struct uart_driver *drv,
+						   struct uart_port *port);
+
+#else
+
+static inline
+int serial_base_match_and_update_preferred_console(struct uart_driver *drv,
+						   struct uart_port *port)
+{
+	return 0;
+}
+
+#endif
drivers/tty/serial/serial_base_bus.c +37 -0
index 4df2a4b10445..d822499ba9d6 100644
@@ -8,6 +8,7 @@
  * The serial core bus manages the serial core controller instances.
  */
 
+#include <linux/cleanup.h>
 #include <linux/container_of.h>
 #include <linux/device.h>
 #include <linux/idr.h>
@@ -204,6 +205,42 @@ void serial_base_port_device_remove(struct serial_port_device *port_dev)
 	put_device(&port_dev->dev);
 }
 
+#ifdef CONFIG_SERIAL_CORE_CONSOLE
+
+/**
+ * serial_base_match_and_update_preferred_console - Match and update a preferred console
+ * @drv: Serial port device driver
+ * @port: Serial port instance
+ *
+ * Tries to match and update the preferred console for a serial port for
+ * the kernel command line option console=DEVNAME:0.0.
+ *
+ * Cannot be called early for ISA ports, depends on struct device.
+ *
+ * Return: 0 on success, negative error code on failure.
+ */
+int serial_base_match_and_update_preferred_console(struct uart_driver *drv,
+						   struct uart_port *port)
+{
+	const char *port_match __free(kfree) = NULL;
+	int ret;
+
+	port_match = kasprintf(GFP_KERNEL, "%s:%d.%d", dev_name(port->dev),
+			       port->ctrl_id, port->port_id);
+	if (!port_match)
+		return -ENOMEM;
+
+	ret = match_devname_and_update_preferred_console(port_match,
+							 drv->dev_name,
+							 port->line);
+	if (ret == -ENOENT)
+		return 0;
+
+	return ret;
+}
+
+#endif
+
 static int serial_base_init(void)
 {
 	int ret;
drivers/tty/serial/serial_core.c +4 -0
index 2a8006e3d687..9a18d0b95a41 100644
@@ -3422,6 +3422,10 @@ int serial_core_register_port(struct uart_driver *drv, struct uart_port *port)
 	if (ret)
 		goto err_unregister_ctrl_dev;
 
+	ret = serial_base_match_and_update_preferred_console(drv, port);
+	if (ret)
+		goto err_unregister_port_dev;
+
 	ret = serial_core_add_one_port(drv, port);
 	if (ret)
 		goto err_unregister_port_dev;
Signature · 1 line
2.45.2
#5 lore raw

PATCH 3/3 Documentation: kernel-parameters: Add DEVNAME:0.0 format for serial ports

In reply to Tony Lindgren

From: Tony Lindgren <[email protected]>

Document the console option for DEVNAME:0.0 style addressing for serial ports.

---
 .../admin-guide/kernel-parameters.txt         | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)
Documentation/admin-guide/kernel-parameters.txt +19 -0
index 27ec49af1bf2..11e57ba2985c 100644
@@ -788,6 +788,25 @@
 			Documentation/networking/netconsole.rst for an
 			alternative.
 
+		<DEVNAME>:<n>.<n>[,options]
+			Use the specified serial port on the serial core bus.
+			The addressing uses DEVNAME of the physical serial port
+			device, followed by the serial core controller instance,
+			and the serial port instance. The options are the same
+			as documented for the ttyS addressing above.
+
+			The mapping of the serial ports to the tty instances
+			can be viewed with:
+
+			$ ls -d /sys/bus/serial-base/devices/*:*.*/tty/*
+			/sys/bus/serial-base/devices/00:04:0.0/tty/ttyS0
+
+			In the above example, the console can be addressed with
+			console=00:04:0.0. Note that a console addressed this
+			way will only get added when the related device driver
+			is ready. The use of an earlycon parameter in addition to
+			the console may be desired for console output early on.
+
 		uart[8250],io,<addr>[,options]
 		uart[8250],mmio,<addr>[,options]
 		uart[8250],mmio16,<addr>[,options]
Signature · 1 line
2.45.2
maintainer Reviewed-by on v1 3/3
#6 lore raw

Re: [PATCH 3/3] Documentation: kernel-parameters: Add DEVNAME:0.0 format for serial ports

Quoted 8 lines · Tony Lindgren

From: Tony Lindgren <[email protected]>

Document the console option for DEVNAME:0.0 style addressing for serial ports.

Best Regards,
Petr