Ksplice: Add functions for walking kallsyms symbols
PATCH 6/9 Ksplice: Add functions for walking kallsyms symbols
From: Anders Kaseorg <[email protected]>
Impact: New API
kallsyms_lookup_name only returns the first match that it finds. Ksplice needs information about all symbols with a given name in order to correctly resolve local symbols.
kallsyms_on_each_symbol provides a generic mechanism for iterating over the kallsyms table.
--- include/linux/kallsyms.h | 13 +++++++++++++ include/linux/module.h | 12 ++++++++++++ kernel/kallsyms.c | 19 +++++++++++++++++++ kernel/module.c | 19 +++++++++++++++++++ 4 files changed, 63 insertions(+)
include/linux/kallsyms.h +13 -0
@@ -17,6 +17,11 @@/* Lookup the address for a symbol. Returns 0 if not found. */ unsigned long kallsyms_lookup_name (const char *name); +/* Call a function on each kallsyms symbol in the core kernel */ +int kallsyms_on_each_symbol (int (*fn)(void *,const char *,struct module *, +unsigned long ), +void *data); +extern int kallsyms_lookup_size_offset (unsigned long addr,unsigned long *symbolsize,unsigned long *offset);
@@ -43,6 +48,14 @@ static inline unsigned long kallsyms_lookup_name(const char *name)return 0 ; } +static inline int kallsyms_on_each_symbol (int (*fn)(void *,const char *, +struct module *, +unsigned long ), +void *data) +{ +return 0 ; +} +static inline int kallsyms_lookup_size_offset (unsigned long addr,unsigned long *symbolsize,unsigned long *offset)
include/linux/module.h +12 -0
@@ -378,6 +378,10 @@ int module_get_kallsym(unsigned int symnum, unsigned long *value, char *type,/* Look for this name: can be of form module:name. */ unsigned long module_kallsyms_lookup_name (const char *name); +int module_kallsyms_on_each_symbol (int (*fn)(void *,const char *, +struct module *,unsigned long ), +void *data); +extern void __module_put_and_exit (struct module *mod,long code) __attribute__((noreturn));#define module_put_and_exit (code) __module_put_and_exit(THIS_MODULE, code);
@@ -546,6 +550,14 @@ static inline unsigned long module_kallsyms_lookup_name(const char *name)return 0 ; } +static inline int module_kallsyms_on_each_symbol (int (*fn)(void *,const char *, +struct module *, +unsigned long ), +void *data) +{ +return 0 ; +} +static inline int register_module_notifier (struct notifier_block * nb) {/* no events will happen anyway, so this can always succeed */
kernel/kallsyms.c +19 -0
@@ -161,6 +161,25 @@ unsigned long kallsyms_lookup_name(const char *name)return module_kallsyms_lookup_name (name); } +int kallsyms_on_each_symbol (int (*fn)(void *,const char *,struct module *, +unsigned long ), +void *data) +{ +char namebuf[KSYM_NAME_LEN ]; +unsigned long i; +unsigned int off; +int ret; + +for (i =0 , off =0 ; i < kallsyms_num_syms; i++) { + off =kallsyms_expand_symbol (off, namebuf); + ret =fn (data, namebuf,NULL , kallsyms_addresses[i]); +if (ret !=0 ) +return ret; + } +return module_kallsyms_on_each_symbol (fn, data); +} +EXPORT_SYMBOL_GPL (kallsyms_on_each_symbol); +static unsigned long get_symbol_pos (unsigned long addr,unsigned long *symbolsize,unsigned long *offset)
kernel/module.c +19 -0
@@ -2554,6 +2554,25 @@ unsigned long module_kallsyms_lookup_name(const char *name)preempt_enable ();return ret; } + +int module_kallsyms_on_each_symbol (int (*fn)(void *,const char *, +struct module *,unsigned long ), +void *data) +{ +struct module *mod; +unsigned int i; +int ret; + +list_for_each_entry (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; + } + } +return 0 ; +}#endif /* CONFIG_KALLSYMS */ static char *module_flags (struct module *mod,char *buf)
Folks,
Please forgive me not tracking ksplice closely enough - I didn't think it required these changes - is there some refactoring going on currently or am I mistaken and these patches are now a necessary pre-req.?
Jon.
Quoted 5 lines · Jon Masters
Folks,
Please forgive me not tracking ksplice closely enough - I didn't think it required these changes - is there some refactoring going on currently or am I mistaken and these patches are now a necessary pre-req.?
Hi Jon,
There are two different versions of the Ksplice kernel module, a "standalone" version that works with an unmodified kernel, and the version that we've proposed for mainline merge.
One difference between the two versions is that the standalone version has implementations of functions such as kallsyms_on_each_symbol in the Ksplice core module (i.e. the module containing ksplice.c).
Normally, one would not be able to implement kallsyms_on_each_symbol in a module, because it would not have access to necessary symbols such as kallsyms_num_syms (an unexported global symbol). The standalone version of Ksplice resolves these symbols through a bootstrapping process.
This bootstrapping technique doesn't make any sense for a Ksplice in mainline; these prerequisite patches put functions such as kallsyms_on_each_symbol where they belong.
-Tim Abbott
Quoted 3 lines · Tim Abbott
There are two different versions of the Ksplice kernel module, a "standalone" version that works with an unmodified kernel, and the version that we've proposed for mainline merge.
Ah thanks, I didn't realize you were proposing for mainline merge - awesome. That would really be a useful merge...how close do you think that is?
Jon.
Quoted 3 lines · Jon Masters
Ah thanks, I didn't realize you were proposing for mainline merge - awesome. That would really be a useful merge...how close do you think that is?
I don't know when it will be merged, but I can comment on the status of our patches.
Ksplice has essentially two prerequisite changes:
- Changes to the module subsystem. Rusty Russell included versions of those patches in a recent patch series for the module system targeted at 2.6.30.
- Support for building the Linux kernel with -ffunction-sections -fdata-sections. Linus was asked about a week ago whether he would take the patch, but he has not responded yet.
As for the Ksplice core, Rusty Russell has started reading the code and has requested some changes to it to assist further review. We hope to send a new patch series with those changes made next week.
-Tim Abbott