[patch RFC 29/29] printk: Add atomic write enforcement to warn/panic...

From: Thomas Gleixner
Date: Sat Sep 10 2022 - 18:30:59 EST


Signed-off-by: John Ogness <jogness@xxxxxxxxxxxxx>

Invoke the atomic write enforcement functions for warn/panic to ensure that
the information gets out to the consoles.

This is not yet a final solution as this still unlocks consoles and depends
on the "reliablity" of legacy consoles which are invoked during printk().

Once the legacy is converted over this can be changed to lock consoles on
entry, print undisturbed and release them on exit.

Signed-off-by: John Ogness <jogness@xxxxxxxxxxxxx>
Signed-off-by: Thomas Gleixner <tglx@xxxxxxxxxxxxx>
---
kernel/panic.c | 12 ++++++++++++
1 file changed, 12 insertions(+)

--- a/kernel/panic.c
+++ b/kernel/panic.c
@@ -256,6 +256,12 @@ void panic(const char *fmt, ...)
if (old_cpu != PANIC_CPU_INVALID && old_cpu != this_cpu)
panic_smp_self_stop();

+ /*
+ * No point in saving the previous printk severity level
+ * here. Panic won't come back
+ */
+ cons_atomic_enter(CONS_PRIO_PANIC);
+
console_verbose();
bust_spinlocks(1);
va_start(args, fmt);
@@ -602,6 +608,10 @@ struct warn_args {
void __warn(const char *file, int line, void *caller, unsigned taint,
struct pt_regs *regs, struct warn_args *args)
{
+ enum cons_prio prev_prio;
+
+ prev_prio = cons_atomic_enter(CONS_PRIO_EMERGENCY);
+
disable_trace_on_warning();

if (file)
@@ -633,6 +643,8 @@ void __warn(const char *file, int line,

/* Just a warning, don't kill lockdep. */
add_taint(taint, LOCKDEP_STILL_OK);
+
+ cons_atomic_exit(CONS_PRIO_EMERGENCY, prev_prio);
}

#ifndef __WARN_FLAGS