Commit a0060505 authored by Christoph Hellwig's avatar Christoph Hellwig Committed by Jessica Yu
Browse files

module: use RCU to synchronize find_module



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: default avatarPetr Mladek <pmladek@suse.com>
Acked-by: default avatarMiroslav Benes <mbenes@suse.cz>
Signed-off-by: default avatarChristoph Hellwig <hch@lst.de>
Signed-off-by: default avatarJessica Yu <jeyu@kernel.org>
parent 089049f6
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -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 {
+3 −2
Original line number Diff line number Diff line
@@ -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)
+0 −1
Original line number Diff line number Diff line
@@ -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);
}

+2 −2
Original line number Diff line number Diff line
@@ -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;