module: Optimize search_module_extables()
authorPeter Zijlstra <peterz@infradead.org>
Wed, 8 Feb 2017 14:48:01 +0000 (15:48 +0100)
committerJessica Yu <jeyu@redhat.com>
Sat, 11 Feb 2017 03:21:10 +0000 (19:21 -0800)
While looking through the __ex_table stuff I found that we do a linear
lookup of the module. Also fix up a comment.

Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Acked-by: Mark Rutland <mark.rutland@arm.com>
Signed-off-by: Jessica Yu <jeyu@redhat.com>
kernel/module.c

index 330f64e7e1936e1c693f828627a8417e6c1d391a..32d0d32abbf6f8cf50504c1380798209696fdd42 100644 (file)
@@ -4170,22 +4170,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;
 }