Commit a5c43dae authored by Alexey Dobriyan's avatar Alexey Dobriyan Committed by Linus Torvalds

Fix race between cat /proc/slab_allocators and rmmod

Same story as with cat /proc/*/wchan race vs rmmod race, only
/proc/slab_allocators want more info than just symbol name.
Signed-off-by: default avatarAlexey Dobriyan <adobriyan@sw.ru>
Acked-by: default avatarRusty Russell <rusty@rustcorp.com.au>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent 9d65cb4a
...@@ -31,6 +31,7 @@ extern int sprint_symbol(char *buffer, unsigned long address); ...@@ -31,6 +31,7 @@ extern int sprint_symbol(char *buffer, unsigned long address);
extern void __print_symbol(const char *fmt, unsigned long address); extern void __print_symbol(const char *fmt, unsigned long address);
int lookup_symbol_name(unsigned long addr, char *symname); int lookup_symbol_name(unsigned long addr, char *symname);
int lookup_symbol_attrs(unsigned long addr, unsigned long *size, unsigned long *offset, char *modname, char *name);
#else /* !CONFIG_KALLSYMS */ #else /* !CONFIG_KALLSYMS */
...@@ -65,6 +66,11 @@ static inline int lookup_symbol_name(unsigned long addr, char *symname) ...@@ -65,6 +66,11 @@ static inline int lookup_symbol_name(unsigned long addr, char *symname)
return -ERANGE; return -ERANGE;
} }
static inline int lookup_symbol_attrs(unsigned long addr, unsigned long *size, unsigned long *offset, char *modname, char *name)
{
return -ERANGE;
}
/* Stupid that this does nothing, but I didn't create this mess. */ /* Stupid that this does nothing, but I didn't create this mess. */
#define __print_symbol(fmt, addr) #define __print_symbol(fmt, addr)
#endif /*CONFIG_KALLSYMS*/ #endif /*CONFIG_KALLSYMS*/
......
...@@ -455,6 +455,7 @@ const char *module_address_lookup(unsigned long addr, ...@@ -455,6 +455,7 @@ const char *module_address_lookup(unsigned long addr,
unsigned long *offset, unsigned long *offset,
char **modname); char **modname);
int lookup_module_symbol_name(unsigned long addr, char *symname); int lookup_module_symbol_name(unsigned long addr, char *symname);
int lookup_module_symbol_attrs(unsigned long addr, unsigned long *size, unsigned long *offset, char *modname, char *name);
/* For extable.c to search modules' exception tables. */ /* For extable.c to search modules' exception tables. */
const struct exception_table_entry *search_module_extables(unsigned long addr); const struct exception_table_entry *search_module_extables(unsigned long addr);
...@@ -531,6 +532,11 @@ static inline int lookup_module_symbol_name(unsigned long addr, char *symname) ...@@ -531,6 +532,11 @@ static inline int lookup_module_symbol_name(unsigned long addr, char *symname)
return -ERANGE; return -ERANGE;
} }
static inline int lookup_module_symbol_attrs(unsigned long addr, unsigned long *size, unsigned long *offset, char *modname, char *name)
{
return -ERANGE;
}
static inline int module_get_kallsym(unsigned int symnum, unsigned long *value, static inline int module_get_kallsym(unsigned int symnum, unsigned long *value,
char *type, char *name, char *type, char *name,
char *module_name, int *exported) char *module_name, int *exported)
......
...@@ -286,6 +286,25 @@ int lookup_symbol_name(unsigned long addr, char *symname) ...@@ -286,6 +286,25 @@ int lookup_symbol_name(unsigned long addr, char *symname)
return lookup_module_symbol_name(addr, symname); return lookup_module_symbol_name(addr, symname);
} }
int lookup_symbol_attrs(unsigned long addr, unsigned long *size,
unsigned long *offset, char *modname, char *name)
{
name[0] = '\0';
name[KSYM_NAME_LEN] = '\0';
if (is_ksym_addr(addr)) {
unsigned long pos;
pos = get_symbol_pos(addr, size, offset);
/* Grab name */
kallsyms_expand_symbol(get_symbol_offset(pos), name);
modname[0] = '\0';
return 0;
}
/* see if it's in a module */
return lookup_module_symbol_attrs(addr, size, offset, modname, name);
}
/* Look up a kernel symbol and return it in a text buffer. */ /* Look up a kernel symbol and return it in a text buffer. */
int sprint_symbol(char *buffer, unsigned long address) int sprint_symbol(char *buffer, unsigned long address)
{ {
......
...@@ -2149,6 +2149,33 @@ out: ...@@ -2149,6 +2149,33 @@ out:
return -ERANGE; return -ERANGE;
} }
int lookup_module_symbol_attrs(unsigned long addr, unsigned long *size,
unsigned long *offset, char *modname, char *name)
{
struct module *mod;
mutex_lock(&module_mutex);
list_for_each_entry(mod, &modules, list) {
if (within(addr, mod->module_init, mod->init_size) ||
within(addr, mod->module_core, mod->core_size)) {
const char *sym;
sym = get_ksymbol(mod, addr, size, offset);
if (!sym)
goto out;
if (modname)
strlcpy(modname, mod->name, MODULE_NAME_LEN + 1);
if (name)
strlcpy(name, sym, KSYM_NAME_LEN + 1);
mutex_unlock(&module_mutex);
return 0;
}
}
out:
mutex_unlock(&module_mutex);
return -ERANGE;
}
int module_get_kallsym(unsigned int symnum, unsigned long *value, char *type, int module_get_kallsym(unsigned int symnum, unsigned long *value, char *type,
char *name, char *module_name, int *exported) char *name, char *module_name, int *exported)
{ {
......
...@@ -4432,16 +4432,12 @@ static void handle_slab(unsigned long *n, struct kmem_cache *c, struct slab *s) ...@@ -4432,16 +4432,12 @@ static void handle_slab(unsigned long *n, struct kmem_cache *c, struct slab *s)
static void show_symbol(struct seq_file *m, unsigned long address) static void show_symbol(struct seq_file *m, unsigned long address)
{ {
#ifdef CONFIG_KALLSYMS #ifdef CONFIG_KALLSYMS
char *modname;
const char *name;
unsigned long offset, size; unsigned long offset, size;
char namebuf[KSYM_NAME_LEN+1]; char modname[MODULE_NAME_LEN + 1], name[KSYM_NAME_LEN + 1];
name = kallsyms_lookup(address, &size, &offset, &modname, namebuf);
if (name) { if (lookup_symbol_attrs(address, &size, &offset, modname, name) == 0) {
seq_printf(m, "%s+%#lx/%#lx", name, offset, size); seq_printf(m, "%s+%#lx/%#lx", name, offset, size);
if (modname) if (modname[0])
seq_printf(m, " [%s]", modname); seq_printf(m, " [%s]", modname);
return; return;
} }
......
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