Skip to contentSkip to conversation

tracing: Last minute updates for 4.13

PATCH New Steven Rostedt 1 participant 4 messages Jul 6, 2017

Subsystems (2)
lore
Share & tools
lore

Steven Rostedt

author maintainer
#0 lore raw

cover tracing: Last minute updates for 4.13

Some quick fixes for 4.13, includes merging a fix that was already sent to mainline.

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

Head SHA1: 69d71879d2cf67a381055f698a1d7def00dc4ed7

Steven Rostedt (VMware) (4):
ftrace: Decrement count for dyn_ftrace_total_info for init functions
ftrace: Fix regression with module command in stack_trace_filter Merge commit '0f17976568b3f72e676450af0c0db6f8752253d6' into trace/ftrace/core
ftrace: Test for NULL iter->tr in regex for stack_trace_filter changes

----

 kernel/trace/ftrace.c          |  6 ++----
 kernel/trace/trace.c           |  3 +++
 kernel/trace/trace_functions.c | 12 ++++++++++++
 kernel/trace/trace_stack.c     |  6 ++++--
 4 files changed, 21 insertions(+), 6 deletions(-)
author maintainer
#1 lore raw

PATCH 1/3 ftrace: Decrement count for dyn_ftrace_total_info for init functions

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

Init boot up functions may be traced, but they are also freed when the kernel finishes booting. These are removed from the ftrace tables, and the debug variable for dyn_ftrace_total_info needs to reflect that as well.

---
 kernel/trace/ftrace.c | 1 +
 1 file changed, 1 insertion(+)
kernel/trace/ftrace.c +1 -0
index 2c79630cd267..e392f750a1cf 100644
@@ -5825,6 +5825,7 @@ void __init ftrace_free_init_mem(void)
 		if (!rec)
 			continue;
 		pg->index--;
