Skip to contentSkip to conversation

tracing: kprobes: Prohibit probing on notrace functions

PATCH Superseded Masami Hiramatsu 4 participants 20 messages Jul 26, 2018 – Jul 28, 2018

Subsystems (2)

v2 of 5 Superseded Latest is v5 →

lore
Share & tools
lore

Masami Hiramatsu

author maintainer
#0 lore raw

v2 cover tracing: kprobes: Prohibit probing on notrace functions

Hello, this is the 2nd version of the series to prohibit kprobe on notrace functions which Francis sent before.

Here is v1 series:
https://lkml.org/lkml/2018/7/12/678

In this version, I've add a kconfig option to remove notrace protection just for debugging, and also fix ftracetest testcase to not probe notrace function.

Thank you,

---

Francis Deslauriers (1):
selftest/ftrace: Move kprobe selftest function to separate compile unit

Masami Hiramatsu (2):
tracing: kprobes: Prohibit probing on notrace function selftests/ftrace: Fix kprobe string testcase to not probe notrace function

 kernel/trace/Kconfig                               |   18 ++++++++++
 kernel/trace/Makefile                              |    5 +++
 kernel/trace/trace_kprobe.c                        |   35 ++++++++++++++------
 kernel/trace/trace_kprobe_selftest.c               |   10 ++++++
 kernel/trace/trace_kprobe_selftest.h               |    7 ++++
 .../ftrace/test.d/kprobe/kprobe_args_string.tc     |   30 +++++++----------
 6 files changed, 76 insertions(+), 29 deletions(-)
 create mode 100644 kernel/trace/trace_kprobe_selftest.c
 create mode 100644 kernel/trace/trace_kprobe_selftest.h

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

author maintainer
#1 lore raw

PATCH v2 1/3 tracing: kprobes: Prohibit probing on notrace function

Prohibit kprobe-events probing on notrace function. Since probing on the notrace function can cause recursive event call. In most case those are just skipped, but in some case it falls into infinit recursive call.

This protection can be disabled by the kconfig CONFIG_KPROBE_EVENTS_ON_NOTRACE=y, but it is highly recommended to keep it "n" for normal kernel.

---
Changes from v1
- Add CONFIG_KPROBE_EVENTS_ON_NOTRACE kconfig for knocking down the protection.

---
 kernel/trace/Kconfig        |   18 ++++++++++++++++++
 kernel/trace/trace_kprobe.c |   23 +++++++++++++++++++++++
 2 files changed, 41 insertions(+)
kernel/trace/Kconfig +18 -0
index dcc0166d1997..24d5a58467a3 100644
@@ -456,6 +456,24 @@ config KPROBE_EVENTS
 	  This option is also required by perf-probe subcommand of perf tools.
 	  If you want to use perf tools, this option is strongly recommended.
 
+config KPROBE_EVENTS_ON_NOTRACE
+	bool "Do NOT protect notrace function from kprobe events"
+	depends on KPROBE_EVENTS
+	default n
+	help
+	  This is only for the developers who want to debug ftrace itself
+	  using kprobe events.
+
+	  Usually, ftrace related functions are protected from kprobe-events
+	  to prevent an infinit recursion or any unexpected execution path
+	  which leads to a kernel crash.
+
+	  This option disables such protection and allows you to put kprobe
+	  events on ftrace functions for debugging ftrace by itself.
+	  Note that this might let you shoot yourself in the foot.
+
+	  If unsure, say N.
+
 config UPROBE_EVENTS
 	bool "Enable uprobes-based dynamic events"
 	depends on ARCH_SUPPORTS_UPROBES
kernel/trace/trace_kprobe.c +23 -0
index 27ace4513c43..1f1b4d712a7e 100644
@@ -496,6 +496,23 @@ disable_trace_kprobe(struct trace_kprobe *tk, struct trace_event_file *file)
 	return ret;
 }
 
