panic: Flush unsafe consoles before panic reboot
RFC PATCH 1/1 panic: Flush unsafe consoles before panic reboot
Netconsole registers with CON_NBCON_ATOMIC_UNSAFE, so its write_atomic() callback is only usable during nbcon_atomic_flush_unsafe(). Previously this was only called by vpanic() if panic_timeout=0 - i.e. if the system was configured not to reboot on panic. So if the system was configured to reboot on panic, netconsole would never receive the panic logs.
Move vpanic()'s emergency_restart() call to after the call to nbcon_atomic_flush_unsafe() to solve this problem. The downside is that potentially unsafe operations are now performed prior to emergency_restart() which could theoretically reduce the chances of the restart succeeding. But we are already in a panic situation so it could be argued that everything is best effort already.
In older kernels (v6.19 and earlier) netconsole is able to print these panic logs while the system is configured to reboot on panic. So from a user perspective this is a regression caused by commit 7eab73b18630 ("netconsole: convert to NBCON console infrastructure").
We have automated test systems without BMC access, which rely on these two features working together.
--- kernel/panic.c | 35 ++++++++++++++++++----------------- 1 file changed, 18 insertions(+), 17 deletions(-)
kernel/panic.c +18 -17
@@ -732,32 +732,22 @@ void vpanic(const char *fmt, va_list args)mdelay (PANIC_TIMER_STEP ); } } -if (panic_timeout !=0 ) { -/* -* This will not be a clean reboot, with everything -* shutting down. But if there is a chance of -* rebooting the system it will be rebooted. -*/ -if (panic_reboot_mode !=REBOOT_UNDEFINED ) - reboot_mode = panic_reboot_mode; -emergency_restart (); - } +if (panic_timeout ==0 ) {#ifdef __sparc__ - {extern int stop_a_enabled;/* Make sure the user can actually press Stop-A (L1-A) */ stop_a_enabled =1 ;pr_emerg ("Press Stop-A (L1-A) from sun keyboard or send break\n" -"twice on console to return to the boot prom\n" ); - } +"twice on console to return to the boot prom\n" );#endif #if defined(CONFIG_S390 ) -disabled_wait (); +disabled_wait ();#endif -pr_emerg ("---[ end Kernel panic - not syncing: %s ]---\n" , buf); +pr_emerg ("---[ end Kernel panic - not syncing: %s ]---\n" , buf); -/* Do not scroll important messages printed above */ - suppress_printk =1 ; +/* Do not scroll important messages printed above */ + suppress_printk =1 ; + }/* * The final messages may not have been printed if in a context that
@@ -767,6 +757,17 @@ void vpanic(const char *fmt, va_list args)console_flush_on_panic (CONSOLE_FLUSH_PENDING );nbcon_atomic_flush_unsafe (); +if (panic_timeout !=0 ) { +/* +* This will not be a clean reboot, with everything +* shutting down. But if there is a chance of +* rebooting the system it will be rebooted. +*/ +if (panic_reboot_mode !=REBOOT_UNDEFINED ) + reboot_mode = panic_reboot_mode; +emergency_restart (); + } +local_irq_enable ();for (i =0 ; ; i +=PANIC_TIMER_STEP ) {touch_softlockup_watchdog ();
--
2.43.0
Quoted 18 lines · Ryan Roberts
Netconsole registers with
CON_NBCON_ATOMIC_UNSAFE, so itswrite_atomic()callback is only usable duringnbcon_atomic_flush_unsafe(). Previously this was only called byvpanic()if panic_timeout=0 - i.e. if the system was configured not to reboot on panic. So if the system was configured to reboot on panic, netconsole would never receive the panic logs.Move vpanic()'s
emergency_restart()call to after the call tonbcon_atomic_flush_unsafe()to solve this problem. The downside is that potentially unsafe operations are now performed prior toemergency_restart()which could theoretically reduce the chances of the restart succeeding. But we are already in a panic situation so it could be argued that everything is best effort already.In older kernels (v6.19 and earlier) netconsole is able to print these panic logs while the system is configured to reboot on panic. So from a user perspective this is a regression caused by commit
7eab73b18630("netconsole: convert to NBCON console infrastructure").
Quoted 6 lines
We have automated test systems without BMC access, which rely on these two features working together.
Fixes 7eab73b18630 ("netconsole: convert to NBCON console infrastructure")Signed-off-by Ryan Roberts <[email protected]>---
Oops forgot to add commentary to the bottom:
I've set this as RFC because I'm not sure if the current behaviour is a deliberate design decision? I guess if we flush the unsafe console, there is a possibility it deadlocks, preventing the subsequent reboot. If people are concerned about this, perhaps this needs a cmdline flag?
Thanks,
Ryan
Quoted 68 lines
kernel/panic.c | 35 ++++++++++++++++++----------------- 1 file changed, 18 insertions(+), 17 deletions(-)kernel/panic.c +18
-18@@ -732,32 +732,22 @@ void vpanic(const char *fmt, va_list args)mdelay (PANIC_TIMER_STEP ); } } -if (panic_timeout !=0 ) { -/* -* This will not be a clean reboot, with everything -* shutting down. But if there is a chance of -* rebooting the system it will be rebooted. -*/ -if (panic_reboot_mode !=REBOOT_UNDEFINED ) - reboot_mode = panic_reboot_mode; -emergency_restart (); - } +if (panic_timeout ==0 ) {#ifdef __sparc__ - {extern int stop_a_enabled;/* Make sure the user can actually press Stop-A (L1-A) */ stop_a_enabled =1 ;pr_emerg ("Press Stop-A (L1-A) from sun keyboard or send break\n" -"twice on console to return to the boot prom\n" ); - } +"twice on console to return to the boot prom\n" );#endif #if defined(CONFIG_S390 ) -disabled_wait (); +disabled_wait ();#endif -pr_emerg ("---[ end Kernel panic - not syncing: %s ]---\n" , buf); +pr_emerg ("---[ end Kernel panic - not syncing: %s ]---\n" , buf); -/* Do not scroll important messages printed above */ - suppress_printk =1 ; +/* Do not scroll important messages printed above */ + suppress_printk =1 ; + }/* * The final messages may not have been printed if in a context that @@ -767,6 +757,17 @@ void vpanic(const char *fmt, va_list args)console_flush_on_panic (CONSOLE_FLUSH_PENDING );nbcon_atomic_flush_unsafe (); +if (panic_timeout !=0 ) { +/* +* This will not be a clean reboot, with everything +* shutting down. But if there is a chance of +* rebooting the system it will be rebooted. +*/ +if (panic_reboot_mode !=REBOOT_UNDEFINED ) + reboot_mode = panic_reboot_mode; +emergency_restart (); + } +local_irq_enable ();for (i =0 ; ; i +=PANIC_TIMER_STEP ) {touch_softlockup_watchdog (); --2.43.0
Hey, I think thisll conflict with the arch_do_panic() patch (b45d6e4b3580)
Once you rebase. I'd reckon the
change shrinks to just moving the panic_timeout != 0 block below nbcon_atomic_flush_unsafe().
On your RFC question, whether the current behavior is deliberate: I don't think it is. nbcon_atomic_flush_unsafe() was placed at the end of vpanic() by 5dde3b735413 as a final attempt to flush pending messages, and at
that point no console was actually CON_NBCON_ATOMIC_UNSAFE, netconsole was still legacy. There was nothing to lose by putting it last. The ordering only became a bug once the first unsafe console showed up. John and Petr can confirm, but I found no sign anyone chose this.
Quoted 1 line · Bradley Morgan
Hey, I think thisll conflict with the
arch_do_panic()patch (b45d6e4b3580)
Ahh I see it here:
https://lore.kernel.org/all/[email protected]/
And looks like it's in Andrew's mm-nonmm-unstable branch. I guess I should repost based on that branch?
Quoted 4 lines
Once you rebase. I'd reckon the
change shrinks to just moving thepanic_timeout!= 0 block belownbcon_atomic_flush_unsafe().
I think I'll also want to make the call to arch_do_panic() conditional on (panic_timeout == 0) so it's equivalent to the patch I sent?
Quoted 9 lines
On your RFC question, whether the current behavior is deliberate: I don't think it is.
nbcon_atomic_flush_unsafe()was placed at the end ofvpanic()by5dde3b735413as a final attempt to flush pending messages, and at
that point no console was actuallyCON_NBCON_ATOMIC_UNSAFE, netconsole was still legacy. There was nothing to lose by putting it last. The ordering only became a bug once the first unsafe console showed up. John and Petr can confirm, but I found no sign anyone chose this.
OK great; I'll wait a few days for others to chime in, otherwise I'll plan to repost based on mm-nonmm-unstable, dropping the RFC tag.
Thanks,
Ryan
Quoted 4 lines
Quoted 9 lines · Ryan Roberts
Quoted 1 line · Bradley Morgan
Hey, I think thisll conflict with the
arch_do_panic()patch(
b45d6e4b3580)Ahh I see it here:
https://lore.kernel.org/all/[email protected]/And looks like it's in Andrew's mm-nonmm-unstable branch. I guess I should repost based on that branch?
Yes.
(That branch also goes to linux-next)
Quoted 30 lines
Quoted 5 lines
Once you rebase. I'd reckon the
change shrinks to just moving thepanic_timeout!= 0 block belownbcon_atomic_flush_unsafe().I think I'll also want to make the call to
arch_do_panic()conditional on (panic_timeout== 0) so it's equivalent to the patch I sent?Quoted 4 lines
On your RFC question, whether the current behavior is deliberate: I don't think it is.
nbcon_atomic_flush_unsafe()was placed at the end ofvpanic()by5dde3b735413as a final attempt to flush pending messages,and
Quoted 5 lines
at
that point no console was actuallyCON_NBCON_ATOMIC_UNSAFE, netconsole was still legacy. There was nothing to lose by putting it last. The ordering only became a bug once the first unsafe console showed up. John and Petr can confirm, but I found no sign anyone chose this.OK great; I'll wait a few days for others to chime in, otherwise I'll plan to
repost based on mm-nonmm-unstable, dropping the RFC tag.Thanks,
RyanQuoted 2 lines
Quoted 4 lines
Quoted 2 lines
--- Thanks!
Petr Mladek
maintainerQuoted 6 lines · Ryan Roberts
Netconsole registers with
CON_NBCON_ATOMIC_UNSAFE, so itswrite_atomic()callback is only usable duringnbcon_atomic_flush_unsafe(). Previously this was only called byvpanic()if panic_timeout=0 - i.e. if the system was configured not to reboot on panic. So if the system was configured to reboot on panic, netconsole would never receive the panic logs.
Quoted 6 lines
Move vpanic()'s
emergency_restart()call to after the call tonbcon_atomic_flush_unsafe()to solve this problem. The downside is that potentially unsafe operations are now performed prior toemergency_restart()which could theoretically reduce the chances of the restart succeeding. But we are already in a panic situation so it could be argued that everything is best effort already.
The panic() code is like walking on bumpy roads. It tries to be as safe as possible. IMHO, it has few important tasks:
+ show debug messages
+ create crash dump (optional)
+ safely reboot (optional)
The debug messages are important but some users might prioritize reboot over the debug messages. It helps when the panic() is rare (low likely race) and the system is quickly able to handle the load after the reboot.
This is why we put nbcon_atomic_flush_unsafe() only into the path which ends with an infinite loop.
Quoted 7 lines
In older kernels (v6.19 and earlier) netconsole is able to print these panic logs while the system is configured to reboot on panic. So from a user perspective this is a regression caused by commit
7eab73b18630("netconsole: convert to NBCON console infrastructure").We have automated test systems without BMC access, which rely on these two features working together.
I see. To be precise, I would say that the primary culprit is the commit 187de7c212e5fa87 ("printk: nbcon: Allow unsafe write_atomic() for panic"). It adds support for consoles which will be flushed in panic() only by nbcon_atomic_flush_unsafe().
It is a big difference because printk() tries to flush both legacy and "safe" NBCON consoles directly in panic(). In addition, they are explicitely flushed by console_flush_on_panic().
console_flush_on_panic() is called more times in panic(). And it tries to flush legacy consoles the unsafe way even before emergency_restart().
OK, we should close this gap. But I suggest another solution.
We already have the following functions for flushing NBCON consoles using write_atomic()
+ nbcon_atomic_flush_pending() - flush CON_NBCON consoles
using con->write_atomic() but only when safe
+ nbcon_atomic_flush_unsafe() - flush CON_NBCON consoles
using con->write_atomic() and allow unsafe takeover.
I suggest to add 3rd variant, for example:
+ nbcon_atomic_unsafe_flush_unsafe() - flush
CON_NBCON_ATOMIC_UNSAFE consoles with con->write_atomic() and allow unsafe takeover.
And I would call this 3rd variant in console_flush_on_panic(), something like:
void console_flush_on_panic(enum con_flush_mode mode) {
[...]
printk_get_console_flush_type(&ft);
if (ft.nbcon_atomic) {
nbcon_atomic_flush_pending();
nbcon_atomic_unsafe_flush_unsafe();
}
/* Flush legacy consoles once allowed, even when dangerous. */
if (legacy_allow_panic_sync)
console_flush_all(false, &next_seq, &handover);
}But maybe, this is over engineered and we should just call nbcon_atomic_flush_unsafe() in console_flush_on_panic(), like:
void console_flush_on_panic(enum con_flush_mode mode) {
[...]
printk_get_console_flush_type(&ft);
if (ft.nbcon_atomic) {
nbcon_atomic_flush_pending();
nbcon_atomic_flush_unsafe();
}
/* Flush legacy consoles once allowed, even when dangerous. */
if (legacy_allow_panic_sync)
console_flush_all(false, &next_seq, &handover);
}If there there are people really concerned about the reboot reliability then we might need to make it configurable, e.g. by adding reliable_panic command line option which would skip the unsafe flush before reboot.
See below.
Quoted 28 lines
kernel/panic.c +2
-13@@ -732,32 +732,22 @@ void vpanic(const char *fmt, va_list args)mdelay (PANIC_TIMER_STEP ); } } -if (panic_timeout !=0 ) { -/* -* This will not be a clean reboot, with everything -* shutting down. But if there is a chance of -* rebooting the system it will be rebooted. -*/ -if (panic_reboot_mode !=REBOOT_UNDEFINED ) - reboot_mode = panic_reboot_mode; -emergency_restart (); - } +if (panic_timeout ==0 ) {#ifdef __sparc__ - {extern int stop_a_enabled;/* Make sure the user can actually press Stop-A (L1-A) */ stop_a_enabled =1 ;pr_emerg ("Press Stop-A (L1-A) from sun keyboard or send break\n" -"twice on console to return to the boot prom\n" ); - } +"twice on console to return to the boot prom\n" );#endif #if defined(CONFIG_S390 )
kernel/panic.c void vpanic(const char *fmt, va_list args) · line 749
Quoted 10 lines
kernel/panic.c +4
-4-disabled_wait (); +disabled_wait ();#endif -pr_emerg ("---[ end Kernel panic - not syncing: %s ]---\n" , buf); +pr_emerg ("---[ end Kernel panic - not syncing: %s ]---\n" , buf); -/* Do not scroll important messages printed above */ - suppress_printk =1 ; +/* Do not scroll important messages printed above */ + suppress_printk =1 ;
We should not supress printk when emergency_restart() is going to be called. It might print some error messages which might explain why it failed, ...
Quoted 12 lines
kernel/panic.c +5
-0+ }/* * The final messages may not have been printed if in a context that @@ -767,6 +757,17 @@ void vpanic(const char *fmt, va_list args)console_flush_on_panic (CONSOLE_FLUSH_PENDING );nbcon_atomic_flush_unsafe (); +if (panic_timeout !=0 ) { +/* +* This will not be a clean reboot, with everything +* shutting down. But if there is a chance of
kernel/panic.c void vpanic(const char *fmt, va_list args) · line 773
Quoted 10 lines
kernel/panic.c +7
-0+* rebooting the system it will be rebooted. +*/ +if (panic_reboot_mode !=REBOOT_UNDEFINED ) + reboot_mode = panic_reboot_mode; +emergency_restart (); + } +local_irq_enable ();for (i =0 ; ; i +=PANIC_TIMER_STEP ) {touch_softlockup_watchdog ();
Best Regards,
Petr
Quoted 92 lines · Petr Mladek
Quoted 6 lines · Ryan Roberts
Netconsole registers with
CON_NBCON_ATOMIC_UNSAFE, so itswrite_atomic()callback is only usable duringnbcon_atomic_flush_unsafe(). Previously this was only called byvpanic()if panic_timeout=0 - i.e. if the system was configured not to reboot on panic. So if the system was configured to reboot on panic, netconsole would never receive the panic logs.Quoted 6 lines
Move vpanic()'s
emergency_restart()call to after the call tonbcon_atomic_flush_unsafe()to solve this problem. The downside is that potentially unsafe operations are now performed prior toemergency_restart()which could theoretically reduce the chances of the restart succeeding. But we are already in a panic situation so it could be argued that everything is best effort already.The
panic()code is like walking on bumpy roads. It tries to be as safe as possible. IMHO, it has few important tasks:+ show debug messages
+ create crash dump (optional)
+ safely reboot (optional)The debug messages are important but some users might prioritize reboot over the debug messages. It helps when the
panic()is rare (low likely race) and the system is quickly able to handle the load after the reboot.This is why we put
nbcon_atomic_flush_unsafe()only into the path which ends with an infinite loop.Quoted 7 lines
In older kernels (v6.19 and earlier) netconsole is able to print these panic logs while the system is configured to reboot on panic. So from a user perspective this is a regression caused by commit
7eab73b18630("netconsole: convert to NBCON console infrastructure").We have automated test systems without BMC access, which rely on these two features working together.
I see. To be precise, I would say that the primary culprit is the commit
187de7c212e5fa87("printk: nbcon: Allow unsafewrite_atomic()for panic"). It adds support for consoles which will be flushed inpanic()only bynbcon_atomic_flush_unsafe().It is a big difference because
printk()tries to flush both legacy and "safe" NBCON consoles directly inpanic(). In addition, they are explicitely flushed byconsole_flush_on_panic().
console_flush_on_panic()is called more times inpanic(). And it tries to flush legacy consoles the unsafe way even beforeemergency_restart().OK, we should close this gap. But I suggest another solution.
We already have the following functions for flushing NBCON consoles using
write_atomic()+
nbcon_atomic_flush_pending()- flushCON_NBCONconsolesusing con->write_atomic() but only when safe+
nbcon_atomic_flush_unsafe()- flushCON_NBCONconsolesusing con->write_atomic() and allow unsafe takeover.I suggest to add 3rd variant, for example:
+
nbcon_atomic_unsafe_flush_unsafe()- flushCON_NBCON_ATOMIC_UNSAFE consoles with con->write_atomic() and allow unsafe takeover.And I would call this 3rd variant in
console_flush_on_panic(), something like:void
console_flush_on_panic(enum con_flush_mode mode){
[...]printk_get_console_flush_type(&ft); if (ft.nbcon_atomic) { nbcon_atomic_flush_pending(); nbcon_atomic_unsafe_flush_unsafe(); } /* Flush legacy consoles once allowed, even when dangerous. */ if (legacy_allow_panic_sync) console_flush_all(false, &next_seq, &handover); }But maybe, this is over engineered and we should just call
nbcon_atomic_flush_unsafe()inconsole_flush_on_panic(), like:void
console_flush_on_panic(enum con_flush_mode mode){
[...]
Quoted 10 lines
printk_get_console_flush_type(&ft);
if (ft.nbcon_atomic) {
nbcon_atomic_flush_pending();
nbcon_atomic_flush_unsafe();
}
/* Flush legacy consoles once allowed, even when dangerous. */
if (legacy_allow_panic_sync)
console_flush_all(false, &next_seq, &handover);
}Hi Ryan, are you still planning to send a non-RFC patch? If not, I'm happy to take over and send a patch with Petr's suggestion. We are seeing cases in production of panic logs not reaching netconsole because of this.
John Ogness
maintainerSorry for the late response... this fell through the cracks. Response below...
Quoted 30 lines · Petr Mladek
Quoted 7 lines
In older kernels (v6.19 and earlier) netconsole is able to print these panic logs while the system is configured to reboot on panic. So from a user perspective this is a regression caused by commit
7eab73b18630("netconsole: convert to NBCON console infrastructure").We have automated test systems without BMC access, which rely on these two features working together.
I see. To be precise, I would say that the primary culprit is the commit
187de7c212e5fa87("printk: nbcon: Allow unsafewrite_atomic()for panic"). It adds support for consoles which will be flushed inpanic()only bynbcon_atomic_flush_unsafe().It is a big difference because
printk()tries to flush both legacy and "safe" NBCON consoles directly inpanic(). In addition, they are explicitely flushed byconsole_flush_on_panic().
console_flush_on_panic()is called more times inpanic(). And it tries to flush legacy consoles the unsafe way even beforeemergency_restart().OK, we should close this gap. But I suggest another solution.
We already have the following functions for flushing NBCON consoles using
write_atomic()+
nbcon_atomic_flush_pending()- flushCON_NBCONconsolesusing con->write_atomic() but only when safe
Quoted 8 lines
+
nbcon_atomic_flush_unsafe()- flushCON_NBCONconsolesusing con->write_atomic() and allow unsafe takeover.I suggest to add 3rd variant, for example:
+
nbcon_atomic_unsafe_flush_unsafe()- flushCON_NBCON_ATOMIC_UNSAFE consoles with con->write_atomic() and allow unsafe takeover.
nbcon_atomic_flush_unsafe() already includes CON_NBCON_ATOMIC_UNSAFE.
Quoted 10 lines
And I would call this 3rd variant in
console_flush_on_panic(), something like:void
console_flush_on_panic(enum con_flush_mode mode){
[...]printk_get_console_flush_type(&ft); if (ft.nbcon_atomic) { nbcon_atomic_flush_pending(); nbcon_atomic_unsafe_flush_unsafe();
s/nbcon_atomic_unsafe_flush_unsafe/nbcon_atomic_flush_unsafe/
console_flush_on_panic() is used in multiple places and depending on the user, it may be too risky. Yes, if there are legacy consoles the user is already taking this risk. But with nbcon we would like to excercise some risk management.
Quoted 4 lines
If there there are people really concerned about the reboot reliability then we might need to make it configurable, e.g. by adding
reliable_paniccommand line option which would skip the unsafe flush before reboot.
Yes. When originally developing the nbcon, tglx and I talked about many more details related to this topic. For example, the ability to order the unsafe flushing. That is one of the reasons that nbcon flushes the full backlog for each console, rather than each console only flushing a single record.
If we are going to expose an interface to configure if unsafe flushing should occur, then we should also consider ordering. Even if we do not want to build in the ordering support right now, the interface should be such that it can be easily extended to support this.
*** WARNING: Now we get into my brainstorming, which could be rough. ***
Rather than a big hammer option, I see this more as a per-console configuration (similar to how we want to go with the console loglevels).
Netconsole is a bit tricky, because it has its own format separate from console. This would need to be addressed for the per-console loglevels as well. Maybe it should be extended to something like:
netconsole=[+][r][src-port]@[src-ip]/[<dev>],[tgt-port]@<tgt-ip>/[tgt-macaddr][,options]
Which would allow things like:
netconsole=@/,@10.10.0.2/,loglevel:3,unsafe_panic:1
This would also allow to specify that consoles should _not_ perform unsafe flushing:
console=ttyS0,115200,unsafe_panic:0
And it could be used for ordering, flusing from highest value to lowest:
netconsole=@/,@10.10.0.2/,unsafe_panic:2 console=ttyS0,115200,unsafe_panic:12
(First ttyS0 is unsafe-flushed, then the netconsole is unsafe-flushed.)
For consoles with CON_NBCON_ATOMIC_UNSAFE, the default would be unsafe_panic:0. Otherwise the default would be unsafe_panic:1.
Unfortunately the above idea does not consider the reboot vs. busy-loop paths. I could imagine there are those that only want a different ordering/disabling for paths where the kernel will continue to be useful (for example, a reboot). I think that makes sense. But I am not really sure how that distinction should be made. We don't want to configure ourselves to death. Maybe that distinction is not relevant.
John
Petr Mladek
maintainerQuoted 37 lines · John Ogness
Sorry for the late response... this fell through the cracks. Response below...
Quoted 33 lines · Petr Mladek
Quoted 7 lines
In older kernels (v6.19 and earlier) netconsole is able to print these panic logs while the system is configured to reboot on panic. So from a user perspective this is a regression caused by commit
7eab73b18630("netconsole: convert to NBCON console infrastructure").We have automated test systems without BMC access, which rely on these two features working together.
I see. To be precise, I would say that the primary culprit is the commit
187de7c212e5fa87("printk: nbcon: Allow unsafewrite_atomic()for panic"). It adds support for consoles which will be flushed inpanic()only bynbcon_atomic_flush_unsafe().It is a big difference because
printk()tries to flush both legacy and "safe" NBCON consoles directly inpanic(). In addition, they are explicitely flushed byconsole_flush_on_panic().
console_flush_on_panic()is called more times inpanic(). And it tries to flush legacy consoles the unsafe way even beforeemergency_restart().OK, we should close this gap. But I suggest another solution.
We already have the following functions for flushing NBCON consoles using
write_atomic()+
nbcon_atomic_flush_pending()- flushCON_NBCONconsolesusing con->write_atomic() but only when safe+
nbcon_atomic_flush_unsafe()- flushCON_NBCONconsolesusing con->write_atomic() and allow unsafe takeover.
Quoted 7 lines
Quoted 5 lines
I suggest to add 3rd variant, for example:
+
nbcon_atomic_unsafe_flush_unsafe()- flushCON_NBCON_ATOMIC_UNSAFE consoles with con->write_atomic() and allow unsafe takeover.
nbcon_atomic_flush_unsafe()already includesCON_NBCON_ATOMIC_UNSAFE.
I was not clear enoungh. The purpose of the 3rd variant was to allow the unsafe takeover only for consoles with CON_NBCON_ATOMIC_UNSAFE. And rely only on the safe atomic flush for consoles which support it.
But it is likely too complicated and probably not worth it.
Quoted 11 lines
Quoted 10 lines
And I would call this 3rd variant in
console_flush_on_panic(), something like:void
console_flush_on_panic(enum con_flush_mode mode){
[...]printk_get_console_flush_type(&ft); if (ft.nbcon_atomic) { nbcon_atomic_flush_pending(); nbcon_atomic_unsafe_flush_unsafe();
Quoted 1 line
s/nbcon_atomic_unsafe_flush_unsafe/nbcon_atomic_flush_unsafe/
Yes, I am fine with this.
Quoted 50 lines
console_flush_on_panic()is used in multiple places and depending on the user, it may be too risky. Yes, if there are legacy consoles the user is already taking this risk. But with nbcon we would like to excercise some risk management.Quoted 4 lines
If there there are people really concerned about the reboot reliability then we might need to make it configurable, e.g. by adding
reliable_paniccommand line option which would skip the unsafe flush before reboot.Yes. When originally developing the nbcon, tglx and I talked about many more details related to this topic. For example, the ability to order the unsafe flushing. That is one of the reasons that nbcon flushes the full backlog for each console, rather than each console only flushing a single record.
If we are going to expose an interface to configure if unsafe flushing should occur, then we should also consider ordering. Even if we do not want to build in the ordering support right now, the interface should be such that it can be easily extended to support this.
*** WARNING: Now we get into my brainstorming, which could be rough. ***
Rather than a big hammer option, I see this more as a per-console configuration (similar to how we want to go with the console loglevels).
Netconsole is a bit tricky, because it has its own format separate from console. This would need to be addressed for the per-console loglevels as well. Maybe it should be extended to something like:
netconsole=[+][r][src-port]@[src-ip]/[<dev>],[tgt-port]@<tgt-ip>/[tgt-macaddr][,options]
Which would allow things like:
netconsole=@/,@10.10.0.2/,loglevel:3,unsafe_panic:1
This would also allow to specify that consoles should _not_ perform unsafe flushing:
console=ttyS0,115200,unsafe_panic:0
And it could be used for ordering, flusing from highest value to lowest:
netconsole=@/,@10.10.0.2/,unsafe_panic:2 console=ttyS0,115200,unsafe_panic:12
(First ttyS0 is unsafe-flushed, then the netconsole is unsafe-flushed.)
For consoles with
CON_NBCON_ATOMIC_UNSAFE, the default would be unsafe_panic:0. Otherwise the default would be unsafe_panic:1.
Quoted 6 lines
Unfortunately the above idea does not consider the reboot vs. busy-loop paths. I could imagine there are those that only want a different ordering/disabling for paths where the kernel will continue to be useful (for example, a reboot). I think that makes sense. But I am not really sure how that distinction should be made. We don't want to configure ourselves to death. Maybe that distinction is not relevant.
This sounds reasonable. And it is good to have a plan. Well, I would add this complexity only when there is a real demand for it :-)
Best Regards,
Petr
Quoted 65 lines · Petr Mladek
Quoted 37 lines · John Ogness
Sorry for the late response... this fell through the cracks. Response below...
Quoted 33 lines · Petr Mladek
Quoted 7 lines
In older kernels (v6.19 and earlier) netconsole is able to print these panic logs while the system is configured to reboot on panic. So from a user perspective this is a regression caused by commit
7eab73b18630("netconsole: convert to NBCON console infrastructure").We have automated test systems without BMC access, which rely on these two features working together.
I see. To be precise, I would say that the primary culprit is the commit
187de7c212e5fa87("printk: nbcon: Allow unsafewrite_atomic()for panic"). It adds support for consoles which will be flushed inpanic()only bynbcon_atomic_flush_unsafe().It is a big difference because
printk()tries to flush both legacy and "safe" NBCON consoles directly inpanic(). In addition, they are explicitely flushed byconsole_flush_on_panic().
console_flush_on_panic()is called more times inpanic(). And it tries to flush legacy consoles the unsafe way even beforeemergency_restart().OK, we should close this gap. But I suggest another solution.
We already have the following functions for flushing NBCON consoles using
write_atomic()+
nbcon_atomic_flush_pending()- flushCON_NBCONconsolesusing con->write_atomic() but only when safe+
nbcon_atomic_flush_unsafe()- flushCON_NBCONconsolesusing con->write_atomic() and allow unsafe takeover.Quoted 7 lines
Quoted 5 lines
I suggest to add 3rd variant, for example:
+
nbcon_atomic_unsafe_flush_unsafe()- flushCON_NBCON_ATOMIC_UNSAFE consoles with con->write_atomic() and allow unsafe takeover.
nbcon_atomic_flush_unsafe()already includesCON_NBCON_ATOMIC_UNSAFE.I was not clear enoungh. The purpose of the 3rd variant was to allow the unsafe takeover only for consoles with
CON_NBCON_ATOMIC_UNSAFE. And rely only on the safe atomic flush for consoles which support it.But it is likely too complicated and probably not worth it.
Quoted 11 lines
Quoted 10 lines
And I would call this 3rd variant in
console_flush_on_panic(), something like:void
console_flush_on_panic(enum con_flush_mode mode){
[...]printk_get_console_flush_type(&ft); if (ft.nbcon_atomic) { nbcon_atomic_flush_pending(); nbcon_atomic_unsafe_flush_unsafe();
Quoted 3 lines
Quoted 1 line
s/nbcon_atomic_unsafe_flush_unsafe/nbcon_atomic_flush_unsafe/
Yes, I am fine with this.
This fixes the reboot case, since console_flush_on_panic() runs before emergency_restart().
But I got the feeling that it does not help when a crash kernel is loaded, which is a common production setup, and how our fleet runs.
With kdump, the kernel kexecs before any of the console_flush_on_panic() calls in panic():
1) panic() calls __crash_kexec() before panic_other_cpus_shutdown(), or right after kmsg_dump() with crash_kexec_post_notifiers.
2) On an oops, oops_end() (x86) and die() (arm64) call crash_kexec() directly when kexec_should_crash() says so (panic_on_oops, oops in interrupt, ...), so panic() never runs. With crash_kexec_post_notifiers they go through panic() and hit 1).
So netconsole, or any CON_NBCON_ATOMIC_UNSAFE console, prints nothing on kdump hosts.
Quoted 2 lines · Breno Leitao
So netconsole, or any
CON_NBCON_ATOMIC_UNSAFEconsole, prints nothing on kdump hosts.
For flushing unsafe on nbcon on hosts with kdump environment, this seems to do the work, but, maybe this is too unsafe !?
kernel/crash_core.c +2 -0
@@ -140,6 +140,8 @@ void __noclone __crash_kexec(struct pt_regs *regs)crash_setup_regs (&fixed_regs, regs);crash_save_vmcoreinfo (); +/* Flush consoles with an unsafe write_atomic(), e.g. netconsole. */ +nbcon_atomic_flush_unsafe ();machine_crash_shutdown (&fixed_regs);crash_cma_clear_pending_dma ();machine_kexec (kexec_crash_image);
John Ogness
maintainerQuoted 6 lines · Breno Leitao
Quoted 2 lines · Breno Leitao
So netconsole, or any
CON_NBCON_ATOMIC_UNSAFEconsole, prints nothing on kdump hosts.For flushing unsafe on nbcon on hosts with kdump environment, this seems to do the work, but, maybe this is too unsafe !?
For the general case, it is certainly too unsafe. As I suggested [0] we need a way to allows users to make this decision. nbcon was designed to allow for printing policies, but we have not yet provided the interfaces for the user specify such policies nor the mechanism to enforce the policies.
Perhaps we need to begin by identifying all the sites where the current kernel is ending (whether reboot, shutdown, panic, kexec, hang).
kernel/crash_core.c void __noclone __crash_kexec(struct pt_regs *regs) · line 144
Quoted 10 lines
kernel/crash_core.c +2
-0@@ -140,6 +140,8 @@ void __noclone __crash_kexec(struct pt_regs *regs)crash_setup_regs (&fixed_regs, regs);crash_save_vmcoreinfo (); +/* Flush consoles with an unsafe write_atomic(), e.g. netconsole. */ +nbcon_atomic_flush_unsafe ();
I am guessing that the CPU is _always_ in emergency state here? Otherwise the flushing problem exists for all atomic consoles.
kernel/crash_core.c void __noclone __crash_kexec(struct pt_regs *regs) · line 147
Quoted 4 lines
kernel/crash_core.c +0
-0machine_crash_shutdown (&fixed_regs);crash_cma_clear_pending_dma ();machine_kexec (kexec_crash_image);
John
Quoted 5 lines · John Ogness
Quoted 1 line · Breno Leitao
On Tue, Oct 27, 2026 at 09:12:09AM -0700, Breno Leitao wrote:
Perhaps we need to begin by identifying all the sites where the current kernel is ending (whether reboot, shutdown, panic, kexec, hang).
Ack. This is what I have so far on the panic side:
1) panic() ending in the final loop (panic_timeout=0): flushed at the
end, including the unsafe consoles (d988d9a9b9d180, 5dde3b735413).
2) panic() ending in emergency_restart(): no unsafe flush (Ryan's RFC).
3) panic() ending in __crash_kexec(): the console_flush_on_panic() and nbcon_atomic_flush_unsafe() calls all come later, with or without crash_kexec_post_notifiers.
4) An oops ending in crash_kexec() straight from oops_end()/die(), when kexec_should_crash() is true. panic() never runs.
5) Other crash_kexec() callers, such as s390 and hypervisors.
Quoted 5 lines
kernel/crash_core.c void __noclone __crash_kexec(struct pt_regs *regs) · line 144
Quoted 2 lines
kernel/crash_core.c +2
-0+/* Flush consoles with an unsafe write_atomic(), e.g. netconsole. */ +nbcon_atomic_flush_unsafe ();I am guessing that the CPU is _always_ in emergency state here? Otherwise the flushing problem exists for all atomic consoles.
True. But for the unsafe consoles, the end of panic() already handles this.
d988d9a9b9d180 ("panic: Flush kernel log buffer at the end") added a final console_flush_on_panic(), and 5dde3b735413 ("printk: nbcon: Add unsafe flushing on panic") added nbcon_atomic_flush_unsafe() after it, to make sure the last messages get out.
That _only_ runs when panic() ends in the final loop, though. kdump never gets there, and neither does reboot-on-panic or, possibly, some of the other "kernel ending" sites you mentioned above.
The kdump case is the one I care about most. It is a regression for us (Meta) in production, where kdump is always armed: netconsole has lost these messages since it moved to nbcon.
So far we have identified two places that need the same unsafe flush that 5dde3b735413 added to the final loop:
a) panic() ending in emergency_restart(). Petr's suggestion to flush from console_flush_on_panic() covers this one.
b) __crash_kexec(), reached from panic() or straight from
oops_end()/die().
Quoted 9 lines · John Ogness
*** WARNING: Now we get into my brainstorming, which could be rough. ***
Rather than a big hammer option, I see this more as a per-console configuration (similar to how we want to go with the console loglevels).
Netconsole is a bit tricky, because it has its own format separate from console. This would need to be addressed for the per-console loglevels as well. Maybe it should be extended to something like:
Quoted 5 lines
netconsole=[+][r][src-port]@[src-ip]/[<dev>],[tgt-port]@<tgt-ip>/[tgt-macaddr][,options]
Which would allow things like:
netconsole=@/,@10.10.0.2/,loglevel:3,unsafe_panic:1
This cannot be per target, given that netconsole has multiple targets (as remote hosts/IPs), but a single registered console.
As of right now, all targets share the same remote, and would have the same unsafe_panic priority.
Quoted 5 lines
This would also allow to specify that consoles should _not_ perform unsafe flushing:
console=ttyS0,115200,unsafe_panic:0
Quoted 8 lines
And it could be used for ordering, flusing from highest value to lowest:
netconsole=@/,@10.10.0.2/,unsafe_panic:2 console=ttyS0,115200,unsafe_panic:12
(First ttyS0 is unsafe-flushed, then the netconsole is unsafe-flushed.)
For consoles with
CON_NBCON_ATOMIC_UNSAFE, the default would be unsafe_panic:0. Otherwise the default would be unsafe_panic:1.
How do you plan to use 'unsafe_panic' order exactly?
Thanks,
--breno
John Ogness
maintainerQuoted 9 lines · Breno Leitao
Quoted 9 lines
*** WARNING: Now we get into my brainstorming, which could be rough. ***
Rather than a big hammer option, I see this more as a per-console configuration (similar to how we want to go with the console loglevels).
Netconsole is a bit tricky, because it has its own format separate from console. This would need to be addressed for the per-console loglevels as well. Maybe it should be extended to something like:
Quoted 8 lines
Quoted 5 lines
netconsole=[+][r][src-port]@[src-ip]/[<dev>],[tgt-port]@<tgt-ip>/[tgt-macaddr][,options]
Which would allow things like:
netconsole=@/,@10.10.0.2/,loglevel:3,unsafe_panic:1
This cannot be per target, given that netconsole has multiple targets (as remote hosts/IPs), but a single registered console.
Well, actually there are two. I can setup a target using extended=0 and another using extended=1 and then I see both "netconsole hubs": netcon0 and netcon_ext0.
Quoted 2 lines
As of right now, all targets share the same remote, and would have the same
unsafe_panicpriority.
s/all targets/all targets of the same mode/
As you mentioned in the replay thread [0], maybe we should consider registering a console for each target. I would expect that may even simplify the "netconsole hub" dance that the netconsole code is currently doing.
This change should not require any changes to existing netconsole usage. AFAICT the differences would only be visible in /proc/consoles. The advantage would be that each target could be additionally individually configured using the generic /sys/class/consoles interface for general features like:
loglevel, sync, replay, unsafe_panic
I am not suggesting removing the /sys/kernel/config/netconsole interface. That works well for setting up the netconsoles. (Although "extended" should then also migrate (or symlink) to the generic per-console interface.) The /sys/class/consoles interface is supplemental for the general console features (and maybe both could provide symlinks to the other).
Quoted 7 lines
Quoted 7 lines
This would also allow to specify that consoles should _not_ perform unsafe flushing:
console=ttyS0,115200,unsafe_panic:0
And it could be used for ordering, flusing from highest value to lowest:
Quoted 8 lines
Quoted 6 lines
netconsole=@/,@10.10.0.2/,unsafe_panic:2 console=ttyS0,115200,unsafe_panic:12
(First ttyS0 is unsafe-flushed, then the netconsole is unsafe-flushed.)
For consoles with
CON_NBCON_ATOMIC_UNSAFE, the default would be unsafe_panic:0. Otherwise the default would be unsafe_panic:1.How do you plan to use '
unsafe_panic' order exactly?
Currently at the end of panic() an unsafe flush occurs by simply iterating through the list of consoles. That list ordering does have a fixed algorithm behind it, but it is quite hard to follow.
By explicitly providing an unsafe ordering, the user could specify the order of the consoles where the backlog is flushed unsafely. That ordering may be based on probable reliability (maybe the chances of an unsafe netconsole flush hanging are less than the chances of an unsafe serial console flush hanging) or priority (if I only get 1 flush, then I want it with the netconsole, so try it first).
And the feature could also be used to disable unsafe flushing so that a particular console _never_ unsafe flushes (maybe the unsafe flushing with a particular console driver is guaranteed fireworks, so it should be avoided).
John
Quoted 9 lines · John Ogness
Quoted 4 lines · Breno Leitao
Quoted 2 lines
For consoles with
CON_NBCON_ATOMIC_UNSAFE, the default would be unsafe_panic:0. Otherwise the default would be unsafe_panic:1.How do you plan to use '
unsafe_panic' order exactly?Currently at the end of
panic()an unsafe flush occurs by simply iterating through the list of consoles. That list ordering does have a fixed algorithm behind it, but it is quite hard to follow.
But is that flush invoked at all on the kdump/kexec path?
As far as I can see, nbcon_atomic_flush_unsafe() has a single caller, at the very end of vpanic(). So the unsafe consoles are only flushed in one specific "kernel ending" case: panic() with panic_timeout=0 and no crash kernel loaded.
I think we are mixing two different topics here:
1) How to set the order of the unsafe flush (per console, from the cmdline and/or sysfs).
2) A hook at the "kernel ending" sites (the panic reboot path, __crash_kexec(), ...), so we do not forget to flush the unsafe consoles there.
Should we split them?
The missing hook in 2) is what drops the netconsole panic output today, while 1) is policy on top of it.
Thanks for the suggestions,
--breno
John Ogness
maintainerQuoted 21 lines · Breno Leitao
Quoted 8 lines
Quoted 4 lines
Quoted 2 lines
For consoles with
CON_NBCON_ATOMIC_UNSAFE, the default would be unsafe_panic:0. Otherwise the default would be unsafe_panic:1.How do you plan to use '
unsafe_panic' order exactly?Currently at the end of
panic()an unsafe flush occurs by simply iterating through the list of consoles. That list ordering does have a fixed algorithm behind it, but it is quite hard to follow.But is that flush invoked at all on the kdump/kexec path?
As far as I can see,
nbcon_atomic_flush_unsafe()has a single caller, at the very end ofvpanic(). So the unsafe consoles are only flushed in one specific "kernel ending" case:panic()with panic_timeout=0 and no crash kernel loaded.I think we are mixing two different topics here:
1) How to set the order of the unsafe flush (per console, from the cmdline and/or sysfs).
Quoted 8 lines
2) A hook at the "kernel ending" sites (the panic reboot path,
__crash_kexec(), ...), so we do not forget to flush the unsafe consoles there.Should we split them?
The missing hook in 2) is what drops the netconsole panic output today, while 1) is policy on top of it.
They are separate but related. We need to address the missing hooks. But we cannot simply add unsafe flushing to those hooks. We need to allow policy for that.
First we need to make sure all "kernel ending" points are doing proper atomic (safe!) flushing. Ideally these are either graceful endings, so the kthreads are properly shutdown and printk naturally transitions to atomic printing. Or they are emergency situations and printk must forcefully transition to atomic printing. (Netconsole does not yet benefit from this, but we need to be sure that safe consoles are covered.)
Then we need to add an interface to allow the user to specify policy for the points to determine unsafe flushing. I would request that the interface is such that we can extend it to allow ordering of that unsafe flushing.
Note that the interface may involve some significant rework on how netconsoles are managed.
This all needs to be coordinated with other things already in the queue due to the overlap in code and features:
- preferred console cleanup/refactor [0]
- CON_ENABLE cleanup [1]
- introduction of per-console loglevels [2]
- per-console replaying [3]
I am not suggesting that all these things must come first, but we need to keep an eye on the big picture rather than hacking in some quick workarounds for netconsole.
John
[0] https://lore.kernel.org/lkml/[email protected]
[1] https://lore.kernel.org/lkml/[email protected]
[2] https://lore.kernel.org/lkml/[email protected]
[3] https://lore.kernel.org/lkml/[email protected]
Quoted 58 lines · John Ogness
Quoted 21 lines · Breno Leitao
Quoted 8 lines
Quoted 4 lines
Quoted 2 lines
For consoles with
CON_NBCON_ATOMIC_UNSAFE, the default would be unsafe_panic:0. Otherwise the default would be unsafe_panic:1.How do you plan to use '
unsafe_panic' order exactly?Currently at the end of
panic()an unsafe flush occurs by simply iterating through the list of consoles. That list ordering does have a fixed algorithm behind it, but it is quite hard to follow.But is that flush invoked at all on the kdump/kexec path?
As far as I can see,
nbcon_atomic_flush_unsafe()has a single caller, at the very end ofvpanic(). So the unsafe consoles are only flushed in one specific "kernel ending" case:panic()with panic_timeout=0 and no crash kernel loaded.I think we are mixing two different topics here:
1) How to set the order of the unsafe flush (per console, from the cmdline and/or sysfs).
Quoted 8 lines
2) A hook at the "kernel ending" sites (the panic reboot path,
__crash_kexec(), ...), so we do not forget to flush the unsafe consoles there.Should we split them?
The missing hook in 2) is what drops the netconsole panic output today, while 1) is policy on top of it.
They are separate but related. We need to address the missing hooks. But we cannot simply add unsafe flushing to those hooks. We need to allow policy for that.
First we need to make sure all "kernel ending" points are doing proper atomic (safe!) flushing. Ideally these are either graceful endings, so the kthreads are properly shutdown and printk naturally transitions to atomic printing. Or they are emergency situations and printk must forcefully transition to atomic printing. (Netconsole does not yet benefit from this, but we need to be sure that safe consoles are covered.)
Then we need to add an interface to allow the user to specify policy for the points to determine unsafe flushing. I would request that the interface is such that we can extend it to allow ordering of that unsafe flushing.
Note that the interface may involve some significant rework on how netconsoles are managed.
This all needs to be coordinated with other things already in the queue due to the overlap in code and features:
- preferred console cleanup/refactor [0]
-
CON_ENABLEcleanup [1]
Quoted 7 lines
- introduction of per-console loglevels [2]
- per-console replaying [3]
I am not suggesting that all these things must come first, but we need to keep an eye on the big picture rather than hacking in some quick workarounds for netconsole.
Right, thanks for the explanation and the links. Here is my view right now:
1) Converting netconsole to NBCON caused an undesired "regression" for users who would prefer the messages go out, even if unsafely. (as Ryan and Meta)
2) It seems the proper solution for this will take a few cycles.
3) I would hate to leave users with this "regression" we have today.
Do you have any suggestion for something doable in the short term?
Would reverting netconsole's NBCON conversion, while we address the dependnecies above, be an option?
Thanks,
--breno
John Ogness
maintainerQuoted 5 lines · Breno Leitao
Here is my view right now:
1) Converting netconsole to NBCON caused an undesired "regression" for users who would prefer the messages go out, even if unsafely. (as Ryan and Meta)
Legacy consoles were never truly synchronous. But, generally speaking, they were mostly synchronous in normal situations, which was good enough (and certainly more synchronous than the nbcon netconsole implementation today).
Quoted 1 line
2) It seems the proper solution for this will take a few cycles.
Based on past experience, I agree.
Quoted 1 line
3) I would hate to leave users with this "regression" we have today.
Agreed.
Quoted 1 line
Do you have any suggestion for something doable in the short term?
It depends on what is deemed acceptable. For example, we could introduce a Kconfig to always unsafe-flush when the kernel ends. This would be a fairly straight-forward change and require no changes from the user environment. Later we could add boottime/runtime configuration for this policy and make it per-console.
If Kconfig changes are not acceptable, we could hardwire unsafe flushing only for the netconsole (rather than all consoles). This would be a bit ugly, but it would still help us to identify all the correct points to enforce a later boottime/runtime policy.
I am open to both of these suggestions.
Quoted 2 lines
Would reverting netconsole's NBCON conversion, while we address the dependnecies above, be an option?
That would be unfortunate since the nbcon consoles provide a real benefit during runtime (full offloading of console printing). Also, the nbcon callbacks allowed the netconsole code to simplify due to the known in_task() context.
And I would like to remind that our ultimate goal would be to establish safe atomic printing for the netconsole. So any workarounds (such as CON_NBCON_ATOMIC_UNSAFE) are only meant to be temporary (even if temporary will be measured in years).
John
Petr Mladek
maintainerQuoted 20 lines · John Ogness
Quoted 5 lines · Breno Leitao
Here is my view right now:
1) Converting netconsole to NBCON caused an undesired "regression" for users who would prefer the messages go out, even if unsafely. (as Ryan and Meta)
Legacy consoles were never truly synchronous. But, generally speaking, they were mostly synchronous in normal situations, which was good enough (and certainly more synchronous than the nbcon netconsole implementation today).
Quoted 1 line
2) It seems the proper solution for this will take a few cycles.
Based on past experience, I agree.
Quoted 1 line
3) I would hate to leave users with this "regression" we have today.
Agreed.
Quoted 7 lines
Quoted 1 line
Do you have any suggestion for something doable in the short term?
It depends on what is deemed acceptable. For example, we could introduce a
Kconfigto always unsafe-flush when the kernel ends. This would be a fairly straight-forward change and require no changes from the user environment. Later we could add boottime/runtime configuration for this policy and make it per-console.
Honestly, I do not like much the kconfig option. IMHO, people would want to change the behavior for debugging purposes. So that a command line parameter would be better.
Quoted 4 lines
If
Kconfigchanges are not acceptable, we could hardwire unsafe flushing only for the netconsole (rather than all consoles). This would be a bit ugly, but it would still help us to identify all the correct points to enforce a later boottime/runtime policy.
This looks like a good compromise from my POV. NBCON console drivers with a safe con->write_atomic() have a good chance to flush messages before crash_kexec(). But consoles with CON_NBCON_ATOMIC_UNSAFE could be flushed on the unsafe way in panic().
It is basically the 3rd variant of the atomic flush which I described at https://lore.kernel.org/all/[email protected]/
We should think twice about the name so that we do not mix it with need to nbcon_atomic_flush_unsafe(). I propose:
nbcon_atomic_unsafe_flush_unsafe()
where "atomic_unsafe" commes from CON_NBCON_ATOMIC_UNSAFE. Or we could emphasize the fact that it is only the atomic_unsafe and use:
nbcon_atomic_unsafe_only_flush()
and I would pass it via a parameter to
static void __nbcon_atomic_flush_pending(u64 stop_seq, bool unsafe_only)
{
struct console *con;
int cookie;
cookie = console_srcu_read_lock();
for_each_console_srcu(con) {
short flags = console_srcu_read_flags(con);
if (!(flags & CON_NBCON))
continue;+ if (unsafe_only && !(flags & CON_NBCON_ATOMIC_UNSAFE))
+ continue;
+
if (!console_is_usable(con, flags, true)) continue; if (nbcon_seq_read(con) >= stop_seq) continue; nbcon_atomic_flush_pending_con(con, stop_seq); } console_srcu_read_unlock(cookie); }
Another question is where to call it. I guess the it should be called in two code paths:
+ __crash_kexec() likely after stopping other CPUs
+ console_flush_on_panic() after flushing safe nbcon consoles the safe way
Quoted 9 lines
I am open to both of these suggestions.
Quoted 2 lines
Would reverting netconsole's NBCON conversion, while we address the dependnecies above, be an option?
That would be unfortunate since the nbcon consoles provide a real benefit during runtime (full offloading of console printing). Also, the nbcon callbacks allowed the netconsole code to simplify due to the known
in_task()context.
I agree. It would be great to keep the netconsole driver converted.
Quoted 4 lines
And I would like to remind that our ultimate goal would be to establish safe atomic printing for the netconsole. So any workarounds (such as
CON_NBCON_ATOMIC_UNSAFE) are only meant to be temporary (even if temporary will be measured in years).
Yeah, making this work a safe way would be a pretty challenging job.
Best Regards,
Petr
Quoted 7 lines · Petr Mladek
Another question is where to call it. I guess the it should be called in two code paths:
+
__crash_kexec()likely after stopping other CPUs+
console_flush_on_panic()after flushing safe nbcon consoles the safe way
What about something like:
commit de57403441b601af01d92bc03bf0625338d39c80
Author: Breno Leitao <[email protected]> Date: Fri Oct 30 10:08:01 2026 -0700
panic: flush unsafe consoles before reboot and kdump
netconsole registers with CON_NBCON_ATOMIC_UNSAFE since commit 7eab73b18630 ("netconsole: convert to NBCON console infrastructure"), so its write_atomic() only runs from nbcon_atomic_flush_unsafe(). vpanic() calls that right before its final busy loop, after emergency_restart() and after __crash_kexec().
A panic that reboots (panic_timeout != 0) or boots a crash kernel therefore never reaches the netconsole target. Neither does an oops that goes to kdump through crash_kexec(), which skips vpanic() entirely. Before the conversion, netconsole was a legacy console, flushed by console_flush_on_panic() ahead of the reboot.
Add nbcon_atomic_unsafe_only_flush(), which flushes only the CON_NBCON_ATOMIC_UNSAFE consoles and allows unsafe takeovers on them. Call it on the panic CPU once the other CPUs are stopped, leaving the consoles with a safe write_atomic() alone.
In vpanic() it runs after the safe flush, when panic_other_cpus_shutdown() has stopped the other CPUs. In __crash_kexec() it runs after crash_smp_send_stop() and before machine_crash_shutdown(), the order panic() already uses with crash_kexec_post_notifiers.
The call does not go into console_flush_on_panic(), because kgdb_panic() calls that before the other CPUs are stopped. It does not go after machine_crash_shutdown() either: on TDX guests tdx_kexec_finish() zaps the shared PTEs there, and netconsole on a virtio NIC would touch that memory.
A write_atomic() that hangs now keeps the machine from rebooting or from reaching the crash kernel.
include/linux/console.h +2 -1
@@ -183,7 +183,8 @@ static inline void con_debug_leave(void) { }* @CON_NBCON: Console can operate outside of the legacy style console_lock * constraints. * @CON_NBCON_ATOMIC_UNSAFE: The write_atomic() callback is not safe and is -* therefore only used by nbcon_atomic_flush_unsafe(). +* therefore only used by nbcon_atomic_flush_unsafe() and +* nbcon_atomic_unsafe_only_flush(). */ enum cons_flags {CON_PRINTBUFFER =BIT (0 ),
include/linux/printk.h +5 -0
@@ -208,6 +208,7 @@ void printk_legacy_allow_panic_sync(void);extern bool nbcon_device_try_acquire (struct console *con);extern void nbcon_device_release (struct console *con);void nbcon_atomic_flush_unsafe (void ); +void nbcon_atomic_unsafe_only_flush (void );bool pr_flush (int timeout_ms,bool reset_on_progress);#else static inline __printf(1, 0)
@@ -322,6 +323,10 @@ static inline void nbcon_atomic_flush_unsafe(void) { } +static inline void nbcon_atomic_unsafe_only_flush (void ) +{ +} +static inline bool pr_flush (int timeout_ms,bool reset_on_progress) {return true;
kernel/crash_core.c +7 -0
@@ -140,6 +140,13 @@ void __noclone __crash_kexec(struct pt_regs *regs)crash_setup_regs (&fixed_regs, regs);crash_save_vmcoreinfo (); +/* +* Flush the unsafe consoles with the other CPUs +* stopped, before machine_crash_shutdown() tears +* down what they may need. +*/ +crash_smp_send_stop (); +nbcon_atomic_unsafe_only_flush ();machine_crash_shutdown (&fixed_regs);crash_cma_clear_pending_dma ();machine_kexec (kexec_crash_image);
kernel/panic.c +1 -0
@@ -723,6 +723,9 @@ void vpanic(const char *fmt, va_list args) panic_console_replay)console_flush_on_panic (CONSOLE_REPLAY_ALL ); +/* The other CPUs are stopped, flush the unsafe consoles too.
h /tmp/puf_post.sh kerneltest001.31.atn1 6791 atn1a &); (sh /tmp/puf_post.sh kerneltest005.19.atn2 6792 atn2a &) /
+ nbcon_atomic_unsafe_only_flush();
+
if (!panic_blink)
panic_blink = no_blink;
kernel/printk/nbcon.c +21 -3
@@ -1653,8 +1653,9 @@ static void nbcon_atomic_flush_pending_con(struct console *con, u64 stop_seq)* __nbcon_atomic_flush_pending - Flush all nbcon consoles using their * write_atomic() callback * @stop_seq: Flush up until this record +* @unsafe_only: Flush only the CON_NBCON_ATOMIC_UNSAFE consoles */ -static void __nbcon_atomic_flush_pending (u64 stop_seq) +static void __nbcon_atomic_flush_pending (u64 stop_seq,bool unsafe_only) {struct console *con;int cookie;
@@ -1666,6 +1667,9 @@ static void __nbcon_atomic_flush_pending(u64 stop_seq)if (!(flags &CON_NBCON ))continue ; +if (unsafe_only && !(flags &CON_NBCON_ATOMIC_UNSAFE )) +continue ; +if (!console_is_usable (con, flags, true))continue ;
@@ -1688,7 +1692,7 @@ static void __nbcon_atomic_flush_pending(u64 stop_seq)*/ void nbcon_atomic_flush_pending (void ) { -__nbcon_atomic_flush_pending (prb_next_reserve_seq (prb)); +__nbcon_atomic_flush_pending (prb_next_reserve_seq (prb), false); }/**
@@ -1701,7 +1705,21 @@ void nbcon_atomic_flush_pending(void)void nbcon_atomic_flush_unsafe (void ) { panic_nbcon_allow_unsafe_takeover = true; -__nbcon_atomic_flush_pending (prb_next_reserve_seq (prb)); +__nbcon_atomic_flush_pending (prb_next_reserve_seq (prb), false); + panic_nbcon_allow_unsafe_takeover = false; +} + +/** +* nbcon_atomic_unsafe_only_flush - Flush only the CON_NBCON_ATOMIC_UNSAFE +* consoles, allowing unsafe hostile takeovers +* +* Like nbcon_atomic_flush_unsafe(), but consoles with a safe write_atomic() +* are left alone. Meant for the panic CPU once the other CPUs are stopped. +*/ +void nbcon_atomic_unsafe_only_flush (void ) +{ + panic_nbcon_allow_unsafe_takeover = true; +__nbcon_atomic_flush_pending (prb_next_reserve_seq (prb), true); panic_nbcon_allow_unsafe_takeover = false; }
Petr Mladek
maintainerQuoted 41 lines · Breno Leitao
Quoted 7 lines · Petr Mladek
Another question is where to call it. I guess the it should be called in two code paths:
+
__crash_kexec()likely after stopping other CPUs+
console_flush_on_panic()after flushing safe nbcon consoles the safe wayWhat about something like:
commit
de57403441b601af01d92bc03bf0625338d39c80Author: Breno Leitao <[email protected]> Date: Fri Oct 30 10:08:01 2026 -0700panic: flush unsafe consoles before reboot and kdump
netconsole registers with
CON_NBCON_ATOMIC_UNSAFEsince commit7eab73b18630("netconsole: convert to NBCON console infrastructure"), so itswrite_atomic()only runs fromnbcon_atomic_flush_unsafe().vpanic()calls that right before its final busy loop, afteremergency_restart()and after__crash_kexec().A panic that reboots (
panic_timeout!= 0) or boots a crash kernel therefore never reaches the netconsole target. Neither does an oops that goes to kdump throughcrash_kexec(), which skipsvpanic()entirely. Before the conversion, netconsole was a legacy console, flushed byconsole_flush_on_panic()ahead of the reboot.Add
nbcon_atomic_unsafe_only_flush(), which flushes only theCON_NBCON_ATOMIC_UNSAFEconsoles and allows unsafe takeovers on them. Call it on the panic CPU once the other CPUs are stopped, leaving the consoles with a safewrite_atomic()alone.In
vpanic()it runs after the safe flush, whenpanic_other_cpus_shutdown()has stopped the other CPUs. In__crash_kexec()it runs aftercrash_smp_send_stop()and beforemachine_crash_shutdown(), the orderpanic()already uses withcrash_kexec_post_notifiers.
Quoted 5 lines
The call does not go into
console_flush_on_panic(), becausekgdb_panic()calls that before the other CPUs are stopped. It does not go aftermachine_crash_shutdown()either: on TDX gueststdx_kexec_finish()zaps the shared PTEs there, and netconsole on a virtio NIC would touch that memory.
This is the 1st time I hear about it. Does it mean that netconsole should not be called after this point, please?
I wonder how this worked before the netconsole was converted to the NBCON API. I guess that it "worked" because there was neither printk() nor any explicit console flush after this point.
Quoted 6 lines
A
write_atomic()that hangs now keeps the machine from rebooting or from reaching the crash kernel.
kernel/crash_core.c void __noclone __crash_kexec(struct pt_regs *regs) · line 148
Quoted 9 lines
kernel/crash_core.c +6
-0@@ -140,6 +140,13 @@ void __noclone __crash_kexec(struct pt_regs *regs)crash_setup_regs (&fixed_regs, regs);crash_save_vmcoreinfo (); +/* +* Flush the unsafe consoles with the other CPUs +* stopped, before machine_crash_shutdown() tears +* down what they may need. +*/ +crash_smp_send_stop ();
AFAIK, the crashdump currently shows all CPUs online. And the backtrace shows whatever they were doing last.
Stopping the CPUs earlier would change the existing behavior. And we would need to discuss this with crashdump maintainers.
Well, I know that stopping other CPUs makes it more safe. But is it strictly necessary? We did not stop the CPUs when the netconsole was handled by the legacy loop.
Quoted 13 lines
kernel/crash_core.c +1
-0+nbcon_atomic_unsafe_only_flush ();machine_crash_shutdown (&fixed_regs);crash_cma_clear_pending_dma ();machine_kexec (kexec_crash_image);kernel/panic.c +1
-0@@ -723,6 +723,9 @@ void vpanic(const char *fmt, va_list args) panic_console_replay)console_flush_on_panic (CONSOLE_REPLAY_ALL ); +/* The other CPUs are stopped, flush the unsafe consoles too.
Quoted 2 lines
h
/tmp/puf_post.shkerneltest001.31.atn1 6791 atn1a &); (sh/tmp/puf_post.shkerneltest005.19.atn2 6792 atn2a &)
The last two lines are some mess ;-)
kernel/panic.c
Quoted 2 lines
/
kernel/panic.c +1
-0+nbcon_atomic_unsafe_only_flush ();
This might be too early. Anyway, it is before printing the line:
pr_emerg("Rebooting in %d seconds..\n", panic_timeout);I have a crazy idea and do this:
kernel/printk/nbcon.c +14 -1
@@ -1688,7 +1688,20 @@ static void __nbcon_atomic_flush_pending(u64 stop_seq)*/ void nbcon_atomic_flush_pending (void ) { -__nbcon_atomic_flush_pending (prb_next_reserve_seq (prb)); +u64 stop_seq =prb_next_reserve_seq (prb); + +__nbcon_atomic_flush_pending (stop_seq, false); + +/* +* This is a compromise. Otherwise, NBCON consoles would never +* have a chance to show messages in the panic paths where +* the unsafe flush is not explicitely called. +*/ +if (panic_on_this_cpu () && oops_in_progress) { + panic_nbcon_allow_unsafe_takeover = true; +__nbcon_atomic_flush_pending (stop_seq, true); + panic_nbcon_allow_unsafe_takeover = false; + } }
It would allow to flush the messages directly by printk().
I know that it would be a step back in the reliability. But showing the messages looks more important to me than a reliable reboot. And we could make it configurable when needed.
Also we could add more checks. For example, do the unsafe flush only when "num_online_cpus == 1" or so.
Quoted 20 lines
kernel/panic.c +1
-0+if (!panic_blink) panic_blink = no_blink;kernel/printk/nbcon.c +2
-1@@ -1653,8 +1653,9 @@ static void nbcon_atomic_flush_pending_con(struct console *con, u64 stop_seq)* __nbcon_atomic_flush_pending - Flush all nbcon consoles using their * write_atomic() callback * @stop_seq: Flush up until this record +* @unsafe_only: Flush only the CON_NBCON_ATOMIC_UNSAFE consoles */ -static void __nbcon_atomic_flush_pending (u64 stop_seq) +static void __nbcon_atomic_flush_pending (u64 stop_seq,bool unsafe_only) {struct console *con;int cookie;
kernel/printk/nbcon.c static void __nbcon_atomic_flush_pending(u64 stop_seq) · line 1675
Quoted 9 lines
kernel/printk/nbcon.c +3
-0@@ -1666,6 +1667,9 @@ static void __nbcon_atomic_flush_pending(u64 stop_seq)if (!(flags &CON_NBCON ))continue ; +if (unsafe_only && !(flags &CON_NBCON_ATOMIC_UNSAFE )) +continue ; +if (!console_is_usable (con, flags, true))continue ;
This looks good to me.
Quoted 12 lines
kernel/printk/nbcon.c +7
-1@@ -1701,7 +1705,21 @@ void nbcon_atomic_flush_pending(void)void nbcon_atomic_flush_unsafe (void ) { panic_nbcon_allow_unsafe_takeover = true; -__nbcon_atomic_flush_pending (prb_next_reserve_seq (prb)); +__nbcon_atomic_flush_pending (prb_next_reserve_seq (prb), false); + panic_nbcon_allow_unsafe_takeover = false; +} + +/** +* nbcon_atomic_unsafe_only_flush - Flush only the CON_NBCON_ATOMIC_UNSAFE +* consoles, allowing unsafe hostile takeovers
kernel/printk/nbcon.c void nbcon_atomic_flush_pending(void) · line 1724
Quoted 10 lines
kernel/printk/nbcon.c +8
-0+* +* Like nbcon_atomic_flush_unsafe(), but consoles with a safe write_atomic() +* are left alone. Meant for the panic CPU once the other CPUs are stopped. +*/ +void nbcon_atomic_unsafe_only_flush (void ) +{ + panic_nbcon_allow_unsafe_takeover = true; +__nbcon_atomic_flush_pending (prb_next_reserve_seq (prb), true); panic_nbcon_allow_unsafe_takeover = false; }
Also the name nbcon_atomic_unsafe_only_flush() sounds good to me.
Best Regards,
Petr
Quoted 6 lines · Petr Mladek
Quoted 5 lines
The call does not go into
console_flush_on_panic(), becausekgdb_panic()calls that before the other CPUs are stopped. It does not go aftermachine_crash_shutdown()either: on TDX gueststdx_kexec_finish()zaps the shared PTEs there, and netconsole on a virtio NIC would touch that memory.
Quoted 6 lines
This is the 1st time I hear about it. Does it mean that netconsole should not be called after this point, please?
I wonder how this worked before the netconsole was converted to the NBCON API. I guess that it "worked" because there was neither
printk()nor any explicit console flush after this point.
Maybe. Kgdb is being removed so, maybe we don't need it:
https://lore.kernel.org/all/[email protected]/
Quoted 20 lines
Quoted 7 lines
A
write_atomic()that hangs now keeps the machine from rebooting or from reaching the crash kernel.kernel/crash_core.c void __noclone __crash_kexec(struct pt_regs *regs) · line 148
Quoted 9 lines
kernel/crash_core.c +6
-0@@ -140,6 +140,13 @@ void __noclone __crash_kexec(struct pt_regs *regs)crash_setup_regs (&fixed_regs, regs);crash_save_vmcoreinfo (); +/* +* Flush the unsafe consoles with the other CPUs +* stopped, before machine_crash_shutdown() tears +* down what they may need. +*/ +crash_smp_send_stop ();AFAIK, the crashdump currently shows all CPUs online. And the backtrace shows whatever they were doing last.
Quoted 6 lines
Stopping the CPUs earlier would change the existing behavior. And we would need to discuss this with crashdump maintainers.
Well, I know that stopping other CPUs makes it more safe. But is it strictly necessary? We did not stop the CPUs when the netconsole was handled by the legacy loop.
That is fair, I will keep the old/legacy behavior now.
Quoted 12 lines
Quoted 12 lines
kernel/crash_core.c +1
-0+nbcon_atomic_unsafe_only_flush ();machine_crash_shutdown (&fixed_regs);crash_cma_clear_pending_dma ();machine_kexec (kexec_crash_image);kernel/panic.c +0
-0@@ -723,6 +723,9 @@ void vpanic(const char *fmt, va_list args) panic_console_replay)console_flush_on_panic (CONSOLE_REPLAY_ALL );
Quoted 5 lines
Quoted 3 lines
kernel/panic.c +1
-0+/* The other CPUs are stopped, flush the unsafe consoles too. h
/tmp/puf_post.shkerneltest001.31.atn1 6791 atn1a &); (sh/tmp/puf_post.shkerneltest005.19.atn2 6792 atn2a &)The last two lines are some mess ;-)
Damn, sorry, These are my testing hosts I was using to test this patch.
Quoted 35 lines
kernel/panic.c
Quoted 3 lines
/
kernel/panic.c +1
-0+nbcon_atomic_unsafe_only_flush ();This might be too early. Anyway, it is before printing the line:
pr_emerg("Rebooting in %d seconds..\n", panic_timeout);I have a crazy idea and do this:
kernel/printk/nbcon.c +14
-1@@ -1688,7 +1688,20 @@ static void __nbcon_atomic_flush_pending(u64 stop_seq)*/ void nbcon_atomic_flush_pending (void ) { -__nbcon_atomic_flush_pending (prb_next_reserve_seq (prb)); +u64 stop_seq =prb_next_reserve_seq (prb); + +__nbcon_atomic_flush_pending (stop_seq, false); + +/* +* This is a compromise. Otherwise, NBCON consoles would never +* have a chance to show messages in the panic paths where +* the unsafe flush is not explicitely called. +*/ +if (panic_on_this_cpu () && oops_in_progress) { + panic_nbcon_allow_unsafe_takeover = true; +__nbcon_atomic_flush_pending (stop_seq, true); + panic_nbcon_allow_unsafe_takeover = false; + } }It would allow to flush the messages directly by
printk().
Quoted 2 lines
I know that it would be a step back in the reliability. But showing the messages looks more important to me than a reliable reboot.
100% agreed. At Meta, we check if kdump is working or not based on these massages. Given kdump cannot work due to 100 of different issues, this line is more important than kdump by all changes.
Let me play with your crazy idea and see how it goes.
Thanks for helping here,
--breno
John Ogness
maintainerQuoted 27 lines · Petr Mladek
I have a crazy idea and do this:
kernel/printk/nbcon.c +14
-1@@ -1688,7 +1688,20 @@ static void __nbcon_atomic_flush_pending(u64 stop_seq)*/ void nbcon_atomic_flush_pending (void ) { -__nbcon_atomic_flush_pending (prb_next_reserve_seq (prb)); +u64 stop_seq =prb_next_reserve_seq (prb); + +__nbcon_atomic_flush_pending (stop_seq, false); + +/* +* This is a compromise. Otherwise, NBCON consoles would never +* have a chance to show messages in the panic paths where +* the unsafe flush is not explicitely called. +*/ +if (panic_on_this_cpu () && oops_in_progress) { + panic_nbcon_allow_unsafe_takeover = true; +__nbcon_atomic_flush_pending (stop_seq, true); + panic_nbcon_allow_unsafe_takeover = false; + } }It would allow to flush the messages directly by
printk().
Quoted 6 lines
I know that it would be a step back in the reliability. But showing the messages looks more important to me than a reliable reboot. And we could make it configurable when needed.
Also we could add more checks. For example, do the unsafe flush only when "
num_online_cpus== 1" or so.
I can accept this, since legacy-netconsole had these risks anyway. My only concern is when we add an interface for the unsafe flushing policy, will we continue to have unsafe flushing be the default for netconsole? I guess we would need to keep it the same to avoid regressions (just as we need to have it on by default now).
John
Petr Mladek
maintainerQuoted 32 lines · John Ogness
Quoted 31 lines · Petr Mladek
I have a crazy idea and do this:
kernel/printk/nbcon.c +14
-1@@ -1688,7 +1688,20 @@ static void __nbcon_atomic_flush_pending(u64 stop_seq)*/ void nbcon_atomic_flush_pending (void ) { -__nbcon_atomic_flush_pending (prb_next_reserve_seq (prb)); +u64 stop_seq =prb_next_reserve_seq (prb); + +__nbcon_atomic_flush_pending (stop_seq, false); + +/* +* This is a compromise. Otherwise, NBCON consoles would never +* have a chance to show messages in the panic paths where +* the unsafe flush is not explicitely called. +*/ +if (panic_on_this_cpu () && oops_in_progress) { + panic_nbcon_allow_unsafe_takeover = true; +__nbcon_atomic_flush_pending (stop_seq, true); + panic_nbcon_allow_unsafe_takeover = false; + } }It would allow to flush the messages directly by
printk().I know that it would be a step back in the reliability. But showing the messages looks more important to me than a reliable reboot. And we could make it configurable when needed.
Quoted 8 lines
Quoted 2 lines
Also we could add more checks. For example, do the unsafe flush only when "
num_online_cpus== 1" or so.I can accept this, since legacy-netconsole had these risks anyway. My only concern is when we add an interface for the unsafe flushing policy, will we continue to have unsafe flushing be the default for netconsole? I guess we would need to keep it the same to avoid regressions (just as we need to have it on by default now).
Good point. I think that this basically goes down to the question whether we would later introduce an option:
--panic-focus-on-debug or --panic-focus-on-reboot
The current state is somewhere in the middle. I would say that:
+ the legacy consoles are more focusing on the debugging side because bust_spinlocks() is called early. And console_flush_on_panic() is called before emergency_restart().
+ the nbcon console are more focusing on safe reboot because nbcon_atomic_flush_unsafe() is called only when followed by an infinite diod blinking.
It looked like the nbcon handling was good enough before we added netconsole with an unsafe write_atomic. And maybe even before converting the widely used uart 8250 serial console driver.
People started complaining about missing messages with the converted netconsole and uart 8250 drivers. The current nbcon handling looks like a regression to these people.
My take would be to modify the nbcon handling to be more like the legacy one and focus more on debugging. If anyone gets concerned by the reboot reliability then we could add the --panic-focus-on-reboot and make the reboot more safe in this case.
How does that sound, please?
Best Regards,
Petr
John Ogness
maintainerQuoted 14 lines · Petr Mladek
Quoted 5 lines
I can accept this, since legacy-netconsole had these risks anyway. My only concern is when we add an interface for the unsafe flushing policy, will we continue to have unsafe flushing be the default for netconsole? I guess we would need to keep it the same to avoid regressions (just as we need to have it on by default now).
Good point. I think that this basically goes down to the question whether we would later introduce an option:
--panic-focus-on-debug or --panic-focus-on-rebootThe current state is somewhere in the middle. I would say that:
Quoted 7 lines
+ the legacy consoles are more focusing on the debugging side because
bust_spinlocks()is called early. Andconsole_flush_on_panic()is called beforeemergency_restart().+ the nbcon console are more focusing on safe reboot because
nbcon_atomic_flush_unsafe()is called only when followed by an infinite diod blinking.
Note that this difference between legacy and nbcon was one of the primary design goals for nbcon. It is not chance that we are avoiding "hope and pray mode".
Quoted 8 lines
It looked like the nbcon handling was good enough before we added netconsole with an unsafe
write_atomic. And maybe even before converting the widely used uart 8250 serial console driver.People started complaining about missing messages with the converted netconsole and uart 8250 drivers. The current nbcon handling looks like a regression to these people.
Please let's not throw everything into the same pot. The reported missing 8250 messages are real regressions due to missing flushes. These must be fixed.
The netconsole issue is separate. Unlike 8250, the netconsole does not provide a safe variant. This is also a regression, but for different reasons.
And maybe users want safe drivers (such as 8250) to enter "hope and pray mode" on kernel ending sites, which is something even legacy consoles could not always do.
Quoted 5 lines
My take would be to modify the nbcon handling to be more like the legacy one and focus more on debugging. If anyone gets concerned by the reboot reliability then we could add the --panic-focus-on-reboot and make the reboot more safe in this case.
I prefer we do not hard-code policies. It would be trivial to add a policy field and flags to the console struct. We could allow drivers to declare their own diverging defaults if they want. When we are touching all these flush sites, let us add code guided by policy instead of hard-coding policy.
And _later_, once we have /sys/class/consoles, it becomes trivial to expose these policies to userspace for reading/modifying.
John
Petr Mladek
maintainerQuoted 36 lines · John Ogness
Quoted 14 lines · Petr Mladek
Quoted 5 lines
I can accept this, since legacy-netconsole had these risks anyway. My only concern is when we add an interface for the unsafe flushing policy, will we continue to have unsafe flushing be the default for netconsole? I guess we would need to keep it the same to avoid regressions (just as we need to have it on by default now).
Good point. I think that this basically goes down to the question whether we would later introduce an option:
--panic-focus-on-debug or --panic-focus-on-rebootThe current state is somewhere in the middle. I would say that:
Quoted 7 lines
+ the legacy consoles are more focusing on the debugging side because
bust_spinlocks()is called early. Andconsole_flush_on_panic()is called beforeemergency_restart().+ the nbcon console are more focusing on safe reboot because
nbcon_atomic_flush_unsafe()is called only when followed by an infinite diod blinking.Note that this difference between legacy and nbcon was one of the primary design goals for nbcon. It is not chance that we are avoiding "hope and pray mode".
Quoted 8 lines
It looked like the nbcon handling was good enough before we added netconsole with an unsafe
write_atomic. And maybe even before converting the widely used uart 8250 serial console driver.People started complaining about missing messages with the converted netconsole and uart 8250 drivers. The current nbcon handling looks like a regression to these people.
Quoted 7 lines
Please let's not throw everything into the same pot. The reported missing 8250 messages are real regressions due to missing flushes. These must be fixed.
The netconsole issue is separate. Unlike 8250, the netconsole does not provide a safe variant. This is also a regression, but for different reasons.
Just to explain. I reacted on the sentence:
"My only concern is when we add an interface for the unsafe flushing policy,
will we continue to have unsafe flushing be the default for netconsole?"
I wanted to point out that the recent reports about missing messages from both act 8250 and netconsole were seen as regressions. And we should try to make it behave as before.
But you are right that the there is a difference. The messages were missing with:
+ UAW 8250 because of bugs. All nbcon consoles relayed on kthreads in situations where they did not worked. We are solving this by explicitly switching to the atomic mode or by an explicit flush.
+ netconsole by design. The netconsole does not have a safe write_atomic() callback. We should allow unsafe takeover in some situations.
Now, the question is where to allow the unsafe takeover for netconsole. I guess that we will need to allow it in similar situations where people complained about DAR 8250 driver, or pl011, e.g. even in emergency_restart().
Quoted 3 lines
And maybe users want safe drivers (such as 8250) to enter "hope and pray mode" on kernel ending sites, which is something even legacy consoles could not always do.
I think that I finally understand your concern. You would like to add a per-console flag for "debugging" or "safe" mode. But it might be weird when:
+ netconsole is in the "debugging" mode by default.
+ other serial consoles are in the "safe" mode by default.
Do I get it correctly, please?
Quoted 6 lines
Quoted 5 lines
My take would be to modify the nbcon handling to be more like the legacy one and focus more on debugging. If anyone gets concerned by the reboot reliability then we could add the --panic-focus-on-reboot and make the reboot more safe in this case.
Quoted 8 lines
I prefer we do not hard-code policies. It would be trivial to add a policy field and flags to the console struct. We could allow drivers to declare their own diverging defaults if they want. When we are touching all these flush sites, let us add code guided by policy instead of hard-coding policy.
And _later_, once we have
/sys/class/consoles, it becomes trivial to expose these policies to userspace for reading/modifying.
I think that we should avoid people reporting regressions so that we should allow unsafe takeover for the netconsole where reasonable by default.
I see two solutions:
1. Keep all NBCON consoles consistent and allow unsafe takeover on more locations, independently whether they have safe or unsafe write_atomic().
2. Allow the unsafe takeover on more locations only for netconsole. And later allow to set both per-console policies: "debugging" vs. "safe". And accept that netconsole has different default policy.
I personally prefer the 2nd solution. Netconsole has always been a bit special. And maybe someone would implement the safe write_atomic in the future which will make it more normal, ...
Best Regards,
Petr
John Ogness
maintainerQuoted 11 lines · Petr Mladek
Quoted 3 lines
And maybe users want safe drivers (such as 8250) to enter "hope and pray mode" on kernel ending sites, which is something even legacy consoles could not always do.
I think that I finally understand your concern. You would like to add a per-console flag for "debugging" or "safe" mode. But it might be weird when:
+ netconsole is in the "debugging" mode by default.
+ other serial consoles are in the "safe" mode by default.
Yes. Although I would not call it "debugging" and "safe".
Quoted 6 lines
I see two solutions:
1. Keep all NBCON consoles consistent and allow unsafe takeover on more locations, independently whether they have safe or unsafe
write_atomic().
Quoted 8 lines
2. Allow the unsafe takeover on more locations only for netconsole. And later allow to set both per-console policies: "debugging" vs. "safe". And accept that netconsole has different default policy.
I personally prefer the 2nd solution. Netconsole has always been a bit special. And maybe someone would implement the safe
write_atomicin the future which will make it more normal, ...
I agree. I am preparing a patch that should allow exactly that and hopefully make my idea with the policies clear.
John
John Ogness
maintainerQuoted 5 lines · Breno Leitao
kernel/crash_core.c +0
-0
kernel/crash_core.c void __noclone __crash_kexec(struct pt_regs *regs) · line 148
Quoted 9 lines
kernel/crash_core.c +6
-0@@ -140,6 +140,13 @@ void __noclone __crash_kexec(struct pt_regs *regs)crash_setup_regs (&fixed_regs, regs);crash_save_vmcoreinfo (); +/* +* Flush the unsafe consoles with the other CPUs +* stopped, before machine_crash_shutdown() tears +* down what they may need. +*/ +crash_smp_send_stop ();
I advise against this if it is just for console flushing since it is changing behavior. If it is generally a good idea, then ok.
Quoted 9 lines
kernel/crash_core.c +1
-0+nbcon_atomic_unsafe_only_flush ();machine_crash_shutdown (&fixed_regs);crash_cma_clear_pending_dma ();machine_kexec (kexec_crash_image);kernel/panic.c +0
-0
kernel/panic.c void vpanic(const char *fmt, va_list args) · line 728
Quoted 6 lines
kernel/panic.c +3
-0@@ -723,6 +723,9 @@ void vpanic(const char *fmt, va_list args) panic_console_replay)console_flush_on_panic (CONSOLE_REPLAY_ALL ); +/* The other CPUs are stopped, flush the unsafe consoles too. +nbcon_atomic_unsafe_only_flush(); +
As Petr mentioned, this is too early. It should be after the final printk().
Quoted 49 lines
kernel/panic.c +0
-0if (!panic_blink) panic_blink = no_blink;kernel/printk/nbcon.c +13
-3@@ -1653,8 +1653,9 @@ static void nbcon_atomic_flush_pending_con(struct console *con, u64 stop_seq)* __nbcon_atomic_flush_pending - Flush all nbcon consoles using their * write_atomic() callback * @stop_seq: Flush up until this record +* @unsafe_only: Flush only the CON_NBCON_ATOMIC_UNSAFE consoles */ -static void __nbcon_atomic_flush_pending (u64 stop_seq) +static void __nbcon_atomic_flush_pending (u64 stop_seq,bool unsafe_only) {struct console *con;int cookie;@@ -1666,6 +1667,9 @@ static void __nbcon_atomic_flush_pending(u64 stop_seq)if (!(flags &CON_NBCON ))continue ; +if (unsafe_only && !(flags &CON_NBCON_ATOMIC_UNSAFE )) +continue ; +if (!console_is_usable (con, flags, true))continue ;@@ -1688,7 +1692,7 @@ static void __nbcon_atomic_flush_pending(u64 stop_seq)*/ void nbcon_atomic_flush_pending (void ) { -__nbcon_atomic_flush_pending (prb_next_reserve_seq (prb)); +__nbcon_atomic_flush_pending (prb_next_reserve_seq (prb), false); }/** @@ -1701,7 +1705,21 @@ void nbcon_atomic_flush_pending(void)void nbcon_atomic_flush_unsafe (void ) { panic_nbcon_allow_unsafe_takeover = true; -__nbcon_atomic_flush_pending (prb_next_reserve_seq (prb)); +__nbcon_atomic_flush_pending (prb_next_reserve_seq (prb), false); + panic_nbcon_allow_unsafe_takeover = false; +} + +/** +* nbcon_atomic_unsafe_only_flush - Flush only the CON_NBCON_ATOMIC_UNSAFE +* consoles, allowing unsafe hostile takeovers
kernel/printk/nbcon.c void nbcon_atomic_flush_pending(void) · line 1724
Quoted 10 lines
kernel/printk/nbcon.c +8
-0+* +* Like nbcon_atomic_flush_unsafe(), but consoles with a safe write_atomic() +* are left alone. Meant for the panic CPU once the other CPUs are stopped. +*/ +void nbcon_atomic_unsafe_only_flush (void ) +{ + panic_nbcon_allow_unsafe_takeover = true; +__nbcon_atomic_flush_pending (prb_next_reserve_seq (prb), true); panic_nbcon_allow_unsafe_takeover = false; }
The rest looks ok to me.
John