printk: nbcon: Add unsafe flushing on panic

BugLink: https://bugs.launchpad.net/bugs/2060704

Add nbcon_atomic_flush_unsafe() to flush all nbcon consoles
using the write_atomic() callback and allowing unsafe hostile
takeovers. Call this at the end of panic() as a final attempt
to flush any pending messages.

Note that legacy consoles use unsafe methods for flushing
from the beginning of panic (see bust_spinlocks()). Therefore,
systems using both legacy and nbcon consoles may still fail to
see panic messages due to unsafe legacy console usage.

Signed-off-by: John Ogness <john.ogness@linutronix.de>
Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
Signed-off-by: Kevin Becker <kevin.becker@canonical.com>
This commit is contained in:
John Ogness
2023-10-20 10:03:42 +00:00
committed by Kevin Becker
parent 34946627e6
commit a28d7db6ef
3 changed files with 27 additions and 5 deletions
+5
View File
@@ -197,6 +197,7 @@ extern asmlinkage void dump_stack(void) __cold;
void printk_trigger_flush(void);
extern void nbcon_driver_acquire(struct console *con);
extern void nbcon_driver_release(struct console *con);
void nbcon_atomic_flush_unsafe(void);
#else
static inline __printf(1, 0)
int vprintk(const char *s, va_list args)
@@ -285,6 +286,10 @@ static inline void nbcon_driver_release(struct console *con)
{
}
static inline void nbcon_atomic_flush_unsafe(void)
{
}
#endif
bool this_cpu_in_panic(void);
+1
View File
@@ -453,6 +453,7 @@ void panic(const char *fmt, ...)
* Explicitly flush the kernel log buffer one last time.
*/
console_flush_on_panic(CONSOLE_FLUSH_PENDING);
nbcon_atomic_flush_unsafe();
local_irq_enable();
for (i = 0; ; i += PANIC_TIMER_STEP) {
+21 -5
View File
@@ -1033,6 +1033,7 @@ bool nbcon_legacy_emit_next_record(struct console *con, bool *handover,
* write_atomic() callback
* @con: The nbcon console to flush
* @stop_seq: Flush up until this record
* @allow_unsafe_takeover: True, to allow unsafe hostile takeovers
*
* Return: True if taken over while printing. Otherwise false.
*
@@ -1041,7 +1042,8 @@ bool nbcon_legacy_emit_next_record(struct console *con, bool *handover,
* there are no more records available to read or this context is not allowed
* to acquire the console.
*/
static bool __nbcon_atomic_flush_pending_con(struct console *con, u64 stop_seq)
static bool __nbcon_atomic_flush_pending_con(struct console *con, u64 stop_seq,
bool allow_unsafe_takeover)
{
struct nbcon_write_context wctxt = { };
struct nbcon_context *ctxt = &ACCESS_PRIVATE(&wctxt, ctxt);
@@ -1049,6 +1051,7 @@ static bool __nbcon_atomic_flush_pending_con(struct console *con, u64 stop_seq)
ctxt->console = con;
ctxt->spinwait_max_us = 2000;
ctxt->prio = nbcon_get_default_prio();
ctxt->allow_unsafe_takeover = allow_unsafe_takeover;
if (!nbcon_context_try_acquire(ctxt))
return false;
@@ -1075,8 +1078,9 @@ static bool __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
* @allow_unsafe_takeover: True, to allow unsafe hostile takeovers
*/
static void __nbcon_atomic_flush_pending(u64 stop_seq)
static void __nbcon_atomic_flush_pending(u64 stop_seq, bool allow_unsafe_takeover)
{
struct console *con;
bool should_retry;
@@ -1109,8 +1113,8 @@ static void __nbcon_atomic_flush_pending(u64 stop_seq)
*/
local_irq_save(irq_flags);
should_retry |= __nbcon_atomic_flush_pending_con(con, stop_seq);
should_retry |= __nbcon_atomic_flush_pending_con(con, stop_seq,
allow_unsafe_takeover);
local_irq_restore(irq_flags);
}
console_srcu_read_unlock(cookie);
@@ -1127,7 +1131,19 @@ 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);
}
/**
* nbcon_atomic_flush_unsafe - Flush all nbcon consoles using their
* write_atomic() callback and allowing unsafe hostile takeovers
*
* Flush the backlog up through the currently newest record. Unsafe hostile
* takeovers will be performed, if necessary.
*/
void nbcon_atomic_flush_unsafe(void)
{
__nbcon_atomic_flush_pending(prb_next_reserve_seq(prb), true);
}
/**