+#ifdef CONFIG_KPROBE_EVENTS_ON_NOTRACE
+#define within_notrace_func(tk)	(false)
+#else
+static bool within_notrace_func(struct trace_kprobe *tk)
+{
+	unsigned long offset, size, addr;
+
+	addr = kallsyms_lookup_name(trace_kprobe_symbol(tk));
+	addr += trace_kprobe_offset(tk);
+
+	if (!kallsyms_lookup_size_offset(addr, &size, &offset))
+		return true;	/* Out of range. */
+
+	return !ftrace_location_range(addr - offset, addr - offset + size);
+}
+#endif
+
 /* Internal register function - just handle k*probes and flags */
 static int __register_trace_kprobe(struct trace_kprobe *tk)
 {
@@ -504,6 +521,12 @@ static int __register_trace_kprobe(struct trace_kprobe *tk)
 	if (trace_probe_is_registered(&tk->tp))
 		return -EINVAL;
 
+	if (within_notrace_func(tk)) {
+		pr_warn("Could not probe notrace function %s\n",
+			trace_kprobe_symbol(tk));
+		return -EINVAL;
+	}
+
 	for (i = 0; i < tk->tp.nr_args; i++)
 		traceprobe_update_arg(&tk->tp.args[i]);
 
author maintainer
#2 lore raw

Re: [PATCH v2 1/3] tracing: kprobes: Prohibit probing on notrace function

Quoted 55 lines · On Thu, 26 Jul 2018 14:53:27 +0900 Masami Hiramatsu <[email protected]> wrote:

Prohibit kprobe-events probing on notrace function. Since probing on the notrace function can cause recursive event call. In most case those are just skipped, but in some case it falls into infinit recursive call.

This protection can be disabled by the kconfig CONFIG_KPROBE_EVENTS_ON_NOTRACE=y, but it is highly recommended to keep it "n" for normal kernel.

---
Changes from v1
- Add CONFIG_KPROBE_EVENTS_ON_NOTRACE kconfig for knocking down the protection.

---
 kernel/trace/Kconfig        |   18 ++++++++++++++++++
 kernel/trace/trace_kprobe.c |   23 +++++++++++++++++++++++
 2 files changed, 41 insertions(+)
kernel/trace/Kconfig +18 -0
index dcc0166d1997..24d5a58467a3 100644
@@ -456,6 +456,24 @@ config KPROBE_EVENTS
 	  This option is also required by perf-probe subcommand of perf tools.
 	  If you want to use perf tools, this option is strongly recommended.
 
+config KPROBE_EVENTS_ON_NOTRACE
+	bool "Do NOT protect notrace function from kprobe events"
+	depends on KPROBE_EVENTS
+	default n
+	help
+	  This is only for the developers who want to debug ftrace itself
+	  using kprobe events.
+
+	  Usually, ftrace related functions are protected from kprobe-events
+	  to prevent an infinit recursion or any unexpected execution path
+	  which leads to a kernel crash.
+
+	  This option disables such protection and allows you to put kprobe
+	  events on ftrace functions for debugging ftrace by itself.
+	  Note that this might let you shoot yourself in the foot.
+
+	  If unsure, say N.
+
 config UPROBE_EVENTS
 	bool "Enable uprobes-based dynamic events"
 	depends on ARCH_SUPPORTS_UPROBES
kernel/trace/trace_kprobe.c +0 -0
index 27ace4513c43..1f1b4d712a7e 100644
@@ -496,6 +496,23 @@ disable_trace_kprobe(struct trace_kprobe *tk, struct trace_event_file *file)
 	return ret;

kernel/trace/trace_kprobe.c disable_trace_kprobe(struct trace_kprobe *tk, struct trace_event_file *file) · line 506

Quoted 10 lines
kernel/trace/trace_kprobe.c +8 -0
 }
 
+#ifdef CONFIG_KPROBE_EVENTS_ON_NOTRACE
+#define within_notrace_func(tk)	(false)
+#else
+static bool within_notrace_func(struct trace_kprobe *tk)
+{
+	unsigned long offset, size, addr;
+
+	addr = kallsyms_lookup_name(trace_kprobe_symbol(tk));

Oops, I found this is wrong. (Thanks for old myself :P) As ftracetest probepoint.tc said, kprobe-events can be defined without symbol (direct address) for debugging. In that case trace_kprobe_symbol will not return the symbol string. I'll fix this series again.

Thank you,

Quoted 26 lines
kernel/trace/trace_kprobe.c +15 -0
+	addr += trace_kprobe_offset(tk);
+
+	if (!kallsyms_lookup_size_offset(addr, &size, &offset))
+		return true;	/* Out of range. */
+
+	return !ftrace_location_range(addr - offset, addr - offset + size);
+}
+#endif
+
 /* Internal register function - just handle k*probes and flags */
 static int __register_trace_kprobe(struct trace_kprobe *tk)
 {
@@ -504,6 +521,12 @@ static int __register_trace_kprobe(struct trace_kprobe *tk)
 	if (trace_probe_is_registered(&tk->tp))
 		return -EINVAL;
 
+	if (within_notrace_func(tk)) {
+		pr_warn("Could not probe notrace function %s\n",
+			trace_kprobe_symbol(tk));
+		return -EINVAL;
+	}
+
 	for (i = 0; i < tk->tp.nr_args; i++)
 		traceprobe_update_arg(&tk->tp.args[i]);
 
Signature · 1 line
Masami Hiramatsu <[email protected]>
#3 lore raw

Re: [PATCH v2 1/3] tracing: kprobes: Prohibit probing on notrace function

In reply to Masami Hiramatsu
I love your patch! Yet something to improve:

Hi Masami,

I love your patch! Yet something to improve:

[auto build test ERROR on tip/perf/core]
[also build test ERROR on v4.18-rc6 next-20180727]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system]

url: https://github.com/0day-ci/linux/commits/Masami-Hiramatsu/tracing-kprobes-Prohibit-probing-on-notrace-functions/20180728-145919
config: x86_64-randconfig-x018-201829 (attached as .config)
compiler: gcc-7 (Debian 7.3.0-16) 7.3.0
reproduce:

        # save the attached .config to linux build tree
        make ARCH=x86_64 

All errors (new ones prefixed by >>):

kernel//trace/trace_kprobe.c: In function 'within_notrace_func':

>> kernel//trace/trace_kprobe.c:503:10: error: implicit declaration of function 'ftrace_location_range'; did you mean 'ftrace_location'? [-Werror=implicit-function-declaration]
     return !ftrace_location_range(addr - offset, addr - offset + size);
             ^~~~~~~~~~~~~~~~~~~~~
             ftrace_location

cc1: some warnings being treated as errors

vim +503 kernel//trace/trace_kprobe.c

489
490 #ifdef CONFIG_KPROBE_EVENTS_ON_NOTRACE
491 #define within_notrace_func(tk) (false)
492 #else
493 static bool within_notrace_func(struct trace_kprobe *tk)
494 {
495 unsigned long offset, size, addr;
496
497 addr = kallsyms_lookup_name(trace_kprobe_symbol(tk));
498 addr += trace_kprobe_offset(tk);
499
500 if (!kallsyms_lookup_size_offset(addr, &size, &offset))
501 return true; /* Out of range. */
502

 > 503		return !ftrace_location_range(addr - offset, addr - offset + size);

504 }
505 #endif
506