+		ftrace_update_tot_cnt--;
 		if (!pg->index) {
 			*last_pg = pg->next;
 			order = get_count_order(pg->size / ENTRIES_PER_PAGE);
Signature · 1 line
2.10.2
author maintainer
#2 lore raw

PATCH 2/3 ftrace: Fix regression with module command in stack_trace_filter

In reply to Steven Rostedt

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

When doing the following command:

 # echo ":mod:kvm_intel" > /sys/kernel/tracing/stack_trace_filter

it triggered a crash.

This happened with the clean up of probes. It required all callers to the regex function (doing ftrace filtering) to have ops->private be a pointer to a trace_array. But for the stack tracer, that is not the case.

Allow for the ops->private to be NULL, and change the function command callbacks to handle the trace_array pointer being NULL as well.

Fixes d2afd57a4b96 ("tracing/ftrace: Allow instances to have their own function probes")
---
 kernel/trace/ftrace.c          |  3 ---
 kernel/trace/trace.c           |  3 +++
 kernel/trace/trace_functions.c | 12 ++++++++++++
 kernel/trace/trace_stack.c     |  6 ++++--
 4 files changed, 19 insertions(+), 5 deletions(-)
kernel/trace/ftrace.c +0 -3
index 9e5841dc14b5..b308be30dfb9 100644
@@ -4337,9 +4337,6 @@ static int ftrace_process_regex(struct ftrace_iterator *iter,
 
 	command = strsep(&next, ":");
 
-	if (WARN_ON_ONCE(!tr))
-		return -EINVAL;
-
 	mutex_lock(&ftrace_cmd_mutex);
 	list_for_each_entry(p, &ftrace_commands, list) {
 		if (strcmp(p->name, command) == 0) {
kernel/trace/trace.c +3 -0
index 1122f151466f..091e801145c9 100644
@@ -6881,6 +6881,9 @@ ftrace_trace_snapshot_callback(struct trace_array *tr, struct ftrace_hash *hash,
 	char *number;
 	int ret;
 
+	if (!tr)
+		return -ENODEV;
+
 	/* hash funcs only work with set_ftrace_filter */
 	if (!enable)
 		return -EINVAL;
kernel/trace/trace_functions.c +12 -0
index a3bddbfd0874..a0910c0cdf2e 100644
@@ -654,6 +654,9 @@ ftrace_trace_onoff_callback(struct trace_array *tr, struct ftrace_hash *hash,
 {
 	struct ftrace_probe_ops *ops;
 
+	if (!tr)
+		return -ENODEV;
+
 	/* we register both traceon and traceoff to this callback */
 	if (strcmp(cmd, "traceon") == 0)
 		ops = param ? &traceon_count_probe_ops : &traceon_probe_ops;
@@ -670,6 +673,9 @@ ftrace_stacktrace_callback(struct trace_array *tr, struct ftrace_hash *hash,
 {
 	struct ftrace_probe_ops *ops;
 
+	if (!tr)
+		return -ENODEV;
+
 	ops = param ? &stacktrace_count_probe_ops : &stacktrace_probe_ops;
 
 	return ftrace_trace_probe_callback(tr, ops, hash, glob, cmd,
@@ -682,6 +688,9 @@ ftrace_dump_callback(struct trace_array *tr, struct ftrace_hash *hash,
 {
 	struct ftrace_probe_ops *ops;
 
+	if (!tr)
+		return -ENODEV;
+
 	ops = &dump_probe_ops;
 
 	/* Only dump once. */
@@ -695,6 +704,9 @@ ftrace_cpudump_callback(struct trace_array *tr, struct ftrace_hash *hash,
 {
 	struct ftrace_probe_ops *ops;
 
+	if (!tr)
+		return -ENODEV;
+
 	ops = &cpudump_probe_ops;
 
 	/* Only dump once. */
kernel/trace/trace_stack.c +4 -2
index 76aa04d4c925..b4a751e8f9d6 100644
@@ -409,7 +409,9 @@ static const struct file_operations stack_trace_fops = {
 static int
 stack_trace_filter_open(struct inode *inode, struct file *file)
 {
-	return ftrace_regex_open(&trace_ops, FTRACE_ITER_FILTER,
+	struct ftrace_ops *ops = inode->i_private;
+
+	return ftrace_regex_open(ops, FTRACE_ITER_FILTER,
 				 inode, file);
 }
 
@@ -476,7 +478,7 @@ static __init int stack_trace_init(void)
 			NULL, &stack_trace_fops);
 
 	trace_create_file("stack_trace_filter", 0444, d_tracer,
-			NULL, &stack_trace_filter_fops);
+			  &trace_ops, &stack_trace_filter_fops);
 
 	if (stack_trace_filter_buf[0])
 		ftrace_set_early_filter(&trace_ops, stack_trace_filter_buf, 1);
Signature · 1 line
2.10.2
author maintainer
#3 lore raw

PATCH 3/3 ftrace: Test for NULL iter->tr in regex for stack_trace_filter changes

In reply to Steven Rostedt

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

As writing into stack_trace_filter, the iter-tr is not set and is NULL. Check if it is NULL before dereferencing it in ftrace_regex_release().

Fixes 8c08f0d5c6fb ("ftrace: Have cached module filters be an active filter")
---
 kernel/trace/ftrace.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/trace/ftrace.c +1 -1
index f8c18f15b190..2953d558bbee 100644
@@ -5043,7 +5043,7 @@ int ftrace_regex_release(struct inode *inode, struct file *file)
 
 		if (filter_hash) {
 			orig_hash = &iter->ops->func_hash->filter_hash;
-			if (!list_empty(&iter->tr->mod_trace))
+			if (iter->tr && !list_empty(&iter->tr->mod_trace))
 				iter->hash->flags |= FTRACE_HASH_FL_MOD;
 		} else
 			orig_hash = &iter->ops->func_hash->notrace_hash;
Signature · 1 line
2.10.2