Skip to contentSkip to conversation

tracing: Last minute updates

PATCH New Steven Rostedt 1 participant 7 messages Mar 5, 2019

Subsystems (5)
lore
Share & tools
lore

Steven Rostedt

author maintainer
#0 lore raw

cover tracing: Last minute updates

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

Head SHA1: 9f0bbf3115ca9f91f43b7c74e9ac7d79f47fc6c2

Colin Ian King (1):

      tracing: Fix spelling mistake: "analagous" -> "analogous"

Jann Horn (1):
tracing/perf: Use strndup_user() instead of buggy open-coded version

Srikar Dronamraju (1):
doc: trace: Fix documentation for uprobe_profile

Steven Rostedt (VMware) (1):
x86/ftrace: Fix warning and considate ftrace_jmp_replace() and ftrace_call_replace()

Tom Zanussi (2):
tracing: Use str_has_prefix() in synth_event_create()
tracing: Use strncpy instead of memcpy for string keys in hist triggers

----

 Documentation/trace/uprobetracer.rst |  7 +++---
 arch/x86/kernel/ftrace.c             | 42 +++++++++++++++---------------------
 kernel/trace/trace.c                 |  2 +-
 kernel/trace/trace_event_perf.c      | 16 ++++++--------
 kernel/trace/trace_events_hist.c     |  9 ++++----
 5 files changed, 33 insertions(+), 43 deletions(-)
author maintainer
#1 lore raw

PATCH 1/6 tracing: Fix spelling mistake: "analagous" -> "analogous"

From: Colin Ian King <[email protected]>

There is a spelling mistake in the mini-howto help text. Fix it.

---
 kernel/trace/trace.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/trace/trace.c +1 -1
index 2cf3c747a357..3835f7ed3293 100644
@@ -4916,7 +4916,7 @@ static const char readme_msg[] =
 	"\t    unchanged.\n\n"
 	"\t    The enable_hist and disable_hist triggers can be used to\n"
 	"\t    have one event conditionally start and stop another event's\n"
-	"\t    already-attached hist trigger.  The syntax is analagous to\n"
+	"\t    already-attached hist trigger.  The syntax is analogous to\n"
 	"\t    the enable_event and disable_event triggers.\n\n"
 	"\t    Hist trigger handlers and actions are executed whenever a\n"
 	"\t    a histogram entry is added or updated.  They take the form:\n\n"
Signature · 1 line
2.20.1
author maintainer
#2 lore raw

PATCH 2/6 doc: trace: Fix documentation for uprobe_profile

In reply to Steven Rostedt

From: Srikar Dronamraju <[email protected]>

uprobe_profile has filename and number of probe hits information for each uprobe event. The documentation erroneously talks about probe mis-hits. Update the documentation to the correct information.

---
 Documentation/trace/uprobetracer.rst | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)
Documentation/trace/uprobetracer.rst +3 -4
index 4c3bfde2ba47..4346e23e3ae7 100644
@@ -73,10 +73,9 @@ For $comm, the default type is "string"; any other type is invalid.
 
 Event Profiling
 ---------------
-You can check the total number of probe hits and probe miss-hits via
-/sys/kernel/debug/tracing/uprobe_profile.
-The first column is event name, the second is the number of probe hits,
-the third is the number of probe miss-hits.
+You can check the total number of probe hits per event via
+/sys/kernel/debug/tracing/uprobe_profile. The first column is the filename,
+the second is the event name, the third is the number of probe hits.
 
 Usage examples
 --------------
Signature · 1 line
2.20.1
author maintainer
#3 lore raw

PATCH 3/6 tracing/perf: Use strndup_user() instead of buggy open-coded version

In reply to Steven Rostedt

From: Jann Horn <[email protected]>

The first version of this method was missing the check for ret == PATH_MAX; then such a check was added, but it didn't call kfree() on error, so there was still a small memory leak in the error case. Fix it by using strndup_user() instead of open-coding it.

Cc Ingo Molnar <[email protected]>
Fixes 0eadcc7a7bc0 ("perf/core: Fix perf_uprobe_init()")
---
 kernel/trace/trace_event_perf.c | 16 +++++++---------
 1 file changed, 7 insertions(+), 9 deletions(-)
