diff options
author | Steven Rostedt (Google) <rostedt@goodmis.org> | 2024-01-09 15:48:59 -0500 |
---|---|---|
committer | Steven Rostedt (Google) <rostedt@goodmis.org> | 2024-01-09 21:50:19 -0500 |
commit | 28eebc1a65f19899c91ef41fbf3d7751835b40ea (patch) | |
tree | 5e80016b0e7883609940323af909039fde4926ed | |
parent | 065d914b4b8be049764de44945a6ccff33a976d6 (diff) | |
download | libtracefs-28eebc1a65f19899c91ef41fbf3d7751835b40ea.tar.gz |
libtracefs: Have tracefs_cpu_flush(_buf)() use mapping
If the tracefs_cpu is opened with tracefs_cpu_open_mapped() and uses
tracefs_cpu_read_buf() along with tracefs_cpu_flush_buf(), the flush will
load the tcpu->kbuf with a new buffer which may make the one in the mmapped
out of sync.
If the tcpu is mapped, make sure tracefs_cpu_flush() and
tracefs_cpu_flush_buf() also use the mapping.
Link: https://lore.kernel.org/linux-trace-devel/20240109205112.74225-5-rostedt@goodmis.org
Cc: Vincent Donnefort <vdonnefort@google.com>
Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
-rw-r--r-- | src/tracefs-record.c | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/src/tracefs-record.c b/src/tracefs-record.c index 4a59c61..fca3ddf 100644 --- a/src/tracefs-record.c +++ b/src/tracefs-record.c @@ -690,6 +690,9 @@ int tracefs_cpu_flush(struct tracefs_cpu *tcpu, void *buffer) if (tcpu->buffered < 0) tcpu->buffered = 0; + if (tcpu->mapping) + return trace_mmap_read(tcpu->mapping, buffer); + if (tcpu->buffered) { ret = read(tcpu->splice_pipe[0], buffer, tcpu->subbuf_size); if (ret > 0) @@ -729,6 +732,13 @@ struct kbuffer *tracefs_cpu_flush_buf(struct tracefs_cpu *tcpu) if (!get_buffer(tcpu)) return NULL; + if (tcpu->mapping) { + /* Make sure that reading is now non blocking */ + set_nonblock(tcpu); + ret = trace_mmap_load_subbuf(tcpu->mapping, tcpu->kbuf); + return ret > 0 ? tcpu->kbuf : NULL; + } + ret = tracefs_cpu_flush(tcpu, tcpu->buffer); if (ret <= 0) return NULL; |