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@kernel.org>
Closes: https://lore.kernel.org/linux-trace-kernel/20260924151509.23AEE1F000FF@smtp.kernel.org/ (local)
Signed-off-by: Vincent Donnefort <vdonnefort@google.com>
---
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 4dab77883bd5..0dc661a95d67 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>
@@ -6297,7 +6298,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.0.455.g6c5a503b38-goog