2020-09-10 08:57:16

by Masami Hiramatsu

[permalink] [raw]
Subject: [PATCH v3 0/8] tracing/boot: Add new options for tracing specific period

Hi,

Here is the 3rd version of the series to improve the boot-time tracing to
support kretprobe and tracing_on option. Previous version is here:

https://lkml.kernel.org/r/159894698993.1478826.2813843560314595660.stgit@devnote2

This version adds uprobe %return suffix support ([5/8]) and the testcases
([8/8]), and update kprobe %suffix support([4/8]) and the uprobe event
document([6/8]).


The combination of tracing_on and kretprobe allows us to trace events
while a specific function call period. For example, the below bootconfig
will make a function callgraph in the pci_proc_init() function at boot
time.

ftrace {
tracing_on = 0 # off at start
tracer = function_graph
event.kprobes {
start_event {
probes = "pci_proc_init"
actions = "traceon"
}
end_event {
probes = "pci_proc_init%return"
actions = "traceoff"
}
}
}

Here is the example output;

# tracer: function_graph
#
# CPU DURATION FUNCTION CALLS
# | | | | | | |
0) | pci_proc_init() {
0) | proc_mkdir() {
0) | proc_mkdir_data() {
0) | __proc_create() {
0) | _raw_read_lock() {
0) 0.179 us | preempt_count_add();
0) 0.203 us | do_raw_read_lock();
0) 1.210 us | }
0) | __xlate_proc_name() {
0) 0.449 us | pde_subdir_find();
0) 0.913 us | }
0) | _raw_read_unlock() {
0) 0.169 us | do_raw_read_unlock();
0) 0.175 us | preempt_count_sub();
0) 0.841 us | }
0) | kmem_cache_alloc() {
0) | fs_reclaim_acquire() {
0) 0.154 us | __need_fs_reclaim();
0) 0.240 us | fs_reclaim_acquire.part.0();
0) 0.889 us | }
0) | fs_reclaim_release() {
0) 0.174 us | __need_fs_reclaim();
0) 0.516 us | }
0) 0.157 us | should_failslab();
0) | rcu_read_lock_sched_held() {
0) | rcu_read_lock_held_common() {
0) 0.156 us | rcu_is_watching();
0) 0.158 us | rcu_lockdep_current_cpu_online();
0) 0.735 us | }
0) 1.054 us | }
0) 3.407 us | }
0) 0.168 us | __raw_spin_lock_init();
0) 7.575 us | }
0) | proc_register() {
0) | _raw_spin_lock_irqsave() {
0) 0.187 us | preempt_count_add();
...


Thank you,

---

Masami Hiramatsu (8):
kprobes: tracing/kprobes: Fix to kill kprobes on initmem after boot
tracing/boot: Add per-instance tracing_on option support
Documentation: tracing: Add tracing_on option to boot-time tracer
tracing/kprobes: Support perf-style return probe
tracing/uprobes: Support perf-style return probe
Documentation: tracing: Add %return suffix description
Documentation: tracing: boot: Add an example of tracing function-calls
selftests/ftrace: Add %return suffix tests


Documentation/trace/boottime-trace.rst | 24 ++++++++++++++++++++
Documentation/trace/kprobetrace.rst | 2 ++
Documentation/trace/uprobetracer.rst | 2 ++
include/linux/kprobes.h | 5 ++++
init/main.c | 2 ++
kernel/kprobes.c | 22 ++++++++++++++++++
kernel/trace/trace.c | 4 ++-
kernel/trace/trace_boot.c | 10 ++++++++
kernel/trace/trace_kprobe.c | 18 ++++++++++++++-
kernel/trace/trace_probe.h | 1 +
kernel/trace/trace_uprobe.c | 15 ++++++++++++-
.../ftrace/test.d/kprobe/kprobe_syntax_errors.tc | 6 +++++
.../test.d/kprobe/kretprobe_return_suffix.tc | 21 ++++++++++++++++++
.../ftrace/test.d/kprobe/uprobe_syntax_errors.tc | 6 +++++
14 files changed, 134 insertions(+), 4 deletions(-)
create mode 100644 tools/testing/selftests/ftrace/test.d/kprobe/kretprobe_return_suffix.tc

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


2020-09-10 08:58:10

by Masami Hiramatsu

[permalink] [raw]
Subject: [PATCH v3 1/8] kprobes: tracing/kprobes: Fix to kill kprobes on initmem after boot

Since kprobe_event= cmdline option allows user to put kprobes on the
functions in initmem, kprobe has to make such probes gone after boot.
Currently the probes on the init functions in modules will be handled
by module callback, but the kernel init text isn't handled.
Without this, kprobes may access non-exist text area to disable or
remove it.

