module interface improvement for kprobes
In-Reply-To: <[email protected]>
Quoted 5 lines · David Smith
Quoted 5 lines
Quoted 5 lines
I've added a new function,
module_get_byname(), that looks up a module by name and returns the module reference. Note thatmodule_get_byname()also increments the module reference count. It does this so that the module won't be unloaded between the time thatmodule_get_byname()is called andregister_kprobe()is called.
Your patch is word-wrapped.
Also:
Quoted 9 lines
kernel/module.c +3
-0@@ -291,7 +291,27 @@ static struct module *find_module(const }return NULL ; } + +int module_get_byname (const char *mod_name,struct module **mod) +{
kernel/module.c static struct module *find_module(const · line 306
Quoted 10 lines
kernel/module.c +9
-0+ *mod =NULL ; +/* We must hold module_mutex before calling find_module(). */ +if (mutex_lock_interruptible (&module_mutex) !=0 ) +return -EINTR ; + + *mod =find_module (mod_name); +mutex_unlock (&module_mutex); +if (*mod) { +if (!strong_try_module_get (*mod)) {
What keeps the module from going away between the mutex_unlock() and strong_try_module_get()? It needs to be something like this:
*mod = find_module(mod_name);
if (*mod)
ret = strong_try_module_get(*mod);
mutex_unlock(&module_mutex);
if (!ret) {
*mod = NULL;
return -EINVAL;
}Quoted 11 lines
kernel/module.c +8
-0+ *mod =NULL ; +return -EINVAL ; + } + } +return 0 ; +} +EXPORT_SYMBOL_GPL (module_get_byname); +#ifdef CONFIG_SMP /* Number of blocks used and allocated. */ static unsigned int pcpu_num_used, pcpu_num_allocated;
Signature · 1 line
Chuck