Skip to content

Commit 966b7d0

Browse files
committed
module: Add module_for_each_mod() function
The tracing system needs a way to save all the currently loaded modules and their addresses into persistent memory so that it can evaluate the addresses on a reboot from a crash. When the persistent memory trace starts, it will load the module addresses and names into the persistent memory. To do so, it will call the module_for_each_mod() function and pass it a function and data structure to get called on each loaded module. Then it can record the memory. This only implements that function. Cc: Luis Chamberlain <[email protected]> Cc: Masami Hiramatsu <[email protected]> Cc: Mark Rutland <[email protected]> Cc: Mathieu Desnoyers <[email protected]> Cc: Andrew Morton <[email protected]> Cc: Sami Tolvanen <[email protected]> Cc: Daniel Gomez <[email protected]> Cc: [email protected] Link: https://lore.kernel.org/[email protected] Acked-by: Petr Pavlu <[email protected]> Signed-off-by: Steven Rostedt (Google) <[email protected]>
1 parent b653348 commit 966b7d0

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

include/linux/module.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -782,6 +782,8 @@ static inline void *module_writable_address(struct module *mod, void *loc)
782782
return __module_writable_address(mod, loc);
783783
}
784784

785+
void module_for_each_mod(int(*func)(struct module *mod, void *data), void *data);
786+
785787
#else /* !CONFIG_MODULES... */
786788

787789
static inline struct module *__module_address(unsigned long addr)
@@ -894,6 +896,10 @@ static inline void *module_writable_address(struct module *mod, void *loc)
894896
{
895897
return loc;
896898
}
899+
900+
static inline void module_for_each_mod(int(*func)(struct module *mod, void *data), void *data)
901+
{
902+
}
897903
#endif /* CONFIG_MODULES */
898904

899905
#ifdef CONFIG_SYSFS

kernel/module/main.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3809,6 +3809,19 @@ bool is_module_text_address(unsigned long addr)
38093809
return ret;
38103810
}
38113811

3812+
void module_for_each_mod(int(*func)(struct module *mod, void *data), void *data)
3813+
{
3814+
struct module *mod;
3815+
3816+
guard(rcu)();
3817+
list_for_each_entry_rcu(mod, &modules, list) {
3818+
if (mod->state == MODULE_STATE_UNFORMED)
3819+
continue;
3820+
if (func(mod, data))
3821+
break;
3822+
}
3823+
}
3824+
38123825
/**
38133826
* __module_text_address() - get the module whose code contains an address.
38143827
* @addr: the address.

0 commit comments

Comments
 (0)