linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Steven Rostedt <rostedt@goodmis.org>
To: linux-kernel@vger.kernel.org
Cc: Ingo Molnar <mingo@kernel.org>,
	Andrew Morton <akpm@linux-foundation.org>,
	stable@vger.kernel.org
Subject: [for-linus][PATCH 12/12] ring-buffer: Always check to put back before stamp when crossing pages
Date: Tue, 01 Dec 2020 10:58:47 -0500	[thread overview]
Message-ID: <20201201160006.827647495@goodmis.org> (raw)
In-Reply-To: 20201201155835.647858317@goodmis.org

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

The current ring buffer logic checks to see if the updating of the event
buffer was interrupted, and if it is, it will try to fix up the before stamp
with the write stamp to make them equal again. This logic is flawed, because
if it is not interrupted, the two are guaranteed to be different, as the
current event just updated the before stamp before allocation. This
guarantees that the next event (this one or another interrupting one) will
think it interrupted the time updates of a previous event and inject an
absolute time stamp to compensate.

The correct logic is to always update the timestamps when traversing to a
new sub buffer.

Cc: stable@vger.kernel.org
Fixes: a389d86f7fd09 ("ring-buffer: Have nested events still record running time stamp")
Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
---
 kernel/trace/ring_buffer.c | 14 ++++++--------
 1 file changed, 6 insertions(+), 8 deletions(-)

diff --git a/kernel/trace/ring_buffer.c b/kernel/trace/ring_buffer.c
index 35d91b20d47a..a6268e09160a 100644
--- a/kernel/trace/ring_buffer.c
+++ b/kernel/trace/ring_buffer.c
@@ -3234,14 +3234,12 @@ __rb_reserve_next(struct ring_buffer_per_cpu *cpu_buffer,
 
 	/* See if we shot pass the end of this buffer page */
 	if (unlikely(write > BUF_PAGE_SIZE)) {
-		if (tail != w) {
-			/* before and after may now different, fix it up*/
-			b_ok = rb_time_read(&cpu_buffer->before_stamp, &info->before);
-			a_ok = rb_time_read(&cpu_buffer->write_stamp, &info->after);
-			if (a_ok && b_ok && info->before != info->after)
-				(void)rb_time_cmpxchg(&cpu_buffer->before_stamp,
-						      info->before, info->after);
-		}
+		/* before and after may now different, fix it up*/
+		b_ok = rb_time_read(&cpu_buffer->before_stamp, &info->before);
+		a_ok = rb_time_read(&cpu_buffer->write_stamp, &info->after);
+		if (a_ok && b_ok && info->before != info->after)
+			(void)rb_time_cmpxchg(&cpu_buffer->before_stamp,
+					      info->before, info->after);
 		return rb_move_tail(cpu_buffer, tail, info);
 	}
 
-- 
2.28.0



      parent reply	other threads:[~2020-12-01 16:01 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-12-01 15:58 [for-linus][PATCH 00/12] tracing: Fixes for 5.10-rc6 Steven Rostedt
2020-12-01 15:58 ` [for-linus][PATCH 01/12] tools/bootconfig: Fix errno reference after printf() Steven Rostedt
2020-12-01 15:58 ` [for-linus][PATCH 02/12] tools/bootconfig: Fix to check the write failure correctly Steven Rostedt
2020-12-01 15:58 ` [for-linus][PATCH 03/12] tools/bootconfig: Align the bootconfig applied initrd image size to 4 Steven Rostedt
2020-12-01 15:58 ` [for-linus][PATCH 04/12] docs: bootconfig: Update file format on initrd image Steven Rostedt
2020-12-01 15:58 ` [for-linus][PATCH 05/12] ring-buffer: Update write stamp with the correct ts Steven Rostedt
2020-12-01 15:58 ` [for-linus][PATCH 06/12] ring-buffer: Set the right timestamp in the slow path of __rb_reserve_next() Steven Rostedt
2020-12-01 15:58 ` [for-linus][PATCH 07/12] samples/ftrace: Mark my_tramp[12]? global Steven Rostedt
2020-12-01 15:58 ` [for-linus][PATCH 08/12] tracing: Remove WARN_ON in start_thread() Steven Rostedt
2020-12-01 15:58 ` [for-linus][PATCH 09/12] tracing: Fix alignment of static buffer Steven Rostedt
2020-12-01 15:58 ` [for-linus][PATCH 10/12] ftrace: Fix updating FTRACE_FL_TRAMP Steven Rostedt
2020-12-01 15:58 ` [for-linus][PATCH 11/12] ftrace: Fix DYNAMIC_FTRACE_WITH_DIRECT_CALLS dependency Steven Rostedt
2020-12-01 15:58 ` Steven Rostedt [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20201201160006.827647495@goodmis.org \
    --to=rostedt@goodmis.org \
    --cc=akpm@linux-foundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@kernel.org \
    --cc=stable@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).