Merge branches 'release', 'asus', 'bugzilla-12450', 'cpuidle', 'debug', 'ec', 'misc...
[safe/jmp/linux-2.6] / kernel / module.c
index b7205f6..ba22484 100644 (file)
 #include <linux/moduleloader.h>
 #include <linux/init.h>
 #include <linux/kallsyms.h>
+#include <linux/fs.h>
 #include <linux/sysfs.h>
 #include <linux/kernel.h>
 #include <linux/slab.h>
 #include <linux/vmalloc.h>
 #include <linux/elf.h>
+#include <linux/proc_fs.h>
 #include <linux/seq_file.h>
 #include <linux/syscalls.h>
 #include <linux/fcntl.h>
 #include <linux/device.h>
 #include <linux/string.h>
 #include <linux/mutex.h>
-#include <linux/unwind.h>
+#include <linux/rculist.h>
 #include <asm/uaccess.h>
 #include <asm/cacheflush.h>
 #include <linux/license.h>
 #include <asm/sections.h>
+#include <linux/tracepoint.h>
+#include <linux/ftrace.h>
+#include <linux/async.h>
 
 #if 0
 #define DEBUGP printk
@@ -61,7 +66,7 @@
 #define INIT_OFFSET_MASK (1UL << (BITS_PER_LONG-1))
 
 /* List of modules, protected by module_mutex or preempt_disable
- * (add/delete uses stop_machine). */
+ * (delete uses stop_machine/add uses RCU list operations). */
 static DEFINE_MUTEX(module_mutex);
 static LIST_HEAD(modules);
 
@@ -130,6 +135,29 @@ static unsigned int find_sec(Elf_Ehdr *hdr,
        return 0;
 }
 
+/* Find a module section, or NULL. */
+static void *section_addr(Elf_Ehdr *hdr, Elf_Shdr *shdrs,
+                         const char *secstrings, const char *name)
+{
+       /* Section 0 has sh_addr 0. */
+       return (void *)shdrs[find_sec(hdr, shdrs, secstrings, name)].sh_addr;
+}
+
+/* Find a module section, or NULL.  Fill in number of "objects" in section. */
+static void *section_objs(Elf_Ehdr *hdr,
+                         Elf_Shdr *sechdrs,
+                         const char *secstrings,
+                         const char *name,
+                         size_t object_size,
+                         unsigned int *num)
+{
+       unsigned int sec = find_sec(hdr, sechdrs, secstrings, name);
+
+       /* Section 0 has sh_addr 0 and sh_size 0. */
+       *num = sechdrs[sec].sh_size / object_size;
+       return (void *)sechdrs[sec].sh_addr;
+}
+
 /* Provided by the linker */
 extern const struct kernel_symbol __start___ksymtab[];
 extern const struct kernel_symbol __stop___ksymtab[];
