Skip to contentSkip to conversation

tracing: fix trace_print_seq()

PATCH In review Xiao Guangrong 4 participants 7 messages Jul 1, 2009 – Jul 2, 2009 Tracing

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 tracing: fix trace_print_seq()

We will lose something if trace_seq->buffer[0] is 0, because the copy length is calculated by strlen() in seq_puts(), so using seq_write() instead of seq_puts().

There have a example:
after reboot:

# echo kmemtrace > current_tracer
# echo 0 > options/kmem_minimalistic
# cat trace
# tracer: kmemtrace
#
#
Nothing is exported, because the first byte of trace_seq->buffer[ ]
is KMEMTRACE_USER_ALLOC.
( the value of KMEMTRACE_USER_ALLOC is zero, seeing
  kmemtrace_print_alloc_user() in kernel/trace/kmemtrace.c)
---
 kernel/trace/trace_output.c |    3 +--
 1 files changed, 1 insertions(+), 2 deletions(-)
kernel/trace/trace_output.c +1 -2
index 7938f3a..e0c2545 100644
@@ -27,8 +27,7 @@ void trace_print_seq(struct seq_file *m, struct trace_seq *s)
 {
 	int len = s->len >= PAGE_SIZE ? PAGE_SIZE - 1 : s->len;
 
-	s->buffer[len] = 0;
-	seq_puts(m, s->buffer);
+	seq_write(m, s->buffer, len);
 
 	trace_seq_init(s);
 }
Signature · 1 line
1.6.1.2
Acked-by on v1 1/1
#1 lore raw
Quoted 39 lines · Xiao Guangrong

We will lose something if trace_seq->buffer[0] is 0, because the copy length is calculated by strlen() in seq_puts(), so using seq_write() instead of seq_puts().

There have a example:
after reboot:

# echo kmemtrace > current_tracer
# echo 0 > options/kmem_minimalistic
# cat trace
# tracer: kmemtrace
#
#
Nothing is exported, because the first byte of trace_seq->buffer[ ]
is KMEMTRACE_USER_ALLOC.
( the value of KMEMTRACE_USER_ALLOC is zero, seeing
  kmemtrace_print_alloc_user() in kernel/trace/kmemtrace.c)
---
 kernel/trace/trace_output.c |    3 +--
 1 files changed, 1 insertions(+), 2 deletions(-)
kernel/trace/trace_output.c +1 -2
index 7938f3a..e0c2545 100644
@@ -27,8 +27,7 @@ void trace_print_seq(struct seq_file *m, struct trace_seq *s)
 {
 	int len = s->len >= PAGE_SIZE ? PAGE_SIZE - 1 : s->len;
 
-	s->buffer[len] = 0;
-	seq_puts(m, s->buffer);
+	seq_write(m, s->buffer, len);
 
 	trace_seq_init(s);
 }
Signature · 1 line
1.6.1.2

Looks good, thanks.

But having a '\0' in a non binary trace looks weird. Why do we have such plain KMEMTRACE_USER_ALLOC whereas binary tracing is not set, as your example shows it?

#3 lore raw

[tip:tracing/urgent] tracing: Fix trace_print_seq()

In reply to Xiao Guangrong
Commit-ID:  5c37f525657e879a17a27c83021602cd55837531
Gitweb:     http://git.kernel.org/tip/5c37f525657e879a17a27c83021602cd55837531
Author:     Xiao Guangrong <[email protected]>
AuthorDate: Wed, 1 Jul 2009 16:50:25 +0800
Committer:  Ingo Molnar <[email protected]>
CommitDate: Wed, 1 Jul 2009 16:03:50 +0200

tracing: Fix trace_print_seq()

We will lose something if trace_seq->buffer[0] is 0, because the copy length is calculated by strlen() in seq_puts(), so using seq_write() instead of seq_puts().

There have a example:
after reboot:

 # echo kmemtrace > current_tracer
 # echo 0 > options/kmem_minimalistic
 # cat trace
 # tracer: kmemtrace
 #
 #

Nothing is exported, because the first byte of trace_seq->buffer[ ] is KMEMTRACE_USER_ALLOC.

( the value of KMEMTRACE_USER_ALLOC is zero, seeing
kmemtrace_print_alloc_user() in kernel/trace/kmemtrace.c)

Cc Eduard - Gabriel Munteanu <[email protected]>
Cc Steven Rostedt <[email protected]>
Cc Pekka Enberg <[email protected]>

LKML-Reference: <[email protected]>

---
 kernel/trace/trace_output.c |    3 +--
 1 files changed, 1 insertions(+), 2 deletions(-)
kernel/trace/trace_output.c +1 -2
index 7938f3a..e0c2545 100644
@@ -27,8 +27,7 @@ void trace_print_seq(struct seq_file *m, struct trace_seq *s)
 {
 	int len = s->len >= PAGE_SIZE ? PAGE_SIZE - 1 : s->len;
 
-	s->buffer[len] = 0;
-	seq_puts(m, s->buffer);
+	seq_write(m, s->buffer, len);
 
 	trace_seq_init(s);
 }
Acked-by
#4 lore raw

Re: [tip:tracing/urgent] tracing: Fix trace_print_seq()

Quoted 29 lines · tip-bot for Xiao Guangrong
Commit-ID:  5c37f525657e879a17a27c83021602cd55837531
Gitweb:     http://git.kernel.org/tip/5c37f525657e879a17a27c83021602cd55837531
Author:     Xiao Guangrong <[email protected]>
AuthorDate: Wed, 1 Jul 2009 16:50:25 +0800
Committer:  Ingo Molnar <[email protected]>
CommitDate: Wed, 1 Jul 2009 16:03:50 +0200

tracing: Fix trace_print_seq()

