Skip to contentSkip to conversation

tracing: A couple of fixes

PATCH New Steven Rostedt 1 participant 3 messages Mar 5, 2022

Subsystems (2)
lore
Share & tools
lore
author maintainer
#2 lore raw

PATCH 2/2 tracing: Fix return value of __setup handlers

In reply to Steven Rostedt

From: Randy Dunlap <[email protected]>

__setup() handlers should generally return 1 to indicate that the boot options have been handled.

Using invalid option values causes the entire kernel boot option string to be reported as Unknown and added to init's environment strings, polluting it.

Unknown kernel command line parameters "BOOT_IMAGE=/boot/bzImage-517rc6
kprobe_event=p,syscall_any,$arg1 trace_options=quiet trace_clock=jiffies", will be passed to user space.

Run /sbin/init as init process
with arguments:
/sbin/init
with environment:

     HOME=/
     TERM=linux
     BOOT_IMAGE=/boot/bzImage-517rc6
     kprobe_event=p,syscall_any,$arg1
     trace_options=quiet
     trace_clock=jiffies

Return 1 from the __setup() handlers so that init's environment is not polluted with kernel boot options.

Fixes 7bcfaf54f591 ("tracing: Add trace_options kernel command line parameter")
Fixes e1e232ca6b8f ("tracing: Add trace_clock=<clock> kernel parameter")
Fixes 970988e19eb0 ("tracing/kprobe: Add kprobe_event= boot parameter")
---
 kernel/trace/trace.c        | 4 ++--
 kernel/trace/trace_kprobe.c | 2 +-
 2 files changed, 3 insertions(+), 3 deletions(-)
kernel/trace/trace.c +2 -2
index 3050892d1812..eb44418574f9 100644
@@ -235,7 +235,7 @@ static char trace_boot_options_buf[MAX_TRACER_SIZE] __initdata;
 static int __init set_trace_boot_options(char *str)
 {
 	strlcpy(trace_boot_options_buf, str, MAX_TRACER_SIZE);
-	return 0;
+	return 1;
 }
 __setup("trace_options=", set_trace_boot_options);
 
@@ -246,7 +246,7 @@ static int __init set_trace_boot_clock(char *str)
 {
 	strlcpy(trace_boot_clock_buf, str, MAX_TRACER_SIZE);
 	trace_boot_clock = trace_boot_clock_buf;
-	return 0;
+	return 1;
 }
 __setup("trace_clock=", set_trace_boot_clock);
 
kernel/trace/trace_kprobe.c +1 -1
index 508f14af4f2c..b62fd785b599 100644
@@ -32,7 +32,7 @@ static int __init set_kprobe_boot_events(char *str)
 	strlcpy(kprobe_boot_events_buf, str, COMMAND_LINE_SIZE);
 	disable_tracing_selftest("running kprobe events");
 
-	return 0;
+	return 1;
 }
 __setup("kprobe_event=", set_kprobe_boot_events);
 
Signature · 1 line
2.34.1
author maintainer
#1 lore raw

PATCH 1/2 tracing/histogram: Fix sorting on old "cpu" value

In reply to Steven Rostedt

From: "Steven Rostedt (Google)" <[email protected]>

When trying to add a histogram against an event with the "cpu" field, it was impossible due to "cpu" being a keyword to key off of the running CPU. So to fix this, it was changed to "common_cpu" to match the other generic fields (like "common_pid"). But since some scripts used "cpu" for keying off of the CPU (for events that did not have "cpu" as a field, which is most of them), a backward compatibility trick was added such that if "cpu" was used as a key, and the event did not have "cpu" as a field name, then it would fallback and switch over to "common_cpu".

This fix has a couple of subtle bugs. One was that when switching over to "common_cpu", it did not change the field name, it just set a flag. But the code still found a "cpu" field. The "cpu" field is used for filtering and is returned when the event does not have a "cpu" field.

This was found by:

  # cd /sys/kernel/tracing
  # echo hist:key=cpu,pid:sort=cpu > events/sched/sched_wakeup/trigger
  # cat events/sched/sched_wakeup/hist

Which showed the histogram unsorted:

{ cpu: 19, pid: 1175 } hitcount: 1
{ cpu: 6, pid: 239 } hitcount: 2
{ cpu: 23, pid: 1186 } hitcount: 14

{ cpu:         12, pid:        249 } hitcount:          2
{ cpu:          3, pid:        994 } hitcount:          5

Instead of hard coding the "cpu" checks, take advantage of the fact that trace_event_field_field() returns a special field for "cpu" and "CPU" if the event does not have "cpu" as a field. This special field has the "filter_type" of "FILTER_CPU". Check that to test if the returned field is of the CPU type instead of doing the string compare.

Also, fix the sorting bug by testing for the hist_field flag of HIST_FIELD_FL_CPU when setting up the sort routine. Otherwise it will use the special CPU field to know what compare routine to use, and since that special field does not have a size, it returns tracing_map_cmp_none.

Fixes 1e3bac71c505 ("tracing/histogram: Rename "cpu" to "common_cpu"")
---
 kernel/trace/trace_events_hist.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
kernel/trace/trace_events_hist.c +3 -3
index ada87bfb5bb8..dc7f733b4cb3 100644
@@ -2289,9 +2289,9 @@ parse_field(struct hist_trigger_data *hist_data, struct trace_event_file *file,
 			/*
 			 * For backward compatibility, if field_name
 			 * was "cpu", then we treat this the same as
-			 * common_cpu.
+			 * common_cpu. This also works for "CPU".
 			 */
-			if (strcmp(field_name, "cpu") == 0) {
+			if (field && field->filter_type == FILTER_CPU) {
 				*flags |= HIST_FIELD_FL_CPU;
 			} else {
 				hist_err(tr, HIST_ERR_FIELD_NOT_FOUND,
@@ -4832,7 +4832,7 @@ static int create_tracing_map_fields(struct hist_trigger_data *hist_data)
 
 			if (hist_field->flags & HIST_FIELD_FL_STACKTRACE)
 				cmp_fn = tracing_map_cmp_none;
-			else if (!field)
+			else if (!field || hist_field->flags & HIST_FIELD_FL_CPU)
 				cmp_fn = tracing_map_cmp_num(hist_field->size,
 							     hist_field->is_signed);
 			else if (is_string_field(field))
Signature · 1 line
2.34.1

Steven Rostedt

author maintainer
#0 lore raw

cover tracing: A couple of fixes

Two tracing fixes:

- Fix sorting on old "cpu" value in histograms

- Fix return value of __setup() boot parameter handlers.

Head SHA1: 1d02b444b8d1345ea4708db3bab4db89a7784b55

Randy Dunlap (1):
tracing: Fix return value of __setup handlers

Steven Rostedt (Google) (1):
tracing/histogram: Fix sorting on old "cpu" value

----

 kernel/trace/trace.c             | 4 ++--
 kernel/trace/trace_events_hist.c | 6 +++---
 kernel/trace/trace_kprobe.c      | 2 +-
 3 files changed, 6 insertions(+), 6 deletions(-)