From: Steven Rostedt <rostedt@goodmis.org>
To: linux-kernel@vger.kernel.org
Cc: Ingo Molnar <mingo@kernel.org>,
Andrew Morton <akpm@linux-foundation.org>
Subject: [for-next][PATCH 7/7] ftrace: Add helper find_direct_entry() to consolidate code
Date: Sun, 17 Nov 2019 17:13:03 -0500 [thread overview]
Message-ID: <20191117221311.056891660@goodmis.org> (raw)
In-Reply-To: 20191117221256.228674565@goodmis.org
From: "Steven Rostedt (VMware)" <rostedt@goodmis.org>
Both unregister_ftrace_direct() and modify_ftrace_direct() needs to
normalize the ip passed in to match the rec->ip, as it is acceptable to have
the ip on the ftrace call site but not the start. There are also common
validity checks with the record found by the ip, these should be done for
both unregister_ftrace_direct() and modify_ftrace_direct().
Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
---
kernel/trace/ftrace.c | 59 +++++++++++++++++++++----------------------
1 file changed, 29 insertions(+), 30 deletions(-)
diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c
index 9fe33ebaf914..ef79c8393f53 100644
--- a/kernel/trace/ftrace.c
+++ b/kernel/trace/ftrace.c
@@ -5112,30 +5112,40 @@ int register_ftrace_direct(unsigned long ip, unsigned long addr)
}
EXPORT_SYMBOL_GPL(register_ftrace_direct);
-int unregister_ftrace_direct(unsigned long ip, unsigned long addr)
+static struct ftrace_func_entry *find_direct_entry(unsigned long *ip)
{
struct ftrace_func_entry *entry;
- struct ftrace_direct_func *direct;
struct dyn_ftrace *rec;
- int ret = -ENODEV;
- mutex_lock(&direct_mutex);
+ rec = lookup_rec(*ip, *ip);
+ if (!rec)
+ return NULL;
- entry = __ftrace_lookup_ip(direct_functions, ip);
+ entry = __ftrace_lookup_ip(direct_functions, rec->ip);
if (!entry) {
- /* OK if it is off by a little */
- rec = lookup_rec(ip, ip);
- if (!rec || rec->ip == ip)
- goto out_unlock;
+ WARN_ON(rec->flags & FTRACE_FL_DIRECT);
+ return NULL;
+ }
- entry = __ftrace_lookup_ip(direct_functions, rec->ip);
- if (!entry) {
- WARN_ON(rec->flags & FTRACE_FL_DIRECT);
- goto out_unlock;
- }
+ WARN_ON(!(rec->flags & FTRACE_FL_DIRECT));
- WARN_ON(!(rec->flags & FTRACE_FL_DIRECT));
- }
+ /* Passed in ip just needs to be on the call site */
+ *ip = rec->ip;
+
+ return entry;
+}
+
+int unregister_ftrace_direct(unsigned long ip, unsigned long addr)
+{
+ struct ftrace_direct_func *direct;
+ struct ftrace_func_entry *entry;
+ int ret = -ENODEV;
+
+ mutex_lock(&direct_mutex);
+
+ entry = find_direct_entry(&ip);
+ if (!entry)
+ goto out_unlock;
if (direct_functions->count == 1)
unregister_ftrace_function(&direct_ops);
@@ -5187,24 +5197,13 @@ int modify_ftrace_direct(unsigned long ip,
unsigned long old_addr, unsigned long new_addr)
{
struct ftrace_func_entry *entry;
- struct dyn_ftrace *rec;
int ret = -ENODEV;
mutex_lock(&direct_mutex);
- entry = __ftrace_lookup_ip(direct_functions, ip);
- if (!entry) {
- /* OK if it is off by a little */
- rec = lookup_rec(ip, ip);
- if (!rec || rec->ip == ip)
- goto out_unlock;
-
- entry = __ftrace_lookup_ip(direct_functions, rec->ip);
- if (!entry)
- goto out_unlock;
- ip = rec->ip;
- WARN_ON(!(rec->flags & FTRACE_FL_DIRECT));
- }
+ entry = find_direct_entry(&ip);
+ if (!entry)
+ goto out_unlock;
ret = -EINVAL;
if (entry->direct != old_addr)
--
2.24.0
prev parent reply other threads:[~2019-11-17 22:13 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-11-17 22:12 [for-next][PATCH 0/7] tracing: Some more updates for 5.5 Steven Rostedt
2019-11-17 22:12 ` [for-next][PATCH 1/7] ftrace: Add modify_ftrace_direct() Steven Rostedt
2019-11-17 22:12 ` [for-next][PATCH 2/7] ftrace/samples: Add a sample module that implements modify_ftrace_direct() Steven Rostedt
2019-11-17 22:12 ` [for-next][PATCH 3/7] tracing: Increase SYNTH_FIELDS_MAX for synthetic_events Steven Rostedt
2019-11-17 22:13 ` [for-next][PATCH 4/7] ftrace/selftests: Fix spelling mistake "wakeing" -> "waking" Steven Rostedt
2019-11-17 22:13 ` [for-next][PATCH 5/7] ftrace: Fix accounting bug with direct->count in register_ftrace_direct() Steven Rostedt
2019-11-17 22:13 ` [for-next][PATCH 6/7] ftrace: Add another check for match " Steven Rostedt
2019-11-17 22:13 ` Steven Rostedt [this message]
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=20191117221311.056891660@goodmis.org \
--to=rostedt@goodmis.org \
--cc=akpm@linux-foundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@kernel.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