From: Steven Rostedt <rostedt@goodmis.org>
To: linux-kernel@vger.kernel.org
Cc: Ingo Molnar <mingo@elte.hu>,
Andrew Morton <akpm@linux-foundation.org>,
Peter Zijlstra <peterz@infradead.org>,
Frederic Weisbecker <fweisbec@gmail.com>,
Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com>,
"H. Peter Anvin" <hpa@zytor.com>, Dave Jones <davej@redhat.com>,
Andi Kleen <ak@linux.intel.com>
Subject: [PATCH 1/5] ftrace: Synchronize variable setting with breakpoints
Date: Wed, 30 May 2012 21:28:30 -0400 [thread overview]
Message-ID: <20120531020440.476352979@goodmis.org> (raw)
In-Reply-To: 20120531012829.160060586@goodmis.org
[-- Attachment #1: Type: text/plain, Size: 2667 bytes --]
From: Steven Rostedt <srostedt@redhat.com>
When the function tracer starts modifying the code via breakpoints
it sets a variable (modifying_ftrace_code) to inform the breakpoint
handler to call the ftrace int3 code.
But there's no synchronization between setting this code and the
handler, thus it is possible for the handler to be called on another
CPU before it sees the variable. This will cause a kernel crash as
the int3 handler will not know what to do with it.
I originally added smp_mb()'s to force the visibility of the variable
but H. Peter Anvin suggested that I just make it atomic.
Suggested-by: H. Peter Anvin <hpa@zytor.com>
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
---
arch/x86/include/asm/ftrace.h | 2 +-
arch/x86/kernel/ftrace.c | 6 +++---
arch/x86/kernel/traps.c | 3 ++-
3 files changed, 6 insertions(+), 5 deletions(-)
diff --git a/arch/x86/include/asm/ftrace.h b/arch/x86/include/asm/ftrace.h
index 18d9005..b0767bc 100644
--- a/arch/x86/include/asm/ftrace.h
+++ b/arch/x86/include/asm/ftrace.h
@@ -34,7 +34,7 @@
#ifndef __ASSEMBLY__
extern void mcount(void);
-extern int modifying_ftrace_code;
+extern atomic_t modifying_ftrace_code;
static inline unsigned long ftrace_call_adjust(unsigned long addr)
{
diff --git a/arch/x86/kernel/ftrace.c b/arch/x86/kernel/ftrace.c
index 32ff365..ea9904f 100644
--- a/arch/x86/kernel/ftrace.c
+++ b/arch/x86/kernel/ftrace.c
@@ -168,7 +168,7 @@ int ftrace_update_ftrace_func(ftrace_func_t func)
return ret;
}
-int modifying_ftrace_code __read_mostly;
+atomic_t modifying_ftrace_code __read_mostly;
/*
* A breakpoint was added to the code address we are about to
@@ -491,11 +491,11 @@ void ftrace_replace_code(int enable)
void arch_ftrace_update_code(int command)
{
- modifying_ftrace_code++;
+ atomic_inc(&modifying_ftrace_code);
ftrace_modify_all_code(command);
- modifying_ftrace_code--;
+ atomic_dec(&modifying_ftrace_code);
}
int __init ftrace_dyn_arch_init(void *data)
diff --git a/arch/x86/kernel/traps.c b/arch/x86/kernel/traps.c
index ff08457..32443ae 100644
--- a/arch/x86/kernel/traps.c
+++ b/arch/x86/kernel/traps.c
@@ -304,7 +304,8 @@ dotraplinkage void __kprobes notrace do_int3(struct pt_regs *regs, long error_co
{
#ifdef CONFIG_DYNAMIC_FTRACE
/* ftrace must be first, everything else may cause a recursive crash */
- if (unlikely(modifying_ftrace_code) && ftrace_int3_handler(regs))
+ if (unlikely(atomic_read(&modifying_ftrace_code)) &&
+ ftrace_int3_handler(regs))
return;
#endif
#ifdef CONFIG_KGDB_LOW_LEVEL_TRAP
--
1.7.10
[-- Attachment #2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 836 bytes --]
next prev parent reply other threads:[~2012-05-31 2:05 UTC|newest]
Thread overview: 47+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-05-31 1:28 [PATCH 0/5] [GIT PULL] ftrace: Fix bug with function tracing and lockdep Steven Rostedt
2012-05-31 1:28 ` Steven Rostedt [this message]
2012-05-31 11:06 ` [PATCH 1/5] ftrace: Synchronize variable setting with breakpoints Peter Zijlstra
2012-05-31 14:08 ` Steven Rostedt
2012-05-31 15:16 ` Masami Hiramatsu
2012-05-31 15:29 ` Steven Rostedt
2012-05-31 17:28 ` Peter Zijlstra
2012-05-31 18:42 ` Steven Rostedt
2012-05-31 17:40 ` Peter Zijlstra
2012-05-31 17:44 ` Peter Zijlstra
2012-05-31 17:53 ` Steven Rostedt
2012-05-31 18:03 ` Peter Zijlstra
2012-05-31 18:50 ` Steven Rostedt
2012-05-31 19:06 ` Peter Zijlstra
2012-05-31 19:55 ` Mathieu Desnoyers
2012-05-31 20:10 ` Steven Rostedt
2012-05-31 20:26 ` Peter Zijlstra
2012-05-31 20:37 ` Steven Rostedt
2012-05-31 20:40 ` Steven Rostedt
2012-05-31 20:40 ` Peter Zijlstra
2012-05-31 20:49 ` Steven Rostedt
2012-06-01 4:53 ` Masami Hiramatsu
2012-06-01 11:37 ` Steven Rostedt
2012-06-01 12:52 ` Masami Hiramatsu
2012-06-01 0:45 ` Arnaldo Carvalho de Melo
2012-05-31 1:28 ` [PATCH 2/5] ftrace: Use breakpoint method to update ftrace caller Steven Rostedt
2012-05-31 11:18 ` Peter Zijlstra
2012-05-31 14:19 ` Steven Rostedt
2012-05-31 1:28 ` [PATCH 3/5] x86: Reset the debug_stack update counter Steven Rostedt
2012-05-31 19:19 ` H. Peter Anvin
2012-05-31 19:26 ` Steven Rostedt
2012-05-31 1:28 ` [PATCH 4/5] x86: Allow nesting of the debug stack IDT setting Steven Rostedt
2012-05-31 18:44 ` H. Peter Anvin
2012-05-31 18:58 ` H. Peter Anvin
2012-05-31 19:25 ` Steven Rostedt
2012-05-31 19:27 ` H. Peter Anvin
2012-05-31 20:00 ` Steven Rostedt
2012-05-31 20:17 ` H. Peter Anvin
2012-05-31 20:35 ` Steven Rostedt
2012-05-31 20:39 ` H. Peter Anvin
2012-05-31 20:56 ` Steven Rostedt
2012-05-31 21:09 ` H. Peter Anvin
2012-05-31 21:37 ` Steven Rostedt
2012-05-31 21:38 ` Steven Rostedt
2012-06-01 2:30 ` Steven Rostedt
2012-05-31 1:28 ` [PATCH 5/5] ftrace/x86: Do not change stacks in DEBUG when calling lockdep Steven Rostedt
2012-05-31 2:13 ` [PATCH 0/5] (for 3.5)[GIT PULL] ftrace: Fix bug with function tracing and lockdep 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=20120531020440.476352979@goodmis.org \
--to=rostedt@goodmis.org \
--cc=ak@linux.intel.com \
--cc=akpm@linux-foundation.org \
--cc=davej@redhat.com \
--cc=fweisbec@gmail.com \
--cc=hpa@zytor.com \
--cc=linux-kernel@vger.kernel.org \
--cc=masami.hiramatsu.pt@hitachi.com \
--cc=mingo@elte.hu \
--cc=peterz@infradead.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