From: sashiko-bot@kernel.org
To: "Vincent Donnefort" <vdonnefort@google.com>,
linux-trace-kernel@vger.kernel.org
Subject: Re: [PATCH v10 11/19] ring-buffer: Use panic-friendly locking in ring_buffer_iter interface
Date: Thu, 03 Dec 2026 19:38:14 +0000 [thread overview]
Message-ID: <sashiko-outbox-248526@kernel.org> (raw)
In-Reply-To: <20261203190007.2431041-12-vdonnefort@google.com>
Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [High] ring-buffer: rb_reader_lock() still deadlocks on non-NMI panics
- [Medium] ring-buffer: lockless rb_inc_iter() can dereference NULL or
loop forever
--
commit b583ab4b894210054f1b1cf5e2a158a5ba95e6c9
Author: Vincent Donnefort <vdonnefort@google.com>
ring-buffer: Use panic-friendly locking in ring_buffer_iter interface
This commit switches ring_buffer_iter_reset(), ring_buffer_iter_peek(), and
ring_buffer_iter_advance() from raw_spin_lock_irqsave() to local_irq_save()
and rb_reader_lock() in preparation for dumping remote buffers on panic.
> diff --git a/kernel/trace/ring_buffer.c b/kernel/trace/ring_buffer.c
> index 554013a189b96..9b8b6133bce87 100644
> --- a/kernel/trace/ring_buffer.c
> +++ b/kernel/trace/ring_buffer.c
[ ... ]
> @@ -5707,15 +5710,18 @@ void ring_buffer_iter_reset(struct ring_buffer_iter *iter)
> {
> struct ring_buffer_per_cpu *cpu_buffer;
> unsigned long flags;
> + bool dolock;
>
> if (!iter)
> return;
>
> cpu_buffer = iter->cpu_buffer;
>
> - raw_spin_lock_irqsave(&cpu_buffer->reader_lock, flags);
> + local_irq_save(flags);
> + dolock = rb_reader_lock(cpu_buffer);
> rb_iter_reset(iter);
> - raw_spin_unlock_irqrestore(&cpu_buffer->reader_lock, flags);
> + rb_reader_unlock(cpu_buffer, dolock);
> + local_irq_restore(flags);
> }
> EXPORT_SYMBOL_GPL(ring_buffer_iter_reset);
[Severity: High]
Can rb_reader_lock() still deadlock on cpu_buffer->reader_lock during
non-NMI panics?
rb_reader_lock() only uses raw_spin_trylock() when in_nmi() is true, and
otherwise calls blocking raw_spin_lock(). Because ring_buffer_poll_remote()
acquires cpu_buffer->reader_lock with IRQs enabled, a normal stop IPI from
panic_other_cpus_shutdown() can halt a CPU while it holds the lock:
CPU0 CPU1
ring_buffer_poll_remote()
lock(&cpu_buffer->reader_lock)
vpanic()
panic_other_cpus_shutdown()
<stop IPI, halted>
panic_notifier_list
...
ring_buffer_iter_reset()
rb_reader_lock()
raw_spin_lock(...)
<-- spins forever
The same deadlock also occurs in ring_buffer_iter_peek() and
ring_buffer_iter_advance(), or when an NMI stop fallback halts an
IRQ-disabled reader. The panicking CPU then hangs inside the panic notifier
chain before console flush, kdump, or reboot can run. Should
rb_reader_lock() also check panic_in_progress()?
[ ... ]
> @@ -6414,11 +6420,14 @@ ring_buffer_iter_peek(struct ring_buffer_iter *iter, u64 *ts)
> struct ring_buffer_per_cpu *cpu_buffer = iter->cpu_buffer;
> struct ring_buffer_event *event;
> unsigned long flags;
> + bool dolock;
>
> again:
> - raw_spin_lock_irqsave(&cpu_buffer->reader_lock, flags);
> + local_irq_save(flags);
> + dolock = rb_reader_lock(cpu_buffer);
> event = rb_iter_peek(iter, ts);
> - raw_spin_unlock_irqrestore(&cpu_buffer->reader_lock, flags);
> + rb_reader_unlock(cpu_buffer, dolock);
> + local_irq_restore(flags);
>
> if (event && event->type_len == RINGBUF_TYPE_PADDING)
> goto again;
[Severity: Medium]
Can lockless rb_inc_iter() dereference a NULL iter->head_page when
rb_reader_lock() fails to acquire reader_lock?
When rb_reader_lock() returns false, rb_iter_peek() and rb_advance_iter()
run without cpu_buffer->reader_lock and call rb_inc_iter() when advancing
off cpu_buffer->reader_page:
kernel/trace/ring_buffer.c:rb_inc_iter() {
...
if (iter->head_page == cpu_buffer->reader_page)
iter->head_page = rb_set_head_page(cpu_buffer);
else
rb_inc_page(&iter->head_page);
if (rb_page_commit(iter->head_page) & RB_MISSED_EVENTS)
iter->missed_events = -1;
iter->page_stamp = iter->read_stamp = iter->head_page->page->time_stamp;
}
If the interrupted reader_lock holder was between rb_list_head_clear() and
rb_set_list_to_head() (for example in rb_update_remote_head() or
__rb_get_reader_page_from_remote()), rb_set_head_page() returns NULL and
rb_inc_iter() crashes with a NULL pointer dereference, aborting the panic
dump.
If __rb_get_reader_page_from_remote() was interrupted while prev_head was
detached and RB_PAGE_HEAD was cleared, rb_set_head_page() can also loop
forever walking the ring without ever reaching the detached head. In
addition, on remote buffers atomic_inc(&cpu_buffer->record_disabled) in
rb_reader_lock() does not stop the remote producer, while lockless
rb_iter_reset() -> rb_update_remote_head() still mutates shared
cpu_buffer->head_page, cpu_buffer->commit_page, and RB_PAGE_HEAD bits.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261203190007.2431041-1-vdonnefort@google.com?part=11
next prev parent reply other threads:[~2026-12-03 19:38 UTC|newest]
Thread overview: 33+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-03 18:59 [PATCH v10 00/19] tracing/remotes: Add printk, dump_on_panic and boot parameters Vincent Donnefort
2026-12-03 18:59 ` [PATCH v10 01/19] tracing/remotes: Gate tracefs files opening on trace remote registration Vincent Donnefort
2026-12-03 19:20 ` sashiko-bot
2026-12-03 18:59 ` [PATCH v10 02/19] tracing/remotes: Release tracefs,eventfs on registration failure Vincent Donnefort
2026-12-03 19:24 ` sashiko-bot
2026-12-03 18:59 ` [PATCH v10 03/19] tracing/remotes: Use kstrtobool for boolean tracefs files Vincent Donnefort
2026-12-03 18:59 ` [PATCH v10 04/19] tracing/remotes: Initialise pos in trace_start() Vincent Donnefort
2026-12-03 19:18 ` sashiko-bot
2026-12-03 18:59 ` [PATCH v10 05/19] tracing/remotes: Annotate remote shared fields with READ_ONCE/WRITE_ONCE Vincent Donnefort
2026-12-03 19:19 ` sashiko-bot
2026-12-03 18:59 ` [PATCH v10 06/19] tracing/remotes: Use a single per-remote polling work Vincent Donnefort
2026-12-03 18:59 ` [PATCH v10 07/19] tracing/simple_ring_buffer: Add support for compressed length Vincent Donnefort
2026-12-03 18:59 ` [PATCH v10 08/19] tracing/remotes: Add dmesg tracefs file Vincent Donnefort
2026-12-03 19:43 ` sashiko-bot
2026-12-03 18:59 ` [PATCH v10 09/19] tracing/remotes: selftests: Add a test for the " Vincent Donnefort
2026-12-03 19:39 ` sashiko-bot
2026-12-03 18:59 ` [PATCH v10 10/19] tracing/remotes: selftests: Prefix hypervisor folder Vincent Donnefort
2026-12-03 18:59 ` [PATCH v10 11/19] ring-buffer: Use panic-friendly locking in ring_buffer_iter interface Vincent Donnefort
2026-12-03 19:38 ` sashiko-bot [this message]
2026-12-03 19:00 ` [PATCH v10 12/19] ring-buffer: Add kerneldoc for ring_buffer_poll_remote Vincent Donnefort
2026-12-03 19:00 ` [PATCH v10 13/19] tracing/remotes: Use ring_buffer_capacity() in trace_remote_has_cpu() Vincent Donnefort
2026-12-03 19:00 ` [PATCH v10 14/19] tracing/remotes: Add dump_on_panic tracefs file Vincent Donnefort
2026-12-03 19:52 ` sashiko-bot
2026-12-03 19:00 ` [PATCH v10 15/19] tracing/remotes: selftests: Add a test for the " Vincent Donnefort
2026-12-03 19:50 ` sashiko-bot
2026-12-03 19:00 ` [PATCH v10 16/19] tracing/remotes: Add poll_ms " Vincent Donnefort
2026-12-03 19:50 ` sashiko-bot
2026-12-03 19:00 ` [PATCH v10 17/19] tracing/remotes: Add trace_remote cmdline options Vincent Donnefort
2026-12-03 19:58 ` sashiko-bot
2026-12-03 19:00 ` [PATCH v10 18/19] Documentation: tracing/remotes: Add detailed tracefs layout Vincent Donnefort
2026-12-03 19:48 ` sashiko-bot
2026-12-03 19:00 ` [PATCH v10 19/19] Documentation/kernel-parameters: Add trace_remote Vincent Donnefort
2026-12-03 19:53 ` sashiko-bot
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=sashiko-outbox-248526@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=linux-trace-kernel@vger.kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
--cc=vdonnefort@google.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.