serial: 8250: allow use of non-runtime configured uart ports
PATCH v3 1/4 serial: 8250: allow use of non-runtime configured uart ports
The logic to find unused ports when registering new 8250 uart ports searches only up to CONFIG_SERIAL_8250_RUNTIME_UARTS, which forces users of external 8250 ports to increase the number of runtime ports artificially.
Fix this by initializing each allocated port structure with basic settings like line number and uart operation callbacks, and by searching the entire array of allocated ports to find an unused one.
--- drivers/tty/serial/8250/8250_core.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-)
drivers/tty/serial/8250/8250_core.c +5 -4
@@ -500,7 +500,7 @@ static void __init serial8250_isa_init_ports(void)if (nr_uarts >UART_NR ) nr_uarts =UART_NR ; -for (i =0 ; i < nr_uarts; i++) { +for (i =0 ; i <UART_NR ; i++) {struct uart_8250_port *up = &serial8250_ports[i];struct uart_port *port = &up->port;
@@ -926,15 +926,16 @@ static struct uart_8250_port *serial8250_find_match_or_unused(const struct uart_/* try line number first if still available */ i = port->line; -if (i < nr_uarts && serial8250_ports[i].port.type ==PORT_UNKNOWN && +if (i <UART_NR && serial8250_ports[i].port.type ==PORT_UNKNOWN && serial8250_ports[i].port.iobase ==0 )return &serial8250_ports[i]; +/* * We didn't find a matching entry, so look for the first * free entry. We look for one which hasn't been previously * used (indicated by zero iobase). */ -for (i =0 ; i < nr_uarts; i++) +for (i =0 ; i <UART_NR ; i++)if (serial8250_ports[i].port.type ==PORT_UNKNOWN && serial8250_ports[i].port.iobase ==0 )return &serial8250_ports[i];
@@ -943,7 +944,7 @@ static struct uart_8250_port *serial8250_find_match_or_unused(const struct uart_* That also failed. Last resort is to find any entry which * doesn't have a real port associated with it. */ -for (i =0 ; i < nr_uarts; i++) +for (i =0 ; i <UART_NR ; i++)if (serial8250_ports[i].port.type ==PORT_UNKNOWN )return &serial8250_ports[i];
Signature · 1 line
2.38.1
PATCH v3 2/4 serial: 8250: allow zero runtime-configured ports
One should be able to set CONFIG_SERIAL_8250_RUNTIME_UARTS=0 on platforms with zero built-in 8250-like ports. However, that case was prohibited in commit 59cfc45f17d6
("serial: 8250: Do nothing if nr_uarts=0"), because of missing array initialization, effectively disabling the driver entirely.
The missing array initialization has been fixed in the previous commit, so remove check for zero runtime ports. Said check gets to stay when initializing early consoles, though, because that makes sense for built-in ports only.
--- drivers/tty/serial/8250/8250_core.c | 6 ------ 1 file changed, 6 deletions(-)
drivers/tty/serial/8250/8250_core.c +0 -6
@@ -680,9 +680,6 @@ static struct console univ8250_console = {static int __init univ8250_console_init (void ) { -if (nr_uarts ==0 ) -return -ENODEV ; -serial8250_isa_init_ports ();register_console (&univ8250_console);return 0 ;
@@ -1171,9 +1168,6 @@ static int __init serial8250_init(void) {int ret; -if (nr_uarts ==0 ) -return -ENODEV ; -serial8250_isa_init_ports (); pr_info("Serial: 8250/16550 driver, %d ports, IRQ sharing %sabled\n",
Signature · 1 line
2.38.1
PATCH v3 3/4 serial: 8250: skip platform device registration with no runtime ports
In reply to Martin HundebøllSkip registration of the platform device used for built-in ports, if no such ports are configured/created.
---
Change since v1:
* call serial8250_pnp_init() also when nr_uarts is zero
Change since v2:
* invert condition to initialize built-in ports (as suggested by Ilpo)
drivers/tty/serial/8250/8250_core.c | 30 +++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-)
drivers/tty/serial/8250/8250_core.c +18 -12
@@ -1186,22 +1186,26 @@ static int __init serial8250_init(void)if (ret) goto unreg_uart_drv; - serial8250_isa_devs =platform_device_alloc ("serial8250" , -PLAT8250_DEV_LEGACY ); -if (!serial8250_isa_devs) { - ret = -ENOMEM ; - goto unreg_pnp; +if (nr_uarts) { + serial8250_isa_devs =platform_device_alloc ("serial8250" , +PLAT8250_DEV_LEGACY ); +if (!serial8250_isa_devs) { + ret = -ENOMEM ; + goto unreg_pnp; + } + + ret =platform_device_add (serial8250_isa_devs); +if (ret) + goto put_dev; + +serial8250_register_ports (&serial8250_reg, &serial8250_isa_devs->dev); } - ret =platform_device_add (serial8250_isa_devs); -if (ret) - goto put_dev; - -serial8250_register_ports (&serial8250_reg, &serial8250_isa_devs->dev); - ret =platform_driver_register (&serial8250_isa_driver);if (ret ==0 ) goto out; +if (!nr_uarts) + goto unreg_pnp;platform_device_del (serial8250_isa_devs); put_dev:
@@ -1230,7 +1234,9 @@ static void __exit serial8250_exit(void) serial8250_isa_devs =NULL ;platform_driver_unregister (&serial8250_isa_driver); -platform_device_unregister (isa_dev); + +if (nr_uarts) +platform_device_unregister (isa_dev);serial8250_pnp_exit ();
Signature · 1 line
2.38.1
Re: [PATCH v3 3/4] serial: 8250: skip platform device registration with no runtime ports
Quoted 4 lines · Martin Hundebøll
Skip registration of the platform device used for built-in ports, if no such ports are configured/created.
Signed-off-by Martin Hundebøll <[email protected]>
For patches 1-3:
Please include these tags into the next version of your submission. Thank you.
Signature · 1 line
i.
Quoted 65 lines
---
Change since v1:
* callserial8250_pnp_init()also whennr_uartsis zeroChange since v2:
* invert condition to initialize built-in ports (as suggested by Ilpo)drivers/tty/serial/8250/8250_core.c | 30 +++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-)drivers/tty/serial/8250/8250_core.c +18
-12@@ -1186,22 +1186,26 @@ static int __init serial8250_init(void)if (ret) goto unreg_uart_drv; - serial8250_isa_devs =platform_device_alloc ("serial8250" , -PLAT8250_DEV_LEGACY ); -if (!serial8250_isa_devs) { - ret = -ENOMEM ; - goto unreg_pnp; +if (nr_uarts) { + serial8250_isa_devs =platform_device_alloc ("serial8250" , +PLAT8250_DEV_LEGACY ); +if (!serial8250_isa_devs) { + ret = -ENOMEM ; + goto unreg_pnp; + } + + ret =platform_device_add (serial8250_isa_devs); +if (ret) + goto put_dev; + +serial8250_register_ports (&serial8250_reg, &serial8250_isa_devs->dev); } - ret =platform_device_add (serial8250_isa_devs); -if (ret) - goto put_dev; - -serial8250_register_ports (&serial8250_reg, &serial8250_isa_devs->dev); - ret =platform_driver_register (&serial8250_isa_driver);if (ret ==0 ) goto out; +if (!nr_uarts) + goto unreg_pnp;platform_device_del (serial8250_isa_devs); put_dev:@@ -1230,7 +1234,9 @@ static void __exit serial8250_exit(void) serial8250_isa_devs =NULL ;platform_driver_unregister (&serial8250_isa_driver); -platform_device_unregister (isa_dev); + +if (nr_uarts) +platform_device_unregister (isa_dev);serial8250_pnp_exit ();
Re: [PATCH v3 3/4] serial: 8250: skip platform device registration with no runtime ports
Quoted 7 lines · Ilpo Järvinen
Quoted 4 lines · Martin Hundebøll
Skip registration of the platform device used for built-in ports, if no such ports are configured/created.
Signed-off-by Martin Hundebøll <[email protected]>
Quoted 7 lines
For patches 1-3:
Tested-by Ilpo Järvinen <[email protected]>Reviewed-by Ilpo Järvinen <[email protected]>Please include these tags into the next version of your submission. Thank you.
Actually, I just found out that some set of cmdline parameters do no longer work the same. So I'm retracting both of my tags for now.
=0 did work as expected due to this change which I tested and some other values >4 but there now seems to be problem of the console not showing up like previously when I don't give nr_uarts at all.
Signature · 1 line
i.
Re: [PATCH v3 3/4] serial: 8250: skip platform device registration with no runtime ports
Quoted 17 lines · Ilpo Järvinen
Quoted 7 lines · Ilpo Järvinen
Quoted 4 lines · Martin Hundebøll
Skip registration of the platform device used for built-in ports, if no such ports are configured/created.
Signed-off-by Martin Hundebøll <[email protected]>Quoted 7 lines
For patches 1-3:
Tested-by Ilpo Järvinen <[email protected]>Reviewed-by Ilpo Järvinen <[email protected]>Please include these tags into the next version of your submission. Thank you.
Quoted 6 lines
Actually, I just found out that some set of cmdline parameters do no longer work the same. So I'm retracting both of my tags for now.
=0 did work as expected due to this change which I tested and some other values >4 but there now seems to be problem of the console not showing up like previously when I don't give
nr_uartsat all.
NAK from me until the problem is resolved adequately.
Already the patch 1/4 causes an unacceptable reassignment of ttySx targets. This is going to break people's cmdline console setups so you need to find a better way.
Before any of these patches:
[ 0.000000] Command line: console=ttyS0,115200n8 8250.nr_uarts=4 [ 0.021031] Kernel command line: console=ttyS0,115200n8 8250.nr_uarts=4 [ 0.441924] printk: console [ttyS0] enabled [ 2.243165] printk: console [ttyS0] disabled [ 2.245682] dw-apb-uart.6: ttyS0 at MMIO 0x4010006000 (irq = 33, base_baud = 115200) is a 16550A [ 4.010237] printk: console [ttyS0] enabled [ 5.933887] dw-apb-uart.7: ttyS1 at MMIO 0x4010007000 (irq = 16, base_baud = 6250000) is a 16550A [ 5.952829] dw-apb-uart.8: ttyS2 at MMIO 0x4010008000 (irq = 17, base_baud = 6250000) is a 16550A
After 1/4 ttyS0 is no longer the same:
[ 0.000000] Command line: console=ttyS0,115200n8 8250.nr_uarts=4 [ 0.021023] Kernel command line: console=ttyS0,115200n8 8250.nr_uarts=4 [ 0.441872] printk: console [ttyS0] enabled [ 2.233584] dw-apb-uart.6: ttyS4 at MMIO 0x4010006000 (irq = 33, base_baud = 115200) is a 16550A [ 2.241955] dw-apb-uart.7: ttyS5 at MMIO 0x4010007000 (irq = 16, base_baud = 6250000) is a 16550A [ 2.249804] dw-apb-uart.8: ttyS6 at MMIO 0x4010008000 (irq = 17, base_baud = 6250000) is a 16550A
Signature · 1 line
i.
Re: [PATCH v3 3/4] serial: 8250: skip platform device registration with no runtime ports
Quoted 43 lines · Ilpo Järvinen
Quoted 17 lines · Ilpo Järvinen
Quoted 7 lines · Ilpo Järvinen
Quoted 4 lines · Martin Hundebøll
Skip registration of the platform device used for built-in ports, if no such ports are configured/created.
Signed-off-by Martin Hundebøll <[email protected]>Quoted 7 lines
For patches 1-3:
Tested-by Ilpo Järvinen <[email protected]>Reviewed-by Ilpo Järvinen <[email protected]>Please include these tags into the next version of your submission. Thank you.
Quoted 6 lines
Actually, I just found out that some set of cmdline parameters do no longer work the same. So I'm retracting both of my tags for now.
=0 did work as expected due to this change which I tested and some other values >4 but there now seems to be problem of the console not showing up like previously when I don't give
nr_uartsat all.NAK from me until the problem is resolved adequately.
Already the patch 1/4 causes an unacceptable reassignment of ttySx targets. This is going to break people's cmdline console setups so you need to find a better way.
Before any of these patches:
[ 0.000000] Command line: console=ttyS0,115200n8 8250.nr_uarts=4 [ 0.021031] Kernel command line: console=ttyS0,115200n8 8250.nr_uarts=4 [ 0.441924] printk: console [ttyS0] enabled [ 2.243165] printk: console [ttyS0] disabled [ 2.245682] dw-apb-uart.6: ttyS0 at MMIO 0x4010006000 (irq = 33, base_baud = 115200) is a 16550A [ 4.010237] printk: console [ttyS0] enabled [ 5.933887] dw-apb-uart.7: ttyS1 at MMIO 0x4010007000 (irq = 16, base_baud = 6250000) is a 16550A [ 5.952829] dw-apb-uart.8: ttyS2 at MMIO 0x4010008000 (irq = 17, base_baud = 6250000) is a 16550A
Quoted 8 lines
After 1/4 ttyS0 is no longer the same:
[ 0.000000] Command line: console=ttyS0,115200n8 8250.nr_uarts=4 [ 0.021023] Kernel command line: console=ttyS0,115200n8 8250.nr_uarts=4 [ 0.441872] printk: console [ttyS0] enabled [ 2.233584] dw-apb-uart.6: ttyS4 at MMIO 0x4010006000 (irq = 33, base_baud = 115200) is a 16550A [ 2.241955] dw-apb-uart.7: ttyS5 at MMIO 0x4010007000 (irq = 16, base_baud = 6250000) is a 16550A [ 2.249804] dw-apb-uart.8: ttyS6 at MMIO 0x4010008000 (irq = 17, base_baud = 6250000) is a 16550A
Thanks for testing this.
The old behavior is wrong: your designware ports replace the built-in ones (0 to 3) instead of using the unused ones (4 to 31). With these patches, it acts as I'd expect: the built-in ports are kept, and any later discovered ports follow.
Yes, breaking existing systems in this way is unacceptable. I'm not sure how to approach this, but I'm inclined to introduce a new config variable to keep the broken behavior?
// Martin
Re: [PATCH v3 3/4] serial: 8250: skip platform device registration with no runtime ports
Quoted 62 lines · Martin Hundebøll
Quoted 57 lines · Ilpo Järvinen
Quoted 18 lines · Ilpo Järvinen
Quoted 8 lines · Ilpo Järvinen
Quoted 5 lines · Martin Hundebøll
Skip registration of the platform device used for built-in ports, if no
such ports are configured/created.Signed-off-by Martin Hundebøll <[email protected]>Quoted 7 lines
For patches 1-3:
Tested-by Ilpo Järvinen <[email protected]>Reviewed-by Ilpo Järvinen <[email protected]>Please include these tags into the next version of your submission. Thank you.
Quoted 6 lines
Actually, I just found out that some set of cmdline parameters do no longer work the same. So I'm retracting both of my tags for now.
=0 did work as expected due to this change which I tested and some other values >4 but there now seems to be problem of the console not showing up like previously when I don't give
nr_uartsat all.NAK from me until the problem is resolved adequately.
Already the patch 1/4 causes an unacceptable reassignment of ttySx targets. This is going to break people's cmdline console setups so you need to find a better way.
Before any of these patches:
[ 0.000000] Command line: console=ttyS0,115200n8 8250.nr_uarts=4 [ 0.021031] Kernel command line: console=ttyS0,115200n8 8250.nr_uarts=4 [ 0.441924] printk: console [ttyS0] enabled [ 2.243165] printk: console [ttyS0] disabled [ 2.245682] dw-apb-uart.6: ttyS0 at MMIO 0x4010006000 (irq = 33, base_baud = 115200) is a 16550A [ 4.010237] printk: console [ttyS0] enabled [ 5.933887] dw-apb-uart.7: ttyS1 at MMIO 0x4010007000 (irq = 16, base_baud = 6250000) is a 16550A [ 5.952829] dw-apb-uart.8: ttyS2 at MMIO 0x4010008000 (irq = 17,
base_baud= 6250000) is a 16550AAfter 1/4 ttyS0 is no longer the same:
[ 0.000000] Command line: console=ttyS0,115200n8 8250.nr_uarts=4 [ 0.021023] Kernel command line: console=ttyS0,115200n8 8250.nr_uarts=4 [ 0.441872] printk: console [ttyS0] enabled [ 2.233584] dw-apb-uart.6: ttyS4 at MMIO 0x4010006000 (irq = 33, base_baud = 115200) is a 16550A [ 2.241955] dw-apb-uart.7: ttyS5 at MMIO 0x4010007000 (irq = 16, base_baud = 6250000) is a 16550A [ 2.249804] dw-apb-uart.8: ttyS6 at MMIO 0x4010008000 (irq = 17,Quoted 1 line
base_baud= 6250000) is a 16550AThanks for testing this.
Quoted 8 lines
The old behavior is wrong: your designware ports replace the built-in ones (0 to 3) instead of using the unused ones (4 to 31). With these patches, it acts as I'd expect: the built-in ports are kept, and any later discovered ports follow.
Yes, breaking existing systems in this way is unacceptable. I'm not sure how to approach this, but I'm inclined to introduce a new config variable to keep the broken behavior?
To me this looks now more an attempt to repurpose the nr_uarts to mean something it really hasn't. Clearly it hasn't meant non-discoverable ports earlier but something related to the maximum number ports. This also explains why we had that misunderstanding about the meaning of nr_uarts between us earlier.
The code which makes this "wrong behavior" to happen is the last loop in serial8250_find_match_or_unused(). Given its comment, I think it has been very much intentional behavior. Pretending that non-discoverable port is more real/precious than a port that was later _discovered_ and is very much a real one is what brings you to this renumbering issue.
I'm not anymore sure about your goals really. Now it sounds one of the goals is preserving the non-discoverable ports, whereas previously it was just about allowing 0 of them.
How about you add entirely new CONFIG and/or param for this minimum number of non-discoverable ports and make the last resort loop (or perhaps all but the first loop) in serial8250_find_match_or_unused() to honor that (start looking only from port above that index). If it defaults to 0, I think this renumbering issue is avoided. Would it work for all the goals you have?
With that change, I don't know what condition should trigger what you do in 3/4 though.
Signature · 1 line
i.
Re: [PATCH v3 3/4] serial: 8250: skip platform device registration with no runtime ports
Quoted 73 lines · Ilpo Järvinen
Quoted 62 lines · Martin Hundebøll
Quoted 57 lines · Ilpo Järvinen
Quoted 18 lines · Ilpo Järvinen
Quoted 8 lines · Ilpo Järvinen
Quoted 5 lines · Martin Hundebøll
Skip registration of the platform device used for built-in ports, if no
such ports are configured/created.Signed-off-by Martin Hundebøll <[email protected]>Quoted 7 lines
For patches 1-3:
Tested-by Ilpo Järvinen <[email protected]>Reviewed-by Ilpo Järvinen <[email protected]>Please include these tags into the next version of your submission. Thank you.
Quoted 6 lines
Actually, I just found out that some set of cmdline parameters do no longer work the same. So I'm retracting both of my tags for now.
=0 did work as expected due to this change which I tested and some other values >4 but there now seems to be problem of the console not showing up like previously when I don't give
nr_uartsat all.NAK from me until the problem is resolved adequately.
Already the patch 1/4 causes an unacceptable reassignment of ttySx targets. This is going to break people's cmdline console setups so you need to find a better way.
Before any of these patches:
[ 0.000000] Command line: console=ttyS0,115200n8 8250.nr_uarts=4 [ 0.021031] Kernel command line: console=ttyS0,115200n8 8250.nr_uarts=4 [ 0.441924] printk: console [ttyS0] enabled [ 2.243165] printk: console [ttyS0] disabled [ 2.245682] dw-apb-uart.6: ttyS0 at MMIO 0x4010006000 (irq = 33, base_baud = 115200) is a 16550A [ 4.010237] printk: console [ttyS0] enabled [ 5.933887] dw-apb-uart.7: ttyS1 at MMIO 0x4010007000 (irq = 16, base_baud = 6250000) is a 16550A [ 5.952829] dw-apb-uart.8: ttyS2 at MMIO 0x4010008000 (irq = 17,
base_baud= 6250000) is a 16550AAfter 1/4 ttyS0 is no longer the same:
[ 0.000000] Command line: console=ttyS0,115200n8 8250.nr_uarts=4 [ 0.021023] Kernel command line: console=ttyS0,115200n8 8250.nr_uarts=4 [ 0.441872] printk: console [ttyS0] enabled [ 2.233584] dw-apb-uart.6: ttyS4 at MMIO 0x4010006000 (irq = 33, base_baud = 115200) is a 16550A [ 2.241955] dw-apb-uart.7: ttyS5 at MMIO 0x4010007000 (irq = 16, base_baud = 6250000) is a 16550A [ 2.249804] dw-apb-uart.8: ttyS6 at MMIO 0x4010008000 (irq = 17,Quoted 1 line
base_baud= 6250000) is a 16550AThanks for testing this.
Quoted 8 lines
The old behavior is wrong: your designware ports replace the built-in ones (0 to 3) instead of using the unused ones (4 to 31). With these patches, it acts as I'd expect: the built-in ports are kept, and any later discovered ports follow.
Yes, breaking existing systems in this way is unacceptable. I'm not sure how to approach this, but I'm inclined to introduce a new config variable to keep the broken behavior?
Quoted 5 lines
To me this looks now more an attempt to repurpose the
nr_uartsto mean something it really hasn't. Clearly it hasn't meant non-discoverable ports earlier but something related to the maximum number ports. This also explains why we had that misunderstanding about the meaning ofnr_uartsbetween us earlier.
I was confused about the relation between SERIAL_8250_NR_UARTS and SERIAL_8250_RUNTIME_UARTS, and started digging through the code. The description of NR_UARTS clearly states that it controls the number of *supported* uarts, but I found that it was in fact controlled by RUNTIME_UARTS (8250.nr_uarts).
With the current behavior, ever setting NR_UARTS to anything different from RUNTIME_UARTS makes no sense, since the code only loops until RUNTIME_UARTS. Both Arch Linux and Fedora have come to the same conclusion, since they set both configs to 32. So now I have 32 useless /dev/ttyS* nodes on my laptop. If you run ubuntu on a machine with no uart hardware attached, you'll get 48 useless ttyS* nodes, of which only the first 32 will ever be available for real hardware.
If you look at uevents from 8250 when the designware ports are discovered, you'll see a DELETE of the built-in ttyS0 first, and then an ADD of the designware ttyS0. My understanding is that we should never have had that built-in ttyS0 in the first place?
Quoted 5 lines
The code which makes this "wrong behavior" to happen is the last loop in
serial8250_find_match_or_unused(). Given its comment, I think it has been very much intentional behavior. Pretending that non-discoverable port is more real/precious than a port that was later _discovered_ and is very much a real one is what brings you to this renumbering issue.
The serial8250_find_match_or_unused() logic exists to relate non-discoverable ports to those discovered later through ACPI PNP. Some of my systems announces those built-in ports with ACPI, in which case the discovered ports are assigned to their "built-in" numbers.
I believe all systems running today announce these built-in ports through ACPI PNP, but they are still usable as early consoles, so this special logic is still needed?
Quoted 3 lines
I'm not anymore sure about your goals really. Now it sounds one of the goals is preserving the non-discoverable ports, whereas previously it was just about allowing 0 of them.
My initial goal was to rely on discoverable ports only. Some of our systems have no built-in uarts, so the bash init script failed to even start, because the kernel command line had console=ttyS0, and bash tried to do set terminal attributes on it. I am only trying to fix the code "the right way", but that might not be possible without breaking numbering fo existing systems.
Quoted 6 lines
How about you add entirely new CONFIG and/or param for this minimum number of non-discoverable ports and make the last resort loop (or perhaps all but the first loop) in
serial8250_find_match_or_unused()to honor that (start looking only from port above that index). If it defaults to 0, I think this renumbering issue is avoided. Would it work for all the goals you have?
That would work for me. But shouldn't we clean up the SERIAL_8250_NR_UARTS vs. SERIAL_8250_RUNTIME_UARTS also?
Re: [PATCH v3 3/4] serial: 8250: skip platform device registration with no runtime ports
Quoted 65 lines · Martin Hundebøll
Quoted 58 lines · Ilpo Järvinen
Quoted 51 lines · Martin Hundebøll
Quoted 39 lines · Ilpo Järvinen
Quoted 5 lines · Ilpo Järvinen
=0 did work as expected due to this change which I tested and some other
values >4 but there now seems to be problem of the console not showing up
like previously when I don't givenr_uartsat all.NAK from me until the problem is resolved adequately.
Already the patch 1/4 causes an unacceptable reassignment of ttySx targets. This is going to break people's cmdline console setups so you need to find a better way.
Before any of these patches:
[ 0.000000] Command line: console=ttyS0,115200n8 8250.nr_uarts=4 [ 0.021031] Kernel command line: console=ttyS0,115200n8 8250.nr_uarts=4 [ 0.441924] printk: console [ttyS0] enabled [ 2.243165] printk: console [ttyS0] disabled [ 2.245682] dw-apb-uart.6: ttyS0 at MMIO 0x4010006000 (irq = 33, base_baud = 115200) is a 16550A [ 4.010237] printk: console [ttyS0] enabled [ 5.933887] dw-apb-uart.7: ttyS1 at MMIO 0x4010007000 (irq = 16, base_baud = 6250000) is a 16550A [ 5.952829] dw-apb-uart.8: ttyS2 at MMIO 0x4010008000 (irq = 17,
base_baud= 6250000) is a 16550AAfter 1/4 ttyS0 is no longer the same:
[ 0.000000] Command line: console=ttyS0,115200n8 8250.nr_uarts=4 [ 0.021023] Kernel command line: console=ttyS0,115200n8 8250.nr_uarts=4 [ 0.441872] printk: console [ttyS0] enabled [ 2.233584] dw-apb-uart.6: ttyS4 at MMIO 0x4010006000 (irq = 33, base_baud = 115200) is a 16550A [ 2.241955] dw-apb-uart.7: ttyS5 at MMIO 0x4010007000 (irq = 16, base_baud = 6250000) is a 16550A [ 2.249804] dw-apb-uart.8: ttyS6 at MMIO 0x4010008000 (irq = 17,Quoted 1 line
base_baud= 6250000) is a 16550AThanks for testing this.
The old behavior is wrong: your designware ports replace the built-in ones (0
to 3) instead of using the unused ones (4 to 31). With these patches, it acts
as I'd expect: the built-in ports are kept, and any later discovered ports follow.Quoted 5 lines
Yes, breaking existing systems in this way is unacceptable. I'm not sure how
to approach this, but I'm inclined to introduce a new config variable to keep
the broken behavior?Quoted 5 lines
To me this looks now more an attempt to repurpose the
nr_uartsto mean something it really hasn't. Clearly it hasn't meant non-discoverable ports earlier but something related to the maximum number ports. This also explains why we had that misunderstanding about the meaning ofnr_uartsbetween us earlier.
Quoted 8 lines
I was confused about the relation between
SERIAL_8250_NR_UARTSandSERIAL_8250_RUNTIME_UARTS, and started digging through the code. The description ofNR_UARTSclearly states that it controls the number of *supported* uarts, but I found that it was in fact controlled byRUNTIME_UARTS(8250.nr_uarts).With the current behavior, ever setting
NR_UARTSto anything different fromRUNTIME_UARTSmakes no sense, since the code only loops untilRUNTIME_UARTS.
One is there to size the array (max you can have with a particular build of a kernel ever). The other is to control the maximum number of ports per boot. I'd guess the former is there mainly for legacy reason from the era when memory really was scarser resource than it is today.
Quoted 5 lines
Both Arch Linux and Fedora have come to the same conclusion, since they set both configs to 32. So now I have 32 useless
/dev/ttyS*nodes on my laptop. If you run ubuntu on a machine with no uart hardware attached, you'll get 48 useless ttyS* nodes, of which only the first 32 will ever be available for real hardware.
Why load the driver then at all, if there's no need/hw for it? Ironically, setting nr_uarts (as it is) to a smaller value would reduce that waste and in case of =0 the driver wouldn't be loaded.
I know distros will do it but that's their policy decision that doesn't really belong here. If there's hw/need for any users of a distro, they provide the support in the most generic way that makes things easy for them/users, that is, by having sufficient number of ports for (almost) all usecases.
In addition, to me n useless ports just sitting there doesn't sound that serious issue that it would warrant breaking setups that currently depend on certain ttyS numbers (I suppose you actually agree with this point).
Quoted 4 lines
If you look at uevents from 8250 when the designware ports are discovered, you'll see a DELETE of the built-in ttyS0 first, and then an ADD of the designware ttyS0. My understanding is that we should never have had that built-in ttyS0 in the first place?
I certainly suspect the built-in one really isn't there (in ACPI) but I don't want to spend my time on confirming the obvious.
Quoted 6 lines
Quoted 5 lines
The code which makes this "wrong behavior" to happen is the last loop in
serial8250_find_match_or_unused(). Given its comment, I think it has been very much intentional behavior. Pretending that non-discoverable port is more real/precious than a port that was later _discovered_ and is very much a real one is what brings you to this renumbering issue.
Quoted 8 lines
The
serial8250_find_match_or_unused()logic exists to relate non-discoverable ports to those discovered later through ACPI PNP. Some of my systems announces those built-in ports with ACPI, in which case the discovered ports are assigned to their "built-in" numbers.I believe all systems running today announce these built-in ports through ACPI PNP, but they are still usable as early consoles, so this special logic is still needed?
Unfortunately, I don't know the answer to whether it is a safe assumption or not.
Quoted 9 lines
Quoted 3 lines
I'm not anymore sure about your goals really. Now it sounds one of the goals is preserving the non-discoverable ports, whereas previously it was just about allowing 0 of them.
My initial goal was to rely on discoverable ports only. Some of our systems have no built-in uarts, so the bash init script failed to even start, because the kernel command line had console=ttyS0, and bash tried to do set terminal attributes on it. I am only trying to fix the code "the right way", but that might not be possible without breaking numbering fo existing systems.
Again I don't follow the reasoning fully here. What is your end goal here in this scenario. You'd either want to have no ports to appear at all or have a non-discoverable (=bogus) port as ttyS0. Which way it is?
If you, on the other hand, would have a discoverable port that will take over ttyS0, I don't understand why it fails so it seemingly leaves only those two options I gave.
Quoted 9 lines
Quoted 6 lines
How about you add entirely new CONFIG and/or param for this minimum number of non-discoverable ports and make the last resort loop (or perhaps all but the first loop) in
serial8250_find_match_or_unused()to honor that (start looking only from port above that index). If it defaults to 0, I think this renumbering issue is avoided. Would it work for all the goals you have?That would work for me. But shouldn't we clean up the
SERIAL_8250_NR_UARTSvs.SERIAL_8250_RUNTIME_UARTSalso?
I'm not convinced there's something wrong with it. It's legacy yes, but the max ports compiled in vs max ports per boot is not wrong/buggy as is.
Signature · 1 line
i.
Re: [PATCH v3 3/4] serial: 8250: skip platform device registration with no runtime ports
Quoted 72 lines · Ilpo Järvinen
Quoted 71 lines · Martin Hundebøll
Quoted 58 lines · Ilpo Järvinen
Quoted 51 lines · Martin Hundebøll
Quoted 39 lines · Ilpo Järvinen
Quoted 5 lines · Ilpo Järvinen
=0 did work as expected due to this change which I tested and some other
values >4 but there now seems to be problem of the console not showing up
like previously when I don't givenr_uartsat all.NAK from me until the problem is resolved adequately.
Already the patch 1/4 causes an unacceptable reassignment of ttySx targets. This is going to break people's cmdline console setups so you need to find a better way.
Before any of these patches:
[ 0.000000] Command line: console=ttyS0,115200n8 8250.nr_uarts=4 [ 0.021031] Kernel command line: console=ttyS0,115200n8 8250.nr_uarts=4 [ 0.441924] printk: console [ttyS0] enabled [ 2.243165] printk: console [ttyS0] disabled [ 2.245682] dw-apb-uart.6: ttyS0 at MMIO 0x4010006000 (irq = 33, base_baud = 115200) is a 16550A [ 4.010237] printk: console [ttyS0] enabled [ 5.933887] dw-apb-uart.7: ttyS1 at MMIO 0x4010007000 (irq = 16, base_baud = 6250000) is a 16550A [ 5.952829] dw-apb-uart.8: ttyS2 at MMIO 0x4010008000 (irq = 17,
base_baud= 6250000) is a 16550AAfter 1/4 ttyS0 is no longer the same:
[ 0.000000] Command line: console=ttyS0,115200n8 8250.nr_uarts=4 [ 0.021023] Kernel command line: console=ttyS0,115200n8 8250.nr_uarts=4 [ 0.441872] printk: console [ttyS0] enabled [ 2.233584] dw-apb-uart.6: ttyS4 at MMIO 0x4010006000 (irq = 33, base_baud = 115200) is a 16550A [ 2.241955] dw-apb-uart.7: ttyS5 at MMIO 0x4010007000 (irq = 16, base_baud = 6250000) is a 16550A [ 2.249804] dw-apb-uart.8: ttyS6 at MMIO 0x4010008000 (irq = 17,Quoted 1 line
base_baud= 6250000) is a 16550AThanks for testing this.
The old behavior is wrong: your designware ports replace the built-in ones (0
to 3) instead of using the unused ones (4 to 31). With these patches, it acts
as I'd expect: the built-in ports are kept, and any later discovered ports follow.Quoted 5 lines
Yes, breaking existing systems in this way is unacceptable. I'm not sure how
to approach this, but I'm inclined to introduce a new config variable to keep
the broken behavior?Quoted 5 lines
To me this looks now more an attempt to repurpose the
nr_uartsto mean something it really hasn't. Clearly it hasn't meant non-discoverable ports earlier but something related to the maximum number ports. This also explains why we had that misunderstanding about the meaning ofnr_uartsbetween us earlier.I was confused about the relation between
SERIAL_8250_NR_UARTSandSERIAL_8250_RUNTIME_UARTS, and started digging through the code. The description ofNR_UARTSclearly states that it controls the number of *supported* uarts, but I found that it was in fact controlled byRUNTIME_UARTS(8250.nr_uarts).
Quoted 7 lines
Quoted 2 lines
With the current behavior, ever setting
NR_UARTSto anything different fromRUNTIME_UARTSmakes no sense, since the code only loops untilRUNTIME_UARTS.One is there to size the array (max you can have with a particular build of a kernel ever). The other is to control the maximum number of ports per boot. I'd guess the former is there mainly for legacy reason from the era when memory really was scarser resource than it is today.
Oh, I see.
Quoted 9 lines
Quoted 5 lines
Both Arch Linux and Fedora have come to the same conclusion, since they set both configs to 32. So now I have 32 useless
/dev/ttyS*nodes on my laptop. If you run ubuntu on a machine with no uart hardware attached, you'll get 48 useless ttyS* nodes, of which only the first 32 will ever be available for real hardware.Why load the driver then at all, if there's no need/hw for it? Ironically, setting
nr_uarts(as it is) to a smaller value would reduce that waste and in case of =0 the driver wouldn't be loaded.
We have some PCIe attached UARTs that doesn't appear until after the system is up and running (they sit behind an FPGA controlled from userspace.) Some revisions have built-in UARTs while others don't, and I would like to run the same kernel, rootfs, and boot configuration on all of them.
Quoted 9 lines
I know distros will do it but that's their policy decision that doesn't really belong here. If there's hw/need for any users of a distro, they provide the support in the most generic way that makes things easy for them/users, that is, by having sufficient number of ports for (almost) all usecases.
In addition, to me n useless ports just sitting there doesn't sound that serious issue that it would warrant breaking setups that currently depend on certain ttyS numbers (I suppose you actually agree with this point).
Agreed. Although we have seen races between the DELETE and ADD uevents mentioned below, leading to non-deterministical device numbers.
Quoted 7 lines
Quoted 4 lines
If you look at uevents from 8250 when the designware ports are discovered, you'll see a DELETE of the built-in ttyS0 first, and then an ADD of the designware ttyS0. My understanding is that we should never have had that built-in ttyS0 in the first place?
I certainly suspect the built-in one really isn't there (in ACPI) but I don't want to spend my time on confirming the obvious.
From a system booted with these patches, and 8250.nr_uarts=0, I get two ports from ACPI PNP:
# cat /sys/class/tty/ttyS0/port 0x3F8 # cat /sys/class/tty/ttyS1/port 0x2F8
which matches the SERIAL_PORT_DNFS define in arch/x86/include/asm/serial.h
Quoted 28 lines
Quoted 6 lines
Quoted 5 lines
The code which makes this "wrong behavior" to happen is the last loop in
serial8250_find_match_or_unused(). Given its comment, I think it has been very much intentional behavior. Pretending that non-discoverable port is more real/precious than a port that was later _discovered_ and is very much a real one is what brings you to this renumbering issue.Quoted 8 lines
The
serial8250_find_match_or_unused()logic exists to relate non-discoverable ports to those discovered later through ACPI PNP. Some of my systems announces those built-in ports with ACPI, in which case the discovered ports are assigned to their "built-in" numbers.I believe all systems running today announce these built-in ports through ACPI PNP, but they are still usable as early consoles, so this special logic is still needed?
Unfortunately, I don't know the answer to whether it is a safe assumption or not.
Quoted 9 lines
Quoted 3 lines
I'm not anymore sure about your goals really. Now it sounds one of the goals is preserving the non-discoverable ports, whereas previously it was just about allowing 0 of them.
My initial goal was to rely on discoverable ports only. Some of our systems have no built-in uarts, so the bash init script failed to even start, because the kernel command line had console=ttyS0, and bash tried to do set terminal attributes on it. I am only trying to fix the code "the right way", but that might not be possible without breaking numbering fo existing systems.
Quoted 7 lines
Again I don't follow the reasoning fully here. What is your end goal here in this scenario. You'd either want to have no ports to appear at all or have a non-discoverable (=bogus) port as ttyS0. Which way it is?
If you, on the other hand, would have a discoverable port that will take over ttyS0, I don't understand why it fails so it seemingly leaves only those two options I gave.
My endgoal is to avoid a bogus ttyS0, but a working driver (for the PCIe connected ports).
I still think it seems wrong to have non-working device nodes. They only confuse both people and software:
% sudo stty -F /dev/ttyS0
stty: /dev/ttyS0: Input/output error
Quoted 7 lines
Quoted 7 lines
Quoted 6 lines
How about you add entirely new CONFIG and/or param for this minimum number of non-discoverable ports and make the last resort loop (or perhaps all but the first loop) in
serial8250_find_match_or_unused()to honor that (start looking only from port above that index). If it defaults to 0, I think this renumbering issue is avoided. Would it work for all the goals you have?
Quoted 5 lines
Quoted 2 lines
That would work for me. But shouldn't we clean up the
SERIAL_8250_NR_UARTSvs.SERIAL_8250_RUNTIME_UARTSalso?I'm not convinced there's something wrong with it. It's legacy yes, but the max ports compiled in vs max ports per boot is not wrong/buggy as is.
Your interpretation of those two makes sense, but I don't really see a usecase for setting 8250.nr_uarts at boot time though.
// Martin
Re: [PATCH v3 3/4] serial: 8250: skip platform device registration with no runtime ports
Quoted 9 lines · Martin Hundebøll
Quoted 5 lines · Ilpo Järvinen
On Tue, 1 Nov 2022, Martin Hundebøll wrote:
In addition, to me n useless ports just sitting there doesn't sound that serious issue that it would warrant breaking setups that currently depend on certain ttyS numbers (I suppose you actually agree with this point).
Agreed. Although we have seen races between the DELETE and ADD uevents mentioned below, leading to non-deterministical device numbers.
No doubt there will be cases were the numbering is not as stable as we'd like but it seems an unrelated issue.
Quoted 9 lines
Quoted 9 lines
Quoted 4 lines
If you look at uevents from 8250 when the designware ports are discovered, you'll see a DELETE of the built-in ttyS0 first, and then an ADD of the designware ttyS0. My understanding is that we should never have had that built-in ttyS0 in the first place?
I certainly suspect the built-in one really isn't there (in ACPI) but I don't want to spend my time on confirming the obvious.
From a system booted with these patches, and 8250.nr_uarts=0, I get two
Quoted 8 lines
ports from ACPI PNP:
# cat /sys/class/tty/ttyS0/port 0x3F8 # cat /sys/class/tty/ttyS1/port 0x2F8which matches the
SERIAL_PORT_DNFSdefine inarch/x86/include/asm/serial.h
I was talking about the system I was testing with.
Quoted 18 lines
Quoted 10 lines
Quoted 9 lines
Quoted 3 lines
I'm not anymore sure about your goals really. Now it sounds one of the goals is preserving the non-discoverable ports, whereas previously it was just about allowing 0 of them.
My initial goal was to rely on discoverable ports only. Some of our systems have no built-in uarts, so the bash init script failed to even start, because the kernel command line had console=ttyS0, and bash tried to do set terminal attributes on it. I am only trying to fix the code "the right way", but that might not be possible without breaking numbering fo existing systems.
Quoted 7 lines
Again I don't follow the reasoning fully here. What is your end goal here in this scenario. You'd either want to have no ports to appear at all or have a non-discoverable (=bogus) port as ttyS0. Which way it is?
If you, on the other hand, would have a discoverable port that will take over ttyS0, I don't understand why it fails so it seemingly leaves only those two options I gave.
Quoted 8 lines
My endgoal is to avoid a bogus ttyS0, but a working driver (for the PCIe connected ports).
I still think it seems wrong to have non-working device nodes. They only confuse both people and software:
% sudo stty -F
/dev/ttyS0
stty:/dev/ttyS0: Input/output error
So simply add the maximum number of non-discoverable ports? Something which isn't reusing nr_uarts or its related CONFIG, and pick such a default which doesn't break existing cmdlines.
Quoted 8 lines
Quoted 5 lines
Quoted 2 lines
That would work for me. But shouldn't we clean up the
SERIAL_8250_NR_UARTSvs.SERIAL_8250_RUNTIME_UARTSalso?I'm not convinced there's something wrong with it. It's legacy yes, but the max ports compiled in vs max ports per boot is not wrong/buggy as is.
Your interpretation of those two makes sense, but I don't really see a usecase for setting 8250.nr_uarts at boot time though.
You might not but we shouldn't change it to mean something else.
Signature · 1 line
i.
PATCH v3 4/4 tty: 8250: update description of RUNTIME_PORTS / nr_uarts
In reply to Martin HundebøllThe 8250 module has been updated allow configurations with zero builtin UART ports, so change the description of the parameter to reflect that.
---
Change since v2:
* new patch
drivers/tty/serial/8250/8250_core.c | 3 ++- drivers/tty/serial/8250/Kconfig | 10 +++++----- 2 files changed, 7 insertions(+), 6 deletions(-)
drivers/tty/serial/8250/8250_core.c +2 -1
@@ -1257,7 +1257,8 @@ module_param_hw(share_irqs, uint, other, 0644);MODULE_PARM_DESC (share_irqs,"Share IRQs with other non-8250/16x50 devices (unsafe)" );module_param (nr_uarts, uint,0644 ); -MODULE_PARM_DESC(nr_uarts, "Maximum number of UARTs supported. (1-" __MODULE_STRING(CONFIG_SERIAL_8250_NR_UARTS) ")"); +MODULE_PARM_DESC(nr_uarts, "Number of built-in (non-discoverable) UARTs to initialize. (1-" + _MODULE_STRING(CONFIG_SERIAL_8250_NR_UARTS) ")");module_param (skip_txen_test, uint,0644 );MODULE_PARM_DESC (skip_txen_test,"Skip checking for the TXEN bug at init time" );
drivers/tty/serial/8250/Kconfig +5 -5
@@ -191,15 +191,15 @@ config SERIAL_8250_NR_UARTS via hot-plug, or any ISA multi-port serial cards. config SERIAL_8250_RUNTIME_UARTS - int "Number of 8250/16550 serial ports to register at runtime" + int "Number of built-in (non-discoverable) UARTs to initialize at boot time" depends on SERIAL_8250 range 0 SERIAL_8250_NR_UARTS default "4" help - Set this to the maximum number of serial ports you want - the kernel to register at boot time. This can be overridden - with the module parameter "nr_uarts", or boot-time parameter - 8250.nr_uarts + Set this to the maximum number of built-in (non-discoverable) serial + ports you want the kernel to initialize at boot time. This can be + overridden with the module parameter "nr_uarts", or boot-time + parameter 8250.nr_uarts config SERIAL_8250_EXTENDED bool "Extended 8250/16550 serial driver options"
Signature · 1 line
2.38.1
Re: [PATCH v3 4/4] tty: 8250: update description of RUNTIME_PORTS / nr_uarts
Quoted 18 lines · Martin Hundebøll
The 8250 module has been updated allow configurations with zero builtin UART ports, so change the description of the parameter to reflect that.
Signed-off-by Martin Hundebøll <[email protected]>---
Change since v2:
* new patchdrivers/tty/serial/8250/8250_core.c | 3 ++- drivers/tty/serial/8250/Kconfig | 10 +++++----- 2 files changed, 7 insertions(+), 6 deletions(-)drivers/tty/serial/8250/8250_core.c +0
-0
drivers/tty/serial/8250/8250_core.c module_param_hw(share_irqs, uint, other, 0644); · line 1261
Quoted 6 lines
drivers/tty/serial/8250/8250_core.c +2
-1@@ -1257,7 +1257,8 @@ module_param_hw(share_irqs, uint, other, 0644);MODULE_PARM_DESC (share_irqs,"Share IRQs with other non-8250/16x50 devices (unsafe)" );module_param (nr_uarts, uint,0644 ); -MODULE_PARM_DESC(nr_uarts, "Maximum number of UARTs supported. (1-" __MODULE_STRING(CONFIG_SERIAL_8250_NR_UARTS) ")"); +MODULE_PARM_DESC(nr_uarts, "Number of built-in (non-discoverable) UARTs to initialize. (1-" + _MODULE_STRING(CONFIG_SERIAL_8250_NR_UARTS) ")");
This fails to build. You have dropped the second underscore for some reason.
Shouldn't that 1- be also changed to 0- ?
Signature · 1 line
i.
Quoted 29 lines
drivers/tty/serial/8250/8250_core.c +0
-0module_param (skip_txen_test, uint,0644 );MODULE_PARM_DESC (skip_txen_test,"Skip checking for the TXEN bug at init time" );drivers/tty/serial/8250/Kconfig +5
-5@@ -191,15 +191,15 @@ config SERIAL_8250_NR_UARTS via hot-plug, or any ISA multi-port serial cards. config SERIAL_8250_RUNTIME_UARTS - int "Number of 8250/16550 serial ports to register at runtime" + int "Number of built-in (non-discoverable) UARTs to initialize at boot time" depends on SERIAL_8250 range 0 SERIAL_8250_NR_UARTS default "4" help - Set this to the maximum number of serial ports you want - the kernel to register at boot time. This can be overridden - with the module parameter "nr_uarts", or boot-time parameter - 8250.nr_uarts + Set this to the maximum number of built-in (non-discoverable) serial + ports you want the kernel to initialize at boot time. This can be + overridden with the module parameter "nr_uarts", or boot-time + parameter 8250.nr_uarts config SERIAL_8250_EXTENDED bool "Extended 8250/16550 serial driver options"
Re: [PATCH v3 4/4] tty: 8250: update description of RUNTIME_PORTS / nr_uarts
Quoted 22 lines · Ilpo Järvinen
Quoted 20 lines · Martin Hundebøll
The 8250 module has been updated allow configurations with zero builtin UART ports, so change the description of the parameter to reflect that.
Signed-off-by Martin Hundebøll<[email protected]>---
Change since v2:
* new patchdrivers/tty/serial/8250/8250_core.c | 3 ++- drivers/tty/serial/8250/Kconfig | 10 +++++----- 2 files changed, 7 insertions(+), 6 deletions(-)drivers/tty/serial/8250/8250_core.c +0
-0@@ -1257,7 +1257,8 @@ module_param_hw(share_irqs, uint, other, 0644);MODULE_PARM_DESC (share_irqs,"Share IRQs with other non-8250/16x50 devices (unsafe)" );
Quoted 6 lines
drivers/tty/serial/8250/8250_core.c module_param_hw(share_irqs, uint, other, 0644); · line 1261
Quoted 4 lines
drivers/tty/serial/8250/8250_core.c +2
-1module_param (nr_uarts, uint,0644 ); -MODULE_PARM_DESC(nr_uarts, "Maximum number of UARTs supported. (1-" __MODULE_STRING(CONFIG_SERIAL_8250_NR_UARTS) ")"); +MODULE_PARM_DESC(nr_uarts, "Number of built-in (non-discoverable) UARTs to initialize. (1-" + _MODULE_STRING(CONFIG_SERIAL_8250_NR_UARTS) ")");This fails to build. You have dropped the second underscore for some reason.
Running checkpatch after make is dangerous...
Quoted 1 line
Shouldn't that 1- be also changed to 0- ?
Correct. In fact, it should be 0 - ARRAY_SIZE(old_serial_port) - 1.
// Martin