All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/3] ftrace updates to tip/core/urgent
@ 2008-11-19  5:34 Steven Rostedt
  2008-11-19  5:34 ` [PATCH 1/3] ftrace: fix set_ftrace_filter Steven Rostedt
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Steven Rostedt @ 2008-11-19  5:34 UTC (permalink / raw)
  To: linux-kernel; +Cc: Ingo Molnar, Andrew Morton

[
  Lets try that again. My series file was nuked.
]

Ingo,

I ported the following patches to tip/core/urgent since they are candidates
for 2.6.28.

The first two are trivial, short, and should not be an issue. The first
two handle the printing of the set_ftrace_filter file correctly.

The third is a bigger patch "108 lines changed" and is actually a
clean up and fix.  The difference is that the current logic to
determine if a function should be enabled or not is incorrect.
With different combinations of using set_ftrace_filter and
set_ftrace_notrace, incorrect functions may be traced, or not traced.

But this bug that the patch fixes is not a critical bug. It should not
cause any stability problems with the kernel. The bug will only
produce undesirable traces.

But on the other hand, adding that last patch should not cause any
stability issues as well. And it makes the complex function cleaner
and more importantly, by coupling the ENABLED flag of the record
with the enabling (or disabling) of the tracing of the function
the record represents, makes the code more robust.


The following patches are in:

  git://git.kernel.org/pub/scm/linux/kernel/git/rostedt/linux-2.6-trace.git

      branch: tip/urgent


Steven Rostedt (3):
      ftrace: fix set_ftrace_filter
      ftrace: make filtered functions effective on setting
      ftrace: fix dyn ftrace filter selection

----
 kernel/trace/ftrace.c |  113 +++++++++++++++++++++++-------------------------
 1 files changed, 54 insertions(+), 59 deletions(-)

-- 

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH 1/3] ftrace: fix set_ftrace_filter
  2008-11-19  5:34 [PATCH 0/3] ftrace updates to tip/core/urgent Steven Rostedt
@ 2008-11-19  5:34 ` Steven Rostedt
  2008-11-19  5:34 ` [PATCH 2/3] ftrace: make filtered functions effective on setting Steven Rostedt
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: Steven Rostedt @ 2008-11-19  5:34 UTC (permalink / raw)
  To: linux-kernel; +Cc: Ingo Molnar, Andrew Morton, Steven Rostedt

[-- Attachment #1: 0001-ftrace-fix-set_ftrace_filter.patch --]
[-- Type: text/plain, Size: 992 bytes --]

Impact: fix of output of set_ftrace_filter

The commit "ftrace: do not show freed records in
             available_filter_functions"

Removed a bit too much from the set_ftrace_filter code, where we now see
all functions in the set_ftrace_filter file even when we set a filter.

Signed-off-by: Steven Rostedt <srostedt@redhat.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
---
 kernel/trace/ftrace.c |    3 +++
 1 files changed, 3 insertions(+), 0 deletions(-)

diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c
index 4a39d24..dcac741 100644
--- a/kernel/trace/ftrace.c
+++ b/kernel/trace/ftrace.c
@@ -738,6 +738,9 @@ t_next(struct seq_file *m, void *v, loff_t *pos)
 		    ((iter->flags & FTRACE_ITER_FAILURES) &&
 		     !(rec->flags & FTRACE_FL_FAILED)) ||
 
+		    ((iter->flags & FTRACE_ITER_FILTER) &&
+		     !(rec->flags & FTRACE_FL_FILTER)) ||
+
 		    ((iter->flags & FTRACE_ITER_NOTRACE) &&
 		     !(rec->flags & FTRACE_FL_NOTRACE))) {
 			rec = NULL;
-- 
1.5.6.5

-- 

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH 2/3] ftrace: make filtered functions effective on setting
  2008-11-19  5:34 [PATCH 0/3] ftrace updates to tip/core/urgent Steven Rostedt
  2008-11-19  5:34 ` [PATCH 1/3] ftrace: fix set_ftrace_filter Steven Rostedt
@ 2008-11-19  5:34 ` Steven Rostedt
  2008-11-19  5:34 ` [PATCH 3/3] ftrace: fix dyn ftrace filter selection Steven Rostedt
  2008-11-19  8:01 ` [PATCH 0/3] ftrace updates to tip/core/urgent Ingo Molnar
  3 siblings, 0 replies; 5+ messages in thread
From: Steven Rostedt @ 2008-11-19  5:34 UTC (permalink / raw)
  To: linux-kernel; +Cc: Ingo Molnar, Andrew Morton, Steven Rostedt

[-- Attachment #1: 0002-ftrace-make-filtered-functions-effective-on-setting.patch --]
[-- Type: text/plain, Size: 1019 bytes --]

Impact: fix filter selection to apply when set

It can be confusing when the set_filter_functions is set (or cleared)
and the functions being recorded by the dynamic tracer does not
match.

This patch causes the code to be updated if the function tracer is
enabled and the filter is changed.

Signed-off-by: Steven Rostedt <srostedt@redhat.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
---
 kernel/trace/ftrace.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c
index dcac741..5cbddb5 100644
--- a/kernel/trace/ftrace.c
+++ b/kernel/trace/ftrace.c
@@ -1189,7 +1189,7 @@ ftrace_regex_release(struct inode *inode, struct file *file, int enable)
 
 	mutex_lock(&ftrace_sysctl_lock);
 	mutex_lock(&ftrace_start_lock);
-	if (iter->filtered && ftrace_start && ftrace_enabled)
+	if (ftrace_start && ftrace_enabled)
 		ftrace_run_update_code(FTRACE_ENABLE_CALLS);
 	mutex_unlock(&ftrace_start_lock);
 	mutex_unlock(&ftrace_sysctl_lock);
-- 
1.5.6.5

-- 

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH 3/3] ftrace: fix dyn ftrace filter selection
  2008-11-19  5:34 [PATCH 0/3] ftrace updates to tip/core/urgent Steven Rostedt
  2008-11-19  5:34 ` [PATCH 1/3] ftrace: fix set_ftrace_filter Steven Rostedt
  2008-11-19  5:34 ` [PATCH 2/3] ftrace: make filtered functions effective on setting Steven Rostedt
@ 2008-11-19  5:34 ` Steven Rostedt
  2008-11-19  8:01 ` [PATCH 0/3] ftrace updates to tip/core/urgent Ingo Molnar
  3 siblings, 0 replies; 5+ messages in thread
From: Steven Rostedt @ 2008-11-19  5:34 UTC (permalink / raw)
  To: linux-kernel; +Cc: Ingo Molnar, Andrew Morton, Steven Rostedt

[-- Attachment #1: 0003-ftrace-fix-dyn-ftrace-filter-selection.patch --]
[-- Type: text/plain, Size: 6438 bytes --]

Impact: clean up and fix for dyn ftrace filter selection

The previous logic of the dynamic ftrace selection of enabling
or disabling functions was complex and incorrect. This patch simplifies
the code and corrects the usage. This simplification also makes the
code more robust.

Here is the correct logic:

  Given a function that can be traced by dynamic ftrace:

  If the function is not to be traced, disable it if it was enabled.
  (this is if the function is in the set_ftrace_notrace file)

  (filter is on if there exists any functions in set_ftrace_filter file)

  If the filter is on, and we are enabling functions:
    If the function is in set_ftrace_filter, enable it if it is not
      already enabled.
    If the function is not in set_ftrace_filter, disable it if it is not
      already disabled.

  Otherwise, if the filter is off and we are enabling function tracing:
    Enable the function if it is not already enabled.

  Otherwise, if we are disabling function tracing:
    Disable the function if it is not already disabled.

This code now sets or clears the ENABLED flag in the record, and at the
end it will enable the function if the flag is set, or disable the function
if the flag is cleared.

The parameters for the function that does the above logic is also
simplified. Instead of passing in confusing "new" and "old" where
they might be swapped if the "enabled" flag is not set. The old logic
even had one of the above always NULL and had to be filled in. The new
logic simply passes in one parameter called "nop". A "call" is calculated
in the code, and at the end of the logic, when we know we need to either
disable or enable the function, we can then use the "nop" and "call"
properly.

This code is more robust than the previous version.

Signed-off-by: Steven Rostedt <srostedt@redhat.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
---
 kernel/trace/ftrace.c |  108 ++++++++++++++++++++++--------------------------
 1 files changed, 50 insertions(+), 58 deletions(-)

diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c
index 5cbddb5..fdaab04 100644
--- a/kernel/trace/ftrace.c
+++ b/kernel/trace/ftrace.c
@@ -327,96 +327,89 @@ ftrace_record_ip(unsigned long ip)
 
 static int
 __ftrace_replace_code(struct dyn_ftrace *rec,
-		      unsigned char *old, unsigned char *new, int enable)
+		      unsigned char *nop, int enable)
 {
 	unsigned long ip, fl;
+	unsigned char *call, *old, *new;
 
 	ip = rec->ip;
 
-	if (ftrace_filtered && enable) {
+	/*
+	 * If this record is not to be traced and
+	 * it is not enabled then do nothing.
+	 *
+	 * If this record is not to be traced and
+	 * it is enabled then disabled it.
+	 *
+	 */
+	if (rec->flags & FTRACE_FL_NOTRACE) {
+		if (rec->flags & FTRACE_FL_ENABLED)
+			rec->flags &= ~FTRACE_FL_ENABLED;
+		else
+			return 0;
+
+	} else if (ftrace_filtered && enable) {
 		/*
-		 * If filtering is on:
-		 *
-		 * If this record is set to be filtered and
-		 * is enabled then do nothing.
-		 *
-		 * If this record is set to be filtered and
-		 * it is not enabled, enable it.
-		 *
-		 * If this record is not set to be filtered
-		 * and it is not enabled do nothing.
-		 *
-		 * If this record is set not to trace then
-		 * do nothing.
-		 *
-		 * If this record is set not to trace and
-		 * it is enabled then disable it.
-		 *
-		 * If this record is not set to be filtered and
-		 * it is enabled, disable it.
+		 * Filtering is on:
 		 */
 
-		fl = rec->flags & (FTRACE_FL_FILTER | FTRACE_FL_NOTRACE |
-				   FTRACE_FL_ENABLED);
+		fl = rec->flags & (FTRACE_FL_FILTER | FTRACE_FL_ENABLED);
 
-		if ((fl ==  (FTRACE_FL_FILTER | FTRACE_FL_ENABLED)) ||
-		    (fl ==  (FTRACE_FL_FILTER | FTRACE_FL_NOTRACE)) ||
-		    !fl || (fl == FTRACE_FL_NOTRACE))
+		/* Record is filtered and enabled, do nothing */
+		if (fl == (FTRACE_FL_FILTER | FTRACE_FL_ENABLED))
 			return 0;
 
-		/*
-		 * If it is enabled disable it,
-		 * otherwise enable it!
-		 */
-		if (fl & FTRACE_FL_ENABLED) {
-			/* swap new and old */
-			new = old;
-			old = ftrace_call_replace(ip, FTRACE_ADDR);
+		/* Record is not filtered and is not enabled do nothing */
+		if (!fl)
+			return 0;
+
+		/* Record is not filtered but enabled, disable it */
+		if (fl == FTRACE_FL_ENABLED)
 			rec->flags &= ~FTRACE_FL_ENABLED;
-		} else {
-			new = ftrace_call_replace(ip, FTRACE_ADDR);
+		else
+		/* Otherwise record is filtered but not enabled, enable it */
 			rec->flags |= FTRACE_FL_ENABLED;
-		}
 	} else {
+		/* Disable or not filtered */
 
 		if (enable) {
-			/*
-			 * If this record is set not to trace and is
-			 * not enabled, do nothing.
-			 */
-			fl = rec->flags & (FTRACE_FL_NOTRACE | FTRACE_FL_ENABLED);
-			if (fl == FTRACE_FL_NOTRACE)
-				return 0;
-
-			new = ftrace_call_replace(ip, FTRACE_ADDR);
-		} else
-			old = ftrace_call_replace(ip, FTRACE_ADDR);
-
-		if (enable) {
+			/* if record is enabled, do nothing */
 			if (rec->flags & FTRACE_FL_ENABLED)
 				return 0;
+
 			rec->flags |= FTRACE_FL_ENABLED;
+
 		} else {
+
+			/* if record is not enabled do nothing */
 			if (!(rec->flags & FTRACE_FL_ENABLED))
 				return 0;
+
 			rec->flags &= ~FTRACE_FL_ENABLED;
 		}
 	}
 
+	call = ftrace_call_replace(ip, FTRACE_ADDR);
+
+	if (rec->flags & FTRACE_FL_ENABLED) {
+		old = nop;
+		new = call;
+	} else {
+		old = call;
+		new = nop;
+	}
+
 	return ftrace_modify_code(ip, old, new);
 }
 
 static void ftrace_replace_code(int enable)
 {
 	int i, failed;
-	unsigned char *new = NULL, *old = NULL;
+	unsigned char *nop = NULL;
 	struct dyn_ftrace *rec;
 	struct ftrace_page *pg;
 
-	if (enable)
-		old = ftrace_nop_replace();
-	else
-		new = ftrace_nop_replace();
+	nop = ftrace_nop_replace();
 
 	for (pg = ftrace_pages_start; pg; pg = pg->next) {
 		for (i = 0; i < pg->index; i++) {
@@ -434,7 +427,7 @@ static void ftrace_replace_code(int enable)
 				unfreeze_record(rec);
 			}
 
-			failed = __ftrace_replace_code(rec, old, new, enable);
+			failed = __ftrace_replace_code(rec, nop, enable);
 			if (failed && (rec->flags & FTRACE_FL_CONVERTED)) {
 				rec->flags |= FTRACE_FL_FAILED;
 				if ((system_state == SYSTEM_BOOTING) ||
@@ -538,8 +531,7 @@ static void ftrace_startup(void)
 
 	mutex_lock(&ftrace_start_lock);
 	ftrace_start++;
-	if (ftrace_start == 1)
-		command |= FTRACE_ENABLE_CALLS;
+	command |= FTRACE_ENABLE_CALLS;
 
 	if (saved_ftrace_func != ftrace_trace_function) {
 		saved_ftrace_func = ftrace_trace_function;
-- 
1.5.6.5

-- 

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH 0/3] ftrace updates to tip/core/urgent
  2008-11-19  5:34 [PATCH 0/3] ftrace updates to tip/core/urgent Steven Rostedt
                   ` (2 preceding siblings ...)
  2008-11-19  5:34 ` [PATCH 3/3] ftrace: fix dyn ftrace filter selection Steven Rostedt
@ 2008-11-19  8:01 ` Ingo Molnar
  3 siblings, 0 replies; 5+ messages in thread
