Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

Merge tag 'modules-next-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/rusty/linux

Pull module updates from Rusty Russell:
"Nothing interesting. Except the most embarrassing bugfix ever. But
let's ignore that"

* tag 'modules-next-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/rusty/linux:
module: cleanup call chain.
module: do percpu allocation after uniqueness check. No, really!
modules: don't fail to load on unknown parameters.
ABI: Clarify when /sys/module/MODULENAME is created
There is no /sys/parameters
module: don't modify argument of module_kallsyms_lookup_name()

+52 -39
+7 -3
Documentation/ABI/stable/sysfs-module
··· 4 4 5 5 /sys/module/MODULENAME 6 6 The name of the module that is in the kernel. This 7 - module name will show up either if the module is built 8 - directly into the kernel, or if it is loaded as a 9 - dynamic module. 7 + module name will always show up if the module is loaded as a 8 + dynamic module. If it is built directly into the kernel, it 9 + will only show up if it has a version or at least one 10 + parameter. 11 + 12 + Note: The conditions of creation in the built-in case are not 13 + by design and may be removed in the future. 10 14 11 15 /sys/module/MODULENAME/parameters 12 16 This directory contains individual files that are each
+1 -1
include/linux/moduleparam.h
··· 439 439 extern int param_set_copystring(const char *val, const struct kernel_param *); 440 440 extern int param_get_string(char *buffer, const struct kernel_param *kp); 441 441 442 - /* for exporting parameters in /sys/parameters */ 442 + /* for exporting parameters in /sys/module/.../parameters */ 443 443 444 444 struct module; 445 445
+43 -34
kernel/module.c
··· 455 455 EXPORT_SYMBOL_GPL(find_symbol); 456 456 457 457 /* Search for module by name: must hold module_mutex. */ 458 - static struct module *find_module_all(const char *name, 458 + static struct module *find_module_all(const char *name, size_t len, 459 459 bool even_unformed) 460 460 { 461 461 struct module *mod; ··· 463 463 list_for_each_entry(mod, &modules, list) { 464 464 if (!even_unformed && mod->state == MODULE_STATE_UNFORMED) 465 465 continue; 466 - if (strcmp(mod->name, name) == 0) 466 + if (strlen(mod->name) == len && !memcmp(mod->name, name, len)) 467 467 return mod; 468 468 } 469 469 return NULL; ··· 471 471 472 472 struct module *find_module(const char *name) 473 473 { 474 - return find_module_all(name, false); 474 + return find_module_all(name, strlen(name), false); 475 475 } 476 476 EXPORT_SYMBOL_GPL(find_module); 477 477 ··· 482 482 return mod->percpu; 483 483 } 484 484 485 - static int percpu_modalloc(struct module *mod, 486 - unsigned long size, unsigned long align) 485 + static int percpu_modalloc(struct module *mod, struct load_info *info) 487 486 { 487 + Elf_Shdr *pcpusec = &info->sechdrs[info->index.pcpu]; 488 + unsigned long align = pcpusec->sh_addralign; 489 + 490 + if (!pcpusec->sh_size) 491 + return 0; 492 + 488 493 if (align > PAGE_SIZE) { 489 494 printk(KERN_WARNING "%s: per-cpu alignment %li > %li\n", 490 495 mod->name, align, PAGE_SIZE); 491 496 align = PAGE_SIZE; 492 497 } 493 498 494 - mod->percpu = __alloc_reserved_percpu(size, align); 499 + mod->percpu = __alloc_reserved_percpu(pcpusec->sh_size, align); 495 500 if (!mod->percpu) { 496 501 printk(KERN_WARNING 497 502 "%s: Could not allocate %lu bytes percpu data\n", 498 - mod->name, size); 503 + mod->name, (unsigned long)pcpusec->sh_size); 499 504 return -ENOMEM; 500 505 } 501 - mod->percpu_size = size; 506 + mod->percpu_size = pcpusec->sh_size; 502 507 return 0; 503 508 } 504 509 ··· 568 563 { 569 564 return NULL; 570 565 } 571 - static inline int percpu_modalloc(struct module *mod, 572 - unsigned long size, unsigned long align) 566 + static int percpu_modalloc(struct module *mod, struct load_info *info) 573 567 { 574 - return -ENOMEM; 568 + /* UP modules shouldn't have this section: ENOMEM isn't quite right */ 569 + if (info->sechdrs[info->index.pcpu].sh_size != 0) 570 + return -ENOMEM; 571 + return 0; 575 572 } 576 573 static inline void percpu_modfree(struct module *mod) 577 574 { ··· 2934 2927 { 2935 2928 /* Module within temporary copy. */ 2936 2929 struct module *mod; 2937 - Elf_Shdr *pcpusec; 2938 2930 int err; 2939 2931 2940 2932 mod = setup_load_info(info, flags); ··· 2948 2942 err = module_frob_arch_sections(info->hdr, info->sechdrs, 2949 2943 info->secstrings, mod); 2950 2944 if (err < 0) 2951 - goto out; 2945 + return ERR_PTR(err); 2952 2946 2953 - pcpusec = &info->sechdrs[info->index.pcpu]; 2954 - if (pcpusec->sh_size) { 2955 - /* We have a special allocation for this section. */ 2956 - err = percpu_modalloc(mod, 2957 - pcpusec->sh_size, pcpusec->sh_addralign); 2958 - if (err) 2959 - goto out; 2960 - pcpusec->sh_flags &= ~(unsigned long)SHF_ALLOC; 2961 - } 2947 + /* We will do a special allocation for per-cpu sections later. */ 2948 + info->sechdrs[info->index.pcpu].sh_flags &= ~(unsigned long)SHF_ALLOC; 2962 2949 2963 2950 /* Determine total sizes, and put offsets in sh_entsize. For now 2964 2951 this is done generically; there doesn't appear to be any ··· 2962 2963 /* Allocate and move to the final place */ 2963 2964 err = move_module(mod, info); 2964 2965 if (err) 2965 - goto free_percpu; 2966 + return ERR_PTR(err); 2966 2967 2967 2968 /* Module has been copied to its final place now: return it. */ 2968 2969 mod = (void *)info->sechdrs[info->index.mod].sh_addr; 2969 2970 kmemleak_load_module(mod, info); 2970 2971 return mod; 2971 - 2972 - free_percpu: 2973 - percpu_modfree(mod); 2974 - out: 2975 - return ERR_PTR(err); 2976 2972 } 2977 2973 2978 2974 /* mod is no longer valid after this! */ ··· 3008 3014 bool ret; 3009 3015 3010 3016 mutex_lock(&module_mutex); 3011 - mod = find_module_all(name, true); 3017 + mod = find_module_all(name, strlen(name), true); 3012 3018 ret = !mod || mod->state == MODULE_STATE_LIVE 3013 3019 || mod->state == MODULE_STATE_GOING; 3014 3020 mutex_unlock(&module_mutex); ··· 3146 3152 3147 3153 again: 3148 3154 mutex_lock(&module_mutex); 3149 - if ((old = find_module_all(mod->name, true)) != NULL) { 3155 + old = find_module_all(mod->name, strlen(mod->name), true); 3156 + if (old != NULL) { 3150 3157 if (old->state == MODULE_STATE_COMING 3151 3158 || old->state == MODULE_STATE_UNFORMED) { 3152 3159 /* Wait in case it fails to load. */ ··· 3193 3198 return err; 3194 3199 } 3195 3200 3201 + static int unknown_module_param_cb(char *param, char *val, const char *modname) 3202 + { 3203 + /* Check for magic 'dyndbg' arg */ 3204 + int ret = ddebug_dyndbg_module_param_cb(param, val, modname); 3205 + if (ret != 0) { 3206 + printk(KERN_WARNING "%s: unknown parameter '%s' ignored\n", 3207 + modname, param); 3208 + } 3209 + return 0; 3210 + } 3211 + 3196 3212 /* Allocate and load the module: note that size of section 0 is always 3197 3213 zero, and we rely on this for optional sections. */ 3198 3214 static int load_module(struct load_info *info, const char __user *uargs, ··· 3242 3236 add_taint_module(mod, TAINT_FORCED_MODULE, LOCKDEP_STILL_OK); 3243 3237 } 3244 3238 #endif 3239 + 3240 + /* To avoid stressing percpu allocator, do this once we're unique. */ 3241 + err = percpu_modalloc(mod, info); 3242 + if (err) 3243 + goto unlink_mod; 3245 3244 3246 3245 /* Now module is in final location, initialize linked lists, etc. */ 3247 3246 err = module_unload_init(mod); ··· 3295 3284 3296 3285 /* Module is ready to execute: parsing args may do that. */ 3297 3286 err = parse_args(mod->name, mod->args, mod->kp, mod->num_kp, 3298 - -32768, 32767, &ddebug_dyndbg_module_param_cb); 3287 + -32768, 32767, unknown_module_param_cb); 3299 3288 if (err < 0) 3300 3289 goto bug_cleanup; 3301 3290 ··· 3574 3563 /* Don't lock: we're in enough trouble already. */ 3575 3564 preempt_disable(); 3576 3565 if ((colon = strchr(name, ':')) != NULL) { 3577 - *colon = '\0'; 3578 - if ((mod = find_module(name)) != NULL) 3566 + if ((mod = find_module_all(name, colon - name, false)) != NULL) 3579 3567 ret = mod_find_symname(mod, colon+1); 3580 - *colon = ':'; 3581 3568 } else { 3582 3569 list_for_each_entry_rcu(mod, &modules, list) { 3583 3570 if (mod->state == MODULE_STATE_UNFORMED)
+1 -1
kernel/params.c
··· 787 787 } 788 788 789 789 /* 790 - * param_sysfs_builtin - add contents in /sys/parameters for built-in modules 790 + * param_sysfs_builtin - add sysfs parameters for built-in modules 791 791 * 792 792 * Add module_parameters to sysfs for "modules" built into the kernel. 793 793 *