Skip to content

Commit 970988e

Browse files
mhiramatrostedt
authored andcommitted
tracing/kprobe: Add kprobe_event= boot parameter
Add kprobe_event= boot parameter to define kprobe events at boot time. The definition syntax is similar to tracefs/kprobe_events interface, but use ',' and ';' instead of ' ' and '\n' respectively. e.g. kprobe_event=p,vfs_read,$arg1,$arg2 This puts a probe on vfs_read with argument1 and 2, and enable the new event. Link: http://lkml.kernel.org/r/155851395498.15728.830529496248543583.stgit@devnote2 Signed-off-by: Masami Hiramatsu <[email protected]> Signed-off-by: Steven Rostedt (VMware) <[email protected]>
1 parent b5f8b32 commit 970988e

File tree

3 files changed

+81
-0
lines changed

3 files changed

+81
-0
lines changed

Documentation/admin-guide/kernel-parameters.txt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2007,6 +2007,19 @@
20072007
Built with CONFIG_DEBUG_KMEMLEAK_DEFAULT_OFF=y,
20082008
the default is off.
20092009

2010+
kprobe_event=[probe-list]
2011+
[FTRACE] Add kprobe events and enable at boot time.
2012+
The probe-list is a semicolon delimited list of probe
2013+
definitions. Each definition is same as kprobe_events
2014+
interface, but the parameters are comma delimited.
2015+
For example, to add a kprobe event on vfs_read with
2016+
arg1 and arg2, add to the command line;
2017+
2018+
kprobe_event=p,vfs_read,$arg1,$arg2
2019+
2020+
See also Documentation/trace/kprobetrace.rst "Kernel
2021+
Boot Parameter" section.
2022+
20102023
kpti= [ARM64] Control page table isolation of user
20112024
and kernel address spaces.
20122025
Default: enabled on cores which need mitigation.

Documentation/trace/kprobetrace.rst

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,20 @@ You can check the total number of probe hits and probe miss-hits via
146146
The first column is event name, the second is the number of probe hits,
147147
the third is the number of probe miss-hits.
148148

149+
Kernel Boot Parameter
150+
---------------------
151+
You can add and enable new kprobe events when booting up the kernel by
152+
"kprobe_event=" parameter. The parameter accepts a semicolon-delimited
153+
kprobe events, which format is similar to the kprobe_events.
154+
The difference is that the probe definition parameters are comma-delimited
155+
instead of space. For example, adding myprobe event on do_sys_open like below
156+
157+
p:myprobe do_sys_open dfd=%ax filename=%dx flags=%cx mode=+4($stack)
158+
159+
should be below for kernel boot parameter (just replace spaces with comma)
160+
161+
p:myprobe,do_sys_open,dfd=%ax,filename=%dx,flags=%cx,mode=+4($stack)
162+
149163

150164
Usage examples
151165
--------------

kernel/trace/trace_kprobe.c

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,26 @@
1212
#include <linux/rculist.h>
1313
#include <linux/error-injection.h>
1414

15+
#include <asm/setup.h> /* for COMMAND_LINE_SIZE */
16+
1517
#include "trace_dynevent.h"
1618
#include "trace_kprobe_selftest.h"
1719
#include "trace_probe.h"
1820
#include "trace_probe_tmpl.h"
1921

2022
#define KPROBE_EVENT_SYSTEM "kprobes"
2123
#define KRETPROBE_MAXACTIVE_MAX 4096
24+
#define MAX_KPROBE_CMDLINE_SIZE 1024
25+
26+
/* Kprobe early definition from command line */
27+
static char kprobe_boot_events_buf[COMMAND_LINE_SIZE] __initdata;
28+
29+
static int __init set_kprobe_boot_events(char *str)
30+
{
31+
strlcpy(kprobe_boot_events_buf, str, COMMAND_LINE_SIZE);
32+
return 0;
33+
}
34+
__setup("kprobe_event=", set_kprobe_boot_events);
2235

2336
static int trace_kprobe_create(int argc, const char **argv);
2437
static int trace_kprobe_show(struct seq_file *m, struct dyn_event *ev);
@@ -1494,6 +1507,44 @@ void destroy_local_trace_kprobe(struct trace_event_call *event_call)
14941507
}
14951508
#endif /* CONFIG_PERF_EVENTS */
14961509

1510+
static __init void enable_boot_kprobe_events(void)
1511+
{
1512+
struct trace_array *tr = top_trace_array();
1513+
struct trace_event_file *file;
1514+
struct trace_kprobe *tk;
1515+
struct dyn_event *pos;
1516+
1517+
mutex_lock(&event_mutex);
1518+
for_each_trace_kprobe(tk, pos) {
1519+
list_for_each_entry(file, &tr->events, list)
1520+
if (file->event_call == &tk->tp.call)
1521+
trace_event_enable_disable(file, 1, 0);
1522+
}
1523+
mutex_unlock(&event_mutex);
1524+
}
1525+
1526+
static __init void setup_boot_kprobe_events(void)
1527+
{
1528+
char *p, *cmd = kprobe_boot_events_buf;
1529+
int ret;
1530+
1531+
strreplace(kprobe_boot_events_buf, ',', ' ');
1532+
1533+
while (cmd && *cmd != '\0') {
1534+
p = strchr(cmd, ';');
1535+
if (p)
1536+
*p++ = '\0';
1537+
1538+
ret = trace_run_command(cmd, create_or_delete_trace_kprobe);
1539+
if (ret)
1540+
pr_warn("Failed to add event(%d): %s\n", ret, cmd);
1541+
1542+
cmd = p;
1543+
}
1544+
1545+
enable_boot_kprobe_events();
1546+
}
1547+
14971548
/* Make a tracefs interface for controlling probe points */
14981549
static __init int init_kprobe_trace(void)
14991550
{
@@ -1525,6 +1576,9 @@ static __init int init_kprobe_trace(void)
15251576

15261577
if (!entry)
15271578
pr_warn("Could not create tracefs 'kprobe_profile' entry\n");
1579+
1580+
setup_boot_kprobe_events();
1581+
15281582
return 0;
15291583
}
15301584
fs_initcall(init_kprobe_trace);

0 commit comments

Comments
 (0)