This is a note to let you know that I've just added the patch titled tracing: Add ioctl() to force ring buffer waiters to wake up to the 5.15-stable tree which can be found at: http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary The filename of the patch is: tracing-add-ioctl-to-force-ring-buffer-waiters-to-wake-up.patch and it can be found in the queue-5.15 subdirectory. If you, or anyone else, feels it should not be added to the stable tree, please let <stable@xxxxxxxxxxxxxxx> know about it. >From 01b2a52171735c6eea80ee2f355f32bea6c41418 Mon Sep 17 00:00:00 2001 From: "Steven Rostedt (Google)" <rostedt@xxxxxxxxxxx> Date: Thu, 29 Sep 2022 09:50:29 -0400 Subject: tracing: Add ioctl() to force ring buffer waiters to wake up From: Steven Rostedt (Google) <rostedt@xxxxxxxxxxx> commit 01b2a52171735c6eea80ee2f355f32bea6c41418 upstream. If a process is waiting on the ring buffer for data, there currently isn't a clean way to force it to wake up. Add an ioctl call that will force any tasks that are waiting on the trace_pipe_raw file to wake up. Link: https://lkml.kernel.org/r/20220929095029.117f913f@xxxxxxxxxxxxxxxxxx Cc: stable@xxxxxxxxxxxxxxx Cc: Ingo Molnar <mingo@xxxxxxxxxx> Cc: Andrew Morton <akpm@xxxxxxxxxxxxxxxxxxxx> Fixes: e30f53aad2202 ("tracing: Do not busy wait in buffer splice") Signed-off-by: Steven Rostedt (Google) <rostedt@xxxxxxxxxxx> Signed-off-by: Greg Kroah-Hartman <gregkh@xxxxxxxxxxxxxxxxxxx> --- kernel/trace/trace.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) --- a/kernel/trace/trace.c +++ b/kernel/trace/trace.c @@ -8310,12 +8310,34 @@ out: return ret; } +/* An ioctl call with cmd 0 to the ring buffer file will wake up all waiters */ +static long tracing_buffers_ioctl(struct file *file, unsigned int cmd, unsigned long arg) +{ + struct ftrace_buffer_info *info = file->private_data; + struct trace_iterator *iter = &info->iter; + + if (cmd) + return -ENOIOCTLCMD; + + mutex_lock(&trace_types_lock); + + iter->wait_index++; + /* Make sure the waiters see the new wait_index */ + smp_wmb(); + + ring_buffer_wake_waiters(iter->array_buffer->buffer, iter->cpu_file); + + mutex_unlock(&trace_types_lock); + return 0; +} + static const struct file_operations tracing_buffers_fops = { .open = tracing_buffers_open, .read = tracing_buffers_read, .poll = tracing_buffers_poll, .release = tracing_buffers_release, .splice_read = tracing_buffers_splice_read, + .unlocked_ioctl = tracing_buffers_ioctl, .llseek = no_llseek, }; Patches currently in stable-queue which might be from rostedt@xxxxxxxxxxx are queue-5.15/tracing-fix-reading-strings-from-synthetic-events.patch queue-5.15/tracing-add-ioctl-to-force-ring-buffer-waiters-to-wake-up.patch queue-5.15/ring-buffer-have-the-shortest_full-queue-be-the-shortest-not-longest.patch queue-5.15/ring-buffer-add-ring_buffer_wake_waiters.patch queue-5.15/tracing-move-duplicate-code-of-trace_kprobe-eprobe.c-into-header.patch queue-5.15/tracing-add-fault-name-injection-to-kernel-probes.patch queue-5.15/ring-buffer-fix-race-between-reset-page-and-reading-page.patch queue-5.15/tracing-wake-up-ring-buffer-waiters-on-closing-of-the-file.patch queue-5.15/tracing-disable-interrupt-or-preemption-before-acquiring-arch_spinlock_t.patch queue-5.15/tracing-wake-up-waiters-when-tracing-is-disabled.patch queue-5.15/ring-buffer-allow-splice-to-read-previous-partially-read-pages.patch queue-5.15/ring-buffer-check-pending-waiters-when-doing-wake-ups-as-well.patch queue-5.15/ftrace-properly-unset-ftrace_hash_fl_mod.patch