Skip to content

Commit ce6513f

Browse files
committed
Merge tag 'modules-next-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/rusty/linux
Pull module updates from Rusty Russell: "Mainly boring here, too. rmmod --wait finally removed, though" * tag 'modules-next-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/rusty/linux: modpost: fix bogus 'exported twice' warnings. init: fix in-place parameter modification regression asmlinkage, module: Make ksymtab and kcrctab symbols and __this_module __visible kernel: add support for init_array constructors modpost: Optionally ignore secondary errors seen if a single module build fails module: remove rmmod --wait option.
2 parents d8fe4ac + b6568b1 commit ce6513f

7 files changed

Lines changed: 55 additions & 52 deletions

File tree

include/asm-generic/vmlinux.lds.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -473,6 +473,7 @@
473473
#define KERNEL_CTORS() . = ALIGN(8); \
474474
VMLINUX_SYMBOL(__ctors_start) = .; \
475475
*(.ctors) \
476+
*(.init_array) \
476477
VMLINUX_SYMBOL(__ctors_end) = .;
477478
#else
478479
#define KERNEL_CTORS()

include/linux/export.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ extern struct module __this_module;
4343
/* Mark the CRC weak since genksyms apparently decides not to
4444
* generate a checksums for some symbols */
4545
#define __CRC_SYMBOL(sym, sec) \
46-
extern void *__crc_##sym __attribute__((weak)); \
46+
extern __visible void *__crc_##sym __attribute__((weak)); \
4747
static const unsigned long __kcrctab_##sym \
4848
__used \
4949
__attribute__((section("___kcrctab" sec "+" #sym), unused)) \
@@ -59,7 +59,7 @@ extern struct module __this_module;
5959
static const char __kstrtab_##sym[] \
6060
__attribute__((section("__ksymtab_strings"), aligned(1))) \
6161
= VMLINUX_SYMBOL_STR(sym); \
62-
static const struct kernel_symbol __ksymtab_##sym \
62+
__visible const struct kernel_symbol __ksymtab_##sym \
6363
__used \
6464
__attribute__((section("___ksymtab" sec "+" #sym), unused)) \
6565
= { (unsigned long)&sym, __kstrtab_##sym }

include/linux/module.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -367,9 +367,6 @@ struct module
367367
/* What modules do I depend on? */
368368
struct list_head target_list;
369369

370-
/* Who is waiting for us to be unloaded */
371-
struct task_struct *waiter;
372-
373370
/* Destruction function. */
374371
void (*exit)(void);
375372

init/main.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,8 @@ char __initdata boot_command_line[COMMAND_LINE_SIZE];
131131
char *saved_command_line;
132132
/* Command line for parameter parsing */
133133
static char *static_command_line;
134+
/* Command line for per-initcall parameter parsing */
135+
static char *initcall_command_line;
134136

135137
static char *execute_command;
136138
static char *ramdisk_execute_command;
@@ -354,6 +356,7 @@ static inline void smp_prepare_cpus(unsigned int maxcpus) { }
354356
static void __init setup_command_line(char *command_line)
355357
{
356358
saved_command_line = alloc_bootmem(strlen (boot_command_line)+1);
359+
initcall_command_line = alloc_bootmem(strlen (boot_command_line)+1);
357360
static_command_line = alloc_bootmem(strlen (command_line)+1);
358361
strcpy (saved_command_line, boot_command_line);
359362
strcpy (static_command_line, command_line);
@@ -751,9 +754,9 @@ static void __init do_initcall_level(int level)
751754
extern const struct kernel_param __start___param[], __stop___param[];
752755
initcall_t *fn;
753756

754-
strcpy(static_command_line, saved_command_line);
757+
strcpy(initcall_command_line, saved_command_line);
755758
parse_args(initcall_level_names[level],
756-
static_command_line, __start___param,
759+
initcall_command_line, __start___param,
757760
__stop___param - __start___param,
758761
level, level,
759762
&repair_env_string);

kernel/module.c

Lines changed: 26 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -641,8 +641,6 @@ static int module_unload_init(struct module *mod)
641641

642642
/* Hold reference count during initialization. */
643643
__this_cpu_write(mod->refptr->incs, 1);
644-
/* Backwards compatibility macros put refcount during init. */
645-
mod->waiter = current;
646644

647645
return 0;
648646
}
@@ -768,16 +766,9 @@ static int __try_stop_module(void *_sref)
768766

769767
static int try_stop_module(struct module *mod, int flags, int *forced)
770768
{
771-
if (flags & O_NONBLOCK) {
772-
struct stopref sref = { mod, flags, forced };
769+
struct stopref sref = { mod, flags, forced };
773770

774-
return stop_machine(__try_stop_module, &sref, NULL);
775-
} else {
776-
/* We don't need to stop the machine for this. */
777-
mod->state = MODULE_STATE_GOING;
778-
synchronize_sched();
779-
return 0;
780-
}
771+
return stop_machine(__try_stop_module, &sref, NULL);
781772
}
782773

783774
unsigned long module_refcount(struct module *mod)
@@ -810,21 +801,6 @@ EXPORT_SYMBOL(module_refcount);
810801
/* This exists whether we can unload or not */
811802
static void free_module(struct module *mod);
812803

813-
static void wait_for_zero_refcount(struct module *mod)
814-
{
815-
/* Since we might sleep for some time, release the mutex first */
816-
mutex_unlock(&module_mutex);
817-
for (;;) {
818-
pr_debug("Looking at refcount...\n");
819-
set_current_state(TASK_UNINTERRUPTIBLE);
820-
if (module_refcount(mod) == 0)
821-
break;
822-
schedule();
823-
}
824-
current->state = TASK_RUNNING;
825-
mutex_lock(&module_mutex);
826-
}
827-
828804
SYSCALL_DEFINE2(delete_module, const char __user *, name_user,
829805
unsigned int, flags)
830806
{
@@ -839,6 +815,11 @@ SYSCALL_DEFINE2(delete_module, const char __user *, name_user,
839815
return -EFAULT;
840816
name[MODULE_NAME_LEN-1] = '\0';
841817

818+
if (!(flags & O_NONBLOCK)) {
819+
printk(KERN_WARNING
820+
"waiting module removal not supported: please upgrade");
821+
}
822+
842823
if (mutex_lock_interruptible(&module_mutex) != 0)
843824
return -EINTR;
844825

@@ -856,8 +837,7 @@ SYSCALL_DEFINE2(delete_module, const char __user *, name_user,
856837

857838
/* Doing init or already dying? */
858839
if (mod->state != MODULE_STATE_LIVE) {
859-
/* FIXME: if (force), slam module count and wake up
860-
waiter --RR */
840+
/* FIXME: if (force), slam module count damn the torpedoes */
861841
pr_debug("%s already dying\n", mod->name);
862842
ret = -EBUSY;
863843
goto out;
@@ -873,18 +853,11 @@ SYSCALL_DEFINE2(delete_module, const char __user *, name_user,
873853
}
874854
}
875855

876-
/* Set this up before setting mod->state */
877-
mod->waiter = current;
878-
879856
/* Stop the machine so refcounts can't move and disable module. */
880857
ret = try_stop_module(mod, flags, &forced);
881858
if (ret != 0)
882859
goto out;
883860

884-
/* Never wait if forced. */
885-
if (!forced && module_refcount(mod) != 0)
886-
wait_for_zero_refcount(mod);
887-
888861
mutex_unlock(&module_mutex);
889862
/* Final destruction now no one is using it. */
890863
if (mod->exit != NULL)
@@ -1002,9 +975,6 @@ void module_put(struct module *module)
1002975
__this_cpu_inc(module->refptr->decs);
1003976

1004977
trace_module_put(module, _RET_IP_);
1005-
/* Maybe they're waiting for us to drop reference? */
1006-
if (unlikely(!module_is_live(module)))
1007-
wake_up_process(module->waiter);
1008978
preempt_enable();
1009979
}
1010980
}
@@ -2728,7 +2698,7 @@ static int check_modinfo(struct module *mod, struct load_info *info, int flags)
27282698
return 0;
27292699
}
27302700

2731-
static void find_module_sections(struct module *mod, struct load_info *info)
2701+
static int find_module_sections(struct module *mod, struct load_info *info)
27322702
{
27332703
mod->kp = section_objs(info, "__param",
27342704
sizeof(*mod->kp), &mod->num_kp);
@@ -2758,6 +2728,18 @@ static void find_module_sections(struct module *mod, struct load_info *info)
27582728
#ifdef CONFIG_CONSTRUCTORS
27592729
mod->ctors = section_objs(info, ".ctors",
27602730
sizeof(*mod->ctors), &mod->num_ctors);
2731+
if (!mod->ctors)
2732+
mod->ctors = section_objs(info, ".init_array",
2733+
sizeof(*mod->ctors), &mod->num_ctors);
2734+
else if (find_sec(info, ".init_array")) {
2735+
/*
2736+
* This shouldn't happen with same compiler and binutils
2737+
* building all parts of the module.
2738+
*/
2739+
printk(KERN_WARNING "%s: has both .ctors and .init_array.\n",
2740+
mod->name);
2741+
return -EINVAL;
2742+
}
27612743
#endif
27622744

27632745
#ifdef CONFIG_TRACEPOINTS
@@ -2795,6 +2777,8 @@ static void find_module_sections(struct module *mod, struct load_info *info)
27952777

27962778
info->debug = section_objs(info, "__verbose",
27972779
sizeof(*info->debug), &info->num_debug);
2780+
2781+
return 0;
27982782
}
27992783

28002784
static int move_module(struct module *mod, struct load_info *info)
@@ -3248,7 +3232,9 @@ static int load_module(struct load_info *info, const char __user *uargs,
32483232

32493233
/* Now we've got everything in the final locations, we can
32503234
* find optional sections. */
3251-
find_module_sections(mod, info);
3235+
err = find_module_sections(mod, info);
3236+
if (err)
3237+
goto free_unload;
32523238

32533239
err = check_module_license_and_versions(mod);
32543240
if (err)

scripts/Makefile.modpost

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,11 @@ modpost = scripts/mod/modpost \
7979
$(if $(CONFIG_DEBUG_SECTION_MISMATCH),,-S) \
8080
$(if $(KBUILD_EXTMOD)$(KBUILD_MODPOST_WARN),-w)
8181

82+
MODPOST_OPT=$(subst -i,-n,$(filter -i,$(MAKEFLAGS)))
83+
8284
# We can go over command line length here, so be careful.
8385
quiet_cmd_modpost = MODPOST $(words $(filter-out vmlinux FORCE, $^)) modules
84-
cmd_modpost = $(MODLISTCMD) | sed 's/\.ko$$/.o/' | $(modpost) -s -T -
86+
cmd_modpost = $(MODLISTCMD) | sed 's/\.ko$$/.o/' | $(modpost) $(MODPOST_OPT) -s -T -
8587

8688
PHONY += __modpost
8789
__modpost: $(modules:.ko=.o) FORCE

scripts/mod/modpost.c

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include <string.h>
1818
#include <limits.h>
1919
#include <stdbool.h>
20+
#include <errno.h>
2021
#include "modpost.h"
2122
#include "../../include/generated/autoconf.h"
2223
#include "../../include/linux/license.h"
@@ -37,6 +38,8 @@ static int warn_unresolved = 0;
3738
/* How a symbol is exported */
3839
static int sec_mismatch_count = 0;
3940
static int sec_mismatch_verbose = 1;
41+
/* ignore missing files */
42+
static int ignore_missing_files;
4043

4144
enum export {
4245
export_plain, export_unused, export_gpl,
@@ -161,7 +164,7 @@ struct symbol {
161164
unsigned int vmlinux:1; /* 1 if symbol is defined in vmlinux */
162165
unsigned int kernel:1; /* 1 if symbol is from kernel
163166
* (only for external modules) **/
164-
unsigned int preloaded:1; /* 1 if symbol from Module.symvers */
167+
unsigned int preloaded:1; /* 1 if symbol from Module.symvers, or crc */
165168
enum export export; /* Type of export */
166169
char name[0];
167170
};
@@ -329,8 +332,11 @@ static void sym_update_crc(const char *name, struct module *mod,
329332
{
330333
struct symbol *s = find_symbol(name);
331334

332-
if (!s)
335+
if (!s) {
333336
s = new_symbol(name, mod, export);
337+
/* Don't complain when we find it later. */
338+
s->preloaded = 1;
339+
}
334340
s->crc = crc;
335341
s->crc_valid = 1;
336342
}
@@ -407,6 +413,11 @@ static int parse_elf(struct elf_info *info, const char *filename)
407413

408414
hdr = grab_file(filename, &info->size);
409415
if (!hdr) {
416+
if (ignore_missing_files) {
417+
fprintf(stderr, "%s: %s (ignored)\n", filename,
418+
strerror(errno));
419+
return 0;
420+
}
410421
perror(filename);
411422
exit(1);
412423
}
@@ -1852,7 +1863,7 @@ static void add_header(struct buffer *b, struct module *mod)
18521863
buf_printf(b, "\n");
18531864
buf_printf(b, "MODULE_INFO(vermagic, VERMAGIC_STRING);\n");
18541865
buf_printf(b, "\n");
1855-
buf_printf(b, "struct module __this_module\n");
1866+
buf_printf(b, "__visible struct module __this_module\n");
18561867
buf_printf(b, "__attribute__((section(\".gnu.linkonce.this_module\"))) = {\n");
18571868
buf_printf(b, "\t.name = KBUILD_MODNAME,\n");
18581869
if (mod->has_init)
@@ -2118,7 +2129,7 @@ int main(int argc, char **argv)
21182129
struct ext_sym_list *extsym_iter;
21192130
struct ext_sym_list *extsym_start = NULL;
21202131

2121-
while ((opt = getopt(argc, argv, "i:I:e:msST:o:awM:K:")) != -1) {
2132+
while ((opt = getopt(argc, argv, "i:I:e:mnsST:o:awM:K:")) != -1) {
21222133
switch (opt) {
21232134
case 'i':
21242135
kernel_read = optarg;
@@ -2138,6 +2149,9 @@ int main(int argc, char **argv)
21382149
case 'm':
21392150
modversions = 1;
21402151
break;
2152+
case 'n':
2153+
ignore_missing_files = 1;
2154+
break;
21412155
case 'o':
21422156
dump_write = optarg;
21432157
break;

0 commit comments

Comments
 (0)