---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all Intel Corporation

author maintainer
#4 lore raw

Re: [PATCH v2 1/3] tracing: kprobes: Prohibit probing on notrace function

Oops, thanks!

I've missed CONFIG_FUNCTION_TRACER=n case...

Quoted 48 lines · On Sat, 28 Jul 2018 16:11:34 +0800 kbuild test robot <[email protected]> wrote:

Hi Masami,

I love your patch! Yet something to improve:

[auto build test ERROR on tip/perf/core]
[also build test ERROR on v4.18-rc6 next-20180727]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system]

url: https://github.com/0day-ci/linux/commits/Masami-Hiramatsu/tracing-kprobes-Prohibit-probing-on-notrace-functions/20180728-145919
config: x86_64-randconfig-x018-201829 (attached as .config)
compiler: gcc-7 (Debian 7.3.0-16) 7.3.0
reproduce:

        # save the attached .config to linux build tree
        make ARCH=x86_64 

All errors (new ones prefixed by >>):

kernel//trace/trace_kprobe.c: In function 'within_notrace_func':

Quoted 1 line
Quoted 1 line

kernel//trace/trace_kprobe.c:503:10: error: implicit declaration of function 'ftrace_location_range'; did you mean 'ftrace_location'? [-Werror=implicit-function-declaration]

     return !ftrace_location_range(addr - offset, addr - offset + size);
             ^~~~~~~~~~~~~~~~~~~~~
             ftrace_location

cc1: some warnings being treated as errors

vim +503 kernel//trace/trace_kprobe.c

   489	
   490	#ifdef CONFIG_KPROBE_EVENTS_ON_NOTRACE
   491	#define within_notrace_func(tk)	(false)
   492	#else
   493	static bool within_notrace_func(struct trace_kprobe *tk)
   494	{
   495		unsigned long offset, size, addr;
   496	
   497		addr = kallsyms_lookup_name(trace_kprobe_symbol(tk));
   498		addr += trace_kprobe_offset(tk);
   499	
   500		if (!kallsyms_lookup_size_offset(addr, &size, &offset))
   501			return true;	/* Out of range. */
   502	
Quoted 1 line

503 return !ftrace_location_range(addr - offset, addr - offset + size);

504 }
505 #endif
506

---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all Intel Corporation

Signature · 1 line
Masami Hiramatsu <[email protected]>
#5 lore raw

Re: [PATCH v2 1/3] tracing: kprobes: Prohibit probing on notrace function

In reply to Masami Hiramatsu
I love your patch! Yet something to improve:

Hi Masami,

I love your patch! Yet something to improve:

[auto build test ERROR on tip/perf/core]
[also build test ERROR on v4.18-rc6 next-20180727]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system]

url: https://github.com/0day-ci/linux/commits/Masami-Hiramatsu/tracing-kprobes-Prohibit-probing-on-notrace-functions/20180728-145919
config: i386-randconfig-a0-201829 (attached as .config)
compiler: gcc-4.9 (Debian 4.9.4-2) 4.9.4 reproduce:

        # save the attached .config to linux build tree
        make ARCH=i386 

All errors (new ones prefixed by >>):

kernel/trace/trace_kprobe.c: In function 'within_notrace_func':

>> kernel/trace/trace_kprobe.c:503:2: error: implicit declaration of function 'ftrace_location_range' [-Werror=implicit-function-declaration]
     return !ftrace_location_range(addr - offset, addr - offset + size);
     ^

cc1: some warnings being treated as errors

vim +/ftrace_location_range +503 kernel/trace/trace_kprobe.c

489
490 #ifdef CONFIG_KPROBE_EVENTS_ON_NOTRACE
491 #define within_notrace_func(tk) (false)
492 #else
493 static bool within_notrace_func(struct trace_kprobe *tk)
494 {
495 unsigned long offset, size, addr;
496
497 addr = kallsyms_lookup_name(trace_kprobe_symbol(tk));
498 addr += trace_kprobe_offset(tk);
499
500 if (!kallsyms_lookup_size_offset(addr, &size, &offset))
501 return true; /* Out of range. */
502

 > 503		return !ftrace_location_range(addr - offset, addr - offset + size);

504 }
505 #endif
506

---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all Intel Corporation

author maintainer
#6 lore raw

PATCH v2 2/3 selftest/ftrace: Move kprobe selftest function to separate compile unit

In reply to Masami Hiramatsu

From: Francis Deslauriers <[email protected]>

Move selftest function to its own compile unit so it can be compiled with the ftrace cflags (CC_FLAGS_FTRACE) allowing it to be probed during the ftrace startup tests.

---
 kernel/trace/Makefile                |    5 +++++
 kernel/trace/trace_kprobe.c          |   12 +-----------
 kernel/trace/trace_kprobe_selftest.c |   10 ++++++++++
 kernel/trace/trace_kprobe_selftest.h |    7 +++++++
 4 files changed, 23 insertions(+), 11 deletions(-)
 create mode 100644 kernel/trace/trace_kprobe_selftest.c
 create mode 100644 kernel/trace/trace_kprobe_selftest.h
kernel/trace/Makefile +5 -0
index e2538c7638d4..e38771eccb2f 100644
@@ -13,6 +13,11 @@ obj-y += trace_selftest_dynamic.o
 endif
 endif
 
