Skip to content

Commit eb5bf81

Browse files
mhiramatrostedt
authored andcommitted
tracing/kprobe: Add per-probe delete from event
Allow user to delete a probe from event. This is done by head match. For example, if we have 2 probes on an event $ cat kprobe_events p:kprobes/testprobe _do_fork r1=%ax r2=%dx p:kprobes/testprobe idle_fork r1=%ax r2=%cx Then you can remove one of them by passing the head of definition which identify the probe. $ echo "-:kprobes/testprobe idle_fork" >> kprobe_events Link: http://lkml.kernel.org/r/156095688848.28024.15798690082378432435.stgit@devnote2 Signed-off-by: Masami Hiramatsu <mhiramat@kernel.org> Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
1 parent 41af3cf commit eb5bf81

3 files changed

Lines changed: 44 additions & 1 deletion

File tree

‎kernel/trace/trace_kprobe.c‎

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,13 +137,36 @@ static bool trace_kprobe_is_busy(struct dyn_event *ev)
137137
return trace_probe_is_enabled(&tk->tp);
138138
}
139139

140+
static bool trace_kprobe_match_command_head(struct trace_kprobe *tk,
141+
int argc, const char **argv)
142+
{
143+
char buf[MAX_ARGSTR_LEN + 1];
144+
145+
if (!argc)
146+
return true;
147+
148+
if (!tk->symbol)
149+
snprintf(buf, sizeof(buf), "0x%p", tk->rp.kp.addr);
150+
else if (tk->rp.kp.offset)
151+
snprintf(buf, sizeof(buf), "%s+%u",
152+
trace_kprobe_symbol(tk), tk->rp.kp.offset);
153+
else
154+
snprintf(buf, sizeof(buf), "%s", trace_kprobe_symbol(tk));
155+
if (strcmp(buf, argv[0]))
156+
return false;
157+
argc--; argv++;
158+
159+
return trace_probe_match_command_args(&tk->tp, argc, argv);
160+
}
161+
140162
static bool trace_kprobe_match(const char *system, const char *event,
141163
int argc, const char **argv, struct dyn_event *ev)
142164
{
143165
struct trace_kprobe *tk = to_trace_kprobe(ev);
144166

145167
return strcmp(trace_probe_name(&tk->tp), event) == 0 &&
146-
(!system || strcmp(trace_probe_group_name(&tk->tp), system) == 0);
168+
(!system || strcmp(trace_probe_group_name(&tk->tp), system) == 0) &&
169+
trace_kprobe_match_command_head(tk, argc, argv);
147170
}
148171

149172
static nokprobe_inline unsigned long trace_kprobe_nhit(struct trace_kprobe *tk)

‎kernel/trace/trace_probe.c‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1047,3 +1047,21 @@ int trace_probe_compare_arg_type(struct trace_probe *a, struct trace_probe *b)
10471047

10481048
return 0;
10491049
}
1050+
1051+
bool trace_probe_match_command_args(struct trace_probe *tp,
1052+
int argc, const char **argv)
1053+
{
1054+
char buf[MAX_ARGSTR_LEN + 1];
1055+
int i;
1056+
1057+
if (tp->nr_args < argc)
1058+
return false;
1059+
1060+
for (i = 0; i < argc; i++) {
1061+
snprintf(buf, sizeof(buf), "%s=%s",
1062+
tp->args[i].name, tp->args[i].comm);
1063+
if (strcmp(buf, argv[i]))
1064+
return false;
1065+
}
1066+
return true;
1067+
}

‎kernel/trace/trace_probe.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -332,6 +332,8 @@ int trace_probe_remove_file(struct trace_probe *tp,
332332
struct event_file_link *trace_probe_get_file_link(struct trace_probe *tp,
333333
struct trace_event_file *file);
334334
int trace_probe_compare_arg_type(struct trace_probe *a, struct trace_probe *b);
335+
bool trace_probe_match_command_args(struct trace_probe *tp,
336+
int argc, const char **argv);
335337

336338
#define trace_probe_for_each_link(pos, tp) \
337339
list_for_each_entry(pos, &(tp)->event->files, list)

0 commit comments

Comments
 (0)