kbuffer: Always walk the events to calculate timestamp in kbuffer_read_buffer()

If the buffer to read the kbuffer subbuffer is big enough to hold the
entire buffer, it was simply copied. But this is not good enough, as the
next read should include the events after what was copied. That means the
timestamps need to be calculated.

Just copying the data is not enough as the timestamp of any event is an
offset of the previous event. To know the event timestamp after what was
copied, the timestamps of the events before it need to be read, to know
what the offset is against of the following event.

Link: https://lore.kernel.org/linux-trace-devel/ZZwFvyGvm0C38eBh@google.com/
Link: https://lore.kernel.org/linux-trace-devel/20240108123420.5e227075@gandalf.local.home

Fixes: 05821189 ("kbuffer: Add kbuffer_read_buffer()")
Reported-by: Vincent Donnefort <vdonnefort@google.com>
Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
1 file changed