+ifdef CONFIG_FTRACE_STARTUP_TEST
+CFLAGS_trace_kprobe_selftest.o = $(CC_FLAGS_FTRACE)
+obj-$(CONFIG_KPROBE_EVENTS) += trace_kprobe_selftest.o
+endif
+
 # If unlikely tracing is enabled, do not trace these files
 ifdef CONFIG_TRACING_BRANCHES
 KBUILD_CFLAGS += -DDISABLE_BRANCH_PROFILING
kernel/trace/trace_kprobe.c +1 -11
index 1f1b4d712a7e..859f7c310a00 100644
@@ -23,6 +23,7 @@
 #include <linux/rculist.h>
 #include <linux/error-injection.h>
 
+#include "trace_kprobe_selftest.h"
 #include "trace_probe.h"
 
 #define KPROBE_EVENT_SYSTEM "kprobes"
@@ -1573,17 +1574,6 @@ fs_initcall(init_kprobe_trace);
 
 
 #ifdef CONFIG_FTRACE_STARTUP_TEST
-/*
- * The "__used" keeps gcc from removing the function symbol
- * from the kallsyms table. 'noinline' makes sure that there
- * isn't an inlined version used by the test method below
- */
-static __used __init noinline int
-kprobe_trace_selftest_target(int a1, int a2, int a3, int a4, int a5, int a6)
-{
-	return a1 + a2 + a3 + a4 + a5 + a6;
-}
-
 static __init struct trace_event_file *
 find_trace_probe_file(struct trace_kprobe *tk, struct trace_array *tr)
 {
kernel/trace/trace_kprobe_selftest.c new file +10 -0
new file mode 100644
index 000000000000..16548ee4c8c6
@@ -0,0 +1,10 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Function used during the kprobe self test. This function is in a separate
+ * compile unit so it can be compile with CC_FLAGS_FTRACE to ensure that it
+ * can be probed by the selftests.
+ */
+int kprobe_trace_selftest_target(int a1, int a2, int a3, int a4, int a5, int a6)
+{
+	return a1 + a2 + a3 + a4 + a5 + a6;
+}
kernel/trace/trace_kprobe_selftest.h new file +7 -0
new file mode 100644
index 000000000000..4e10ec41c013
@@ -0,0 +1,7 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * Function used during the kprobe self test. This function is in a separate
+ * compile unit so it can be compile with CC_FLAGS_FTRACE to ensure that it
+ * can be probed by the selftests.
+ */
+int kprobe_trace_selftest_target(int a1, int a2, int a3, int a4, int a5, int a6);
maintainer
#7 lore raw

Re: [PATCH v2 2/3] selftest/ftrace: Move kprobe selftest function to separate compile unit

Quoted 8 lines · On Thu, 26 Jul 2018 14:53:55 +0900 Masami Hiramatsu <[email protected]> wrote:

From: Francis Deslauriers <[email protected]>

Move selftest function to its own compile unit so it can be compiled with the ftrace cflags (CC_FLAGS_FTRACE) allowing it to be probed during the ftrace startup tests.

Hi Masami,

Actually, since you are sending this as part of your patch queue, you need to add your Signed-off-by here and not Acked-by. That means it has gone through you.

I've applied the first patch already, just resend this one, where you add you Signed-off-by instead of Acked-by.

Thanks!

-- Steve

Quoted 9 lines
---
 kernel/trace/Makefile                |    5 +++++
 kernel/trace/trace_kprobe.c          |   12 +-----------
 kernel/trace/trace_kprobe_selftest.c |   10 ++++++++++
 kernel/trace/trace_kprobe_selftest.h |    7 +++++++
 4 files changed, 23 insertions(+), 11 deletions(-)
 create mode 100644 kernel/trace/trace_kprobe_selftest.c
 create mode 100644 kernel/trace/trace_kprobe_selftest.h
author maintainer
#8 lore raw

Re: [PATCH v2 2/3] selftest/ftrace: Move kprobe selftest function to separate compile unit

Quoted 9 lines · On Thu, 26 Jul 2018 19:29:43 -0400 Steven Rostedt <[email protected]> wrote:
Quoted 6 lines · On Thu, 26 Jul 2018 14:53:55 +0900 Masami Hiramatsu <[email protected]> wrote:

From: Francis Deslauriers <[email protected]>

Move selftest function to its own compile unit so it can be compiled with the ftrace cflags (CC_FLAGS_FTRACE) allowing it to be probed during the ftrace startup tests.

Quoted 8 lines
Quoted 2 lines

Hi Masami,

Actually, since you are sending this as part of your patch queue, you need to add your Signed-off-by here and not Acked-by. That means it has gone through you.

Ah, I see.

Quoted 3 lines

I've applied the first patch already, just resend this one, where you add you Signed-off-by instead of Acked-by.

OK, I'll do that soon.

Thanks!

Quoted 15 lines

Thanks!

-- Steve

Quoted 9 lines
---
 kernel/trace/Makefile                |    5 +++++
 kernel/trace/trace_kprobe.c          |   12 +-----------
 kernel/trace/trace_kprobe_selftest.c |   10 ++++++++++
 kernel/trace/trace_kprobe_selftest.h |    7 +++++++
 4 files changed, 23 insertions(+), 11 deletions(-)
 create mode 100644 kernel/trace/trace_kprobe_selftest.c
 create mode 100644 kernel/trace/trace_kprobe_selftest.h
Signature · 1 line
Masami Hiramatsu <[email protected]>
author maintainer
#9 lore raw

PATCH v2 2/3 selftest/ftrace: Move kprobe selftest function to separate compile unit

In reply to Steven Rostedt

From: Francis Deslauriers <[email protected]>

Move selftest function to its own compile unit so it can be compiled with the ftrace cflags (CC_FLAGS_FTRACE) allowing it to be probed during the ftrace startup tests.

---
 kernel/trace/Makefile                |    5 +++++
 kernel/trace/trace_kprobe.c          |   12 +-----------
 kernel/trace/trace_kprobe_selftest.c |   10 ++++++++++
 kernel/trace/trace_kprobe_selftest.h |    7 +++++++
 4 files changed, 23 insertions(+), 11 deletions(-)
 create mode 100644 kernel/trace/trace_kprobe_selftest.c
 create mode 100644 kernel/trace/trace_kprobe_selftest.h
kernel/trace/Makefile +5 -0
index e2538c7638d4..e38771eccb2f 100644
@@ -13,6 +13,11 @@ obj-y += trace_selftest_dynamic.o
 endif
 endif
 
+ifdef CONFIG_FTRACE_STARTUP_TEST
+CFLAGS_trace_kprobe_selftest.o = $(CC_FLAGS_FTRACE)
+obj-$(CONFIG_KPROBE_EVENTS) += trace_kprobe_selftest.o
+endif
+
 # If unlikely tracing is enabled, do not trace these files
 ifdef CONFIG_TRACING_BRANCHES
 KBUILD_CFLAGS += -DDISABLE_BRANCH_PROFILING
kernel/trace/trace_kprobe.c +1 -11
index 1f1b4d712a7e..859f7c310a00 100644
@@ -23,6 +23,7 @@
 #include <linux/rculist.h>
 #include <linux/error-injection.h>
 
+#include "trace_kprobe_selftest.h"
 #include "trace_probe.h"
 
 #define KPROBE_EVENT_SYSTEM "kprobes"
@@ -1573,17 +1574,6 @@ fs_initcall(init_kprobe_trace);
 
 
 #ifdef CONFIG_FTRACE_STARTUP_TEST
-/*
- * The "__used" keeps gcc from removing the function symbol
- * from the kallsyms table. 'noinline' makes sure that there
- * isn't an inlined version used by the test method below
- */
-static __used __init noinline int
-kprobe_trace_selftest_target(int a1, int a2, int a3, int a4, int a5, int a6)
-{
-	return a1 + a2 + a3 + a4 + a5 + a6;
-}
-
 static __init struct trace_event_file *
 find_trace_probe_file(struct trace_kprobe *tk, struct trace_array *tr)
 {
kernel/trace/trace_kprobe_selftest.c new file +10 -0
new file mode 100644
index 000000000000..16548ee4c8c6
@@ -0,0 +1,10 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Function used during the kprobe self test. This function is in a separate
+ * compile unit so it can be compile with CC_FLAGS_FTRACE to ensure that it
+ * can be probed by the selftests.
+ */
+int kprobe_trace_selftest_target(int a1, int a2, int a3, int a4, int a5, int a6)
+{
+	return a1 + a2 + a3 + a4 + a5 + a6;
+}
kernel/trace/trace_kprobe_selftest.h new file +7 -0
new file mode 100644
index 000000000000..4e10ec41c013
@@ -0,0 +1,7 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * Function used during the kprobe self test. This function is in a separate
+ * compile unit so it can be compile with CC_FLAGS_FTRACE to ensure that it
+ * can be probed by the selftests.
+ */
+int kprobe_trace_selftest_target(int a1, int a2, int a3, int a4, int a5, int a6);
author maintainer
#10 lore raw

PATCH v2 3/3 selftests/ftrace: Fix kprobe string testcase to not probe notrace function

In reply to Masami Hiramatsu

Fix kprobe string argument testcase to not probe notrace function. Instead, it probes tracefs function which must be available with ftrace.

---
 .../ftrace/test.d/kprobe/kprobe_args_string.tc     |   30 ++++++++------------
 1 file changed, 12 insertions(+), 18 deletions(-)
tools/testing/selftests/ftrace/test.d/kprobe/kprobe_args_string.tc +12 -18
index a0002563e9ee..1ad70cdaf442 100644
@@ -9,28 +9,22 @@ echo > kprobe_events
 
 case `uname -m` in
 x86_64)
-  ARG2=%si
-  OFFS=8
+  ARG1=%di
 ;;
 i[3456]86)
