Skip to contentSkip to conversation

netconsole: various improvements

PATCH Superseded Tony Dinh 3 participants 7 messages Mar 18, 2023 – Mar 20, 2023

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Tony Dinh

author
#0 lore raw

PATCH 1/1 netconsole: various improvements

- When Netconsole is running, stdin/stdout/stderr are set to nc. Reset stdin/stdout/stderr to serial (a sane deffault) before booting kernel.
- Enable net_timeout when netconsole starts will give a better user experience if netconsole server is not running.

---

 boot/bootm.c             | 16 +++++++++++++++-
 drivers/net/netconsole.c |  2 +-
 2 files changed, 16 insertions(+), 2 deletions(-)
boot/bootm.c +15 -1
index 2eec60ec7b..c4a3aaf1bd 100644
@@ -473,7 +473,21 @@ ulong bootm_disable_interrupts(void)
 	 */
 	iflag = disable_interrupts();
 #ifdef CONFIG_NETCONSOLE
-	/* Stop the ethernet stack if NetConsole could have left it up */
+	/*
+	 * Make sure that the starting kernel message printed out.
+	 * Reset stdin/out/err back to serial and stop the ethernet
+	 * stack if NetConsole could have left it up
+	 */
+	char *s;
+	int ret;
+
+	s = env_get("stdout");
+	if (strcmp(s, "nc") == 0) {
+		printf("\n\nStarting kernel ...\n");
+		ret = env_set("stdin", "serial");
+		ret = env_set("stdout", "serial");
+		ret = env_set("stderr", "serial");
+	}
 	eth_halt();
 #endif
 
drivers/net/netconsole.c +1 -1
index 151bc55e07..2091014918 100644
@@ -20,7 +20,7 @@ static int input_size; /* char count in input buffer */
 static int input_offset; /* offset to valid chars in input buffer */
 static int input_recursion;
 static int output_recursion;
-static int net_timeout;
+static int net_timeout = 1;
 static uchar nc_ether[6]; /* server enet address */
 static struct in_addr nc_ip; /* server ip */
 static short nc_out_port; /* target output port */
Signature · 1 line
2.30.2
#1 lore raw

Hi Tony,

Quoted 3 lines · Tony Dinh

- When Netconsole is running, stdin/stdout/stderr are set to nc. Reset stdin/stdout/stderr to serial (a sane deffault) before booting kernel.

spelling

Quoted 15 lines

- Enable net_timeout when netconsole starts will give a better user experience if netconsole server is not running.

---

 boot/bootm.c             | 16 +++++++++++++++-
 drivers/net/netconsole.c |  2 +-
 2 files changed, 16 insertions(+), 2 deletions(-)
boot/bootm.c +0 -0
index 2eec60ec7b..c4a3aaf1bd 100644

boot/bootm.c ulong bootm_disable_interrupts(void) · line 475

Quoted 3 lines
boot/bootm.c +0 -0
@@ -473,7 +473,21 @@ ulong bootm_disable_interrupts(void)
         */
        iflag = disable_interrupts();
 #ifdef CONFIG_NETCONSOLE

Can you convert this to 'if IS_ENABLED(...)' at the same time?

Quoted 24 lines
boot/bootm.c +15 -1
-       /* Stop the ethernet stack if NetConsole could have left it up */
+       /*
+        * Make sure that the starting kernel message printed out.
+        * Reset stdin/out/err back to serial and stop the ethernet
+        * stack if NetConsole could have left it up
+        */
+       char *s;
+       int ret;
+
+       s = env_get("stdout");
+       if (strcmp(s, "nc") == 0) {
+               printf("\n\nStarting kernel ...\n");
+               ret = env_set("stdin", "serial");
+               ret = env_set("stdout", "serial");
+               ret = env_set("stderr", "serial");
+       }
        eth_halt();
 #endif
 
drivers/net/netconsole.c +0 -0
index 151bc55e07..2091014918 100644

drivers/net/netconsole.c static int input_size; /* char count in input buffer */ · line 23

Quoted 5 lines
drivers/net/netconsole.c +1 -1
@@ -20,7 +20,7 @@ static int input_size; /* char count in input buffer */
 static int input_offset; /* offset to valid chars in input buffer */
 static int input_recursion;
 static int output_recursion;
-static int net_timeout;
+static int net_timeout = 1;

What is this change?

Quoted 6 lines
drivers/net/netconsole.c +0 -1
 static uchar nc_ether[6]; /* server enet address */
 static struct in_addr nc_ip; /* server ip */
 static short nc_out_port; /* target output port */
