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