kernel/trace/trace_event_perf.c +7 -9
index 76217bbef815..4629a6104474 100644
@@ -299,15 +299,13 @@ int perf_uprobe_init(struct perf_event *p_event,
 
 	if (!p_event->attr.uprobe_path)
 		return -EINVAL;
-	path = kzalloc(PATH_MAX, GFP_KERNEL);
-	if (!path)
-		return -ENOMEM;
-	ret = strncpy_from_user(
-		path, u64_to_user_ptr(p_event->attr.uprobe_path), PATH_MAX);
-	if (ret == PATH_MAX)
-		return -E2BIG;
-	if (ret < 0)
-		goto out;
+
+	path = strndup_user(u64_to_user_ptr(p_event->attr.uprobe_path),
+			    PATH_MAX);
+	if (IS_ERR(path)) {
+		ret = PTR_ERR(path);
+		return (ret == -EINVAL) ? -E2BIG : ret;
+	}
 	if (path[0] == '\0') {
 		ret = -EINVAL;
 		goto out;
Signature · 1 line
2.20.1
author maintainer
#4 lore raw

PATCH 4/6 x86/ftrace: Fix warning and considate ftrace_jmp_replace() and ftrace_call_replace()

In reply to Steven Rostedt

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

Arnd reported the following compiler warning:

arch/x86/kernel/ftrace.c:669:23: error: 'ftrace_jmp_replace' defined but not used [-Werror=unused-function]

The ftrace_jmp_replace() function now only has a single user and should be simply moved by that user. But looking at the code, it shows that ftrace_jmp_replace() is similar to ftrace_call_replace() except that instead of using the opcode of 0xe8 it uses 0xe9. It makes more sense to consolidate that function into one implementation that both ftrace_jmp_replace() and ftrace_call_replace() use by passing in the op code separate.

The structure in ftrace_code_union is also modified to replace the "e8" field with the more appropriate name "op".

Fixes d2a68c4effd8 ("x86/ftrace: Do not call function graph from dynamic trampolines")
---
 arch/x86/kernel/ftrace.c | 42 ++++++++++++++++------------------------
 1 file changed, 17 insertions(+), 25 deletions(-)
arch/x86/kernel/ftrace.c +17 -25
index 8257a59704ae..763d4264d16a 100644
@@ -49,7 +49,7 @@ int ftrace_arch_code_modify_post_process(void)
 union ftrace_code_union {
 	char code[MCOUNT_INSN_SIZE];
 	struct {
-		unsigned char e8;
+		unsigned char op;
 		int offset;
 	} __attribute__((packed));
 };
@@ -59,20 +59,23 @@ static int ftrace_calc_offset(long ip, long addr)
 	return (int)(addr - ip);
 }
 
-static unsigned char *ftrace_call_replace(unsigned long ip, unsigned long addr)
+static unsigned char *
+ftrace_text_replace(unsigned char op, unsigned long ip, unsigned long addr)
 {
 	static union ftrace_code_union calc;
 
-	calc.e8		= 0xe8;
+	calc.op		= op;
 	calc.offset	= ftrace_calc_offset(ip + MCOUNT_INSN_SIZE, addr);
 
-	/*
-	 * No locking needed, this must be called via kstop_machine
-	 * which in essence is like running on a uniprocessor machine.
-	 */
 	return calc.code;
 }
 
+static unsigned char *
+ftrace_call_replace(unsigned long ip, unsigned long addr)
+{
+	return ftrace_text_replace(0xe8, ip, addr);
+}
+
 static inline int
 within(unsigned long addr, unsigned long start, unsigned long end)
 {
@@ -664,22 +667,6 @@ int __init ftrace_dyn_arch_init(void)
 	return 0;
 }
 
-#if defined(CONFIG_X86_64) || defined(CONFIG_FUNCTION_GRAPH_TRACER)
-static unsigned char *ftrace_jmp_replace(unsigned long ip, unsigned long addr)
-{
-	static union ftrace_code_union calc;
-
-	/* Jmp not a call (ignore the .e8) */
-	calc.e8		= 0xe9;
-	calc.offset	= ftrace_calc_offset(ip + MCOUNT_INSN_SIZE, addr);
-
-	/*
-	 * ftrace external locks synchronize the access to the static variable.
-	 */
-	return calc.code;
-}
-#endif
-
 /* Currently only x86_64 supports dynamic trampolines */
 #ifdef CONFIG_X86_64
 
@@ -891,8 +878,8 @@ static void *addr_from_call(void *ptr)
 		return NULL;
 
 	/* Make sure this is a call */
-	if (WARN_ON_ONCE(calc.e8 != 0xe8)) {
-		pr_warn("Expected e8, got %x\n", calc.e8);
+	if (WARN_ON_ONCE(calc.op != 0xe8)) {
+		pr_warn("Expected e8, got %x\n", calc.op);
 		return NULL;
 	}
 
@@ -963,6 +950,11 @@ void arch_ftrace_trampoline_free(struct ftrace_ops *ops)
 #ifdef CONFIG_DYNAMIC_FTRACE
 extern void ftrace_graph_call(void);
 
+static unsigned char *ftrace_jmp_replace(unsigned long ip, unsigned long addr)
+{
+	return ftrace_text_replace(0xe9, ip, addr);
+}
+
 static int ftrace_mod_jmp(unsigned long ip, void *func)
 {
 	unsigned char *new;
Signature · 1 line
2.20.1
author maintainer
#5 lore raw

PATCH 5/6 tracing: Use str_has_prefix() in synth_event_create()

In reply to Steven Rostedt

From: Tom Zanussi <[email protected]>

Since we now have a str_has_prefix() that returns the length, we can use that instead of explicitly calculating it.

---
 kernel/trace/trace_events_hist.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
kernel/trace/trace_events_hist.c +2 -2
index 66386ba1425f..5b03b9a869bb 100644
@@ -1316,8 +1316,8 @@ static int synth_event_create(int argc, const char **argv)
 
 	/* This interface accepts group name prefix */
 	if (strchr(name, '/')) {
-		len = sizeof(SYNTH_SYSTEM "/") - 1;
-		if (strncmp(name, SYNTH_SYSTEM "/", len))
+		len = str_has_prefix(name, SYNTH_SYSTEM "/");
+		if (len == 0)
 			return -EINVAL;
 		name += len;
 	}
Signature · 1 line
2.20.1
author maintainer
#6 lore raw

PATCH 6/6 tracing: Use strncpy instead of memcpy for string keys in hist triggers

In reply to Steven Rostedt

From: Tom Zanussi <[email protected]>

Because there may be random garbage beyond a string's null terminator, it's not correct to copy the the complete character array for use as a hist trigger key. This results in multiple histogram entries for the 'same' string key.

So, in the case of a string key, use strncpy instead of memcpy to avoid copying in the extra bytes.

Before, using the gdbus entries in the following hist trigger as an example:

  # echo 'hist:key=comm' > /sys/kernel/debug/tracing/events/sched/sched_waking/trigger
  # cat /sys/kernel/debug/tracing/events/sched/sched_waking/hist

...

  { comm: ImgDecoder #4                      } hitcount:        203
  { comm: gmain                              } hitcount:        213
  { comm: gmain                              } hitcount:        216
  { comm: StreamTrans #73                    } hitcount:        221
  { comm: mozStorage #3                      } hitcount:        230
  { comm: gdbus                              } hitcount:        233
  { comm: StyleThread#5                      } hitcount:        253
  { comm: gdbus                              } hitcount:        256
  { comm: gdbus                              } hitcount:        260
  { comm: StyleThread#4                      } hitcount:        271

...

  # cat /sys/kernel/debug/tracing/events/sched/sched_waking/hist | egrep gdbus | wc -l
  51

After:

  # cat /sys/kernel/debug/tracing/events/sched/sched_waking/hist | egrep gdbus | wc -l
  1
Cc Namhyung Kim <[email protected]>
Fixes 79e577cbce4c4 ("tracing: Support string type key properly")
---
 kernel/trace/trace_events_hist.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
kernel/trace/trace_events_hist.c +3 -2
index 5b03b9a869bb..c7774fa119a7 100644
@@ -5157,9 +5157,10 @@ static inline void add_to_key(char *compound_key, void *key,
 		/* ensure NULL-termination */
 		if (size > key_field->size - 1)
 			size = key_field->size - 1;
-	}
 
-	memcpy(compound_key + key_field->offset, key, size);
+		strncpy(compound_key + key_field->offset, (char *)key, size);
+	} else
+		memcpy(compound_key + key_field->offset, key, size);
 }
 
 static void
Signature · 1 line
2.20.1