diff options
Diffstat (limited to 'kernel/module.c')
-rw-r--r-- | kernel/module.c | 284 |
1 files changed, 122 insertions, 162 deletions
diff --git a/kernel/module.c b/kernel/module.c index 0d8d21ee792c..c0f1826e2d9e 100644 --- a/kernel/module.c +++ b/kernel/module.c | |||
@@ -42,6 +42,7 @@ | |||
42 | #include <linux/string.h> | 42 | #include <linux/string.h> |
43 | #include <linux/mutex.h> | 43 | #include <linux/mutex.h> |
44 | #include <linux/unwind.h> | 44 | #include <linux/unwind.h> |
45 | #include <linux/rculist.h> | ||
45 | #include <asm/uaccess.h> | 46 | #include <asm/uaccess.h> |
46 | #include <asm/cacheflush.h> | 47 | #include <asm/cacheflush.h> |
47 | #include <linux/license.h> | 48 | #include <linux/license.h> |
@@ -63,7 +64,7 @@ | |||
63 | #define INIT_OFFSET_MASK (1UL << (BITS_PER_LONG-1)) | 64 | #define INIT_OFFSET_MASK (1UL << (BITS_PER_LONG-1)) |
64 | 65 | ||
65 | /* List of modules, protected by module_mutex or preempt_disable | 66 | /* List of modules, protected by module_mutex or preempt_disable |
66 | * (add/delete uses stop_machine). */ | 67 | * (delete uses stop_machine/add uses RCU list operations). */ |
67 | static DEFINE_MUTEX(module_mutex); | 68 | static DEFINE_MUTEX(module_mutex); |
68 | static LIST_HEAD(modules); | 69 | static LIST_HEAD(modules); |
69 | 70 | ||
@@ -132,6 +133,29 @@ static unsigned int find_sec(Elf_Ehdr *hdr, | |||
132 | return 0; | 133 | return 0; |
133 | } | 134 | } |
134 | 135 | ||
136 | /* Find a module section, or NULL. */ | ||
137 | static void *section_addr(Elf_Ehdr *hdr, Elf_Shdr *shdrs, | ||
138 | const char *secstrings, const char *name) | ||
139 | { | ||
140 | /* Section 0 has sh_addr 0. */ | ||
141 | return (void *)shdrs[find_sec(hdr, shdrs, secstrings, name)].sh_addr; | ||
142 | } | ||
143 | |||
144 | /* Find a module section, or NULL. Fill in number of "objects" in section. */ | ||
145 | static void *section_objs(Elf_Ehdr *hdr, | ||
146 | Elf_Shdr *sechdrs, | ||
147 | const char *secstrings, | ||
148 | const char *name, | ||
149 | size_t object_size, | ||
150 | unsigned int *num) | ||
151 | { | ||
152 | unsigned int sec = find_sec(hdr, sechdrs, secstrings, name); | ||
153 | |||
154 | /* Section 0 has sh_addr 0 and sh_size 0. */ | ||
155 | *num = sechdrs[sec].sh_size / object_size; | ||
156 | return (void *)sechdrs[sec].sh_addr; | ||
157 | } | ||
158 | |||
135 | /* Provided by the linker */ | 159 | /* Provided by the linker */ |
136 | extern const struct kernel_symbol __start___ksymtab[]; | 160 | extern const struct kernel_symbol __start___ksymtab[]; |
137 | extern const struct kernel_symbol __stop___ksymtab[]; | 161 | extern const struct kernel_symbol __stop___ksymtab[]; |
@@ -218,7 +242,7 @@ static bool each_symbol(bool (*fn)(const struct symsearch *arr, | |||
218 | if (each_symbol_in_section(arr, ARRAY_SIZE(arr), NULL, fn, data)) | 242 | if (each_symbol_in_section(arr, ARRAY_SIZE(arr), NULL, fn, data)) |
219 | return true; | 243 | return true; |
220 | 244 | ||
221 | list_for_each_entry(mod, &modules, list) { | 245 | list_for_each_entry_rcu(mod, &modules, list) { |
222 | struct symsearch arr[] = { | 246 | struct symsearch arr[] = { |
223 | { mod->syms, mod->syms + mod->num_syms, mod->crcs, | 247 | { mod->syms, mod->syms + mod->num_syms, mod->crcs, |
224 | NOT_GPL_ONLY, false }, | 248 | NOT_GPL_ONLY, false }, |
@@ -1394,17 +1418,6 @@ static void mod_kobject_remove(struct module *mod) | |||
1394 | } | 1418 | } |
1395 | 1419 | ||
1396 | /* | 1420 | /* |
1397 | * link the module with the whole machine is stopped with interrupts off | ||
1398 | * - this defends against kallsyms not taking locks | ||
1399 | */ | ||
1400 | static int __link_module(void *_mod) | ||
1401 | { | ||
1402 | struct module *mod = _mod; | ||
1403 | list_add(&mod->list, &modules); | ||
1404 | return 0; | ||
1405 | } | ||
1406 | |||
1407 | /* | ||
1408 | * unlink the module with the whole machine is stopped with interrupts off | 1421 | * unlink the module with the whole machine is stopped with interrupts off |
1409 | * - this defends against kallsyms not taking locks | 1422 | * - this defends against kallsyms not taking locks |
1410 | */ | 1423 | */ |
@@ -1789,32 +1802,20 @@ static inline void add_kallsyms(struct module *mod, | |||
1789 | } | 1802 | } |
1790 | #endif /* CONFIG_KALLSYMS */ | 1803 | #endif /* CONFIG_KALLSYMS */ |
1791 | 1804 | ||
1792 | #ifdef CONFIG_DYNAMIC_PRINTK_DEBUG | 1805 | static void dynamic_printk_setup(struct mod_debug *debug, unsigned int num) |
1793 | static void dynamic_printk_setup(Elf_Shdr *sechdrs, unsigned int verboseindex) | ||
1794 | { | 1806 | { |
1795 | struct mod_debug *debug_info; | 1807 | #ifdef CONFIG_DYNAMIC_PRINTK_DEBUG |
1796 | unsigned long pos, end; | 1808 | unsigned int i; |
1797 | unsigned int num_verbose; | ||
1798 | |||
1799 | pos = sechdrs[verboseindex].sh_addr; | ||
1800 | num_verbose = sechdrs[verboseindex].sh_size / | ||
1801 | sizeof(struct mod_debug); | ||
1802 | end = pos + (num_verbose * sizeof(struct mod_debug)); | ||
1803 | 1809 | ||
1804 | for (; pos < end; pos += sizeof(struct mod_debug)) { | 1810 | for (i = 0; i < num; i++) { |
1805 | debug_info = (struct mod_debug *)pos; | 1811 | register_dynamic_debug_module(debug[i].modname, |
1806 | register_dynamic_debug_module(debug_info->modname, | 1812 | debug[i].type, |
1807 | debug_info->type, debug_info->logical_modname, | 1813 | debug[i].logical_modname, |
1808 | debug_info->flag_names, debug_info->hash, | 1814 | debug[i].flag_names, |
1809 | debug_info->hash2); | 1815 | debug[i].hash, debug[i].hash2); |
1810 | } | 1816 | } |
1811 | } | ||
1812 | #else | ||
1813 | static inline void dynamic_printk_setup(Elf_Shdr *sechdrs, | ||
1814 | unsigned int verboseindex) | ||
1815 | { | ||
1816 | } | ||
1817 | #endif /* CONFIG_DYNAMIC_PRINTK_DEBUG */ | 1817 | #endif /* CONFIG_DYNAMIC_PRINTK_DEBUG */ |
1818 | } | ||
1818 | 1819 | ||
1819 | static void *module_alloc_update_bounds(unsigned long size) | 1820 | static void *module_alloc_update_bounds(unsigned long size) |
1820 | { | 1821 | { |
@@ -1843,37 +1844,14 @@ static noinline struct module *load_module(void __user *umod, | |||
1843 | unsigned int i; | 1844 | unsigned int i; |
1844 | unsigned int symindex = 0; | 1845 | unsigned int symindex = 0; |
1845 | unsigned int strindex = 0; | 1846 | unsigned int strindex = 0; |
1846 | unsigned int setupindex; | 1847 | unsigned int modindex, versindex, infoindex, pcpuindex; |
1847 | unsigned int exindex; | ||
1848 | unsigned int exportindex; | ||
1849 | unsigned int modindex; | ||
1850 | unsigned int obsparmindex; | ||
1851 | unsigned int infoindex; | ||
1852 | unsigned int gplindex; | ||
1853 | unsigned int crcindex; | ||
1854 | unsigned int gplcrcindex; | ||
1855 | unsigned int versindex; | ||
1856 | unsigned int pcpuindex; | ||
1857 | unsigned int gplfutureindex; | ||
1858 | unsigned int gplfuturecrcindex; | ||
1859 | unsigned int unwindex = 0; | 1848 | unsigned int unwindex = 0; |
1860 | #ifdef CONFIG_UNUSED_SYMBOLS | 1849 | unsigned int num_kp, num_mcount; |
1861 | unsigned int unusedindex; | 1850 | struct kernel_param *kp; |
1862 | unsigned int unusedcrcindex; | ||
1863 | unsigned int unusedgplindex; | ||
1864 | unsigned int unusedgplcrcindex; | ||
1865 | #endif | ||
1866 | unsigned int markersindex; | ||
1867 | unsigned int markersstringsindex; | ||
1868 | unsigned int verboseindex; | ||
1869 | unsigned int tracepointsindex; | ||
1870 | unsigned int tracepointsstringsindex; | ||
1871 | unsigned int mcountindex; | ||
1872 | struct module *mod; | 1851 | struct module *mod; |
1873 | long err = 0; | 1852 | long err = 0; |
1874 | void *percpu = NULL, *ptr = NULL; /* Stops spurious gcc warning */ | 1853 | void *percpu = NULL, *ptr = NULL; /* Stops spurious gcc warning */ |
1875 | void *mseg; | 1854 | unsigned long *mseg; |
1876 | struct exception_table_entry *extable; | ||
1877 | mm_segment_t old_fs; | 1855 | mm_segment_t old_fs; |
1878 | 1856 | ||
1879 | DEBUGP("load_module: umod=%p, len=%lu, uargs=%p\n", | 1857 | DEBUGP("load_module: umod=%p, len=%lu, uargs=%p\n", |
@@ -1937,6 +1915,7 @@ static noinline struct module *load_module(void __user *umod, | |||
1937 | err = -ENOEXEC; | 1915 | err = -ENOEXEC; |
1938 | goto free_hdr; | 1916 | goto free_hdr; |
1939 | } | 1917 | } |
1918 | /* This is temporary: point mod into copy of data. */ | ||
1940 | mod = (void *)sechdrs[modindex].sh_addr; | 1919 | mod = (void *)sechdrs[modindex].sh_addr; |
1941 | 1920 | ||
1942 | if (symindex == 0) { | 1921 | if (symindex == 0) { |
@@ -1946,22 +1925,6 @@ static noinline struct module *load_module(void __user *umod, | |||
1946 | goto free_hdr; | 1925 | goto free_hdr; |
1947 | } | 1926 | } |
1948 | 1927 | ||
1949 | /* Optional sections */ | ||
1950 | exportindex = find_sec(hdr, sechdrs, secstrings, "__ksymtab"); | ||
1951 | gplindex = find_sec(hdr, sechdrs, secstrings, "__ksymtab_gpl"); | ||
1952 | gplfutureindex = find_sec(hdr, sechdrs, secstrings, "__ksymtab_gpl_future"); | ||
1953 | crcindex = find_sec(hdr, sechdrs, secstrings, "__kcrctab"); | ||
1954 | gplcrcindex = find_sec(hdr, sechdrs, secstrings, "__kcrctab_gpl"); | ||
1955 | gplfuturecrcindex = find_sec(hdr, sechdrs, secstrings, "__kcrctab_gpl_future"); | ||
1956 | #ifdef CONFIG_UNUSED_SYMBOLS | ||
1957 | unusedindex = find_sec(hdr, sechdrs, secstrings, "__ksymtab_unused"); | ||
1958 | unusedgplindex = find_sec(hdr, sechdrs, secstrings, "__ksymtab_unused_gpl"); | ||
1959 | unusedcrcindex = find_sec(hdr, sechdrs, secstrings, "__kcrctab_unused"); | ||
1960 | unusedgplcrcindex = find_sec(hdr, sechdrs, secstrings, "__kcrctab_unused_gpl"); | ||
1961 | #endif | ||
1962 | setupindex = find_sec(hdr, sechdrs, secstrings, "__param"); | ||
1963 | exindex = find_sec(hdr, sechdrs, secstrings, "__ex_table"); | ||
1964 | obsparmindex = find_sec(hdr, sechdrs, secstrings, "__obsparm"); | ||
1965 | versindex = find_sec(hdr, sechdrs, secstrings, "__versions"); | 1928 | versindex = find_sec(hdr, sechdrs, secstrings, "__versions"); |
1966 | infoindex = find_sec(hdr, sechdrs, secstrings, ".modinfo"); | 1929 | infoindex = find_sec(hdr, sechdrs, secstrings, ".modinfo"); |
1967 | pcpuindex = find_pcpusec(hdr, sechdrs, secstrings); | 1930 | pcpuindex = find_pcpusec(hdr, sechdrs, secstrings); |
@@ -2117,42 +2080,57 @@ static noinline struct module *load_module(void __user *umod, | |||
2117 | if (err < 0) | 2080 | if (err < 0) |
2118 | goto cleanup; | 2081 | goto cleanup; |
2119 | 2082 | ||
2120 | /* Set up EXPORTed & EXPORT_GPLed symbols (section 0 is 0 length) */ | 2083 | /* Now we've got everything in the final locations, we can |
2121 | mod->num_syms = sechdrs[exportindex].sh_size / sizeof(*mod->syms); | 2084 | * find optional sections. */ |
2122 | mod->syms = (void *)sechdrs[exportindex].sh_addr; | 2085 | kp = section_objs(hdr, sechdrs, secstrings, "__param", sizeof(*kp), |
2123 | if (crcindex) | 2086 | &num_kp); |
2124 | mod->crcs = (void *)sechdrs[crcindex].sh_addr; | 2087 | mod->syms = section_objs(hdr, sechdrs, secstrings, "__ksymtab", |
2125 | mod->num_gpl_syms = sechdrs[gplindex].sh_size / sizeof(*mod->gpl_syms); | 2088 | sizeof(*mod->syms), &mod->num_syms); |
2126 | mod->gpl_syms = (void *)sechdrs[gplindex].sh_addr; | 2089 | mod->crcs = section_addr(hdr, sechdrs, secstrings, "__kcrctab"); |
2127 | if (gplcrcindex) | 2090 | mod->gpl_syms = section_objs(hdr, sechdrs, secstrings, "__ksymtab_gpl", |
2128 | mod->gpl_crcs = (void *)sechdrs[gplcrcindex].sh_addr; | 2091 | sizeof(*mod->gpl_syms), |
2129 | mod->num_gpl_future_syms = sechdrs[gplfutureindex].sh_size / | 2092 | &mod->num_gpl_syms); |
2130 | sizeof(*mod->gpl_future_syms); | 2093 | mod->gpl_crcs = section_addr(hdr, sechdrs, secstrings, "__kcrctab_gpl"); |
2131 | mod->gpl_future_syms = (void *)sechdrs[gplfutureindex].sh_addr; | 2094 | mod->gpl_future_syms = section_objs(hdr, sechdrs, secstrings, |
2132 | if (gplfuturecrcindex) | 2095 | "__ksymtab_gpl_future", |
2133 | mod->gpl_future_crcs = (void *)sechdrs[gplfuturecrcindex].sh_addr; | 2096 | sizeof(*mod->gpl_future_syms), |
2097 | &mod->num_gpl_future_syms); | ||
2098 | mod->gpl_future_crcs = section_addr(hdr, sechdrs, secstrings, | ||
2099 | "__kcrctab_gpl_future"); | ||
2134 | 2100 | ||
2135 | #ifdef CONFIG_UNUSED_SYMBOLS | 2101 | #ifdef CONFIG_UNUSED_SYMBOLS |
2136 | mod->num_unused_syms = sechdrs[unusedindex].sh_size / | 2102 | mod->unused_syms = section_objs(hdr, sechdrs, secstrings, |
2137 | sizeof(*mod->unused_syms); | 2103 | "__ksymtab_unused", |
2138 | mod->num_unused_gpl_syms = sechdrs[unusedgplindex].sh_size / | 2104 | sizeof(*mod->unused_syms), |
2139 | sizeof(*mod->unused_gpl_syms); | 2105 | &mod->num_unused_syms); |
2140 | mod->unused_syms = (void *)sechdrs[unusedindex].sh_addr; | 2106 | mod->unused_crcs = section_addr(hdr, sechdrs, secstrings, |
2141 | if (unusedcrcindex) | 2107 | "__kcrctab_unused"); |
2142 | mod->unused_crcs = (void *)sechdrs[unusedcrcindex].sh_addr; | 2108 | mod->unused_gpl_syms = section_objs(hdr, sechdrs, secstrings, |
2143 | mod->unused_gpl_syms = (void *)sechdrs[unusedgplindex].sh_addr; | 2109 | "__ksymtab_unused_gpl", |
2144 | if (unusedgplcrcindex) | 2110 | sizeof(*mod->unused_gpl_syms), |
2145 | mod->unused_gpl_crcs | 2111 | &mod->num_unused_gpl_syms); |
2146 | = (void *)sechdrs[unusedgplcrcindex].sh_addr; | 2112 | mod->unused_gpl_crcs = section_addr(hdr, sechdrs, secstrings, |
2113 | "__kcrctab_unused_gpl"); | ||
2114 | #endif | ||
2115 | |||
2116 | #ifdef CONFIG_MARKERS | ||
2117 | mod->markers = section_objs(hdr, sechdrs, secstrings, "__markers", | ||
2118 | sizeof(*mod->markers), &mod->num_markers); | ||
2119 | #endif | ||
2120 | #ifdef CONFIG_TRACEPOINTS | ||
2121 | mod->tracepoints = section_objs(hdr, sechdrs, secstrings, | ||
2122 | "__tracepoints", | ||
2123 | sizeof(*mod->tracepoints), | ||
2124 | &mod->num_tracepoints); | ||
2147 | #endif | 2125 | #endif |
2148 | 2126 | ||
2149 | #ifdef CONFIG_MODVERSIONS | 2127 | #ifdef CONFIG_MODVERSIONS |
2150 | if ((mod->num_syms && !crcindex) | 2128 | if ((mod->num_syms && !mod->crcs) |
2151 | || (mod->num_gpl_syms && !gplcrcindex) | 2129 | || (mod->num_gpl_syms && !mod->gpl_crcs) |
2152 | || (mod->num_gpl_future_syms && !gplfuturecrcindex) | 2130 | || (mod->num_gpl_future_syms && !mod->gpl_future_crcs) |
2153 | #ifdef CONFIG_UNUSED_SYMBOLS | 2131 | #ifdef CONFIG_UNUSED_SYMBOLS |
2154 | || (mod->num_unused_syms && !unusedcrcindex) | 2132 | || (mod->num_unused_syms && !mod->unused_crcs) |
2155 | || (mod->num_unused_gpl_syms && !unusedgplcrcindex) | 2133 | || (mod->num_unused_gpl_syms && !mod->unused_gpl_crcs) |
2156 | #endif | 2134 | #endif |
2157 | ) { | 2135 | ) { |
2158 | printk(KERN_WARNING "%s: No versions for exported symbols.\n", mod->name); | 2136 | printk(KERN_WARNING "%s: No versions for exported symbols.\n", mod->name); |
@@ -2161,16 +2139,6 @@ static noinline struct module *load_module(void __user *umod, | |||
2161 | goto cleanup; | 2139 | goto cleanup; |
2162 | } | 2140 | } |
2163 | #endif | 2141 | #endif |
2164 | markersindex = find_sec(hdr, sechdrs, secstrings, "__markers"); | ||
2165 | markersstringsindex = find_sec(hdr, sechdrs, secstrings, | ||
2166 | "__markers_strings"); | ||
2167 | verboseindex = find_sec(hdr, sechdrs, secstrings, "__verbose"); | ||
2168 | tracepointsindex = find_sec(hdr, sechdrs, secstrings, "__tracepoints"); | ||
2169 | tracepointsstringsindex = find_sec(hdr, sechdrs, secstrings, | ||
2170 | "__tracepoints_strings"); | ||
2171 | |||
2172 | mcountindex = find_sec(hdr, sechdrs, secstrings, | ||
2173 | "__mcount_loc"); | ||
2174 | 2142 | ||
2175 | /* Now do relocations. */ | 2143 | /* Now do relocations. */ |
2176 | for (i = 1; i < hdr->e_shnum; i++) { | 2144 | for (i = 1; i < hdr->e_shnum; i++) { |
@@ -2193,28 +2161,16 @@ static noinline struct module *load_module(void __user *umod, | |||
2193 | if (err < 0) | 2161 | if (err < 0) |
2194 | goto cleanup; | 2162 | goto cleanup; |
2195 | } | 2163 | } |
2196 | #ifdef CONFIG_MARKERS | ||
2197 | mod->markers = (void *)sechdrs[markersindex].sh_addr; | ||
2198 | mod->num_markers = | ||
2199 | sechdrs[markersindex].sh_size / sizeof(*mod->markers); | ||
2200 | #endif | ||
2201 | #ifdef CONFIG_TRACEPOINTS | ||
2202 | mod->tracepoints = (void *)sechdrs[tracepointsindex].sh_addr; | ||
2203 | mod->num_tracepoints = | ||
2204 | sechdrs[tracepointsindex].sh_size / sizeof(*mod->tracepoints); | ||
2205 | #endif | ||
2206 | |||
2207 | 2164 | ||
2208 | /* Find duplicate symbols */ | 2165 | /* Find duplicate symbols */ |
2209 | err = verify_export_symbols(mod); | 2166 | err = verify_export_symbols(mod); |
2210 | |||
2211 | if (err < 0) | 2167 | if (err < 0) |
2212 | goto cleanup; | 2168 | goto cleanup; |
2213 | 2169 | ||
2214 | /* Set up and sort exception table */ | 2170 | /* Set up and sort exception table */ |
2215 | mod->num_exentries = sechdrs[exindex].sh_size / sizeof(*mod->extable); | 2171 | mod->extable = section_objs(hdr, sechdrs, secstrings, "__ex_table", |
2216 | mod->extable = extable = (void *)sechdrs[exindex].sh_addr; | 2172 | sizeof(*mod->extable), &mod->num_exentries); |
2217 | sort_extable(extable, extable + mod->num_exentries); | 2173 | sort_extable(mod->extable, mod->extable + mod->num_exentries); |
2218 | 2174 | ||
2219 | /* Finally, copy percpu area over. */ | 2175 | /* Finally, copy percpu area over. */ |
2220 | percpu_modcopy(mod->percpu, (void *)sechdrs[pcpuindex].sh_addr, | 2176 | percpu_modcopy(mod->percpu, (void *)sechdrs[pcpuindex].sh_addr, |
@@ -2223,11 +2179,17 @@ static noinline struct module *load_module(void __user *umod, | |||
2223 | add_kallsyms(mod, sechdrs, symindex, strindex, secstrings); | 2179 | add_kallsyms(mod, sechdrs, symindex, strindex, secstrings); |
2224 | 2180 | ||
2225 | if (!mod->taints) { | 2181 | if (!mod->taints) { |
2182 | struct mod_debug *debug; | ||
2183 | unsigned int num_debug; | ||
2184 | |||
2226 | #ifdef CONFIG_MARKERS | 2185 | #ifdef CONFIG_MARKERS |
2227 | marker_update_probe_range(mod->markers, | 2186 | marker_update_probe_range(mod->markers, |
2228 | mod->markers + mod->num_markers); | 2187 | mod->markers + mod->num_markers); |
2229 | #endif | 2188 | #endif |
2230 | dynamic_printk_setup(sechdrs, verboseindex); | 2189 | debug = section_objs(hdr, sechdrs, secstrings, "__verbose", |
2190 | sizeof(*debug), &num_debug); | ||
2191 | dynamic_printk_setup(debug, num_debug); | ||
2192 | |||
2231 | #ifdef CONFIG_TRACEPOINTS | 2193 | #ifdef CONFIG_TRACEPOINTS |
2232 | tracepoint_update_probe_range(mod->tracepoints, | 2194 | tracepoint_update_probe_range(mod->tracepoints, |
2233 | mod->tracepoints + mod->num_tracepoints); | 2195 | mod->tracepoints + mod->num_tracepoints); |
@@ -2235,8 +2197,9 @@ static noinline struct module *load_module(void __user *umod, | |||
2235 | } | 2197 | } |
2236 | 2198 | ||
2237 | /* sechdrs[0].sh_size is always zero */ | 2199 | /* sechdrs[0].sh_size is always zero */ |
2238 | mseg = (void *)sechdrs[mcountindex].sh_addr; | 2200 | mseg = section_objs(hdr, sechdrs, secstrings, "__mcount_loc", |
2239 | ftrace_init_module(mseg, mseg + sechdrs[mcountindex].sh_size); | 2201 | sizeof(*mseg), &num_mcount); |
2202 | ftrace_init_module(mseg, mseg + num_mcount); | ||
2240 | 2203 | ||
2241 | err = module_finalize(hdr, sechdrs, mod); | 2204 | err = module_finalize(hdr, sechdrs, mod); |
2242 | if (err < 0) | 2205 | if (err < 0) |
@@ -2261,30 +2224,24 @@ static noinline struct module *load_module(void __user *umod, | |||
2261 | set_fs(old_fs); | 2224 | set_fs(old_fs); |
2262 | 2225 | ||
2263 | mod->args = args; | 2226 | mod->args = args; |
2264 | if (obsparmindex) | 2227 | if (section_addr(hdr, sechdrs, secstrings, "__obsparm")) |
2265 | printk(KERN_WARNING "%s: Ignoring obsolete parameters\n", | 2228 | printk(KERN_WARNING "%s: Ignoring obsolete parameters\n", |
2266 | mod->name); | 2229 | mod->name); |
2267 | 2230 | ||
2268 | /* Now sew it into the lists so we can get lockdep and oops | 2231 | /* Now sew it into the lists so we can get lockdep and oops |
2269 | * info during argument parsing. Noone should access us, since | 2232 | * info during argument parsing. Noone should access us, since |
2270 | * strong_try_module_get() will fail. */ | 2233 | * strong_try_module_get() will fail. |
2271 | stop_machine(__link_module, mod, NULL); | 2234 | * lockdep/oops can run asynchronous, so use the RCU list insertion |
2272 | 2235 | * function to insert in a way safe to concurrent readers. | |
2273 | /* Size of section 0 is 0, so this works well if no params */ | 2236 | * The mutex protects against concurrent writers. |
2274 | err = parse_args(mod->name, mod->args, | 2237 | */ |
2275 | (struct kernel_param *) | 2238 | list_add_rcu(&mod->list, &modules); |
2276 | sechdrs[setupindex].sh_addr, | 2239 | |
2277 | sechdrs[setupindex].sh_size | 2240 | err = parse_args(mod->name, mod->args, kp, num_kp, NULL); |
2278 | / sizeof(struct kernel_param), | ||
2279 | NULL); | ||
2280 | if (err < 0) | 2241 | if (err < 0) |
2281 | goto unlink; | 2242 | goto unlink; |
2282 | 2243 | ||
2283 | err = mod_sysfs_setup(mod, | 2244 | err = mod_sysfs_setup(mod, kp, num_kp); |
2284 | (struct kernel_param *) | ||
2285 | sechdrs[setupindex].sh_addr, | ||
2286 | sechdrs[setupindex].sh_size | ||
2287 | / sizeof(struct kernel_param)); | ||
2288 | if (err < 0) | 2245 | if (err < 0) |
2289 | goto unlink; | 2246 | goto unlink; |
2290 | add_sect_attrs(mod, hdr->e_shnum, secstrings, sechdrs); | 2247 | add_sect_attrs(mod, hdr->e_shnum, secstrings, sechdrs); |
@@ -2473,7 +2430,7 @@ const char *module_address_lookup(unsigned long addr, | |||
2473 | const char *ret = NULL; | 2430 | const char *ret = NULL; |
2474 | 2431 | ||
2475 | preempt_disable(); | 2432 | preempt_disable(); |
2476 | list_for_each_entry(mod, &modules, list) { | 2433 | list_for_each_entry_rcu(mod, &modules, list) { |
2477 | if (within(addr, mod->module_init, mod->init_size) | 2434 | if (within(addr, mod->module_init, mod->init_size) |
2478 | || within(addr, mod->module_core, mod->core_size)) { | 2435 | || within(addr, mod->module_core, mod->core_size)) { |
2479 | if (modname) | 2436 | if (modname) |
@@ -2496,7 +2453,7 @@ int lookup_module_symbol_name(unsigned long addr, char *symname) | |||
2496 | struct module *mod; | 2453 | struct module *mod; |
2497 | 2454 | ||
2498 | preempt_disable(); | 2455 | preempt_disable(); |
2499 | list_for_each_entry(mod, &modules, list) { | 2456 | list_for_each_entry_rcu(mod, &modules, list) { |
2500 | if (within(addr, mod->module_init, mod->init_size) || | 2457 | if (within(addr, mod->module_init, mod->init_size) || |
2501 | within(addr, mod->module_core, mod->core_size)) { | 2458 | within(addr, mod->module_core, mod->core_size)) { |
2502 | const char *sym; | 2459 | const char *sym; |
@@ -2520,7 +2477,7 @@ int lookup_module_symbol_attrs(unsigned long addr, unsigned long *size, | |||
2520 | struct module *mod; | 2477 | struct module *mod; |
2521 | 2478 | ||
2522 | preempt_disable(); | 2479 | preempt_disable(); |
2523 | list_for_each_entry(mod, &modules, list) { | 2480 | list_for_each_entry_rcu(mod, &modules, list) { |
2524 | if (within(addr, mod->module_init, mod->init_size) || | 2481 | if (within(addr, mod->module_init, mod->init_size) || |
2525 | within(addr, mod->module_core, mod->core_size)) { | 2482 | within(addr, mod->module_core, mod->core_size)) { |
2526 | const char *sym; | 2483 | const char *sym; |
@@ -2547,7 +2504,7 @@ int module_get_kallsym(unsigned int symnum, unsigned long *value, char *type, | |||
2547 | struct module *mod; | 2504 | struct module *mod; |
2548 | 2505 | ||
2549 | preempt_disable(); | 2506 | preempt_disable(); |
2550 | list_for_each_entry(mod, &modules, list) { | 2507 | list_for_each_entry_rcu(mod, &modules, list) { |
2551 | if (symnum < mod->num_symtab) { | 2508 | if (symnum < mod->num_symtab) { |
2552 | *value = mod->symtab[symnum].st_value; | 2509 | *value = mod->symtab[symnum].st_value; |
2553 | *type = mod->symtab[symnum].st_info; | 2510 | *type = mod->symtab[symnum].st_info; |
@@ -2590,7 +2547,7 @@ unsigned long module_kallsyms_lookup_name(const char *name) | |||
2590 | ret = mod_find_symname(mod, colon+1); | 2547 | ret = mod_find_symname(mod, colon+1); |
2591 | *colon = ':'; | 2548 | *colon = ':'; |
2592 | } else { | 2549 | } else { |
2593 | list_for_each_entry(mod, &modules, list) | 2550 | list_for_each_entry_rcu(mod, &modules, list) |
2594 | if ((ret = mod_find_symname(mod, name)) != 0) | 2551 | if ((ret = mod_find_symname(mod, name)) != 0) |
2595 | break; | 2552 | break; |
2596 | } | 2553 | } |
@@ -2693,7 +2650,7 @@ const struct exception_table_entry *search_module_extables(unsigned long addr) | |||
2693 | struct module *mod; | 2650 | struct module *mod; |
2694 | 2651 | ||
2695 | preempt_disable(); | 2652 | preempt_disable(); |
2696 | list_for_each_entry(mod, &modules, list) { | 2653 | list_for_each_entry_rcu(mod, &modules, list) { |
2697 | if (mod->num_exentries == 0) | 2654 | if (mod->num_exentries == 0) |
2698 | continue; | 2655 | continue; |
2699 | 2656 | ||
@@ -2719,7 +2676,7 @@ int is_module_address(unsigned long addr) | |||
2719 | 2676 | ||
2720 | preempt_disable(); | 2677 | preempt_disable(); |
2721 | 2678 | ||
2722 | list_for_each_entry(mod, &modules, list) { | 2679 | list_for_each_entry_rcu(mod, &modules, list) { |
2723 | if (within(addr, mod->module_core, mod->core_size)) { | 2680 | if (within(addr, mod->module_core, mod->core_size)) { |
2724 | preempt_enable(); | 2681 | preempt_enable(); |
2725 | return 1; | 2682 | return 1; |
@@ -2740,7 +2697,7 @@ struct module *__module_text_address(unsigned long addr) | |||
2740 | if (addr < module_addr_min || addr > module_addr_max) | 2697 | if (addr < module_addr_min || addr > module_addr_max) |
2741 | return NULL; | 2698 | return NULL; |
2742 | 2699 | ||
2743 | list_for_each_entry(mod, &modules, list) | 2700 | list_for_each_entry_rcu(mod, &modules, list) |
2744 | if (within(addr, mod->module_init, mod->init_text_size) | 2701 | if (within(addr, mod->module_init, mod->init_text_size) |
2745 | || within(addr, mod->module_core, mod->core_text_size)) | 2702 | || within(addr, mod->module_core, mod->core_text_size)) |
2746 | return mod; | 2703 | return mod; |
@@ -2765,8 +2722,11 @@ void print_modules(void) | |||
2765 | char buf[8]; | 2722 | char buf[8]; |
2766 | 2723 | ||
2767 | printk("Modules linked in:"); | 2724 | printk("Modules linked in:"); |
2768 | list_for_each_entry(mod, &modules, list) | 2725 | /* Most callers should already have preempt disabled, but make sure */ |
2726 | preempt_disable(); | ||
2727 | list_for_each_entry_rcu(mod, &modules, list) | ||
2769 | printk(" %s%s", mod->name, module_flags(mod, buf)); | 2728 | printk(" %s%s", mod->name, module_flags(mod, buf)); |
2729 | preempt_enable(); | ||
2770 | if (last_unloaded_module[0]) | 2730 | if (last_unloaded_module[0]) |
2771 | printk(" [last unloaded: %s]", last_unloaded_module); | 2731 | printk(" [last unloaded: %s]", last_unloaded_module); |
2772 | printk("\n"); | 2732 | printk("\n"); |