-  ARG2=%cx
-  OFFS=4
+  ARG1=%ax
 ;;
 aarch64)
-  ARG2=%x1
-  OFFS=8
+  ARG1=%x0
 ;;
 arm*)
-  ARG2=%r1
-  OFFS=4
+  ARG1=%r0
 ;;
 ppc64*)
-  ARG2=%r4
-  OFFS=8
+  ARG1=%r3
 ;;
 ppc*)
-  ARG2=%r4
-  OFFS=4
+  ARG1=%r3
 ;;
 *)
   echo "Please implement other architecture here"
@@ -38,17 +32,17 @@ ppc*)
 esac
 
 : "Test get argument (1)"
-echo "p:testprobe create_trace_kprobe arg1=+0(+0(${ARG2})):string" > kprobe_events
+echo "p:testprobe tracefs_create_dir arg1=+0(${ARG1}):string" > kprobe_events
 echo 1 > events/kprobes/testprobe/enable
-! echo test >> kprobe_events
-tail -n 1 trace | grep -qe "testprobe.* arg1=\"test\""
+echo "p:test _do_fork" >> kprobe_events
+grep -qe "testprobe.* arg1=\"test\"" trace
 
 echo 0 > events/kprobes/testprobe/enable
 : "Test get argument (2)"
-echo "p:testprobe create_trace_kprobe arg1=+0(+0(${ARG2})):string arg2=+0(+${OFFS}(${ARG2})):string" > kprobe_events
+echo "p:testprobe tracefs_create_dir arg1=+0(${ARG1}):string arg2=+0(${ARG1}):string" > kprobe_events
 echo 1 > events/kprobes/testprobe/enable
