Re: [PATCH 5/7] Ksplice: Add functions for walking kallsyms symbols

Anders Kaseorg
2009-02-04T21:31:43Z

On Wed, 4 Feb 2009, Rusty Russell wrote:
> Seems reasonable. Did you really not want a name-filtering version? That
> might be generally useful.

We don’t actually want a name-filtering version for Ksplice. We process
all the symbols we need in one pass, in order to avoid traversing the
kallsyms list separately for each symbol.

> But does no locking at all. It either needs a comment that it can only be
> called from inside stop_machine, or that it needs preempt disabled, or
> whatever.

It might as well use preempt_disable() and RCU itself (patch below).

> Is the !CONFIG_KALLSYMS version useful to you? If not, please don't
> implement the noop version. I want someone who *does* expect it to work to
> have to think about it if they use it...

No, we don’t have a particular use for it; we added it for consistency
with kallsyms_lookup_name(), etc.

Anders

diff --git a/kernel/module.c b/kernel/module.c
index 556112c..6bb5814 100644
--- a/kernel/module.c
+++ b/kernel/module.c
@@ -2577,17 +2577,20 @@ int module_kallsyms_on_each_symbol(int (*fn)(void *, const char *,
{
struct module *mod;
unsigned int i;
- int ret;
+ int ret = 0;

- list_for_each_entry(mod, &modules, list) {
+ preempt_disable();
+ list_for_each_entry_rcu(mod, &modules, list) {
for (i = 0; i < mod->num_symtab; i++) {
ret = fn(data, mod->strtab + mod->symtab[i].st_name,
mod, mod->symtab[i].st_value);
if (ret != 0)
- return ret;
+ goto out;
}
}
- return 0;
+out:
+ preempt_enable();
+ return ret;
}
#endif /* CONFIG_KALLSYMS */