From 3f2b9c9cdf389e303b2273679af08aab5f153517 Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Tue, 17 Sep 2013 05:48:51 +0930 Subject: module: remove rmmod --wait option. The option to wait for a module reference count to reach zero was in the initial module implementation, but it was never supported in modprobe (you had to use rmmod --wait). After discussion with Lucas, It has been deprecated (with a 10 second sleep) in kmod for the last year. This finally removes it: the flag will evoke a printk warning and a normal (non-blocking) remove attempt. Cc: Lucas De Marchi Signed-off-by: Rusty Russell --- include/linux/module.h | 3 --- kernel/module.c | 46 ++++++++-------------------------------------- 2 files changed, 8 insertions(+), 41 deletions(-) diff --git a/include/linux/module.h b/include/linux/module.h index 05f2447f8c1..15cd6b1b211 100644 --- a/include/linux/module.h +++ b/include/linux/module.h @@ -367,9 +367,6 @@ struct module /* What modules do I depend on? */ struct list_head target_list; - /* Who is waiting for us to be unloaded */ - struct task_struct *waiter; - /* Destruction function. */ void (*exit)(void); diff --git a/kernel/module.c b/kernel/module.c index dc582749fa1..947105fd4ca 100644 --- a/kernel/module.c +++ b/kernel/module.c @@ -644,8 +644,6 @@ static int module_unload_init(struct module *mod) /* Hold reference count during initialization. */ __this_cpu_write(mod->refptr->incs, 1); - /* Backwards compatibility macros put refcount during init. */ - mod->waiter = current; return 0; } @@ -771,16 +769,9 @@ static int __try_stop_module(void *_sref) static int try_stop_module(struct module *mod, int flags, int *forced) { - if (flags & O_NONBLOCK) { - struct stopref sref = { mod, flags, forced }; + struct stopref sref = { mod, flags, forced }; - return stop_machine(__try_stop_module, &sref, NULL); - } else { - /* We don't need to stop the machine for this. */ - mod->state = MODULE_STATE_GOING; - synchronize_sched(); - return 0; - } + return stop_machine(__try_stop_module, &sref, NULL); } unsigned long module_refcount(struct module *mod) @@ -813,21 +804,6 @@ EXPORT_SYMBOL(module_refcount); /* This exists whether we can unload or not */ static void free_module(struct module *mod); -static void wait_for_zero_refcount(struct module *mod) -{ - /* Since we might sleep for some time, release the mutex first */ - mutex_unlock(&module_mutex); - for (;;) { - pr_debug("Looking at refcount...\n"); - set_current_state(TASK_UNINTERRUPTIBLE); - if (module_refcount(mod) == 0) - break; - schedule(); - } - current->state = TASK_RUNNING; - mutex_lock(&module_mutex); -} - SYSCALL_DEFINE2(delete_module, const char __user *, name_user, unsigned int, flags) { @@ -842,6 +818,11 @@ SYSCALL_DEFINE2(delete_module, const char __user *, name_user, return -EFAULT; name[MODULE_NAME_LEN-1] = '\0'; + if (!(flags & O_NONBLOCK)) { + printk(KERN_WARNING + "waiting module removal not supported: please upgrade"); + } + if (mutex_lock_interruptible(&module_mutex) != 0) return -EINTR; @@ -859,8 +840,7 @@ SYSCALL_DEFINE2(delete_module, const char __user *, name_user, /* Doing init or already dying? */ if (mod->state != MODULE_STATE_LIVE) { - /* FIXME: if (force), slam module count and wake up - waiter --RR */ + /* FIXME: if (force), slam module count damn the torpedoes */ pr_debug("%s already dying\n", mod->name); ret = -EBUSY; goto out; @@ -876,18 +856,11 @@ SYSCALL_DEFINE2(delete_module, const char __user *, name_user, } } - /* Set this up before setting mod->state */ - mod->waiter = current; - /* Stop the machine so refcounts can't move and disable module. */ ret = try_stop_module(mod, flags, &forced); if (ret != 0) goto out; - /* Never wait if forced. */ - if (!forced && module_refcount(mod) != 0) - wait_for_zero_refcount(mod); - mutex_unlock(&module_mutex); /* Final destruction now no one is using it. */ if (mod->exit != NULL) @@ -1005,9 +978,6 @@ void module_put(struct module *module) __this_cpu_inc(module->refptr->decs); trace_module_put(module, _RET_IP_); - /* Maybe they're waiting for us to drop reference? */ - if (unlikely(!module_is_live(module))) - wake_up_process(module->waiter); preempt_enable(); } } -- cgit v1.2.3-18-g5258 From eed380f3f5933edb8f4c055ba34ae7908ed38565 Mon Sep 17 00:00:00 2001 From: Guenter Roeck Date: Mon, 23 Sep 2013 15:23:54 +0930 Subject: modpost: Optionally ignore secondary errors seen if a single module build fails Commit ea4054a23 (modpost: handle huge numbers of modules) added support for building a large number of modules. Unfortunately, the commit changed the semantics of the makefile: Instead of passing only existing object files to modpost, make now passes all expected object files. If make was started with option -i, this results in a modpost error if a single file failed to build. Example with the current btrfs build falure on m68k: fs/btrfs/btrfs.o: No such file or directory make[1]: [__modpost] Error 1 (ignored) This error is followed by lots of errors such as: m68k-linux-gcc: error: arch/m68k/emu/nfcon.mod.c: No such file or directory m68k-linux-gcc: fatal error: no input files compilation terminated. make[1]: [arch/m68k/emu/nfcon.mod.o] Error 1 (ignored) This doesn't matter much for normal builds, but it is annoying for builds started with "make -i" due to the large number of secondary errors. Those errors unnececessarily clog any error log and make it difficult to find the real errors in the build. Fix the problem by adding a new parameter '-n' to modpost. If this parameter is specified, modpost reports but ignores missing object files. With this patch, error output from above problem is (with make -i): m68k-linux-ld: cannot find fs/btrfs/ioctl.o: No such file or directory make[2]: [fs/btrfs/btrfs.o] Error 1 (ignored) ... fs/btrfs/btrfs.o: No such file or directory (ignored) Cc: Rusty Russell Cc: Michael Marek Signed-off-by: Guenter Roeck Signed-off-by: Rusty Russell --- scripts/Makefile.modpost | 4 +++- scripts/mod/modpost.c | 13 ++++++++++++- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/scripts/Makefile.modpost b/scripts/Makefile.modpost index 8dcdca27d83..69f0a1417e9 100644 --- a/scripts/Makefile.modpost +++ b/scripts/Makefile.modpost @@ -79,9 +79,11 @@ modpost = scripts/mod/modpost \ $(if $(CONFIG_DEBUG_SECTION_MISMATCH),,-S) \ $(if $(KBUILD_EXTMOD)$(KBUILD_MODPOST_WARN),-w) +MODPOST_OPT=$(subst -i,-n,$(filter -i,$(MAKEFLAGS))) + # We can go over command line length here, so be careful. quiet_cmd_modpost = MODPOST $(words $(filter-out vmlinux FORCE, $^)) modules - cmd_modpost = $(MODLISTCMD) | sed 's/\.ko$$/.o/' | $(modpost) -s -T - + cmd_modpost = $(MODLISTCMD) | sed 's/\.ko$$/.o/' | $(modpost) $(MODPOST_OPT) -s -T - PHONY += __modpost __modpost: $(modules:.ko=.o) FORCE diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c index 8247979e8f6..393706b3777 100644 --- a/scripts/mod/modpost.c +++ b/scripts/mod/modpost.c @@ -17,6 +17,7 @@ #include #include #include +#include #include "modpost.h" #include "../../include/generated/autoconf.h" #include "../../include/linux/license.h" @@ -37,6 +38,8 @@ static int warn_unresolved = 0; /* How a symbol is exported */ static int sec_mismatch_count = 0; static int sec_mismatch_verbose = 1; +/* ignore missing files */ +static int ignore_missing_files; enum export { export_plain, export_unused, export_gpl, @@ -407,6 +410,11 @@ static int parse_elf(struct elf_info *info, const char *filename) hdr = grab_file(filename, &info->size); if (!hdr) { + if (ignore_missing_files) { + fprintf(stderr, "%s: %s (ignored)\n", filename, + strerror(errno)); + return 0; + } perror(filename); exit(1); } @@ -2119,7 +2127,7 @@ int main(int argc, char **argv) struct ext_sym_list *extsym_iter; struct ext_sym_list *extsym_start = NULL; - while ((opt = getopt(argc, argv, "i:I:e:msST:o:awM:K:")) != -1) { + while ((opt = getopt(argc, argv, "i:I:e:mnsST:o:awM:K:")) != -1) { switch (opt) { case 'i': kernel_read = optarg; @@ -2139,6 +2147,9 @@ int main(int argc, char **argv) case 'm': modversions = 1; break; + case 'n': + ignore_missing_files = 1; + break; case 'o': dump_write = optarg; break; -- cgit v1.2.3-18-g5258 From eb3057df732c304622aee77c450761746939a2dc Mon Sep 17 00:00:00 2001 From: Frantisek Hrbata Date: Mon, 14 Oct 2013 18:08:46 +1030 Subject: kernel: add support for init_array constructors This adds the .init_array section as yet another section with constructors. This is needed because gcc could add __gcov_init calls to .init_array or .ctors section, depending on gcc (and binutils) version . v2: - reuse mod->ctors for .init_array section for modules, because gcc uses .ctors or .init_array, but not both at the same time v3: - fail to load if that does happen somehow. Signed-off-by: Frantisek Hrbata Signed-off-by: Rusty Russell --- include/asm-generic/vmlinux.lds.h | 1 + kernel/module.c | 20 ++++++++++++++++++-- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinux.lds.h index 83e2c31e8b0..bc2121fa913 100644 --- a/include/asm-generic/vmlinux.lds.h +++ b/include/asm-generic/vmlinux.lds.h @@ -473,6 +473,7 @@ #define KERNEL_CTORS() . = ALIGN(8); \ VMLINUX_SYMBOL(__ctors_start) = .; \ *(.ctors) \ + *(.init_array) \ VMLINUX_SYMBOL(__ctors_end) = .; #else #define KERNEL_CTORS() diff --git a/kernel/module.c b/kernel/module.c index 947105fd4ca..5c9cf84017d 100644 --- a/kernel/module.c +++ b/kernel/module.c @@ -2708,7 +2708,7 @@ static int check_modinfo(struct module *mod, struct load_info *info, int flags) return 0; } -static void find_module_sections(struct module *mod, struct load_info *info) +static int find_module_sections(struct module *mod, struct load_info *info) { mod->kp = section_objs(info, "__param", sizeof(*mod->kp), &mod->num_kp); @@ -2738,6 +2738,18 @@ static void find_module_sections(struct module *mod, struct load_info *info) #ifdef CONFIG_CONSTRUCTORS mod->ctors = section_objs(info, ".ctors", sizeof(*mod->ctors), &mod->num_ctors); + if (!mod->ctors) + mod->ctors = section_objs(info, ".init_array", + sizeof(*mod->ctors), &mod->num_ctors); + else if (find_sec(info, ".init_array")) { + /* + * This shouldn't happen with same compiler and binutils + * building all parts of the module. + */ + printk(KERN_WARNING "%s: has both .ctors and .init_array.\n", + mod->name); + return -EINVAL; + } #endif #ifdef CONFIG_TRACEPOINTS @@ -2776,6 +2788,8 @@ static void find_module_sections(struct module *mod, struct load_info *info) info->debug = section_objs(info, "__verbose", sizeof(*info->debug), &info->num_debug); + + return 0; } static int move_module(struct module *mod, struct load_info *info) @@ -3233,7 +3247,9 @@ static int load_module(struct load_info *info, const char __user *uargs, /* Now we've got everything in the final locations, we can * find optional sections. */ - find_module_sections(mod, info); + err = find_module_sections(mod, info); + if (err) + goto free_unload; err = check_module_license_and_versions(mod); if (err) -- cgit v1.2.3-18-g5258 From e0f244c63fc9d192dfd399cc2677bbdca61994b1 Mon Sep 17 00:00:00 2001 From: Andi Kleen Date: Wed, 23 Oct 2013 10:57:58 +1030 Subject: asmlinkage, module: Make ksymtab and kcrctab symbols and __this_module __visible Make the ksymtab symbols for EXPORT_SYMBOL visible. This prevents the LTO compiler from adding a .NUMBER prefix, which avoids various problems in later export processing. Cc: rusty@rustcorp.com.au Signed-off-by: Andi Kleen Signed-off-by: Rusty Russell --- include/linux/export.h | 4 ++-- scripts/mod/modpost.c | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/include/linux/export.h b/include/linux/export.h index 412cd509eff..3f2793d5189 100644 --- a/include/linux/export.h +++ b/include/linux/export.h @@ -43,7 +43,7 @@ extern struct module __this_module; /* Mark the CRC weak since genksyms apparently decides not to * generate a checksums for some symbols */ #define __CRC_SYMBOL(sym, sec) \ - extern void *__crc_##sym __attribute__((weak)); \ + extern __visible void *__crc_##sym __attribute__((weak)); \ static const unsigned long __kcrctab_##sym \ __used \ __attribute__((section("___kcrctab" sec "+" #sym), unused)) \ @@ -59,7 +59,7 @@ extern struct module __this_module; static const char __kstrtab_##sym[] \ __attribute__((section("__ksymtab_strings"), aligned(1))) \ = VMLINUX_SYMBOL_STR(sym); \ - static const struct kernel_symbol __ksymtab_##sym \ + __visible const struct kernel_symbol __ksymtab_##sym \ __used \ __attribute__((section("___ksymtab" sec "+" #sym), unused)) \ = { (unsigned long)&sym, __kstrtab_##sym } diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c index 393706b3777..9b873ac6ed7 100644 --- a/scripts/mod/modpost.c +++ b/scripts/mod/modpost.c @@ -1861,7 +1861,7 @@ static void add_header(struct buffer *b, struct module *mod) buf_printf(b, "\n"); buf_printf(b, "MODULE_INFO(vermagic, VERMAGIC_STRING);\n"); buf_printf(b, "\n"); - buf_printf(b, "struct module __this_module\n"); + buf_printf(b, "__visible struct module __this_module\n"); buf_printf(b, "__attribute__((section(\".gnu.linkonce.this_module\"))) = {\n"); buf_printf(b, "\t.name = KBUILD_MODNAME,\n"); if (mod->has_init) -- cgit v1.2.3-18-g5258 From 08746a65c2961b5765a66350823ff75ace63bfd1 Mon Sep 17 00:00:00 2001 From: Krzysztof Mazur Date: Thu, 31 Oct 2013 13:45:39 +1030 Subject: init: fix in-place parameter modification regression Before commit 026cee0086fe1df4cf74691cf273062cc769617d ("params: _initcall-like kernel parameters") the __setup parameter parsing code could modify parameter in the static_command_line buffer and such modifications were kept. After that commit such modifications are destroyed during per-initcall level parameter parsing because the same static_command_line buffer is used and only parameters for appropriate initcall level are parsed. That change broke at least parsing "ubd" parameter in the ubd driver when the COW file is used. Now the separate buffer is used for per-initcall parameter parsing. Signed-off-by: Krzysztof Mazur Signed-off-by: Rusty Russell --- init/main.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/init/main.c b/init/main.c index af310afbef2..1300a0dd320 100644 --- a/init/main.c +++ b/init/main.c @@ -131,6 +131,8 @@ char __initdata boot_command_line[COMMAND_LINE_SIZE]; char *saved_command_line; /* Command line for parameter parsing */ static char *static_command_line; +/* Command line for per-initcall parameter parsing */ +static char *initcall_command_line; static char *execute_command; static char *ramdisk_execute_command; @@ -347,6 +349,7 @@ static inline void smp_prepare_cpus(unsigned int maxcpus) { } static void __init setup_command_line(char *command_line) { saved_command_line = alloc_bootmem(strlen (boot_command_line)+1); + initcall_command_line = alloc_bootmem(strlen (boot_command_line)+1); static_command_line = alloc_bootmem(strlen (command_line)+1); strcpy (saved_command_line, boot_command_line); strcpy (static_command_line, command_line); @@ -744,9 +747,9 @@ static void __init do_initcall_level(int level) extern const struct kernel_param __start___param[], __stop___param[]; initcall_t *fn; - strcpy(static_command_line, saved_command_line); + strcpy(initcall_command_line, saved_command_line); parse_args(initcall_level_names[level], - static_command_line, __start___param, + initcall_command_line, __start___param, __stop___param - __start___param, level, level, &repair_env_string); -- cgit v1.2.3-18-g5258 From b6568b1a19ad995221d1816c4fcdd116d9c33e42 Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Thu, 7 Nov 2013 12:09:13 +1030 Subject: modpost: fix bogus 'exported twice' warnings. Andi's change in e0f244c63fc9 ("asmlinkage, module: Make ksymtab and kcrctab symbols and __this_module __visible") make the crc appear first in the symbol table. modpost creates an entry when it sees the CRC, then when it sees the actual symbol, it complains that it's seen it before. The preloaded flag already exists for the equivalent case where we loaded from Module.symvers, so use that. Reported-by: Stephen Rothwell Tested-by: The Awesome Power Of linux-next Signed-off-by: Rusty Russell --- scripts/mod/modpost.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c index 9b873ac6ed7..5c677a3e748 100644 --- a/scripts/mod/modpost.c +++ b/scripts/mod/modpost.c @@ -164,7 +164,7 @@ struct symbol { unsigned int vmlinux:1; /* 1 if symbol is defined in vmlinux */ unsigned int kernel:1; /* 1 if symbol is from kernel * (only for external modules) **/ - unsigned int preloaded:1; /* 1 if symbol from Module.symvers */ + unsigned int preloaded:1; /* 1 if symbol from Module.symvers, or crc */ enum export export; /* Type of export */ char name[0]; }; @@ -332,8 +332,11 @@ static void sym_update_crc(const char *name, struct module *mod, { struct symbol *s = find_symbol(name); - if (!s) + if (!s) { s = new_symbol(name, mod, export); + /* Don't complain when we find it later. */ + s->preloaded = 1; + } s->crc = crc; s->crc_valid = 1; } -- cgit v1.2.3-18-g5258