Skip to content

Commit d4df54f

Browse files
committed
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: Masami Hiramatsu (Google) <[email protected]>
1 parent d5dbf8b commit d4df54f

File tree

2 files changed

+44
-10
lines changed

2 files changed

+44
-10
lines changed

include/linux/tracepoint.h

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,13 @@ struct tp_module {
6464
bool trace_module_has_bad_taint(struct module *mod);
6565
extern int register_tracepoint_module_notifier(struct notifier_block *nb);
6666
extern int unregister_tracepoint_module_notifier(struct notifier_block *nb);
67-
void for_each_module_tracepoint(void (*fct)(struct tracepoint *, void *),
67+
void for_each_module_tracepoint(void (*fct)(struct tracepoint *,
68+
struct module *, void *),
6869
void *priv);
70+
void for_each_tracepoint_in_module(struct module *,
71+
void (*fct)(struct tracepoint *,
72+
struct module *, void *),
73+
void *priv);
6974
#else
7075
static inline bool trace_module_has_bad_taint(struct module *mod)
7176
{
@@ -82,10 +87,18 @@ int unregister_tracepoint_module_notifier(struct notifier_block *nb)
8287
return 0;
8388
}
8489
static inline
85-
void for_each_module_tracepoint(void (*fct)(struct tracepoint *, void *),
90+
void for_each_module_tracepoint(void (*fct)(struct tracepoint *,
91+
struct module *, void *),
8692
void *priv)
8793
{
8894
}
95+
static inline
96+
void for_each_tracepoint_in_module(struct module *mod,
97+
void (*fct)(struct tracepoint *,
98+
struct module *, void *),
99+
void *priv)
100+
{
101+
}
89102
#endif /* CONFIG_MODULES */
90103

91104
/*

kernel/tracepoint.c

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -736,24 +736,45 @@ static __init int init_tracepoints(void)
736736
}
737737
__initcall(init_tracepoints);
738738

739+
/**
740+
* for_each_tracepoint_in_module - iteration on all tracepoints in a module
741+
* @mod: module
742+
* @fct: callback
743+
* @priv: private data
744+
*/
745+
void for_each_tracepoint_in_module(struct module *mod,
746+
void (*fct)(struct tracepoint *tp,
747+
struct module *mod, void *priv),
748+
void *priv)
749+
{
750+
tracepoint_ptr_t *begin, *end, *iter;
751+
752+
lockdep_assert_held(&tracepoint_module_list_mutex);
753+
754+
if (!mod)
755+
return;
756+
757+
begin = mod->tracepoints_ptrs;
758+
end = mod->tracepoints_ptrs + mod->num_tracepoints;
759+
760+
for (iter = begin; iter < end; iter++)
761+
fct(tracepoint_ptr_deref(iter), mod, priv);
762+
}
763+
739764
/**
740765
* for_each_module_tracepoint - iteration on all tracepoints in all modules
741766
* @fct: callback
742767
* @priv: private data
743768
*/
744-
void for_each_module_tracepoint(void (*fct)(struct tracepoint *tp, void *priv),
769+
void for_each_module_tracepoint(void (*fct)(struct tracepoint *tp,
770+
struct module *mod, void *priv),
745771
void *priv)
746772
{
747773
struct tp_module *tp_mod;
748-
struct module *mod;
749774

750775
mutex_lock(&tracepoint_module_list_mutex);
751-
list_for_each_entry(tp_mod, &tracepoint_module_list, list) {
752-
mod = tp_mod->mod;
753-
for_each_tracepoint_range(mod->tracepoints_ptrs,
754-
mod->tracepoints_ptrs + mod->num_tracepoints,
755-
fct, priv);
756-
}
776+
list_for_each_entry(tp_mod, &tracepoint_module_list, list)
777+
for_each_tracepoint_in_module(tp_mod->mod, fct, priv);
757778
mutex_unlock(&tracepoint_module_list_mutex);
758779
}
759780
#endif /* CONFIG_MODULES */

0 commit comments

Comments
 (0)