Skip to contentSkip to conversation

FAILED: patch "[PATCH] tracing: Wake up ring buffer waiters on closing of the file" failed to apply to 4.9-stable tree

PATCH [email protected] 1 participant 1 message Oct 16, 2022

Subsystems (2)
lore
Share & tools
lore

[email protected]

author maintainer
#0 lore raw

The patch below does not apply to the 4.9-stable tree.
If someone wants it applied there, or to any other stable or longterm tree, then please email the backport, including the original git commit id to <[email protected]>.

Possible dependencies:

f3ddb74ad079 ("tracing: Wake up ring buffer waiters on closing of the file") efbbdaa22bb7 ("tracing: Show real address for trace event arguments") 8e99cf91b99b ("tracing: Do not allocate buffer in trace_find_next_entry() in atomic") ff895103a84a ("tracing: Save off entry when peeking at next entry") 03329f993978 ("tracing: Add tracefs file buffer_percentage") 2c2b0a78b373 ("ring-buffer: Add percentage of ring buffer full to wake up reader") 2c1ea60b195d ("tracing: Add timestamp_mode trace file")
00b4145298ae ("ring-buffer: Add interface for setting absolute time stamps") ecf927000ce3 ("ring_buffer_poll_wait() return value used as return value of ->poll()") 065e63f95143 ("tracing: Only have rmmod clear buffers that its events were active in") dc8d387210e3 ("tracing: Update Documentation/trace/ftrace.txt")

thanks,

greg k-h

------------------ original commit in Linus's tree ------------------

From f3ddb74ad0790030c9592229fb14d8c451f4e9a8 Mon Sep 17 00:00:00 2001
From: "Steven Rostedt (Google)" <[email protected]>
Date: Tue, 27 Sep 2022 19:15:27 -0400
Subject: [PATCH] tracing: Wake up ring buffer waiters on closing of the file

When the file that represents the ring buffer is closed, there may be waiters waiting on more input from the ring buffer. Call ring_buffer_wake_waiters() to wake up any waiters when the file is closed.

Cc Ingo Molnar <[email protected]>
Cc Andrew Morton <[email protected]>
Fixes e30f53aad2202 ("tracing: Do not busy wait in buffer splice")
include/linux/trace_events.h +1 -0
index 8401dec93c15..20749bd9db71 100644
@@ -92,6 +92,7 @@ struct trace_iterator {
 	unsigned int		temp_size;
 	char			*fmt;	/* modified format holder */
 	unsigned int		fmt_size;
+	long			wait_index;
 
 	/* trace_seq for __print_flags() and __print_symbolic() etc. */
 	struct trace_seq	tmp_seq;
kernel/trace/trace.c +15 -0
index aed7ea6e6045..e101b0764b39 100644
@@ -8160,6 +8160,12 @@ static int tracing_buffers_release(struct inode *inode, struct file *file)
 
 	__trace_array_put(iter->tr);
 
+	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);
+
 	if (info->spare)
 		ring_buffer_free_read_page(iter->array_buffer->buffer,
 					   info->spare_cpu, info->spare);
@@ -8313,6 +8319,8 @@ tracing_buffers_splice_read(struct file *file, loff_t *ppos,
 
 	/* did we read anything? */
 	if (!spd.nr_pages) {
+		long wait_index;
+
 		if (ret)
 			goto out;
 
@@ -8320,10 +8328,17 @@ tracing_buffers_splice_read(struct file *file, loff_t *ppos,
 		if ((file->f_flags & O_NONBLOCK) || (flags & SPLICE_F_NONBLOCK))
 			goto out;
 
+		wait_index = READ_ONCE(iter->wait_index);
+
 		ret = wait_on_pipe(iter, iter->tr->buffer_percent);
 		if (ret)
 			goto out;
 
+		/* Make sure we see the new wait_index */
+		smp_rmb();
+		if (wait_index != iter->wait_index)
+			goto out;
+
 		goto again;
 	}