Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

authored by

Masami Hiramatsu and committed by
Steven Rostedt (VMware)
715fa2fd e3dc9f89

+15 -14
+15 -8
kernel/trace/trace_kprobe.c
··· 157 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 166 /* Return 0 if it fails to find the symbol address */ 161 167 static nokprobe_inline 162 168 unsigned long trace_kprobe_address(struct trace_kprobe *tk) ··· 250 244 tk->rp.kp.pre_handler = kprobe_dispatcher; 251 245 252 246 tk->rp.maxactive = maxactive; 247 + INIT_HLIST_NODE(&tk->rp.kp.hlist); 248 + INIT_LIST_HEAD(&tk->rp.kp.list); 253 249 254 250 ret = trace_probe_init(&tk->tp, event, group); 255 251 if (ret < 0) ··· 281 273 { 282 274 int ret = 0; 283 275 284 - if (trace_probe_is_registered(&tk->tp) && !trace_kprobe_has_gone(tk)) { 276 + if (trace_kprobe_is_registered(tk) && !trace_kprobe_has_gone(tk)) { 285 277 if (trace_kprobe_is_return(tk)) 286 278 ret = enable_kretprobe(&tk->rp); 287 279 else ··· 341 333 } else 342 334 trace_probe_clear_flag(tp, TP_FLAG_PROFILE); 343 335 344 - if (!trace_probe_is_enabled(tp) && trace_probe_is_registered(tp)) { 336 + if (!trace_probe_is_enabled(tp) && trace_kprobe_is_registered(tk)) { 345 337 if (trace_kprobe_is_return(tk)) 346 338 disable_kretprobe(&tk->rp); 347 339 else ··· 389 381 { 390 382 int i, ret; 391 383 392 - if (trace_probe_is_registered(&tk->tp)) 384 + if (trace_kprobe_is_registered(tk)) 393 385 return -EINVAL; 394 386 395 387 if (within_notrace_func(tk)) { ··· 415 407 else 416 408 ret = register_kprobe(&tk->rp.kp); 417 409 418 - if (ret == 0) 419 - trace_probe_set_flag(&tk->tp, TP_FLAG_REGISTERED); 420 410 return ret; 421 411 } 422 412 423 413 /* Internal unregister function - just handle k*probes and flags */ 424 414 static void __unregister_trace_kprobe(struct trace_kprobe *tk) 425 415 { 426 - if (trace_probe_is_registered(&tk->tp)) { 416 + if (trace_kprobe_is_registered(tk)) { 427 417 if (trace_kprobe_is_return(tk)) 428 418 unregister_kretprobe(&tk->rp); 429 419 else 430 420 unregister_kprobe(&tk->rp.kp); 431 - trace_probe_clear_flag(&tk->tp, TP_FLAG_REGISTERED); 432 - /* Cleanup kprobe for reuse */ 421 + /* Cleanup kprobe for reuse and mark it unregistered */ 422 + INIT_HLIST_NODE(&tk->rp.kp.hlist); 423 + INIT_LIST_HEAD(&tk->rp.kp.list); 433 424 if (tk->rp.kp.symbol_name) 434 425 tk->rp.kp.addr = NULL; 435 426 }
-6
kernel/trace/trace_probe.h
··· 55 55 /* Flags for trace_probe */ 56 56 #define TP_FLAG_TRACE 1 57 57 #define TP_FLAG_PROFILE 2 58 - #define TP_FLAG_REGISTERED 4 59 58 60 59 /* data_loc: data location, compatible with u32 */ 61 60 #define make_data_loc(len, offs) \ ··· 258 259 static inline bool trace_probe_is_enabled(struct trace_probe *tp) 259 260 { 260 261 return trace_probe_test_flag(tp, TP_FLAG_TRACE | TP_FLAG_PROFILE); 261 - } 262 - 263 - static inline bool trace_probe_is_registered(struct trace_probe *tp) 264 - { 265 - return trace_probe_test_flag(tp, TP_FLAG_REGISTERED); 266 262 } 267 263 268 264 static inline const char *trace_probe_name(struct trace_probe *tp)