diff options
author | Masami Hiramatsu <mhiramat@kernel.org> | 2019-05-31 11:18:07 -0400 |
---|---|---|
committer | Steven Rostedt (VMware) <rostedt@goodmis.org> | 2019-07-16 15:14:47 -0400 |
commit | 715fa2fd4c6c3e9165659ac26a582b8a2e607b93 (patch) | |
tree | 3b98b168ba4ed21159dcc32720520599b9e450d7 | |
parent | e3dc9f898ef9c6a1a96378517573ee2d04d0abcc (diff) |
tracing/kprobe: Check registered state using kprobe
Change registered check only by trace_kprobe and remove
TP_FLAG_REGISTERED from trace_probe, since this feature
is only used for trace_kprobe.
Link: http://lkml.kernel.org/r/155931588704.28323.4952266828256245833.stgit@devnote2
Signed-off-by: Masami Hiramatsu <mhiramat@kernel.org>
Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
-rw-r--r-- | kernel/trace/trace_kprobe.c | 23 | ||||
-rw-r--r-- | kernel/trace/trace_probe.h | 6 |
2 files changed, 15 insertions, 14 deletions
diff --git a/kernel/trace/trace_kprobe.c b/kernel/trace/trace_kprobe.c index 62362ad1ad98..9d483ad9bb6c 100644 --- a/kernel/trace/trace_kprobe.c +++ b/kernel/trace/trace_kprobe.c | |||
@@ -157,6 +157,12 @@ static nokprobe_inline unsigned long trace_kprobe_nhit(struct trace_kprobe *tk) | |||
157 | return nhit; | 157 | return nhit; |
158 | } | 158 | } |
159 | 159 | ||
160 | static nokprobe_inline bool trace_kprobe_is_registered(struct trace_kprobe *tk) | ||
161 | { | ||
162 | return !(list_empty(&tk->rp.kp.list) && | ||
163 | hlist_unhashed(&tk->rp.kp.hlist)); | ||
164 | } | ||
165 | |||
160 | /* Return 0 if it fails to find the symbol address */ | 166 | /* Return 0 if it fails to find the symbol address */ |
161 | static nokprobe_inline | 167 | static nokprobe_inline |
162 | unsigned long trace_kprobe_address(struct trace_kprobe *tk) | 168 | unsigned long trace_kprobe_address(struct trace_kprobe *tk) |
@@ -244,6 +250,8 @@ static struct trace_kprobe *alloc_trace_kprobe(const char *group, | |||
244 | tk->rp.kp.pre_handler = kprobe_dispatcher; | 250 | tk->rp.kp.pre_handler = kprobe_dispatcher; |
245 | 251 | ||
246 | tk->rp.maxactive = maxactive; | 252 | tk->rp.maxactive = maxactive; |
253 | INIT_HLIST_NODE(&tk->rp.kp.hlist); | ||
254 | INIT_LIST_HEAD(&tk->rp.kp.list); | ||
247 | 255 | ||
248 | ret = trace_probe_init(&tk->tp, event, group); | 256 | ret = trace_probe_init(&tk->tp, event, group); |
249 | if (ret < 0) | 257 | if (ret < 0) |
@@ -273,7 +281,7 @@ static inline int __enable_trace_kprobe(struct trace_kprobe *tk) | |||
273 | { | 281 | { |
274 | int ret = 0; | 282 | int ret = 0; |
275 | 283 | ||
276 | if (trace_probe_is_registered(&tk->tp) && !trace_kprobe_has_gone(tk)) { | 284 | if (trace_kprobe_is_registered(tk) && !trace_kprobe_has_gone(tk)) { |
277 | if (trace_kprobe_is_return(tk)) | 285 | if (trace_kprobe_is_return(tk)) |
278 | ret = enable_kretprobe(&tk->rp); | 286 | ret = enable_kretprobe(&tk->rp); |
279 | else | 287 | else |
@@ -333,7 +341,7 @@ disable_trace_kprobe(struct trace_kprobe *tk, struct trace_event_file *file) | |||
333 | } else | 341 | } else |
334 | trace_probe_clear_flag(tp, TP_FLAG_PROFILE); | 342 | trace_probe_clear_flag(tp, TP_FLAG_PROFILE); |
335 | 343 | ||
336 | if (!trace_probe_is_enabled(tp) && trace_probe_is_registered(tp)) { | 344 | if (!trace_probe_is_enabled(tp) && trace_kprobe_is_registered(tk)) { |
337 | if (trace_kprobe_is_return(tk)) | 345 | if (trace_kprobe_is_return(tk)) |
338 | disable_kretprobe(&tk->rp); | 346 | disable_kretprobe(&tk->rp); |
339 | else | 347 | else |
@@ -381,7 +389,7 @@ static int __register_trace_kprobe(struct trace_kprobe *tk) | |||
381 | { | 389 | { |
382 | int i, ret; | 390 | int i, ret; |
383 | 391 | ||
384 | if (trace_probe_is_registered(&tk->tp)) | 392 | if (trace_kprobe_is_registered(tk)) |
385 | return -EINVAL; | 393 | return -EINVAL; |
386 | 394 | ||
387 | if (within_notrace_func(tk)) { | 395 | if (within_notrace_func(tk)) { |
@@ -407,21 +415,20 @@ static int __register_trace_kprobe(struct trace_kprobe *tk) | |||
407 | else | 415 | else |
408 | ret = register_kprobe(&tk->rp.kp); | 416 | ret = register_kprobe(&tk->rp.kp); |
409 | 417 | ||
410 | if (ret == 0) | ||
411 | trace_probe_set_flag(&tk->tp, TP_FLAG_REGISTERED); | ||
412 | return ret; | 418 | return ret; |
413 | } | 419 | } |
414 | 420 | ||
415 | /* Internal unregister function - just handle k*probes and flags */ | 421 | /* Internal unregister function - just handle k*probes and flags */ |
416 | static void __unregister_trace_kprobe(struct trace_kprobe *tk) | 422 | static void __unregister_trace_kprobe(struct trace_kprobe *tk) |
417 | { | 423 | { |
418 | if (trace_probe_is_registered(&tk->tp)) { | 424 | if (trace_kprobe_is_registered(tk)) { |
419 | if (trace_kprobe_is_return(tk)) | 425 | if (trace_kprobe_is_return(tk)) |
420 | unregister_kretprobe(&tk->rp); | 426 | unregister_kretprobe(&tk->rp); |
421 | else | 427 | else |
422 | unregister_kprobe(&tk->rp.kp); | 428 | unregister_kprobe(&tk->rp.kp); |
423 | trace_probe_clear_flag(&tk->tp, TP_FLAG_REGISTERED); | 429 | /* Cleanup kprobe for reuse and mark it unregistered */ |
424 | /* Cleanup kprobe for reuse */ | 430 | INIT_HLIST_NODE(&tk->rp.kp.hlist); |
431 | INIT_LIST_HEAD(&tk->rp.kp.list); | ||
425 | if (tk->rp.kp.symbol_name) | 432 | if (tk->rp.kp.symbol_name) |
426 | tk->rp.kp.addr = NULL; | 433 | tk->rp.kp.addr = NULL; |
427 | } | 434 | } |
diff --git a/kernel/trace/trace_probe.h b/kernel/trace/trace_probe.h index 6c33d4aa36c3..d1714820efe1 100644 --- a/kernel/trace/trace_probe.h +++ b/kernel/trace/trace_probe.h | |||
@@ -55,7 +55,6 @@ | |||
55 | /* Flags for trace_probe */ | 55 | /* Flags for trace_probe */ |
56 | #define TP_FLAG_TRACE 1 | 56 | #define TP_FLAG_TRACE 1 |
57 | #define TP_FLAG_PROFILE 2 | 57 | #define TP_FLAG_PROFILE 2 |
58 | #define TP_FLAG_REGISTERED 4 | ||
59 | 58 | ||
60 | /* data_loc: data location, compatible with u32 */ | 59 | /* data_loc: data location, compatible with u32 */ |
61 | #define make_data_loc(len, offs) \ | 60 | #define make_data_loc(len, offs) \ |
@@ -261,11 +260,6 @@ static inline bool trace_probe_is_enabled(struct trace_probe *tp) | |||
261 | return trace_probe_test_flag(tp, TP_FLAG_TRACE | TP_FLAG_PROFILE); | 260 | return trace_probe_test_flag(tp, TP_FLAG_TRACE | TP_FLAG_PROFILE); |
262 | } | 261 | } |
263 | 262 | ||
264 | static inline bool trace_probe_is_registered(struct trace_probe *tp) | ||
265 | { | ||
266 | return trace_probe_test_flag(tp, TP_FLAG_REGISTERED); | ||
267 | } | ||
268 | |||
269 | static inline const char *trace_probe_name(struct trace_probe *tp) | 263 | static inline const char *trace_probe_name(struct trace_probe *tp) |
270 | { | 264 | { |
271 | return trace_event_name(&tp->call); | 265 | return trace_event_name(&tp->call); |