--

2.30.2

Could you take a look at converting netconsole to driver model? It should be a child of the eth device probably. I think this patch is OK for, but it would be better if the driver could deregister itself from stdio in its remove() method, perhaps installing serial at that point.

Regards,
SImon

author
#2 lore raw

Hi Simon,

Quoted 9 lines · Simon Glass

Hi Tony,

Quoted 3 lines · Tony Dinh

- When Netconsole is running, stdin/stdout/stderr are set to nc. Reset stdin/stdout/stderr to serial (a sane deffault) before booting kernel.

spelling

OK.

Quoted 11 lines
Quoted 11 lines

- Enable net_timeout when netconsole starts will give a better user experience if netconsole server is not running.

---

 boot/bootm.c             | 16 +++++++++++++++-
 drivers/net/netconsole.c |  2 +-
 2 files changed, 16 insertions(+), 2 deletions(-)
Quoted 10 lines

boot/bootm.c ulong bootm_disable_interrupts(void) · line 475

Quoted 8 lines
boot/bootm.c +0 -0
index 2eec60ec7b..c4a3aaf1bd 100644
@@ -473,7 +473,21 @@ ulong bootm_disable_interrupts(void)
         */
        iflag = disable_interrupts();
 #ifdef CONFIG_NETCONSOLE

Can you convert this to 'if IS_ENABLED(...)' at the same time?

Sure I will.

Quoted 20 lines
Quoted 20 lines
boot/bootm.c +15 -1
-       /* Stop the ethernet stack if NetConsole could have left it up */
+       /*
+        * Make sure that the starting kernel message printed out.
+        * Reset stdin/out/err back to serial and stop the ethernet
+        * stack if NetConsole could have left it up
+        */
+       char *s;
+       int ret;
+
+       s = env_get("stdout");
+       if (strcmp(s, "nc") == 0) {
+               printf("\n\nStarting kernel ...\n");
+               ret = env_set("stdin", "serial");
+               ret = env_set("stdout", "serial");
+               ret = env_set("stderr", "serial");
+       }
        eth_halt();
 #endif
 
Quoted 12 lines

drivers/net/netconsole.c static int input_size; /* char count in input buffer */ · line 23

Quoted 10 lines
drivers/net/netconsole.c +1 -1
index 151bc55e07..2091014918 100644
@@ -20,7 +20,7 @@ static int input_size; /* char count in input buffer */
 static int input_offset; /* offset to valid chars in input buffer */
 static int input_recursion;
 static int output_recursion;
-static int net_timeout;
+static int net_timeout = 1;

What is this change?

I've been carrying this one-line patch out-of-tree for a few years. Back when I saw that the netconsole started transitioning faster from the serial console (I tested with 2 consoles running) . But I can no longer prove that anymore! code change... I think it does not hurt to set it to timeout initially anyway, since netconsole is polling for chars. But I will remove this part of the patch if others think it is not necessary.

Quoted 8 lines
Quoted 7 lines
drivers/net/netconsole.c +0 -1
 static uchar nc_ether[6]; /* server enet address */
 static struct in_addr nc_ip; /* server ip */
 static short nc_out_port; /* target output port */
--

2.30.2

Quoted 4 lines

Could you take a look at converting netconsole to driver model? It should be a child of the eth device probably. I think this patch is OK for, but it would be better if the driver could deregister itself from stdio in its remove() method, perhaps installing serial at that point.

Agreed. It would be nice to have netconsole as a driver model. It will get more attention that it deserves. I'm a bit short for free time atm, though. I will make it a task to work on it.

Thanks,
Tony

Quoted 2 lines

Regards,
SImon

#3 lore raw
In reply to Tony Dinh
Quoted 2 lines · On Saturday 18 March 2023 14:46:25 Tony Dinh wrote:

- When Netconsole is running, stdin/stdout/stderr are set to nc. Reset stdin/stdout/stderr to serial (a sane deffault) before booting kernel.

This can be a problematic. serial output does not have to be available for all devices. For example on Nokia N900 phone is available only lcd/vga display device.

Also this can break CONSOLE_MUX support when more devices are specified in stdin/stdout/stderr env variables. With CONSOLE_MUX, output is send to more than one device. User may set it to both serial and nc or also to other output (e.g. to lcd like on Nokia N900).

So in my opinion, if "nc" is is going to be turned off then just "nc" string should be removed from env variable and let all other devices stay in env variables.

Maybe you can use something like this? (taken from common/usb_kbd.c)

