]> Git Repo - linux.git/commitdiff
module: use RCU to synchronize find_module
authorChristoph Hellwig <[email protected]>
Tue, 2 Feb 2021 12:13:25 +0000 (13:13 +0100)
committerJessica Yu <[email protected]>
Mon, 8 Feb 2021 11:21:40 +0000 (12:21 +0100)
Allow for a RCU-sched critical section around find_module, following
the lower level find_module_all helper, and switch the two callers
outside of module.c to use such a RCU-sched critical section instead
of module_mutex.

Reviewed-by: Petr Mladek <[email protected]>
Acked-by: Miroslav Benes <[email protected]>
Signed-off-by: Christoph Hellwig <[email protected]>
Signed-off-by: Jessica Yu <[email protected]>
include/linux/module.h
kernel/livepatch/core.c
kernel/module.c
kernel/trace/trace_kprobe.c

index 7a0bcb5b1ffccdd22e2a56a72b3e991db1d08aa4..a64aa84d1b182c26ba114a3cf3f57c070e65604b 100644 (file)
@@ -586,7 +586,7 @@ static inline bool within_module(unsigned long addr, const struct module *mod)
        return within_module_init(addr, mod) || within_module_core(addr, mod);
 }
 
-/* Search for module by name: must hold module_mutex. */
+/* Search for module by name: must be in a RCU-sched critical section. */
 struct module *find_module(const char *name);
 
 struct symsearch {
index f76fdb9255323d809d58495da99882a6710cd855..262cd9b003b9f06144a0333e25181b04bd0ccae5 100644 (file)
@@ -19,6 +19,7 @@
 #include <linux/moduleloader.h>
 #include <linux/completion.h>
 #include <linux/memory.h>
+#include <linux/rcupdate.h>
 #include <asm/cacheflush.h>
 #include "core.h"
 #include "patch.h"
@@ -57,7 +58,7 @@ static void klp_find_object_module(struct klp_object *obj)
        if (!klp_is_module(obj))
                return;
 
-       mutex_lock(&module_mutex);
+       rcu_read_lock_sched();
        /*
         * We do not want to block removal of patched modules and therefore
         * we do not take a reference here. The patches are removed by
@@ -74,7 +75,7 @@ static void klp_find_object_module(struct klp_object *obj)
        if (mod && mod->klp_alive)
                obj->mod = mod;
 
-       mutex_unlock(&module_mutex);
+       rcu_read_unlock_sched();
 }
 
 static bool klp_initialized(void)
index 8fb16e704b89df8ddb2d80a3c57ec37736f29986..63cc03393a07ba0e93cfcd0b82b62d0646898cd2 100644 (file)
@@ -668,7 +668,6 @@ static struct module *find_module_all(const char *name, size_t len,
 
 struct module *find_module(const char *name)
 {
-       module_assert_mutex();
        return find_module_all(name, strlen(name), false);
 }
 
index e6fba1798771b401eaf97d08b2c4d5926eb81995..3137992baa5e7a1aea6b195323328575053ccf56 100644 (file)
@@ -124,9 +124,9 @@ static nokprobe_inline bool trace_kprobe_module_exist(struct trace_kprobe *tk)
        if (!p)
                return true;
        *p = '\0';
-       mutex_lock(&module_mutex);
+       rcu_read_lock_sched();
        ret = !!find_module(tk->symbol);
-       mutex_unlock(&module_mutex);
+       rcu_read_unlock_sched();
        *p = ':';
 
        return ret;
This page took 0.105921 seconds and 4 git commands to generate.