-! echo test1 test2 >> kprobe_events
-tail -n 1 trace | grep -qe "testprobe.* arg1=\"test1\" arg2=\"test2\""
+echo "p:test _do_fork" >> kprobe_events
+grep -qe "testprobe.* arg1=\"test\" arg2=\"test\"" trace
 
 echo 0 > events/enable
 echo > kprobe_events
author maintainer
#11 lore raw

Re: [PATCH v2 3/3] selftests/ftrace: Fix kprobe string testcase to not probe notrace function

Quoted 3 lines · On Thu, 26 Jul 2018 14:54:23 +0900 Masami Hiramatsu <[email protected]> wrote:

Fix kprobe string argument testcase to not probe notrace function. Instead, it probes tracefs function which must be available with ftrace.

Oops, this must be sent to Shuah too.

Shuah, I think you can freely pick this patch to kselftest branch, since this removes a dependency of notrace functions, not depends on any new feature :)

Thank you,

Quoted 70 lines
---
 .../ftrace/test.d/kprobe/kprobe_args_string.tc     |   30 ++++++++------------
 1 file changed, 12 insertions(+), 18 deletions(-)
tools/testing/selftests/ftrace/test.d/kprobe/kprobe_args_string.tc +12 -18
index a0002563e9ee..1ad70cdaf442 100644
@@ -9,28 +9,22 @@ echo > kprobe_events
 
 case `uname -m` in
 x86_64)
-  ARG2=%si
-  OFFS=8
+  ARG1=%di
 ;;
 i[3456]86)
-  ARG2=%cx
-  OFFS=4
+  ARG1=%ax
 ;;
 aarch64)
-  ARG2=%x1
-  OFFS=8
+  ARG1=%x0
 ;;
 arm*)
-  ARG2=%r1
-  OFFS=4
+  ARG1=%r0
 ;;
 ppc64*)
-  ARG2=%r4
-  OFFS=8
+  ARG1=%r3
 ;;
 ppc*)
-  ARG2=%r4
-  OFFS=4
+  ARG1=%r3
 ;;
 *)
   echo "Please implement other architecture here"
@@ -38,17 +32,17 @@ ppc*)
 esac
 
 : "Test get argument (1)"
-echo "p:testprobe create_trace_kprobe arg1=+0(+0(${ARG2})):string" > kprobe_events
+echo "p:testprobe tracefs_create_dir arg1=+0(${ARG1}):string" > kprobe_events
 echo 1 > events/kprobes/testprobe/enable
-! echo test >> kprobe_events
-tail -n 1 trace | grep -qe "testprobe.* arg1=\"test\""
+echo "p:test _do_fork" >> kprobe_events
+grep -qe "testprobe.* arg1=\"test\"" trace
 
 echo 0 > events/kprobes/testprobe/enable
 : "Test get argument (2)"
-echo "p:testprobe create_trace_kprobe arg1=+0(+0(${ARG2})):string arg2=+0(+${OFFS}(${ARG2})):string" > kprobe_events
+echo "p:testprobe tracefs_create_dir arg1=+0(${ARG1}):string arg2=+0(${ARG1}):string" > kprobe_events
 echo 1 > events/kprobes/testprobe/enable
-! echo test1 test2 >> kprobe_events
-tail -n 1 trace | grep -qe "testprobe.* arg1=\"test1\" arg2=\"test2\""
+echo "p:test _do_fork" >> kprobe_events
+grep -qe "testprobe.* arg1=\"test\" arg2=\"test\"" trace
 
 echo 0 > events/enable
 echo > kprobe_events
Signature · 1 line
Masami Hiramatsu <[email protected]>
maintainer Acked-by
#12 lore raw

Re: [PATCH v2 3/3] selftests/ftrace: Fix kprobe string testcase to not probe notrace function

Quoted 7 lines · On Thu, 26 Jul 2018 16:44:09 +0900 Masami Hiramatsu <[email protected]> wrote:
Quoted 3 lines · On Thu, 26 Jul 2018 14:54:23 +0900 Masami Hiramatsu <[email protected]> wrote:

Fix kprobe string argument testcase to not probe notrace function. Instead, it probes tracefs function which must be available with ftrace.

Quoted 6 lines

Oops, this must be sent to Shuah too.

Shuah, I think you can freely pick this patch to kselftest branch, since this removes a dependency of notrace functions, not depends on any new feature :)

Shuah,

Please take this patch in your tree. I'll take the other two.

-- Steve

maintainer
#13 lore raw

Re: [PATCH v2 3/3] selftests/ftrace: Fix kprobe string testcase to not probe notrace function

Quoted 17 lines · Steven Rostedt
Quoted 7 lines · On Thu, 26 Jul 2018 16:44:09 +0900 Masami Hiramatsu <[email protected]> wrote:
Quoted 3 lines · On Thu, 26 Jul 2018 14:54:23 +0900 Masami Hiramatsu <[email protected]> wrote:

Fix kprobe string argument testcase to not probe notrace function. Instead, it probes tracefs function which must be available with ftrace.

Quoted 6 lines

Oops, this must be sent to Shuah too.