#if CONFIG_IS_ENABLED(CONSOLE_MUX)
	if (iomux_replace_device(stdin, "nc", "nulldev"))
		return 1;

#endif

Quoted 53 lines

- Enable net_timeout when netconsole starts will give a better user experience if netconsole server is not running.

---

 boot/bootm.c             | 16 +++++++++++++++-
 drivers/net/netconsole.c |  2 +-
 2 files changed, 16 insertions(+), 2 deletions(-)
boot/bootm.c +15 -1
index 2eec60ec7b..c4a3aaf1bd 100644
@@ -473,7 +473,21 @@ ulong bootm_disable_interrupts(void)
 	 */
 	iflag = disable_interrupts();
 #ifdef CONFIG_NETCONSOLE
-	/* Stop the ethernet stack if NetConsole could have left it up */
+	/*
+	 * Make sure that the starting kernel message printed out.
+	 * Reset stdin/out/err back to serial and stop the ethernet
+	 * stack if NetConsole could have left it up
+	 */
+	char *s;
+	int ret;
+
+	s = env_get("stdout");
+	if (strcmp(s, "nc") == 0) {
+		printf("\n\nStarting kernel ...\n");
+		ret = env_set("stdin", "serial");
+		ret = env_set("stdout", "serial");
+		ret = env_set("stderr", "serial");
+	}
 	eth_halt();
 #endif
 
drivers/net/netconsole.c +1 -1
index 151bc55e07..2091014918 100644
@@ -20,7 +20,7 @@ static int input_size; /* char count in input buffer */
 static int input_offset; /* offset to valid chars in input buffer */
 static int input_recursion;
 static int output_recursion;
-static int net_timeout;
+static int net_timeout = 1;
 static uchar nc_ether[6]; /* server enet address */
 static struct in_addr nc_ip; /* server ip */
 static short nc_out_port; /* target output port */
Signature · 1 line
2.30.2
author
#4 lore raw

Hi Pali,

Quoted 8 lines · Pali Rohár
Quoted 2 lines · On Saturday 18 March 2023 14:46:25 Tony Dinh wrote:

- When Netconsole is running, stdin/stdout/stderr are set to nc. Reset stdin/stdout/stderr to serial (a sane deffault) before booting kernel.

This can be a problematic. serial output does not have to be available for all devices. For example on Nokia N900 phone is available only lcd/vga display device.

Here is a shortcoming of the current implementation of netconsole. When it starts, the user sets the stdin/stdout/stderr envs to nc, and we lose the previous state of the console. Especially with the CONSOLE_MUX is not enabled. There is no way to set them back by setting the envs in booting logic.

