Skip to content

Commit 2a78b85

Browse files
b49020Daniel Thompson
authored andcommitted
kdb: Make kdb_printf() console handling more robust
While rounding up CPUs via NMIs, its possible that a rounded up CPU maybe holding a console port lock leading to kgdb master CPU stuck in a deadlock during invocation of console write operations. A similar deadlock could also be possible while using synchronous breakpoints. So in order to avoid such a deadlock, set oops_in_progress to encourage the console drivers to disregard their internal spin locks: in the current calling context the risk of deadlock is a bigger problem than risks due to re-entering the console driver. We operate directly on oops_in_progress rather than using bust_spinlocks() because the calls bust_spinlocks() makes on exit are not appropriate for this calling context. Suggested-by: Sergey Senozhatsky <[email protected]> Signed-off-by: Sumit Garg <[email protected]> Reviewed-by: Douglas Anderson <[email protected]> Reviewed-by: Petr Mladek <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Daniel Thompson <[email protected]>
1 parent e885728 commit 2a78b85

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

kernel/debug/kdb/kdb_io.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -562,7 +562,18 @@ static void kdb_msg_write(const char *msg, int msg_len)
562562
for_each_console(c) {
563563
if (!(c->flags & CON_ENABLED))
564564
continue;
565+
/*
566+
* Set oops_in_progress to encourage the console drivers to
567+
* disregard their internal spin locks: in the current calling
568+
* context the risk of deadlock is a bigger problem than risks
569+
* due to re-entering the console driver. We operate directly on
570+
* oops_in_progress rather than using bust_spinlocks() because
571+
* the calls bust_spinlocks() makes on exit are not appropriate
572+
* for this calling context.
573+
*/
574+
++oops_in_progress;
565575
c->write(c, msg, msg_len);
576+
--oops_in_progress;
566577
touch_nmi_watchdog();
567578
}
568579
}

0 commit comments

Comments
 (0)