public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Steven Rostedt <rostedt@goodmis.org>
To: linux-kernel@vger.kernel.org
Cc: Ingo Molnar <mingo@elte.hu>,
	Andrew Morton <akpm@linux-foundation.org>,
	Frederic Weisbecker <fweisbec@gmail.com>,
	Vaibhav Nagarnaik <vnagarnaik@google.com>
Subject: [PATCH 04/15] ring-buffer: Add integrity check at end of iter read
Date: Fri, 18 May 2012 09:09:02 -0400	[thread overview]
Message-ID: <20120518131048.332990942@goodmis.org> (raw)
In-Reply-To: 20120518130858.392919640@goodmis.org

[-- Attachment #1: Type: text/plain, Size: 2441 bytes --]

From: Steven Rostedt <srostedt@redhat.com>

There use to be ring buffer integrity checks after updating the
size of the ring buffer. But now that the ring buffer can modify
the size while the system is running, the integrity checks were
removed, as they require the ring buffer to be disabed to perform
the check.

Move the integrity check to the reading of the ring buffer via the
iterator reads (the "trace" file). As reading via an iterator requires
disabling the ring buffer, it is a perfect place to have it.

If the ring buffer happens to be disabled when updating the size,
we still perform the integrity check.

Cc: Vaibhav Nagarnaik <vnagarnaik@google.com>
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
---
 kernel/trace/ring_buffer.c |   29 +++++++++++++++++++++++++++++
 1 file changed, 29 insertions(+)

diff --git a/kernel/trace/ring_buffer.c b/kernel/trace/ring_buffer.c
index d673ef0..e0573c5 100644
--- a/kernel/trace/ring_buffer.c
+++ b/kernel/trace/ring_buffer.c
@@ -1599,6 +1599,29 @@ int ring_buffer_resize(struct ring_buffer *buffer, unsigned long size,
 	}
 
  out:
+	/*
+	 * The ring buffer resize can happen with the ring buffer
+	 * enabled, so that the update disturbs the tracing as little
+	 * as possible. But if the buffer is disabled, we do not need
+	 * to worry about that, and we can take the time to verify
+	 * that the buffer is not corrupt.
+	 */
+	if (atomic_read(&buffer->record_disabled)) {
+		atomic_inc(&buffer->record_disabled);
+		/*
+		 * Even though the buffer was disabled, we must make sure
+		 * that it is truly disabled before calling rb_check_pages.
+		 * There could have been a race between checking
+		 * record_disable and incrementing it.
+		 */
+		synchronize_sched();
+		for_each_buffer_cpu(buffer, cpu) {
+			cpu_buffer = buffer->buffers[cpu];
+			rb_check_pages(cpu_buffer);
+		}
+		atomic_dec(&buffer->record_disabled);
+	}
+
 	mutex_unlock(&buffer->mutex);
 	return size;
 
@@ -3750,6 +3773,12 @@ ring_buffer_read_finish(struct ring_buffer_iter *iter)
 {
 	struct ring_buffer_per_cpu *cpu_buffer = iter->cpu_buffer;
 
+	/*
+	 * Ring buffer is disabled from recording, here's a good place
+	 * to check the integrity of the ring buffer. 
+	 */
+	rb_check_pages(cpu_buffer);
+
 	atomic_dec(&cpu_buffer->record_disabled);
 	atomic_dec(&cpu_buffer->buffer->resize_disabled);
 	kfree(iter);
-- 
1.7.10



[-- Attachment #2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 836 bytes --]

  parent reply	other threads:[~2012-05-18 13:14 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-05-18 13:08 [PATCH 00/15] [GIT PULL] tracing: Updates for 3.5 Steven Rostedt
2012-05-18 13:08 ` [PATCH 01/15] tracing: Clean up tracing_mark_write() Steven Rostedt
2012-05-18 13:09 ` [PATCH 02/15] ring-buffer: Make removal of ring buffer pages atomic Steven Rostedt
2012-05-18 13:09 ` [PATCH 03/15] ring-buffer: Make addition of pages in ring buffer atomic Steven Rostedt
2012-05-18 13:09 ` Steven Rostedt [this message]
2012-05-18 13:09 ` [PATCH 05/15] ring-buffer: Reset head page before running self test Steven Rostedt
2012-05-18 13:09 ` [PATCH 06/15] tracing: Check return value of tracing_dentry_percpu() Steven Rostedt
2012-05-18 13:09 ` [PATCH 07/15] tracing: change CPU ring buffer state from tracing_cpumask Steven Rostedt
2012-05-18 13:09 ` [PATCH 08/15] ftrace: Sort all function addresses, not just per page Steven Rostedt
2012-05-18 13:09 ` [PATCH 09/15] ftrace: Remove extra helper functions Steven Rostedt
2012-05-18 13:09 ` [PATCH 10/15] ftrace: Speed up search by skipping pages by address Steven Rostedt
2012-05-18 13:09 ` [PATCH 11/15] ftrace: Consolidate ftrace_location() and ftrace_text_reserved() Steven Rostedt
2012-05-18 13:09 ` [PATCH 12/15] ftrace: Return record ip addr for ftrace_location() Steven Rostedt
2012-05-18 14:19   ` Masami Hiramatsu
2012-05-18 13:09 ` [PATCH 13/15] ftrace: Make ftrace_modify_all_code() global for archs to use Steven Rostedt
2012-05-18 13:09 ` [PATCH 14/15] ftrace/x86: Have x86 ftrace use the ftrace_modify_all_code() Steven Rostedt
2012-05-18 13:09 ` [PATCH 15/15] ftrace: Remove selecting FRAME_POINTER with FUNCTION_TRACER Steven Rostedt
2012-05-19  1:43 ` [PATCH 00/15] [GIT PULL] tracing: Updates for 3.5 Steven Rostedt
2012-05-19 10:12   ` Ingo Molnar
2012-05-19 12:25     ` Steven Rostedt

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=20120518131048.332990942@goodmis.org \
    --to=rostedt@goodmis.org \
    --cc=akpm@linux-foundation.org \
    --cc=fweisbec@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@elte.hu \
    --cc=vnagarnaik@google.com \
    /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