tracepoint: Support iterating tracepoints in a loading module

Add for_each_tracepoint_in_module() function to iterate tracepoints in
a module. This API is needed for handling tracepoints in a loading
module from tracepoint_module_notifier callback function.
This also update for_each_module_tracepoint() to pass the module to
callback function so that it can find module easily.

Link: https://lore.kernel.org/all/172397778740.286558.15781131277732977643.stgit@devnote2/Signed-off-by: default avatarMasami Hiramatsu (Google) <mhiramat@kernel.org>
parent d5dbf8b4
...@@ -64,8 +64,13 @@ struct tp_module { ...@@ -64,8 +64,13 @@ struct tp_module {
bool trace_module_has_bad_taint(struct module *mod); bool trace_module_has_bad_taint(struct module *mod);
extern int register_tracepoint_module_notifier(struct notifier_block *nb); extern int register_tracepoint_module_notifier(struct notifier_block *nb);
extern int unregister_tracepoint_module_notifier(struct notifier_block *nb); extern int unregister_tracepoint_module_notifier(struct notifier_block *nb);
void for_each_module_tracepoint(void (*fct)(struct tracepoint *, void *), void for_each_module_tracepoint(void (*fct)(struct tracepoint *,
struct module *, void *),
void *priv); void *priv);
void for_each_tracepoint_in_module(struct module *,
void (*fct)(struct tracepoint *,
struct module *, void *),
void *priv);
#else #else
static inline bool trace_module_has_bad_taint(struct module *mod) static inline bool trace_module_has_bad_taint(struct module *mod)
{ {
...@@ -82,10 +87,18 @@ int unregister_tracepoint_module_notifier(struct notifier_block *nb) ...@@ -82,10 +87,18 @@ int unregister_tracepoint_module_notifier(struct notifier_block *nb)
return 0; return 0;
} }
static inline static inline
void for_each_module_tracepoint(void (*fct)(struct tracepoint *, void *), void for_each_module_tracepoint(void (*fct)(struct tracepoint *,
struct module *, void *),
void *priv) void *priv)
{ {
} }
static inline
void for_each_tracepoint_in_module(struct module *mod,
void (*fct)(struct tracepoint *,
struct module *, void *),
void *priv)
{
}
#endif /* CONFIG_MODULES */ #endif /* CONFIG_MODULES */
/* /*
......
...@@ -736,24 +736,45 @@ static __init int init_tracepoints(void) ...@@ -736,24 +736,45 @@ static __init int init_tracepoints(void)
} }
__initcall(init_tracepoints); __initcall(init_tracepoints);
/**
* for_each_tracepoint_in_module - iteration on all tracepoints in a module
* @mod: module
* @fct: callback
* @priv: private data
*/
void for_each_tracepoint_in_module(struct module *mod,
void (*fct)(struct tracepoint *tp,
struct module *mod, void *priv),
void *priv)
{
tracepoint_ptr_t *begin, *end, *iter;
lockdep_assert_held(&tracepoint_module_list_mutex);
if (!mod)
return;
begin = mod->tracepoints_ptrs;
end = mod->tracepoints_ptrs + mod->num_tracepoints;
for (iter = begin; iter < end; iter++)
fct(tracepoint_ptr_deref(iter), mod, priv);
}
/** /**
* for_each_module_tracepoint - iteration on all tracepoints in all modules * for_each_module_tracepoint - iteration on all tracepoints in all modules
* @fct: callback * @fct: callback
* @priv: private data * @priv: private data
*/ */
void for_each_module_tracepoint(void (*fct)(struct tracepoint *tp, void *priv), void for_each_module_tracepoint(void (*fct)(struct tracepoint *tp,
struct module *mod, void *priv),
void *priv) void *priv)
{ {
struct tp_module *tp_mod; struct tp_module *tp_mod;
struct module *mod;
mutex_lock(&tracepoint_module_list_mutex); mutex_lock(&tracepoint_module_list_mutex);
list_for_each_entry(tp_mod, &tracepoint_module_list, list) { list_for_each_entry(tp_mod, &tracepoint_module_list, list)
mod = tp_mod->mod; for_each_tracepoint_in_module(tp_mod->mod, fct, priv);
for_each_tracepoint_range(mod->tracepoints_ptrs,
mod->tracepoints_ptrs + mod->num_tracepoints,
fct, priv);
}
mutex_unlock(&tracepoint_module_list_mutex); mutex_unlock(&tracepoint_module_list_mutex);
} }
#endif /* CONFIG_MODULES */ #endif /* CONFIG_MODULES */
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment