diff options
Diffstat (limited to 'kernel/module.c')
-rw-r--r-- | kernel/module.c | 184 |
1 files changed, 57 insertions, 127 deletions
diff --git a/kernel/module.c b/kernel/module.c index 91fe6958b6e1..1bb4c5e0d56e 100644 --- a/kernel/module.c +++ b/kernel/module.c | |||
@@ -47,8 +47,6 @@ | |||
47 | #include <asm/cacheflush.h> | 47 | #include <asm/cacheflush.h> |
48 | #include <linux/license.h> | 48 | #include <linux/license.h> |
49 | 49 | ||
50 | extern int module_sysfs_initialized; | ||
51 | |||
52 | #if 0 | 50 | #if 0 |
53 | #define DEBUGP printk | 51 | #define DEBUGP printk |
54 | #else | 52 | #else |
@@ -498,6 +496,8 @@ static struct module_attribute modinfo_##field = { \ | |||
498 | MODINFO_ATTR(version); | 496 | MODINFO_ATTR(version); |
499 | MODINFO_ATTR(srcversion); | 497 | MODINFO_ATTR(srcversion); |
500 | 498 | ||
499 | static char last_unloaded_module[MODULE_NAME_LEN+1]; | ||
500 | |||
501 | #ifdef CONFIG_MODULE_UNLOAD | 501 | #ifdef CONFIG_MODULE_UNLOAD |
502 | /* Init the unload section of the module. */ | 502 | /* Init the unload section of the module. */ |
503 | static void module_unload_init(struct module *mod) | 503 | static void module_unload_init(struct module *mod) |
@@ -721,6 +721,8 @@ sys_delete_module(const char __user *name_user, unsigned int flags) | |||
721 | mod->exit(); | 721 | mod->exit(); |
722 | mutex_lock(&module_mutex); | 722 | mutex_lock(&module_mutex); |
723 | } | 723 | } |
724 | /* Store the name of the last unloaded module for diagnostic purposes */ | ||
725 | sprintf(last_unloaded_module, mod->name); | ||
724 | free_module(mod); | 726 | free_module(mod); |
725 | 727 | ||
726 | out: | 728 | out: |
@@ -1122,7 +1124,7 @@ static void add_notes_attrs(struct module *mod, unsigned int nsect, | |||
1122 | ++loaded; | 1124 | ++loaded; |
1123 | } | 1125 | } |
1124 | 1126 | ||
1125 | notes_attrs->dir = kobject_add_dir(&mod->mkobj.kobj, "notes"); | 1127 | notes_attrs->dir = kobject_create_and_add("notes", &mod->mkobj.kobj); |
1126 | if (!notes_attrs->dir) | 1128 | if (!notes_attrs->dir) |
1127 | goto out; | 1129 | goto out; |
1128 | 1130 | ||
@@ -1219,15 +1221,16 @@ int mod_sysfs_init(struct module *mod) | |||
1219 | err = -EINVAL; | 1221 | err = -EINVAL; |
1220 | goto out; | 1222 | goto out; |
1221 | } | 1223 | } |
1222 | memset(&mod->mkobj.kobj, 0, sizeof(mod->mkobj.kobj)); | ||
1223 | err = kobject_set_name(&mod->mkobj.kobj, "%s", mod->name); | ||
1224 | if (err) | ||
1225 | goto out; | ||
1226 | kobj_set_kset_s(&mod->mkobj, module_subsys); | ||
1227 | mod->mkobj.mod = mod; | 1224 | mod->mkobj.mod = mod; |
1228 | 1225 | ||
1229 | kobject_init(&mod->mkobj.kobj); | 1226 | memset(&mod->mkobj.kobj, 0, sizeof(mod->mkobj.kobj)); |
1227 | mod->mkobj.kobj.kset = module_kset; | ||
1228 | err = kobject_init_and_add(&mod->mkobj.kobj, &module_ktype, NULL, | ||
1229 | "%s", mod->name); | ||
1230 | if (err) | ||
1231 | kobject_put(&mod->mkobj.kobj); | ||
1230 | 1232 | ||
1233 | /* delay uevent until full sysfs population */ | ||
1231 | out: | 1234 | out: |
1232 | return err; | 1235 | return err; |
1233 | } | 1236 | } |
@@ -1238,12 +1241,7 @@ int mod_sysfs_setup(struct module *mod, | |||
1238 | { | 1241 | { |
1239 | int err; | 1242 | int err; |
1240 | 1243 | ||
1241 | /* delay uevent until full sysfs population */ | 1244 | mod->holders_dir = kobject_create_and_add("holders", &mod->mkobj.kobj); |
1242 | err = kobject_add(&mod->mkobj.kobj); | ||
1243 | if (err) | ||
1244 | goto out; | ||
1245 | |||
1246 | mod->holders_dir = kobject_add_dir(&mod->mkobj.kobj, "holders"); | ||
1247 | if (!mod->holders_dir) { | 1245 | if (!mod->holders_dir) { |
1248 | err = -ENOMEM; | 1246 | err = -ENOMEM; |
1249 | goto out_unreg; | 1247 | goto out_unreg; |
@@ -1263,11 +1261,9 @@ int mod_sysfs_setup(struct module *mod, | |||
1263 | out_unreg_param: | 1261 | out_unreg_param: |
1264 | module_param_sysfs_remove(mod); | 1262 | module_param_sysfs_remove(mod); |
1265 | out_unreg_holders: | 1263 | out_unreg_holders: |
1266 | kobject_unregister(mod->holders_dir); | 1264 | kobject_put(mod->holders_dir); |
1267 | out_unreg: | 1265 | out_unreg: |
1268 | kobject_del(&mod->mkobj.kobj); | ||
1269 | kobject_put(&mod->mkobj.kobj); | 1266 | kobject_put(&mod->mkobj.kobj); |
1270 | out: | ||
1271 | return err; | 1267 | return err; |
1272 | } | 1268 | } |
1273 | #endif | 1269 | #endif |
@@ -1276,9 +1272,9 @@ static void mod_kobject_remove(struct module *mod) | |||
1276 | { | 1272 | { |
1277 | module_remove_modinfo_attrs(mod); | 1273 | module_remove_modinfo_attrs(mod); |
1278 | module_param_sysfs_remove(mod); | 1274 | module_param_sysfs_remove(mod); |
1279 | kobject_unregister(mod->mkobj.drivers_dir); | 1275 | kobject_put(mod->mkobj.drivers_dir); |
1280 | kobject_unregister(mod->holders_dir); | 1276 | kobject_put(mod->holders_dir); |
1281 | kobject_unregister(&mod->mkobj.kobj); | 1277 | kobject_put(&mod->mkobj.kobj); |
1282 | } | 1278 | } |
1283 | 1279 | ||
1284 | /* | 1280 | /* |
@@ -1884,10 +1880,10 @@ static struct module *load_module(void __user *umod, | |||
1884 | /* Now we've moved module, initialize linked lists, etc. */ | 1880 | /* Now we've moved module, initialize linked lists, etc. */ |
1885 | module_unload_init(mod); | 1881 | module_unload_init(mod); |
1886 | 1882 | ||
1887 | /* Initialize kobject, so we can reference it. */ | 1883 | /* add kobject, so we can reference it. */ |
1888 | err = mod_sysfs_init(mod); | 1884 | err = mod_sysfs_init(mod); |
1889 | if (err) | 1885 | if (err) |
1890 | goto cleanup; | 1886 | goto free_unload; |
1891 | 1887 | ||
1892 | /* Set up license info based on the info section */ | 1888 | /* Set up license info based on the info section */ |
1893 | set_license(mod, get_modinfo(sechdrs, infoindex, "license")); | 1889 | set_license(mod, get_modinfo(sechdrs, infoindex, "license")); |
@@ -2057,6 +2053,9 @@ static struct module *load_module(void __user *umod, | |||
2057 | arch_cleanup: | 2053 | arch_cleanup: |
2058 | module_arch_cleanup(mod); | 2054 | module_arch_cleanup(mod); |
2059 | cleanup: | 2055 | cleanup: |
2056 | kobject_del(&mod->mkobj.kobj); | ||
2057 | kobject_put(&mod->mkobj.kobj); | ||
2058 | free_unload: | ||
2060 | module_unload_free(mod); | 2059 | module_unload_free(mod); |
2061 | module_free(mod, mod->module_init); | 2060 | module_free(mod, mod->module_init); |
2062 | free_core: | 2061 | free_core: |
@@ -2214,29 +2213,34 @@ static const char *get_ksymbol(struct module *mod, | |||
2214 | /* For kallsyms to ask for address resolution. NULL means not found. | 2213 | /* For kallsyms to ask for address resolution. NULL means not found. |
2215 | We don't lock, as this is used for oops resolution and races are a | 2214 | We don't lock, as this is used for oops resolution and races are a |
2216 | lesser concern. */ | 2215 | lesser concern. */ |
2216 | /* FIXME: Risky: returns a pointer into a module w/o lock */ | ||
2217 | const char *module_address_lookup(unsigned long addr, | 2217 | const char *module_address_lookup(unsigned long addr, |
2218 | unsigned long *size, | 2218 | unsigned long *size, |
2219 | unsigned long *offset, | 2219 | unsigned long *offset, |
2220 | char **modname) | 2220 | char **modname) |
2221 | { | 2221 | { |
2222 | struct module *mod; | 2222 | struct module *mod; |
2223 | const char *ret = NULL; | ||
2223 | 2224 | ||
2225 | preempt_disable(); | ||
2224 | list_for_each_entry(mod, &modules, list) { | 2226 | list_for_each_entry(mod, &modules, list) { |
2225 | if (within(addr, mod->module_init, mod->init_size) | 2227 | if (within(addr, mod->module_init, mod->init_size) |
2226 | || within(addr, mod->module_core, mod->core_size)) { | 2228 | || within(addr, mod->module_core, mod->core_size)) { |
2227 | if (modname) | 2229 | if (modname) |
2228 | *modname = mod->name; | 2230 | *modname = mod->name; |
2229 | return get_ksymbol(mod, addr, size, offset); | 2231 | ret = get_ksymbol(mod, addr, size, offset); |
2232 | break; | ||
2230 | } | 2233 | } |
2231 | } | 2234 | } |
2232 | return NULL; | 2235 | preempt_enable(); |
2236 | return ret; | ||
2233 | } | 2237 | } |
2234 | 2238 | ||
2235 | int lookup_module_symbol_name(unsigned long addr, char *symname) | 2239 | int lookup_module_symbol_name(unsigned long addr, char *symname) |
2236 | { | 2240 | { |
2237 | struct module *mod; | 2241 | struct module *mod; |
2238 | 2242 | ||
2239 | mutex_lock(&module_mutex); | 2243 | preempt_disable(); |
2240 | list_for_each_entry(mod, &modules, list) { | 2244 | list_for_each_entry(mod, &modules, list) { |
2241 | if (within(addr, mod->module_init, mod->init_size) || | 2245 | if (within(addr, mod->module_init, mod->init_size) || |
2242 | within(addr, mod->module_core, mod->core_size)) { | 2246 | within(addr, mod->module_core, mod->core_size)) { |
@@ -2246,12 +2250,12 @@ int lookup_module_symbol_name(unsigned long addr, char *symname) | |||
2246 | if (!sym) | 2250 | if (!sym) |
2247 | goto out; | 2251 | goto out; |
2248 | strlcpy(symname, sym, KSYM_NAME_LEN); | 2252 | strlcpy(symname, sym, KSYM_NAME_LEN); |
2249 | mutex_unlock(&module_mutex); | 2253 | preempt_enable(); |
2250 | return 0; | 2254 | return 0; |
2251 | } | 2255 | } |
2252 | } | 2256 | } |
2253 | out: | 2257 | out: |
2254 | mutex_unlock(&module_mutex); | 2258 | preempt_enable(); |
2255 | return -ERANGE; | 2259 | return -ERANGE; |
2256 | } | 2260 | } |
2257 | 2261 | ||
@@ -2260,7 +2264,7 @@ int lookup_module_symbol_attrs(unsigned long addr, unsigned long *size, | |||
2260 | { | 2264 | { |
2261 | struct module *mod; | 2265 | struct module *mod; |
2262 | 2266 | ||
2263 | mutex_lock(&module_mutex); | 2267 | preempt_disable(); |
2264 | list_for_each_entry(mod, &modules, list) { | 2268 | list_for_each_entry(mod, &modules, list) { |
2265 | if (within(addr, mod->module_init, mod->init_size) || | 2269 | if (within(addr, mod->module_init, mod->init_size) || |
2266 | within(addr, mod->module_core, mod->core_size)) { | 2270 | within(addr, mod->module_core, mod->core_size)) { |
@@ -2273,12 +2277,12 @@ int lookup_module_symbol_attrs(unsigned long addr, unsigned long *size, | |||
2273 | strlcpy(modname, mod->name, MODULE_NAME_LEN); | 2277 | strlcpy(modname, mod->name, MODULE_NAME_LEN); |
2274 | if (name) | 2278 | if (name) |
2275 | strlcpy(name, sym, KSYM_NAME_LEN); | 2279 | strlcpy(name, sym, KSYM_NAME_LEN); |
2276 | mutex_unlock(&module_mutex); | 2280 | preempt_enable(); |
2277 | return 0; | 2281 | return 0; |
2278 | } | 2282 | } |
2279 | } | 2283 | } |
2280 | out: | 2284 | out: |
2281 | mutex_unlock(&module_mutex); | 2285 | preempt_enable(); |
2282 | return -ERANGE; | 2286 | return -ERANGE; |
2283 | } | 2287 | } |
2284 | 2288 | ||
@@ -2287,7 +2291,7 @@ int module_get_kallsym(unsigned int symnum, unsigned long *value, char *type, | |||
2287 | { | 2291 | { |
2288 | struct module *mod; | 2292 | struct module *mod; |
2289 | 2293 | ||
2290 | mutex_lock(&module_mutex); | 2294 | preempt_disable(); |
2291 | list_for_each_entry(mod, &modules, list) { | 2295 | list_for_each_entry(mod, &modules, list) { |
2292 | if (symnum < mod->num_symtab) { | 2296 | if (symnum < mod->num_symtab) { |
2293 | *value = mod->symtab[symnum].st_value; | 2297 | *value = mod->symtab[symnum].st_value; |
@@ -2296,12 +2300,12 @@ int module_get_kallsym(unsigned int symnum, unsigned long *value, char *type, | |||
2296 | KSYM_NAME_LEN); | 2300 | KSYM_NAME_LEN); |
2297 | strlcpy(module_name, mod->name, MODULE_NAME_LEN); | 2301 | strlcpy(module_name, mod->name, MODULE_NAME_LEN); |
2298 | *exported = is_exported(name, mod); | 2302 | *exported = is_exported(name, mod); |
2299 | mutex_unlock(&module_mutex); | 2303 | preempt_enable(); |
2300 | return 0; | 2304 | return 0; |
2301 | } | 2305 | } |
2302 | symnum -= mod->num_symtab; | 2306 | symnum -= mod->num_symtab; |
2303 | } | 2307 | } |
2304 | mutex_unlock(&module_mutex); | 2308 | preempt_enable(); |
2305 | return -ERANGE; | 2309 | return -ERANGE; |
2306 | } | 2310 | } |
2307 | 2311 | ||
@@ -2324,6 +2328,7 @@ unsigned long module_kallsyms_lookup_name(const char *name) | |||
2324 | unsigned long ret = 0; | 2328 | unsigned long ret = 0; |
2325 | 2329 | ||
2326 | /* Don't lock: we're in enough trouble already. */ | 2330 | /* Don't lock: we're in enough trouble already. */ |
2331 | preempt_disable(); | ||
2327 | if ((colon = strchr(name, ':')) != NULL) { | 2332 | if ((colon = strchr(name, ':')) != NULL) { |
2328 | *colon = '\0'; | 2333 | *colon = '\0'; |
2329 | if ((mod = find_module(name)) != NULL) | 2334 | if ((mod = find_module(name)) != NULL) |
@@ -2334,6 +2339,7 @@ unsigned long module_kallsyms_lookup_name(const char *name) | |||
2334 | if ((ret = mod_find_symname(mod, name)) != 0) | 2339 | if ((ret = mod_find_symname(mod, name)) != 0) |
2335 | break; | 2340 | break; |
2336 | } | 2341 | } |
2342 | preempt_enable(); | ||
2337 | return ret; | 2343 | return ret; |
2338 | } | 2344 | } |
2339 | #endif /* CONFIG_KALLSYMS */ | 2345 | #endif /* CONFIG_KALLSYMS */ |
@@ -2355,21 +2361,30 @@ static void m_stop(struct seq_file *m, void *p) | |||
2355 | mutex_unlock(&module_mutex); | 2361 | mutex_unlock(&module_mutex); |
2356 | } | 2362 | } |
2357 | 2363 | ||
2358 | static char *taint_flags(unsigned int taints, char *buf) | 2364 | static char *module_flags(struct module *mod, char *buf) |
2359 | { | 2365 | { |
2360 | int bx = 0; | 2366 | int bx = 0; |
2361 | 2367 | ||
2362 | if (taints) { | 2368 | if (mod->taints || |
2369 | mod->state == MODULE_STATE_GOING || | ||
2370 | mod->state == MODULE_STATE_COMING) { | ||
2363 | buf[bx++] = '('; | 2371 | buf[bx++] = '('; |
2364 | if (taints & TAINT_PROPRIETARY_MODULE) | 2372 | if (mod->taints & TAINT_PROPRIETARY_MODULE) |
2365 | buf[bx++] = 'P'; | 2373 | buf[bx++] = 'P'; |
2366 | if (taints & TAINT_FORCED_MODULE) | 2374 | if (mod->taints & TAINT_FORCED_MODULE) |
2367 | buf[bx++] = 'F'; | 2375 | buf[bx++] = 'F'; |
2368 | /* | 2376 | /* |
2369 | * TAINT_FORCED_RMMOD: could be added. | 2377 | * TAINT_FORCED_RMMOD: could be added. |
2370 | * TAINT_UNSAFE_SMP, TAINT_MACHINE_CHECK, TAINT_BAD_PAGE don't | 2378 | * TAINT_UNSAFE_SMP, TAINT_MACHINE_CHECK, TAINT_BAD_PAGE don't |
2371 | * apply to modules. | 2379 | * apply to modules. |
2372 | */ | 2380 | */ |
2381 | |||
2382 | /* Show a - for module-is-being-unloaded */ | ||
2383 | if (mod->state == MODULE_STATE_GOING) | ||
2384 | buf[bx++] = '-'; | ||
2385 | /* Show a + for module-is-being-loaded */ | ||
2386 | if (mod->state == MODULE_STATE_COMING) | ||
2387 | buf[bx++] = '+'; | ||
2373 | buf[bx++] = ')'; | 2388 | buf[bx++] = ')'; |
2374 | } | 2389 | } |
2375 | buf[bx] = '\0'; | 2390 | buf[bx] = '\0'; |
@@ -2396,7 +2411,7 @@ static int m_show(struct seq_file *m, void *p) | |||
2396 | 2411 | ||
2397 | /* Taints info */ | 2412 | /* Taints info */ |
2398 | if (mod->taints) | 2413 | if (mod->taints) |
2399 | seq_printf(m, " %s", taint_flags(mod->taints, buf)); | 2414 | seq_printf(m, " %s", module_flags(mod, buf)); |
2400 | 2415 | ||
2401 | seq_printf(m, "\n"); | 2416 | seq_printf(m, "\n"); |
2402 | return 0; | 2417 | return 0; |
@@ -2491,97 +2506,12 @@ void print_modules(void) | |||
2491 | 2506 | ||
2492 | printk("Modules linked in:"); | 2507 | printk("Modules linked in:"); |
2493 | list_for_each_entry(mod, &modules, list) | 2508 | list_for_each_entry(mod, &modules, list) |
2494 | printk(" %s%s", mod->name, taint_flags(mod->taints, buf)); | 2509 | printk(" %s%s", mod->name, module_flags(mod, buf)); |
2510 | if (last_unloaded_module[0]) | ||
2511 | printk(" [last unloaded: %s]", last_unloaded_module); | ||
2495 | printk("\n"); | 2512 | printk("\n"); |
2496 | } | 2513 | } |
2497 | 2514 | ||
2498 | #ifdef CONFIG_SYSFS | ||
2499 | static char *make_driver_name(struct device_driver *drv) | ||
2500 | { | ||
2501 | char *driver_name; | ||
2502 | |||
2503 | driver_name = kmalloc(strlen(drv->name) + strlen(drv->bus->name) + 2, | ||
2504 | GFP_KERNEL); | ||
2505 | if (!driver_name) | ||
2506 | return NULL; | ||
2507 | |||
2508 | sprintf(driver_name, "%s:%s", drv->bus->name, drv->name); | ||
2509 | return driver_name; | ||
2510 | } | ||
2511 | |||
2512 | static void module_create_drivers_dir(struct module_kobject *mk) | ||
2513 | { | ||
2514 | if (!mk || mk->drivers_dir) | ||
2515 | return; | ||
2516 | |||
2517 | mk->drivers_dir = kobject_add_dir(&mk->kobj, "drivers"); | ||
2518 | } | ||
2519 | |||
2520 | void module_add_driver(struct module *mod, struct device_driver *drv) | ||
2521 | { | ||
2522 | char *driver_name; | ||
2523 | int no_warn; | ||
2524 | struct module_kobject *mk = NULL; | ||
2525 | |||
2526 | if (!drv) | ||
2527 | return; | ||
2528 | |||
2529 | if (mod) | ||
2530 | mk = &mod->mkobj; | ||
2531 | else if (drv->mod_name) { | ||
2532 | struct kobject *mkobj; | ||
2533 | |||
2534 | /* Lookup built-in module entry in /sys/modules */ | ||
2535 | mkobj = kset_find_obj(&module_subsys, drv->mod_name); | ||
2536 | if (mkobj) { | ||
2537 | mk = container_of(mkobj, struct module_kobject, kobj); | ||
2538 | /* remember our module structure */ | ||
2539 | drv->mkobj = mk; | ||
2540 | /* kset_find_obj took a reference */ | ||
2541 | kobject_put(mkobj); | ||
2542 | } | ||
2543 | } | ||
2544 | |||
2545 | if (!mk) | ||
2546 | return; | ||
2547 | |||
2548 | /* Don't check return codes; these calls are idempotent */ | ||
2549 | no_warn = sysfs_create_link(&drv->kobj, &mk->kobj, "module"); | ||
2550 | driver_name = make_driver_name(drv); | ||
2551 | if (driver_name) { | ||
2552 | module_create_drivers_dir(mk); | ||
2553 | no_warn = sysfs_create_link(mk->drivers_dir, &drv->kobj, | ||
2554 | driver_name); | ||
2555 | kfree(driver_name); | ||
2556 | } | ||
2557 | } | ||
2558 | EXPORT_SYMBOL(module_add_driver); | ||
2559 | |||
2560 | void module_remove_driver(struct device_driver *drv) | ||
2561 | { | ||
2562 | struct module_kobject *mk = NULL; | ||
2563 | char *driver_name; | ||
2564 | |||
2565 | if (!drv) | ||
2566 | return; | ||
2567 | |||
2568 | sysfs_remove_link(&drv->kobj, "module"); | ||
2569 | |||
2570 | if (drv->owner) | ||
2571 | mk = &drv->owner->mkobj; | ||
2572 | else if (drv->mkobj) | ||
2573 | mk = drv->mkobj; | ||
2574 | if (mk && mk->drivers_dir) { | ||
2575 | driver_name = make_driver_name(drv); | ||
2576 | if (driver_name) { | ||
2577 | sysfs_remove_link(mk->drivers_dir, driver_name); | ||
2578 | kfree(driver_name); | ||
2579 | } | ||
2580 | } | ||
2581 | } | ||
2582 | EXPORT_SYMBOL(module_remove_driver); | ||
2583 | #endif | ||
2584 | |||
2585 | #ifdef CONFIG_MODVERSIONS | 2515 | #ifdef CONFIG_MODVERSIONS |
2586 | /* Generate the signature for struct module here, too, for modversions. */ | 2516 | /* Generate the signature for struct module here, too, for modversions. */ |
2587 | void struct_module(struct module *mod) { return; } | 2517 | void struct_module(struct module *mod) { return; } |