From: Steven Rostedt <rostedt@goodmis.org>
To: linux-kernel@vger.kernel.org
Cc: Linus Torvalds <torvalds@linux-foundation.org>,
Ingo Molnar <mingo@kernel.org>,
Andrew Morton <akpm@linux-foundation.org>,
Pratyush Anand <panand@redhat.com>, <stable@vger.kernel.org>
Subject: [PATCH 3/5] ftrace: Clear REGS_EN and TRAMP_EN flags on disabling record via sysctl
Date: Mon, 09 Mar 2015 12:03:56 -0400 [thread overview]
Message-ID: <20150309160546.993340275@goodmis.org> (raw)
In-Reply-To: <20150309160353.065685105@goodmis.org>
[-- Attachment #1: 0003-ftrace-Clear-REGS_EN-and-TRAMP_EN-flags-on-disabling.patch --]
[-- Type: text/plain, Size: 2414 bytes --]
From: "Steven Rostedt (Red Hat)" <rostedt@goodmis.org>
When /proc/sys/kernel/ftrace_enabled is set to zero, all function
tracing is disabled. But the records that represent the functions
still hold information about the ftrace_ops that are hooked to them.
ftrace_ops may request "REGS" (have a full set of pt_regs passed to
the callback), or "TRAMP" (the ops has its own trampoline to use).
When the record is updated to represent the state of the ops hooked
to it, it sets "REGS_EN" and/or "TRAMP_EN" to state that the callback
points to the correct trampoline (REGS has its own trampoline).
When ftrace_enabled is set to zero, all ftrace locations are a nop,
so they do not point to any trampoline. But the _EN flags are still
set. This can cause the accounting to go wrong when ftrace_enabled
is cleared and an ops that has a trampoline is registered or unregistered.
For example, the following will cause ftrace to crash:
# echo function_graph > /sys/kernel/debug/tracing/current_tracer
# echo 0 > /proc/sys/kernel/ftrace_enabled
# echo nop > /sys/kernel/debug/tracing/current_tracer
# echo 1 > /proc/sys/kernel/ftrace_enabled
# echo function_graph > /sys/kernel/debug/tracing/current_tracer
As function_graph uses a trampoline, when ftrace_enabled is set to zero
the updates to the record are not done. When enabling function_graph
again, the record will still have the TRAMP_EN flag set, and it will
look for an op that has a trampoline other than the function_graph
ops, and fail to find one.
Cc: stable@vger.kernel.org # 3.17+
Reported-by: Pratyush Anand <panand@redhat.com>
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
---
kernel/trace/ftrace.c | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)
diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c
index 45e5cb143d17..14947e014b78 100644
--- a/kernel/trace/ftrace.c
+++ b/kernel/trace/ftrace.c
@@ -2041,8 +2041,12 @@ static int ftrace_check_record(struct dyn_ftrace *rec, int enable, int update)
if (!ftrace_rec_count(rec))
rec->flags = 0;
else
- /* Just disable the record (keep REGS state) */
- rec->flags &= ~FTRACE_FL_ENABLED;
+ /*
+ * Just disable the record, but keep the ops TRAMP
+ * and REGS states. The _EN flags must be disabled though.
+ */
+ rec->flags &= ~(FTRACE_FL_ENABLED | FTRACE_FL_TRAMP_EN |
+ FTRACE_FL_REGS_EN);
}
return FTRACE_UPDATE_MAKE_NOP;
--
2.1.4
next prev parent reply other threads:[~2015-03-09 16:06 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-03-09 16:03 [PATCH 0/5] [GIT PULL] seq-buf/ftrace: Various fixes Steven Rostedt
2015-03-09 16:03 ` [PATCH 1/5] seq_buf: Fix seq_buf_vprintf() truncation Steven Rostedt
2015-03-09 16:03 ` [PATCH 2/5] seq_buf: Fix seq_buf_bprintf() truncation Steven Rostedt
2015-03-09 16:03 ` Steven Rostedt [this message]
2015-03-09 16:03 ` [PATCH 4/5] ftrace: Fix en(dis)able graph caller when en(dis)abling record via sysctl Steven Rostedt
2015-03-09 16:03 ` [PATCH 5/5] ftrace: Fix ftrace enable ordering of sysctl ftrace_enabled Steven Rostedt
2015-03-10 1:14 ` [PATCH 0/5] [GIT PULL] seq-buf/ftrace: Various fixes Linus Torvalds
2015-03-10 1:36 ` Steven Rostedt
2015-03-10 1:43 ` Linus Torvalds
2015-03-10 2:03 ` 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=20150309160546.993340275@goodmis.org \
--to=rostedt@goodmis.org \
--cc=akpm@linux-foundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@kernel.org \
--cc=panand@redhat.com \
--cc=stable@vger.kernel.org \
--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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Powered by JetHome