aboutsummaryrefslogtreecommitdiffstats
path: root/kernel/module.c
diff options
context:
space:
mode:
authorGrant Likely <grant.likely@secretlab.ca>2010-05-22 02:36:56 -0400
committerGrant Likely <grant.likely@secretlab.ca>2010-05-22 02:36:56 -0400
commitcf9b59e9d3e008591d1f54830f570982bb307a0d (patch)
tree113478ce8fd8c832ba726ffdf59b82cb46356476 /kernel/module.c
parent44504b2bebf8b5823c59484e73096a7d6574471d (diff)
parentf4b87dee923342505e1ddba8d34ce9de33e75050 (diff)
Merge remote branch 'origin' into secretlab/next-devicetree
Merging in current state of Linus' tree to deal with merge conflicts and build failures in vio.c after merge. Conflicts: drivers/i2c/busses/i2c-cpm.c drivers/i2c/busses/i2c-mpc.c drivers/net/gianfar.c Also fixed up one line in arch/powerpc/kernel/vio.c to use the correct node pointer. Signed-off-by: Grant Likely <grant.likely@secretlab.ca>
Diffstat (limited to 'kernel/module.c')
-rw-r--r--kernel/module.c85
1 files changed, 47 insertions, 38 deletions
diff --git a/kernel/module.c b/kernel/module.c
index 1016b75b026a..a8014bfb5a4e 100644
--- a/kernel/module.c
+++ b/kernel/module.c
@@ -59,8 +59,6 @@
59#define CREATE_TRACE_POINTS 59#define CREATE_TRACE_POINTS
60#include <trace/events/module.h> 60#include <trace/events/module.h>
61 61
62EXPORT_TRACEPOINT_SYMBOL(module_get);
63
64#if 0 62#if 0
65#define DEBUGP printk 63#define DEBUGP printk
66#else 64#else
@@ -79,6 +77,10 @@ EXPORT_TRACEPOINT_SYMBOL(module_get);
79DEFINE_MUTEX(module_mutex); 77DEFINE_MUTEX(module_mutex);
80EXPORT_SYMBOL_GPL(module_mutex); 78EXPORT_SYMBOL_GPL(module_mutex);
81static 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
82 84
83/* Block module loading/unloading? */ 85/* Block module loading/unloading? */
84int modules_disabled = 0; 86int modules_disabled = 0;
@@ -515,6 +517,9 @@ MODINFO_ATTR(srcversion);
515static char last_unloaded_module[MODULE_NAME_LEN+1]; 517static char last_unloaded_module[MODULE_NAME_LEN+1];
516 518
517#ifdef CONFIG_MODULE_UNLOAD 519#ifdef CONFIG_MODULE_UNLOAD
520
521EXPORT_TRACEPOINT_SYMBOL(module_get);
522
518/* Init the unload section of the module. */ 523/* Init the unload section of the module. */
519static void module_unload_init(struct module *mod) 524static void module_unload_init(struct module *mod)
520{ 525{
@@ -560,33 +565,26 @@ int use_module(struct module *a, struct module *b)
560 struct module_use *use; 565 struct module_use *use;
561 int no_warn, err; 566 int no_warn, err;
562 567
563 if (b == NULL || already_uses(a, b)) return 1; 568 if (b == NULL || already_uses(a, b))
564
565 /* If we're interrupted or time out, we fail. */
566 if (wait_event_interruptible_timeout(
567 module_wq, (err = strong_try_module_get(b)) != -EBUSY,
568 30 * HZ) <= 0) {
569 printk("%s: gave up waiting for init of module %s.\n",
570 a->name, b->name);
571 return 0; 569 return 0;
572 }
573 570
574 /* If strong_try_module_get() returned a different error, we fail. */ 571 /* If we're interrupted or time out, we fail. */
572 err = strong_try_module_get(b);
575 if (err) 573 if (err)
576 return 0; 574 return err;
577 575
578 DEBUGP("Allocating new usage for %s.\n", a->name); 576 DEBUGP("Allocating new usage for %s.\n", a->name);
579 use = kmalloc(sizeof(*use), GFP_ATOMIC); 577 use = kmalloc(sizeof(*use), GFP_ATOMIC);
580 if (!use) { 578 if (!use) {
581 printk("%s: out of memory loading\n", a->name); 579 printk("%s: out of memory loading\n", a->name);
582 module_put(b); 580 module_put(b);
583 return 0; 581 return -ENOMEM;
584 } 582 }
585 583
586 use->module_which_uses = a; 584 use->module_which_uses = a;
587 list_add(&use->list, &b->modules_which_use_me); 585 list_add(&use->list, &b->modules_which_use_me);
588 no_warn = sysfs_create_link(b->holders_dir, &a->mkobj.kobj, a->name); 586 no_warn = sysfs_create_link(b->holders_dir, &a->mkobj.kobj, a->name);
589 return 1; 587 return 0;
590} 588}
591EXPORT_SYMBOL_GPL(use_module); 589EXPORT_SYMBOL_GPL(use_module);
592 590
@@ -723,16 +721,8 @@ SYSCALL_DEFINE2(delete_module, const char __user *, name_user,
723 return -EFAULT; 721 return -EFAULT;
724 name[MODULE_NAME_LEN-1] = '\0'; 722 name[MODULE_NAME_LEN-1] = '\0';
725 723
726 /* Create stop_machine threads since free_module relies on 724 if (mutex_lock_interruptible(&module_mutex) != 0)
727 * a non-failing stop_machine call. */ 725 return -EINTR;
728 ret = stop_machine_create();
729 if (ret)
730 return ret;
731
732 if (mutex_lock_interruptible(&module_mutex) != 0) {
733 ret = -EINTR;
734 goto out_stop;
735 }
736 726
737 mod = find_module(name); 727 mod = find_module(name);
738 if (!mod) { 728 if (!mod) {
@@ -792,8 +782,6 @@ SYSCALL_DEFINE2(delete_module, const char __user *, name_user,
792 782
793 out: 783 out:
794 mutex_unlock(&module_mutex); 784 mutex_unlock(&module_mutex);
795out_stop:
796 stop_machine_destroy();
797 return ret; 785 return ret;
798} 786}
799 787
@@ -867,8 +855,7 @@ void module_put(struct module *module)
867 smp_wmb(); /* see comment in module_refcount */ 855 smp_wmb(); /* see comment in module_refcount */
868 __this_cpu_inc(module->refptr->decs); 856 __this_cpu_inc(module->refptr->decs);
869 857
870 trace_module_put(module, _RET_IP_, 858 trace_module_put(module, _RET_IP_);
871 __this_cpu_read(module->refptr->decs));
872 /* Maybe they're waiting for us to drop reference? */ 859 /* Maybe they're waiting for us to drop reference? */
873 if (unlikely(!module_is_live(module))) 860 if (unlikely(!module_is_live(module)))
874 wake_up_process(module->waiter); 861 wake_up_process(module->waiter);
@@ -890,7 +877,7 @@ static inline void module_unload_free(struct module *mod)
890 877
891int use_module(struct module *a, struct module *b) 878int use_module(struct module *a, struct module *b)
892{ 879{
893 return strong_try_module_get(b) == 0; 880 return strong_try_module_get(b);
894} 881}
895EXPORT_SYMBOL_GPL(use_module); 882EXPORT_SYMBOL_GPL(use_module);
896 883
@@ -1061,17 +1048,39 @@ static const struct kernel_symbol *resolve_symbol(Elf_Shdr *sechdrs,
1061 struct module *owner; 1048 struct module *owner;
1062 const struct kernel_symbol *sym; 1049 const struct kernel_symbol *sym;
1063 const unsigned long *crc; 1050 const unsigned long *crc;
1051 DEFINE_WAIT(wait);
1052 int err;
1053 long timeleft = 30 * HZ;
1064 1054
1055again:
1065 sym = find_symbol(name, &owner, &crc, 1056 sym = find_symbol(name, &owner, &crc,
1066 !(mod->taints & (1 << TAINT_PROPRIETARY_MODULE)), true); 1057 !(mod->taints & (1 << TAINT_PROPRIETARY_MODULE)), true);
1067 /* use_module can fail due to OOM, 1058 if (!sym)
1068 or module initialization or unloading */ 1059 return NULL;
1069 if (sym) { 1060
1070 if (!check_version(sechdrs, versindex, name, mod, crc, owner) 1061 if (!check_version(sechdrs, versindex, name, mod, crc, owner))
1071 || !use_module(mod, owner)) 1062 return NULL;
1072 sym = NULL; 1063
1064 prepare_to_wait(&module_wq, &wait, TASK_INTERRUPTIBLE);
1065 err = use_module(mod, owner);
1066 if (likely(!err) || err != -EBUSY || signal_pending(current)) {
1067 finish_wait(&module_wq, &wait);
1068 return err ? NULL : sym;
1073 } 1069 }
1074 return sym; 1070
1071 /* Module is still loading. Drop lock and wait. */
1072 mutex_unlock(&module_mutex);
1073 timeleft = schedule_timeout(timeleft);
1074 mutex_lock(&module_mutex);
1075 finish_wait(&module_wq, &wait);
1076
1077 /* Module might be gone entirely, or replaced. Re-lookup. */
1078 if (timeleft)
1079 goto again;
1080
1081 printk(KERN_WARNING "%s: gave up waiting for init of module %s.\n",
1082 mod->name, owner->name);
1083 return NULL;
1075} 1084}
1076 1085
1077/* 1086/*
@@ -1192,7 +1201,7 @@ struct module_notes_attrs {
1192 struct bin_attribute attrs[0]; 1201 struct bin_attribute attrs[0];
1193}; 1202};
1194 1203
1195static ssize_t module_notes_read(struct kobject *kobj, 1204static ssize_t module_notes_read(struct file *filp, struct kobject *kobj,
1196 struct bin_attribute *bin_attr, 1205 struct bin_attribute *bin_attr,
1197 char *buf, loff_t pos, size_t count) 1206 char *buf, loff_t pos, size_t count)
1198{ 1207{