Shuah, I think you can freely pick this patch to kselftest branch, since this removes a dependency of notrace functions, not depends on any new feature :)

Quoted 8 lines

Shuah,

Please take this patch in your tree. I'll take the other two.

-- Steve

Steve,

yes. I will pick this up.

thanks,
-- Shuah

author maintainer
#14 lore raw

Re: [PATCH v2 3/3] selftests/ftrace: Fix kprobe string testcase to not probe notrace function

Quoted 22 lines · On Thu, 26 Jul 2018 15:22:22 -0600 Shuah Khan <[email protected]> wrote:
Quoted 21 lines · Steven Rostedt
Quoted 7 lines · On Thu, 26 Jul 2018 16:44:09 +0900 Masami Hiramatsu <[email protected]> wrote:
Quoted 3 lines · On Thu, 26 Jul 2018 14:54:23 +0900 Masami Hiramatsu <[email protected]> wrote:

Fix kprobe string argument testcase to not probe notrace function. Instead, it probes tracefs function which must be available with ftrace.

Quoted 6 lines

Oops, this must be sent to Shuah too.

Shuah, I think you can freely pick this patch to kselftest branch, since this removes a dependency of notrace functions, not depends on any new feature :)

Shuah,

Please take this patch in your tree. I'll take the other two.

Quoted 8 lines
Quoted 4 lines

-- Steve

Steve,

yes. I will pick this up.

Thanks Steve and Shuah!

Quoted 5 lines

thanks,
-- Shuah

Signature · 1 line
Masami Hiramatsu <[email protected]>
maintainer
#15 lore raw

Re: [PATCH v2 3/3] selftests/ftrace: Fix kprobe string testcase to not probe notrace function

Quoted 25 lines · Masami Hiramatsu
Quoted 22 lines · On Thu, 26 Jul 2018 15:22:22 -0600 Shuah Khan <[email protected]> wrote:
Quoted 21 lines · Steven Rostedt
Quoted 7 lines · On Thu, 26 Jul 2018 16:44:09 +0900 Masami Hiramatsu <[email protected]> wrote:
Quoted 3 lines · On Thu, 26 Jul 2018 14:54:23 +0900 Masami Hiramatsu <[email protected]> wrote:

Fix kprobe string argument testcase to not probe notrace function. Instead, it probes tracefs function which must be available with ftrace.

Quoted 6 lines

Oops, this must be sent to Shuah too.

Shuah, I think you can freely pick this patch to kselftest branch, since this removes a dependency of notrace functions, not depends on any new feature :)

Shuah,

Please take this patch in your tree. I'll take the other two.

Quoted 9 lines
Quoted 8 lines
Quoted 4 lines

-- Steve

Steve,

yes. I will pick this up.

Masami,

The patch isn't in my Inbox. Could you please send it.

thanks,
-- Shuah

maintainer
#16 lore raw

Re: [PATCH v2 3/3] selftests/ftrace: Fix kprobe string testcase to not probe notrace function

Quoted 3 lines · On Fri, 27 Jul 2018 08:26:40 -0600 Shuah Khan <[email protected]> wrote:

Masami,

The patch isn't in my Inbox. Could you please send it.

You don't subscribe to LKML? ;-)

I just bounced it to you.

-- Steve

author maintainer
#17 lore raw

Re: [PATCH v2 3/3] selftests/ftrace: Fix kprobe string testcase to not probe notrace function

Quoted 5 lines · On Fri, 27 Jul 2018 10:31:45 -0400 Steven Rostedt <[email protected]> wrote:
Quoted 2 lines · On Fri, 27 Jul 2018 08:26:40 -0600 Shuah Khan <[email protected]> wrote:

Masami,

Quoted 7 lines
Quoted 1 line

The patch isn't in my Inbox. Could you please send it.

You don't subscribe to LKML? ;-)

I just bounced it to you.

-- Steve

Sorry Shuah and Steve,

I've fixed a problem in this patch. I've sent v3 patch to you.

Thank you,

Signature · 1 line
Masami Hiramatsu <[email protected]>
maintainer
#18 lore raw

Re: [PATCH v2 3/3] selftests/ftrace: Fix kprobe string testcase to not probe notrace function

In reply to Masami Hiramatsu
Quoted 3 lines · On Thu, 26 Jul 2018 14:54:23 +0900 Masami Hiramatsu <[email protected]> wrote:

Fix kprobe string argument testcase to not probe notrace function. Instead, it probes tracefs function which must be available with ftrace.

Hi Masami,

With these patches applied, this test fails:

./ftracetest test.d/kprobe/probepoint.tc

Gives me the error in dmseg:

trace_kprobe: Could not probe notrace function create_trace_kprobe

Is this expected? I don't see create_trace_kprobe as a notrace function either.

I even applied patch 3 (going through Shuah's tree) to me test and it still fails.

Config attached.

-- Steve

Quoted 69 lines
---
 .../ftrace/test.d/kprobe/kprobe_args_string.tc     |   30 ++++++++------------
 1 file changed, 12 insertions(+), 18 deletions(-)
tools/testing/selftests/ftrace/test.d/kprobe/kprobe_args_string.tc +12 -18
index a0002563e9ee..1ad70cdaf442 100644
@@ -9,28 +9,22 @@ echo > kprobe_events
 
 case `uname -m` in
 x86_64)
-  ARG2=%si
-  OFFS=8
+  ARG1=%di
 ;;
 i[3456]86)
-  ARG2=%cx
-  OFFS=4
+  ARG1=%ax
 ;;
 aarch64)
-  ARG2=%x1
-  OFFS=8
+  ARG1=%x0
 ;;
 arm*)
