[PATCH v9 12/21] ring-buffer: Avoid reader_lock deadlock during panic

From: Vincent Donnefort

Date: Tue Nov 24 2026 - 10:30:25 EST


Although reader_lock is taken with IRQs disabled, panic shutdown can
stop CPUs with NMIs (most likely if the first attempt with maskable
interrupts failed). Those NMIs may stop a CPU while it holds the
reader_lock. Use trylock when panic_on_this_cpu() just like in_nmi().

Fixes: 289a5a25c5d0 ("ring-buffer: Give NMIs a chance to lock the reader_lock")
Reported-by: Sashiko <sashiko-bot@xxxxxxxxxx>
Closes: https://lore.kernel.org/linux-trace-kernel/20260924151509.23AEE1F000FF@xxxxxxxxxxxxxxx/
Signed-off-by: Vincent Donnefort <vdonnefort@xxxxxxxxxx>
---
kernel/trace/ring_buffer.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/kernel/trace/ring_buffer.c b/kernel/trace/ring_buffer.c
index 928fdd4718ea..42507e97291f 100644
--- a/kernel/trace/ring_buffer.c
+++ b/kernel/trace/ring_buffer.c
@@ -22,6 +22,7 @@
#include <linux/kthread.h> /* for self test */
#include <linux/module.h>
#include <linux/percpu.h>
+#include <linux/panic.h>
#include <linux/mutex.h>
#include <linux/delay.h>
#include <linux/slab.h>
@@ -6323,7 +6324,7 @@ EXPORT_SYMBOL_GPL(ring_buffer_iter_peek);

static inline bool rb_reader_lock(struct ring_buffer_per_cpu *cpu_buffer)
{
- if (likely(!in_nmi())) {
+ if (likely(!in_nmi() && !panic_on_this_cpu())) {
raw_spin_lock(&cpu_buffer->reader_lock);
return true;
}
--
2.56.1.809.ga0b61035b5-goog