Skip to content

Commit 747774d

Browse files
mhiramatrostedt
authored andcommitted
tracing/probe: Add trace flag access APIs for trace_probe
Add trace_probe_test/set/clear_flag() functions for accessing trace_probe.flag field. This flags field should not be accessed directly. Link: http://lkml.kernel.org/r/155931585683.28323.314290023236905988.stgit@devnote2 Signed-off-by: Masami Hiramatsu <mhiramat@kernel.org> Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
1 parent b5f935e commit 747774d

4 files changed

Lines changed: 41 additions & 23 deletions

File tree

‎kernel/trace/trace_kprobe.c‎

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,7 @@ enable_trace_kprobe(struct trace_kprobe *tk, struct trace_event_file *file)
298298
if (ret)
299299
return ret;
300300
} else
301-
tk->tp.flags |= TP_FLAG_PROFILE;
301+
trace_probe_set_flag(&tk->tp, TP_FLAG_PROFILE);
302302

303303
if (enabled)
304304
return 0;
@@ -308,7 +308,7 @@ enable_trace_kprobe(struct trace_kprobe *tk, struct trace_event_file *file)
308308
if (file)
309309
trace_probe_remove_file(&tk->tp, file);
310310
else
311-
tk->tp.flags &= ~TP_FLAG_PROFILE;
311+
trace_probe_clear_flag(&tk->tp, TP_FLAG_PROFILE);
312312
}
313313

314314
return ret;
@@ -329,9 +329,9 @@ disable_trace_kprobe(struct trace_kprobe *tk, struct trace_event_file *file)
329329
return -ENOENT;
330330
if (!trace_probe_has_single_file(tp))
331331
goto out;
332-
tp->flags &= ~TP_FLAG_TRACE;
332+
trace_probe_clear_flag(tp, TP_FLAG_TRACE);
333333
} else
334-
tp->flags &= ~TP_FLAG_PROFILE;
334+
trace_probe_clear_flag(tp, TP_FLAG_PROFILE);
335335

336336
if (!trace_probe_is_enabled(tp) && trace_probe_is_registered(tp)) {
337337
if (trace_kprobe_is_return(tk))
@@ -408,7 +408,7 @@ static int __register_trace_kprobe(struct trace_kprobe *tk)
408408
ret = register_kprobe(&tk->rp.kp);
409409

410410
if (ret == 0)
411-
tk->tp.flags |= TP_FLAG_REGISTERED;
411+
trace_probe_set_flag(&tk->tp, TP_FLAG_REGISTERED);
412412
return ret;
413413
}
414414

@@ -420,7 +420,7 @@ static void __unregister_trace_kprobe(struct trace_kprobe *tk)
420420
unregister_kretprobe(&tk->rp);
421421
else
422422
unregister_kprobe(&tk->rp.kp);
423-
tk->tp.flags &= ~TP_FLAG_REGISTERED;
423+
trace_probe_clear_flag(&tk->tp, TP_FLAG_REGISTERED);
424424
/* Cleanup kprobe for reuse */
425425
if (tk->rp.kp.symbol_name)
426426
tk->rp.kp.addr = NULL;
@@ -1313,10 +1313,10 @@ static int kprobe_dispatcher(struct kprobe *kp, struct pt_regs *regs)
13131313

13141314
raw_cpu_inc(*tk->nhit);
13151315

1316-
if (tk->tp.flags & TP_FLAG_TRACE)
1316+
if (trace_probe_test_flag(&tk->tp, TP_FLAG_TRACE))
13171317
kprobe_trace_func(tk, regs);
13181318
#ifdef CONFIG_PERF_EVENTS
1319-
if (tk->tp.flags & TP_FLAG_PROFILE)
1319+
if (trace_probe_test_flag(&tk->tp, TP_FLAG_PROFILE))
13201320
ret = kprobe_perf_func(tk, regs);
13211321
#endif
13221322
return ret;
@@ -1330,10 +1330,10 @@ kretprobe_dispatcher(struct kretprobe_instance *ri, struct pt_regs *regs)
13301330

13311331
raw_cpu_inc(*tk->nhit);
13321332

1333-
if (tk->tp.flags & TP_FLAG_TRACE)
1333+
if (trace_probe_test_flag(&tk->tp, TP_FLAG_TRACE))
13341334
kretprobe_trace_func(tk, ri, regs);
13351335
#ifdef CONFIG_PERF_EVENTS
1336-
if (tk->tp.flags & TP_FLAG_PROFILE)
1336+
if (trace_probe_test_flag(&tk->tp, TP_FLAG_PROFILE))
13371337
kretprobe_perf_func(tk, ri, regs);
13381338
#endif
13391339
return 0; /* We don't tweek kernel, so just return 0 */

‎kernel/trace/trace_probe.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -948,7 +948,7 @@ int trace_probe_add_file(struct trace_probe *tp, struct trace_event_file *file)
948948
link->file = file;
949949
INIT_LIST_HEAD(&link->list);
950950
list_add_tail_rcu(&link->list, &tp->files);
951-
tp->flags |= TP_FLAG_TRACE;
951+
trace_probe_set_flag(tp, TP_FLAG_TRACE);
952952
return 0;
953953
}
954954

