From: Philippe Elie <phil.el@wanadoo.fr>
To: linux-kernel@vger.kernel.org
Cc: Linus Torvalds <torvalds@linux-foundation.org>,
Andrew Morton <akpm@linux-foundation.org>,
Sami Farin <safari-kernel@safari.iki.fi>
Subject: [patch 1/2] oProfile: oops when profile_pc() return ~0LU
Date: Sun, 21 Oct 2007 14:08:42 +0200 [thread overview]
Message-ID: <20071021120842.GA2886@zaniah> (raw)
From: Philippe Elie <phil.el@wanadoo.fr>
Instruction pointer returned by profile_pc() can be a random value. This
break the assumption than we can safely set struct op_sample.eip field to
a magic value to signal to the per-cpu buffer reader side special event
like task switch ending up in a segfault in get_task_mm() when profile_pc()
return ~0UL. Fixed by exchanging the meaning of eip/event field for these
specials events.
Special thanks to Sami Farin who reported the oops and helped patiently
to narrow down the problem.
CC: Andrew Morton <akpm@linux-foundation.org>
CC: Linus Torvalds <torvalds@linux-foundation.org>
CC: Sami Farin <safari-kernel@safari.iki.fi>
---
drivers/oprofile/buffer_sync.c | 12 ++++++------
drivers/oprofile/cpu_buffer.c | 2 +-
2 files changed, 7 insertions(+), 7 deletions(-)
Beside Sami, Jesse Barnes already reported this bug two years ago
but I've been unable to understand it at this time.
diff --git a/drivers/oprofile/buffer_sync.c b/drivers/oprofile/buffer_sync.c
index 8134c7e..7a4ccc7 100644
--- a/drivers/oprofile/buffer_sync.c
+++ b/drivers/oprofile/buffer_sync.c
@@ -514,21 +514,21 @@ void sync_buffer(int cpu)
for (i = 0; i < available; ++i) {
struct op_sample * s = &cpu_buf->buffer[cpu_buf->tail_pos];
- if (is_code(s->eip)) {
- if (s->event <= CPU_IS_KERNEL) {
+ if (is_code(s->event)) {
+ if (s->eip <= CPU_IS_KERNEL) {
/* kernel/userspace switch */
- in_kernel = s->event;
+ in_kernel = s->eip;
if (state == sb_buffer_start)
state = sb_sample_start;
- add_kernel_ctx_switch(s->event);
- } else if (s->event == CPU_TRACE_BEGIN) {
+ add_kernel_ctx_switch(s->eip);
+ } else if (s->eip == CPU_TRACE_BEGIN) {
state = sb_bt_start;
add_trace_begin();
} else {
struct mm_struct * oldmm = mm;
/* userspace context switch */
- new = (struct task_struct *)s->event;
+ new = (struct task_struct *)s->eip;
release_mm(oldmm);
mm = take_tasks_mm(new);
diff --git a/drivers/oprofile/cpu_buffer.c b/drivers/oprofile/cpu_buffer.c
index a83c3db..c856530 100644
--- a/drivers/oprofile/cpu_buffer.c
+++ b/drivers/oprofile/cpu_buffer.c
@@ -156,7 +156,7 @@ add_sample(struct oprofile_cpu_buffer * cpu_buf,
static inline void
add_code(struct oprofile_cpu_buffer * buffer, unsigned long value)
{
- add_sample(buffer, ESCAPE_CODE, value);
+ add_sample(buffer, value, ESCAPE_CODE);
}
/* This must be safe from any context. It's safe writing here
next reply other threads:[~2007-10-21 12:13 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-10-21 12:08 Philippe Elie [this message]
2007-10-23 2:38 ` [patch 1/2] oProfile: oops when profile_pc() return ~0LU Linus Torvalds
2007-10-23 10:10 ` Sami Farin
2007-10-23 16:13 ` Philippe Elie
2007-10-23 16:49 ` Sami Farin
2007-10-23 16:55 ` Linus Torvalds
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=20071021120842.GA2886@zaniah \
--to=phil.el@wanadoo.fr \
--cc=akpm@linux-foundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=safari-kernel@safari.iki.fi \
--cc=torvalds@linux-foundation.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.