mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Joel Fernandes <joelaf@google.com>
To: Steven Rostedt <rostedt@goodmis.org>
Cc: Linux Kernel Mailing List <linux-kernel@vger.kernel.org>,
	Ingo Molnar <mingo@kernel.org>,
	Andrew Morton <akpm@linux-foundation.org>,
	Jessica Yu <jeyu@kernel.org>,
	"Joel Fernandes (Google)" <joel.opensrc@gmail.com>
Subject: Re: [for-next][PATCH 15/16] ftrace: Add freeing algorithm to free ftrace_mod_maps
Date: Sun, 8 Oct 2017 01:42:15 -0700	[thread overview]
Message-ID: <bd4dd10e-44a7-4f21-0fbd-fa52a265a4f2@google.com> (raw)
In-Reply-To: <CAEi0qNmwyEfk+pyNAVsrSCCn9YGM2n-VVnoJmYLMdou7adEakw@mail.gmail.com>

Hi Steve,

> "Joel Fernandes (Google)" <joel.opensrc@gmail.com> wrote:
[..]
> Also could you let me know what is the correct behavior of the filters
> after a module being traced is unloaded, are the filters supposed to
> be setup again after the module is unloaded, before the module can be
> loaded again?

Actually I learnt that it doesn't get preserved and wrote a patch to fix that, let me know
what you think, thanks. (its only lightly tested - checked that the filters are preserved,
will do more testing tomorrow):

---8<---
From: Joel Fernandes <joelaf@google.com>
Subject: [PATCH RFC] ftrace: Preserve filters across loading/unloading of module

When a module is removed, the filters associated with it is cleared, however it
doesn't make sense to clear it in the following work flow:

1. setup filters (:mod:<mod-name>)
2. load module
3. unload module
4. load module

In step 4, the filters would have gone. Since the recently added mechanism to
do step 1 before 2 (deferred execution of the module command string) is already
present, we can reuse the same mechanism to preserve the filters. This patch
does that and avoids losing the filters and having to set them up again.

Cc: Steven Rostedt <rostedt@goodmis.org>
Signed-off-by: Joel Fernandes <joelaf@google.com>
---
 kernel/trace/ftrace.c | 25 ++++++++++++++++++++-----
 1 file changed, 20 insertions(+), 5 deletions(-)

diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c
index 6abfafd7f173..4979fd2ef466 100644
--- a/kernel/trace/ftrace.c
+++ b/kernel/trace/ftrace.c
@@ -5693,7 +5693,9 @@ static int referenced_filters(struct dyn_ftrace *rec)
 }
 
 static void
-clear_mod_from_hash(struct ftrace_page *pg, struct ftrace_hash *hash)
+deactivate_mod_from_hash(struct module *mod, struct ftrace_page *pg,
+			 struct trace_array *tr, int enable,
+			 struct ftrace_hash *hash)
 {
 	struct ftrace_func_entry *entry;
 	struct dyn_ftrace *rec;
@@ -5712,11 +5714,22 @@ clear_mod_from_hash(struct ftrace_page *pg, struct ftrace_hash *hash)
 		 */
 		if (entry)
 			entry->ip = 0;
+
+		/*
+		 * The hash has been made cleared, however lets save it as a
+		 * string for the next time the module is loaded.
+		 */
+		if (entry) {
+			char func[KSYM_SYMBOL_LEN];
+			kallsyms_lookup(rec->ip, NULL, NULL, NULL, func);
+			ftrace_add_mod(tr, func, mod->name, enable);
+		}
 	}
 }
 
 /* Clear any records from hashs */
-static void clear_mod_from_hashes(struct ftrace_page *pg)
+static void deactivate_mod_from_hashes(struct module *mod,
+				       struct ftrace_page *pg)
 {
 	struct trace_array *tr;
 
@@ -5725,8 +5738,10 @@ static void clear_mod_from_hashes(struct ftrace_page *pg)
 		if (!tr->ops || !tr->ops->func_hash)
 			continue;
 		mutex_lock(&tr->ops->func_hash->regex_lock);
-		clear_mod_from_hash(pg, tr->ops->func_hash->filter_hash);
-		clear_mod_from_hash(pg, tr->ops->func_hash->notrace_hash);
+		deactivate_mod_from_hash(mod, pg, tr, 1,
+					 tr->ops->func_hash->filter_hash);
+		deactivate_mod_from_hash(mod, pg, tr, 0,
+					 tr->ops->func_hash->notrace_hash);
 		mutex_unlock(&tr->ops->func_hash->regex_lock);
 	}
 	mutex_unlock(&trace_types_lock);
