From: Steven Rostedt <rostedt@goodmis.org>
To: linux-kernel@vger.kernel.org
Cc: Ingo Molnar <mingo@elte.hu>, Andrew Morton <akpm@linux-foundation.org>
Subject: [PATCH 2/5] ring-buffer: Check if ring buffer iterator has stale data
Date: Tue, 26 Jan 2010 17:09:25 -0500 [thread overview]
Message-ID: <20100126221712.676452282@goodmis.org> (raw)
In-Reply-To: 20100126220923.534282809@goodmis.org
[-- Attachment #1: 0002-ring-buffer-Check-if-ring-buffer-iterator-has-stale-.patch --]
[-- Type: text/plain, Size: 2358 bytes --]
From: Steven Rostedt <srostedt@redhat.com>
Usually reads of the ring buffer is performed by a single task.
There are two types of reads from the ring buffer.
One is a consuming read which will consume the entry that was read
and the next read will be the entry that follows.
The other is an iterator that will let the user read the contents of
the ring buffer without modifying it. When an iterator is allocated,
writes to the ring buffer are disabled to protect the iterator.
The problem exists when consuming reads happen while an iterator is
allocated. Specifically, the kind of read that swaps out an entire
page (used by splice) and replaces it with a new read. If the iterator
is on the page that is swapped out, then the next read may read
from this swapped out page and return garbage.
This patch adds a check when reading the iterator to make sure that
the iterator contents are still valid. If a consuming read has taken
place, the iterator is reset.
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
---
kernel/trace/ring_buffer.c | 13 +++++++++++++
1 files changed, 13 insertions(+), 0 deletions(-)
diff --git a/kernel/trace/ring_buffer.c b/kernel/trace/ring_buffer.c
index edefe3b..503b630 100644
--- a/kernel/trace/ring_buffer.c
+++ b/kernel/trace/ring_buffer.c
@@ -464,6 +464,8 @@ struct ring_buffer_iter {
struct ring_buffer_per_cpu *cpu_buffer;
unsigned long head;
struct buffer_page *head_page;
+ struct buffer_page *cache_reader_page;
+ unsigned long cache_read;
u64 read_stamp;
};
@@ -2716,6 +2718,8 @@ static void rb_iter_reset(struct ring_buffer_iter *iter)
iter->read_stamp = cpu_buffer->read_stamp;
else
iter->read_stamp = iter->head_page->page->time_stamp;
+ iter->cache_reader_page = cpu_buffer->reader_page;
+ iter->cache_read = cpu_buffer->read;
}
/**
@@ -3066,6 +3070,15 @@ rb_iter_peek(struct ring_buffer_iter *iter, u64 *ts)
cpu_buffer = iter->cpu_buffer;
buffer = cpu_buffer->buffer;
+ /*
+ * Check if someone performed a consuming read to
+ * the buffer. A consuming read invalidates the iterator
+ * and we need to reset the iterator in this case.
+ */
+ if (unlikely(iter->cache_read != cpu_buffer->read ||
+ iter->cache_reader_page != cpu_buffer->reader_page))
+ rb_iter_reset(iter);
+
again:
/*
* We repeat when a timestamp is encountered.
--
1.6.5
next prev parent reply other threads:[~2010-01-26 22:17 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-01-26 22:09 [PATCH 0/5][GIT PULL][v2.6.33] tracing: fixes and documentation updates Steven Rostedt
2010-01-26 22:09 ` [PATCH 1/5] tracing: Prevent kernel oops with corrupted buffer Steven Rostedt
2010-01-26 22:32 ` Andrew Morton
2010-01-26 22:39 ` Frederic Weisbecker
2010-01-26 23:20 ` Steven Rostedt
2010-01-26 23:24 ` Steven Rostedt
2010-01-26 22:09 ` Steven Rostedt [this message]
2010-01-26 22:09 ` [PATCH 3/5] ring-buffer: Check for end of page in iterator Steven Rostedt
2010-01-26 22:09 ` [PATCH 4/5] tracing/documentation: Fix a typo in ftrace.txt Steven Rostedt
2010-01-26 22:09 ` [PATCH 5/5] tracing/documentation: Cover new frame pointer semantics Steven Rostedt
2010-01-27 9:37 ` [PATCH 0/5][GIT PULL][v2.6.33] tracing: fixes and documentation updates Ingo Molnar
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=20100126221712.676452282@goodmis.org \
--to=rostedt@goodmis.org \
--cc=akpm@linux-foundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@elte.hu \
/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