aboutsummaryrefslogtreecommitdiffstats
path: root/kernel/module.c
diff options
context:
space:
mode:
Diffstat (limited to 'kernel/module.c')
-rw-r--r--kernel/module.c65
1 files changed, 41 insertions, 24 deletions
diff --git a/kernel/module.c b/kernel/module.c
index e2564580f3f1..625985e70e9d 100644
--- a/kernel/module.c
+++ b/kernel/module.c
@@ -77,6 +77,10 @@
77DEFINE_MUTEX(module_mutex); 77DEFINE_MUTEX(module_mutex);
78EXPORT_SYMBOL_GPL(module_mutex); 78EXPORT_SYMBOL_GPL(module_mutex);
79static LIST_HEAD(modules); 79static LIST_HEAD(modules);
80#ifdef CONFIG_KGDB_KDB
81struct list_head *kdb_modules = &modules; /* kdb needs the list of modules */
82#endif /* CONFIG_KGDB_KDB */
83
80 84
81/* Block module loading/unloading? */ 85/* Block module loading/unloading? */
82int modules_disabled = 0; 86int modules_disabled = 0;
@@ -176,8 +180,6 @@ extern const struct kernel_symbol __start___ksymtab_gpl[];
176extern const struct kernel_symbol __stop___ksymtab_gpl[]; 180extern const struct kernel_symbol __stop___ksymtab_gpl[];
177extern const struct kernel_symbol __start___ksymtab_gpl_future[]; 181extern const struct kernel_symbol __start___ksymtab_gpl_future[];
178extern const struct kernel_symbol __stop___ksymtab_gpl_future[]; 182extern const struct kernel_symbol __stop___ksymtab_gpl_future[];
179extern const struct kernel_symbol __start___ksymtab_gpl_future[];
180extern const struct kernel_symbol __stop___ksymtab_gpl_future[];
181extern const unsigned long __start___kcrctab[]; 183extern const unsigned long __start___kcrctab[];
182extern const unsigned long __start___kcrctab_gpl[]; 184extern const unsigned long __start___kcrctab_gpl[];
183extern const unsigned long __start___kcrctab_gpl_future[]; 185extern const unsigned long __start___kcrctab_gpl_future[];
@@ -561,33 +563,26 @@ int use_module(struct module *a, struct module *b)
561 struct module_use *use; 563 struct module_use *use;
562 int no_warn, err; 564 int no_warn, err;
563 565
564 if (b == NULL || already_uses(a, b)) return 1; 566 if (b == NULL || already_uses(a, b))
565
566 /* If we're interrupted or time out, we fail. */
567 if (wait_event_interruptible_timeout(
568 module_wq, (err = strong_try_module_get(b)) != -EBUSY,
569 30 * HZ) <= 0) {
570 printk("%s: gave up waiting for init of module %s.\n",
571 a->name, b->name);
572 return 0; 567 return 0;
573 }
574 568
575 /* If strong_try_module_get() returned a different error, we fail. */ 569 /* If we're interrupted or time out, we fail. */
570 err = strong_try_module_get(b);
576 if (err) 571 if (err)
577 return 0; 572 return err;
578 573
579 DEBUGP("Allocating new usage for %s.\n", a->name); 574 DEBUGP("Allocating new usage for %s.\n", a->name);
580 use = kmalloc(sizeof(*use), GFP_ATOMIC); 575 use = kmalloc(sizeof(*use), GFP_ATOMIC);
581 if (!use) { 576 if (!use) {
582 printk("%s: out of memory loading\n", a->name); 577 printk("%s: out of memory loading\n", a->name);
583 module_put(b); 578 module_put(b);
584 return 0; 579 return -ENOMEM;
585 } 580 }
586 581
587 use->module_which_uses = a; 582 use->module_which_uses = a;
588 list_add(&use->list, &b->modules_which_use_me); 583 list_add(&use->list, &b->modules_which_use_me);
589 no_warn = sysfs_create_link(b->holders_dir, &a->mkobj.kobj, a->name); 584 no_warn = sysfs_create_link(b->holders_dir, &a->mkobj.kobj, a->name);
590 return 1; 585 return 0;
591} 586}
592EXPORT_SYMBOL_GPL(use_module); 587EXPORT_SYMBOL_GPL(use_module);
593 588
@@ -880,7 +875,7 @@ static inline void module_unload_free(struct module *mod)
880 875
881int use_module(struct module *a, struct module *b) 876int use_module(struct module *a, struct module *b)
882{ 877{
883 return strong_try_module_get(b) == 0; 878 return strong_try_module_get(b);
884} 879}
885EXPORT_SYMBOL_GPL(use_module); 880EXPORT_SYMBOL_GPL(use_module);
886 881
@@ -1051,17 +1046,39 @@ static const struct kernel_symbol *resolve_symbol(Elf_Shdr *sechdrs,
1051 struct module *owner; 1046 struct module *owner;
1052 const struct kernel_symbol *sym; 1047 const struct kernel_symbol *sym;
1053 const unsigned long *crc; 1048 const unsigned long *crc;
1049 DEFINE_WAIT(wait);
1050 int err;
1051 long timeleft = 30 * HZ;
1054 1052
1053again:
1055 sym = find_symbol(name, &owner, &crc, 1054 sym = find_symbol(name, &owner, &crc,
1056 !(mod->taints & (1 << TAINT_PROPRIETARY_MODULE)), true); 1055 !(mod->taints & (1 << TAINT_PROPRIETARY_MODULE)), true);
1057 /* use_module can fail due to OOM, 1056 if (!sym)
1058 or module initialization or unloading */ 1057 return NULL;
1059 if (sym) { 1058
1060 if (!check_version(sechdrs, versindex, name, mod, crc, owner) 1059 if (!check_version(sechdrs, versindex, name, mod, crc, owner))
1061 || !use_module(mod, owner)) 1060 return NULL;
1062 sym = NULL; 1061
1062 prepare_to_wait(&module_wq, &wait, TASK_INTERRUPTIBLE);
1063 err = use_module(mod, owner);
1064 if (likely(!err) || err != -EBUSY || signal_pending(current)) {
1065 finish_wait(&module_wq, &wait);
1066 return err ? NULL : sym;
1063 } 1067 }
1064 return sym; 1068
1069 /* Module is still loading. Drop lock and wait. */
1070 mutex_unlock(&module_mutex);
1071 timeleft = schedule_timeout(timeleft);
1072 mutex_lock(&module_mutex);
1073 finish_wait(&module_wq, &wait);
1074
1075 /* Module might be gone entirely, or replaced. Re-lookup. */
1076 if (timeleft)
1077 goto again;
1078
1079 printk(KERN_WARNING "%s: gave up waiting for init of module %s.\n",
1080 mod->name, owner->name);
1081 return NULL;
1065} 1082}
1066 1083
1067/* 1084/*
@@ -1182,7 +1199,7 @@ struct module_notes_attrs {
1182 struct bin_attribute attrs[0]; 1199 struct bin_attribute attrs[0];
1183}; 1200};
1184 1201
1185static ssize_t module_notes_read(struct kobject *kobj, 1202static ssize_t module_notes_read(struct file *filp, struct kobject *kobj,
1186 struct bin_attribute *bin_attr, 1203 struct bin_attribute *bin_attr,
1187 char *buf, loff_t pos, size_t count) 1204 char *buf, loff_t pos, size_t count)
1188{ 1205{