Skip to contentSkip to conversation

tracing: Fix config dependency and trigger parser

PATCH In review Masami Hiramatsu 2 participants 4 messages Jun 20, 2020 – Jun 23, 2020 Tracing

lore
Share & tools
lore

Masami Hiramatsu

author maintainer
#0 lore raw

cover tracing: Fix config dependency and trigger parser

Hi,

These are some fixes which I found recentry on ftrace.

- Since the boot-time tracing synthetic event feature is decoupled from trigger recenty, it should use CONFIG_SYNTH_EVENT.
- The parser of event trigger seems rejecting some redundant spaces. But it is hard users to find the wrong point. Such spaces should be accepted.

BTW, I also found the trigger parser accepts some inputs which may not correctly formatted, e.g.

 # echo "traceon 1" > events/ftrace/print/trigger

(from the document, it must be "traceon:1")
But I think this does not decrease the usability.

Thank you,

---

Masami Hiramatsu (2):
tracing/boot: Fix config dependency for synthedic event
tracing: Fix event trigger to accept redundant spaces

 kernel/trace/trace_boot.c           |    2 +-
 kernel/trace/trace_events_trigger.c |   21 +++++++++++++++++++--
 2 files changed, 20 insertions(+), 3 deletions(-)

--
Masami Hiramatsu (Linaro) <[email protected]>

author maintainer
#1 lore raw

PATCH 1/2 tracing/boot: Fix config dependency for synthedic event

Since commit 726721a51838 ("tracing: Move synthetic events to a separate file") decoupled synthetic event from histogram, boot-time tracing also has to check CONFIG_SYNTH_EVENT instead of CONFIG_HIST_TRIGGERS.

Fixes 726721a51838 ("tracing: Move synthetic events to a separate file")
---
 kernel/trace/trace_boot.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/trace/trace_boot.c +1 -1
index 9de29bb45a27..8b5490cb02bb 100644
@@ -120,7 +120,7 @@ trace_boot_add_kprobe_event(struct xbc_node *node, const char *event)
 }
 #endif
 
-#ifdef CONFIG_HIST_TRIGGERS
+#ifdef CONFIG_SYNTH_EVENTS
 static int __init
 trace_boot_add_synth_event(struct xbc_node *node, const char *event)
 {
author maintainer
#2 lore raw

PATCH 2/2 tracing: Fix event trigger to accept redundant spaces

In reply to Masami Hiramatsu

Fix the event trigger to accept redundant spaces in the trigger input.

For example, these return -EINVAL

echo " traceon" > events/ftrace/print/trigger
echo "traceon if common_pid == 0" > events/ftrace/print/trigger echo "disable_event:kmem:kmalloc " > events/ftrace/print/trigger

But these are hard to find what is wrong.

To fix this issue, use skip_spaces() to remove spaces in front of actual tokens, and set NULL if there is no token.

Fixes 85f2b08268c0 ("tracing: Add basic event trigger framework")
---
 kernel/trace/trace_events_trigger.c |   21 +++++++++++++++++++--
 1 file changed, 19 insertions(+), 2 deletions(-)
kernel/trace/trace_events_trigger.c +19 -2
index 3a74736da363..f725802160c0 100644
@@ -216,11 +216,17 @@ static int event_trigger_regex_open(struct inode *inode, struct file *file)
 
 int trigger_process_regex(struct trace_event_file *file, char *buff)
 {
-	char *command, *next = buff;
+	char *command, *next;
 	struct event_command *p;
 	int ret = -EINVAL;
 
+	next = buff = skip_spaces(buff);
 	command = strsep(&next, ": \t");
+	if (next) {
+		next = skip_spaces(next);
+		if (!*next)
+			next = NULL;
+	}
 	command = (command[0] != '!') ? command : command + 1;
 
 	mutex_lock(&trigger_cmd_mutex);
@@ -630,8 +636,14 @@ event_trigger_callback(struct event_command *cmd_ops,
 	int ret;
 
 	/* separate the trigger from the filter (t:n [if filter]) */
-	if (param && isdigit(param[0]))
+	if (param && isdigit(param[0])) {
 		trigger = strsep(&param, " \t");
+		if (param) {
+			param = skip_spaces(param);
+			if (!*param)
+				param = NULL;
+		}
+	}
 
 	trigger_ops = cmd_ops->get_trigger_ops(cmd, trigger);
 
@@ -1368,6 +1380,11 @@ int event_enable_trigger_func(struct event_command *cmd_ops,
 	trigger = strsep(&param, " \t");
 	if (!trigger)
 		return -EINVAL;
+	if (param) {
+		param = skip_spaces(param);
+		if (!*param)
+			param = NULL;
+	}
 
 	system = strsep(&trigger, ":");
 	if (!trigger)
Reviewed-by on the v1 series
#3 lore raw
In reply to Masami Hiramatsu

Hi Masami,

Quoted 6 lines · Masami Hiramatsu

Hi,

These are some fixes which I found recentry on ftrace.

- Since the boot-time tracing synthetic event feature is decoupled from trigger recenty, it should use CONFIG_SYNTH_EVENT.

Oops, yeah, I missed this one in the update, thanks for finding it.

Quoted 4 lines

- The parser of event trigger seems rejecting some redundant spaces. But it is hard users to find the wrong point. Such spaces should be accepted.

Agreed, your patch makes things much better, thanks.

You can add my reviewed-by for both patches.

Thanks,

Tom

Quoted 23 lines

BTW, I also found the trigger parser accepts some inputs which may not correctly formatted, e.g.

 # echo "traceon 1" > events/ftrace/print/trigger

(from the document, it must be "traceon:1")
But I think this does not decrease the usability.

Thank you,

---

Masami Hiramatsu (2):
tracing/boot: Fix config dependency for synthedic event
tracing: Fix event trigger to accept redundant spaces

 kernel/trace/trace_boot.c           |    2 +-
 kernel/trace/trace_events_trigger.c |   21 +++++++++++++++++++--
 2 files changed, 20 insertions(+), 3 deletions(-)

--
Masami Hiramatsu (Linaro) <[email protected]>