Re: PATCH: get_module_symbol() not SMP-safe

From: David Woodhouse (
Date: Tue May 09 2000 - 07:38:55 EST said:
> Callers of module services are already restricted, the module code
> expects them to be holding the big kernel lock. Anybody can call
> get_module_symbol() as long as they lock_kernel() first. You do not
> have to be in an init_module routine. OTOH, why would anybody look
> for module symbols anywhere except from init_module? You do the
> fixups once, when the module is loaded.

I could live with that, I suppose, as long as it's documented as such.

However, we do need a clean way to find the _correct_ module and increment
its use count. What 8390.hI currently does is fairly ugly, IMO.

I know how we could achieve that - why not just have get_module_symbol()
increase the use count for you? That way, people just _couldn't_ screw it

/me ducks :)

Index: kernel/module.c
RCS file: /cvs/linux/kernel/module.c,v
retrieving revision
diff -u -w -r1.2.2.7 module.c
--- kernel/module.c 2000/03/21 17:19:37
+++ kernel/module.c 2000/05/09 12:36:35
@@ -974,7 +974,17 @@
  * NULL, it looks for the name in any registered symbol table. If the
  * modname is an empty string, it looks for the symbol in kernel exported
  * symbol tables.
+ *
+ * NOTE: Unless you are holding the kernel lock, there's no guarantee
+ * that the module in which your symbol was found is still loaded by
+ * the time get_module_symbol() returns.
+ *
+ * You should be holding the kernel lock while calling this function,
+ * and must subsequently find the module and increase its use count,
+ * before doing anything which may sleep. Otherwise, the module may
+ * have disappeared by the time you dereference the symbol.
 unsigned long
 get_module_symbol(char *modname, char *symname)


- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to Please read the FAQ at

This archive was generated by hypermail 2b29 : Mon May 15 2000 - 21:00:13 EST