* [PATCH] ring-buffer: Acquire the lock with irqsave in rb_wake_up_waiters()
@ 2026-09-11 10:21 Sebastian Andrzej Siewior
2026-09-11 17:17 ` Vincent Donnefort
0 siblings, 1 reply; 2+ messages in thread
From: Sebastian Andrzej Siewior @ 2026-09-11 10:21 UTC (permalink / raw)
To: linux-trace-kernel, linux-rt-devel
Cc: Steven Rostedt, Masami Hiramatsu, Mathieu Desnoyers,
Sebastian Andrzej Siewior, Clark Williams
rb_wake_up_waiters() is a irq_work callback which is initialized with
init_irq_work(). As such it will be invoked in thread context on
PREEMPT_RT. Invoking the callback in IRQ context on PREEMPT_RT is not an
option due its usage of wake_up_all().
Since this callback may run in thread context, it needs to acqurie
ring_buffer_per_cpu::reader_lock with disabling interrupts and may not
assume that they are disabled.
Use raw_spinlock_irqsave() to acquire ring_buffer_per_cpu::reader_lock.
Fixes: 68282dd930ea3 ("ring-buffer: Fix resetting of shortest_full")
Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
---
kernel/trace/ring_buffer.c | 13 ++++++-------
1 file changed, 6 insertions(+), 7 deletions(-)
diff --git a/kernel/trace/ring_buffer.c b/kernel/trace/ring_buffer.c
index 9c03a555a6ba2..681f9daf6fabb 100644
--- a/kernel/trace/ring_buffer.c
+++ b/kernel/trace/ring_buffer.c
@@ -904,14 +904,13 @@ static void rb_wake_up_waiters(struct irq_work *work)
struct ring_buffer_per_cpu *cpu_buffer =
container_of(rbwork, struct ring_buffer_per_cpu, irq_work);
- /* Called from interrupt context */
- raw_spin_lock(&cpu_buffer->reader_lock);
- rbwork->wakeup_full = false;
- rbwork->full_waiters_pending = false;
+ scoped_guard(raw_spinlock_irqsave, &cpu_buffer->reader_lock) {
+ rbwork->wakeup_full = false;
+ rbwork->full_waiters_pending = false;
- /* Waking up all waiters, they will reset the shortest full */
- cpu_buffer->shortest_full = 0;
- raw_spin_unlock(&cpu_buffer->reader_lock);
+ /* Waking up all waiters, they will reset the shortest full */
+ cpu_buffer->shortest_full = 0;
+ }
wake_up_all(&rbwork->full_waiters);
}
--
2.55.0
^ permalink raw reply related [flat|nested] 2+ messages in thread* Re: [PATCH] ring-buffer: Acquire the lock with irqsave in rb_wake_up_waiters()
2026-09-11 10:21 [PATCH] ring-buffer: Acquire the lock with irqsave in rb_wake_up_waiters() Sebastian Andrzej Siewior
@ 2026-09-11 17:17 ` Vincent Donnefort
0 siblings, 0 replies; 2+ messages in thread
From: Vincent Donnefort @ 2026-09-11 17:17 UTC (permalink / raw)
To: Sebastian Andrzej Siewior
Cc: linux-trace-kernel, linux-rt-devel, Steven Rostedt,
Masami Hiramatsu, Mathieu Desnoyers, Clark Williams
On Fri, Sep 11, 2026 at 12:21:52PM +0200, Sebastian Andrzej Siewior wrote:
> rb_wake_up_waiters() is a irq_work callback which is initialized with
> init_irq_work(). As such it will be invoked in thread context on
> PREEMPT_RT. Invoking the callback in IRQ context on PREEMPT_RT is not an
> option due its usage of wake_up_all().
> Since this callback may run in thread context, it needs to acqurie
nit: typo "acquire"
> ring_buffer_per_cpu::reader_lock with disabling interrupts and may not
> assume that they are disabled.
>
> Use raw_spinlock_irqsave() to acquire ring_buffer_per_cpu::reader_lock.
>
> Fixes: 68282dd930ea3 ("ring-buffer: Fix resetting of shortest_full")
> Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
> ---
> kernel/trace/ring_buffer.c | 13 ++++++-------
> 1 file changed, 6 insertions(+), 7 deletions(-)
>
> diff --git a/kernel/trace/ring_buffer.c b/kernel/trace/ring_buffer.c
> index 9c03a555a6ba2..681f9daf6fabb 100644
> --- a/kernel/trace/ring_buffer.c
> +++ b/kernel/trace/ring_buffer.c
> @@ -904,14 +904,13 @@ static void rb_wake_up_waiters(struct irq_work *work)
> struct ring_buffer_per_cpu *cpu_buffer =
> container_of(rbwork, struct ring_buffer_per_cpu, irq_work);
>
> - /* Called from interrupt context */
> - raw_spin_lock(&cpu_buffer->reader_lock);
> - rbwork->wakeup_full = false;
> - rbwork->full_waiters_pending = false;
> + scoped_guard(raw_spinlock_irqsave, &cpu_buffer->reader_lock) {
> + rbwork->wakeup_full = false;
> + rbwork->full_waiters_pending = false;
>
> - /* Waking up all waiters, they will reset the shortest full */
> - cpu_buffer->shortest_full = 0;
> - raw_spin_unlock(&cpu_buffer->reader_lock);
> + /* Waking up all waiters, they will reset the shortest full */
> + cpu_buffer->shortest_full = 0;
> + }
>
> wake_up_all(&rbwork->full_waiters);
> }
> --
> 2.55.0
>
>
Reviewed-by: Vincent Donnefort <vdonnefort@google.com>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-09-11 17:18 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-09-11 10:21 [PATCH] ring-buffer: Acquire the lock with irqsave in rb_wake_up_waiters() Sebastian Andrzej Siewior
2026-09-11 17:17 ` Vincent Donnefort
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox