Skip to contentSkip to conversation

[2.6.31] tracing: more fixes

GIT PULL New Steven Rostedt 1 participant 5 messages Jul 23, 2009

Subsystems (2)
lore
Share & tools
lore

Steven Rostedt

author maintainer
#0 lore raw

Ingo and Thomas,

Here are 4 more fixes that should be in 31. They are minor and small, but still should be made.

Please pull the latest tip/tracing/urgent-1 tree, which can be found at:

git://git.kernel.org/pub/scm/linux/kernel/git/rostedt/linux-2.6-trace.git
tip/tracing/urgent-1

Matt Fleming (2):
ftrace: Fix the conditional that updates $ref_func
ftrace: Only update $offset when we update $ref_func

Steven Rostedt (2):
tracing: show proper address for trace-printk format
tracing: only truncate ftrace files when O_TRUNC is set

----

 kernel/trace/ftrace.c       |    4 ++--
 kernel/trace/trace.c        |    2 +-
 kernel/trace/trace_events.c |    2 +-
 kernel/trace/trace_printk.c |    2 +-
 scripts/recordmcount.pl     |    5 +++--
 5 files changed, 8 insertions(+), 7 deletions(-)
author maintainer
#1 lore raw

PATCH 1/4 tracing: show proper address for trace-printk format

From: Steven Rostedt <[email protected]>

Since the trace_printk may use pointers to the format fields in the buffer, they are exported via debugfs/tracing/printk_formats. This is used by utilities that read the ring buffer in binary format. It helps the utilities map the address of the format in the binary buffer to what the printf format looks like.

Unfortunately, the way the output code works, it exports the address of the pointer to the format address, and not the format address itself. This makes the file totally useless in trying to figure out what format string a binary address belongs to.

---
 kernel/trace/trace_printk.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
kernel/trace/trace_printk.c +1 -1
index 7b62781..687699d 100644
@@ -176,7 +176,7 @@ static int t_show(struct seq_file *m, void *v)
 	const char *str = *fmt;
 	int i;
 
-	seq_printf(m, "0x%lx : \"", (unsigned long)fmt);
+	seq_printf(m, "0x%lx : \"", *(unsigned long *)fmt);
 
 	/*
 	 * Tabs and new lines need to be converted.
Signature · 3 lines
1.6.3.3

-- 
author maintainer
#2 lore raw

PATCH 2/4 tracing: only truncate ftrace files when O_TRUNC is set

In reply to Steven Rostedt

From: Steven Rostedt <[email protected]>

The current code will truncate the ftrace files contents if O_APPEND is not set and the file is opened in write mode. This is incorrect. It should only truncate the file if O_TRUNC is set. Otherwise if one of these files is opened by a C program with fopen "r+", it will incorrectly truncate the file.

---
 kernel/trace/ftrace.c       |    4 ++--
 kernel/trace/trace.c        |    2 +-
 kernel/trace/trace_events.c |    2 +-
 3 files changed, 4 insertions(+), 4 deletions(-)
kernel/trace/ftrace.c +2 -2
index 1f3ec2a..1e1d23c 100644
@@ -1662,7 +1662,7 @@ ftrace_regex_open(struct inode *inode, struct file *file, int enable)
 
 	mutex_lock(&ftrace_regex_lock);
 	if ((file->f_mode & FMODE_WRITE) &&
-	    !(file->f_flags & O_APPEND))
+	    (file->f_flags & O_TRUNC))
 		ftrace_filter_reset(enable);
 
 	if (file->f_mode & FMODE_READ) {
@@ -2577,7 +2577,7 @@ ftrace_graph_open(struct inode *inode, struct file *file)
 
 	mutex_lock(&graph_lock);
 	if ((file->f_mode & FMODE_WRITE) &&
-	    !(file->f_flags & O_APPEND)) {
+	    (file->f_flags & O_TRUNC)) {
 		ftrace_graph_count = 0;
 		memset(ftrace_graph_funcs, 0, sizeof(ftrace_graph_funcs));
 	}
kernel/trace/trace.c +1 -1
index 8bc8d8a..d8ef285 100644
@@ -2031,7 +2031,7 @@ static int tracing_open(struct inode *inode, struct file *file)
 
 	/* If this file was open for write, then erase contents */
 	if ((file->f_mode & FMODE_WRITE) &&
-	    !(file->f_flags & O_APPEND)) {
+	    (file->f_flags & O_TRUNC)) {
 		long cpu = (long) inode->i_private;
 
 		if (cpu == TRACE_PIPE_ALL_CPU)
kernel/trace/trace_events.c +1 -1
index 53c8fd3..23d2972 100644
@@ -376,7 +376,7 @@ ftrace_event_seq_open(struct inode *inode, struct file *file)
 	const struct seq_operations *seq_ops;
 
 	if ((file->f_mode & FMODE_WRITE) &&
-	    !(file->f_flags & O_APPEND))
+	    (file->f_flags & O_TRUNC))
 		ftrace_clear_events();
 
 	seq_ops = inode->i_private;
Signature · 3 lines
1.6.3.3

-- 
author maintainer
#3 lore raw

PATCH 3/4 ftrace: Fix the conditional that updates $ref_func

In reply to Steven Rostedt

From: Matt Fleming <[email protected]>

Fix the conditional that checks if we already have a $ref_func and that the new function is weak. The code as previously checking whether either condition was false, and we really need to only update $ref_func is both cconditions are false.

LKML-Reference: <[email protected]>

---
 scripts/recordmcount.pl |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
scripts/recordmcount.pl +1 -1
index 7109e2b..16c5563 100755
@@ -414,7 +414,7 @@ while (<IN>) {
 	    $read_function = 0;
 	} else {
 	    # if we already have a function, and this is weak, skip it
-	    if (!defined($ref_func) || !defined($weak{$text})) {
+	    if (!defined($ref_func) && !defined($weak{$text})) {
 		$ref_func = $text;
 	    }
 	}
Signature · 3 lines
1.6.3.3

-- 
author maintainer
#4 lore raw

PATCH 4/4 ftrace: Only update $offset when we update $ref_func

In reply to Steven Rostedt

From: Matt Fleming <[email protected]>

The value of $offset should be the offset of $ref_func from the beginning of the object file. Therefore, we should set both variables together.

This fixes a bug I was hitting on sh where $offset (which is used to calcualte the addends for the __mcount_loc entries) was being set multiple times and didn't correspond to $ref_func's offset in the object file. The addends in __mcount_loc were calculated incorrectly, resulting in ftrace dynamically modifying addresses that weren't mcount call sites.

LKML-Reference: <[email protected]>

---
 scripts/recordmcount.pl |    3 ++-
 1 files changed, 2 insertions(+), 1 deletions(-)
scripts/recordmcount.pl +2 -1
index 16c5563..d29baa2 100755
@@ -403,7 +403,6 @@ while (<IN>) {
     # section found, now is this a start of a function?
     } elsif ($read_function && /$function_regex/) {
 	$text_found = 1;
-	$offset = hex $1;
 	$text = $2;
 
 	# if this is either a local function or a weak function
@@ -412,10 +411,12 @@ while (<IN>) {
 	if (!defined($locals{$text}) && !defined($weak{$text})) {
 	    $ref_func = $text;
 	    $read_function = 0;
+	    $offset = hex $1;
 	} else {
 	    # if we already have a function, and this is weak, skip it
 	    if (!defined($ref_func) && !defined($weak{$text})) {
 		$ref_func = $text;
+		$offset = hex $1;
 	    }
 	}
     } elsif ($read_headers && /$mcount_section/) {
Signature · 3 lines
1.6.3.3

--