Fixes: 970988e19eb0 ("tracing/kprobe: Add kprobe_event= boot parameter")
Cc: [email protected]
Signed-off-by: Masami Hiramatsu <[email protected]>
---
Changes in v2:
- Fix kprobe_free_init_mem() not depending on CONFIG_DEBUG_FS.
---
include/linux/kprobes.h | 5 +++++
init/main.c | 2 ++
kernel/kprobes.c | 22 ++++++++++++++++++++++
3 files changed, 29 insertions(+)

diff --git a/include/linux/kprobes.h b/include/linux/kprobes.h
index 9be1bff4f586..8aab327b5539 100644
--- a/include/linux/kprobes.h
+++ b/include/linux/kprobes.h
@@ -373,6 +373,8 @@ void unregister_kretprobes(struct kretprobe **rps, int num);
void kprobe_flush_task(struct task_struct *tk);
void recycle_rp_inst(struct kretprobe_instance *ri, struct hlist_head *head);

+void kprobe_free_init_mem(void);
+
int disable_kprobe(struct kprobe *kp);
int enable_kprobe(struct kprobe *kp);

@@ -435,6 +437,9 @@ static inline void unregister_kretprobes(struct kretprobe **rps, int num)
static inline void kprobe_flush_task(struct task_struct *tk)
{
}
+static inline void kprobe_free_init_mem(void)
+{
+}
static inline int disable_kprobe(struct kprobe *kp)
{
return -ENOSYS;
diff --git a/init/main.c b/init/main.c
index ae78fb68d231..038128b2a755 100644
--- a/init/main.c
+++ b/init/main.c
@@ -33,6 +33,7 @@
#include <linux/nmi.h>
#include <linux/percpu.h>
#include <linux/kmod.h>
+#include <linux/kprobes.h>
#include <linux/vmalloc.h>
#include <linux/kernel_stat.h>
#include <linux/start_kernel.h>
@@ -1402,6 +1403,7 @@ static int __ref kernel_init(void *unused)
kernel_init_freeable();
/* need to finish all async __init code before freeing the memory */
async_synchronize_full();
+ kprobe_free_init_mem();
ftrace_free_init_mem();
free_initmem();
mark_readonly();
diff --git a/kernel/kprobes.c b/kernel/kprobes.c
index 287b263c9cb9..2880cdf37c47 100644
--- a/kernel/kprobes.c
+++ b/kernel/kprobes.c
@@ -2452,6 +2452,28 @@ static struct notifier_block kprobe_module_nb = {
extern unsigned long __start_kprobe_blacklist[];
extern unsigned long __stop_kprobe_blacklist[];

+void kprobe_free_init_mem(void)
+{
+ void *start = (void *)(&__init_begin);
+ void *end = (void *)(&__init_end);
+ struct hlist_head *head;
+ struct kprobe *p;
+ int i;
+
+ mutex_lock(&kprobe_mutex);
+
+ /* Kill all kprobes on initmem */
+ for (i = 0; i < KPROBE_TABLE_SIZE; i++) {
+ head = &kprobe_table[i];
+ hlist_for_each_entry(p, head, hlist) {
+ if (start <= (void *)p->addr && (void *)p->addr < end)
+ kill_kprobe(p);
+ }
+ }
+
+ mutex_unlock(&kprobe_mutex);
+}
+
static int __init init_kprobes(void)
{
int i, err = 0;

2020-09-10 08:59:16

by Masami Hiramatsu

[permalink] [raw]
Subject: [PATCH v3 4/8] tracing/kprobes: Support perf-style return probe

Support perf-style return probe ("SYMBOL%return") for kprobe events.
This will allow boot-time tracing user to define a return probe event.

Signed-off-by: Masami Hiramatsu <[email protected]>
---
Changes in v3:
- Update README so that user can notice the kernel supports this feature.
- Add a new error message.
---
kernel/trace/trace.c | 2 +-
kernel/trace/trace_kprobe.c | 18 +++++++++++++++++-
kernel/trace/trace_probe.h | 1 +
3 files changed, 19 insertions(+), 2 deletions(-)

diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
index f40d850ebabc..2c8c8f7ddef7 100644
--- a/kernel/trace/trace.c
+++ b/kernel/trace/trace.c
@@ -5122,7 +5122,7 @@ static const char readme_msg[] =
"\t -:[<group>/]<event>\n"
#ifdef CONFIG_KPROBE_EVENTS
"\t place: [<module>:]<symbol>[+<offset>]|<memaddr>\n"
- "place (kretprobe): [<module>:]<symbol>[+<offset>]|<memaddr>\n"
+ "place (kretprobe): [<module>:]<symbol>[+<offset>]%return|<memaddr>\n"
#endif
#ifdef CONFIG_UPROBE_EVENTS
" place (uprobe): <path>:<offset>[(ref_ctr_offset)]\n"
diff --git a/kernel/trace/trace_kprobe.c b/kernel/trace/trace_kprobe.c
index aefb6065b508..e33690a12255 100644
--- a/kernel/trace/trace_kprobe.c
+++ b/kernel/trace/trace_kprobe.c
@@ -717,6 +717,9 @@ static int trace_kprobe_create(int argc, const char *argv[])
* p[:[GRP/]EVENT] [MOD:]KSYM[+OFFS]|KADDR [FETCHARGS]
* - Add kretprobe:
* r[MAXACTIVE][:[GRP/]EVENT] [MOD:]KSYM[+0] [FETCHARGS]
+ * Or
+ * p:[GRP/]EVENT] [MOD:]KSYM[+0]%return [FETCHARGS]
+ *
* Fetch args:
* $retval : fetch return value
* $stack : fetch stack address
@@ -746,7 +749,6 @@ static int trace_kprobe_create(int argc, const char *argv[])
switch (argv[0][0]) {
case 'r':
is_return = true;
- flags |= TPARG_FL_RETURN;
break;
case 'p':
break;
@@ -804,12 +806,26 @@ static int trace_kprobe_create(int argc, const char *argv[])
symbol = kstrdup(argv[1], GFP_KERNEL);
if (!symbol)
return -ENOMEM;
+
+ tmp = strchr(symbol, '%');
+ if (tmp) {
+ if (!strcmp(tmp, "%return")) {
+ *tmp = '\0';
+ is_return = true;
+ } else {
+ trace_probe_log_err(tmp - symbol, BAD_ADDR_SUFFIX);
+ goto parse_error;
+ }
+ }
+
/* TODO: support .init module functions */
ret = traceprobe_split_symbol_offset(symbol, &offset);
if (ret || offset < 0 || offset > UINT_MAX) {
trace_probe_log_err(0, BAD_PROBE_ADDR);
goto parse_error;
}
+ if (is_return)
+ flags |= TPARG_FL_RETURN;
if (kprobe_on_func_entry(NULL, symbol, offset))
flags |= TPARG_FL_FENTRY;
if (offset && is_return && !(flags & TPARG_FL_FENTRY)) {
diff --git a/kernel/trace/trace_probe.h b/kernel/trace/trace_probe.h
index a22b62813f8c..04d00987da69 100644
--- a/kernel/trace/trace_probe.h
+++ b/kernel/trace/trace_probe.h
@@ -404,6 +404,7 @@ extern int traceprobe_define_arg_fields(struct trace_event_call *event_call,
C(MAXACT_TOO_BIG, "Maxactive is too big"), \
C(BAD_PROBE_ADDR, "Invalid probed address or symbol"), \
C(BAD_RETPROBE, "Retprobe address must be an function entry"), \
+ C(BAD_ADDR_SUFFIX, "Invalid probed address suffix"), \
C(NO_GROUP_NAME, "Group name is not specified"), \
C(GROUP_TOO_LONG, "Group name is too long"), \
C(BAD_GROUP_NAME, "Group name must follow the same rules as C identifiers"), \

2020-09-10 08:59:22

by Masami Hiramatsu

[permalink] [raw]
Subject: [PATCH v3 6/8] Documentation: tracing: Add %return suffix description

Add a description of the %return suffix option for kprobe event and
uprobe event.

Signed-off-by: Masami Hiramatsu <[email protected]>
---
Changes in v3
- Add description for uprobe events too.
Changes in v2
- Use a tab for indentation as other lines do.
---
Documentation/trace/kprobetrace.rst | 2 ++
Documentation/trace/uprobetracer.rst | 2 ++
2 files changed, 4 insertions(+)

diff --git a/Documentation/trace/kprobetrace.rst b/Documentation/trace/kprobetrace.rst
index c1709165c553..a18eb97a263c 100644
--- a/Documentation/trace/kprobetrace.rst
+++ b/Documentation/trace/kprobetrace.rst
@@ -30,6 +30,7 @@ Synopsis of kprobe_events

p[:[GRP/]EVENT] [MOD:]SYM[+offs]|MEMADDR [FETCHARGS] : Set a probe
r[MAXACTIVE][:[GRP/]EVENT] [MOD:]SYM[+0] [FETCHARGS] : Set a return probe
+ p:[GRP/]EVENT] [MOD:]SYM[+0]%return [FETCHARGS] : Set a return probe
-:[GRP/]EVENT : Clear a probe

GRP : Group name. If omitted, use "kprobes" for it.
@@ -37,6 +38,7 @@ Synopsis of kprobe_events
based on SYM+offs or MEMADDR.
MOD : Module name which has given SYM.
SYM[+offs] : Symbol+offset where the probe is inserted.
+ SYM%return : Return address of the symbol
MEMADDR : Address where the probe is inserted.
MAXACTIVE : Maximum number of instances of the specified function that
can be probed simultaneously, or 0 for the default value
diff --git a/Documentation/trace/uprobetracer.rst b/Documentation/trace/uprobetracer.rst
index 98cde99939d7..a8e5938f609e 100644
--- a/Documentation/trace/uprobetracer.rst
+++ b/Documentation/trace/uprobetracer.rst
@@ -28,6 +28,7 @@ Synopsis of uprobe_tracer

p[:[GRP/]EVENT] PATH:OFFSET [FETCHARGS] : Set a uprobe
r[:[GRP/]EVENT] PATH:OFFSET [FETCHARGS] : Set a return uprobe (uretprobe)
+ p[:[GRP/]EVENT] PATH:OFFSET%return [FETCHARGS] : Set a return uprobe (uretprobe)
-:[GRP/]EVENT : Clear uprobe or uretprobe event

GRP : Group name. If omitted, "uprobes" is the default value.
@@ -35,6 +36,7 @@ Synopsis of uprobe_tracer
on PATH+OFFSET.
PATH : Path to an executable or a library.
OFFSET : Offset where the probe is inserted.
+ OFFSET%return : Offset where the return probe is inserted.

FETCHARGS : Arguments. Each probe can have up to 128 args.
%REG : Fetch register REG

2020-09-10 08:59:45

by Masami Hiramatsu

[permalink] [raw]
Subject: [PATCH v3 5/8] tracing/uprobes: Support perf-style return probe

Support perf-style return probe ("SYMBOL%return") for uprobe events
as same as kprobe events does.

Signed-off-by: Masami Hiramatsu <[email protected]>
---
kernel/trace/trace.c | 2 +-
kernel/trace/trace_uprobe.c | 15 ++++++++++++++-
2 files changed, 15 insertions(+), 2 deletions(-)

diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
index 2c8c8f7ddef7..faf55f5dd99d 100644
--- a/kernel/trace/trace.c
+++ b/kernel/trace/trace.c
@@ -5125,7 +5125,7 @@ static const char readme_msg[] =
"place (kretprobe): [<module>:]<symbol>[+<offset>]%return|<memaddr>\n"
#endif
#ifdef CONFIG_UPROBE_EVENTS
- " place (uprobe): <path>:<offset>[(ref_ctr_offset)]\n"
+ " place (uprobe): <path>:<offset>[%return][(ref_ctr_offset)]\n"
#endif
"\t args: <name>=fetcharg[:type]\n"
"\t fetcharg: %<register>, @<address>, @<symbol>[+|-<offset>],\n"
diff --git a/kernel/trace/trace_uprobe.c b/kernel/trace/trace_uprobe.c
index f4286c9bdeb4..fb5ec4e55484 100644
--- a/kernel/trace/trace_uprobe.c
+++ b/kernel/trace/trace_uprobe.c
@@ -528,7 +528,7 @@ static int register_trace_uprobe(struct trace_uprobe *tu)

/*
* Argument syntax:
- * - Add uprobe: p|r[:[GRP/]EVENT] PATH:OFFSET [FETCHARGS]
+ * - Add uprobe: p|r[:[GRP/]EVENT] PATH:OFFSET[%return][(REF)] [FETCHARGS]
*/
static int trace_uprobe_create(int argc, const char **argv)
{
@@ -617,6 +617,19 @@ static int trace_uprobe_create(int argc, const char **argv)
}
}

+ /* Check if there is %return suffix */
+ tmp = strchr(arg, '%');
+ if (tmp) {
+ if (!strcmp(tmp, "%return")) {
+ *tmp = '\0';
+ is_return = true;
+ } else {
+ trace_probe_log_err(tmp - filename, BAD_ADDR_SUFFIX);
+ ret = -EINVAL;
+ goto fail_address_parse;
+ }
+ }
+
/* Parse uprobe offset. */
ret = kstrtoul(arg, 0, &offset);
if (ret) {

2020-09-10 08:59:49

by Masami Hiramatsu

[permalink] [raw]
Subject: [PATCH v3 8/8] selftests/ftrace: Add %return suffix tests

Add kprobe %return suffix testcase and syntax error tests
for %return suffix.

Signed-off-by: Masami Hiramatsu <[email protected]>
---
.../ftrace/test.d/kprobe/kprobe_syntax_errors.tc | 6 ++++++
.../test.d/kprobe/kretprobe_return_suffix.tc | 21 ++++++++++++++++++++
.../ftrace/test.d/kprobe/uprobe_syntax_errors.tc | 6 ++++++
3 files changed, 33 insertions(+)
create mode 100644 tools/testing/selftests/ftrace/test.d/kprobe/kretprobe_return_suffix.tc

diff --git a/tools/testing/selftests/ftrace/test.d/kprobe/kprobe_syntax_errors.tc b/tools/testing/selftests/ftrace/test.d/kprobe/kprobe_syntax_errors.tc
index b4d834675e59..56b3f36c722b 100644
--- a/tools/testing/selftests/ftrace/test.d/kprobe/kprobe_syntax_errors.tc
+++ b/tools/testing/selftests/ftrace/test.d/kprobe/kprobe_syntax_errors.tc
@@ -97,4 +97,10 @@ check_error 'p:kprobes/testevent _do_fork ^abcd=\"foo"' # DIFF_ARG_TYPE
check_error '^p:kprobes/testevent _do_fork abcd=\1' # SAME_PROBE
fi

+# %return suffix errors
+if grep -q "place (kretprobe): .*%return.*" README; then
+check_error 'p vfs_read^%hoge' # BAD_ADDR_SUFFIX
+check_error 'p ^vfs_read+10%return' # BAD_RETPROBE
+fi
+
exit 0
diff --git a/tools/testing/selftests/ftrace/test.d/kprobe/kretprobe_return_suffix.tc b/tools/testing/selftests/ftrace/test.d/kprobe/kretprobe_return_suffix.tc
new file mode 100644
index 000000000000..f07bd15cc033
--- /dev/null
+++ b/tools/testing/selftests/ftrace/test.d/kprobe/kretprobe_return_suffix.tc
@@ -0,0 +1,21 @@
+#!/bin/sh
+# SPDX-License-Identifier: GPL-2.0
+# description: Kretprobe %%return suffix test
+# requires: kprobe_events '<symbol>[+<offset>]%return':README
+
+# Test for kretprobe by "r"
+echo 'r:myprobeaccept vfs_read' > kprobe_events
+RESULT1=`cat kprobe_events`
+
+# Test for kretprobe by "%return"
+echo 'p:myprobeaccept vfs_read%return' > kprobe_events
+RESULT2=`cat kprobe_events`
+
+if [ "$RESULT1" != "$RESULT2" ]; then
+ echo "Error: %return suffix didn't make a return probe."
+ echo "r-command: $RESULT1"
+ echo "%return: $RESULT2"
+ exit_fail
+fi
+
+echo > kprobe_events
diff --git a/tools/testing/selftests/ftrace/test.d/kprobe/uprobe_syntax_errors.tc b/tools/testing/selftests/ftrace/test.d/kprobe/uprobe_syntax_errors.tc
index 7b5b60c3c5a2..f5e3f9e4a01f 100644
--- a/tools/testing/selftests/ftrace/test.d/kprobe/uprobe_syntax_errors.tc
+++ b/tools/testing/selftests/ftrace/test.d/kprobe/uprobe_syntax_errors.tc
@@ -17,4 +17,10 @@ check_error 'p /bin/sh:10(10)^a' # BAD_REFCNT_SUFFIX
check_error 'p /bin/sh:10 ^@+ab' # BAD_FILE_OFFS
check_error 'p /bin/sh:10 ^@symbol' # SYM_ON_UPROBE

+# %return suffix error
+if grep -q "place (uprobe): .*%return.*" README; then
+check_error 'p /bin/sh:10^%hoge' # BAD_ADDR_SUFFIX
+check_error 'p /bin/sh:10(10)^%return' # BAD_REFCNT_SUFFIX
+fi
+
exit 0

2020-09-10 09:00:11

by Masami Hiramatsu

[permalink] [raw]
Subject: [PATCH v3 7/8] Documentation: tracing: boot: Add an example of tracing function-calls

Add an example of tracing function calls on a specific function.

Signed-off-by: Masami Hiramatsu <[email protected]>
---
Documentation/trace/boottime-trace.rst | 20 ++++++++++++++++++++
1 file changed, 20 insertions(+)

diff --git a/Documentation/trace/boottime-trace.rst b/Documentation/trace/boottime-trace.rst
index 1341b449acaa..c216f5695ae2 100644
--- a/Documentation/trace/boottime-trace.rst
+++ b/Documentation/trace/boottime-trace.rst
@@ -168,6 +168,26 @@ is for tracing functions starting with "user\_", and others tracing
The instance node also accepts event nodes so that each instance
can customize its event tracing.

+With the trigger action and kprobes, you can trace function-graph while
+a function is called. For example, this will trace all function calls in
+the pci_proc_init()::
+
+ ftrace {
+ tracing_on = 0
+ tracer = function_graph
+ event.kprobes {
+ start_event {
+ probes = "pci_proc_init"
+ actions = "traceon"
+ }
+ end_event {
+ probes = "pci_proc_init%return"
+ actions = "traceoff"
+ }
+ }
+ }
+
+
This boot-time tracing also supports ftrace kernel parameters via boot
config.
For example, following kernel parameters::

2020-09-10 09:00:11

by Masami Hiramatsu

[permalink] [raw]
Subject: [PATCH v3 3/8] Documentation: tracing: Add tracing_on option to boot-time tracer

Add tracing_on option description to the boot-time tracer.

Signed-off-by: Masami Hiramatsu <[email protected]>
---
Documentation/trace/boottime-trace.rst | 4 ++++
1 file changed, 4 insertions(+)

diff --git a/Documentation/trace/boottime-trace.rst b/Documentation/trace/boottime-trace.rst
index dcb390075ca1..1341b449acaa 100644
--- a/Documentation/trace/boottime-trace.rst
+++ b/Documentation/trace/boottime-trace.rst
@@ -61,6 +61,10 @@ These options can be used for each instance including global ftrace node.
ftrace.[instance.INSTANCE.]options = OPT1[, OPT2[...]]
Enable given ftrace options.

+ftrace.[instance.INSTANCE.]tracing_on = 0|1
+ Enable/Disable tracing on this instance when boot.
+ (you can enable it by the "traceon" event trigger action)
+
ftrace.[instance.INSTANCE.]trace_clock = CLOCK
Set given CLOCK to ftrace's trace_clock.


2020-09-10 09:01:20

by Masami Hiramatsu

[permalink] [raw]
Subject: [PATCH v3 2/8] tracing/boot: Add per-instance tracing_on option support

Add per-instance tracing_on option, which will be useful with
traceon/traceoff event trigger actions. For example, if we
disable tracing_on by default and set traceon and traceoff on
a pair of events, we can trace functions between the pair of
events.

Signed-off-by: Masami Hiramatsu <[email protected]>
---
kernel/trace/trace_boot.c | 10 ++++++++++
1 file changed, 10 insertions(+)

diff --git a/kernel/trace/trace_boot.c b/kernel/trace/trace_boot.c
index fa0fc08c6ef8..d52d441a17e8 100644
--- a/kernel/trace/trace_boot.c
+++ b/kernel/trace/trace_boot.c
@@ -40,6 +40,16 @@ trace_boot_set_instance_options(struct trace_array *tr, struct xbc_node *node)
pr_err("Failed to set option: %s\n", buf);
}

+ p = xbc_node_find_value(node, "tracing_on", NULL);
+ if (p && *p != '\0') {
+ if (kstrtoul(p, 10, &v))
+ pr_err("Failed to set tracing on: %s\n", p);
+ if (v)
+ tracer_tracing_on(tr);
+ else
+ tracer_tracing_off(tr);
+ }
+
p = xbc_node_find_value(node, "trace_clock", NULL);
if (p && *p != '\0') {
if (tracing_set_clock(tr, p) < 0)

2020-09-10 13:34:48

by Bird, Tim

[permalink] [raw]
Subject: RE: [PATCH v3 3/8] Documentation: tracing: Add tracing_on option to boot-time tracer



> -----Original Message-----
> From: Masami Hiramatsu
>
> Add tracing_on option description to the boot-time tracer.
>
> Signed-off-by: Masami Hiramatsu <[email protected]>
> ---
> Documentation/trace/boottime-trace.rst | 4 ++++
> 1 file changed, 4 insertions(+)
>
> diff --git a/Documentation/trace/boottime-trace.rst b/Documentation/trace/boottime-trace.rst
> index dcb390075ca1..1341b449acaa 100644
> --- a/Documentation/trace/boottime-trace.rst
> +++ b/Documentation/trace/boottime-trace.rst
> @@ -61,6 +61,10 @@ These options can be used for each instance including global ftrace node.
> ftrace.[instance.INSTANCE.]options = OPT1[, OPT2[...]]
> Enable given ftrace options.
>
> +ftrace.[instance.INSTANCE.]tracing_on = 0|1
> + Enable/Disable tracing on this instance when boot.

when boot. -> when booting.
(or when boot. -> on boot.)
-- Tim

> + (you can enable it by the "traceon" event trigger action)
> +
> ftrace.[instance.INSTANCE.]trace_clock = CLOCK
> Set given CLOCK to ftrace's trace_clock.
>

2020-09-10 22:44:23

by Masami Hiramatsu

[permalink] [raw]
Subject: Re: [PATCH v3 3/8] Documentation: tracing: Add tracing_on option to boot-time tracer

Hi Tim,

On Thu, 10 Sep 2020 13:26:05 +0000
"Bird, Tim" <[email protected]> wrote:

>
>
> > -----Original Message-----
> > From: Masami Hiramatsu
> >
> > Add tracing_on option description to the boot-time tracer.
> >
> > Signed-off-by: Masami Hiramatsu <[email protected]>
> > ---
> > Documentation/trace/boottime-trace.rst | 4 ++++
> > 1 file changed, 4 insertions(+)
> >
> > diff --git a/Documentation/trace/boottime-trace.rst b/Documentation/trace/boottime-trace.rst
> > index dcb390075ca1..1341b449acaa 100644
> > --- a/Documentation/trace/boottime-trace.rst
> > +++ b/Documentation/trace/boottime-trace.rst
> > @@ -61,6 +61,10 @@ These options can be used for each instance including global ftrace node.
> > ftrace.[instance.INSTANCE.]options = OPT1[, OPT2[...]]
> > Enable given ftrace options.
> >
> > +ftrace.[instance.INSTANCE.]tracing_on = 0|1
> > + Enable/Disable tracing on this instance when boot.
>
> when boot. -> when booting.
> (or when boot. -> on boot.)

Thanks! "when booting" or maybe "when starting boot-time tracing"
will be more accurate, since if user sets the "ftrace=function"
in the kernel command line, it will start tracing function calls
until the boot-time tracing stops it by this option.

Thank you,


> -- Tim
>
> > + (you can enable it by the "traceon" event trigger action)
> > +
> > ftrace.[instance.INSTANCE.]trace_clock = CLOCK
> > Set given CLOCK to ftrace's trace_clock.
> >
>


--
Masami Hiramatsu <[email protected]>

2020-09-10 23:35:34

by Steven Rostedt

[permalink] [raw]
Subject: Re: [PATCH v3 0/8] tracing/boot: Add new options for tracing specific period

On Thu, 10 Sep 2020 17:54:54 +0900
Masami Hiramatsu <[email protected]> wrote:

> Hi,
>
> Here is the 3rd version of the series to improve the boot-time tracing to
> support kretprobe and tracing_on option. Previous version is here:
>
> https://lkml.kernel.org/r/159894698993.1478826.2813843560314595660.stgit@devnote2
>
> This version adds uprobe %return suffix support ([5/8]) and the testcases
> ([8/8]), and update kprobe %suffix support([4/8]) and the uprobe event
> document([6/8]).
>
>
> The combination of tracing_on and kretprobe allows us to trace events
> while a specific function call period. For example, the below bootconfig
> will make a function callgraph in the pci_proc_init() function at boot
> time.
>
> ftrace {
> tracing_on = 0 # off at start
> tracer = function_graph
> event.kprobes {
> start_event {
> probes = "pci_proc_init"
> actions = "traceon"
> }
> end_event {
> probes = "pci_proc_init%return"
> actions = "traceoff"
> }
> }
> }
>
> Here is the example output;
>

[..]

Hi Masami,

This looks really great! I just got back from a 10 day holiday, and I'm
drowning in "catch-up". I plan on looking at all this relatively soon
(in a week or two?). I just don't want you to think I'm ignoring this.

-- Steve

2020-09-11 00:48:53

by Masami Hiramatsu

[permalink] [raw]
Subject: [PATCH v3.1 3/8] Documentation: tracing: Add tracing_on option to boot-time tracer

Add tracing_on option description to the boot-time tracer.

Signed-off-by: Masami Hiramatsu <[email protected]>
---
Changes in v3.1:
- Fix "on boot" to "on starting boot-time tracing".
---
Documentation/trace/boottime-trace.rst | 4 ++++
1 file changed, 4 insertions(+)

diff --git a/Documentation/trace/boottime-trace.rst b/Documentation/trace/boottime-trace.rst
index dcb390075ca1..9bc8aceb8c0a 100644
--- a/Documentation/trace/boottime-trace.rst
+++ b/Documentation/trace/boottime-trace.rst
@@ -61,6 +61,10 @@ These options can be used for each instance including global ftrace node.
ftrace.[instance.INSTANCE.]options = OPT1[, OPT2[...]]
Enable given ftrace options.

+ftrace.[instance.INSTANCE.]tracing_on = 0|1
+ Enable/Disable tracing on this instance when starting boot-time tracing.
+ (you can enable it by the "traceon" event trigger action)
+
ftrace.[instance.INSTANCE.]trace_clock = CLOCK
Set given CLOCK to ftrace's trace_clock.


2020-09-11 01:28:58

by Masami Hiramatsu

[permalink] [raw]
Subject: Re: [PATCH v3 0/8] tracing/boot: Add new options for tracing specific period

On Thu, 10 Sep 2020 19:34:33 -0400
Steven Rostedt <[email protected]> wrote:

> On Thu, 10 Sep 2020 17:54:54 +0900
> Masami Hiramatsu <[email protected]> wrote:
>
> > Hi,
> >
> > Here is the 3rd version of the series to improve the boot-time tracing to
> > support kretprobe and tracing_on option. Previous version is here:
> >
> > https://lkml.kernel.org/r/159894698993.1478826.2813843560314595660.stgit@devnote2
> >
> > This version adds uprobe %return suffix support ([5/8]) and the testcases
> > ([8/8]), and update kprobe %suffix support([4/8]) and the uprobe event
> > document([6/8]).
> >
> >
> > The combination of tracing_on and kretprobe allows us to trace events
> > while a specific function call period. For example, the below bootconfig
> > will make a function callgraph in the pci_proc_init() function at boot
> > time.
> >
> > ftrace {
> > tracing_on = 0 # off at start
> > tracer = function_graph
> > event.kprobes {
> > start_event {
> > probes = "pci_proc_init"
> > actions = "traceon"
> > }
> > end_event {
> > probes = "pci_proc_init%return"
> > actions = "traceoff"
> > }
> > }
> > }
> >
> > Here is the example output;
> >
>
> [..]
>
> Hi Masami,
>
> This looks really great! I just got back from a 10 day holiday, and I'm
> drowning in "catch-up". I plan on looking at all this relatively soon
> (in a week or two?). I just don't want you to think I'm ignoring this.

Hi Steve,

Thanks, I hope you enjoyed the holiday!
BTW, this series includes some document update and testcases.
Since we can not decouple these updates, I think it is better you to
pull the series.

Regards,

--
Masami Hiramatsu <[email protected]>

2020-09-11 01:37:32

by Shuah Khan

[permalink] [raw]
Subject: Re: [PATCH v3 0/8] tracing/boot: Add new options for tracing specific period

On 9/10/20 7:27 PM, Masami Hiramatsu wrote:
> On Thu, 10 Sep 2020 19:34:33 -0400
> Steven Rostedt <[email protected]> wrote:
>
>> On Thu, 10 Sep 2020 17:54:54 +0900
>> Masami Hiramatsu <[email protected]> wrote:
>>
>>> Hi,
>>>
>>> Here is the 3rd version of the series to improve the boot-time tracing to
>>> support kretprobe and tracing_on option. Previous version is here:
>>>
>>> https://lkml.kernel.org/r/159894698993.1478826.2813843560314595660.stgit@devnote2
>>>
>>> This version adds uprobe %return suffix support ([5/8]) and the testcases
>>> ([8/8]), and update kprobe %suffix support([4/8]) and the uprobe event
>>> document([6/8]).
>>>
>>>
>>> The combination of tracing_on and kretprobe allows us to trace events
>>> while a specific function call period. For example, the below bootconfig
>>> will make a function callgraph in the pci_proc_init() function at boot
>>> time.
>>>
>>> ftrace {
>>> tracing_on = 0 # off at start
>>> tracer = function_graph
>>> event.kprobes {
>>> start_event {
>>> probes = "pci_proc_init"
>>> actions = "traceon"
>>> }
>>> end_event {
>>> probes = "pci_proc_init%return"
>>> actions = "traceoff"
>>> }
>>> }
>>> }
>>>
>>> Here is the example output;
>>>
>>
>> [..]
>>
>> Hi Masami,
>>
>> This looks really great! I just got back from a 10 day holiday, and I'm
>> drowning in "catch-up". I plan on looking at all this relatively soon
>> (in a week or two?). I just don't want you to think I'm ignoring this.
>
> Hi Steve,
>
> Thanks, I hope you enjoyed the holiday!
> BTW, this series includes some document update and testcases.
> Since we can not decouple these updates, I think it is better you to
> pull the series.
>

Hi Steve and Masami,

selftests patch 8/8 in this series looks good to me. My ack for
it to go through Steve's ftrace tree

Acked-by: Shuah Khan <[email protected]>

thanks,
-- Shuah