We will lose something if trace_seq->buffer[0] is 0, because the copy length is calculated by strlen() in seq_puts(), so using seq_write() instead of seq_puts().

There have a example:
after reboot:

 # echo kmemtrace > current_tracer
 # echo 0 > options/kmem_minimalistic
 # cat trace
 # tracer: kmemtrace
 #
 #

Nothing is exported, because the first byte of trace_seq->buffer[ ] is KMEMTRACE_USER_ALLOC.

( the value of KMEMTRACE_USER_ALLOC is zero, seeing
kmemtrace_print_alloc_user() in kernel/trace/kmemtrace.c)

Quoted 7 lines
Cc Eduard - Gabriel Munteanu <[email protected]>
Cc Steven Rostedt <[email protected]>
Cc Pekka Enberg <[email protected]>

LKML-Reference: <[email protected]>

Nice catch!

#5 lore raw

[tip:tracing/urgent] tracing: Fix trace_print_seq()

In reply to Xiao Guangrong
Commit-ID:  393ab9a2a6cf958c9549e35bd88c03b9b3eae64e
Gitweb:     http://git.kernel.org/tip/393ab9a2a6cf958c9549e35bd88c03b9b3eae64e
Author:     Xiao Guangrong <[email protected]>
AuthorDate: Wed, 1 Jul 2009 16:50:25 +0800
Committer:  Ingo Molnar <[email protected]>
CommitDate: Wed, 1 Jul 2009 16:41:31 +0200

tracing: Fix trace_print_seq()

We will lose something if trace_seq->buffer[0] is 0, because the copy length is calculated by strlen() in seq_puts(), so using seq_write() instead of seq_puts().

There have a example:
after reboot:

 # echo kmemtrace > current_tracer
 # echo 0 > options/kmem_minimalistic
 # cat trace
 # tracer: kmemtrace
 #
 #

Nothing is exported, because the first byte of trace_seq->buffer[ ] is KMEMTRACE_USER_ALLOC.

( the value of KMEMTRACE_USER_ALLOC is zero, seeing
kmemtrace_print_alloc_user() in kernel/trace/kmemtrace.c)

LKML-Reference: <[email protected]>

---
 kernel/trace/trace_output.c |    3 +--
 1 files changed, 1 insertions(+), 2 deletions(-)
kernel/trace/trace_output.c +1 -2
index 7938f3a..e0c2545 100644
@@ -27,8 +27,7 @@ void trace_print_seq(struct seq_file *m, struct trace_seq *s)
 {
 	int len = s->len >= PAGE_SIZE ? PAGE_SIZE - 1 : s->len;
 
-	s->buffer[len] = 0;
-	seq_puts(m, s->buffer);
+	seq_write(m, s->buffer, len);
 
 	trace_seq_init(s);
 }
#2 lore raw
In reply to Frederic Weisbecker
Quoted 13 lines
Quoted 13 lines

There have a example:
after reboot:

# echo kmemtrace > current_tracer
# echo 0 > options/kmem_minimalistic
# cat trace
# tracer: kmemtrace
#
#
Nothing is exported, because the first byte of trace_seq->buffer[ ]
is KMEMTRACE_USER_ALLOC.
( the value of KMEMTRACE_USER_ALLOC is zero, seeing
  kmemtrace_print_alloc_user() in kernel/trace/kmemtrace.c)

...

Quoted 8 lines

Looks good, thanks.

But having a '\0' in a non binary trace looks weird. Why do we have such plain KMEMTRACE_USER_ALLOC whereas binary tracing is not set, as your example shows it?

Because of this commit:

| commit 42af9054c0eeed09ec58d13ec8bf52d225ebcfcc
| Author: Eduard - Gabriel Munteanu <[email protected]>
| Date:   Mon Mar 23 15:12:26 2009 +0200
|
|    kmemtrace: restore original tracing data binary format, improve ABI

I think we should change it to use trace_event->binary() interface for binary trace.

#6 lore raw

[tip:tracing/urgent] tracing: Fix trace_print_seq()

In reply to Xiao Guangrong
Commit-ID:  e1af3aec3e2e7d21d4b3054323779d478c19d907
Gitweb:     http://git.kernel.org/tip/e1af3aec3e2e7d21d4b3054323779d478c19d907
Author:     Xiao Guangrong <[email protected]>
AuthorDate: Wed, 1 Jul 2009 16:50:25 +0800
Committer:  Ingo Molnar <[email protected]>
CommitDate: Thu, 2 Jul 2009 08:51:13 +0200

tracing: Fix trace_print_seq()

We will lose something if trace_seq->buffer[0] is 0, because the copy length is calculated by strlen() in seq_puts(), so using seq_write() instead of seq_puts().

There have a example:
after reboot:

 # echo kmemtrace > current_tracer
 # echo 0 > options/kmem_minimalistic
 # cat trace
 # tracer: kmemtrace
 #
 #

Nothing is exported, because the first byte of trace_seq->buffer[ ] is KMEMTRACE_USER_ALLOC.

( the value of KMEMTRACE_USER_ALLOC is zero, seeing
kmemtrace_print_alloc_user() in kernel/trace/kmemtrace.c)

LKML-Reference: <[email protected]>

---
 kernel/trace/trace_output.c |    3 +--
 1 files changed, 1 insertions(+), 2 deletions(-)
kernel/trace/trace_output.c +1 -2
index 7938f3a..e0c2545 100644
@@ -27,8 +27,7 @@ void trace_print_seq(struct seq_file *m, struct trace_seq *s)
 {
 	int len = s->len >= PAGE_SIZE ? PAGE_SIZE - 1 : s->len;
 
-	s->buffer[len] = 0;
-	seq_puts(m, s->buffer);
+	seq_write(m, s->buffer, len);
 
 	trace_seq_init(s);
 }