It sounds like we need to implement internal envs to save the previous state, and then restore it before shutting down the network and booting the kernel.
I recall in previous Linux kernel versions many years ago Linux still booted OK, but recently it can no longer boot with the stdio set to nc (I've tested this failure case). Perhaps nc should _not_ be set explicitly by the user. We might need a u-boot command to start netconsole, and that would include checking if the serverip is running?

Quoted 10 lines

Also this can break CONSOLE_MUX support when more devices are specified in stdin/stdout/stderr env variables. With CONSOLE_MUX, output is send to more than one device. User may set it to both serial and nc or also to other output (e.g. to lcd like on Nokia N900).

So in my opinion, if "nc" is is going to be turned off then just "nc" string should be removed from env variable and let all other devices stay in env variables.

Quoted 6 lines

Maybe you can use something like this? (taken from common/usb_kbd.c)

#if CONFIG_IS_ENABLED(CONSOLE_MUX)
if (iomux_replace_device(stdin, "nc", "nulldev"))
return 1;
#endif

Thanks for pointing out that fact about CONSOLE_MUX. Yes I will incorporate that as part of the logic.

All the best,
Tony

Quoted 54 lines
Quoted 54 lines

- Enable net_timeout when netconsole starts will give a better user experience if netconsole server is not running.

---

 boot/bootm.c             | 16 +++++++++++++++-
 drivers/net/netconsole.c |  2 +-
 2 files changed, 16 insertions(+), 2 deletions(-)
boot/bootm.c +15 -1
index 2eec60ec7b..c4a3aaf1bd 100644
@@ -473,7 +473,21 @@ ulong bootm_disable_interrupts(void)
       */
      iflag = disable_interrupts();
 #ifdef CONFIG_NETCONSOLE
-     /* Stop the ethernet stack if NetConsole could have left it up */
+     /*
+      * Make sure that the starting kernel message printed out.
+      * Reset stdin/out/err back to serial and stop the ethernet
+      * stack if NetConsole could have left it up
+      */
+     char *s;
+     int ret;
+
+     s = env_get("stdout");
+     if (strcmp(s, "nc") == 0) {
+             printf("\n\nStarting kernel ...\n");
+             ret = env_set("stdin", "serial");
+             ret = env_set("stdout", "serial");
+             ret = env_set("stderr", "serial");
+     }
      eth_halt();
 #endif
 
drivers/net/netconsole.c +1 -2
index 151bc55e07..2091014918 100644
@@ -20,7 +20,7 @@ static int input_size; /* char count in input buffer */
 static int input_offset; /* offset to valid chars in input buffer */
 static int input_recursion;
 static int output_recursion;
-static int net_timeout;
+static int net_timeout = 1;
 static uchar nc_ether[6]; /* server enet address */
 static struct in_addr nc_ip; /* server ip */
 static short nc_out_port; /* target output port */
--

2.30.2

#5 lore raw
Quoted 12 lines · On Sunday 19 March 2023 16:25:25 Tony Dinh wrote:

Hi Pali,

Quoted 8 lines · Pali Rohár
Quoted 2 lines · On Saturday 18 March 2023 14:46:25 Tony Dinh wrote:

- When Netconsole is running, stdin/stdout/stderr are set to nc. Reset stdin/stdout/stderr to serial (a sane deffault) before booting kernel.

This can be a problematic. serial output does not have to be available for all devices. For example on Nokia N900 phone is available only lcd/vga display device.

Quoted 5 lines

Here is a shortcoming of the current implementation of netconsole. When it starts, the user sets the stdin/stdout/stderr envs to nc, and we lose the previous state of the console. Especially with the CONSOLE_MUX is not enabled. There is no way to set them back by setting the envs in booting logic.

Cannot user use console mux and set stdout to both serial and nc at the same time?

Quoted 87 lines

It sounds like we need to implement internal envs to save the previous state, and then restore it before shutting down the network and booting the kernel.
I recall in previous Linux kernel versions many years ago Linux still booted OK, but recently it can no longer boot with the stdio set to nc (I've tested this failure case). Perhaps nc should _not_ be set explicitly by the user. We might need a u-boot command to start netconsole, and that would include checking if the serverip is running?

Quoted 10 lines

Also this can break CONSOLE_MUX support when more devices are specified in stdin/stdout/stderr env variables. With CONSOLE_MUX, output is send to more than one device. User may set it to both serial and nc or also to other output (e.g. to lcd like on Nokia N900).

So in my opinion, if "nc" is is going to be turned off then just "nc" string should be removed from env variable and let all other devices stay in env variables.

Quoted 6 lines

Maybe you can use something like this? (taken from common/usb_kbd.c)

#if CONFIG_IS_ENABLED(CONSOLE_MUX)
if (iomux_replace_device(stdin, "nc", "nulldev"))
return 1;
#endif

Thanks for pointing out that fact about CONSOLE_MUX. Yes I will incorporate that as part of the logic.

All the best,
Tony

Quoted 54 lines
Quoted 54 lines

- Enable net_timeout when netconsole starts will give a better user experience if netconsole server is not running.

---

 boot/bootm.c             | 16 +++++++++++++++-
 drivers/net/netconsole.c |  2 +-
 2 files changed, 16 insertions(+), 2 deletions(-)
boot/bootm.c +15 -1
index 2eec60ec7b..c4a3aaf1bd 100644
@@ -473,7 +473,21 @@ ulong bootm_disable_interrupts(void)
       */
      iflag = disable_interrupts();
 #ifdef CONFIG_NETCONSOLE
-     /* Stop the ethernet stack if NetConsole could have left it up */
+     /*
+      * Make sure that the starting kernel message printed out.
+      * Reset stdin/out/err back to serial and stop the ethernet
+      * stack if NetConsole could have left it up
+      */
+     char *s;
+     int ret;
+
+     s = env_get("stdout");
+     if (strcmp(s, "nc") == 0) {
+             printf("\n\nStarting kernel ...\n");
+             ret = env_set("stdin", "serial");
+             ret = env_set("stdout", "serial");
+             ret = env_set("stderr", "serial");
+     }
      eth_halt();
 #endif
 
drivers/net/netconsole.c +1 -2
index 151bc55e07..2091014918 100644
@@ -20,7 +20,7 @@ static int input_size; /* char count in input buffer */
 static int input_offset; /* offset to valid chars in input buffer */
 static int input_recursion;
 static int output_recursion;
-static int net_timeout;
+static int net_timeout = 1;
 static uchar nc_ether[6]; /* server enet address */
 static struct in_addr nc_ip; /* server ip */
 static short nc_out_port; /* target output port */
--

2.30.2

author
#6 lore raw

Hi Pali,

Quoted 14 lines · Pali Rohár
Quoted 12 lines · On Sunday 19 March 2023 16:25:25 Tony Dinh wrote:

Hi Pali,

Quoted 8 lines · Pali Rohár
Quoted 2 lines · On Saturday 18 March 2023 14:46:25 Tony Dinh wrote:

- When Netconsole is running, stdin/stdout/stderr are set to nc. Reset stdin/stdout/stderr to serial (a sane deffault) before booting kernel.

This can be a problematic. serial output does not have to be available for all devices. For example on Nokia N900 phone is available only lcd/vga display device.

Quoted 8 lines
Quoted 5 lines

Here is a shortcoming of the current implementation of netconsole. When it starts, the user sets the stdin/stdout/stderr envs to nc, and we lose the previous state of the console. Especially with the CONSOLE_MUX is not enabled. There is no way to set them back by setting the envs in booting logic.

Cannot user use console mux and set stdout to both serial and nc at the same time?

Agree, we can make that available. And a lot of existing boards out there are setting
"setenv ncip $serverip; setenv stdin nc; setenv stdout nc; setenv stderr nc;" We can say that with the new u-boot version, they have to upgrade their netconsole related envs.

I've seen too many users having trouble with netconsole, so I think perhaps a netconsole command performing the muxing and setting envs internally might be helpful.

Thanks,
Tony

Quoted 88 lines
Quoted 88 lines

It sounds like we need to implement internal envs to save the previous state, and then restore it before shutting down the network and booting the kernel.
I recall in previous Linux kernel versions many years ago Linux still booted OK, but recently it can no longer boot with the stdio set to nc (I've tested this failure case). Perhaps nc should _not_ be set explicitly by the user. We might need a u-boot command to start netconsole, and that would include checking if the serverip is running?

Quoted 10 lines

Also this can break CONSOLE_MUX support when more devices are specified in stdin/stdout/stderr env variables. With CONSOLE_MUX, output is send to more than one device. User may set it to both serial and nc or also to other output (e.g. to lcd like on Nokia N900).

So in my opinion, if "nc" is is going to be turned off then just "nc" string should be removed from env variable and let all other devices stay in env variables.

Quoted 6 lines

Maybe you can use something like this? (taken from common/usb_kbd.c)

#if CONFIG_IS_ENABLED(CONSOLE_MUX)
if (iomux_replace_device(stdin, "nc", "nulldev"))
return 1;
#endif

Thanks for pointing out that fact about CONSOLE_MUX. Yes I will incorporate that as part of the logic.

All the best,
Tony

Quoted 54 lines
Quoted 54 lines

- Enable net_timeout when netconsole starts will give a better user experience if netconsole server is not running.

---

 boot/bootm.c             | 16 +++++++++++++++-
 drivers/net/netconsole.c |  2 +-
 2 files changed, 16 insertions(+), 2 deletions(-)
boot/bootm.c +15 -1
index 2eec60ec7b..c4a3aaf1bd 100644
@@ -473,7 +473,21 @@ ulong bootm_disable_interrupts(void)
       */
      iflag = disable_interrupts();
 #ifdef CONFIG_NETCONSOLE
-     /* Stop the ethernet stack if NetConsole could have left it up */
+     /*
+      * Make sure that the starting kernel message printed out.
+      * Reset stdin/out/err back to serial and stop the ethernet
+      * stack if NetConsole could have left it up
+      */
+     char *s;
+     int ret;
+
+     s = env_get("stdout");
+     if (strcmp(s, "nc") == 0) {
+             printf("\n\nStarting kernel ...\n");
+             ret = env_set("stdin", "serial");
+             ret = env_set("stdout", "serial");
+             ret = env_set("stderr", "serial");
+     }
      eth_halt();
 #endif
 
drivers/net/netconsole.c +1 -2
index 151bc55e07..2091014918 100644
@@ -20,7 +20,7 @@ static int input_size; /* char count in input buffer */
 static int input_offset; /* offset to valid chars in input buffer */
 static int input_recursion;
 static int output_recursion;
-static int net_timeout;
+static int net_timeout = 1;
 static uchar nc_ether[6]; /* server enet address */
 static struct in_addr nc_ip; /* server ip */
 static short nc_out_port; /* target output port */
--

2.30.2