nfsd4: remove some dprintk's
[safe/jmp/linux-2.6] / kernel / module.c
index d753fd9..1196f5d 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
@@ -63,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);
 
@@ -102,7 +105,7 @@ static inline int strong_try_module_get(struct module *mod)
 static inline void add_taint_module(struct module *mod, unsigned flag)
 {
        add_taint(flag);
-       mod->taints |= flag;
+       mod->taints |= (1U << flag);
 }
 
 /*
@@ -132,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[];
@@ -218,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 },
@@ -547,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;
 }
@@ -691,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);
@@ -717,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];
@@ -731,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) {
@@ -783,17 +818,21 @@ 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));
+       unregister_dynamic_debug_module(mod->name);
        free_module(mod);
 
  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;
@@ -856,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);
@@ -866,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, " - -");
@@ -925,7 +964,7 @@ static const char vermagic[] = VERMAGIC_STRING;
 static int try_to_force_load(struct module *mod, const char *symname)
 {
 #ifdef CONFIG_MODULE_FORCE_LOAD
-       if (!(tainted & TAINT_FORCED_MODULE))
+       if (!test_taint(TAINT_FORCED_MODULE))
                printk("%s: no version for \"%s\" found: kernel tainted.\n",
                       mod->name, symname);
        add_taint_module(mod, TAINT_FORCED_MODULE);
@@ -1035,7 +1074,7 @@ static unsigned long resolve_symbol(Elf_Shdr *sechdrs,
        const unsigned long *crc;
 
        ret = find_symbol(name, &owner, &crc,
-                         !(mod->taints & TAINT_PROPRIETARY_MODULE), true);
+                         !(mod->taints & (1 << TAINT_PROPRIETARY_MODULE)), true);
        if (!IS_ERR_VALUE(ret)) {
                /* use_module can fail due to OOM,
                   or module initialization or unloading */
@@ -1175,7 +1214,7 @@ static void free_notes_attrs(struct module_notes_attrs *notes_attrs,
                while (i-- > 0)
                        sysfs_remove_bin_file(notes_attrs->dir,
                                              &notes_attrs->attrs[i]);
-               kobject_del(notes_attrs->dir);
+               kobject_put(notes_attrs->dir);
        }
        kfree(notes_attrs);
 }
@@ -1393,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
  */
@@ -1423,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);
 
@@ -1559,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;
@@ -1603,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)
@@ -1621,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);
                }
@@ -1636,7 +1678,7 @@ static void set_license(struct module *mod, const char *license)
                license = "unspecified";
 
        if (!license_is_gpl_compatible(license)) {
-               if (!(tainted & TAINT_PROPRIETARY_MODULE))
+               if (!test_taint(TAINT_PROPRIETARY_MODULE))
                        printk(KERN_WARNING "%s: module license '%s' taints "
                                "kernel.\n", mod->name, license);
                add_taint_module(mod, TAINT_PROPRIETARY_MODULE);
@@ -1706,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 */
@@ -1785,6 +1827,21 @@ static inline void add_kallsyms(struct module *mod,
 }
 #endif /* CONFIG_KALLSYMS */
 
+static void dynamic_printk_setup(struct mod_debug *debug, unsigned int num)
+{
+#ifdef CONFIG_DYNAMIC_PRINTK_DEBUG
+       unsigned int i;
+
+       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);
+       }
+#endif /* CONFIG_DYNAMIC_PRINTK_DEBUG */
+}
+
 static void *module_alloc_update_bounds(unsigned long size)
 {
        void *ret = module_alloc(size);
@@ -1808,38 +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 tracepointsindex;
-       unsigned int tracepointsstringsindex;
-       unsigned int mcountindex;
+       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",
@@ -1851,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;
@@ -1903,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) {
@@ -1912,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;
@@ -1943,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)) {
@@ -1965,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)) {
@@ -2043,6 +2074,14 @@ static noinline struct module *load_module(void __user *umod,
        /* Module has been moved. */
        mod = (void *)sechdrs[modindex].sh_addr;
 
+#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_init;
+       }
+#endif
        /* Now we've moved module, initialize linked lists, etc. */
        module_unload_init(mod);
 
@@ -2075,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);
@@ -2119,15 +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");
-       tracepointsindex = find_sec(hdr, sechdrs, secstrings, "__tracepoints");
-       tracepointsstringsindex = find_sec(hdr, sechdrs, secstrings,
-                                       "__tracepoints_strings");
-
-       mcountindex = find_sec(hdr, sechdrs, secstrings,
-                              "__mcount_loc");
 
        /* Now do relocations. */
        for (i = 1; i < hdr->e_shnum; i++) {
@@ -2150,28 +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
-#ifdef CONFIG_TRACEPOINTS
-       mod->tracepoints = (void *)sechdrs[tracepointsindex].sh_addr;
-       mod->num_tracepoints =
-               sechdrs[tracepointsindex].sh_size / sizeof(*mod->tracepoints);
-#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,
@@ -2180,21 +2213,19 @@ static noinline struct module *load_module(void __user *umod,
        add_kallsyms(mod, sechdrs, symindex, strindex, secstrings);
 
        if (!mod->taints) {
-#ifdef CONFIG_MARKERS
-               marker_update_probe_range(mod->markers,
-                       mod->markers + mod->num_markers);
-#endif
-#ifdef CONFIG_TRACEPOINTS
-               tracepoint_update_probe_range(mod->tracepoints,
-                       mod->tracepoints + mod->num_tracepoints);
-#endif
-       }
+               struct mod_debug *debug;
+               unsigned int num_debug;
 
-       if (mcountindex) {
-               void *mseg = (void *)sechdrs[mcountindex].sh_addr;
-               ftrace_init_module(mseg, mseg + sechdrs[mcountindex].sh_size);
+               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;
@@ -2218,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;
 
@@ -2264,11 +2285,17 @@ 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);
+ free_init:
+#if defined(CONFIG_MODULE_UNLOAD) && defined(CONFIG_SMP)
+       percpu_modfree(mod->refptr);
+#endif
        module_free(mod, mod->module_init);
  free_core:
        module_free(mod, mod->module_core);
+       /* mod will be freed with core. Don't access it beyond this line! */
  free_percpu:
        if (percpu)
                percpu_modfree(percpu);
@@ -2276,6 +2303,7 @@ static noinline struct module *load_module(void __user *umod,
        kfree(args);
  free_hdr:
        vfree(hdr);
+       stop_machine_destroy();
        return ERR_PTR(err);
 
  truncated:
@@ -2285,10 +2313,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;
@@ -2343,11 +2369,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;
@@ -2382,7 +2409,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;
@@ -2429,9 +2456,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);
@@ -2452,9 +2479,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);
@@ -2476,9 +2503,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);
@@ -2503,14 +2530,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;
                }
@@ -2546,7 +2573,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;
        }
@@ -2555,23 +2582,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;
@@ -2580,10 +2590,12 @@ static char *module_flags(struct module *mod, char *buf)
            mod->state == MODULE_STATE_GOING ||
            mod->state == MODULE_STATE_COMING) {
                buf[bx++] = '(';
-               if (mod->taints & TAINT_PROPRIETARY_MODULE)
+               if (mod->taints & (1 << TAINT_PROPRIETARY_MODULE))
                        buf[bx++] = 'P';
-               if (mod->taints & TAINT_FORCED_MODULE)
+               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
@@ -2603,6 +2615,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);
@@ -2633,13 +2663,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)
 {
@@ -2647,7 +2697,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;
 
@@ -2673,8 +2723,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;
                }
@@ -2687,14 +2737,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;
@@ -2719,8 +2769,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");