@@ -5778,7 +5793,7 @@ void ftrace_release_mod(struct module *mod)
 	for (pg = tmp_page; pg; pg = tmp_page) {
 
 		/* Needs to be called outside of ftrace_lock */
-		clear_mod_from_hashes(pg);
+		deactivate_mod_from_hashes(mod, pg);
 
 		order = get_count_order(pg->size / ENTRIES_PER_PAGE);
 		free_pages((unsigned long)pg->records, order);
-- 
2.14.2.920.gcf0c67979c-goog

  reply	other threads:[~2017-10-08  8:42 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-10-06 18:06 [for-next][PATCH 00/16] tracing: Updates for 4.15 Steven Rostedt
2017-10-06 18:06 ` [for-next][PATCH 01/16] tracing: Remove obsolete sched_switch tracer selftest Steven Rostedt
2017-10-06 18:06 ` [for-next][PATCH 02/16] tracing: Remove redundant unread variable ret Steven Rostedt
2017-10-06 18:06 ` [for-next][PATCH 03/16] tracing: Reverse the order of trace_types_lock and event_mutex Steven Rostedt
2017-10-06 18:06 ` [for-next][PATCH 04/16] ring-buffer: Rewrite trace_recursive_(un)lock() to be simpler Steven Rostedt
2017-10-06 18:07 ` [for-next][PATCH 05/16] tracing: Exclude generic fields from histograms Steven Rostedt
2017-10-06 18:07 ` [for-next][PATCH 06/16] tracing: Remove lookups from tracing_map hitcount Steven Rostedt
2017-10-06 18:07 ` [for-next][PATCH 07/16] tracing: Increase tracing map KEYS_MAX size Steven Rostedt
2017-10-06 18:07 ` [for-next][PATCH 08/16] tracing: Make traceprobe parsing code reusable Steven Rostedt
2017-10-06 18:07 ` [for-next][PATCH 09/16] tracing: Clean up hist_field_flags enum Steven Rostedt
2017-10-06 18:07 ` [for-next][PATCH 10/16] tracing: Add hist_field_name() accessor Steven Rostedt
2017-10-06 18:07 ` [for-next][PATCH 11/16] tracing: Reimplement log2 Steven Rostedt
2017-10-06 18:07 ` [for-next][PATCH 12/16] ftrace: Add a ftrace_free_mem() function for modules to use Steven Rostedt
2017-10-06 18:07 ` [for-next][PATCH 13/16] ftrace: Allow module init functions to be traced Steven Rostedt
2017-10-06 18:07 ` [for-next][PATCH 14/16] ftrace: Save module init functions kallsyms symbols for tracing Steven Rostedt
2017-10-06 18:07 ` [for-next][PATCH 15/16] ftrace: Add freeing algorithm to free ftrace_mod_maps Steven Rostedt
2017-10-07  6:41   ` Joel Fernandes (Google)
2017-10-07 13:32     ` Steven Rostedt
2017-10-08  4:52       ` Joel Fernandes (Google)
2017-10-08  8:42         ` Joel Fernandes [this message]
2017-10-08 18:42           ` Steven Rostedt
2017-10-08 18:56             ` Joel Fernandes
2017-10-09  6:07             ` Joel Fernandes
2017-10-09  6:02         ` Joel Fernandes
2017-10-06 18:07 ` [for-next][PATCH 16/16] ftrace/kallsyms: Have /proc/kallsyms show saved mod init functions 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=bd4dd10e-44a7-4f21-0fbd-fa52a265a4f2@google.com \
    --to=joelaf@google.com \
    --cc=akpm@linux-foundation.org \
    --cc=jeyu@kernel.org \
    --cc=joel.opensrc@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@kernel.org \
    --cc=rostedt@goodmis.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