aboutsummaryrefslogtreecommitdiffstats
path: root/kernel/module.c
diff options
context:
space:
mode:
Diffstat (limited to 'kernel/module.c')
-rw-r--r--kernel/module.c53
1 files changed, 17 insertions, 36 deletions
diff --git a/kernel/module.c b/kernel/module.c
index 015d60cfd90e..539fed9ac83c 100644
--- a/kernel/module.c
+++ b/kernel/module.c
@@ -61,10 +61,8 @@ extern int module_sysfs_initialized;
61/* If this is set, the section belongs in the init part of the module */ 61/* If this is set, the section belongs in the init part of the module */
62#define INIT_OFFSET_MASK (1UL << (BITS_PER_LONG-1)) 62#define INIT_OFFSET_MASK (1UL << (BITS_PER_LONG-1))
63 63
64/* Protects module list */ 64/* List of modules, protected by module_mutex or preempt_disable
65static DEFINE_SPINLOCK(modlist_lock); 65 * (add/delete uses stop_machine). */
66
67/* List of modules, protected by module_mutex AND modlist_lock */
68static DEFINE_MUTEX(module_mutex); 66static DEFINE_MUTEX(module_mutex);
69static LIST_HEAD(modules); 67static LIST_HEAD(modules);
70 68
@@ -760,14 +758,13 @@ static void print_unload_info(struct seq_file *m, struct module *mod)
760void __symbol_put(const char *symbol) 758void __symbol_put(const char *symbol)
761{ 759{
762 struct module *owner; 760 struct module *owner;
763 unsigned long flags;
764 const unsigned long *crc; 761 const unsigned long *crc;
765 762
766 spin_lock_irqsave(&modlist_lock, flags); 763 preempt_disable();
767 if (!__find_symbol(symbol, &owner, &crc, 1)) 764 if (!__find_symbol(symbol, &owner, &crc, 1))
768 BUG(); 765 BUG();
769 module_put(owner); 766 module_put(owner);
770 spin_unlock_irqrestore(&modlist_lock, flags); 767 preempt_enable();
771} 768}
772EXPORT_SYMBOL(__symbol_put); 769EXPORT_SYMBOL(__symbol_put);
773 770
@@ -1228,14 +1225,14 @@ static void free_module(struct module *mod)
1228void *__symbol_get(const char *symbol) 1225void *__symbol_get(const char *symbol)
1229{ 1226{
1230 struct module *owner; 1227 struct module *owner;
1231 unsigned long value, flags; 1228 unsigned long value;
1232 const unsigned long *crc; 1229 const unsigned long *crc;
1233 1230
1234 spin_lock_irqsave(&modlist_lock, flags); 1231 preempt_disable();
1235 value = __find_symbol(symbol, &owner, &crc, 1); 1232 value = __find_symbol(symbol, &owner, &crc, 1);
1236 if (value && !strong_try_module_get(owner)) 1233 if (value && !strong_try_module_get(owner))
1237 value = 0; 1234 value = 0;
1238 spin_unlock_irqrestore(&modlist_lock, flags); 1235 preempt_enable();
1239 1236
1240 return (void *)value; 1237 return (void *)value;
1241} 1238}
@@ -2232,26 +2229,13 @@ unsigned long module_kallsyms_lookup_name(const char *name)
2232/* Called by the /proc file system to return a list of modules. */ 2229/* Called by the /proc file system to return a list of modules. */
2233static void *m_start(struct seq_file *m, loff_t *pos) 2230static void *m_start(struct seq_file *m, loff_t *pos)
2234{ 2231{
2235 struct list_head *i;
2236 loff_t n = 0;
2237
2238 mutex_lock(&module_mutex); 2232 mutex_lock(&module_mutex);
2239 list_for_each(i, &modules) { 2233 return seq_list_start(&modules, *pos);
2240 if (n++ == *pos)
2241 break;
2242 }
2243 if (i == &modules)
2244 return NULL;
2245 return i;
2246} 2234}
2247 2235
2248static void *m_next(struct seq_file *m, void *p, loff_t *pos) 2236static void *m_next(struct seq_file *m, void *p, loff_t *pos)
2249{ 2237{
2250 struct list_head *i = p; 2238 return seq_list_next(p, &modules, pos);
2251 (*pos)++;
2252 if (i->next == &modules)
2253 return NULL;
2254 return i->next;
2255} 2239}
2256 2240
2257static void m_stop(struct seq_file *m, void *p) 2241static void m_stop(struct seq_file *m, void *p)
@@ -2321,11 +2305,10 @@ const struct seq_operations modules_op = {
2321/* Given an address, look for it in the module exception tables. */ 2305/* Given an address, look for it in the module exception tables. */
2322const struct exception_table_entry *search_module_extables(unsigned long addr) 2306const struct exception_table_entry *search_module_extables(unsigned long addr)
2323{ 2307{
2324 unsigned long flags;
2325 const struct exception_table_entry *e = NULL; 2308 const struct exception_table_entry *e = NULL;
2326 struct module *mod; 2309 struct module *mod;
2327 2310
2328 spin_lock_irqsave(&modlist_lock, flags); 2311 preempt_disable();
2329 list_for_each_entry(mod, &modules, list) { 2312 list_for_each_entry(mod, &modules, list) {
2330 if (mod->num_exentries == 0) 2313 if (mod->num_exentries == 0)
2331 continue; 2314 continue;
@@ -2336,7 +2319,7 @@ const struct exception_table_entry *search_module_extables(unsigned long addr)
2336 if (e) 2319 if (e)
2337 break; 2320 break;
2338 } 2321 }
2339 spin_unlock_irqrestore(&modlist_lock, flags); 2322 preempt_enable();
2340 2323
2341 /* Now, if we found one, we are running inside it now, hence 2324 /* Now, if we found one, we are running inside it now, hence
2342 we cannot unload the module, hence no refcnt needed. */ 2325 we cannot unload the module, hence no refcnt needed. */
@@ -2348,25 +2331,24 @@ const struct exception_table_entry *search_module_extables(unsigned long addr)
2348 */ 2331 */
2349int is_module_address(unsigned long addr) 2332int is_module_address(unsigned long addr)
2350{ 2333{
2351 unsigned long flags;
2352 struct module *mod; 2334 struct module *mod;
2353 2335
2354 spin_lock_irqsave(&modlist_lock, flags); 2336 preempt_disable();
2355 2337
2356 list_for_each_entry(mod, &modules, list) { 2338 list_for_each_entry(mod, &modules, list) {
2357 if (within(addr, mod->module_core, mod->core_size)) { 2339 if (within(addr, mod->module_core, mod->core_size)) {
2358 spin_unlock_irqrestore(&modlist_lock, flags); 2340 preempt_enable();
2359 return 1; 2341 return 1;
2360 } 2342 }
2361 } 2343 }
2362 2344
2363 spin_unlock_irqrestore(&modlist_lock, flags); 2345 preempt_enable();
2364 2346
2365 return 0; 2347 return 0;
2366} 2348}
2367 2349
2368 2350
2369/* Is this a valid kernel address? We don't grab the lock: we are oopsing. */ 2351/* Is this a valid kernel address? */
2370struct module *__module_text_address(unsigned long addr) 2352struct module *__module_text_address(unsigned long addr)
2371{ 2353{
2372 struct module *mod; 2354 struct module *mod;
@@ -2381,11 +2363,10 @@ struct module *__module_text_address(unsigned long addr)
2381struct module *module_text_address(unsigned long addr) 2363struct module *module_text_address(unsigned long addr)
2382{ 2364{
2383 struct module *mod; 2365 struct module *mod;
2384 unsigned long flags;
2385 2366
2386 spin_lock_irqsave(&modlist_lock, flags); 2367 preempt_disable();
2387 mod = __module_text_address(addr); 2368 mod = __module_text_address(addr);
2388 spin_unlock_irqrestore(&modlist_lock, flags); 2369 preempt_enable();
2389 2370
2390 return mod; 2371 return mod;
2391} 2372}