All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] libtracefs: Update the kbuf for previous read in trace_mmap_load_subbuf()
@ 2024-01-23 17:33 Steven Rostedt
  2024-01-23 17:41 ` Vincent Donnefort
  0 siblings, 1 reply; 5+ messages in thread
From: Steven Rostedt @ 2024-01-23 17:33 UTC (permalink / raw)
  To: Linux Trace Devel; +Cc: Vincent Donnefort

From: "Steven Rostedt (Google)" <rostedt@goodmis.org>

The trace_mmap() checks if the mmapped data has any previously read data
(the reader.read value of the meta page is non-zero), then it will pre-read
the kbuf to move its internal reader pointer to the same value.

But when tracefs_cpu_read_buf() calls trace_mmap_load_subbuf(), its
kbuf->subbuffer will not be the same as the mapped data and
kbuffer_load_subbuffer() is called on it and it is returned. But that means
its read pointer has not been updated, and the read data will restart again.

When the kbuf is updated in trace_mmap_load_subbuf() check the tmap->kbuf to
see if it already read any of the data, and move the kbuffer forward just
like the trace_mmap() does.

Link: https://lore.kernel.org/linux-trace-devel/Za-Md51snPcIoYFn@google.com/

Fixes: 2ed14b59 ("libtracefs: Add ring buffer memory mapping APIs")
Reported-by: Vincent Donnefort <vdonnefort@google.com>
Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
---
 src/tracefs-mmap.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/src/tracefs-mmap.c b/src/tracefs-mmap.c
index d3af453..a288677 100644
--- a/src/tracefs-mmap.c
+++ b/src/tracefs-mmap.c
@@ -165,6 +165,12 @@ __hidden int trace_mmap_load_subbuf(void *mapping, struct kbuffer *kbuf)
 	 */
 	if (data != kbuffer_subbuffer(kbuf)) {
 		kbuffer_load_subbuffer(kbuf, data);
+		/* Move the read pointer forward if need be */
+		if (kbuffer_curr_index(tmap->kbuf)) {
+			int size = kbuffer_curr_offset(tmap->kbuf);
+			char tmpbuf[size];
+			kbuffer_read_buffer(kbuf, tmpbuf, size);
+		}
 		return 1;
 	}
 
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2024-01-24 17:56 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-01-23 17:33 [PATCH] libtracefs: Update the kbuf for previous read in trace_mmap_load_subbuf() Steven Rostedt
2024-01-23 17:41 ` Vincent Donnefort
2024-01-24 16:56   ` Steven Rostedt
2024-01-24 17:54     ` Vincent Donnefort
2024-01-24 17:58       ` Steven Rostedt

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.