@@ -216,7 +244,7 @@ static bool each_symbol(bool (*fn)(const struct symsearch *arr,
        if (each_symbol_in_section(arr, ARRAY_SIZE(arr), NULL, fn, data))
                return true;
 
-       list_for_each_entry(mod, &modules, list) {
+       list_for_each_entry_rcu(mod, &modules, list) {
                struct symsearch arr[] = {
                        { mod->syms, mod->syms + mod->num_syms, mod->crcs,
                          NOT_GPL_ONLY, false },
@@ -545,13 +573,13 @@ static char last_unloaded_module[MODULE_NAME_LEN+1];
 /* Init the unload section of the module. */
 static void module_unload_init(struct module *mod)
 {
-       unsigned int i;
+       int cpu;
 
        INIT_LIST_HEAD(&mod->modules_which_use_me);
-       for (i = 0; i < NR_CPUS; i++)
-               local_set(&mod->ref[i].count, 0);
+       for_each_possible_cpu(cpu)
+               local_set(__module_ref_addr(mod, cpu), 0);
        /* Hold reference count during initialization. */
-       local_set(&mod->ref[raw_smp_processor_id()].count, 1);
+       local_set(__module_ref_addr(mod, raw_smp_processor_id()), 1);
        /* Backwards compatibility macros put refcount during init. */
        mod->waiter = current;
 }
@@ -689,10 +717,11 @@ static int try_stop_module(struct module *mod, int flags, int *forced)
 
 unsigned int module_refcount(struct module *mod)
 {
-       unsigned int i, total = 0;
+       unsigned int total = 0;
+       int cpu;
 
-       for (i = 0; i < NR_CPUS; i++)
-               total += local_read(&mod->ref[i].count);
+       for_each_possible_cpu(cpu)
+               total += local_read(__module_ref_addr(mod, cpu));
        return total;
 }
 EXPORT_SYMBOL(module_refcount);
@@ -715,8 +744,8 @@ static void wait_for_zero_refcount(struct module *mod)
        mutex_lock(&module_mutex);
 }
 
-asmlinkage long
-sys_delete_module(const char __user *name_user, unsigned int flags)
+SYSCALL_DEFINE2(delete_module, const char __user *, name_user,
+               unsigned int, flags)
 {
        struct module *mod;
        char name[MODULE_NAME_LEN];
@@ -729,8 +758,16 @@ sys_delete_module(const char __user *name_user, unsigned int flags)
                return -EFAULT;
        name[MODULE_NAME_LEN-1] = '\0';
 
-       if (mutex_lock_interruptible(&module_mutex) != 0)
-               return -EINTR;
+       /* Create stop_machine threads since free_module relies on
+        * a non-failing stop_machine call. */
+       ret = stop_machine_create();
+       if (ret)
+               return ret;
+
+       if (mutex_lock_interruptible(&module_mutex) != 0) {
+               ret = -EINTR;
+               goto out_stop;
+       }
 
        mod = find_module(name);
        if (!mod) {
@@ -781,6 +818,7 @@ sys_delete_module(const char __user *name_user, unsigned int flags)
                mod->exit();
        blocking_notifier_call_chain(&module_notify_list,
                                     MODULE_STATE_GOING, mod);
+       async_synchronize_full();
        mutex_lock(&module_mutex);
        /* Store the name of the last unloaded module for diagnostic purposes */
        strlcpy(last_unloaded_module, mod->name, sizeof(last_unloaded_module));
@@ -789,10 +827,12 @@ sys_delete_module(const char __user *name_user, unsigned int flags)
 
  out:
        mutex_unlock(&module_mutex);
+out_stop:
+       stop_machine_destroy();
        return ret;
 }
 
-static void print_unload_info(struct seq_file *m, struct module *mod)
+static inline void print_unload_info(struct seq_file *m, struct module *mod)
 {
        struct module_use *use;
        int printed_something = 0;
@@ -855,7 +895,7 @@ void module_put(struct module *module)
 {
        if (module) {
                unsigned int cpu = get_cpu();
-               local_dec(&module->ref[cpu].count);
+               local_dec(__module_ref_addr(module, cpu));
                /* Maybe they're waiting for us to drop reference? */
                if (unlikely(!module_is_live(module)))
                        wake_up_process(module->waiter);
@@ -865,7 +905,7 @@ void module_put(struct module *module)
 EXPORT_SYMBOL(module_put);
 
 #else /* !CONFIG_MODULE_UNLOAD */
-static void print_unload_info(struct seq_file *m, struct module *mod)
+static inline void print_unload_info(struct seq_file *m, struct module *mod)
 {
        /* We don't know the usage count, or what modules are using. */
        seq_printf(m, " - -");
@@ -1392,17 +1432,6 @@ static void mod_kobject_remove(struct module *mod)
 }
 
 /*
- * link the module with the whole machine is stopped with interrupts off
- * - this defends against kallsyms not taking locks
- */
-static int __link_module(void *_mod)
-{
-       struct module *mod = _mod;
-       list_add(&mod->list, &modules);
-       return 0;
-}
-
-/*
  * unlink the module with the whole machine is stopped with interrupts off
  * - this defends against kallsyms not taking locks
  */
@@ -1422,20 +1451,24 @@ static void free_module(struct module *mod)
        remove_sect_attrs(mod);
        mod_kobject_remove(mod);
 
-       unwind_remove_table(mod->unwind_info, 0);
-
        /* Arch-specific cleanup. */
        module_arch_cleanup(mod);
 
        /* Module unload stuff */
        module_unload_free(mod);
 
+       /* release any pointers to mcount in this module */
+       ftrace_release(mod->module_core, mod->core_size);
+
        /* This may be NULL, but that's OK */
        module_free(mod, mod->module_init);
        kfree(mod->args);
        if (mod->percpu)
                percpu_modfree(mod->percpu);
-
+#if defined(CONFIG_MODULE_UNLOAD) && defined(CONFIG_SMP)
+       if (mod->refptr)
+               percpu_modfree(mod->refptr);
+#endif
        /* Free lock-classes: */
        lockdep_free_key_range(mod->module_core, mod->core_size);
 
@@ -1558,11 +1591,21 @@ static int simplify_symbols(Elf_Shdr *sechdrs,
        return ret;
 }
 
+/* Additional bytes needed by arch in front of individual sections */
+unsigned int __weak arch_mod_section_prepend(struct module *mod,
+                                            unsigned int section)
+{
+       /* default implementation just returns zero */
+       return 0;
+}
+
 /* Update size with this section: return offset. */
-static long get_offset(unsigned int *size, Elf_Shdr *sechdr)
+static long get_offset(struct module *mod, unsigned int *size,
+                      Elf_Shdr *sechdr, unsigned int section)
 {
        long ret;
 
+       *size += arch_mod_section_prepend(mod, section);
        ret = ALIGN(*size, sechdr->sh_addralign ?: 1);
        *size = ret + sechdr->sh_size;
        return ret;
@@ -1602,7 +1645,7 @@ static void layout_sections(struct module *mod,
                            || strncmp(secstrings + s->sh_name,
                                       ".init", 5) == 0)
                                continue;
-                       s->sh_entsize = get_offset(&mod->core_size, s);
+                       s->sh_entsize = get_offset(mod, &mod->core_size, s, i);
                        DEBUGP("\t%s\n", secstrings + s->sh_name);
                }
                if (m == 0)
@@ -1620,7 +1663,7 @@ static void layout_sections(struct module *mod,
                            || strncmp(secstrings + s->sh_name,
                                       ".init", 5) != 0)
                                continue;
-                       s->sh_entsize = (get_offset(&mod->init_size, s)
+                       s->sh_entsize = (get_offset(mod, &mod->init_size, s, i)
                                         | INIT_OFFSET_MASK);
                        DEBUGP("\t%s\n", secstrings + s->sh_name);
                }
@@ -1705,15 +1748,15 @@ static const struct kernel_symbol *lookup_symbol(const char *name,
        return NULL;
 }
 
-static int is_exported(const char *name, const struct module *mod)
+static int is_exported(const char *name, unsigned long value,
+                      const struct module *mod)
 {
-       if (!mod && lookup_symbol(name, __start___ksymtab, __stop___ksymtab))
-               return 1;
+       const struct kernel_symbol *ks;
+       if (!mod)
+               ks = lookup_symbol(name, __start___ksymtab, __stop___ksymtab);
        else
-               if (mod && lookup_symbol(name, mod->syms, mod->syms + mod->num_syms))
-                       return 1;
-               else
-                       return 0;
+               ks = lookup_symbol(name, mod->syms, mod->syms + mod->num_syms);
+       return ks != NULL && ks->value == value;
 }
 
 /* As per nm */
@@ -1784,32 +1827,20 @@ static inline void add_kallsyms(struct module *mod,
 }
 #endif /* CONFIG_KALLSYMS */
 
-#ifdef CONFIG_DYNAMIC_PRINTK_DEBUG
-static void dynamic_printk_setup(Elf_Shdr *sechdrs, unsigned int verboseindex)
+static void dynamic_printk_setup(struct mod_debug *debug, unsigned int num)
 {
-       struct mod_debug *debug_info;
-       unsigned long pos, end;
-       unsigned int num_verbose;
-
-       pos = sechdrs[verboseindex].sh_addr;
-       num_verbose = sechdrs[verboseindex].sh_size /
-                               sizeof(struct mod_debug);
-       end = pos + (num_verbose * sizeof(struct mod_debug));
+#ifdef CONFIG_DYNAMIC_PRINTK_DEBUG
+       unsigned int i;
 
-       for (; pos < end; pos += sizeof(struct mod_debug)) {
-               debug_info = (struct mod_debug *)pos;
-               register_dynamic_debug_module(debug_info->modname,
-                       debug_info->type, debug_info->logical_modname,
-                       debug_info->flag_names, debug_info->hash,
-                       debug_info->hash2);
+       for (i = 0; i < num; i++) {
+               register_dynamic_debug_module(debug[i].modname,
+                                             debug[i].type,
+                                             debug[i].logical_modname,
+                                             debug[i].flag_names,
+                                             debug[i].hash, debug[i].hash2);
        }
-}
-#else
-static inline void dynamic_printk_setup(Elf_Shdr *sechdrs,
-                                       unsigned int verboseindex)
-{
-}
 #endif /* CONFIG_DYNAMIC_PRINTK_DEBUG */
+}
 
 static void *module_alloc_update_bounds(unsigned long size)
 {
@@ -1834,36 +1865,17 @@ static noinline struct module *load_module(void __user *umod,
        Elf_Ehdr *hdr;
        Elf_Shdr *sechdrs;
        char *secstrings, *args, *modmagic, *strtab = NULL;
+       char *staging;
        unsigned int i;
        unsigned int symindex = 0;
        unsigned int strindex = 0;
-       unsigned int setupindex;
-       unsigned int exindex;
-       unsigned int exportindex;
-       unsigned int modindex;
-       unsigned int obsparmindex;
-       unsigned int infoindex;
-       unsigned int gplindex;
-       unsigned int crcindex;
-       unsigned int gplcrcindex;
-       unsigned int versindex;
-       unsigned int pcpuindex;
-       unsigned int gplfutureindex;
-       unsigned int gplfuturecrcindex;
-       unsigned int unwindex = 0;
-#ifdef CONFIG_UNUSED_SYMBOLS
-       unsigned int unusedindex;
-       unsigned int unusedcrcindex;
-       unsigned int unusedgplindex;
-       unsigned int unusedgplcrcindex;
-#endif
-       unsigned int markersindex;
-       unsigned int markersstringsindex;
-       unsigned int verboseindex;
+       unsigned int modindex, versindex, infoindex, pcpuindex;
+       unsigned int num_kp, num_mcount;
+       struct kernel_param *kp;
        struct module *mod;
        long err = 0;
        void *percpu = NULL, *ptr = NULL; /* Stops spurious gcc warning */
-       struct exception_table_entry *extable;
+       unsigned long *mseg;
        mm_segment_t old_fs;
 
        DEBUGP("load_module: umod=%p, len=%lu, uargs=%p\n",
@@ -1875,6 +1887,13 @@ static noinline struct module *load_module(void __user *umod,
        /* vmalloc barfs on "unusual" numbers.  Check here */
        if (len > 64 * 1024 * 1024 || (hdr = vmalloc(len)) == NULL)
                return ERR_PTR(-ENOMEM);
+
+       /* Create stop_machine threads since the error path relies on
+        * a non-failing stop_machine call. */
+       err = stop_machine_create();
+       if (err)
+               goto free_hdr;
+
        if (copy_from_user(hdr, umod, len) != 0) {
                err = -EFAULT;
                goto free_hdr;
@@ -1927,6 +1946,7 @@ static noinline struct module *load_module(void __user *umod,
                err = -ENOEXEC;
                goto free_hdr;
        }
+       /* This is temporary: point mod into copy of data. */
        mod = (void *)sechdrs[modindex].sh_addr;
 
        if (symindex == 0) {
@@ -1936,28 +1956,9 @@ static noinline struct module *load_module(void __user *umod,
                goto free_hdr;
        }
 
-       /* Optional sections */
-       exportindex = find_sec(hdr, sechdrs, secstrings, "__ksymtab");
-       gplindex = find_sec(hdr, sechdrs, secstrings, "__ksymtab_gpl");
-       gplfutureindex = find_sec(hdr, sechdrs, secstrings, "__ksymtab_gpl_future");
-       crcindex = find_sec(hdr, sechdrs, secstrings, "__kcrctab");
-       gplcrcindex = find_sec(hdr, sechdrs, secstrings, "__kcrctab_gpl");
-       gplfuturecrcindex = find_sec(hdr, sechdrs, secstrings, "__kcrctab_gpl_future");
-#ifdef CONFIG_UNUSED_SYMBOLS
-       unusedindex = find_sec(hdr, sechdrs, secstrings, "__ksymtab_unused");
-       unusedgplindex = find_sec(hdr, sechdrs, secstrings, "__ksymtab_unused_gpl");
-       unusedcrcindex = find_sec(hdr, sechdrs, secstrings, "__kcrctab_unused");
-       unusedgplcrcindex = find_sec(hdr, sechdrs, secstrings, "__kcrctab_unused_gpl");
-#endif
-       setupindex = find_sec(hdr, sechdrs, secstrings, "__param");
-       exindex = find_sec(hdr, sechdrs, secstrings, "__ex_table");
-       obsparmindex = find_sec(hdr, sechdrs, secstrings, "__obsparm");
        versindex = find_sec(hdr, sechdrs, secstrings, "__versions");
        infoindex = find_sec(hdr, sechdrs, secstrings, ".modinfo");
        pcpuindex = find_pcpusec(hdr, sechdrs, secstrings);
-#ifdef ARCH_UNWIND_SECTION_NAME
-       unwindex = find_sec(hdr, sechdrs, secstrings, ARCH_UNWIND_SECTION_NAME);
-#endif
 
        /* Don't keep modinfo and version sections. */
        sechdrs[infoindex].sh_flags &= ~(unsigned long)SHF_ALLOC;
@@ -1967,8 +1968,6 @@ static noinline struct module *load_module(void __user *umod,
        sechdrs[symindex].sh_flags |= SHF_ALLOC;
        sechdrs[strindex].sh_flags |= SHF_ALLOC;
 #endif
-       if (unwindex)
-               sechdrs[unwindex].sh_flags |= SHF_ALLOC;
 
        /* Check module struct version now, before we try to use module. */
        if (!check_modstruct_version(sechdrs, versindex, mod)) {
@@ -1989,6 +1988,14 @@ static noinline struct module *load_module(void __user *umod,
                goto free_hdr;
        }
 
+       staging = get_modinfo(sechdrs, infoindex, "staging");
+       if (staging) {
+               add_taint_module(mod, TAINT_CRAP);
+               printk(KERN_WARNING "%s: module is from the staging directory,"
+                      " the quality is unknown, you have been warned.\n",
+                      mod->name);
+       }
+
        /* Now copy in args */
        args = strndup_user(uargs, ~0UL >> 1);
        if (IS_ERR(args)) {
@@ -2008,6 +2015,14 @@ static noinline struct module *load_module(void __user *umod,
        if (err < 0)
                goto free_mod;
 
+#if defined(CONFIG_MODULE_UNLOAD) && defined(CONFIG_SMP)
+       mod->refptr = percpu_modalloc(sizeof(local_t), __alignof__(local_t),
+                                     mod->name);
+       if (!mod->refptr) {
+               err = -ENOMEM;
+               goto free_mod;
+       }
+#endif
        if (pcpuindex) {
                /* We have a special allocation for this section. */
                percpu = percpu_modalloc(sechdrs[pcpuindex].sh_size,
@@ -2015,7 +2030,7 @@ static noinline struct module *load_module(void __user *umod,
                                         mod->name);
                if (!percpu) {
                        err = -ENOMEM;
-                       goto free_mod;
+                       goto free_percpu;
                }
                sechdrs[pcpuindex].sh_flags &= ~(unsigned long)SHF_ALLOC;
                mod->percpu = percpu;
@@ -2099,42 +2114,57 @@ static noinline struct module *load_module(void __user *umod,
        if (err < 0)
                goto cleanup;
 
-       /* Set up EXPORTed & EXPORT_GPLed symbols (section 0 is 0 length) */
-       mod->num_syms = sechdrs[exportindex].sh_size / sizeof(*mod->syms);
-       mod->syms = (void *)sechdrs[exportindex].sh_addr;
-       if (crcindex)
-               mod->crcs = (void *)sechdrs[crcindex].sh_addr;
-       mod->num_gpl_syms = sechdrs[gplindex].sh_size / sizeof(*mod->gpl_syms);
-       mod->gpl_syms = (void *)sechdrs[gplindex].sh_addr;
-       if (gplcrcindex)
-               mod->gpl_crcs = (void *)sechdrs[gplcrcindex].sh_addr;
-       mod->num_gpl_future_syms = sechdrs[gplfutureindex].sh_size /
-                                       sizeof(*mod->gpl_future_syms);
-       mod->gpl_future_syms = (void *)sechdrs[gplfutureindex].sh_addr;
-       if (gplfuturecrcindex)
-               mod->gpl_future_crcs = (void *)sechdrs[gplfuturecrcindex].sh_addr;
+       /* Now we've got everything in the final locations, we can
+        * find optional sections. */
+       kp = section_objs(hdr, sechdrs, secstrings, "__param", sizeof(*kp),
+                         &num_kp);
+       mod->syms = section_objs(hdr, sechdrs, secstrings, "__ksymtab",
+                                sizeof(*mod->syms), &mod->num_syms);
+       mod->crcs = section_addr(hdr, sechdrs, secstrings, "__kcrctab");
+       mod->gpl_syms = section_objs(hdr, sechdrs, secstrings, "__ksymtab_gpl",
+                                    sizeof(*mod->gpl_syms),
+                                    &mod->num_gpl_syms);
+       mod->gpl_crcs = section_addr(hdr, sechdrs, secstrings, "__kcrctab_gpl");
+       mod->gpl_future_syms = section_objs(hdr, sechdrs, secstrings,
+                                           "__ksymtab_gpl_future",
+                                           sizeof(*mod->gpl_future_syms),
+                                           &mod->num_gpl_future_syms);
+       mod->gpl_future_crcs = section_addr(hdr, sechdrs, secstrings,
+                                           "__kcrctab_gpl_future");
 
 #ifdef CONFIG_UNUSED_SYMBOLS
-       mod->num_unused_syms = sechdrs[unusedindex].sh_size /
-                                       sizeof(*mod->unused_syms);
-       mod->num_unused_gpl_syms = sechdrs[unusedgplindex].sh_size /
-                                       sizeof(*mod->unused_gpl_syms);
-       mod->unused_syms = (void *)sechdrs[unusedindex].sh_addr;
-       if (unusedcrcindex)
-               mod->unused_crcs = (void *)sechdrs[unusedcrcindex].sh_addr;
-       mod->unused_gpl_syms = (void *)sechdrs[unusedgplindex].sh_addr;
-       if (unusedgplcrcindex)
-               mod->unused_gpl_crcs
-                       = (void *)sechdrs[unusedgplcrcindex].sh_addr;
+       mod->unused_syms = section_objs(hdr, sechdrs, secstrings,
+                                       "__ksymtab_unused",
+                                       sizeof(*mod->unused_syms),
+                                       &mod->num_unused_syms);
+       mod->unused_crcs = section_addr(hdr, sechdrs, secstrings,
+                                       "__kcrctab_unused");
+       mod->unused_gpl_syms = section_objs(hdr, sechdrs, secstrings,
+                                           "__ksymtab_unused_gpl",
+                                           sizeof(*mod->unused_gpl_syms),
+                                           &mod->num_unused_gpl_syms);
+       mod->unused_gpl_crcs = section_addr(hdr, sechdrs, secstrings,
+                                           "__kcrctab_unused_gpl");
+#endif
+
+#ifdef CONFIG_MARKERS
+       mod->markers = section_objs(hdr, sechdrs, secstrings, "__markers",
+                                   sizeof(*mod->markers), &mod->num_markers);
+#endif
+#ifdef CONFIG_TRACEPOINTS
+       mod->tracepoints = section_objs(hdr, sechdrs, secstrings,
+                                       "__tracepoints",
+                                       sizeof(*mod->tracepoints),
+                                       &mod->num_tracepoints);
 #endif
 
 #ifdef CONFIG_MODVERSIONS
-       if ((mod->num_syms && !crcindex)
-           || (mod->num_gpl_syms && !gplcrcindex)
-           || (mod->num_gpl_future_syms && !gplfuturecrcindex)
+       if ((mod->num_syms && !mod->crcs)
+           || (mod->num_gpl_syms && !mod->gpl_crcs)
+           || (mod->num_gpl_future_syms && !mod->gpl_future_crcs)
 #ifdef CONFIG_UNUSED_SYMBOLS
-           || (mod->num_unused_syms && !unusedcrcindex)
-           || (mod->num_unused_gpl_syms && !unusedgplcrcindex)
+           || (mod->num_unused_syms && !mod->unused_crcs)
+           || (mod->num_unused_gpl_syms && !mod->unused_gpl_crcs)
 #endif
                ) {
                printk(KERN_WARNING "%s: No versions for exported symbols.\n", mod->name);
@@ -2143,10 +2173,6 @@ static noinline struct module *load_module(void __user *umod,
                        goto cleanup;
        }
 #endif
-       markersindex = find_sec(hdr, sechdrs, secstrings, "__markers");
-       markersstringsindex = find_sec(hdr, sechdrs, secstrings,
-                                       "__markers_strings");
-       verboseindex = find_sec(hdr, sechdrs, secstrings, "__verbose");
 
        /* Now do relocations. */
        for (i = 1; i < hdr->e_shnum; i++) {
@@ -2169,22 +2195,16 @@ static noinline struct module *load_module(void __user *umod,
                if (err < 0)
                        goto cleanup;
        }
-#ifdef CONFIG_MARKERS
-       mod->markers = (void *)sechdrs[markersindex].sh_addr;
-       mod->num_markers =
-               sechdrs[markersindex].sh_size / sizeof(*mod->markers);
-#endif
 
         /* Find duplicate symbols */
        err = verify_export_symbols(mod);
-
        if (err < 0)
                goto cleanup;
 
        /* Set up and sort exception table */
-       mod->num_exentries = sechdrs[exindex].sh_size / sizeof(*mod->extable);
-       mod->extable = extable = (void *)sechdrs[exindex].sh_addr;
-       sort_extable(extable, extable + mod->num_exentries);
+       mod->extable = section_objs(hdr, sechdrs, secstrings, "__ex_table",
+                                   sizeof(*mod->extable), &mod->num_exentries);
+       sort_extable(mod->extable, mod->extable + mod->num_exentries);
 
        /* Finally, copy percpu area over. */
        percpu_modcopy(mod->percpu, (void *)sechdrs[pcpuindex].sh_addr,
@@ -2192,12 +2212,20 @@ static noinline struct module *load_module(void __user *umod,
 
        add_kallsyms(mod, sechdrs, symindex, strindex, secstrings);
 
-#ifdef CONFIG_MARKERS
-       if (!mod->taints)
-               marker_update_probe_range(mod->markers,
-                       mod->markers + mod->num_markers);
-#endif
-       dynamic_printk_setup(sechdrs, verboseindex);
+       if (!mod->taints) {
+               struct mod_debug *debug;
+               unsigned int num_debug;
+
+               debug = section_objs(hdr, sechdrs, secstrings, "__verbose",
+                                    sizeof(*debug), &num_debug);
+               dynamic_printk_setup(debug, num_debug);
+       }
+
+       /* sechdrs[0].sh_size is always zero */
+       mseg = section_objs(hdr, sechdrs, secstrings, "__mcount_loc",
+                           sizeof(*mseg), &num_mcount);
+       ftrace_init_module(mod, mseg, mseg + num_mcount);
+
        err = module_finalize(hdr, sechdrs, mod);
        if (err < 0)
                goto cleanup;
@@ -2221,43 +2249,33 @@ static noinline struct module *load_module(void __user *umod,
        set_fs(old_fs);
 
        mod->args = args;
-       if (obsparmindex)
+       if (section_addr(hdr, sechdrs, secstrings, "__obsparm"))
                printk(KERN_WARNING "%s: Ignoring obsolete parameters\n",
                       mod->name);
 
        /* Now sew it into the lists so we can get lockdep and oops
-         * info during argument parsing.  Noone should access us, since
-         * strong_try_module_get() will fail. */
-       stop_machine(__link_module, mod, NULL);
-
-       /* Size of section 0 is 0, so this works well if no params */
-       err = parse_args(mod->name, mod->args,
-                        (struct kernel_param *)
-                        sechdrs[setupindex].sh_addr,
-                        sechdrs[setupindex].sh_size
-                        / sizeof(struct kernel_param),
-                        NULL);
+        * info during argument parsing.  Noone should access us, since
+        * strong_try_module_get() will fail.
+        * lockdep/oops can run asynchronous, so use the RCU list insertion
+        * function to insert in a way safe to concurrent readers.
+        * The mutex protects against concurrent writers.
+        */
+       list_add_rcu(&mod->list, &modules);
+
+       err = parse_args(mod->name, mod->args, kp, num_kp, NULL);
        if (err < 0)
                goto unlink;
 
-       err = mod_sysfs_setup(mod,
-                             (struct kernel_param *)
-                             sechdrs[setupindex].sh_addr,
-                             sechdrs[setupindex].sh_size
-                             / sizeof(struct kernel_param));
+       err = mod_sysfs_setup(mod, kp, num_kp);
        if (err < 0)
                goto unlink;
        add_sect_attrs(mod, hdr->e_shnum, secstrings, sechdrs);
        add_notes_attrs(mod, hdr->e_shnum, secstrings, sechdrs);
 
-       /* Size of section 0 is 0, so this works well if no unwind info. */
-       mod->unwind_info = unwind_add_table(mod,
-                                           (void *)sechdrs[unwindex].sh_addr,
-                                           sechdrs[unwindex].sh_size);
-
        /* Get rid of temporary copy */
        vfree(hdr);
 
+       stop_machine_destroy();
        /* Done! */
        return mod;
 
@@ -2267,6 +2285,7 @@ static noinline struct module *load_module(void __user *umod,
  cleanup:
        kobject_del(&mod->mkobj.kobj);
        kobject_put(&mod->mkobj.kobj);
+       ftrace_release(mod->module_core, mod->core_size);
  free_unload:
        module_unload_free(mod);
        module_free(mod, mod->module_init);
@@ -2275,10 +2294,14 @@ static noinline struct module *load_module(void __user *umod,
  free_percpu:
        if (percpu)
                percpu_modfree(percpu);
+#if defined(CONFIG_MODULE_UNLOAD) && defined(CONFIG_SMP)
+       percpu_modfree(mod->refptr);
+#endif
  free_mod:
        kfree(args);
  free_hdr:
        vfree(hdr);
+       stop_machine_destroy();
        return ERR_PTR(err);
 
  truncated:
@@ -2288,10 +2311,8 @@ static noinline struct module *load_module(void __user *umod,
 }
 
 /* This is where the real work happens */
-asmlinkage long
-sys_init_module(void __user *umod,
-               unsigned long len,
-               const char __user *uargs)
+SYSCALL_DEFINE3(init_module, void __user *, umod,
+               unsigned long, len, const char __user *, uargs)
 {
        struct module *mod;
        int ret = 0;
@@ -2346,11 +2367,12 @@ sys_init_module(void __user *umod,
        /* Now it's a first class citizen!  Wake up anyone waiting for it. */
        mod->state = MODULE_STATE_LIVE;
        wake_up(&module_wq);
+       blocking_notifier_call_chain(&module_notify_list,
+                                    MODULE_STATE_LIVE, mod);
 
        mutex_lock(&module_mutex);
        /* Drop initial reference. */
        module_put(mod);
-       unwind_remove_table(mod->unwind_info, 1);
        module_free(mod, mod->module_init);
        mod->module_init = NULL;
        mod->init_size = 0;
@@ -2385,7 +2407,7 @@ static const char *get_ksymbol(struct module *mod,
        unsigned long nextval;
 
        /* At worse, next value is at end of module */
-       if (within(addr, mod->module_init, mod->init_size))
+       if (within_module_init(addr, mod))
                nextval = (unsigned long)mod->module_init+mod->init_text_size;
        else
                nextval = (unsigned long)mod->module_core+mod->core_text_size;
@@ -2432,9 +2454,9 @@ const char *module_address_lookup(unsigned long addr,
        const char *ret = NULL;
 
        preempt_disable();
-       list_for_each_entry(mod, &modules, list) {
-               if (within(addr, mod->module_init, mod->init_size)
-                   || within(addr, mod->module_core, mod->core_size)) {
+       list_for_each_entry_rcu(mod, &modules, list) {
+               if (within_module_init(addr, mod) ||
+                   within_module_core(addr, mod)) {
                        if (modname)
                                *modname = mod->name;
                        ret = get_ksymbol(mod, addr, size, offset);
@@ -2455,9 +2477,9 @@ int lookup_module_symbol_name(unsigned long addr, char *symname)
        struct module *mod;
 
        preempt_disable();
-       list_for_each_entry(mod, &modules, list) {
-               if (within(addr, mod->module_init, mod->init_size) ||
-                   within(addr, mod->module_core, mod->core_size)) {
+       list_for_each_entry_rcu(mod, &modules, list) {
+               if (within_module_init(addr, mod) ||
+                   within_module_core(addr, mod)) {
                        const char *sym;
 
                        sym = get_ksymbol(mod, addr, NULL, NULL);
@@ -2479,9 +2501,9 @@ int lookup_module_symbol_attrs(unsigned long addr, unsigned long *size,
        struct module *mod;
 
        preempt_disable();
-       list_for_each_entry(mod, &modules, list) {
-               if (within(addr, mod->module_init, mod->init_size) ||
-                   within(addr, mod->module_core, mod->core_size)) {
+       list_for_each_entry_rcu(mod, &modules, list) {
+               if (within_module_init(addr, mod) ||
+                   within_module_core(addr, mod)) {
                        const char *sym;
 
                        sym = get_ksymbol(mod, addr, size, offset);
@@ -2506,14 +2528,14 @@ int module_get_kallsym(unsigned int symnum, unsigned long *value, char *type,
        struct module *mod;
 
        preempt_disable();
-       list_for_each_entry(mod, &modules, list) {
+       list_for_each_entry_rcu(mod, &modules, list) {
                if (symnum < mod->num_symtab) {
                        *value = mod->symtab[symnum].st_value;
                        *type = mod->symtab[symnum].st_info;
                        strlcpy(name, mod->strtab + mod->symtab[symnum].st_name,
                                KSYM_NAME_LEN);
                        strlcpy(module_name, mod->name, MODULE_NAME_LEN);
-                       *exported = is_exported(name, mod);
+                       *exported = is_exported(name, *value, mod);
                        preempt_enable();
                        return 0;
                }
@@ -2549,7 +2571,7 @@ unsigned long module_kallsyms_lookup_name(const char *name)
                        ret = mod_find_symname(mod, colon+1);
                *colon = ':';
        } else {
-               list_for_each_entry(mod, &modules, list)
+               list_for_each_entry_rcu(mod, &modules, list)
                        if ((ret = mod_find_symname(mod, name)) != 0)
                                break;
        }
@@ -2558,23 +2580,6 @@ unsigned long module_kallsyms_lookup_name(const char *name)
 }
 #endif /* CONFIG_KALLSYMS */
 
-/* Called by the /proc file system to return a list of modules. */
-static void *m_start(struct seq_file *m, loff_t *pos)
-{
-       mutex_lock(&module_mutex);
-       return seq_list_start(&modules, *pos);
-}
-
-static void *m_next(struct seq_file *m, void *p, loff_t *pos)
-{
-       return seq_list_next(p, &modules, pos);
-}
-
-static void m_stop(struct seq_file *m, void *p)
-{
-       mutex_unlock(&module_mutex);
-}
-
 static char *module_flags(struct module *mod, char *buf)
 {
        int bx = 0;
@@ -2587,6 +2592,8 @@ static char *module_flags(struct module *mod, char *buf)
                        buf[bx++] = 'P';
                if (mod->taints & (1 << TAINT_FORCED_MODULE))
                        buf[bx++] = 'F';
+               if (mod->taints & (1 << TAINT_CRAP))
+                       buf[bx++] = 'C';
                /*
                 * TAINT_FORCED_RMMOD: could be added.
                 * TAINT_UNSAFE_SMP, TAINT_MACHINE_CHECK, TAINT_BAD_PAGE don't
@@ -2606,6 +2613,24 @@ static char *module_flags(struct module *mod, char *buf)
        return buf;
 }
 
+#ifdef CONFIG_PROC_FS
+/* Called by the /proc file system to return a list of modules. */
+static void *m_start(struct seq_file *m, loff_t *pos)
+{
+       mutex_lock(&module_mutex);
+       return seq_list_start(&modules, *pos);
+}
+
+static void *m_next(struct seq_file *m, void *p, loff_t *pos)
+{
+       return seq_list_next(p, &modules, pos);
+}
+
+static void m_stop(struct seq_file *m, void *p)
+{
+       mutex_unlock(&module_mutex);
+}
+
 static int m_show(struct seq_file *m, void *p)
 {
        struct module *mod = list_entry(p, struct module, list);
@@ -2636,13 +2661,33 @@ static int m_show(struct seq_file *m, void *p)
    Where refcount is a number or -, and deps is a comma-separated list
    of depends or -.
 */
-const struct seq_operations modules_op = {
+static const struct seq_operations modules_op = {
        .start  = m_start,
        .next   = m_next,
        .stop   = m_stop,
        .show   = m_show
 };
 
+static int modules_open(struct inode *inode, struct file *file)
+{
+       return seq_open(file, &modules_op);
+}
+
+static const struct file_operations proc_modules_operations = {
+       .open           = modules_open,
+       .read           = seq_read,
+       .llseek         = seq_lseek,
+       .release        = seq_release,
+};
+
+static int __init proc_modules_init(void)
+{
+       proc_create("modules", 0, NULL, &proc_modules_operations);
+       return 0;
+}
+module_init(proc_modules_init);
+#endif
+
 /* Given an address, look for it in the module exception tables. */
 const struct exception_table_entry *search_module_extables(unsigned long addr)
 {
@@ -2650,7 +2695,7 @@ const struct exception_table_entry *search_module_extables(unsigned long addr)
        struct module *mod;
 
        preempt_disable();
-       list_for_each_entry(mod, &modules, list) {
+       list_for_each_entry_rcu(mod, &modules, list) {
                if (mod->num_exentries == 0)
                        continue;
 
@@ -2676,8 +2721,8 @@ int is_module_address(unsigned long addr)
 
        preempt_disable();
 
-       list_for_each_entry(mod, &modules, list) {
-               if (within(addr, mod->module_core, mod->core_size)) {
+       list_for_each_entry_rcu(mod, &modules, list) {
+               if (within_module_core(addr, mod)) {
                        preempt_enable();
                        return 1;
                }
@@ -2690,14 +2735,14 @@ int is_module_address(unsigned long addr)
 
 
 /* Is this a valid kernel address? */
-struct module *__module_text_address(unsigned long addr)
+__notrace_funcgraph struct module *__module_text_address(unsigned long addr)
 {
        struct module *mod;
 
        if (addr < module_addr_min || addr > module_addr_max)
                return NULL;
 
-       list_for_each_entry(mod, &modules, list)
+       list_for_each_entry_rcu(mod, &modules, list)
                if (within(addr, mod->module_init, mod->init_text_size)
                    || within(addr, mod->module_core, mod->core_text_size))
                        return mod;
@@ -2722,8 +2767,11 @@ void print_modules(void)
        char buf[8];
 
        printk("Modules linked in:");
-       list_for_each_entry(mod, &modules, list)
+       /* Most callers should already have preempt disabled, but make sure */
+       preempt_disable();
+       list_for_each_entry_rcu(mod, &modules, list)
                printk(" %s%s", mod->name, module_flags(mod, buf));
+       preempt_enable();
        if (last_unloaded_module[0])
                printk(" [last unloaded: %s]", last_unloaded_module);
        printk("\n");
@@ -2748,3 +2796,50 @@ void module_update_markers(void)
        mutex_unlock(&module_mutex);
 }
 #endif
+
+#ifdef CONFIG_TRACEPOINTS
+void module_update_tracepoints(void)
+{
+       struct module *mod;
+
+       mutex_lock(&module_mutex);
+       list_for_each_entry(mod, &modules, list)
+               if (!mod->taints)
+                       tracepoint_update_probe_range(mod->tracepoints,
+                               mod->tracepoints + mod->num_tracepoints);
+       mutex_unlock(&module_mutex);
+}
+
+/*
+ * Returns 0 if current not found.
+ * Returns 1 if current found.
+ */
+int module_get_iter_tracepoints(struct tracepoint_iter *iter)
+{
+       struct module *iter_mod;
+       int found = 0;
+
+       mutex_lock(&module_mutex);
+       list_for_each_entry(iter_mod, &modules, list) {
+               if (!iter_mod->taints) {
+                       /*
+                        * Sorted module list
+                        */
+                       if (iter_mod < iter->module)
+                               continue;
+                       else if (iter_mod > iter->module)
+                               iter->tracepoint = NULL;
+                       found = tracepoint_get_iter_range(&iter->tracepoint,
+                               iter_mod->tracepoints,
+                               iter_mod->tracepoints
+                                       + iter_mod->num_tracepoints);
+                       if (found) {
+                               iter->module = iter_mod;
+                               break;
+                       }
+               }
+       }
+       mutex_unlock(&module_mutex);
+       return found;
+}
+#endif