Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

ring-buffer: Set the right timestamp in the slow path of __rb_reserve_next()

In the slow path of __rb_reserve_next() a nested event(s) can happen
between evaluating the timestamp delta of the current event and updating
write_stamp via local_cmpxchg(); in this case the delta is not valid
anymore and it should be set to 0 (same timestamp as the interrupting
event), since the event that we are currently processing is not the last
event in the buffer.

Link: https://lkml.kernel.org/r/X8IVJcp1gRE+FJCJ@xps-13-7390

Cc: Ingo Molnar <mingo@redhat.com>
Cc: Masami Hiramatsu <mhiramat@kernel.org>
Cc: stable@vger.kernel.org
Link: https://lwn.net/Articles/831207
Fixes: a389d86f7fd0 ("ring-buffer: Have nested events still record running time stamp")
Signed-off-by: Andrea Righi <andrea.righi@canonical.com>
Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org>

authored by

Andrea Righi and committed by
Steven Rostedt (VMware)
8785f51a 55ea4cf4

+3 -3
+3 -3
kernel/trace/ring_buffer.c
··· 3287 3287 ts = rb_time_stamp(cpu_buffer->buffer); 3288 3288 barrier(); 3289 3289 /*E*/ if (write == (local_read(&tail_page->write) & RB_WRITE_MASK) && 3290 - info->after < ts) { 3290 + info->after < ts && 3291 + rb_time_cmpxchg(&cpu_buffer->write_stamp, 3292 + info->after, ts)) { 3291 3293 /* Nothing came after this event between C and E */ 3292 3294 info->delta = ts - info->after; 3293 - (void)rb_time_cmpxchg(&cpu_buffer->write_stamp, 3294 - info->after, ts); 3295 3295 info->ts = ts; 3296 3296 } else { 3297 3297 /*