[RFC PATCH 0/2] Introduce KGDB_DEBUG_SPINLOCKS

From: Daniel Thompson
Date: Fri May 22 2020 - 10:55:29 EST


The execution context for kgdb/kdb is pretty much unique. We are running
a debug trap handler with all CPUs parked in a holding loop and with
interrupts disabled. At least one CPU is in an unknowable execution
state (could be NMI, IRQ, irqs disabled, etc) and the others are either
servicing an IRQ or NMI depending on architecture.

Breakpoints (including some implicit breakpoints when serious errors
are detected) can happen on more or less any context, including when we
own important spin locks.

As such spin lock waits should never happen whilst we are executing the
kgdb trap handler used except, occasionally, via an explicit command
from a (forewarned?) local operator.

Currently kdb doesn't meet this criteria (although I think kgdb does)
so I started thinking about what tooling we could employ to reinforce
code review and bring problems to the surface.

The result is a patch that extends DEBUG_SPINLOCKS and checks whether
the execution context is safe. The "except via an explicit command"
aspect (mentioned above) convinced me to make the checks conditional
on KGDB_DEBUG_SPINLOCKS.

Daniel Thompson (2):
debug: Convert dbg_slave_lock to an atomic
locking/spinlock/debug: Add checks for kgdb trap safety

include/linux/kgdb.h | 16 ++++++++++++++++
kernel/debug/debug_core.c | 8 ++++----
kernel/locking/spinlock_debug.c | 4 ++++
lib/Kconfig.kgdb | 11 +++++++++++
4 files changed, 35 insertions(+), 4 deletions(-)


base-commit: 6a8b55ed4056ea5559ebe4f6a4b247f627870d4c
--
2.25.4