Another idea for simplifying locking in kernel/module.c
Here is a way to replace all of the specialized "stop CPU"
locking code in kernel/module.c with an rw_semaphore by using down_read_trylock in try_module_get() and down_write when beginning to unload the module.
The following UNTESTED patch, a net deletion of 136 lines,
illustrates the basic idea. I've only verified that the resulting kernel/module.c compiles. I'm sorry that I can't test it right now as I'm in the midst of working on something else.
By the way, I think this change could also help eliminate themodule->state variable, which I believe currently can change while a reader could be trying to read it.
Adam J. Richter __ ______________ 575 Oroville Road [email protected] \ / Milpitas, California 95035 +1 408 309-6081 | g g d r a s i l United States of America
"Free Software For The Rest Of Us."
include/linux/module.h +6 -2
@@ -13,12 +13,13 @@#include <linux/stat.h> #include <linux/compiler.h> #include <linux/cache.h> #include <linux/kmod.h> #include <linux/elf.h> #include <linux/stringify.h> +#include <linux/rwsem.h> #include <asm/module.h> #include <asm/uaccess.h> /* For struct exception_table_entry */ /* Not Yet Implemented */ #define MODULE_LICENSE (name)
@@ -147,12 +148,14 @@struct mod_arch_specific arch;/* Am I unsafe to unload? */ int unsafe;#ifdef CONFIG_MODULE_UNLOAD +struct rw_semaphore unload_rwsem; +/* Reference counts */ struct module_ref ref[NR_CPUS ];/* What modules depend on me? */ struct list_head modules_which_use_me;
@@ -198,15 +201,16 @@static inline int try_module_get (struct module *module) {int ret =1 ;if (module) {unsigned int cpu =get_cpu (); -if (likely (module_is_live (module))) +if (down_read_trylock (&module->unload_rwsem)) {local_inc (&module->ref[cpu].count); -else +up_read (&module->unload_rwsem); + }else ret =0 ;put_cpu (); }return ret; }
kernel/module.c +19 -159
232 lines not on this page · raw message
In message <[email protected]> you write:
Quoted 4 lines
Here is a way to replace all of the specialized "stop CPU"
locking code inkernel/module.cwith anrw_semaphoreby usingdown_read_trylockintry_module_get()anddown_writewhen beginning to unload the module.
And now you can't modularize netfilter modules.
Rusty.
--
Anyone who quotes me in their sig is an idiot. -- Rusty Russell.