-  ARG2=%r1
-  OFFS=4
+  ARG1=%r0
 ;;
 ppc64*)
-  ARG2=%r4
-  OFFS=8
+  ARG1=%r3
 ;;
 ppc*)
-  ARG2=%r4
-  OFFS=4
+  ARG1=%r3
 ;;
 *)
   echo "Please implement other architecture here"
@@ -38,17 +32,17 @@ ppc*)
 esac
 
 : "Test get argument (1)"
-echo "p:testprobe create_trace_kprobe arg1=+0(+0(${ARG2})):string" > kprobe_events
+echo "p:testprobe tracefs_create_dir arg1=+0(${ARG1}):string" > kprobe_events
 echo 1 > events/kprobes/testprobe/enable
-! echo test >> kprobe_events
-tail -n 1 trace | grep -qe "testprobe.* arg1=\"test\""
+echo "p:test _do_fork" >> kprobe_events
+grep -qe "testprobe.* arg1=\"test\"" trace
 
 echo 0 > events/kprobes/testprobe/enable
 : "Test get argument (2)"
-echo "p:testprobe create_trace_kprobe arg1=+0(+0(${ARG2})):string arg2=+0(+${OFFS}(${ARG2})):string" > kprobe_events
+echo "p:testprobe tracefs_create_dir arg1=+0(${ARG1}):string arg2=+0(${ARG1}):string" > kprobe_events
 echo 1 > events/kprobes/testprobe/enable
-! echo test1 test2 >> kprobe_events
-tail -n 1 trace | grep -qe "testprobe.* arg1=\"test1\" arg2=\"test2\""
+echo "p:test _do_fork" >> kprobe_events
+grep -qe "testprobe.* arg1=\"test\" arg2=\"test\"" trace
 
 echo 0 > events/enable
 echo > kprobe_events
author maintainer
#19 lore raw

Re: [PATCH v2 3/3] selftests/ftrace: Fix kprobe string testcase to not probe notrace function

Quoted 15 lines · On Fri, 27 Jul 2018 17:43:07 -0400 Steven Rostedt <[email protected]> wrote:
Quoted 3 lines · On Thu, 26 Jul 2018 14:54:23 +0900 Masami Hiramatsu <[email protected]> wrote:

Fix kprobe string argument testcase to not probe notrace function. Instead, it probes tracefs function which must be available with ftrace.

Hi Masami,

With these patches applied, this test fails:

./ftracetest test.d/kprobe/probepoint.tc

Gives me the error in dmseg:

Quoted 7 lines

trace_kprobe: Could not probe notrace function create_trace_kprobe

Is this expected? I don't see create_trace_kprobe as a notrace function either.

I even applied patch 3 (going through Shuah's tree) to me test and it still fails.

Oops, why I missed this...
OK, I'll fix it.

Thanks,

Quoted 75 lines

Config attached.

-- Steve

Quoted 69 lines
---
 .../ftrace/test.d/kprobe/kprobe_args_string.tc     |   30 ++++++++------------
 1 file changed, 12 insertions(+), 18 deletions(-)
tools/testing/selftests/ftrace/test.d/kprobe/kprobe_args_string.tc +12 -18
index a0002563e9ee..1ad70cdaf442 100644
@@ -9,28 +9,22 @@ echo > kprobe_events
 
 case `uname -m` in
 x86_64)
-  ARG2=%si
-  OFFS=8
+  ARG1=%di
 ;;
 i[3456]86)
-  ARG2=%cx
-  OFFS=4
+  ARG1=%ax
 ;;
 aarch64)
-  ARG2=%x1
-  OFFS=8
+  ARG1=%x0
 ;;
 arm*)
-  ARG2=%r1
-  OFFS=4
+  ARG1=%r0
 ;;
 ppc64*)
-  ARG2=%r4
-  OFFS=8
+  ARG1=%r3
 ;;
 ppc*)
-  ARG2=%r4
-  OFFS=4
+  ARG1=%r3
 ;;
 *)
   echo "Please implement other architecture here"
@@ -38,17 +32,17 @@ ppc*)
 esac
 
 : "Test get argument (1)"
-echo "p:testprobe create_trace_kprobe arg1=+0(+0(${ARG2})):string" > kprobe_events
+echo "p:testprobe tracefs_create_dir arg1=+0(${ARG1}):string" > kprobe_events
 echo 1 > events/kprobes/testprobe/enable
-! echo test >> kprobe_events
-tail -n 1 trace | grep -qe "testprobe.* arg1=\"test\""
+echo "p:test _do_fork" >> kprobe_events
+grep -qe "testprobe.* arg1=\"test\"" trace
 
 echo 0 > events/kprobes/testprobe/enable
 : "Test get argument (2)"
-echo "p:testprobe create_trace_kprobe arg1=+0(+0(${ARG2})):string arg2=+0(+${OFFS}(${ARG2})):string" > kprobe_events
+echo "p:testprobe tracefs_create_dir arg1=+0(${ARG1}):string arg2=+0(${ARG1}):string" > kprobe_events
 echo 1 > events/kprobes/testprobe/enable
-! echo test1 test2 >> kprobe_events
-tail -n 1 trace | grep -qe "testprobe.* arg1=\"test1\" arg2=\"test2\""
+echo "p:test _do_fork" >> kprobe_events
+grep -qe "testprobe.* arg1=\"test\" arg2=\"test\"" trace
 
 echo 0 > events/enable
 echo > kprobe_events
Signature · 1 line
Masami Hiramatsu <[email protected]>