From: Ingo Molnar @ 2008-11-19  8:01 UTC (permalink / raw)
  To: Steven Rostedt; +Cc: linux-kernel, Andrew Morton


* Steven Rostedt <rostedt@goodmis.org> wrote:

> Ingo,
> 
> I ported the following patches to tip/core/urgent since they are 
> candidates for 2.6.28.
> 
> The first two are trivial, short, and should not be an issue. The 
> first two handle the printing of the set_ftrace_filter file 
> correctly.
> 
> The third is a bigger patch "108 lines changed" and is actually a 
> clean up and fix.  The difference is that the current logic to 
> determine if a function should be enabled or not is incorrect. With 
> different combinations of using set_ftrace_filter and 
> set_ftrace_notrace, incorrect functions may be traced, or not 
> traced.
> 
> But this bug that the patch fixes is not a critical bug. It should 
> not cause any stability problems with the kernel. The bug will only 
> produce undesirable traces.
> 
> But on the other hand, adding that last patch should not cause any 
> stability issues as well. And it makes the complex function cleaner 
> and more importantly, by coupling the ENABLED flag of the record 
> with the enabling (or disabling) of the tracing of the function the 
> record represents, makes the code more robust.

ok, agreed.

> The following patches are in:
> 
>   git://git.kernel.org/pub/scm/linux/kernel/git/rostedt/linux-2.6-trace.git
> 
>       branch: tip/urgent
> 
> 
> Steven Rostedt (3):
>       ftrace: fix set_ftrace_filter
>       ftrace: make filtered functions effective on setting
>       ftrace: fix dyn ftrace filter selection
> 
> ----
>  kernel/trace/ftrace.c |  113 +++++++++++++++++++++++-------------------------
>  1 files changed, 54 insertions(+), 59 deletions(-)

pulled into tip/tracing/urgent, thanks Steve!

	Ingo

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2008-11-19  8:01 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-11-19  5:34 [PATCH 0/3] ftrace updates to tip/core/urgent Steven Rostedt
2008-11-19  5:34 ` [PATCH 1/3] ftrace: fix set_ftrace_filter Steven Rostedt
2008-11-19  5:34 ` [PATCH 2/3] ftrace: make filtered functions effective on setting Steven Rostedt
2008-11-19  5:34 ` [PATCH 3/3] ftrace: fix dyn ftrace filter selection Steven Rostedt
2008-11-19  8:01 ` [PATCH 0/3] ftrace updates to tip/core/urgent Ingo Molnar

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.