@@ -979,7 +979,7 @@ int trace_probe_remove_file(struct trace_probe *tp,
979979
kfree(link);
980980

981981
if (list_empty(&tp->files))
982-
tp->flags &= ~TP_FLAG_TRACE;
982+
trace_probe_clear_flag(tp, TP_FLAG_TRACE);
983983

984984
return 0;
985985
}

‎kernel/trace/trace_probe.h‎

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -238,14 +238,32 @@ struct event_file_link {
238238
struct list_head list;
239239
};
240240

241+
static inline bool trace_probe_test_flag(struct trace_probe *tp,
242+
unsigned int flag)
243+
{
244+
return !!(tp->flags & flag);
245+
}
246+
247+
static inline void trace_probe_set_flag(struct trace_probe *tp,
248+
unsigned int flag)
249+
{
250+
tp->flags |= flag;
251+
}
252+
253+
static inline void trace_probe_clear_flag(struct trace_probe *tp,
254+
unsigned int flag)
255+
{
256+
tp->flags &= ~flag;
257+
}
258+
241259
static inline bool trace_probe_is_enabled(struct trace_probe *tp)
242260
{
243-
return !!(tp->flags & (TP_FLAG_TRACE | TP_FLAG_PROFILE));
261+
return trace_probe_test_flag(tp, TP_FLAG_TRACE | TP_FLAG_PROFILE);
244262
}
245263

246264
static inline bool trace_probe_is_registered(struct trace_probe *tp)
247265
{
248-
return !!(tp->flags & TP_FLAG_REGISTERED);
266+
return trace_probe_test_flag(tp, TP_FLAG_REGISTERED);
249267
}
250268

251269
static inline int trace_probe_unregister_event_call(struct trace_probe *tp)

‎kernel/trace/trace_uprobe.c‎

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -927,17 +927,17 @@ probe_event_enable(struct trace_uprobe *tu, struct trace_event_file *file,
927927
int ret;
928928

929929
if (file) {
930-
if (tu->tp.flags & TP_FLAG_PROFILE)
930+
if (trace_probe_test_flag(&tu->tp, TP_FLAG_PROFILE))
931931
return -EINTR;
932932

933933
ret = trace_probe_add_file(&tu->tp, file);
934934
if (ret < 0)
935935
return ret;
936936
} else {
937-
if (tu->tp.flags & TP_FLAG_TRACE)
937+
if (trace_probe_test_flag(&tu->tp, TP_FLAG_TRACE))
938938
return -EINTR;
939939

940-
tu->tp.flags |= TP_FLAG_PROFILE;
940+
trace_probe_set_flag(&tu->tp, TP_FLAG_PROFILE);
941941
}
942942

943943
WARN_ON(!uprobe_filter_is_empty(&tu->filter));
@@ -970,7 +970,7 @@ probe_event_enable(struct trace_uprobe *tu, struct trace_event_file *file,
970970
if (file)
971971
trace_probe_remove_file(&tu->tp, file);
972972
else
973-
tu->tp.flags &= ~TP_FLAG_PROFILE;
973+
trace_probe_clear_flag(&tu->tp, TP_FLAG_PROFILE);
974974

975975
return ret;
976976
}
@@ -988,7 +988,7 @@ probe_event_disable(struct trace_uprobe *tu, struct trace_event_file *file)
988988
if (trace_probe_is_enabled(&tu->tp))
989989
return;
990990
} else
991-
tu->tp.flags &= ~TP_FLAG_PROFILE;
991+
trace_probe_clear_flag(&tu->tp, TP_FLAG_PROFILE);
992992

993993
WARN_ON(!uprobe_filter_is_empty(&tu->filter));
994994

@@ -1266,11 +1266,11 @@ static int uprobe_dispatcher(struct uprobe_consumer *con, struct pt_regs *regs)
12661266
ucb = uprobe_buffer_get();
12671267
store_trace_args(ucb->buf, &tu->tp, regs, esize, dsize);
12681268

1269-
if (tu->tp.flags & TP_FLAG_TRACE)
1269+
if (trace_probe_test_flag(&tu->tp, TP_FLAG_TRACE))
12701270
ret |= uprobe_trace_func(tu, regs, ucb, dsize);
12711271

12721272
#ifdef CONFIG_PERF_EVENTS
1273-
if (tu->tp.flags & TP_FLAG_PROFILE)
1273+
if (trace_probe_test_flag(&tu->tp, TP_FLAG_PROFILE))
12741274
ret |= uprobe_perf_func(tu, regs, ucb, dsize);
12751275
#endif
12761276
uprobe_buffer_put(ucb);
@@ -1301,11 +1301,11 @@ static int uretprobe_dispatcher(struct uprobe_consumer *con,
13011301
ucb = uprobe_buffer_get();
13021302
store_trace_args(ucb->buf, &tu->tp, regs, esize, dsize);
13031303

1304-
if (tu->tp.flags & TP_FLAG_TRACE)
1304+
if (trace_probe_test_flag(&tu->tp, TP_FLAG_TRACE))
13051305
uretprobe_trace_func(tu, func, regs, ucb, dsize);
13061306

13071307
#ifdef CONFIG_PERF_EVENTS
1308-
if (tu->tp.flags & TP_FLAG_PROFILE)
1308+
if (trace_probe_test_flag(&tu->tp, TP_FLAG_PROFILE))
13091309
uretprobe_perf_func(tu, func, regs, ucb, dsize);
13101310
#endif
13111311
uprobe_buffer_put(ucb);

0 commit comments

Comments
 (0)