Commit 811d66a0e1e99902d365497eec7884113a2665bd
1 parent
6526c534b2
Exists in
master
and in
20 other branches
module: group post-relocation functions into post_relocation()
This simply hoists more code out of load_module; we also put the identification of the extable and dynamic debug table in with the others in find_module_sections(). We move the taint check to the actual add/remove of the dynamic debug info: this is certain (find_module_sections is too early). Signed-off-by: Rusty Russell <rusty@rustcorp.com.au> Cc: Yehuda Sadeh <yehuda@hq.newdream.net>
Showing 1 changed file with 32 additions and 24 deletions Side-by-side Diff
kernel/module.c
... | ... | @@ -117,6 +117,8 @@ |
117 | 117 | char *secstrings, *strtab; |
118 | 118 | unsigned long *strmap; |
119 | 119 | unsigned long symoffs, stroffs; |
120 | + struct _ddebug *debug; | |
121 | + unsigned int num_debug; | |
120 | 122 | struct { |
121 | 123 | unsigned int sym, str, mod, vers, info, pcpu; |
122 | 124 | } index; |
... | ... | @@ -1993,7 +1995,7 @@ |
1993 | 1995 | mod->core_size += bitmap_weight(info->strmap, strsect->sh_size); |
1994 | 1996 | } |
1995 | 1997 | |
1996 | -static void add_kallsyms(struct module *mod, struct load_info *info) | |
1998 | +static void add_kallsyms(struct module *mod, const struct load_info *info) | |
1997 | 1999 | { |
1998 | 2000 | unsigned int i, ndst; |
1999 | 2001 | const Elf_Sym *src; |
... | ... | @@ -2040,6 +2042,8 @@ |
2040 | 2042 | |
2041 | 2043 | static void dynamic_debug_setup(struct _ddebug *debug, unsigned int num) |
2042 | 2044 | { |
2045 | + if (!debug) | |
2046 | + return; | |
2043 | 2047 | #ifdef CONFIG_DYNAMIC_DEBUG |
2044 | 2048 | if (ddebug_add_module(debug, num, debug->modname)) |
2045 | 2049 | printk(KERN_ERR "dynamic debug error adding module: %s\n", |
... | ... | @@ -2267,8 +2271,7 @@ |
2267 | 2271 | return 0; |
2268 | 2272 | } |
2269 | 2273 | |
2270 | -static void find_module_sections(struct module *mod, | |
2271 | - const struct load_info *info) | |
2274 | +static void find_module_sections(struct module *mod, struct load_info *info) | |
2272 | 2275 | { |
2273 | 2276 | mod->kp = section_objs(info, "__param", |
2274 | 2277 | sizeof(*mod->kp), &mod->num_kp); |
2275 | 2278 | |
... | ... | @@ -2323,9 +2326,15 @@ |
2323 | 2326 | &mod->num_ftrace_callsites); |
2324 | 2327 | #endif |
2325 | 2328 | |
2329 | + mod->extable = section_objs(info, "__ex_table", | |
2330 | + sizeof(*mod->extable), &mod->num_exentries); | |
2331 | + | |
2326 | 2332 | if (section_addr(info, "__obsparm")) |
2327 | 2333 | printk(KERN_WARNING "%s: Ignoring obsolete parameters\n", |
2328 | 2334 | mod->name); |
2335 | + | |
2336 | + info->debug = section_objs(info, "__verbose", | |
2337 | + sizeof(*info->debug), &info->num_debug); | |
2329 | 2338 | } |
2330 | 2339 | |
2331 | 2340 | static int move_module(struct module *mod, struct load_info *info) |
... | ... | @@ -2512,6 +2521,20 @@ |
2512 | 2521 | module_free(mod, mod->module_core); |
2513 | 2522 | } |
2514 | 2523 | |
2524 | +static int post_relocation(struct module *mod, const struct load_info *info) | |
2525 | +{ | |
2526 | + sort_extable(mod->extable, mod->extable + mod->num_exentries); | |
2527 | + | |
2528 | + /* Copy relocated percpu area over. */ | |
2529 | + percpu_modcopy(mod, (void *)info->sechdrs[info->index.pcpu].sh_addr, | |
2530 | + info->sechdrs[info->index.pcpu].sh_size); | |
2531 | + | |
2532 | + add_kallsyms(mod, info); | |
2533 | + | |
2534 | + /* Arch-specific module finalizing. */ | |
2535 | + return module_finalize(info->hdr, info->sechdrs, mod); | |
2536 | +} | |
2537 | + | |
2515 | 2538 | /* Allocate and load the module: note that size of section 0 is always |
2516 | 2539 | zero, and we rely on this for optional sections. */ |
2517 | 2540 | static noinline struct module *load_module(void __user *umod, |
... | ... | @@ -2521,8 +2544,6 @@ |
2521 | 2544 | struct load_info info = { NULL, }; |
2522 | 2545 | struct module *mod; |
2523 | 2546 | long err; |
2524 | - struct _ddebug *debug = NULL; | |
2525 | - unsigned int num_debug = 0; | |
2526 | 2547 | |
2527 | 2548 | DEBUGP("load_module: umod=%p, len=%lu, uargs=%p\n", |
2528 | 2549 | umod, len, uargs); |
... | ... | @@ -2564,22 +2585,7 @@ |
2564 | 2585 | if (err < 0) |
2565 | 2586 | goto free_modinfo; |
2566 | 2587 | |
2567 | - /* Set up and sort exception table */ | |
2568 | - mod->extable = section_objs(&info, "__ex_table", | |
2569 | - sizeof(*mod->extable), &mod->num_exentries); | |
2570 | - sort_extable(mod->extable, mod->extable + mod->num_exentries); | |
2571 | - | |
2572 | - /* Finally, copy percpu area over. */ | |
2573 | - percpu_modcopy(mod, (void *)info.sechdrs[info.index.pcpu].sh_addr, | |
2574 | - info.sechdrs[info.index.pcpu].sh_size); | |
2575 | - | |
2576 | - add_kallsyms(mod, &info); | |
2577 | - | |
2578 | - if (!mod->taints) | |
2579 | - debug = section_objs(&info, "__verbose", | |
2580 | - sizeof(*debug), &num_debug); | |
2581 | - | |
2582 | - err = module_finalize(info.hdr, info.sechdrs, mod); | |
2588 | + err = post_relocation(mod, &info); | |
2583 | 2589 | if (err < 0) |
2584 | 2590 | goto free_modinfo; |
2585 | 2591 | |
... | ... | @@ -2607,8 +2613,9 @@ |
2607 | 2613 | goto unlock; |
2608 | 2614 | } |
2609 | 2615 | |
2610 | - if (debug) | |
2611 | - dynamic_debug_setup(debug, num_debug); | |
2616 | + /* This has to be done once we're sure module name is unique. */ | |
2617 | + if (!mod->taints) | |
2618 | + dynamic_debug_setup(info.debug, info.num_debug); | |
2612 | 2619 | |
2613 | 2620 | /* Find duplicate symbols */ |
2614 | 2621 | err = verify_export_symbols(mod); |
... | ... | @@ -2640,7 +2647,8 @@ |
2640 | 2647 | /* Unlink carefully: kallsyms could be walking list. */ |
2641 | 2648 | list_del_rcu(&mod->list); |
2642 | 2649 | ddebug: |
2643 | - dynamic_debug_remove(debug); | |
2650 | + if (!mod->taints) | |
2651 | + dynamic_debug_remove(info.debug); | |
2644 | 2652 | unlock: |
2645 | 2653 | mutex_unlock(&module_mutex); |
2646 | 2654 | synchronize_sched(); |