Skip to contentSkip to conversation

module: Optimize search_module_extables()

PATCH Applied Peter Zijlstra 3 participants 3 messages Feb 8, 2017 – Feb 11, 2017

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 module: Optimize search_module_extables()

While looking through the __ex_table stuff I found that we do a linear lookup of the module. Also fix up a comment.

---
 kernel/module.c | 27 ++++++++++++++-------------
 1 file changed, 14 insertions(+), 13 deletions(-)
kernel/module.c +14 -13
index 3d8f126208e3..7bcdc35dbf95 100644
@@ -4165,22 +4165,23 @@ const struct exception_table_entry *search_module_extables(unsigned long addr)
 	struct module *mod;
 
 	preempt_disable();
-	list_for_each_entry_rcu(mod, &modules, list) {
-		if (mod->state == MODULE_STATE_UNFORMED)
-			continue;
-		if (mod->num_exentries == 0)
-			continue;
+	mod = __module_address(addr);
+	if (!mod)
+		goto out;
 
-		e = search_extable(mod->extable,
-				   mod->extable + mod->num_exentries - 1,
-				   addr);
-		if (e)
-			break;
-	}
+	if (!mod->num_exentries)
+		goto out;
+
+	e = search_extable(mod->extable,
+			   mod->extable + mod->num_exentries - 1,
+			   addr);
+out:
 	preempt_enable();
 
-	/* Now, if we found one, we are running inside it now, hence
-	   we cannot unload the module, hence no refcnt needed. */
+	/*
+	 * Now, if we found one, we are running inside it now, hence
+	 * we cannot unload the module, hence no refcnt needed.
+	 */
 	return e;
 }
 
Acked-by on v1 1/1
#1 lore raw
Quoted 5 lines · Peter Zijlstra

While looking through the __ex_table stuff I found that we do a linear lookup of the module. Also fix up a comment.

I'm not all that familiar with the module code, but from a quick scan of __module_address() this looks sane to me. FWIW:

Mark.

Quoted 45 lines
---
 kernel/module.c | 27 ++++++++++++++-------------
 1 file changed, 14 insertions(+), 13 deletions(-)
kernel/module.c +14 -13
index 3d8f126208e3..7bcdc35dbf95 100644
@@ -4165,22 +4165,23 @@ const struct exception_table_entry *search_module_extables(unsigned long addr)
 	struct module *mod;
 
 	preempt_disable();
-	list_for_each_entry_rcu(mod, &modules, list) {
-		if (mod->state == MODULE_STATE_UNFORMED)
-			continue;
-		if (mod->num_exentries == 0)
-			continue;
+	mod = __module_address(addr);
+	if (!mod)
+		goto out;
 
-		e = search_extable(mod->extable,
-				   mod->extable + mod->num_exentries - 1,
-				   addr);
-		if (e)
-			break;
-	}
+	if (!mod->num_exentries)
+		goto out;
+
+	e = search_extable(mod->extable,
+			   mod->extable + mod->num_exentries - 1,
+			   addr);
+out:
 	preempt_enable();
 
-	/* Now, if we found one, we are running inside it now, hence
-	   we cannot unload the module, hence no refcnt needed. */
+	/*
+	 * Now, if we found one, we are running inside it now, hence
+	 * we cannot unload the module, hence no refcnt needed.
+	 */
 	return e;
 }
 
Applied
#2 lore raw
In reply to Peter Zijlstra

+++ Peter Zijlstra [08/02/17 15:48 +0100]:

Quoted 5 lines

While looking through the __ex_table stuff I found that we do a linear lookup of the module. Also fix up a comment.

Applied, thanks.

Hm. A quick scan through module.c still shows a couple of places that use similar linear lookups, and may benefit from the same __module_address optimization. But I'll save that for a separate patch..

Jessica

Quoted 45 lines

---
kernel/module.c | 27 ++++++++++++++-------------

1 file changed, 14 insertions(+), 13 deletions(-)
kernel/module.c +14 -13
index 3d8f126208e3..7bcdc35dbf95 100644
@@ -4165,22 +4165,23 @@ const struct exception_table_entry *search_module_extables(unsigned long addr)
 	struct module *mod;
 
 	preempt_disable();
-	list_for_each_entry_rcu(mod, &modules, list) {
-		if (mod->state == MODULE_STATE_UNFORMED)
-			continue;
-		if (mod->num_exentries == 0)
-			continue;
+	mod = __module_address(addr);
+	if (!mod)
+		goto out;
 
-		e = search_extable(mod->extable,
-				   mod->extable + mod->num_exentries - 1,
-				   addr);
-		if (e)
-			break;
-	}
+	if (!mod->num_exentries)
+		goto out;
+
+	e = search_extable(mod->extable,
+			   mod->extable + mod->num_exentries - 1,
+			   addr);
+out:
 	preempt_enable();
 
-	/* Now, if we found one, we are running inside it now, hence
-	   we cannot unload the module, hence no refcnt needed. */
+	/*
+	 * Now, if we found one, we are running inside it now, hence
+	 * we cannot unload the module, hence no refcnt needed.
+	 */
 	return e;
 }