Commit 554bdfe5acf3715e87c8d5e25a4f9a896ac9f014

Authored by Jan Beulich
Committed by Rusty Russell
1 parent 4a4962263f

module: reduce string table for loaded modules (v2)

Also remove all parts of the string table (referenced by the symbol
table) that are not needed for kallsyms use (i.e. which were only
referenced by symbols discarded by the previous patch, or not
referenced at all for whatever reason).

Signed-off-by: Jan Beulich <jbeulich@novell.com>
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>

Showing 2 changed files with 57 additions and 13 deletions Inline Diff

include/linux/module.h
1 #ifndef _LINUX_MODULE_H 1 #ifndef _LINUX_MODULE_H
2 #define _LINUX_MODULE_H 2 #define _LINUX_MODULE_H
3 /* 3 /*
4 * Dynamic loading of modules into the kernel. 4 * Dynamic loading of modules into the kernel.
5 * 5 *
6 * Rewritten by Richard Henderson <rth@tamu.edu> Dec 1996 6 * Rewritten by Richard Henderson <rth@tamu.edu> Dec 1996
7 * Rewritten again by Rusty Russell, 2002 7 * Rewritten again by Rusty Russell, 2002
8 */ 8 */
9 #include <linux/list.h> 9 #include <linux/list.h>
10 #include <linux/stat.h> 10 #include <linux/stat.h>
11 #include <linux/compiler.h> 11 #include <linux/compiler.h>
12 #include <linux/cache.h> 12 #include <linux/cache.h>
13 #include <linux/kmod.h> 13 #include <linux/kmod.h>
14 #include <linux/elf.h> 14 #include <linux/elf.h>
15 #include <linux/stringify.h> 15 #include <linux/stringify.h>
16 #include <linux/kobject.h> 16 #include <linux/kobject.h>
17 #include <linux/moduleparam.h> 17 #include <linux/moduleparam.h>
18 #include <linux/tracepoint.h> 18 #include <linux/tracepoint.h>
19 19
20 #include <asm/local.h> 20 #include <asm/local.h>
21 #include <asm/module.h> 21 #include <asm/module.h>
22 22
23 #include <trace/events/module.h> 23 #include <trace/events/module.h>
24 24
25 /* Not Yet Implemented */ 25 /* Not Yet Implemented */
26 #define MODULE_SUPPORTED_DEVICE(name) 26 #define MODULE_SUPPORTED_DEVICE(name)
27 27
28 /* some toolchains uses a `_' prefix for all user symbols */ 28 /* some toolchains uses a `_' prefix for all user symbols */
29 #ifndef MODULE_SYMBOL_PREFIX 29 #ifndef MODULE_SYMBOL_PREFIX
30 #define MODULE_SYMBOL_PREFIX "" 30 #define MODULE_SYMBOL_PREFIX ""
31 #endif 31 #endif
32 32
33 #define MODULE_NAME_LEN MAX_PARAM_PREFIX_LEN 33 #define MODULE_NAME_LEN MAX_PARAM_PREFIX_LEN
34 34
35 struct kernel_symbol 35 struct kernel_symbol
36 { 36 {
37 unsigned long value; 37 unsigned long value;
38 const char *name; 38 const char *name;
39 }; 39 };
40 40
41 struct modversion_info 41 struct modversion_info
42 { 42 {
43 unsigned long crc; 43 unsigned long crc;
44 char name[MODULE_NAME_LEN]; 44 char name[MODULE_NAME_LEN];
45 }; 45 };
46 46
47 struct module; 47 struct module;
48 48
49 struct module_attribute { 49 struct module_attribute {
50 struct attribute attr; 50 struct attribute attr;
51 ssize_t (*show)(struct module_attribute *, struct module *, char *); 51 ssize_t (*show)(struct module_attribute *, struct module *, char *);
52 ssize_t (*store)(struct module_attribute *, struct module *, 52 ssize_t (*store)(struct module_attribute *, struct module *,
53 const char *, size_t count); 53 const char *, size_t count);
54 void (*setup)(struct module *, const char *); 54 void (*setup)(struct module *, const char *);
55 int (*test)(struct module *); 55 int (*test)(struct module *);
56 void (*free)(struct module *); 56 void (*free)(struct module *);
57 }; 57 };
58 58
59 struct module_kobject 59 struct module_kobject
60 { 60 {
61 struct kobject kobj; 61 struct kobject kobj;
62 struct module *mod; 62 struct module *mod;
63 struct kobject *drivers_dir; 63 struct kobject *drivers_dir;
64 struct module_param_attrs *mp; 64 struct module_param_attrs *mp;
65 }; 65 };
66 66
67 /* These are either module local, or the kernel's dummy ones. */ 67 /* These are either module local, or the kernel's dummy ones. */
68 extern int init_module(void); 68 extern int init_module(void);
69 extern void cleanup_module(void); 69 extern void cleanup_module(void);
70 70
71 /* Archs provide a method of finding the correct exception table. */ 71 /* Archs provide a method of finding the correct exception table. */
72 struct exception_table_entry; 72 struct exception_table_entry;
73 73
74 const struct exception_table_entry * 74 const struct exception_table_entry *
75 search_extable(const struct exception_table_entry *first, 75 search_extable(const struct exception_table_entry *first,
76 const struct exception_table_entry *last, 76 const struct exception_table_entry *last,
77 unsigned long value); 77 unsigned long value);
78 void sort_extable(struct exception_table_entry *start, 78 void sort_extable(struct exception_table_entry *start,
79 struct exception_table_entry *finish); 79 struct exception_table_entry *finish);
80 void sort_main_extable(void); 80 void sort_main_extable(void);
81 void trim_init_extable(struct module *m); 81 void trim_init_extable(struct module *m);
82 82
83 #ifdef MODULE 83 #ifdef MODULE
84 #define MODULE_GENERIC_TABLE(gtype,name) \ 84 #define MODULE_GENERIC_TABLE(gtype,name) \
85 extern const struct gtype##_id __mod_##gtype##_table \ 85 extern const struct gtype##_id __mod_##gtype##_table \
86 __attribute__ ((unused, alias(__stringify(name)))) 86 __attribute__ ((unused, alias(__stringify(name))))
87 87
88 extern struct module __this_module; 88 extern struct module __this_module;
89 #define THIS_MODULE (&__this_module) 89 #define THIS_MODULE (&__this_module)
90 #else /* !MODULE */ 90 #else /* !MODULE */
91 #define MODULE_GENERIC_TABLE(gtype,name) 91 #define MODULE_GENERIC_TABLE(gtype,name)
92 #define THIS_MODULE ((struct module *)0) 92 #define THIS_MODULE ((struct module *)0)
93 #endif 93 #endif
94 94
95 /* Generic info of form tag = "info" */ 95 /* Generic info of form tag = "info" */
96 #define MODULE_INFO(tag, info) __MODULE_INFO(tag, tag, info) 96 #define MODULE_INFO(tag, info) __MODULE_INFO(tag, tag, info)
97 97
98 /* For userspace: you can also call me... */ 98 /* For userspace: you can also call me... */
99 #define MODULE_ALIAS(_alias) MODULE_INFO(alias, _alias) 99 #define MODULE_ALIAS(_alias) MODULE_INFO(alias, _alias)
100 100
101 /* 101 /*
102 * The following license idents are currently accepted as indicating free 102 * The following license idents are currently accepted as indicating free
103 * software modules 103 * software modules
104 * 104 *
105 * "GPL" [GNU Public License v2 or later] 105 * "GPL" [GNU Public License v2 or later]
106 * "GPL v2" [GNU Public License v2] 106 * "GPL v2" [GNU Public License v2]
107 * "GPL and additional rights" [GNU Public License v2 rights and more] 107 * "GPL and additional rights" [GNU Public License v2 rights and more]
108 * "Dual BSD/GPL" [GNU Public License v2 108 * "Dual BSD/GPL" [GNU Public License v2
109 * or BSD license choice] 109 * or BSD license choice]
110 * "Dual MIT/GPL" [GNU Public License v2 110 * "Dual MIT/GPL" [GNU Public License v2
111 * or MIT license choice] 111 * or MIT license choice]
112 * "Dual MPL/GPL" [GNU Public License v2 112 * "Dual MPL/GPL" [GNU Public License v2
113 * or Mozilla license choice] 113 * or Mozilla license choice]
114 * 114 *
115 * The following other idents are available 115 * The following other idents are available
116 * 116 *
117 * "Proprietary" [Non free products] 117 * "Proprietary" [Non free products]
118 * 118 *
119 * There are dual licensed components, but when running with Linux it is the 119 * There are dual licensed components, but when running with Linux it is the
120 * GPL that is relevant so this is a non issue. Similarly LGPL linked with GPL 120 * GPL that is relevant so this is a non issue. Similarly LGPL linked with GPL
121 * is a GPL combined work. 121 * is a GPL combined work.
122 * 122 *
123 * This exists for several reasons 123 * This exists for several reasons
124 * 1. So modinfo can show license info for users wanting to vet their setup 124 * 1. So modinfo can show license info for users wanting to vet their setup
125 * is free 125 * is free
126 * 2. So the community can ignore bug reports including proprietary modules 126 * 2. So the community can ignore bug reports including proprietary modules
127 * 3. So vendors can do likewise based on their own policies 127 * 3. So vendors can do likewise based on their own policies
128 */ 128 */
129 #define MODULE_LICENSE(_license) MODULE_INFO(license, _license) 129 #define MODULE_LICENSE(_license) MODULE_INFO(license, _license)
130 130
131 /* Author, ideally of form NAME[, NAME]*[ and NAME] */ 131 /* Author, ideally of form NAME[, NAME]*[ and NAME] */
132 #define MODULE_AUTHOR(_author) MODULE_INFO(author, _author) 132 #define MODULE_AUTHOR(_author) MODULE_INFO(author, _author)
133 133
134 /* What your module does. */ 134 /* What your module does. */
135 #define MODULE_DESCRIPTION(_description) MODULE_INFO(description, _description) 135 #define MODULE_DESCRIPTION(_description) MODULE_INFO(description, _description)
136 136
137 /* One for each parameter, describing how to use it. Some files do 137 /* One for each parameter, describing how to use it. Some files do
138 multiple of these per line, so can't just use MODULE_INFO. */ 138 multiple of these per line, so can't just use MODULE_INFO. */
139 #define MODULE_PARM_DESC(_parm, desc) \ 139 #define MODULE_PARM_DESC(_parm, desc) \
140 __MODULE_INFO(parm, _parm, #_parm ":" desc) 140 __MODULE_INFO(parm, _parm, #_parm ":" desc)
141 141
142 #define MODULE_DEVICE_TABLE(type,name) \ 142 #define MODULE_DEVICE_TABLE(type,name) \
143 MODULE_GENERIC_TABLE(type##_device,name) 143 MODULE_GENERIC_TABLE(type##_device,name)
144 144
145 /* Version of form [<epoch>:]<version>[-<extra-version>]. 145 /* Version of form [<epoch>:]<version>[-<extra-version>].
146 Or for CVS/RCS ID version, everything but the number is stripped. 146 Or for CVS/RCS ID version, everything but the number is stripped.
147 <epoch>: A (small) unsigned integer which allows you to start versions 147 <epoch>: A (small) unsigned integer which allows you to start versions
148 anew. If not mentioned, it's zero. eg. "2:1.0" is after 148 anew. If not mentioned, it's zero. eg. "2:1.0" is after
149 "1:2.0". 149 "1:2.0".
150 <version>: The <version> may contain only alphanumerics and the 150 <version>: The <version> may contain only alphanumerics and the
151 character `.'. Ordered by numeric sort for numeric parts, 151 character `.'. Ordered by numeric sort for numeric parts,
152 ascii sort for ascii parts (as per RPM or DEB algorithm). 152 ascii sort for ascii parts (as per RPM or DEB algorithm).
153 <extraversion>: Like <version>, but inserted for local 153 <extraversion>: Like <version>, but inserted for local
154 customizations, eg "rh3" or "rusty1". 154 customizations, eg "rh3" or "rusty1".
155 155
156 Using this automatically adds a checksum of the .c files and the 156 Using this automatically adds a checksum of the .c files and the
157 local headers in "srcversion". 157 local headers in "srcversion".
158 */ 158 */
159 #define MODULE_VERSION(_version) MODULE_INFO(version, _version) 159 #define MODULE_VERSION(_version) MODULE_INFO(version, _version)
160 160
161 /* Optional firmware file (or files) needed by the module 161 /* Optional firmware file (or files) needed by the module
162 * format is simply firmware file name. Multiple firmware 162 * format is simply firmware file name. Multiple firmware
163 * files require multiple MODULE_FIRMWARE() specifiers */ 163 * files require multiple MODULE_FIRMWARE() specifiers */
164 #define MODULE_FIRMWARE(_firmware) MODULE_INFO(firmware, _firmware) 164 #define MODULE_FIRMWARE(_firmware) MODULE_INFO(firmware, _firmware)
165 165
166 /* Given an address, look for it in the exception tables */ 166 /* Given an address, look for it in the exception tables */
167 const struct exception_table_entry *search_exception_tables(unsigned long add); 167 const struct exception_table_entry *search_exception_tables(unsigned long add);
168 168
169 struct notifier_block; 169 struct notifier_block;
170 170
171 #ifdef CONFIG_MODULES 171 #ifdef CONFIG_MODULES
172 172
173 /* Get/put a kernel symbol (calls must be symmetric) */ 173 /* Get/put a kernel symbol (calls must be symmetric) */
174 void *__symbol_get(const char *symbol); 174 void *__symbol_get(const char *symbol);
175 void *__symbol_get_gpl(const char *symbol); 175 void *__symbol_get_gpl(const char *symbol);
176 #define symbol_get(x) ((typeof(&x))(__symbol_get(MODULE_SYMBOL_PREFIX #x))) 176 #define symbol_get(x) ((typeof(&x))(__symbol_get(MODULE_SYMBOL_PREFIX #x)))
177 177
178 #ifndef __GENKSYMS__ 178 #ifndef __GENKSYMS__
179 #ifdef CONFIG_MODVERSIONS 179 #ifdef CONFIG_MODVERSIONS
180 /* Mark the CRC weak since genksyms apparently decides not to 180 /* Mark the CRC weak since genksyms apparently decides not to
181 * generate a checksums for some symbols */ 181 * generate a checksums for some symbols */
182 #define __CRC_SYMBOL(sym, sec) \ 182 #define __CRC_SYMBOL(sym, sec) \
183 extern void *__crc_##sym __attribute__((weak)); \ 183 extern void *__crc_##sym __attribute__((weak)); \
184 static const unsigned long __kcrctab_##sym \ 184 static const unsigned long __kcrctab_##sym \
185 __used \ 185 __used \
186 __attribute__((section("__kcrctab" sec), unused)) \ 186 __attribute__((section("__kcrctab" sec), unused)) \
187 = (unsigned long) &__crc_##sym; 187 = (unsigned long) &__crc_##sym;
188 #else 188 #else
189 #define __CRC_SYMBOL(sym, sec) 189 #define __CRC_SYMBOL(sym, sec)
190 #endif 190 #endif
191 191
192 /* For every exported symbol, place a struct in the __ksymtab section */ 192 /* For every exported symbol, place a struct in the __ksymtab section */
193 #define __EXPORT_SYMBOL(sym, sec) \ 193 #define __EXPORT_SYMBOL(sym, sec) \
194 extern typeof(sym) sym; \ 194 extern typeof(sym) sym; \
195 __CRC_SYMBOL(sym, sec) \ 195 __CRC_SYMBOL(sym, sec) \
196 static const char __kstrtab_##sym[] \ 196 static const char __kstrtab_##sym[] \
197 __attribute__((section("__ksymtab_strings"), aligned(1))) \ 197 __attribute__((section("__ksymtab_strings"), aligned(1))) \
198 = MODULE_SYMBOL_PREFIX #sym; \ 198 = MODULE_SYMBOL_PREFIX #sym; \
199 static const struct kernel_symbol __ksymtab_##sym \ 199 static const struct kernel_symbol __ksymtab_##sym \
200 __used \ 200 __used \
201 __attribute__((section("__ksymtab" sec), unused)) \ 201 __attribute__((section("__ksymtab" sec), unused)) \
202 = { (unsigned long)&sym, __kstrtab_##sym } 202 = { (unsigned long)&sym, __kstrtab_##sym }
203 203
204 #define EXPORT_SYMBOL(sym) \ 204 #define EXPORT_SYMBOL(sym) \
205 __EXPORT_SYMBOL(sym, "") 205 __EXPORT_SYMBOL(sym, "")
206 206
207 #define EXPORT_SYMBOL_GPL(sym) \ 207 #define EXPORT_SYMBOL_GPL(sym) \
208 __EXPORT_SYMBOL(sym, "_gpl") 208 __EXPORT_SYMBOL(sym, "_gpl")
209 209
210 #define EXPORT_SYMBOL_GPL_FUTURE(sym) \ 210 #define EXPORT_SYMBOL_GPL_FUTURE(sym) \
211 __EXPORT_SYMBOL(sym, "_gpl_future") 211 __EXPORT_SYMBOL(sym, "_gpl_future")
212 212
213 213
214 #ifdef CONFIG_UNUSED_SYMBOLS 214 #ifdef CONFIG_UNUSED_SYMBOLS
215 #define EXPORT_UNUSED_SYMBOL(sym) __EXPORT_SYMBOL(sym, "_unused") 215 #define EXPORT_UNUSED_SYMBOL(sym) __EXPORT_SYMBOL(sym, "_unused")
216 #define EXPORT_UNUSED_SYMBOL_GPL(sym) __EXPORT_SYMBOL(sym, "_unused_gpl") 216 #define EXPORT_UNUSED_SYMBOL_GPL(sym) __EXPORT_SYMBOL(sym, "_unused_gpl")
217 #else 217 #else
218 #define EXPORT_UNUSED_SYMBOL(sym) 218 #define EXPORT_UNUSED_SYMBOL(sym)
219 #define EXPORT_UNUSED_SYMBOL_GPL(sym) 219 #define EXPORT_UNUSED_SYMBOL_GPL(sym)
220 #endif 220 #endif
221 221
222 #endif 222 #endif
223 223
224 enum module_state 224 enum module_state
225 { 225 {
226 MODULE_STATE_LIVE, 226 MODULE_STATE_LIVE,
227 MODULE_STATE_COMING, 227 MODULE_STATE_COMING,
228 MODULE_STATE_GOING, 228 MODULE_STATE_GOING,
229 }; 229 };
230 230
231 struct module 231 struct module
232 { 232 {
233 enum module_state state; 233 enum module_state state;
234 234
235 /* Member of list of modules */ 235 /* Member of list of modules */
236 struct list_head list; 236 struct list_head list;
237 237
238 /* Unique handle for this module */ 238 /* Unique handle for this module */
239 char name[MODULE_NAME_LEN]; 239 char name[MODULE_NAME_LEN];
240 240
241 /* Sysfs stuff. */ 241 /* Sysfs stuff. */
242 struct module_kobject mkobj; 242 struct module_kobject mkobj;
243 struct module_attribute *modinfo_attrs; 243 struct module_attribute *modinfo_attrs;
244 const char *version; 244 const char *version;
245 const char *srcversion; 245 const char *srcversion;
246 struct kobject *holders_dir; 246 struct kobject *holders_dir;
247 247
248 /* Exported symbols */ 248 /* Exported symbols */
249 const struct kernel_symbol *syms; 249 const struct kernel_symbol *syms;
250 const unsigned long *crcs; 250 const unsigned long *crcs;
251 unsigned int num_syms; 251 unsigned int num_syms;
252 252
253 /* Kernel parameters. */ 253 /* Kernel parameters. */
254 struct kernel_param *kp; 254 struct kernel_param *kp;
255 unsigned int num_kp; 255 unsigned int num_kp;
256 256
257 /* GPL-only exported symbols. */ 257 /* GPL-only exported symbols. */
258 unsigned int num_gpl_syms; 258 unsigned int num_gpl_syms;
259 const struct kernel_symbol *gpl_syms; 259 const struct kernel_symbol *gpl_syms;
260 const unsigned long *gpl_crcs; 260 const unsigned long *gpl_crcs;
261 261
262 #ifdef CONFIG_UNUSED_SYMBOLS 262 #ifdef CONFIG_UNUSED_SYMBOLS
263 /* unused exported symbols. */ 263 /* unused exported symbols. */
264 const struct kernel_symbol *unused_syms; 264 const struct kernel_symbol *unused_syms;
265 const unsigned long *unused_crcs; 265 const unsigned long *unused_crcs;
266 unsigned int num_unused_syms; 266 unsigned int num_unused_syms;
267 267
268 /* GPL-only, unused exported symbols. */ 268 /* GPL-only, unused exported symbols. */
269 unsigned int num_unused_gpl_syms; 269 unsigned int num_unused_gpl_syms;
270 const struct kernel_symbol *unused_gpl_syms; 270 const struct kernel_symbol *unused_gpl_syms;
271 const unsigned long *unused_gpl_crcs; 271 const unsigned long *unused_gpl_crcs;
272 #endif 272 #endif
273 273
274 /* symbols that will be GPL-only in the near future. */ 274 /* symbols that will be GPL-only in the near future. */
275 const struct kernel_symbol *gpl_future_syms; 275 const struct kernel_symbol *gpl_future_syms;
276 const unsigned long *gpl_future_crcs; 276 const unsigned long *gpl_future_crcs;
277 unsigned int num_gpl_future_syms; 277 unsigned int num_gpl_future_syms;
278 278
279 /* Exception table */ 279 /* Exception table */
280 unsigned int num_exentries; 280 unsigned int num_exentries;
281 struct exception_table_entry *extable; 281 struct exception_table_entry *extable;
282 282
283 /* Startup function. */ 283 /* Startup function. */
284 int (*init)(void); 284 int (*init)(void);
285 285
286 /* If this is non-NULL, vfree after init() returns */ 286 /* If this is non-NULL, vfree after init() returns */
287 void *module_init; 287 void *module_init;
288 288
289 /* Here is the actual code + data, vfree'd on unload. */ 289 /* Here is the actual code + data, vfree'd on unload. */
290 void *module_core; 290 void *module_core;
291 291
292 /* Here are the sizes of the init and core sections */ 292 /* Here are the sizes of the init and core sections */
293 unsigned int init_size, core_size; 293 unsigned int init_size, core_size;
294 294
295 /* The size of the executable code in each section. */ 295 /* The size of the executable code in each section. */
296 unsigned int init_text_size, core_text_size; 296 unsigned int init_text_size, core_text_size;
297 297
298 /* Arch-specific module values */ 298 /* Arch-specific module values */
299 struct mod_arch_specific arch; 299 struct mod_arch_specific arch;
300 300
301 unsigned int taints; /* same bits as kernel:tainted */ 301 unsigned int taints; /* same bits as kernel:tainted */
302 302
303 #ifdef CONFIG_GENERIC_BUG 303 #ifdef CONFIG_GENERIC_BUG
304 /* Support for BUG */ 304 /* Support for BUG */
305 unsigned num_bugs; 305 unsigned num_bugs;
306 struct list_head bug_list; 306 struct list_head bug_list;
307 struct bug_entry *bug_table; 307 struct bug_entry *bug_table;
308 #endif 308 #endif
309 309
310 #ifdef CONFIG_KALLSYMS 310 #ifdef CONFIG_KALLSYMS
311 /* 311 /*
312 * We keep the symbol and string tables for kallsyms. 312 * We keep the symbol and string tables for kallsyms.
313 * The core_* fields below are temporary, loader-only (they 313 * The core_* fields below are temporary, loader-only (they
314 * could really be discarded after module init). 314 * could really be discarded after module init).
315 */ 315 */
316 Elf_Sym *symtab, *core_symtab; 316 Elf_Sym *symtab, *core_symtab;
317 unsigned int num_symtab, core_num_syms; 317 unsigned int num_symtab, core_num_syms;
318 char *strtab; 318 char *strtab, *core_strtab;
319 319
320 /* Section attributes */ 320 /* Section attributes */
321 struct module_sect_attrs *sect_attrs; 321 struct module_sect_attrs *sect_attrs;
322 322
323 /* Notes attributes */ 323 /* Notes attributes */
324 struct module_notes_attrs *notes_attrs; 324 struct module_notes_attrs *notes_attrs;
325 #endif 325 #endif
326 326
327 /* Per-cpu data. */ 327 /* Per-cpu data. */
328 void *percpu; 328 void *percpu;
329 329
330 /* The command line arguments (may be mangled). People like 330 /* The command line arguments (may be mangled). People like
331 keeping pointers to this stuff */ 331 keeping pointers to this stuff */
332 char *args; 332 char *args;
333 #ifdef CONFIG_TRACEPOINTS 333 #ifdef CONFIG_TRACEPOINTS
334 struct tracepoint *tracepoints; 334 struct tracepoint *tracepoints;
335 unsigned int num_tracepoints; 335 unsigned int num_tracepoints;
336 #endif 336 #endif
337 337
338 #ifdef CONFIG_TRACING 338 #ifdef CONFIG_TRACING
339 const char **trace_bprintk_fmt_start; 339 const char **trace_bprintk_fmt_start;
340 unsigned int num_trace_bprintk_fmt; 340 unsigned int num_trace_bprintk_fmt;
341 #endif 341 #endif
342 #ifdef CONFIG_EVENT_TRACING 342 #ifdef CONFIG_EVENT_TRACING
343 struct ftrace_event_call *trace_events; 343 struct ftrace_event_call *trace_events;
344 unsigned int num_trace_events; 344 unsigned int num_trace_events;
345 #endif 345 #endif
346 #ifdef CONFIG_FTRACE_MCOUNT_RECORD 346 #ifdef CONFIG_FTRACE_MCOUNT_RECORD
347 unsigned long *ftrace_callsites; 347 unsigned long *ftrace_callsites;
348 unsigned int num_ftrace_callsites; 348 unsigned int num_ftrace_callsites;
349 #endif 349 #endif
350 350
351 #ifdef CONFIG_MODULE_UNLOAD 351 #ifdef CONFIG_MODULE_UNLOAD
352 /* What modules depend on me? */ 352 /* What modules depend on me? */
353 struct list_head modules_which_use_me; 353 struct list_head modules_which_use_me;
354 354
355 /* Who is waiting for us to be unloaded */ 355 /* Who is waiting for us to be unloaded */
356 struct task_struct *waiter; 356 struct task_struct *waiter;
357 357
358 /* Destruction function. */ 358 /* Destruction function. */
359 void (*exit)(void); 359 void (*exit)(void);
360 360
361 #ifdef CONFIG_SMP 361 #ifdef CONFIG_SMP
362 char *refptr; 362 char *refptr;
363 #else 363 #else
364 local_t ref; 364 local_t ref;
365 #endif 365 #endif
366 #endif 366 #endif
367 367
368 #ifdef CONFIG_CONSTRUCTORS 368 #ifdef CONFIG_CONSTRUCTORS
369 /* Constructor functions. */ 369 /* Constructor functions. */
370 ctor_fn_t *ctors; 370 ctor_fn_t *ctors;
371 unsigned int num_ctors; 371 unsigned int num_ctors;
372 #endif 372 #endif
373 }; 373 };
374 #ifndef MODULE_ARCH_INIT 374 #ifndef MODULE_ARCH_INIT
375 #define MODULE_ARCH_INIT {} 375 #define MODULE_ARCH_INIT {}
376 #endif 376 #endif
377 377
378 extern struct mutex module_mutex; 378 extern struct mutex module_mutex;
379 379
380 /* FIXME: It'd be nice to isolate modules during init, too, so they 380 /* FIXME: It'd be nice to isolate modules during init, too, so they
381 aren't used before they (may) fail. But presently too much code 381 aren't used before they (may) fail. But presently too much code
382 (IDE & SCSI) require entry into the module during init.*/ 382 (IDE & SCSI) require entry into the module during init.*/
383 static inline int module_is_live(struct module *mod) 383 static inline int module_is_live(struct module *mod)
384 { 384 {
385 return mod->state != MODULE_STATE_GOING; 385 return mod->state != MODULE_STATE_GOING;
386 } 386 }
387 387
388 struct module *__module_text_address(unsigned long addr); 388 struct module *__module_text_address(unsigned long addr);
389 struct module *__module_address(unsigned long addr); 389 struct module *__module_address(unsigned long addr);
390 bool is_module_address(unsigned long addr); 390 bool is_module_address(unsigned long addr);
391 bool is_module_text_address(unsigned long addr); 391 bool is_module_text_address(unsigned long addr);
392 392
393 static inline int within_module_core(unsigned long addr, struct module *mod) 393 static inline int within_module_core(unsigned long addr, struct module *mod)
394 { 394 {
395 return (unsigned long)mod->module_core <= addr && 395 return (unsigned long)mod->module_core <= addr &&
396 addr < (unsigned long)mod->module_core + mod->core_size; 396 addr < (unsigned long)mod->module_core + mod->core_size;
397 } 397 }
398 398
399 static inline int within_module_init(unsigned long addr, struct module *mod) 399 static inline int within_module_init(unsigned long addr, struct module *mod)
400 { 400 {
401 return (unsigned long)mod->module_init <= addr && 401 return (unsigned long)mod->module_init <= addr &&
402 addr < (unsigned long)mod->module_init + mod->init_size; 402 addr < (unsigned long)mod->module_init + mod->init_size;
403 } 403 }
404 404
405 /* Search for module by name: must hold module_mutex. */ 405 /* Search for module by name: must hold module_mutex. */
406 struct module *find_module(const char *name); 406 struct module *find_module(const char *name);
407 407
408 struct symsearch { 408 struct symsearch {
409 const struct kernel_symbol *start, *stop; 409 const struct kernel_symbol *start, *stop;
410 const unsigned long *crcs; 410 const unsigned long *crcs;
411 enum { 411 enum {
412 NOT_GPL_ONLY, 412 NOT_GPL_ONLY,
413 GPL_ONLY, 413 GPL_ONLY,
414 WILL_BE_GPL_ONLY, 414 WILL_BE_GPL_ONLY,
415 } licence; 415 } licence;
416 bool unused; 416 bool unused;
417 }; 417 };
418 418
419 /* Search for an exported symbol by name. */ 419 /* Search for an exported symbol by name. */
420 const struct kernel_symbol *find_symbol(const char *name, 420 const struct kernel_symbol *find_symbol(const char *name,
421 struct module **owner, 421 struct module **owner,
422 const unsigned long **crc, 422 const unsigned long **crc,
423 bool gplok, 423 bool gplok,
424 bool warn); 424 bool warn);
425 425
426 /* Walk the exported symbol table */ 426 /* Walk the exported symbol table */
427 bool each_symbol(bool (*fn)(const struct symsearch *arr, struct module *owner, 427 bool each_symbol(bool (*fn)(const struct symsearch *arr, struct module *owner,
428 unsigned int symnum, void *data), void *data); 428 unsigned int symnum, void *data), void *data);
429 429
430 /* Returns 0 and fills in value, defined and namebuf, or -ERANGE if 430 /* Returns 0 and fills in value, defined and namebuf, or -ERANGE if
431 symnum out of range. */ 431 symnum out of range. */
432 int module_get_kallsym(unsigned int symnum, unsigned long *value, char *type, 432 int module_get_kallsym(unsigned int symnum, unsigned long *value, char *type,
433 char *name, char *module_name, int *exported); 433 char *name, char *module_name, int *exported);
434 434
435 /* Look for this name: can be of form module:name. */ 435 /* Look for this name: can be of form module:name. */
436 unsigned long module_kallsyms_lookup_name(const char *name); 436 unsigned long module_kallsyms_lookup_name(const char *name);
437 437
438 int module_kallsyms_on_each_symbol(int (*fn)(void *, const char *, 438 int module_kallsyms_on_each_symbol(int (*fn)(void *, const char *,
439 struct module *, unsigned long), 439 struct module *, unsigned long),
440 void *data); 440 void *data);
441 441
442 extern void __module_put_and_exit(struct module *mod, long code) 442 extern void __module_put_and_exit(struct module *mod, long code)
443 __attribute__((noreturn)); 443 __attribute__((noreturn));
444 #define module_put_and_exit(code) __module_put_and_exit(THIS_MODULE, code); 444 #define module_put_and_exit(code) __module_put_and_exit(THIS_MODULE, code);
445 445
446 #ifdef CONFIG_MODULE_UNLOAD 446 #ifdef CONFIG_MODULE_UNLOAD
447 unsigned int module_refcount(struct module *mod); 447 unsigned int module_refcount(struct module *mod);
448 void __symbol_put(const char *symbol); 448 void __symbol_put(const char *symbol);
449 #define symbol_put(x) __symbol_put(MODULE_SYMBOL_PREFIX #x) 449 #define symbol_put(x) __symbol_put(MODULE_SYMBOL_PREFIX #x)
450 void symbol_put_addr(void *addr); 450 void symbol_put_addr(void *addr);
451 451
452 static inline local_t *__module_ref_addr(struct module *mod, int cpu) 452 static inline local_t *__module_ref_addr(struct module *mod, int cpu)
453 { 453 {
454 #ifdef CONFIG_SMP 454 #ifdef CONFIG_SMP
455 return (local_t *) (mod->refptr + per_cpu_offset(cpu)); 455 return (local_t *) (mod->refptr + per_cpu_offset(cpu));
456 #else 456 #else
457 return &mod->ref; 457 return &mod->ref;
458 #endif 458 #endif
459 } 459 }
460 460
461 /* Sometimes we know we already have a refcount, and it's easier not 461 /* Sometimes we know we already have a refcount, and it's easier not
462 to handle the error case (which only happens with rmmod --wait). */ 462 to handle the error case (which only happens with rmmod --wait). */
463 static inline void __module_get(struct module *module) 463 static inline void __module_get(struct module *module)
464 { 464 {
465 if (module) { 465 if (module) {
466 unsigned int cpu = get_cpu(); 466 unsigned int cpu = get_cpu();
467 local_inc(__module_ref_addr(module, cpu)); 467 local_inc(__module_ref_addr(module, cpu));
468 trace_module_get(module, _THIS_IP_, 468 trace_module_get(module, _THIS_IP_,
469 local_read(__module_ref_addr(module, cpu))); 469 local_read(__module_ref_addr(module, cpu)));
470 put_cpu(); 470 put_cpu();
471 } 471 }
472 } 472 }
473 473
474 static inline int try_module_get(struct module *module) 474 static inline int try_module_get(struct module *module)
475 { 475 {
476 int ret = 1; 476 int ret = 1;
477 477
478 if (module) { 478 if (module) {
479 unsigned int cpu = get_cpu(); 479 unsigned int cpu = get_cpu();
480 if (likely(module_is_live(module))) { 480 if (likely(module_is_live(module))) {
481 local_inc(__module_ref_addr(module, cpu)); 481 local_inc(__module_ref_addr(module, cpu));
482 trace_module_get(module, _THIS_IP_, 482 trace_module_get(module, _THIS_IP_,
483 local_read(__module_ref_addr(module, cpu))); 483 local_read(__module_ref_addr(module, cpu)));
484 } 484 }
485 else 485 else
486 ret = 0; 486 ret = 0;
487 put_cpu(); 487 put_cpu();
488 } 488 }
489 return ret; 489 return ret;
490 } 490 }
491 491
492 extern void module_put(struct module *module); 492 extern void module_put(struct module *module);
493 493
494 #else /*!CONFIG_MODULE_UNLOAD*/ 494 #else /*!CONFIG_MODULE_UNLOAD*/
495 static inline int try_module_get(struct module *module) 495 static inline int try_module_get(struct module *module)
496 { 496 {
497 return !module || module_is_live(module); 497 return !module || module_is_live(module);
498 } 498 }
499 static inline void module_put(struct module *module) 499 static inline void module_put(struct module *module)
500 { 500 {
501 } 501 }
502 static inline void __module_get(struct module *module) 502 static inline void __module_get(struct module *module)
503 { 503 {
504 } 504 }
505 #define symbol_put(x) do { } while(0) 505 #define symbol_put(x) do { } while(0)
506 #define symbol_put_addr(p) do { } while(0) 506 #define symbol_put_addr(p) do { } while(0)
507 507
508 #endif /* CONFIG_MODULE_UNLOAD */ 508 #endif /* CONFIG_MODULE_UNLOAD */
509 int use_module(struct module *a, struct module *b); 509 int use_module(struct module *a, struct module *b);
510 510
511 /* This is a #define so the string doesn't get put in every .o file */ 511 /* This is a #define so the string doesn't get put in every .o file */
512 #define module_name(mod) \ 512 #define module_name(mod) \
513 ({ \ 513 ({ \
514 struct module *__mod = (mod); \ 514 struct module *__mod = (mod); \
515 __mod ? __mod->name : "kernel"; \ 515 __mod ? __mod->name : "kernel"; \
516 }) 516 })
517 517
518 /* For kallsyms to ask for address resolution. namebuf should be at 518 /* For kallsyms to ask for address resolution. namebuf should be at
519 * least KSYM_NAME_LEN long: a pointer to namebuf is returned if 519 * least KSYM_NAME_LEN long: a pointer to namebuf is returned if
520 * found, otherwise NULL. */ 520 * found, otherwise NULL. */
521 const char *module_address_lookup(unsigned long addr, 521 const char *module_address_lookup(unsigned long addr,
522 unsigned long *symbolsize, 522 unsigned long *symbolsize,
523 unsigned long *offset, 523 unsigned long *offset,
524 char **modname, 524 char **modname,
525 char *namebuf); 525 char *namebuf);
526 int lookup_module_symbol_name(unsigned long addr, char *symname); 526 int lookup_module_symbol_name(unsigned long addr, char *symname);
527 int lookup_module_symbol_attrs(unsigned long addr, unsigned long *size, unsigned long *offset, char *modname, char *name); 527 int lookup_module_symbol_attrs(unsigned long addr, unsigned long *size, unsigned long *offset, char *modname, char *name);
528 528
529 /* For extable.c to search modules' exception tables. */ 529 /* For extable.c to search modules' exception tables. */
530 const struct exception_table_entry *search_module_extables(unsigned long addr); 530 const struct exception_table_entry *search_module_extables(unsigned long addr);
531 531
532 int register_module_notifier(struct notifier_block * nb); 532 int register_module_notifier(struct notifier_block * nb);
533 int unregister_module_notifier(struct notifier_block * nb); 533 int unregister_module_notifier(struct notifier_block * nb);
534 534
535 extern void print_modules(void); 535 extern void print_modules(void);
536 536
537 extern void module_update_tracepoints(void); 537 extern void module_update_tracepoints(void);
538 extern int module_get_iter_tracepoints(struct tracepoint_iter *iter); 538 extern int module_get_iter_tracepoints(struct tracepoint_iter *iter);
539 539
540 #else /* !CONFIG_MODULES... */ 540 #else /* !CONFIG_MODULES... */
541 #define EXPORT_SYMBOL(sym) 541 #define EXPORT_SYMBOL(sym)
542 #define EXPORT_SYMBOL_GPL(sym) 542 #define EXPORT_SYMBOL_GPL(sym)
543 #define EXPORT_SYMBOL_GPL_FUTURE(sym) 543 #define EXPORT_SYMBOL_GPL_FUTURE(sym)
544 #define EXPORT_UNUSED_SYMBOL(sym) 544 #define EXPORT_UNUSED_SYMBOL(sym)
545 #define EXPORT_UNUSED_SYMBOL_GPL(sym) 545 #define EXPORT_UNUSED_SYMBOL_GPL(sym)
546 546
547 /* Given an address, look for it in the exception tables. */ 547 /* Given an address, look for it in the exception tables. */
548 static inline const struct exception_table_entry * 548 static inline const struct exception_table_entry *
549 search_module_extables(unsigned long addr) 549 search_module_extables(unsigned long addr)
550 { 550 {
551 return NULL; 551 return NULL;
552 } 552 }
553 553
554 static inline struct module *__module_address(unsigned long addr) 554 static inline struct module *__module_address(unsigned long addr)
555 { 555 {
556 return NULL; 556 return NULL;
557 } 557 }
558 558
559 static inline struct module *__module_text_address(unsigned long addr) 559 static inline struct module *__module_text_address(unsigned long addr)
560 { 560 {
561 return NULL; 561 return NULL;
562 } 562 }
563 563
564 static inline bool is_module_address(unsigned long addr) 564 static inline bool is_module_address(unsigned long addr)
565 { 565 {
566 return false; 566 return false;
567 } 567 }
568 568
569 static inline bool is_module_text_address(unsigned long addr) 569 static inline bool is_module_text_address(unsigned long addr)
570 { 570 {
571 return false; 571 return false;
572 } 572 }
573 573
574 /* Get/put a kernel symbol (calls should be symmetric) */ 574 /* Get/put a kernel symbol (calls should be symmetric) */
575 #define symbol_get(x) ({ extern typeof(x) x __attribute__((weak)); &(x); }) 575 #define symbol_get(x) ({ extern typeof(x) x __attribute__((weak)); &(x); })
576 #define symbol_put(x) do { } while(0) 576 #define symbol_put(x) do { } while(0)
577 #define symbol_put_addr(x) do { } while(0) 577 #define symbol_put_addr(x) do { } while(0)
578 578
579 static inline void __module_get(struct module *module) 579 static inline void __module_get(struct module *module)
580 { 580 {
581 } 581 }
582 582
583 static inline int try_module_get(struct module *module) 583 static inline int try_module_get(struct module *module)
584 { 584 {
585 return 1; 585 return 1;
586 } 586 }
587 587
588 static inline void module_put(struct module *module) 588 static inline void module_put(struct module *module)
589 { 589 {
590 } 590 }
591 591
592 #define module_name(mod) "kernel" 592 #define module_name(mod) "kernel"
593 593
594 /* For kallsyms to ask for address resolution. NULL means not found. */ 594 /* For kallsyms to ask for address resolution. NULL means not found. */
595 static inline const char *module_address_lookup(unsigned long addr, 595 static inline const char *module_address_lookup(unsigned long addr,
596 unsigned long *symbolsize, 596 unsigned long *symbolsize,
597 unsigned long *offset, 597 unsigned long *offset,
598 char **modname, 598 char **modname,
599 char *namebuf) 599 char *namebuf)
600 { 600 {
601 return NULL; 601 return NULL;
602 } 602 }
603 603
604 static inline int lookup_module_symbol_name(unsigned long addr, char *symname) 604 static inline int lookup_module_symbol_name(unsigned long addr, char *symname)
605 { 605 {
606 return -ERANGE; 606 return -ERANGE;
607 } 607 }
608 608
609 static inline int lookup_module_symbol_attrs(unsigned long addr, unsigned long *size, unsigned long *offset, char *modname, char *name) 609 static inline int lookup_module_symbol_attrs(unsigned long addr, unsigned long *size, unsigned long *offset, char *modname, char *name)
610 { 610 {
611 return -ERANGE; 611 return -ERANGE;
612 } 612 }
613 613
614 static inline int module_get_kallsym(unsigned int symnum, unsigned long *value, 614 static inline int module_get_kallsym(unsigned int symnum, unsigned long *value,
615 char *type, char *name, 615 char *type, char *name,
616 char *module_name, int *exported) 616 char *module_name, int *exported)
617 { 617 {
618 return -ERANGE; 618 return -ERANGE;
619 } 619 }
620 620
621 static inline unsigned long module_kallsyms_lookup_name(const char *name) 621 static inline unsigned long module_kallsyms_lookup_name(const char *name)
622 { 622 {
623 return 0; 623 return 0;
624 } 624 }
625 625
626 static inline int module_kallsyms_on_each_symbol(int (*fn)(void *, const char *, 626 static inline int module_kallsyms_on_each_symbol(int (*fn)(void *, const char *,
627 struct module *, 627 struct module *,
628 unsigned long), 628 unsigned long),
629 void *data) 629 void *data)
630 { 630 {
631 return 0; 631 return 0;
632 } 632 }
633 633
634 static inline int register_module_notifier(struct notifier_block * nb) 634 static inline int register_module_notifier(struct notifier_block * nb)
635 { 635 {
636 /* no events will happen anyway, so this can always succeed */ 636 /* no events will happen anyway, so this can always succeed */
637 return 0; 637 return 0;
638 } 638 }
639 639
640 static inline int unregister_module_notifier(struct notifier_block * nb) 640 static inline int unregister_module_notifier(struct notifier_block * nb)
641 { 641 {
642 return 0; 642 return 0;
643 } 643 }
644 644
645 #define module_put_and_exit(code) do_exit(code) 645 #define module_put_and_exit(code) do_exit(code)
646 646
647 static inline void print_modules(void) 647 static inline void print_modules(void)
648 { 648 {
649 } 649 }
650 650
651 static inline void module_update_tracepoints(void) 651 static inline void module_update_tracepoints(void)
652 { 652 {
653 } 653 }
654 654
655 static inline int module_get_iter_tracepoints(struct tracepoint_iter *iter) 655 static inline int module_get_iter_tracepoints(struct tracepoint_iter *iter)
656 { 656 {
657 return 0; 657 return 0;
658 } 658 }
659 659
660 #endif /* CONFIG_MODULES */ 660 #endif /* CONFIG_MODULES */
661 661
662 struct device_driver; 662 struct device_driver;
663 #ifdef CONFIG_SYSFS 663 #ifdef CONFIG_SYSFS
664 struct module; 664 struct module;
665 665
666 extern struct kset *module_kset; 666 extern struct kset *module_kset;
667 extern struct kobj_type module_ktype; 667 extern struct kobj_type module_ktype;
668 extern int module_sysfs_initialized; 668 extern int module_sysfs_initialized;
669 669
670 int mod_sysfs_init(struct module *mod); 670 int mod_sysfs_init(struct module *mod);
671 int mod_sysfs_setup(struct module *mod, 671 int mod_sysfs_setup(struct module *mod,
672 struct kernel_param *kparam, 672 struct kernel_param *kparam,
673 unsigned int num_params); 673 unsigned int num_params);
674 int module_add_modinfo_attrs(struct module *mod); 674 int module_add_modinfo_attrs(struct module *mod);
675 void module_remove_modinfo_attrs(struct module *mod); 675 void module_remove_modinfo_attrs(struct module *mod);
676 676
677 #else /* !CONFIG_SYSFS */ 677 #else /* !CONFIG_SYSFS */
678 678
679 static inline int mod_sysfs_init(struct module *mod) 679 static inline int mod_sysfs_init(struct module *mod)
680 { 680 {
681 return 0; 681 return 0;
682 } 682 }
683 683
684 static inline int mod_sysfs_setup(struct module *mod, 684 static inline int mod_sysfs_setup(struct module *mod,
685 struct kernel_param *kparam, 685 struct kernel_param *kparam,
686 unsigned int num_params) 686 unsigned int num_params)
687 { 687 {
688 return 0; 688 return 0;
689 } 689 }
690 690
691 static inline int module_add_modinfo_attrs(struct module *mod) 691 static inline int module_add_modinfo_attrs(struct module *mod)
692 { 692 {
693 return 0; 693 return 0;
694 } 694 }
695 695
696 static inline void module_remove_modinfo_attrs(struct module *mod) 696 static inline void module_remove_modinfo_attrs(struct module *mod)
697 { } 697 { }
698 698
699 #endif /* CONFIG_SYSFS */ 699 #endif /* CONFIG_SYSFS */
700 700
701 #define symbol_request(x) try_then_request_module(symbol_get(x), "symbol:" #x) 701 #define symbol_request(x) try_then_request_module(symbol_get(x), "symbol:" #x)
702 702
703 /* BELOW HERE ALL THESE ARE OBSOLETE AND WILL VANISH */ 703 /* BELOW HERE ALL THESE ARE OBSOLETE AND WILL VANISH */
704 704
705 #define __MODULE_STRING(x) __stringify(x) 705 #define __MODULE_STRING(x) __stringify(x)
706 706
707 707
708 #ifdef CONFIG_GENERIC_BUG 708 #ifdef CONFIG_GENERIC_BUG
709 int module_bug_finalize(const Elf_Ehdr *, const Elf_Shdr *, 709 int module_bug_finalize(const Elf_Ehdr *, const Elf_Shdr *,
710 struct module *); 710 struct module *);
711 void module_bug_cleanup(struct module *); 711 void module_bug_cleanup(struct module *);
712 712
713 #else /* !CONFIG_GENERIC_BUG */ 713 #else /* !CONFIG_GENERIC_BUG */
714 714
715 static inline int module_bug_finalize(const Elf_Ehdr *hdr, 715 static inline int module_bug_finalize(const Elf_Ehdr *hdr,
716 const Elf_Shdr *sechdrs, 716 const Elf_Shdr *sechdrs,
717 struct module *mod) 717 struct module *mod)
718 { 718 {
719 return 0; 719 return 0;
720 } 720 }
721 static inline void module_bug_cleanup(struct module *mod) {} 721 static inline void module_bug_cleanup(struct module *mod) {}
722 #endif /* CONFIG_GENERIC_BUG */ 722 #endif /* CONFIG_GENERIC_BUG */
723 723
724 #endif /* _LINUX_MODULE_H */ 724 #endif /* _LINUX_MODULE_H */
725 725
1 /* 1 /*
2 Copyright (C) 2002 Richard Henderson 2 Copyright (C) 2002 Richard Henderson
3 Copyright (C) 2001 Rusty Russell, 2002 Rusty Russell IBM. 3 Copyright (C) 2001 Rusty Russell, 2002 Rusty Russell IBM.
4 4
5 This program is free software; you can redistribute it and/or modify 5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by 6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or 7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version. 8 (at your option) any later version.
9 9
10 This program is distributed in the hope that it will be useful, 10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details. 13 GNU General Public License for more details.
14 14
15 You should have received a copy of the GNU General Public License 15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software 16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 17 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 */ 18 */
19 #include <linux/module.h> 19 #include <linux/module.h>
20 #include <linux/moduleloader.h> 20 #include <linux/moduleloader.h>
21 #include <linux/ftrace_event.h> 21 #include <linux/ftrace_event.h>
22 #include <linux/init.h> 22 #include <linux/init.h>
23 #include <linux/kallsyms.h> 23 #include <linux/kallsyms.h>
24 #include <linux/fs.h> 24 #include <linux/fs.h>
25 #include <linux/sysfs.h> 25 #include <linux/sysfs.h>
26 #include <linux/kernel.h> 26 #include <linux/kernel.h>
27 #include <linux/slab.h> 27 #include <linux/slab.h>
28 #include <linux/vmalloc.h> 28 #include <linux/vmalloc.h>
29 #include <linux/elf.h> 29 #include <linux/elf.h>
30 #include <linux/proc_fs.h> 30 #include <linux/proc_fs.h>
31 #include <linux/seq_file.h> 31 #include <linux/seq_file.h>
32 #include <linux/syscalls.h> 32 #include <linux/syscalls.h>
33 #include <linux/fcntl.h> 33 #include <linux/fcntl.h>
34 #include <linux/rcupdate.h> 34 #include <linux/rcupdate.h>
35 #include <linux/capability.h> 35 #include <linux/capability.h>
36 #include <linux/cpu.h> 36 #include <linux/cpu.h>
37 #include <linux/moduleparam.h> 37 #include <linux/moduleparam.h>
38 #include <linux/errno.h> 38 #include <linux/errno.h>
39 #include <linux/err.h> 39 #include <linux/err.h>
40 #include <linux/vermagic.h> 40 #include <linux/vermagic.h>
41 #include <linux/notifier.h> 41 #include <linux/notifier.h>
42 #include <linux/sched.h> 42 #include <linux/sched.h>
43 #include <linux/stop_machine.h> 43 #include <linux/stop_machine.h>
44 #include <linux/device.h> 44 #include <linux/device.h>
45 #include <linux/string.h> 45 #include <linux/string.h>
46 #include <linux/mutex.h> 46 #include <linux/mutex.h>
47 #include <linux/rculist.h> 47 #include <linux/rculist.h>
48 #include <asm/uaccess.h> 48 #include <asm/uaccess.h>
49 #include <asm/cacheflush.h> 49 #include <asm/cacheflush.h>
50 #include <asm/mmu_context.h> 50 #include <asm/mmu_context.h>
51 #include <linux/license.h> 51 #include <linux/license.h>
52 #include <asm/sections.h> 52 #include <asm/sections.h>
53 #include <linux/tracepoint.h> 53 #include <linux/tracepoint.h>
54 #include <linux/ftrace.h> 54 #include <linux/ftrace.h>
55 #include <linux/async.h> 55 #include <linux/async.h>
56 #include <linux/percpu.h> 56 #include <linux/percpu.h>
57 #include <linux/kmemleak.h> 57 #include <linux/kmemleak.h>
58 58
59 #define CREATE_TRACE_POINTS 59 #define CREATE_TRACE_POINTS
60 #include <trace/events/module.h> 60 #include <trace/events/module.h>
61 61
62 EXPORT_TRACEPOINT_SYMBOL(module_get); 62 EXPORT_TRACEPOINT_SYMBOL(module_get);
63 63
64 #if 0 64 #if 0
65 #define DEBUGP printk 65 #define DEBUGP printk
66 #else 66 #else
67 #define DEBUGP(fmt , a...) 67 #define DEBUGP(fmt , a...)
68 #endif 68 #endif
69 69
70 #ifndef ARCH_SHF_SMALL 70 #ifndef ARCH_SHF_SMALL
71 #define ARCH_SHF_SMALL 0 71 #define ARCH_SHF_SMALL 0
72 #endif 72 #endif
73 73
74 /* If this is set, the section belongs in the init part of the module */ 74 /* If this is set, the section belongs in the init part of the module */
75 #define INIT_OFFSET_MASK (1UL << (BITS_PER_LONG-1)) 75 #define INIT_OFFSET_MASK (1UL << (BITS_PER_LONG-1))
76 76
77 /* List of modules, protected by module_mutex or preempt_disable 77 /* List of modules, protected by module_mutex or preempt_disable
78 * (delete uses stop_machine/add uses RCU list operations). */ 78 * (delete uses stop_machine/add uses RCU list operations). */
79 DEFINE_MUTEX(module_mutex); 79 DEFINE_MUTEX(module_mutex);
80 EXPORT_SYMBOL_GPL(module_mutex); 80 EXPORT_SYMBOL_GPL(module_mutex);
81 static LIST_HEAD(modules); 81 static LIST_HEAD(modules);
82 82
83 /* Block module loading/unloading? */ 83 /* Block module loading/unloading? */
84 int modules_disabled = 0; 84 int modules_disabled = 0;
85 85
86 /* Waiting for a module to finish initializing? */ 86 /* Waiting for a module to finish initializing? */
87 static DECLARE_WAIT_QUEUE_HEAD(module_wq); 87 static DECLARE_WAIT_QUEUE_HEAD(module_wq);
88 88
89 static BLOCKING_NOTIFIER_HEAD(module_notify_list); 89 static BLOCKING_NOTIFIER_HEAD(module_notify_list);
90 90
91 /* Bounds of module allocation, for speeding __module_address */ 91 /* Bounds of module allocation, for speeding __module_address */
92 static unsigned long module_addr_min = -1UL, module_addr_max = 0; 92 static unsigned long module_addr_min = -1UL, module_addr_max = 0;
93 93
94 int register_module_notifier(struct notifier_block * nb) 94 int register_module_notifier(struct notifier_block * nb)
95 { 95 {
96 return blocking_notifier_chain_register(&module_notify_list, nb); 96 return blocking_notifier_chain_register(&module_notify_list, nb);
97 } 97 }
98 EXPORT_SYMBOL(register_module_notifier); 98 EXPORT_SYMBOL(register_module_notifier);
99 99
100 int unregister_module_notifier(struct notifier_block * nb) 100 int unregister_module_notifier(struct notifier_block * nb)
101 { 101 {
102 return blocking_notifier_chain_unregister(&module_notify_list, nb); 102 return blocking_notifier_chain_unregister(&module_notify_list, nb);
103 } 103 }
104 EXPORT_SYMBOL(unregister_module_notifier); 104 EXPORT_SYMBOL(unregister_module_notifier);
105 105
106 /* We require a truly strong try_module_get(): 0 means failure due to 106 /* We require a truly strong try_module_get(): 0 means failure due to
107 ongoing or failed initialization etc. */ 107 ongoing or failed initialization etc. */
108 static inline int strong_try_module_get(struct module *mod) 108 static inline int strong_try_module_get(struct module *mod)
109 { 109 {
110 if (mod && mod->state == MODULE_STATE_COMING) 110 if (mod && mod->state == MODULE_STATE_COMING)
111 return -EBUSY; 111 return -EBUSY;
112 if (try_module_get(mod)) 112 if (try_module_get(mod))
113 return 0; 113 return 0;
114 else 114 else
115 return -ENOENT; 115 return -ENOENT;
116 } 116 }
117 117
118 static inline void add_taint_module(struct module *mod, unsigned flag) 118 static inline void add_taint_module(struct module *mod, unsigned flag)
119 { 119 {
120 add_taint(flag); 120 add_taint(flag);
121 mod->taints |= (1U << flag); 121 mod->taints |= (1U << flag);
122 } 122 }
123 123
124 /* 124 /*
125 * A thread that wants to hold a reference to a module only while it 125 * A thread that wants to hold a reference to a module only while it
126 * is running can call this to safely exit. nfsd and lockd use this. 126 * is running can call this to safely exit. nfsd and lockd use this.
127 */ 127 */
128 void __module_put_and_exit(struct module *mod, long code) 128 void __module_put_and_exit(struct module *mod, long code)
129 { 129 {
130 module_put(mod); 130 module_put(mod);
131 do_exit(code); 131 do_exit(code);
132 } 132 }
133 EXPORT_SYMBOL(__module_put_and_exit); 133 EXPORT_SYMBOL(__module_put_and_exit);
134 134
135 /* Find a module section: 0 means not found. */ 135 /* Find a module section: 0 means not found. */
136 static unsigned int find_sec(Elf_Ehdr *hdr, 136 static unsigned int find_sec(Elf_Ehdr *hdr,
137 Elf_Shdr *sechdrs, 137 Elf_Shdr *sechdrs,
138 const char *secstrings, 138 const char *secstrings,
139 const char *name) 139 const char *name)
140 { 140 {
141 unsigned int i; 141 unsigned int i;
142 142
143 for (i = 1; i < hdr->e_shnum; i++) 143 for (i = 1; i < hdr->e_shnum; i++)
144 /* Alloc bit cleared means "ignore it." */ 144 /* Alloc bit cleared means "ignore it." */
145 if ((sechdrs[i].sh_flags & SHF_ALLOC) 145 if ((sechdrs[i].sh_flags & SHF_ALLOC)
146 && strcmp(secstrings+sechdrs[i].sh_name, name) == 0) 146 && strcmp(secstrings+sechdrs[i].sh_name, name) == 0)
147 return i; 147 return i;
148 return 0; 148 return 0;
149 } 149 }
150 150
151 /* Find a module section, or NULL. */ 151 /* Find a module section, or NULL. */
152 static void *section_addr(Elf_Ehdr *hdr, Elf_Shdr *shdrs, 152 static void *section_addr(Elf_Ehdr *hdr, Elf_Shdr *shdrs,
153 const char *secstrings, const char *name) 153 const char *secstrings, const char *name)
154 { 154 {
155 /* Section 0 has sh_addr 0. */ 155 /* Section 0 has sh_addr 0. */
156 return (void *)shdrs[find_sec(hdr, shdrs, secstrings, name)].sh_addr; 156 return (void *)shdrs[find_sec(hdr, shdrs, secstrings, name)].sh_addr;
157 } 157 }
158 158
159 /* Find a module section, or NULL. Fill in number of "objects" in section. */ 159 /* Find a module section, or NULL. Fill in number of "objects" in section. */
160 static void *section_objs(Elf_Ehdr *hdr, 160 static void *section_objs(Elf_Ehdr *hdr,
161 Elf_Shdr *sechdrs, 161 Elf_Shdr *sechdrs,
162 const char *secstrings, 162 const char *secstrings,
163 const char *name, 163 const char *name,
164 size_t object_size, 164 size_t object_size,
165 unsigned int *num) 165 unsigned int *num)
166 { 166 {
167 unsigned int sec = find_sec(hdr, sechdrs, secstrings, name); 167 unsigned int sec = find_sec(hdr, sechdrs, secstrings, name);
168 168
169 /* Section 0 has sh_addr 0 and sh_size 0. */ 169 /* Section 0 has sh_addr 0 and sh_size 0. */
170 *num = sechdrs[sec].sh_size / object_size; 170 *num = sechdrs[sec].sh_size / object_size;
171 return (void *)sechdrs[sec].sh_addr; 171 return (void *)sechdrs[sec].sh_addr;
172 } 172 }
173 173
174 /* Provided by the linker */ 174 /* Provided by the linker */
175 extern const struct kernel_symbol __start___ksymtab[]; 175 extern const struct kernel_symbol __start___ksymtab[];
176 extern const struct kernel_symbol __stop___ksymtab[]; 176 extern const struct kernel_symbol __stop___ksymtab[];
177 extern const struct kernel_symbol __start___ksymtab_gpl[]; 177 extern const struct kernel_symbol __start___ksymtab_gpl[];
178 extern const struct kernel_symbol __stop___ksymtab_gpl[]; 178 extern const struct kernel_symbol __stop___ksymtab_gpl[];
179 extern const struct kernel_symbol __start___ksymtab_gpl_future[]; 179 extern const struct kernel_symbol __start___ksymtab_gpl_future[];
180 extern const struct kernel_symbol __stop___ksymtab_gpl_future[]; 180 extern const struct kernel_symbol __stop___ksymtab_gpl_future[];
181 extern const struct kernel_symbol __start___ksymtab_gpl_future[]; 181 extern const struct kernel_symbol __start___ksymtab_gpl_future[];
182 extern const struct kernel_symbol __stop___ksymtab_gpl_future[]; 182 extern const struct kernel_symbol __stop___ksymtab_gpl_future[];
183 extern const unsigned long __start___kcrctab[]; 183 extern const unsigned long __start___kcrctab[];
184 extern const unsigned long __start___kcrctab_gpl[]; 184 extern const unsigned long __start___kcrctab_gpl[];
185 extern const unsigned long __start___kcrctab_gpl_future[]; 185 extern const unsigned long __start___kcrctab_gpl_future[];
186 #ifdef CONFIG_UNUSED_SYMBOLS 186 #ifdef CONFIG_UNUSED_SYMBOLS
187 extern const struct kernel_symbol __start___ksymtab_unused[]; 187 extern const struct kernel_symbol __start___ksymtab_unused[];
188 extern const struct kernel_symbol __stop___ksymtab_unused[]; 188 extern const struct kernel_symbol __stop___ksymtab_unused[];
189 extern const struct kernel_symbol __start___ksymtab_unused_gpl[]; 189 extern const struct kernel_symbol __start___ksymtab_unused_gpl[];
190 extern const struct kernel_symbol __stop___ksymtab_unused_gpl[]; 190 extern const struct kernel_symbol __stop___ksymtab_unused_gpl[];
191 extern const unsigned long __start___kcrctab_unused[]; 191 extern const unsigned long __start___kcrctab_unused[];
192 extern const unsigned long __start___kcrctab_unused_gpl[]; 192 extern const unsigned long __start___kcrctab_unused_gpl[];
193 #endif 193 #endif
194 194
195 #ifndef CONFIG_MODVERSIONS 195 #ifndef CONFIG_MODVERSIONS
196 #define symversion(base, idx) NULL 196 #define symversion(base, idx) NULL
197 #else 197 #else
198 #define symversion(base, idx) ((base != NULL) ? ((base) + (idx)) : NULL) 198 #define symversion(base, idx) ((base != NULL) ? ((base) + (idx)) : NULL)
199 #endif 199 #endif
200 200
201 static bool each_symbol_in_section(const struct symsearch *arr, 201 static bool each_symbol_in_section(const struct symsearch *arr,
202 unsigned int arrsize, 202 unsigned int arrsize,
203 struct module *owner, 203 struct module *owner,
204 bool (*fn)(const struct symsearch *syms, 204 bool (*fn)(const struct symsearch *syms,
205 struct module *owner, 205 struct module *owner,
206 unsigned int symnum, void *data), 206 unsigned int symnum, void *data),
207 void *data) 207 void *data)
208 { 208 {
209 unsigned int i, j; 209 unsigned int i, j;
210 210
211 for (j = 0; j < arrsize; j++) { 211 for (j = 0; j < arrsize; j++) {
212 for (i = 0; i < arr[j].stop - arr[j].start; i++) 212 for (i = 0; i < arr[j].stop - arr[j].start; i++)
213 if (fn(&arr[j], owner, i, data)) 213 if (fn(&arr[j], owner, i, data))
214 return true; 214 return true;
215 } 215 }
216 216
217 return false; 217 return false;
218 } 218 }
219 219
220 /* Returns true as soon as fn returns true, otherwise false. */ 220 /* Returns true as soon as fn returns true, otherwise false. */
221 bool each_symbol(bool (*fn)(const struct symsearch *arr, struct module *owner, 221 bool each_symbol(bool (*fn)(const struct symsearch *arr, struct module *owner,
222 unsigned int symnum, void *data), void *data) 222 unsigned int symnum, void *data), void *data)
223 { 223 {
224 struct module *mod; 224 struct module *mod;
225 const struct symsearch arr[] = { 225 const struct symsearch arr[] = {
226 { __start___ksymtab, __stop___ksymtab, __start___kcrctab, 226 { __start___ksymtab, __stop___ksymtab, __start___kcrctab,
227 NOT_GPL_ONLY, false }, 227 NOT_GPL_ONLY, false },
228 { __start___ksymtab_gpl, __stop___ksymtab_gpl, 228 { __start___ksymtab_gpl, __stop___ksymtab_gpl,
229 __start___kcrctab_gpl, 229 __start___kcrctab_gpl,
230 GPL_ONLY, false }, 230 GPL_ONLY, false },
231 { __start___ksymtab_gpl_future, __stop___ksymtab_gpl_future, 231 { __start___ksymtab_gpl_future, __stop___ksymtab_gpl_future,
232 __start___kcrctab_gpl_future, 232 __start___kcrctab_gpl_future,
233 WILL_BE_GPL_ONLY, false }, 233 WILL_BE_GPL_ONLY, false },
234 #ifdef CONFIG_UNUSED_SYMBOLS 234 #ifdef CONFIG_UNUSED_SYMBOLS
235 { __start___ksymtab_unused, __stop___ksymtab_unused, 235 { __start___ksymtab_unused, __stop___ksymtab_unused,
236 __start___kcrctab_unused, 236 __start___kcrctab_unused,
237 NOT_GPL_ONLY, true }, 237 NOT_GPL_ONLY, true },
238 { __start___ksymtab_unused_gpl, __stop___ksymtab_unused_gpl, 238 { __start___ksymtab_unused_gpl, __stop___ksymtab_unused_gpl,
239 __start___kcrctab_unused_gpl, 239 __start___kcrctab_unused_gpl,
240 GPL_ONLY, true }, 240 GPL_ONLY, true },
241 #endif 241 #endif
242 }; 242 };
243 243
244 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))
245 return true; 245 return true;
246 246
247 list_for_each_entry_rcu(mod, &modules, list) { 247 list_for_each_entry_rcu(mod, &modules, list) {
248 struct symsearch arr[] = { 248 struct symsearch arr[] = {
249 { mod->syms, mod->syms + mod->num_syms, mod->crcs, 249 { mod->syms, mod->syms + mod->num_syms, mod->crcs,
250 NOT_GPL_ONLY, false }, 250 NOT_GPL_ONLY, false },
251 { mod->gpl_syms, mod->gpl_syms + mod->num_gpl_syms, 251 { mod->gpl_syms, mod->gpl_syms + mod->num_gpl_syms,
252 mod->gpl_crcs, 252 mod->gpl_crcs,
253 GPL_ONLY, false }, 253 GPL_ONLY, false },
254 { mod->gpl_future_syms, 254 { mod->gpl_future_syms,
255 mod->gpl_future_syms + mod->num_gpl_future_syms, 255 mod->gpl_future_syms + mod->num_gpl_future_syms,
256 mod->gpl_future_crcs, 256 mod->gpl_future_crcs,
257 WILL_BE_GPL_ONLY, false }, 257 WILL_BE_GPL_ONLY, false },
258 #ifdef CONFIG_UNUSED_SYMBOLS 258 #ifdef CONFIG_UNUSED_SYMBOLS
259 { mod->unused_syms, 259 { mod->unused_syms,
260 mod->unused_syms + mod->num_unused_syms, 260 mod->unused_syms + mod->num_unused_syms,
261 mod->unused_crcs, 261 mod->unused_crcs,
262 NOT_GPL_ONLY, true }, 262 NOT_GPL_ONLY, true },
263 { mod->unused_gpl_syms, 263 { mod->unused_gpl_syms,
264 mod->unused_gpl_syms + mod->num_unused_gpl_syms, 264 mod->unused_gpl_syms + mod->num_unused_gpl_syms,
265 mod->unused_gpl_crcs, 265 mod->unused_gpl_crcs,
266 GPL_ONLY, true }, 266 GPL_ONLY, true },
267 #endif 267 #endif
268 }; 268 };
269 269
270 if (each_symbol_in_section(arr, ARRAY_SIZE(arr), mod, fn, data)) 270 if (each_symbol_in_section(arr, ARRAY_SIZE(arr), mod, fn, data))
271 return true; 271 return true;
272 } 272 }
273 return false; 273 return false;
274 } 274 }
275 EXPORT_SYMBOL_GPL(each_symbol); 275 EXPORT_SYMBOL_GPL(each_symbol);
276 276
277 struct find_symbol_arg { 277 struct find_symbol_arg {
278 /* Input */ 278 /* Input */
279 const char *name; 279 const char *name;
280 bool gplok; 280 bool gplok;
281 bool warn; 281 bool warn;
282 282
283 /* Output */ 283 /* Output */
284 struct module *owner; 284 struct module *owner;
285 const unsigned long *crc; 285 const unsigned long *crc;
286 const struct kernel_symbol *sym; 286 const struct kernel_symbol *sym;
287 }; 287 };
288 288
289 static bool find_symbol_in_section(const struct symsearch *syms, 289 static bool find_symbol_in_section(const struct symsearch *syms,
290 struct module *owner, 290 struct module *owner,
291 unsigned int symnum, void *data) 291 unsigned int symnum, void *data)
292 { 292 {
293 struct find_symbol_arg *fsa = data; 293 struct find_symbol_arg *fsa = data;
294 294
295 if (strcmp(syms->start[symnum].name, fsa->name) != 0) 295 if (strcmp(syms->start[symnum].name, fsa->name) != 0)
296 return false; 296 return false;
297 297
298 if (!fsa->gplok) { 298 if (!fsa->gplok) {
299 if (syms->licence == GPL_ONLY) 299 if (syms->licence == GPL_ONLY)
300 return false; 300 return false;
301 if (syms->licence == WILL_BE_GPL_ONLY && fsa->warn) { 301 if (syms->licence == WILL_BE_GPL_ONLY && fsa->warn) {
302 printk(KERN_WARNING "Symbol %s is being used " 302 printk(KERN_WARNING "Symbol %s is being used "
303 "by a non-GPL module, which will not " 303 "by a non-GPL module, which will not "
304 "be allowed in the future\n", fsa->name); 304 "be allowed in the future\n", fsa->name);
305 printk(KERN_WARNING "Please see the file " 305 printk(KERN_WARNING "Please see the file "
306 "Documentation/feature-removal-schedule.txt " 306 "Documentation/feature-removal-schedule.txt "
307 "in the kernel source tree for more details.\n"); 307 "in the kernel source tree for more details.\n");
308 } 308 }
309 } 309 }
310 310
311 #ifdef CONFIG_UNUSED_SYMBOLS 311 #ifdef CONFIG_UNUSED_SYMBOLS
312 if (syms->unused && fsa->warn) { 312 if (syms->unused && fsa->warn) {
313 printk(KERN_WARNING "Symbol %s is marked as UNUSED, " 313 printk(KERN_WARNING "Symbol %s is marked as UNUSED, "
314 "however this module is using it.\n", fsa->name); 314 "however this module is using it.\n", fsa->name);
315 printk(KERN_WARNING 315 printk(KERN_WARNING
316 "This symbol will go away in the future.\n"); 316 "This symbol will go away in the future.\n");
317 printk(KERN_WARNING 317 printk(KERN_WARNING
318 "Please evalute if this is the right api to use and if " 318 "Please evalute if this is the right api to use and if "
319 "it really is, submit a report the linux kernel " 319 "it really is, submit a report the linux kernel "
320 "mailinglist together with submitting your code for " 320 "mailinglist together with submitting your code for "
321 "inclusion.\n"); 321 "inclusion.\n");
322 } 322 }
323 #endif 323 #endif
324 324
325 fsa->owner = owner; 325 fsa->owner = owner;
326 fsa->crc = symversion(syms->crcs, symnum); 326 fsa->crc = symversion(syms->crcs, symnum);
327 fsa->sym = &syms->start[symnum]; 327 fsa->sym = &syms->start[symnum];
328 return true; 328 return true;
329 } 329 }
330 330
331 /* Find a symbol and return it, along with, (optional) crc and 331 /* Find a symbol and return it, along with, (optional) crc and
332 * (optional) module which owns it */ 332 * (optional) module which owns it */
333 const struct kernel_symbol *find_symbol(const char *name, 333 const struct kernel_symbol *find_symbol(const char *name,
334 struct module **owner, 334 struct module **owner,
335 const unsigned long **crc, 335 const unsigned long **crc,
336 bool gplok, 336 bool gplok,
337 bool warn) 337 bool warn)
338 { 338 {
339 struct find_symbol_arg fsa; 339 struct find_symbol_arg fsa;
340 340
341 fsa.name = name; 341 fsa.name = name;
342 fsa.gplok = gplok; 342 fsa.gplok = gplok;
343 fsa.warn = warn; 343 fsa.warn = warn;
344 344
345 if (each_symbol(find_symbol_in_section, &fsa)) { 345 if (each_symbol(find_symbol_in_section, &fsa)) {
346 if (owner) 346 if (owner)
347 *owner = fsa.owner; 347 *owner = fsa.owner;
348 if (crc) 348 if (crc)
349 *crc = fsa.crc; 349 *crc = fsa.crc;
350 return fsa.sym; 350 return fsa.sym;
351 } 351 }
352 352
353 DEBUGP("Failed to find symbol %s\n", name); 353 DEBUGP("Failed to find symbol %s\n", name);
354 return NULL; 354 return NULL;
355 } 355 }
356 EXPORT_SYMBOL_GPL(find_symbol); 356 EXPORT_SYMBOL_GPL(find_symbol);
357 357
358 /* Search for module by name: must hold module_mutex. */ 358 /* Search for module by name: must hold module_mutex. */
359 struct module *find_module(const char *name) 359 struct module *find_module(const char *name)
360 { 360 {
361 struct module *mod; 361 struct module *mod;
362 362
363 list_for_each_entry(mod, &modules, list) { 363 list_for_each_entry(mod, &modules, list) {
364 if (strcmp(mod->name, name) == 0) 364 if (strcmp(mod->name, name) == 0)
365 return mod; 365 return mod;
366 } 366 }
367 return NULL; 367 return NULL;
368 } 368 }
369 EXPORT_SYMBOL_GPL(find_module); 369 EXPORT_SYMBOL_GPL(find_module);
370 370
371 #ifdef CONFIG_SMP 371 #ifdef CONFIG_SMP
372 372
373 #ifndef CONFIG_HAVE_LEGACY_PER_CPU_AREA 373 #ifndef CONFIG_HAVE_LEGACY_PER_CPU_AREA
374 374
375 static void *percpu_modalloc(unsigned long size, unsigned long align, 375 static void *percpu_modalloc(unsigned long size, unsigned long align,
376 const char *name) 376 const char *name)
377 { 377 {
378 void *ptr; 378 void *ptr;
379 379
380 if (align > PAGE_SIZE) { 380 if (align > PAGE_SIZE) {
381 printk(KERN_WARNING "%s: per-cpu alignment %li > %li\n", 381 printk(KERN_WARNING "%s: per-cpu alignment %li > %li\n",
382 name, align, PAGE_SIZE); 382 name, align, PAGE_SIZE);
383 align = PAGE_SIZE; 383 align = PAGE_SIZE;
384 } 384 }
385 385
386 ptr = __alloc_reserved_percpu(size, align); 386 ptr = __alloc_reserved_percpu(size, align);
387 if (!ptr) 387 if (!ptr)
388 printk(KERN_WARNING 388 printk(KERN_WARNING
389 "Could not allocate %lu bytes percpu data\n", size); 389 "Could not allocate %lu bytes percpu data\n", size);
390 return ptr; 390 return ptr;
391 } 391 }
392 392
393 static void percpu_modfree(void *freeme) 393 static void percpu_modfree(void *freeme)
394 { 394 {
395 free_percpu(freeme); 395 free_percpu(freeme);
396 } 396 }
397 397
398 #else /* ... CONFIG_HAVE_LEGACY_PER_CPU_AREA */ 398 #else /* ... CONFIG_HAVE_LEGACY_PER_CPU_AREA */
399 399
400 /* Number of blocks used and allocated. */ 400 /* Number of blocks used and allocated. */
401 static unsigned int pcpu_num_used, pcpu_num_allocated; 401 static unsigned int pcpu_num_used, pcpu_num_allocated;
402 /* Size of each block. -ve means used. */ 402 /* Size of each block. -ve means used. */
403 static int *pcpu_size; 403 static int *pcpu_size;
404 404
405 static int split_block(unsigned int i, unsigned short size) 405 static int split_block(unsigned int i, unsigned short size)
406 { 406 {
407 /* Reallocation required? */ 407 /* Reallocation required? */
408 if (pcpu_num_used + 1 > pcpu_num_allocated) { 408 if (pcpu_num_used + 1 > pcpu_num_allocated) {
409 int *new; 409 int *new;
410 410
411 new = krealloc(pcpu_size, sizeof(new[0])*pcpu_num_allocated*2, 411 new = krealloc(pcpu_size, sizeof(new[0])*pcpu_num_allocated*2,
412 GFP_KERNEL); 412 GFP_KERNEL);
413 if (!new) 413 if (!new)
414 return 0; 414 return 0;
415 415
416 pcpu_num_allocated *= 2; 416 pcpu_num_allocated *= 2;
417 pcpu_size = new; 417 pcpu_size = new;
418 } 418 }
419 419
420 /* Insert a new subblock */ 420 /* Insert a new subblock */
421 memmove(&pcpu_size[i+1], &pcpu_size[i], 421 memmove(&pcpu_size[i+1], &pcpu_size[i],
422 sizeof(pcpu_size[0]) * (pcpu_num_used - i)); 422 sizeof(pcpu_size[0]) * (pcpu_num_used - i));
423 pcpu_num_used++; 423 pcpu_num_used++;
424 424
425 pcpu_size[i+1] -= size; 425 pcpu_size[i+1] -= size;
426 pcpu_size[i] = size; 426 pcpu_size[i] = size;
427 return 1; 427 return 1;
428 } 428 }
429 429
430 static inline unsigned int block_size(int val) 430 static inline unsigned int block_size(int val)
431 { 431 {
432 if (val < 0) 432 if (val < 0)
433 return -val; 433 return -val;
434 return val; 434 return val;
435 } 435 }
436 436
437 static void *percpu_modalloc(unsigned long size, unsigned long align, 437 static void *percpu_modalloc(unsigned long size, unsigned long align,
438 const char *name) 438 const char *name)
439 { 439 {
440 unsigned long extra; 440 unsigned long extra;
441 unsigned int i; 441 unsigned int i;
442 void *ptr; 442 void *ptr;
443 int cpu; 443 int cpu;
444 444
445 if (align > PAGE_SIZE) { 445 if (align > PAGE_SIZE) {
446 printk(KERN_WARNING "%s: per-cpu alignment %li > %li\n", 446 printk(KERN_WARNING "%s: per-cpu alignment %li > %li\n",
447 name, align, PAGE_SIZE); 447 name, align, PAGE_SIZE);
448 align = PAGE_SIZE; 448 align = PAGE_SIZE;
449 } 449 }
450 450
451 ptr = __per_cpu_start; 451 ptr = __per_cpu_start;
452 for (i = 0; i < pcpu_num_used; ptr += block_size(pcpu_size[i]), i++) { 452 for (i = 0; i < pcpu_num_used; ptr += block_size(pcpu_size[i]), i++) {
453 /* Extra for alignment requirement. */ 453 /* Extra for alignment requirement. */
454 extra = ALIGN((unsigned long)ptr, align) - (unsigned long)ptr; 454 extra = ALIGN((unsigned long)ptr, align) - (unsigned long)ptr;
455 BUG_ON(i == 0 && extra != 0); 455 BUG_ON(i == 0 && extra != 0);
456 456
457 if (pcpu_size[i] < 0 || pcpu_size[i] < extra + size) 457 if (pcpu_size[i] < 0 || pcpu_size[i] < extra + size)
458 continue; 458 continue;
459 459
460 /* Transfer extra to previous block. */ 460 /* Transfer extra to previous block. */
461 if (pcpu_size[i-1] < 0) 461 if (pcpu_size[i-1] < 0)
462 pcpu_size[i-1] -= extra; 462 pcpu_size[i-1] -= extra;
463 else 463 else
464 pcpu_size[i-1] += extra; 464 pcpu_size[i-1] += extra;
465 pcpu_size[i] -= extra; 465 pcpu_size[i] -= extra;
466 ptr += extra; 466 ptr += extra;
467 467
468 /* Split block if warranted */ 468 /* Split block if warranted */
469 if (pcpu_size[i] - size > sizeof(unsigned long)) 469 if (pcpu_size[i] - size > sizeof(unsigned long))
470 if (!split_block(i, size)) 470 if (!split_block(i, size))
471 return NULL; 471 return NULL;
472 472
473 /* add the per-cpu scanning areas */ 473 /* add the per-cpu scanning areas */
474 for_each_possible_cpu(cpu) 474 for_each_possible_cpu(cpu)
475 kmemleak_alloc(ptr + per_cpu_offset(cpu), size, 0, 475 kmemleak_alloc(ptr + per_cpu_offset(cpu), size, 0,
476 GFP_KERNEL); 476 GFP_KERNEL);
477 477
478 /* Mark allocated */ 478 /* Mark allocated */
479 pcpu_size[i] = -pcpu_size[i]; 479 pcpu_size[i] = -pcpu_size[i];
480 return ptr; 480 return ptr;
481 } 481 }
482 482
483 printk(KERN_WARNING "Could not allocate %lu bytes percpu data\n", 483 printk(KERN_WARNING "Could not allocate %lu bytes percpu data\n",
484 size); 484 size);
485 return NULL; 485 return NULL;
486 } 486 }
487 487
488 static void percpu_modfree(void *freeme) 488 static void percpu_modfree(void *freeme)
489 { 489 {
490 unsigned int i; 490 unsigned int i;
491 void *ptr = __per_cpu_start + block_size(pcpu_size[0]); 491 void *ptr = __per_cpu_start + block_size(pcpu_size[0]);
492 int cpu; 492 int cpu;
493 493
494 /* First entry is core kernel percpu data. */ 494 /* First entry is core kernel percpu data. */
495 for (i = 1; i < pcpu_num_used; ptr += block_size(pcpu_size[i]), i++) { 495 for (i = 1; i < pcpu_num_used; ptr += block_size(pcpu_size[i]), i++) {
496 if (ptr == freeme) { 496 if (ptr == freeme) {
497 pcpu_size[i] = -pcpu_size[i]; 497 pcpu_size[i] = -pcpu_size[i];
498 goto free; 498 goto free;
499 } 499 }
500 } 500 }
501 BUG(); 501 BUG();
502 502
503 free: 503 free:
504 /* remove the per-cpu scanning areas */ 504 /* remove the per-cpu scanning areas */
505 for_each_possible_cpu(cpu) 505 for_each_possible_cpu(cpu)
506 kmemleak_free(freeme + per_cpu_offset(cpu)); 506 kmemleak_free(freeme + per_cpu_offset(cpu));
507 507
508 /* Merge with previous? */ 508 /* Merge with previous? */
509 if (pcpu_size[i-1] >= 0) { 509 if (pcpu_size[i-1] >= 0) {
510 pcpu_size[i-1] += pcpu_size[i]; 510 pcpu_size[i-1] += pcpu_size[i];
511 pcpu_num_used--; 511 pcpu_num_used--;
512 memmove(&pcpu_size[i], &pcpu_size[i+1], 512 memmove(&pcpu_size[i], &pcpu_size[i+1],
513 (pcpu_num_used - i) * sizeof(pcpu_size[0])); 513 (pcpu_num_used - i) * sizeof(pcpu_size[0]));
514 i--; 514 i--;
515 } 515 }
516 /* Merge with next? */ 516 /* Merge with next? */
517 if (i+1 < pcpu_num_used && pcpu_size[i+1] >= 0) { 517 if (i+1 < pcpu_num_used && pcpu_size[i+1] >= 0) {
518 pcpu_size[i] += pcpu_size[i+1]; 518 pcpu_size[i] += pcpu_size[i+1];
519 pcpu_num_used--; 519 pcpu_num_used--;
520 memmove(&pcpu_size[i+1], &pcpu_size[i+2], 520 memmove(&pcpu_size[i+1], &pcpu_size[i+2],
521 (pcpu_num_used - (i+1)) * sizeof(pcpu_size[0])); 521 (pcpu_num_used - (i+1)) * sizeof(pcpu_size[0]));
522 } 522 }
523 } 523 }
524 524
525 static int percpu_modinit(void) 525 static int percpu_modinit(void)
526 { 526 {
527 pcpu_num_used = 2; 527 pcpu_num_used = 2;
528 pcpu_num_allocated = 2; 528 pcpu_num_allocated = 2;
529 pcpu_size = kmalloc(sizeof(pcpu_size[0]) * pcpu_num_allocated, 529 pcpu_size = kmalloc(sizeof(pcpu_size[0]) * pcpu_num_allocated,
530 GFP_KERNEL); 530 GFP_KERNEL);
531 /* Static in-kernel percpu data (used). */ 531 /* Static in-kernel percpu data (used). */
532 pcpu_size[0] = -(__per_cpu_end-__per_cpu_start); 532 pcpu_size[0] = -(__per_cpu_end-__per_cpu_start);
533 /* Free room. */ 533 /* Free room. */
534 pcpu_size[1] = PERCPU_ENOUGH_ROOM + pcpu_size[0]; 534 pcpu_size[1] = PERCPU_ENOUGH_ROOM + pcpu_size[0];
535 if (pcpu_size[1] < 0) { 535 if (pcpu_size[1] < 0) {
536 printk(KERN_ERR "No per-cpu room for modules.\n"); 536 printk(KERN_ERR "No per-cpu room for modules.\n");
537 pcpu_num_used = 1; 537 pcpu_num_used = 1;
538 } 538 }
539 539
540 return 0; 540 return 0;
541 } 541 }
542 __initcall(percpu_modinit); 542 __initcall(percpu_modinit);
543 543
544 #endif /* CONFIG_HAVE_LEGACY_PER_CPU_AREA */ 544 #endif /* CONFIG_HAVE_LEGACY_PER_CPU_AREA */
545 545
546 static unsigned int find_pcpusec(Elf_Ehdr *hdr, 546 static unsigned int find_pcpusec(Elf_Ehdr *hdr,
547 Elf_Shdr *sechdrs, 547 Elf_Shdr *sechdrs,
548 const char *secstrings) 548 const char *secstrings)
549 { 549 {
550 return find_sec(hdr, sechdrs, secstrings, ".data.percpu"); 550 return find_sec(hdr, sechdrs, secstrings, ".data.percpu");
551 } 551 }
552 552
553 static void percpu_modcopy(void *pcpudest, const void *from, unsigned long size) 553 static void percpu_modcopy(void *pcpudest, const void *from, unsigned long size)
554 { 554 {
555 int cpu; 555 int cpu;
556 556
557 for_each_possible_cpu(cpu) 557 for_each_possible_cpu(cpu)
558 memcpy(pcpudest + per_cpu_offset(cpu), from, size); 558 memcpy(pcpudest + per_cpu_offset(cpu), from, size);
559 } 559 }
560 560
561 #else /* ... !CONFIG_SMP */ 561 #else /* ... !CONFIG_SMP */
562 562
563 static inline void *percpu_modalloc(unsigned long size, unsigned long align, 563 static inline void *percpu_modalloc(unsigned long size, unsigned long align,
564 const char *name) 564 const char *name)
565 { 565 {
566 return NULL; 566 return NULL;
567 } 567 }
568 static inline void percpu_modfree(void *pcpuptr) 568 static inline void percpu_modfree(void *pcpuptr)
569 { 569 {
570 BUG(); 570 BUG();
571 } 571 }
572 static inline unsigned int find_pcpusec(Elf_Ehdr *hdr, 572 static inline unsigned int find_pcpusec(Elf_Ehdr *hdr,
573 Elf_Shdr *sechdrs, 573 Elf_Shdr *sechdrs,
574 const char *secstrings) 574 const char *secstrings)
575 { 575 {
576 return 0; 576 return 0;
577 } 577 }
578 static inline void percpu_modcopy(void *pcpudst, const void *src, 578 static inline void percpu_modcopy(void *pcpudst, const void *src,
579 unsigned long size) 579 unsigned long size)
580 { 580 {
581 /* pcpusec should be 0, and size of that section should be 0. */ 581 /* pcpusec should be 0, and size of that section should be 0. */
582 BUG_ON(size != 0); 582 BUG_ON(size != 0);
583 } 583 }
584 584
585 #endif /* CONFIG_SMP */ 585 #endif /* CONFIG_SMP */
586 586
587 #define MODINFO_ATTR(field) \ 587 #define MODINFO_ATTR(field) \
588 static void setup_modinfo_##field(struct module *mod, const char *s) \ 588 static void setup_modinfo_##field(struct module *mod, const char *s) \
589 { \ 589 { \
590 mod->field = kstrdup(s, GFP_KERNEL); \ 590 mod->field = kstrdup(s, GFP_KERNEL); \
591 } \ 591 } \
592 static ssize_t show_modinfo_##field(struct module_attribute *mattr, \ 592 static ssize_t show_modinfo_##field(struct module_attribute *mattr, \
593 struct module *mod, char *buffer) \ 593 struct module *mod, char *buffer) \
594 { \ 594 { \
595 return sprintf(buffer, "%s\n", mod->field); \ 595 return sprintf(buffer, "%s\n", mod->field); \
596 } \ 596 } \
597 static int modinfo_##field##_exists(struct module *mod) \ 597 static int modinfo_##field##_exists(struct module *mod) \
598 { \ 598 { \
599 return mod->field != NULL; \ 599 return mod->field != NULL; \
600 } \ 600 } \
601 static void free_modinfo_##field(struct module *mod) \ 601 static void free_modinfo_##field(struct module *mod) \
602 { \ 602 { \
603 kfree(mod->field); \ 603 kfree(mod->field); \
604 mod->field = NULL; \ 604 mod->field = NULL; \
605 } \ 605 } \
606 static struct module_attribute modinfo_##field = { \ 606 static struct module_attribute modinfo_##field = { \
607 .attr = { .name = __stringify(field), .mode = 0444 }, \ 607 .attr = { .name = __stringify(field), .mode = 0444 }, \
608 .show = show_modinfo_##field, \ 608 .show = show_modinfo_##field, \
609 .setup = setup_modinfo_##field, \ 609 .setup = setup_modinfo_##field, \
610 .test = modinfo_##field##_exists, \ 610 .test = modinfo_##field##_exists, \
611 .free = free_modinfo_##field, \ 611 .free = free_modinfo_##field, \
612 }; 612 };
613 613
614 MODINFO_ATTR(version); 614 MODINFO_ATTR(version);
615 MODINFO_ATTR(srcversion); 615 MODINFO_ATTR(srcversion);
616 616
617 static char last_unloaded_module[MODULE_NAME_LEN+1]; 617 static char last_unloaded_module[MODULE_NAME_LEN+1];
618 618
619 #ifdef CONFIG_MODULE_UNLOAD 619 #ifdef CONFIG_MODULE_UNLOAD
620 /* Init the unload section of the module. */ 620 /* Init the unload section of the module. */
621 static void module_unload_init(struct module *mod) 621 static void module_unload_init(struct module *mod)
622 { 622 {
623 int cpu; 623 int cpu;
624 624
625 INIT_LIST_HEAD(&mod->modules_which_use_me); 625 INIT_LIST_HEAD(&mod->modules_which_use_me);
626 for_each_possible_cpu(cpu) 626 for_each_possible_cpu(cpu)
627 local_set(__module_ref_addr(mod, cpu), 0); 627 local_set(__module_ref_addr(mod, cpu), 0);
628 /* Hold reference count during initialization. */ 628 /* Hold reference count during initialization. */
629 local_set(__module_ref_addr(mod, raw_smp_processor_id()), 1); 629 local_set(__module_ref_addr(mod, raw_smp_processor_id()), 1);
630 /* Backwards compatibility macros put refcount during init. */ 630 /* Backwards compatibility macros put refcount during init. */
631 mod->waiter = current; 631 mod->waiter = current;
632 } 632 }
633 633
634 /* modules using other modules */ 634 /* modules using other modules */
635 struct module_use 635 struct module_use
636 { 636 {
637 struct list_head list; 637 struct list_head list;
638 struct module *module_which_uses; 638 struct module *module_which_uses;
639 }; 639 };
640 640
641 /* Does a already use b? */ 641 /* Does a already use b? */
642 static int already_uses(struct module *a, struct module *b) 642 static int already_uses(struct module *a, struct module *b)
643 { 643 {
644 struct module_use *use; 644 struct module_use *use;
645 645
646 list_for_each_entry(use, &b->modules_which_use_me, list) { 646 list_for_each_entry(use, &b->modules_which_use_me, list) {
647 if (use->module_which_uses == a) { 647 if (use->module_which_uses == a) {
648 DEBUGP("%s uses %s!\n", a->name, b->name); 648 DEBUGP("%s uses %s!\n", a->name, b->name);
649 return 1; 649 return 1;
650 } 650 }
651 } 651 }
652 DEBUGP("%s does not use %s!\n", a->name, b->name); 652 DEBUGP("%s does not use %s!\n", a->name, b->name);
653 return 0; 653 return 0;
654 } 654 }
655 655
656 /* Module a uses b */ 656 /* Module a uses b */
657 int use_module(struct module *a, struct module *b) 657 int use_module(struct module *a, struct module *b)
658 { 658 {
659 struct module_use *use; 659 struct module_use *use;
660 int no_warn, err; 660 int no_warn, err;
661 661
662 if (b == NULL || already_uses(a, b)) return 1; 662 if (b == NULL || already_uses(a, b)) return 1;
663 663
664 /* If we're interrupted or time out, we fail. */ 664 /* If we're interrupted or time out, we fail. */
665 if (wait_event_interruptible_timeout( 665 if (wait_event_interruptible_timeout(
666 module_wq, (err = strong_try_module_get(b)) != -EBUSY, 666 module_wq, (err = strong_try_module_get(b)) != -EBUSY,
667 30 * HZ) <= 0) { 667 30 * HZ) <= 0) {
668 printk("%s: gave up waiting for init of module %s.\n", 668 printk("%s: gave up waiting for init of module %s.\n",
669 a->name, b->name); 669 a->name, b->name);
670 return 0; 670 return 0;
671 } 671 }
672 672
673 /* If strong_try_module_get() returned a different error, we fail. */ 673 /* If strong_try_module_get() returned a different error, we fail. */
674 if (err) 674 if (err)
675 return 0; 675 return 0;
676 676
677 DEBUGP("Allocating new usage for %s.\n", a->name); 677 DEBUGP("Allocating new usage for %s.\n", a->name);
678 use = kmalloc(sizeof(*use), GFP_ATOMIC); 678 use = kmalloc(sizeof(*use), GFP_ATOMIC);
679 if (!use) { 679 if (!use) {
680 printk("%s: out of memory loading\n", a->name); 680 printk("%s: out of memory loading\n", a->name);
681 module_put(b); 681 module_put(b);
682 return 0; 682 return 0;
683 } 683 }
684 684
685 use->module_which_uses = a; 685 use->module_which_uses = a;
686 list_add(&use->list, &b->modules_which_use_me); 686 list_add(&use->list, &b->modules_which_use_me);
687 no_warn = sysfs_create_link(b->holders_dir, &a->mkobj.kobj, a->name); 687 no_warn = sysfs_create_link(b->holders_dir, &a->mkobj.kobj, a->name);
688 return 1; 688 return 1;
689 } 689 }
690 EXPORT_SYMBOL_GPL(use_module); 690 EXPORT_SYMBOL_GPL(use_module);
691 691
692 /* Clear the unload stuff of the module. */ 692 /* Clear the unload stuff of the module. */
693 static void module_unload_free(struct module *mod) 693 static void module_unload_free(struct module *mod)
694 { 694 {
695 struct module *i; 695 struct module *i;
696 696
697 list_for_each_entry(i, &modules, list) { 697 list_for_each_entry(i, &modules, list) {
698 struct module_use *use; 698 struct module_use *use;
699 699
700 list_for_each_entry(use, &i->modules_which_use_me, list) { 700 list_for_each_entry(use, &i->modules_which_use_me, list) {
701 if (use->module_which_uses == mod) { 701 if (use->module_which_uses == mod) {
702 DEBUGP("%s unusing %s\n", mod->name, i->name); 702 DEBUGP("%s unusing %s\n", mod->name, i->name);
703 module_put(i); 703 module_put(i);
704 list_del(&use->list); 704 list_del(&use->list);
705 kfree(use); 705 kfree(use);
706 sysfs_remove_link(i->holders_dir, mod->name); 706 sysfs_remove_link(i->holders_dir, mod->name);
707 /* There can be at most one match. */ 707 /* There can be at most one match. */
708 break; 708 break;
709 } 709 }
710 } 710 }
711 } 711 }
712 } 712 }
713 713
714 #ifdef CONFIG_MODULE_FORCE_UNLOAD 714 #ifdef CONFIG_MODULE_FORCE_UNLOAD
715 static inline int try_force_unload(unsigned int flags) 715 static inline int try_force_unload(unsigned int flags)
716 { 716 {
717 int ret = (flags & O_TRUNC); 717 int ret = (flags & O_TRUNC);
718 if (ret) 718 if (ret)
719 add_taint(TAINT_FORCED_RMMOD); 719 add_taint(TAINT_FORCED_RMMOD);
720 return ret; 720 return ret;
721 } 721 }
722 #else 722 #else
723 static inline int try_force_unload(unsigned int flags) 723 static inline int try_force_unload(unsigned int flags)
724 { 724 {
725 return 0; 725 return 0;
726 } 726 }
727 #endif /* CONFIG_MODULE_FORCE_UNLOAD */ 727 #endif /* CONFIG_MODULE_FORCE_UNLOAD */
728 728
729 struct stopref 729 struct stopref
730 { 730 {
731 struct module *mod; 731 struct module *mod;
732 int flags; 732 int flags;
733 int *forced; 733 int *forced;
734 }; 734 };
735 735
736 /* Whole machine is stopped with interrupts off when this runs. */ 736 /* Whole machine is stopped with interrupts off when this runs. */
737 static int __try_stop_module(void *_sref) 737 static int __try_stop_module(void *_sref)
738 { 738 {
739 struct stopref *sref = _sref; 739 struct stopref *sref = _sref;
740 740
741 /* If it's not unused, quit unless we're forcing. */ 741 /* If it's not unused, quit unless we're forcing. */
742 if (module_refcount(sref->mod) != 0) { 742 if (module_refcount(sref->mod) != 0) {
743 if (!(*sref->forced = try_force_unload(sref->flags))) 743 if (!(*sref->forced = try_force_unload(sref->flags)))
744 return -EWOULDBLOCK; 744 return -EWOULDBLOCK;
745 } 745 }
746 746
747 /* Mark it as dying. */ 747 /* Mark it as dying. */
748 sref->mod->state = MODULE_STATE_GOING; 748 sref->mod->state = MODULE_STATE_GOING;
749 return 0; 749 return 0;
750 } 750 }
751 751
752 static int try_stop_module(struct module *mod, int flags, int *forced) 752 static int try_stop_module(struct module *mod, int flags, int *forced)
753 { 753 {
754 if (flags & O_NONBLOCK) { 754 if (flags & O_NONBLOCK) {
755 struct stopref sref = { mod, flags, forced }; 755 struct stopref sref = { mod, flags, forced };
756 756
757 return stop_machine(__try_stop_module, &sref, NULL); 757 return stop_machine(__try_stop_module, &sref, NULL);
758 } else { 758 } else {
759 /* We don't need to stop the machine for this. */ 759 /* We don't need to stop the machine for this. */
760 mod->state = MODULE_STATE_GOING; 760 mod->state = MODULE_STATE_GOING;
761 synchronize_sched(); 761 synchronize_sched();
762 return 0; 762 return 0;
763 } 763 }
764 } 764 }
765 765
766 unsigned int module_refcount(struct module *mod) 766 unsigned int module_refcount(struct module *mod)
767 { 767 {
768 unsigned int total = 0; 768 unsigned int total = 0;
769 int cpu; 769 int cpu;
770 770
771 for_each_possible_cpu(cpu) 771 for_each_possible_cpu(cpu)
772 total += local_read(__module_ref_addr(mod, cpu)); 772 total += local_read(__module_ref_addr(mod, cpu));
773 return total; 773 return total;
774 } 774 }
775 EXPORT_SYMBOL(module_refcount); 775 EXPORT_SYMBOL(module_refcount);
776 776
777 /* This exists whether we can unload or not */ 777 /* This exists whether we can unload or not */
778 static void free_module(struct module *mod); 778 static void free_module(struct module *mod);
779 779
780 static void wait_for_zero_refcount(struct module *mod) 780 static void wait_for_zero_refcount(struct module *mod)
781 { 781 {
782 /* Since we might sleep for some time, release the mutex first */ 782 /* Since we might sleep for some time, release the mutex first */
783 mutex_unlock(&module_mutex); 783 mutex_unlock(&module_mutex);
784 for (;;) { 784 for (;;) {
785 DEBUGP("Looking at refcount...\n"); 785 DEBUGP("Looking at refcount...\n");
786 set_current_state(TASK_UNINTERRUPTIBLE); 786 set_current_state(TASK_UNINTERRUPTIBLE);
787 if (module_refcount(mod) == 0) 787 if (module_refcount(mod) == 0)
788 break; 788 break;
789 schedule(); 789 schedule();
790 } 790 }
791 current->state = TASK_RUNNING; 791 current->state = TASK_RUNNING;
792 mutex_lock(&module_mutex); 792 mutex_lock(&module_mutex);
793 } 793 }
794 794
795 SYSCALL_DEFINE2(delete_module, const char __user *, name_user, 795 SYSCALL_DEFINE2(delete_module, const char __user *, name_user,
796 unsigned int, flags) 796 unsigned int, flags)
797 { 797 {
798 struct module *mod; 798 struct module *mod;
799 char name[MODULE_NAME_LEN]; 799 char name[MODULE_NAME_LEN];
800 int ret, forced = 0; 800 int ret, forced = 0;
801 801
802 if (!capable(CAP_SYS_MODULE) || modules_disabled) 802 if (!capable(CAP_SYS_MODULE) || modules_disabled)
803 return -EPERM; 803 return -EPERM;
804 804
805 if (strncpy_from_user(name, name_user, MODULE_NAME_LEN-1) < 0) 805 if (strncpy_from_user(name, name_user, MODULE_NAME_LEN-1) < 0)
806 return -EFAULT; 806 return -EFAULT;
807 name[MODULE_NAME_LEN-1] = '\0'; 807 name[MODULE_NAME_LEN-1] = '\0';
808 808
809 /* Create stop_machine threads since free_module relies on 809 /* Create stop_machine threads since free_module relies on
810 * a non-failing stop_machine call. */ 810 * a non-failing stop_machine call. */
811 ret = stop_machine_create(); 811 ret = stop_machine_create();
812 if (ret) 812 if (ret)
813 return ret; 813 return ret;
814 814
815 if (mutex_lock_interruptible(&module_mutex) != 0) { 815 if (mutex_lock_interruptible(&module_mutex) != 0) {
816 ret = -EINTR; 816 ret = -EINTR;
817 goto out_stop; 817 goto out_stop;
818 } 818 }
819 819
820 mod = find_module(name); 820 mod = find_module(name);
821 if (!mod) { 821 if (!mod) {
822 ret = -ENOENT; 822 ret = -ENOENT;
823 goto out; 823 goto out;
824 } 824 }
825 825
826 if (!list_empty(&mod->modules_which_use_me)) { 826 if (!list_empty(&mod->modules_which_use_me)) {
827 /* Other modules depend on us: get rid of them first. */ 827 /* Other modules depend on us: get rid of them first. */
828 ret = -EWOULDBLOCK; 828 ret = -EWOULDBLOCK;
829 goto out; 829 goto out;
830 } 830 }
831 831
832 /* Doing init or already dying? */ 832 /* Doing init or already dying? */
833 if (mod->state != MODULE_STATE_LIVE) { 833 if (mod->state != MODULE_STATE_LIVE) {
834 /* FIXME: if (force), slam module count and wake up 834 /* FIXME: if (force), slam module count and wake up
835 waiter --RR */ 835 waiter --RR */
836 DEBUGP("%s already dying\n", mod->name); 836 DEBUGP("%s already dying\n", mod->name);
837 ret = -EBUSY; 837 ret = -EBUSY;
838 goto out; 838 goto out;
839 } 839 }
840 840
841 /* If it has an init func, it must have an exit func to unload */ 841 /* If it has an init func, it must have an exit func to unload */
842 if (mod->init && !mod->exit) { 842 if (mod->init && !mod->exit) {
843 forced = try_force_unload(flags); 843 forced = try_force_unload(flags);
844 if (!forced) { 844 if (!forced) {
845 /* This module can't be removed */ 845 /* This module can't be removed */
846 ret = -EBUSY; 846 ret = -EBUSY;
847 goto out; 847 goto out;
848 } 848 }
849 } 849 }
850 850
851 /* Set this up before setting mod->state */ 851 /* Set this up before setting mod->state */
852 mod->waiter = current; 852 mod->waiter = current;
853 853
854 /* Stop the machine so refcounts can't move and disable module. */ 854 /* Stop the machine so refcounts can't move and disable module. */
855 ret = try_stop_module(mod, flags, &forced); 855 ret = try_stop_module(mod, flags, &forced);
856 if (ret != 0) 856 if (ret != 0)
857 goto out; 857 goto out;
858 858
859 /* Never wait if forced. */ 859 /* Never wait if forced. */
860 if (!forced && module_refcount(mod) != 0) 860 if (!forced && module_refcount(mod) != 0)
861 wait_for_zero_refcount(mod); 861 wait_for_zero_refcount(mod);
862 862
863 mutex_unlock(&module_mutex); 863 mutex_unlock(&module_mutex);
864 /* Final destruction now noone is using it. */ 864 /* Final destruction now noone is using it. */
865 if (mod->exit != NULL) 865 if (mod->exit != NULL)
866 mod->exit(); 866 mod->exit();
867 blocking_notifier_call_chain(&module_notify_list, 867 blocking_notifier_call_chain(&module_notify_list,
868 MODULE_STATE_GOING, mod); 868 MODULE_STATE_GOING, mod);
869 async_synchronize_full(); 869 async_synchronize_full();
870 mutex_lock(&module_mutex); 870 mutex_lock(&module_mutex);
871 /* Store the name of the last unloaded module for diagnostic purposes */ 871 /* Store the name of the last unloaded module for diagnostic purposes */
872 strlcpy(last_unloaded_module, mod->name, sizeof(last_unloaded_module)); 872 strlcpy(last_unloaded_module, mod->name, sizeof(last_unloaded_module));
873 ddebug_remove_module(mod->name); 873 ddebug_remove_module(mod->name);
874 free_module(mod); 874 free_module(mod);
875 875
876 out: 876 out:
877 mutex_unlock(&module_mutex); 877 mutex_unlock(&module_mutex);
878 out_stop: 878 out_stop:
879 stop_machine_destroy(); 879 stop_machine_destroy();
880 return ret; 880 return ret;
881 } 881 }
882 882
883 static inline void print_unload_info(struct seq_file *m, struct module *mod) 883 static inline void print_unload_info(struct seq_file *m, struct module *mod)
884 { 884 {
885 struct module_use *use; 885 struct module_use *use;
886 int printed_something = 0; 886 int printed_something = 0;
887 887
888 seq_printf(m, " %u ", module_refcount(mod)); 888 seq_printf(m, " %u ", module_refcount(mod));
889 889
890 /* Always include a trailing , so userspace can differentiate 890 /* Always include a trailing , so userspace can differentiate
891 between this and the old multi-field proc format. */ 891 between this and the old multi-field proc format. */
892 list_for_each_entry(use, &mod->modules_which_use_me, list) { 892 list_for_each_entry(use, &mod->modules_which_use_me, list) {
893 printed_something = 1; 893 printed_something = 1;
894 seq_printf(m, "%s,", use->module_which_uses->name); 894 seq_printf(m, "%s,", use->module_which_uses->name);
895 } 895 }
896 896
897 if (mod->init != NULL && mod->exit == NULL) { 897 if (mod->init != NULL && mod->exit == NULL) {
898 printed_something = 1; 898 printed_something = 1;
899 seq_printf(m, "[permanent],"); 899 seq_printf(m, "[permanent],");
900 } 900 }
901 901
902 if (!printed_something) 902 if (!printed_something)
903 seq_printf(m, "-"); 903 seq_printf(m, "-");
904 } 904 }
905 905
906 void __symbol_put(const char *symbol) 906 void __symbol_put(const char *symbol)
907 { 907 {
908 struct module *owner; 908 struct module *owner;
909 909
910 preempt_disable(); 910 preempt_disable();
911 if (!find_symbol(symbol, &owner, NULL, true, false)) 911 if (!find_symbol(symbol, &owner, NULL, true, false))
912 BUG(); 912 BUG();
913 module_put(owner); 913 module_put(owner);
914 preempt_enable(); 914 preempt_enable();
915 } 915 }
916 EXPORT_SYMBOL(__symbol_put); 916 EXPORT_SYMBOL(__symbol_put);
917 917
918 /* Note this assumes addr is a function, which it currently always is. */ 918 /* Note this assumes addr is a function, which it currently always is. */
919 void symbol_put_addr(void *addr) 919 void symbol_put_addr(void *addr)
920 { 920 {
921 struct module *modaddr; 921 struct module *modaddr;
922 unsigned long a = (unsigned long)dereference_function_descriptor(addr); 922 unsigned long a = (unsigned long)dereference_function_descriptor(addr);
923 923
924 if (core_kernel_text(a)) 924 if (core_kernel_text(a))
925 return; 925 return;
926 926
927 /* module_text_address is safe here: we're supposed to have reference 927 /* module_text_address is safe here: we're supposed to have reference
928 * to module from symbol_get, so it can't go away. */ 928 * to module from symbol_get, so it can't go away. */
929 modaddr = __module_text_address(a); 929 modaddr = __module_text_address(a);
930 BUG_ON(!modaddr); 930 BUG_ON(!modaddr);
931 module_put(modaddr); 931 module_put(modaddr);
932 } 932 }
933 EXPORT_SYMBOL_GPL(symbol_put_addr); 933 EXPORT_SYMBOL_GPL(symbol_put_addr);
934 934
935 static ssize_t show_refcnt(struct module_attribute *mattr, 935 static ssize_t show_refcnt(struct module_attribute *mattr,
936 struct module *mod, char *buffer) 936 struct module *mod, char *buffer)
937 { 937 {
938 return sprintf(buffer, "%u\n", module_refcount(mod)); 938 return sprintf(buffer, "%u\n", module_refcount(mod));
939 } 939 }
940 940
941 static struct module_attribute refcnt = { 941 static struct module_attribute refcnt = {
942 .attr = { .name = "refcnt", .mode = 0444 }, 942 .attr = { .name = "refcnt", .mode = 0444 },
943 .show = show_refcnt, 943 .show = show_refcnt,
944 }; 944 };
945 945
946 void module_put(struct module *module) 946 void module_put(struct module *module)
947 { 947 {
948 if (module) { 948 if (module) {
949 unsigned int cpu = get_cpu(); 949 unsigned int cpu = get_cpu();
950 local_dec(__module_ref_addr(module, cpu)); 950 local_dec(__module_ref_addr(module, cpu));
951 trace_module_put(module, _RET_IP_, 951 trace_module_put(module, _RET_IP_,
952 local_read(__module_ref_addr(module, cpu))); 952 local_read(__module_ref_addr(module, cpu)));
953 /* Maybe they're waiting for us to drop reference? */ 953 /* Maybe they're waiting for us to drop reference? */
954 if (unlikely(!module_is_live(module))) 954 if (unlikely(!module_is_live(module)))
955 wake_up_process(module->waiter); 955 wake_up_process(module->waiter);
956 put_cpu(); 956 put_cpu();
957 } 957 }
958 } 958 }
959 EXPORT_SYMBOL(module_put); 959 EXPORT_SYMBOL(module_put);
960 960
961 #else /* !CONFIG_MODULE_UNLOAD */ 961 #else /* !CONFIG_MODULE_UNLOAD */
962 static inline void print_unload_info(struct seq_file *m, struct module *mod) 962 static inline void print_unload_info(struct seq_file *m, struct module *mod)
963 { 963 {
964 /* We don't know the usage count, or what modules are using. */ 964 /* We don't know the usage count, or what modules are using. */
965 seq_printf(m, " - -"); 965 seq_printf(m, " - -");
966 } 966 }
967 967
968 static inline void module_unload_free(struct module *mod) 968 static inline void module_unload_free(struct module *mod)
969 { 969 {
970 } 970 }
971 971
972 int use_module(struct module *a, struct module *b) 972 int use_module(struct module *a, struct module *b)
973 { 973 {
974 return strong_try_module_get(b) == 0; 974 return strong_try_module_get(b) == 0;
975 } 975 }
976 EXPORT_SYMBOL_GPL(use_module); 976 EXPORT_SYMBOL_GPL(use_module);
977 977
978 static inline void module_unload_init(struct module *mod) 978 static inline void module_unload_init(struct module *mod)
979 { 979 {
980 } 980 }
981 #endif /* CONFIG_MODULE_UNLOAD */ 981 #endif /* CONFIG_MODULE_UNLOAD */
982 982
983 static ssize_t show_initstate(struct module_attribute *mattr, 983 static ssize_t show_initstate(struct module_attribute *mattr,
984 struct module *mod, char *buffer) 984 struct module *mod, char *buffer)
985 { 985 {
986 const char *state = "unknown"; 986 const char *state = "unknown";
987 987
988 switch (mod->state) { 988 switch (mod->state) {
989 case MODULE_STATE_LIVE: 989 case MODULE_STATE_LIVE:
990 state = "live"; 990 state = "live";
991 break; 991 break;
992 case MODULE_STATE_COMING: 992 case MODULE_STATE_COMING:
993 state = "coming"; 993 state = "coming";
994 break; 994 break;
995 case MODULE_STATE_GOING: 995 case MODULE_STATE_GOING:
996 state = "going"; 996 state = "going";
997 break; 997 break;
998 } 998 }
999 return sprintf(buffer, "%s\n", state); 999 return sprintf(buffer, "%s\n", state);
1000 } 1000 }
1001 1001
1002 static struct module_attribute initstate = { 1002 static struct module_attribute initstate = {
1003 .attr = { .name = "initstate", .mode = 0444 }, 1003 .attr = { .name = "initstate", .mode = 0444 },
1004 .show = show_initstate, 1004 .show = show_initstate,
1005 }; 1005 };
1006 1006
1007 static struct module_attribute *modinfo_attrs[] = { 1007 static struct module_attribute *modinfo_attrs[] = {
1008 &modinfo_version, 1008 &modinfo_version,
1009 &modinfo_srcversion, 1009 &modinfo_srcversion,
1010 &initstate, 1010 &initstate,
1011 #ifdef CONFIG_MODULE_UNLOAD 1011 #ifdef CONFIG_MODULE_UNLOAD
1012 &refcnt, 1012 &refcnt,
1013 #endif 1013 #endif
1014 NULL, 1014 NULL,
1015 }; 1015 };
1016 1016
1017 static const char vermagic[] = VERMAGIC_STRING; 1017 static const char vermagic[] = VERMAGIC_STRING;
1018 1018
1019 static int try_to_force_load(struct module *mod, const char *reason) 1019 static int try_to_force_load(struct module *mod, const char *reason)
1020 { 1020 {
1021 #ifdef CONFIG_MODULE_FORCE_LOAD 1021 #ifdef CONFIG_MODULE_FORCE_LOAD
1022 if (!test_taint(TAINT_FORCED_MODULE)) 1022 if (!test_taint(TAINT_FORCED_MODULE))
1023 printk(KERN_WARNING "%s: %s: kernel tainted.\n", 1023 printk(KERN_WARNING "%s: %s: kernel tainted.\n",
1024 mod->name, reason); 1024 mod->name, reason);
1025 add_taint_module(mod, TAINT_FORCED_MODULE); 1025 add_taint_module(mod, TAINT_FORCED_MODULE);
1026 return 0; 1026 return 0;
1027 #else 1027 #else
1028 return -ENOEXEC; 1028 return -ENOEXEC;
1029 #endif 1029 #endif
1030 } 1030 }
1031 1031
1032 #ifdef CONFIG_MODVERSIONS 1032 #ifdef CONFIG_MODVERSIONS
1033 static int check_version(Elf_Shdr *sechdrs, 1033 static int check_version(Elf_Shdr *sechdrs,
1034 unsigned int versindex, 1034 unsigned int versindex,
1035 const char *symname, 1035 const char *symname,
1036 struct module *mod, 1036 struct module *mod,
1037 const unsigned long *crc) 1037 const unsigned long *crc)
1038 { 1038 {
1039 unsigned int i, num_versions; 1039 unsigned int i, num_versions;
1040 struct modversion_info *versions; 1040 struct modversion_info *versions;
1041 1041
1042 /* Exporting module didn't supply crcs? OK, we're already tainted. */ 1042 /* Exporting module didn't supply crcs? OK, we're already tainted. */
1043 if (!crc) 1043 if (!crc)
1044 return 1; 1044 return 1;
1045 1045
1046 /* No versions at all? modprobe --force does this. */ 1046 /* No versions at all? modprobe --force does this. */
1047 if (versindex == 0) 1047 if (versindex == 0)
1048 return try_to_force_load(mod, symname) == 0; 1048 return try_to_force_load(mod, symname) == 0;
1049 1049
1050 versions = (void *) sechdrs[versindex].sh_addr; 1050 versions = (void *) sechdrs[versindex].sh_addr;
1051 num_versions = sechdrs[versindex].sh_size 1051 num_versions = sechdrs[versindex].sh_size
1052 / sizeof(struct modversion_info); 1052 / sizeof(struct modversion_info);
1053 1053
1054 for (i = 0; i < num_versions; i++) { 1054 for (i = 0; i < num_versions; i++) {
1055 if (strcmp(versions[i].name, symname) != 0) 1055 if (strcmp(versions[i].name, symname) != 0)
1056 continue; 1056 continue;
1057 1057
1058 if (versions[i].crc == *crc) 1058 if (versions[i].crc == *crc)
1059 return 1; 1059 return 1;
1060 DEBUGP("Found checksum %lX vs module %lX\n", 1060 DEBUGP("Found checksum %lX vs module %lX\n",
1061 *crc, versions[i].crc); 1061 *crc, versions[i].crc);
1062 goto bad_version; 1062 goto bad_version;
1063 } 1063 }
1064 1064
1065 printk(KERN_WARNING "%s: no symbol version for %s\n", 1065 printk(KERN_WARNING "%s: no symbol version for %s\n",
1066 mod->name, symname); 1066 mod->name, symname);
1067 return 0; 1067 return 0;
1068 1068
1069 bad_version: 1069 bad_version:
1070 printk("%s: disagrees about version of symbol %s\n", 1070 printk("%s: disagrees about version of symbol %s\n",
1071 mod->name, symname); 1071 mod->name, symname);
1072 return 0; 1072 return 0;
1073 } 1073 }
1074 1074
1075 static inline int check_modstruct_version(Elf_Shdr *sechdrs, 1075 static inline int check_modstruct_version(Elf_Shdr *sechdrs,
1076 unsigned int versindex, 1076 unsigned int versindex,
1077 struct module *mod) 1077 struct module *mod)
1078 { 1078 {
1079 const unsigned long *crc; 1079 const unsigned long *crc;
1080 1080
1081 if (!find_symbol(MODULE_SYMBOL_PREFIX "module_layout", NULL, 1081 if (!find_symbol(MODULE_SYMBOL_PREFIX "module_layout", NULL,
1082 &crc, true, false)) 1082 &crc, true, false))
1083 BUG(); 1083 BUG();
1084 return check_version(sechdrs, versindex, "module_layout", mod, crc); 1084 return check_version(sechdrs, versindex, "module_layout", mod, crc);
1085 } 1085 }
1086 1086
1087 /* First part is kernel version, which we ignore if module has crcs. */ 1087 /* First part is kernel version, which we ignore if module has crcs. */
1088 static inline int same_magic(const char *amagic, const char *bmagic, 1088 static inline int same_magic(const char *amagic, const char *bmagic,
1089 bool has_crcs) 1089 bool has_crcs)
1090 { 1090 {
1091 if (has_crcs) { 1091 if (has_crcs) {
1092 amagic += strcspn(amagic, " "); 1092 amagic += strcspn(amagic, " ");
1093 bmagic += strcspn(bmagic, " "); 1093 bmagic += strcspn(bmagic, " ");
1094 } 1094 }
1095 return strcmp(amagic, bmagic) == 0; 1095 return strcmp(amagic, bmagic) == 0;
1096 } 1096 }
1097 #else 1097 #else
1098 static inline int check_version(Elf_Shdr *sechdrs, 1098 static inline int check_version(Elf_Shdr *sechdrs,
1099 unsigned int versindex, 1099 unsigned int versindex,
1100 const char *symname, 1100 const char *symname,
1101 struct module *mod, 1101 struct module *mod,
1102 const unsigned long *crc) 1102 const unsigned long *crc)
1103 { 1103 {
1104 return 1; 1104 return 1;
1105 } 1105 }
1106 1106
1107 static inline int check_modstruct_version(Elf_Shdr *sechdrs, 1107 static inline int check_modstruct_version(Elf_Shdr *sechdrs,
1108 unsigned int versindex, 1108 unsigned int versindex,
1109 struct module *mod) 1109 struct module *mod)
1110 { 1110 {
1111 return 1; 1111 return 1;
1112 } 1112 }
1113 1113
1114 static inline int same_magic(const char *amagic, const char *bmagic, 1114 static inline int same_magic(const char *amagic, const char *bmagic,
1115 bool has_crcs) 1115 bool has_crcs)
1116 { 1116 {
1117 return strcmp(amagic, bmagic) == 0; 1117 return strcmp(amagic, bmagic) == 0;
1118 } 1118 }
1119 #endif /* CONFIG_MODVERSIONS */ 1119 #endif /* CONFIG_MODVERSIONS */
1120 1120
1121 /* Resolve a symbol for this module. I.e. if we find one, record usage. 1121 /* Resolve a symbol for this module. I.e. if we find one, record usage.
1122 Must be holding module_mutex. */ 1122 Must be holding module_mutex. */
1123 static const struct kernel_symbol *resolve_symbol(Elf_Shdr *sechdrs, 1123 static const struct kernel_symbol *resolve_symbol(Elf_Shdr *sechdrs,
1124 unsigned int versindex, 1124 unsigned int versindex,
1125 const char *name, 1125 const char *name,
1126 struct module *mod) 1126 struct module *mod)
1127 { 1127 {
1128 struct module *owner; 1128 struct module *owner;
1129 const struct kernel_symbol *sym; 1129 const struct kernel_symbol *sym;
1130 const unsigned long *crc; 1130 const unsigned long *crc;
1131 1131
1132 sym = find_symbol(name, &owner, &crc, 1132 sym = find_symbol(name, &owner, &crc,
1133 !(mod->taints & (1 << TAINT_PROPRIETARY_MODULE)), true); 1133 !(mod->taints & (1 << TAINT_PROPRIETARY_MODULE)), true);
1134 /* use_module can fail due to OOM, 1134 /* use_module can fail due to OOM,
1135 or module initialization or unloading */ 1135 or module initialization or unloading */
1136 if (sym) { 1136 if (sym) {
1137 if (!check_version(sechdrs, versindex, name, mod, crc) || 1137 if (!check_version(sechdrs, versindex, name, mod, crc) ||
1138 !use_module(mod, owner)) 1138 !use_module(mod, owner))
1139 sym = NULL; 1139 sym = NULL;
1140 } 1140 }
1141 return sym; 1141 return sym;
1142 } 1142 }
1143 1143
1144 /* 1144 /*
1145 * /sys/module/foo/sections stuff 1145 * /sys/module/foo/sections stuff
1146 * J. Corbet <corbet@lwn.net> 1146 * J. Corbet <corbet@lwn.net>
1147 */ 1147 */
1148 #if defined(CONFIG_KALLSYMS) && defined(CONFIG_SYSFS) 1148 #if defined(CONFIG_KALLSYMS) && defined(CONFIG_SYSFS)
1149 struct module_sect_attr 1149 struct module_sect_attr
1150 { 1150 {
1151 struct module_attribute mattr; 1151 struct module_attribute mattr;
1152 char *name; 1152 char *name;
1153 unsigned long address; 1153 unsigned long address;
1154 }; 1154 };
1155 1155
1156 struct module_sect_attrs 1156 struct module_sect_attrs
1157 { 1157 {
1158 struct attribute_group grp; 1158 struct attribute_group grp;
1159 unsigned int nsections; 1159 unsigned int nsections;
1160 struct module_sect_attr attrs[0]; 1160 struct module_sect_attr attrs[0];
1161 }; 1161 };
1162 1162
1163 static ssize_t module_sect_show(struct module_attribute *mattr, 1163 static ssize_t module_sect_show(struct module_attribute *mattr,
1164 struct module *mod, char *buf) 1164 struct module *mod, char *buf)
1165 { 1165 {
1166 struct module_sect_attr *sattr = 1166 struct module_sect_attr *sattr =
1167 container_of(mattr, struct module_sect_attr, mattr); 1167 container_of(mattr, struct module_sect_attr, mattr);
1168 return sprintf(buf, "0x%lx\n", sattr->address); 1168 return sprintf(buf, "0x%lx\n", sattr->address);
1169 } 1169 }
1170 1170
1171 static void free_sect_attrs(struct module_sect_attrs *sect_attrs) 1171 static void free_sect_attrs(struct module_sect_attrs *sect_attrs)
1172 { 1172 {
1173 unsigned int section; 1173 unsigned int section;
1174 1174
1175 for (section = 0; section < sect_attrs->nsections; section++) 1175 for (section = 0; section < sect_attrs->nsections; section++)
1176 kfree(sect_attrs->attrs[section].name); 1176 kfree(sect_attrs->attrs[section].name);
1177 kfree(sect_attrs); 1177 kfree(sect_attrs);
1178 } 1178 }
1179 1179
1180 static void add_sect_attrs(struct module *mod, unsigned int nsect, 1180 static void add_sect_attrs(struct module *mod, unsigned int nsect,
1181 char *secstrings, Elf_Shdr *sechdrs) 1181 char *secstrings, Elf_Shdr *sechdrs)
1182 { 1182 {
1183 unsigned int nloaded = 0, i, size[2]; 1183 unsigned int nloaded = 0, i, size[2];
1184 struct module_sect_attrs *sect_attrs; 1184 struct module_sect_attrs *sect_attrs;
1185 struct module_sect_attr *sattr; 1185 struct module_sect_attr *sattr;
1186 struct attribute **gattr; 1186 struct attribute **gattr;
1187 1187
1188 /* Count loaded sections and allocate structures */ 1188 /* Count loaded sections and allocate structures */
1189 for (i = 0; i < nsect; i++) 1189 for (i = 0; i < nsect; i++)
1190 if (sechdrs[i].sh_flags & SHF_ALLOC) 1190 if (sechdrs[i].sh_flags & SHF_ALLOC)
1191 nloaded++; 1191 nloaded++;
1192 size[0] = ALIGN(sizeof(*sect_attrs) 1192 size[0] = ALIGN(sizeof(*sect_attrs)
1193 + nloaded * sizeof(sect_attrs->attrs[0]), 1193 + nloaded * sizeof(sect_attrs->attrs[0]),
1194 sizeof(sect_attrs->grp.attrs[0])); 1194 sizeof(sect_attrs->grp.attrs[0]));
1195 size[1] = (nloaded + 1) * sizeof(sect_attrs->grp.attrs[0]); 1195 size[1] = (nloaded + 1) * sizeof(sect_attrs->grp.attrs[0]);
1196 sect_attrs = kzalloc(size[0] + size[1], GFP_KERNEL); 1196 sect_attrs = kzalloc(size[0] + size[1], GFP_KERNEL);
1197 if (sect_attrs == NULL) 1197 if (sect_attrs == NULL)
1198 return; 1198 return;
1199 1199
1200 /* Setup section attributes. */ 1200 /* Setup section attributes. */
1201 sect_attrs->grp.name = "sections"; 1201 sect_attrs->grp.name = "sections";
1202 sect_attrs->grp.attrs = (void *)sect_attrs + size[0]; 1202 sect_attrs->grp.attrs = (void *)sect_attrs + size[0];
1203 1203
1204 sect_attrs->nsections = 0; 1204 sect_attrs->nsections = 0;
1205 sattr = &sect_attrs->attrs[0]; 1205 sattr = &sect_attrs->attrs[0];
1206 gattr = &sect_attrs->grp.attrs[0]; 1206 gattr = &sect_attrs->grp.attrs[0];
1207 for (i = 0; i < nsect; i++) { 1207 for (i = 0; i < nsect; i++) {
1208 if (! (sechdrs[i].sh_flags & SHF_ALLOC)) 1208 if (! (sechdrs[i].sh_flags & SHF_ALLOC))
1209 continue; 1209 continue;
1210 sattr->address = sechdrs[i].sh_addr; 1210 sattr->address = sechdrs[i].sh_addr;
1211 sattr->name = kstrdup(secstrings + sechdrs[i].sh_name, 1211 sattr->name = kstrdup(secstrings + sechdrs[i].sh_name,
1212 GFP_KERNEL); 1212 GFP_KERNEL);
1213 if (sattr->name == NULL) 1213 if (sattr->name == NULL)
1214 goto out; 1214 goto out;
1215 sect_attrs->nsections++; 1215 sect_attrs->nsections++;
1216 sattr->mattr.show = module_sect_show; 1216 sattr->mattr.show = module_sect_show;
1217 sattr->mattr.store = NULL; 1217 sattr->mattr.store = NULL;
1218 sattr->mattr.attr.name = sattr->name; 1218 sattr->mattr.attr.name = sattr->name;
1219 sattr->mattr.attr.mode = S_IRUGO; 1219 sattr->mattr.attr.mode = S_IRUGO;
1220 *(gattr++) = &(sattr++)->mattr.attr; 1220 *(gattr++) = &(sattr++)->mattr.attr;
1221 } 1221 }
1222 *gattr = NULL; 1222 *gattr = NULL;
1223 1223
1224 if (sysfs_create_group(&mod->mkobj.kobj, &sect_attrs->grp)) 1224 if (sysfs_create_group(&mod->mkobj.kobj, &sect_attrs->grp))
1225 goto out; 1225 goto out;
1226 1226
1227 mod->sect_attrs = sect_attrs; 1227 mod->sect_attrs = sect_attrs;
1228 return; 1228 return;
1229 out: 1229 out:
1230 free_sect_attrs(sect_attrs); 1230 free_sect_attrs(sect_attrs);
1231 } 1231 }
1232 1232
1233 static void remove_sect_attrs(struct module *mod) 1233 static void remove_sect_attrs(struct module *mod)
1234 { 1234 {
1235 if (mod->sect_attrs) { 1235 if (mod->sect_attrs) {
1236 sysfs_remove_group(&mod->mkobj.kobj, 1236 sysfs_remove_group(&mod->mkobj.kobj,
1237 &mod->sect_attrs->grp); 1237 &mod->sect_attrs->grp);
1238 /* We are positive that no one is using any sect attrs 1238 /* We are positive that no one is using any sect attrs
1239 * at this point. Deallocate immediately. */ 1239 * at this point. Deallocate immediately. */
1240 free_sect_attrs(mod->sect_attrs); 1240 free_sect_attrs(mod->sect_attrs);
1241 mod->sect_attrs = NULL; 1241 mod->sect_attrs = NULL;
1242 } 1242 }
1243 } 1243 }
1244 1244
1245 /* 1245 /*
1246 * /sys/module/foo/notes/.section.name gives contents of SHT_NOTE sections. 1246 * /sys/module/foo/notes/.section.name gives contents of SHT_NOTE sections.
1247 */ 1247 */
1248 1248
1249 struct module_notes_attrs { 1249 struct module_notes_attrs {
1250 struct kobject *dir; 1250 struct kobject *dir;
1251 unsigned int notes; 1251 unsigned int notes;
1252 struct bin_attribute attrs[0]; 1252 struct bin_attribute attrs[0];
1253 }; 1253 };
1254 1254
1255 static ssize_t module_notes_read(struct kobject *kobj, 1255 static ssize_t module_notes_read(struct kobject *kobj,
1256 struct bin_attribute *bin_attr, 1256 struct bin_attribute *bin_attr,
1257 char *buf, loff_t pos, size_t count) 1257 char *buf, loff_t pos, size_t count)
1258 { 1258 {
1259 /* 1259 /*
1260 * The caller checked the pos and count against our size. 1260 * The caller checked the pos and count against our size.
1261 */ 1261 */
1262 memcpy(buf, bin_attr->private + pos, count); 1262 memcpy(buf, bin_attr->private + pos, count);
1263 return count; 1263 return count;
1264 } 1264 }
1265 1265
1266 static void free_notes_attrs(struct module_notes_attrs *notes_attrs, 1266 static void free_notes_attrs(struct module_notes_attrs *notes_attrs,
1267 unsigned int i) 1267 unsigned int i)
1268 { 1268 {
1269 if (notes_attrs->dir) { 1269 if (notes_attrs->dir) {
1270 while (i-- > 0) 1270 while (i-- > 0)
1271 sysfs_remove_bin_file(notes_attrs->dir, 1271 sysfs_remove_bin_file(notes_attrs->dir,
1272 &notes_attrs->attrs[i]); 1272 &notes_attrs->attrs[i]);
1273 kobject_put(notes_attrs->dir); 1273 kobject_put(notes_attrs->dir);
1274 } 1274 }
1275 kfree(notes_attrs); 1275 kfree(notes_attrs);
1276 } 1276 }
1277 1277
1278 static void add_notes_attrs(struct module *mod, unsigned int nsect, 1278 static void add_notes_attrs(struct module *mod, unsigned int nsect,
1279 char *secstrings, Elf_Shdr *sechdrs) 1279 char *secstrings, Elf_Shdr *sechdrs)
1280 { 1280 {
1281 unsigned int notes, loaded, i; 1281 unsigned int notes, loaded, i;
1282 struct module_notes_attrs *notes_attrs; 1282 struct module_notes_attrs *notes_attrs;
1283 struct bin_attribute *nattr; 1283 struct bin_attribute *nattr;
1284 1284
1285 /* failed to create section attributes, so can't create notes */ 1285 /* failed to create section attributes, so can't create notes */
1286 if (!mod->sect_attrs) 1286 if (!mod->sect_attrs)
1287 return; 1287 return;
1288 1288
1289 /* Count notes sections and allocate structures. */ 1289 /* Count notes sections and allocate structures. */
1290 notes = 0; 1290 notes = 0;
1291 for (i = 0; i < nsect; i++) 1291 for (i = 0; i < nsect; i++)
1292 if ((sechdrs[i].sh_flags & SHF_ALLOC) && 1292 if ((sechdrs[i].sh_flags & SHF_ALLOC) &&
1293 (sechdrs[i].sh_type == SHT_NOTE)) 1293 (sechdrs[i].sh_type == SHT_NOTE))
1294 ++notes; 1294 ++notes;
1295 1295
1296 if (notes == 0) 1296 if (notes == 0)
1297 return; 1297 return;
1298 1298
1299 notes_attrs = kzalloc(sizeof(*notes_attrs) 1299 notes_attrs = kzalloc(sizeof(*notes_attrs)
1300 + notes * sizeof(notes_attrs->attrs[0]), 1300 + notes * sizeof(notes_attrs->attrs[0]),
1301 GFP_KERNEL); 1301 GFP_KERNEL);
1302 if (notes_attrs == NULL) 1302 if (notes_attrs == NULL)
1303 return; 1303 return;
1304 1304
1305 notes_attrs->notes = notes; 1305 notes_attrs->notes = notes;
1306 nattr = &notes_attrs->attrs[0]; 1306 nattr = &notes_attrs->attrs[0];
1307 for (loaded = i = 0; i < nsect; ++i) { 1307 for (loaded = i = 0; i < nsect; ++i) {
1308 if (!(sechdrs[i].sh_flags & SHF_ALLOC)) 1308 if (!(sechdrs[i].sh_flags & SHF_ALLOC))
1309 continue; 1309 continue;
1310 if (sechdrs[i].sh_type == SHT_NOTE) { 1310 if (sechdrs[i].sh_type == SHT_NOTE) {
1311 nattr->attr.name = mod->sect_attrs->attrs[loaded].name; 1311 nattr->attr.name = mod->sect_attrs->attrs[loaded].name;
1312 nattr->attr.mode = S_IRUGO; 1312 nattr->attr.mode = S_IRUGO;
1313 nattr->size = sechdrs[i].sh_size; 1313 nattr->size = sechdrs[i].sh_size;
1314 nattr->private = (void *) sechdrs[i].sh_addr; 1314 nattr->private = (void *) sechdrs[i].sh_addr;
1315 nattr->read = module_notes_read; 1315 nattr->read = module_notes_read;
1316 ++nattr; 1316 ++nattr;
1317 } 1317 }
1318 ++loaded; 1318 ++loaded;
1319 } 1319 }
1320 1320
1321 notes_attrs->dir = kobject_create_and_add("notes", &mod->mkobj.kobj); 1321 notes_attrs->dir = kobject_create_and_add("notes", &mod->mkobj.kobj);
1322 if (!notes_attrs->dir) 1322 if (!notes_attrs->dir)
1323 goto out; 1323 goto out;
1324 1324
1325 for (i = 0; i < notes; ++i) 1325 for (i = 0; i < notes; ++i)
1326 if (sysfs_create_bin_file(notes_attrs->dir, 1326 if (sysfs_create_bin_file(notes_attrs->dir,
1327 &notes_attrs->attrs[i])) 1327 &notes_attrs->attrs[i]))
1328 goto out; 1328 goto out;
1329 1329
1330 mod->notes_attrs = notes_attrs; 1330 mod->notes_attrs = notes_attrs;
1331 return; 1331 return;
1332 1332
1333 out: 1333 out:
1334 free_notes_attrs(notes_attrs, i); 1334 free_notes_attrs(notes_attrs, i);
1335 } 1335 }
1336 1336
1337 static void remove_notes_attrs(struct module *mod) 1337 static void remove_notes_attrs(struct module *mod)
1338 { 1338 {
1339 if (mod->notes_attrs) 1339 if (mod->notes_attrs)
1340 free_notes_attrs(mod->notes_attrs, mod->notes_attrs->notes); 1340 free_notes_attrs(mod->notes_attrs, mod->notes_attrs->notes);
1341 } 1341 }
1342 1342
1343 #else 1343 #else
1344 1344
1345 static inline void add_sect_attrs(struct module *mod, unsigned int nsect, 1345 static inline void add_sect_attrs(struct module *mod, unsigned int nsect,
1346 char *sectstrings, Elf_Shdr *sechdrs) 1346 char *sectstrings, Elf_Shdr *sechdrs)
1347 { 1347 {
1348 } 1348 }
1349 1349
1350 static inline void remove_sect_attrs(struct module *mod) 1350 static inline void remove_sect_attrs(struct module *mod)
1351 { 1351 {
1352 } 1352 }
1353 1353
1354 static inline void add_notes_attrs(struct module *mod, unsigned int nsect, 1354 static inline void add_notes_attrs(struct module *mod, unsigned int nsect,
1355 char *sectstrings, Elf_Shdr *sechdrs) 1355 char *sectstrings, Elf_Shdr *sechdrs)
1356 { 1356 {
1357 } 1357 }
1358 1358
1359 static inline void remove_notes_attrs(struct module *mod) 1359 static inline void remove_notes_attrs(struct module *mod)
1360 { 1360 {
1361 } 1361 }
1362 #endif 1362 #endif
1363 1363
1364 #ifdef CONFIG_SYSFS 1364 #ifdef CONFIG_SYSFS
1365 int module_add_modinfo_attrs(struct module *mod) 1365 int module_add_modinfo_attrs(struct module *mod)
1366 { 1366 {
1367 struct module_attribute *attr; 1367 struct module_attribute *attr;
1368 struct module_attribute *temp_attr; 1368 struct module_attribute *temp_attr;
1369 int error = 0; 1369 int error = 0;
1370 int i; 1370 int i;
1371 1371
1372 mod->modinfo_attrs = kzalloc((sizeof(struct module_attribute) * 1372 mod->modinfo_attrs = kzalloc((sizeof(struct module_attribute) *
1373 (ARRAY_SIZE(modinfo_attrs) + 1)), 1373 (ARRAY_SIZE(modinfo_attrs) + 1)),
1374 GFP_KERNEL); 1374 GFP_KERNEL);
1375 if (!mod->modinfo_attrs) 1375 if (!mod->modinfo_attrs)
1376 return -ENOMEM; 1376 return -ENOMEM;
1377 1377
1378 temp_attr = mod->modinfo_attrs; 1378 temp_attr = mod->modinfo_attrs;
1379 for (i = 0; (attr = modinfo_attrs[i]) && !error; i++) { 1379 for (i = 0; (attr = modinfo_attrs[i]) && !error; i++) {
1380 if (!attr->test || 1380 if (!attr->test ||
1381 (attr->test && attr->test(mod))) { 1381 (attr->test && attr->test(mod))) {
1382 memcpy(temp_attr, attr, sizeof(*temp_attr)); 1382 memcpy(temp_attr, attr, sizeof(*temp_attr));
1383 error = sysfs_create_file(&mod->mkobj.kobj,&temp_attr->attr); 1383 error = sysfs_create_file(&mod->mkobj.kobj,&temp_attr->attr);
1384 ++temp_attr; 1384 ++temp_attr;
1385 } 1385 }
1386 } 1386 }
1387 return error; 1387 return error;
1388 } 1388 }
1389 1389
1390 void module_remove_modinfo_attrs(struct module *mod) 1390 void module_remove_modinfo_attrs(struct module *mod)
1391 { 1391 {
1392 struct module_attribute *attr; 1392 struct module_attribute *attr;
1393 int i; 1393 int i;
1394 1394
1395 for (i = 0; (attr = &mod->modinfo_attrs[i]); i++) { 1395 for (i = 0; (attr = &mod->modinfo_attrs[i]); i++) {
1396 /* pick a field to test for end of list */ 1396 /* pick a field to test for end of list */
1397 if (!attr->attr.name) 1397 if (!attr->attr.name)
1398 break; 1398 break;
1399 sysfs_remove_file(&mod->mkobj.kobj,&attr->attr); 1399 sysfs_remove_file(&mod->mkobj.kobj,&attr->attr);
1400 if (attr->free) 1400 if (attr->free)
1401 attr->free(mod); 1401 attr->free(mod);
1402 } 1402 }
1403 kfree(mod->modinfo_attrs); 1403 kfree(mod->modinfo_attrs);
1404 } 1404 }
1405 1405
1406 int mod_sysfs_init(struct module *mod) 1406 int mod_sysfs_init(struct module *mod)
1407 { 1407 {
1408 int err; 1408 int err;
1409 struct kobject *kobj; 1409 struct kobject *kobj;
1410 1410
1411 if (!module_sysfs_initialized) { 1411 if (!module_sysfs_initialized) {
1412 printk(KERN_ERR "%s: module sysfs not initialized\n", 1412 printk(KERN_ERR "%s: module sysfs not initialized\n",
1413 mod->name); 1413 mod->name);
1414 err = -EINVAL; 1414 err = -EINVAL;
1415 goto out; 1415 goto out;
1416 } 1416 }
1417 1417
1418 kobj = kset_find_obj(module_kset, mod->name); 1418 kobj = kset_find_obj(module_kset, mod->name);
1419 if (kobj) { 1419 if (kobj) {
1420 printk(KERN_ERR "%s: module is already loaded\n", mod->name); 1420 printk(KERN_ERR "%s: module is already loaded\n", mod->name);
1421 kobject_put(kobj); 1421 kobject_put(kobj);
1422 err = -EINVAL; 1422 err = -EINVAL;
1423 goto out; 1423 goto out;
1424 } 1424 }
1425 1425
1426 mod->mkobj.mod = mod; 1426 mod->mkobj.mod = mod;
1427 1427
1428 memset(&mod->mkobj.kobj, 0, sizeof(mod->mkobj.kobj)); 1428 memset(&mod->mkobj.kobj, 0, sizeof(mod->mkobj.kobj));
1429 mod->mkobj.kobj.kset = module_kset; 1429 mod->mkobj.kobj.kset = module_kset;
1430 err = kobject_init_and_add(&mod->mkobj.kobj, &module_ktype, NULL, 1430 err = kobject_init_and_add(&mod->mkobj.kobj, &module_ktype, NULL,
1431 "%s", mod->name); 1431 "%s", mod->name);
1432 if (err) 1432 if (err)
1433 kobject_put(&mod->mkobj.kobj); 1433 kobject_put(&mod->mkobj.kobj);
1434 1434
1435 /* delay uevent until full sysfs population */ 1435 /* delay uevent until full sysfs population */
1436 out: 1436 out:
1437 return err; 1437 return err;
1438 } 1438 }
1439 1439
1440 int mod_sysfs_setup(struct module *mod, 1440 int mod_sysfs_setup(struct module *mod,
1441 struct kernel_param *kparam, 1441 struct kernel_param *kparam,
1442 unsigned int num_params) 1442 unsigned int num_params)
1443 { 1443 {
1444 int err; 1444 int err;
1445 1445
1446 mod->holders_dir = kobject_create_and_add("holders", &mod->mkobj.kobj); 1446 mod->holders_dir = kobject_create_and_add("holders", &mod->mkobj.kobj);
1447 if (!mod->holders_dir) { 1447 if (!mod->holders_dir) {
1448 err = -ENOMEM; 1448 err = -ENOMEM;
1449 goto out_unreg; 1449 goto out_unreg;
1450 } 1450 }
1451 1451
1452 err = module_param_sysfs_setup(mod, kparam, num_params); 1452 err = module_param_sysfs_setup(mod, kparam, num_params);
1453 if (err) 1453 if (err)
1454 goto out_unreg_holders; 1454 goto out_unreg_holders;
1455 1455
1456 err = module_add_modinfo_attrs(mod); 1456 err = module_add_modinfo_attrs(mod);
1457 if (err) 1457 if (err)
1458 goto out_unreg_param; 1458 goto out_unreg_param;
1459 1459
1460 kobject_uevent(&mod->mkobj.kobj, KOBJ_ADD); 1460 kobject_uevent(&mod->mkobj.kobj, KOBJ_ADD);
1461 return 0; 1461 return 0;
1462 1462
1463 out_unreg_param: 1463 out_unreg_param:
1464 module_param_sysfs_remove(mod); 1464 module_param_sysfs_remove(mod);
1465 out_unreg_holders: 1465 out_unreg_holders:
1466 kobject_put(mod->holders_dir); 1466 kobject_put(mod->holders_dir);
1467 out_unreg: 1467 out_unreg:
1468 kobject_put(&mod->mkobj.kobj); 1468 kobject_put(&mod->mkobj.kobj);
1469 return err; 1469 return err;
1470 } 1470 }
1471 1471
1472 static void mod_sysfs_fini(struct module *mod) 1472 static void mod_sysfs_fini(struct module *mod)
1473 { 1473 {
1474 kobject_put(&mod->mkobj.kobj); 1474 kobject_put(&mod->mkobj.kobj);
1475 } 1475 }
1476 1476
1477 #else /* CONFIG_SYSFS */ 1477 #else /* CONFIG_SYSFS */
1478 1478
1479 static void mod_sysfs_fini(struct module *mod) 1479 static void mod_sysfs_fini(struct module *mod)
1480 { 1480 {
1481 } 1481 }
1482 1482
1483 #endif /* CONFIG_SYSFS */ 1483 #endif /* CONFIG_SYSFS */
1484 1484
1485 static void mod_kobject_remove(struct module *mod) 1485 static void mod_kobject_remove(struct module *mod)
1486 { 1486 {
1487 module_remove_modinfo_attrs(mod); 1487 module_remove_modinfo_attrs(mod);
1488 module_param_sysfs_remove(mod); 1488 module_param_sysfs_remove(mod);
1489 kobject_put(mod->mkobj.drivers_dir); 1489 kobject_put(mod->mkobj.drivers_dir);
1490 kobject_put(mod->holders_dir); 1490 kobject_put(mod->holders_dir);
1491 mod_sysfs_fini(mod); 1491 mod_sysfs_fini(mod);
1492 } 1492 }
1493 1493
1494 /* 1494 /*
1495 * unlink the module with the whole machine is stopped with interrupts off 1495 * unlink the module with the whole machine is stopped with interrupts off
1496 * - this defends against kallsyms not taking locks 1496 * - this defends against kallsyms not taking locks
1497 */ 1497 */
1498 static int __unlink_module(void *_mod) 1498 static int __unlink_module(void *_mod)
1499 { 1499 {
1500 struct module *mod = _mod; 1500 struct module *mod = _mod;
1501 list_del(&mod->list); 1501 list_del(&mod->list);
1502 return 0; 1502 return 0;
1503 } 1503 }
1504 1504
1505 /* Free a module, remove from lists, etc (must hold module_mutex). */ 1505 /* Free a module, remove from lists, etc (must hold module_mutex). */
1506 static void free_module(struct module *mod) 1506 static void free_module(struct module *mod)
1507 { 1507 {
1508 trace_module_free(mod); 1508 trace_module_free(mod);
1509 1509
1510 /* Delete from various lists */ 1510 /* Delete from various lists */
1511 stop_machine(__unlink_module, mod, NULL); 1511 stop_machine(__unlink_module, mod, NULL);
1512 remove_notes_attrs(mod); 1512 remove_notes_attrs(mod);
1513 remove_sect_attrs(mod); 1513 remove_sect_attrs(mod);
1514 mod_kobject_remove(mod); 1514 mod_kobject_remove(mod);
1515 1515
1516 /* Arch-specific cleanup. */ 1516 /* Arch-specific cleanup. */
1517 module_arch_cleanup(mod); 1517 module_arch_cleanup(mod);
1518 1518
1519 /* Module unload stuff */ 1519 /* Module unload stuff */
1520 module_unload_free(mod); 1520 module_unload_free(mod);
1521 1521
1522 /* Free any allocated parameters. */ 1522 /* Free any allocated parameters. */
1523 destroy_params(mod->kp, mod->num_kp); 1523 destroy_params(mod->kp, mod->num_kp);
1524 1524
1525 /* This may be NULL, but that's OK */ 1525 /* This may be NULL, but that's OK */
1526 module_free(mod, mod->module_init); 1526 module_free(mod, mod->module_init);
1527 kfree(mod->args); 1527 kfree(mod->args);
1528 if (mod->percpu) 1528 if (mod->percpu)
1529 percpu_modfree(mod->percpu); 1529 percpu_modfree(mod->percpu);
1530 #if defined(CONFIG_MODULE_UNLOAD) && defined(CONFIG_SMP) 1530 #if defined(CONFIG_MODULE_UNLOAD) && defined(CONFIG_SMP)
1531 if (mod->refptr) 1531 if (mod->refptr)
1532 percpu_modfree(mod->refptr); 1532 percpu_modfree(mod->refptr);
1533 #endif 1533 #endif
1534 /* Free lock-classes: */ 1534 /* Free lock-classes: */
1535 lockdep_free_key_range(mod->module_core, mod->core_size); 1535 lockdep_free_key_range(mod->module_core, mod->core_size);
1536 1536
1537 /* Finally, free the core (containing the module structure) */ 1537 /* Finally, free the core (containing the module structure) */
1538 module_free(mod, mod->module_core); 1538 module_free(mod, mod->module_core);
1539 1539
1540 #ifdef CONFIG_MPU 1540 #ifdef CONFIG_MPU
1541 update_protections(current->mm); 1541 update_protections(current->mm);
1542 #endif 1542 #endif
1543 } 1543 }
1544 1544
1545 void *__symbol_get(const char *symbol) 1545 void *__symbol_get(const char *symbol)
1546 { 1546 {
1547 struct module *owner; 1547 struct module *owner;
1548 const struct kernel_symbol *sym; 1548 const struct kernel_symbol *sym;
1549 1549
1550 preempt_disable(); 1550 preempt_disable();
1551 sym = find_symbol(symbol, &owner, NULL, true, true); 1551 sym = find_symbol(symbol, &owner, NULL, true, true);
1552 if (sym && strong_try_module_get(owner)) 1552 if (sym && strong_try_module_get(owner))
1553 sym = NULL; 1553 sym = NULL;
1554 preempt_enable(); 1554 preempt_enable();
1555 1555
1556 return sym ? (void *)sym->value : NULL; 1556 return sym ? (void *)sym->value : NULL;
1557 } 1557 }
1558 EXPORT_SYMBOL_GPL(__symbol_get); 1558 EXPORT_SYMBOL_GPL(__symbol_get);
1559 1559
1560 /* 1560 /*
1561 * Ensure that an exported symbol [global namespace] does not already exist 1561 * Ensure that an exported symbol [global namespace] does not already exist
1562 * in the kernel or in some other module's exported symbol table. 1562 * in the kernel or in some other module's exported symbol table.
1563 */ 1563 */
1564 static int verify_export_symbols(struct module *mod) 1564 static int verify_export_symbols(struct module *mod)
1565 { 1565 {
1566 unsigned int i; 1566 unsigned int i;
1567 struct module *owner; 1567 struct module *owner;
1568 const struct kernel_symbol *s; 1568 const struct kernel_symbol *s;
1569 struct { 1569 struct {
1570 const struct kernel_symbol *sym; 1570 const struct kernel_symbol *sym;
1571 unsigned int num; 1571 unsigned int num;
1572 } arr[] = { 1572 } arr[] = {
1573 { mod->syms, mod->num_syms }, 1573 { mod->syms, mod->num_syms },
1574 { mod->gpl_syms, mod->num_gpl_syms }, 1574 { mod->gpl_syms, mod->num_gpl_syms },
1575 { mod->gpl_future_syms, mod->num_gpl_future_syms }, 1575 { mod->gpl_future_syms, mod->num_gpl_future_syms },
1576 #ifdef CONFIG_UNUSED_SYMBOLS 1576 #ifdef CONFIG_UNUSED_SYMBOLS
1577 { mod->unused_syms, mod->num_unused_syms }, 1577 { mod->unused_syms, mod->num_unused_syms },
1578 { mod->unused_gpl_syms, mod->num_unused_gpl_syms }, 1578 { mod->unused_gpl_syms, mod->num_unused_gpl_syms },
1579 #endif 1579 #endif
1580 }; 1580 };
1581 1581
1582 for (i = 0; i < ARRAY_SIZE(arr); i++) { 1582 for (i = 0; i < ARRAY_SIZE(arr); i++) {
1583 for (s = arr[i].sym; s < arr[i].sym + arr[i].num; s++) { 1583 for (s = arr[i].sym; s < arr[i].sym + arr[i].num; s++) {
1584 if (find_symbol(s->name, &owner, NULL, true, false)) { 1584 if (find_symbol(s->name, &owner, NULL, true, false)) {
1585 printk(KERN_ERR 1585 printk(KERN_ERR
1586 "%s: exports duplicate symbol %s" 1586 "%s: exports duplicate symbol %s"
1587 " (owned by %s)\n", 1587 " (owned by %s)\n",
1588 mod->name, s->name, module_name(owner)); 1588 mod->name, s->name, module_name(owner));
1589 return -ENOEXEC; 1589 return -ENOEXEC;
1590 } 1590 }
1591 } 1591 }
1592 } 1592 }
1593 return 0; 1593 return 0;
1594 } 1594 }
1595 1595
1596 /* Change all symbols so that st_value encodes the pointer directly. */ 1596 /* Change all symbols so that st_value encodes the pointer directly. */
1597 static int simplify_symbols(Elf_Shdr *sechdrs, 1597 static int simplify_symbols(Elf_Shdr *sechdrs,
1598 unsigned int symindex, 1598 unsigned int symindex,
1599 const char *strtab, 1599 const char *strtab,
1600 unsigned int versindex, 1600 unsigned int versindex,
1601 unsigned int pcpuindex, 1601 unsigned int pcpuindex,
1602 struct module *mod) 1602 struct module *mod)
1603 { 1603 {
1604 Elf_Sym *sym = (void *)sechdrs[symindex].sh_addr; 1604 Elf_Sym *sym = (void *)sechdrs[symindex].sh_addr;
1605 unsigned long secbase; 1605 unsigned long secbase;
1606 unsigned int i, n = sechdrs[symindex].sh_size / sizeof(Elf_Sym); 1606 unsigned int i, n = sechdrs[symindex].sh_size / sizeof(Elf_Sym);
1607 int ret = 0; 1607 int ret = 0;
1608 const struct kernel_symbol *ksym; 1608 const struct kernel_symbol *ksym;
1609 1609
1610 for (i = 1; i < n; i++) { 1610 for (i = 1; i < n; i++) {
1611 switch (sym[i].st_shndx) { 1611 switch (sym[i].st_shndx) {
1612 case SHN_COMMON: 1612 case SHN_COMMON:
1613 /* We compiled with -fno-common. These are not 1613 /* We compiled with -fno-common. These are not
1614 supposed to happen. */ 1614 supposed to happen. */
1615 DEBUGP("Common symbol: %s\n", strtab + sym[i].st_name); 1615 DEBUGP("Common symbol: %s\n", strtab + sym[i].st_name);
1616 printk("%s: please compile with -fno-common\n", 1616 printk("%s: please compile with -fno-common\n",
1617 mod->name); 1617 mod->name);
1618 ret = -ENOEXEC; 1618 ret = -ENOEXEC;
1619 break; 1619 break;
1620 1620
1621 case SHN_ABS: 1621 case SHN_ABS:
1622 /* Don't need to do anything */ 1622 /* Don't need to do anything */
1623 DEBUGP("Absolute symbol: 0x%08lx\n", 1623 DEBUGP("Absolute symbol: 0x%08lx\n",
1624 (long)sym[i].st_value); 1624 (long)sym[i].st_value);
1625 break; 1625 break;
1626 1626
1627 case SHN_UNDEF: 1627 case SHN_UNDEF:
1628 ksym = resolve_symbol(sechdrs, versindex, 1628 ksym = resolve_symbol(sechdrs, versindex,
1629 strtab + sym[i].st_name, mod); 1629 strtab + sym[i].st_name, mod);
1630 /* Ok if resolved. */ 1630 /* Ok if resolved. */
1631 if (ksym) { 1631 if (ksym) {
1632 sym[i].st_value = ksym->value; 1632 sym[i].st_value = ksym->value;
1633 break; 1633 break;
1634 } 1634 }
1635 1635
1636 /* Ok if weak. */ 1636 /* Ok if weak. */
1637 if (ELF_ST_BIND(sym[i].st_info) == STB_WEAK) 1637 if (ELF_ST_BIND(sym[i].st_info) == STB_WEAK)
1638 break; 1638 break;
1639 1639
1640 printk(KERN_WARNING "%s: Unknown symbol %s\n", 1640 printk(KERN_WARNING "%s: Unknown symbol %s\n",
1641 mod->name, strtab + sym[i].st_name); 1641 mod->name, strtab + sym[i].st_name);
1642 ret = -ENOENT; 1642 ret = -ENOENT;
1643 break; 1643 break;
1644 1644
1645 default: 1645 default:
1646 /* Divert to percpu allocation if a percpu var. */ 1646 /* Divert to percpu allocation if a percpu var. */
1647 if (sym[i].st_shndx == pcpuindex) 1647 if (sym[i].st_shndx == pcpuindex)
1648 secbase = (unsigned long)mod->percpu; 1648 secbase = (unsigned long)mod->percpu;
1649 else 1649 else
1650 secbase = sechdrs[sym[i].st_shndx].sh_addr; 1650 secbase = sechdrs[sym[i].st_shndx].sh_addr;
1651 sym[i].st_value += secbase; 1651 sym[i].st_value += secbase;
1652 break; 1652 break;
1653 } 1653 }
1654 } 1654 }
1655 1655
1656 return ret; 1656 return ret;
1657 } 1657 }
1658 1658
1659 /* Additional bytes needed by arch in front of individual sections */ 1659 /* Additional bytes needed by arch in front of individual sections */
1660 unsigned int __weak arch_mod_section_prepend(struct module *mod, 1660 unsigned int __weak arch_mod_section_prepend(struct module *mod,
1661 unsigned int section) 1661 unsigned int section)
1662 { 1662 {
1663 /* default implementation just returns zero */ 1663 /* default implementation just returns zero */
1664 return 0; 1664 return 0;
1665 } 1665 }
1666 1666
1667 /* Update size with this section: return offset. */ 1667 /* Update size with this section: return offset. */
1668 static long get_offset(struct module *mod, unsigned int *size, 1668 static long get_offset(struct module *mod, unsigned int *size,
1669 Elf_Shdr *sechdr, unsigned int section) 1669 Elf_Shdr *sechdr, unsigned int section)
1670 { 1670 {
1671 long ret; 1671 long ret;
1672 1672
1673 *size += arch_mod_section_prepend(mod, section); 1673 *size += arch_mod_section_prepend(mod, section);
1674 ret = ALIGN(*size, sechdr->sh_addralign ?: 1); 1674 ret = ALIGN(*size, sechdr->sh_addralign ?: 1);
1675 *size = ret + sechdr->sh_size; 1675 *size = ret + sechdr->sh_size;
1676 return ret; 1676 return ret;
1677 } 1677 }
1678 1678
1679 /* Lay out the SHF_ALLOC sections in a way not dissimilar to how ld 1679 /* Lay out the SHF_ALLOC sections in a way not dissimilar to how ld
1680 might -- code, read-only data, read-write data, small data. Tally 1680 might -- code, read-only data, read-write data, small data. Tally
1681 sizes, and place the offsets into sh_entsize fields: high bit means it 1681 sizes, and place the offsets into sh_entsize fields: high bit means it
1682 belongs in init. */ 1682 belongs in init. */
1683 static void layout_sections(struct module *mod, 1683 static void layout_sections(struct module *mod,
1684 const Elf_Ehdr *hdr, 1684 const Elf_Ehdr *hdr,
1685 Elf_Shdr *sechdrs, 1685 Elf_Shdr *sechdrs,
1686 const char *secstrings) 1686 const char *secstrings)
1687 { 1687 {
1688 static unsigned long const masks[][2] = { 1688 static unsigned long const masks[][2] = {
1689 /* NOTE: all executable code must be the first section 1689 /* NOTE: all executable code must be the first section
1690 * in this array; otherwise modify the text_size 1690 * in this array; otherwise modify the text_size
1691 * finder in the two loops below */ 1691 * finder in the two loops below */
1692 { SHF_EXECINSTR | SHF_ALLOC, ARCH_SHF_SMALL }, 1692 { SHF_EXECINSTR | SHF_ALLOC, ARCH_SHF_SMALL },
1693 { SHF_ALLOC, SHF_WRITE | ARCH_SHF_SMALL }, 1693 { SHF_ALLOC, SHF_WRITE | ARCH_SHF_SMALL },
1694 { SHF_WRITE | SHF_ALLOC, ARCH_SHF_SMALL }, 1694 { SHF_WRITE | SHF_ALLOC, ARCH_SHF_SMALL },
1695 { ARCH_SHF_SMALL | SHF_ALLOC, 0 } 1695 { ARCH_SHF_SMALL | SHF_ALLOC, 0 }
1696 }; 1696 };
1697 unsigned int m, i; 1697 unsigned int m, i;
1698 1698
1699 for (i = 0; i < hdr->e_shnum; i++) 1699 for (i = 0; i < hdr->e_shnum; i++)
1700 sechdrs[i].sh_entsize = ~0UL; 1700 sechdrs[i].sh_entsize = ~0UL;
1701 1701
1702 DEBUGP("Core section allocation order:\n"); 1702 DEBUGP("Core section allocation order:\n");
1703 for (m = 0; m < ARRAY_SIZE(masks); ++m) { 1703 for (m = 0; m < ARRAY_SIZE(masks); ++m) {
1704 for (i = 0; i < hdr->e_shnum; ++i) { 1704 for (i = 0; i < hdr->e_shnum; ++i) {
1705 Elf_Shdr *s = &sechdrs[i]; 1705 Elf_Shdr *s = &sechdrs[i];
1706 1706
1707 if ((s->sh_flags & masks[m][0]) != masks[m][0] 1707 if ((s->sh_flags & masks[m][0]) != masks[m][0]
1708 || (s->sh_flags & masks[m][1]) 1708 || (s->sh_flags & masks[m][1])
1709 || s->sh_entsize != ~0UL 1709 || s->sh_entsize != ~0UL
1710 || strstarts(secstrings + s->sh_name, ".init")) 1710 || strstarts(secstrings + s->sh_name, ".init"))
1711 continue; 1711 continue;
1712 s->sh_entsize = get_offset(mod, &mod->core_size, s, i); 1712 s->sh_entsize = get_offset(mod, &mod->core_size, s, i);
1713 DEBUGP("\t%s\n", secstrings + s->sh_name); 1713 DEBUGP("\t%s\n", secstrings + s->sh_name);
1714 } 1714 }
1715 if (m == 0) 1715 if (m == 0)
1716 mod->core_text_size = mod->core_size; 1716 mod->core_text_size = mod->core_size;
1717 } 1717 }
1718 1718
1719 DEBUGP("Init section allocation order:\n"); 1719 DEBUGP("Init section allocation order:\n");
1720 for (m = 0; m < ARRAY_SIZE(masks); ++m) { 1720 for (m = 0; m < ARRAY_SIZE(masks); ++m) {
1721 for (i = 0; i < hdr->e_shnum; ++i) { 1721 for (i = 0; i < hdr->e_shnum; ++i) {
1722 Elf_Shdr *s = &sechdrs[i]; 1722 Elf_Shdr *s = &sechdrs[i];
1723 1723
1724 if ((s->sh_flags & masks[m][0]) != masks[m][0] 1724 if ((s->sh_flags & masks[m][0]) != masks[m][0]
1725 || (s->sh_flags & masks[m][1]) 1725 || (s->sh_flags & masks[m][1])
1726 || s->sh_entsize != ~0UL 1726 || s->sh_entsize != ~0UL
1727 || !strstarts(secstrings + s->sh_name, ".init")) 1727 || !strstarts(secstrings + s->sh_name, ".init"))
1728 continue; 1728 continue;
1729 s->sh_entsize = (get_offset(mod, &mod->init_size, s, i) 1729 s->sh_entsize = (get_offset(mod, &mod->init_size, s, i)
1730 | INIT_OFFSET_MASK); 1730 | INIT_OFFSET_MASK);
1731 DEBUGP("\t%s\n", secstrings + s->sh_name); 1731 DEBUGP("\t%s\n", secstrings + s->sh_name);
1732 } 1732 }
1733 if (m == 0) 1733 if (m == 0)
1734 mod->init_text_size = mod->init_size; 1734 mod->init_text_size = mod->init_size;
1735 } 1735 }
1736 } 1736 }
1737 1737
1738 static void set_license(struct module *mod, const char *license) 1738 static void set_license(struct module *mod, const char *license)
1739 { 1739 {
1740 if (!license) 1740 if (!license)
1741 license = "unspecified"; 1741 license = "unspecified";
1742 1742
1743 if (!license_is_gpl_compatible(license)) { 1743 if (!license_is_gpl_compatible(license)) {
1744 if (!test_taint(TAINT_PROPRIETARY_MODULE)) 1744 if (!test_taint(TAINT_PROPRIETARY_MODULE))
1745 printk(KERN_WARNING "%s: module license '%s' taints " 1745 printk(KERN_WARNING "%s: module license '%s' taints "
1746 "kernel.\n", mod->name, license); 1746 "kernel.\n", mod->name, license);
1747 add_taint_module(mod, TAINT_PROPRIETARY_MODULE); 1747 add_taint_module(mod, TAINT_PROPRIETARY_MODULE);
1748 } 1748 }
1749 } 1749 }
1750 1750
1751 /* Parse tag=value strings from .modinfo section */ 1751 /* Parse tag=value strings from .modinfo section */
1752 static char *next_string(char *string, unsigned long *secsize) 1752 static char *next_string(char *string, unsigned long *secsize)
1753 { 1753 {
1754 /* Skip non-zero chars */ 1754 /* Skip non-zero chars */
1755 while (string[0]) { 1755 while (string[0]) {
1756 string++; 1756 string++;
1757 if ((*secsize)-- <= 1) 1757 if ((*secsize)-- <= 1)
1758 return NULL; 1758 return NULL;
1759 } 1759 }
1760 1760
1761 /* Skip any zero padding. */ 1761 /* Skip any zero padding. */
1762 while (!string[0]) { 1762 while (!string[0]) {
1763 string++; 1763 string++;
1764 if ((*secsize)-- <= 1) 1764 if ((*secsize)-- <= 1)
1765 return NULL; 1765 return NULL;
1766 } 1766 }
1767 return string; 1767 return string;
1768 } 1768 }
1769 1769
1770 static char *get_modinfo(Elf_Shdr *sechdrs, 1770 static char *get_modinfo(Elf_Shdr *sechdrs,
1771 unsigned int info, 1771 unsigned int info,
1772 const char *tag) 1772 const char *tag)
1773 { 1773 {
1774 char *p; 1774 char *p;
1775 unsigned int taglen = strlen(tag); 1775 unsigned int taglen = strlen(tag);
1776 unsigned long size = sechdrs[info].sh_size; 1776 unsigned long size = sechdrs[info].sh_size;
1777 1777
1778 for (p = (char *)sechdrs[info].sh_addr; p; p = next_string(p, &size)) { 1778 for (p = (char *)sechdrs[info].sh_addr; p; p = next_string(p, &size)) {
1779 if (strncmp(p, tag, taglen) == 0 && p[taglen] == '=') 1779 if (strncmp(p, tag, taglen) == 0 && p[taglen] == '=')
1780 return p + taglen + 1; 1780 return p + taglen + 1;
1781 } 1781 }
1782 return NULL; 1782 return NULL;
1783 } 1783 }
1784 1784
1785 static void setup_modinfo(struct module *mod, Elf_Shdr *sechdrs, 1785 static void setup_modinfo(struct module *mod, Elf_Shdr *sechdrs,
1786 unsigned int infoindex) 1786 unsigned int infoindex)
1787 { 1787 {
1788 struct module_attribute *attr; 1788 struct module_attribute *attr;
1789 int i; 1789 int i;
1790 1790
1791 for (i = 0; (attr = modinfo_attrs[i]); i++) { 1791 for (i = 0; (attr = modinfo_attrs[i]); i++) {
1792 if (attr->setup) 1792 if (attr->setup)
1793 attr->setup(mod, 1793 attr->setup(mod,
1794 get_modinfo(sechdrs, 1794 get_modinfo(sechdrs,
1795 infoindex, 1795 infoindex,
1796 attr->attr.name)); 1796 attr->attr.name));
1797 } 1797 }
1798 } 1798 }
1799 1799
1800 #ifdef CONFIG_KALLSYMS 1800 #ifdef CONFIG_KALLSYMS
1801 1801
1802 /* lookup symbol in given range of kernel_symbols */ 1802 /* lookup symbol in given range of kernel_symbols */
1803 static const struct kernel_symbol *lookup_symbol(const char *name, 1803 static const struct kernel_symbol *lookup_symbol(const char *name,
1804 const struct kernel_symbol *start, 1804 const struct kernel_symbol *start,
1805 const struct kernel_symbol *stop) 1805 const struct kernel_symbol *stop)
1806 { 1806 {
1807 const struct kernel_symbol *ks = start; 1807 const struct kernel_symbol *ks = start;
1808 for (; ks < stop; ks++) 1808 for (; ks < stop; ks++)
1809 if (strcmp(ks->name, name) == 0) 1809 if (strcmp(ks->name, name) == 0)
1810 return ks; 1810 return ks;
1811 return NULL; 1811 return NULL;
1812 } 1812 }
1813 1813
1814 static int is_exported(const char *name, unsigned long value, 1814 static int is_exported(const char *name, unsigned long value,
1815 const struct module *mod) 1815 const struct module *mod)
1816 { 1816 {
1817 const struct kernel_symbol *ks; 1817 const struct kernel_symbol *ks;
1818 if (!mod) 1818 if (!mod)
1819 ks = lookup_symbol(name, __start___ksymtab, __stop___ksymtab); 1819 ks = lookup_symbol(name, __start___ksymtab, __stop___ksymtab);
1820 else 1820 else
1821 ks = lookup_symbol(name, mod->syms, mod->syms + mod->num_syms); 1821 ks = lookup_symbol(name, mod->syms, mod->syms + mod->num_syms);
1822 return ks != NULL && ks->value == value; 1822 return ks != NULL && ks->value == value;
1823 } 1823 }
1824 1824
1825 /* As per nm */ 1825 /* As per nm */
1826 static char elf_type(const Elf_Sym *sym, 1826 static char elf_type(const Elf_Sym *sym,
1827 Elf_Shdr *sechdrs, 1827 Elf_Shdr *sechdrs,
1828 const char *secstrings, 1828 const char *secstrings,
1829 struct module *mod) 1829 struct module *mod)
1830 { 1830 {
1831 if (ELF_ST_BIND(sym->st_info) == STB_WEAK) { 1831 if (ELF_ST_BIND(sym->st_info) == STB_WEAK) {
1832 if (ELF_ST_TYPE(sym->st_info) == STT_OBJECT) 1832 if (ELF_ST_TYPE(sym->st_info) == STT_OBJECT)
1833 return 'v'; 1833 return 'v';
1834 else 1834 else
1835 return 'w'; 1835 return 'w';
1836 } 1836 }
1837 if (sym->st_shndx == SHN_UNDEF) 1837 if (sym->st_shndx == SHN_UNDEF)
1838 return 'U'; 1838 return 'U';
1839 if (sym->st_shndx == SHN_ABS) 1839 if (sym->st_shndx == SHN_ABS)
1840 return 'a'; 1840 return 'a';
1841 if (sym->st_shndx >= SHN_LORESERVE) 1841 if (sym->st_shndx >= SHN_LORESERVE)
1842 return '?'; 1842 return '?';
1843 if (sechdrs[sym->st_shndx].sh_flags & SHF_EXECINSTR) 1843 if (sechdrs[sym->st_shndx].sh_flags & SHF_EXECINSTR)
1844 return 't'; 1844 return 't';
1845 if (sechdrs[sym->st_shndx].sh_flags & SHF_ALLOC 1845 if (sechdrs[sym->st_shndx].sh_flags & SHF_ALLOC
1846 && sechdrs[sym->st_shndx].sh_type != SHT_NOBITS) { 1846 && sechdrs[sym->st_shndx].sh_type != SHT_NOBITS) {
1847 if (!(sechdrs[sym->st_shndx].sh_flags & SHF_WRITE)) 1847 if (!(sechdrs[sym->st_shndx].sh_flags & SHF_WRITE))
1848 return 'r'; 1848 return 'r';
1849 else if (sechdrs[sym->st_shndx].sh_flags & ARCH_SHF_SMALL) 1849 else if (sechdrs[sym->st_shndx].sh_flags & ARCH_SHF_SMALL)
1850 return 'g'; 1850 return 'g';
1851 else 1851 else
1852 return 'd'; 1852 return 'd';
1853 } 1853 }
1854 if (sechdrs[sym->st_shndx].sh_type == SHT_NOBITS) { 1854 if (sechdrs[sym->st_shndx].sh_type == SHT_NOBITS) {
1855 if (sechdrs[sym->st_shndx].sh_flags & ARCH_SHF_SMALL) 1855 if (sechdrs[sym->st_shndx].sh_flags & ARCH_SHF_SMALL)
1856 return 's'; 1856 return 's';
1857 else 1857 else
1858 return 'b'; 1858 return 'b';
1859 } 1859 }
1860 if (strstarts(secstrings + sechdrs[sym->st_shndx].sh_name, ".debug")) 1860 if (strstarts(secstrings + sechdrs[sym->st_shndx].sh_name, ".debug"))
1861 return 'n'; 1861 return 'n';
1862 return '?'; 1862 return '?';
1863 } 1863 }
1864 1864
1865 static bool is_core_symbol(const Elf_Sym *src, const Elf_Shdr *sechdrs, 1865 static bool is_core_symbol(const Elf_Sym *src, const Elf_Shdr *sechdrs,
1866 unsigned int shnum) 1866 unsigned int shnum)
1867 { 1867 {
1868 const Elf_Shdr *sec; 1868 const Elf_Shdr *sec;
1869 1869
1870 if (src->st_shndx == SHN_UNDEF 1870 if (src->st_shndx == SHN_UNDEF
1871 || src->st_shndx >= shnum 1871 || src->st_shndx >= shnum
1872 || !src->st_name) 1872 || !src->st_name)
1873 return false; 1873 return false;
1874 1874
1875 sec = sechdrs + src->st_shndx; 1875 sec = sechdrs + src->st_shndx;
1876 if (!(sec->sh_flags & SHF_ALLOC) 1876 if (!(sec->sh_flags & SHF_ALLOC)
1877 #ifndef CONFIG_KALLSYMS_ALL 1877 #ifndef CONFIG_KALLSYMS_ALL
1878 || !(sec->sh_flags & SHF_EXECINSTR) 1878 || !(sec->sh_flags & SHF_EXECINSTR)
1879 #endif 1879 #endif
1880 || (sec->sh_entsize & INIT_OFFSET_MASK)) 1880 || (sec->sh_entsize & INIT_OFFSET_MASK))
1881 return false; 1881 return false;
1882 1882
1883 return true; 1883 return true;
1884 } 1884 }
1885 1885
1886 static unsigned long layout_symtab(struct module *mod, 1886 static unsigned long layout_symtab(struct module *mod,
1887 Elf_Shdr *sechdrs, 1887 Elf_Shdr *sechdrs,
1888 unsigned int symindex, 1888 unsigned int symindex,
1889 unsigned int strindex,
1889 const Elf_Ehdr *hdr, 1890 const Elf_Ehdr *hdr,
1890 const char *secstrings) 1891 const char *secstrings,
1892 unsigned long *pstroffs,
1893 unsigned long *strmap)
1891 { 1894 {
1892 unsigned long symoffs; 1895 unsigned long symoffs;
1893 Elf_Shdr *symsect = sechdrs + symindex; 1896 Elf_Shdr *symsect = sechdrs + symindex;
1897 Elf_Shdr *strsect = sechdrs + strindex;
1894 const Elf_Sym *src; 1898 const Elf_Sym *src;
1899 const char *strtab;
1895 unsigned int i, nsrc, ndst; 1900 unsigned int i, nsrc, ndst;
1896 1901
1897 /* Put symbol section at end of init part of module. */ 1902 /* Put symbol section at end of init part of module. */
1898 symsect->sh_flags |= SHF_ALLOC; 1903 symsect->sh_flags |= SHF_ALLOC;
1899 symsect->sh_entsize = get_offset(mod, &mod->init_size, symsect, 1904 symsect->sh_entsize = get_offset(mod, &mod->init_size, symsect,
1900 symindex) | INIT_OFFSET_MASK; 1905 symindex) | INIT_OFFSET_MASK;
1901 DEBUGP("\t%s\n", secstrings + symsect->sh_name); 1906 DEBUGP("\t%s\n", secstrings + symsect->sh_name);
1902 1907
1903 src = (void *)hdr + symsect->sh_offset; 1908 src = (void *)hdr + symsect->sh_offset;
1904 nsrc = symsect->sh_size / sizeof(*src); 1909 nsrc = symsect->sh_size / sizeof(*src);
1910 strtab = (void *)hdr + strsect->sh_offset;
1905 for (ndst = i = 1; i < nsrc; ++i, ++src) 1911 for (ndst = i = 1; i < nsrc; ++i, ++src)
1906 if (is_core_symbol(src, sechdrs, hdr->e_shnum)) 1912 if (is_core_symbol(src, sechdrs, hdr->e_shnum)) {
1913 unsigned int j = src->st_name;
1914
1915 while(!__test_and_set_bit(j, strmap) && strtab[j])
1916 ++j;
1907 ++ndst; 1917 ++ndst;
1918 }
1908 1919
1909 /* Append room for core symbols at end of core part. */ 1920 /* Append room for core symbols at end of core part. */
1910 symoffs = ALIGN(mod->core_size, symsect->sh_addralign ?: 1); 1921 symoffs = ALIGN(mod->core_size, symsect->sh_addralign ?: 1);
1911 mod->core_size = symoffs + ndst * sizeof(Elf_Sym); 1922 mod->core_size = symoffs + ndst * sizeof(Elf_Sym);
1912 1923
1924 /* Put string table section at end of init part of module. */
1925 strsect->sh_flags |= SHF_ALLOC;
1926 strsect->sh_entsize = get_offset(mod, &mod->init_size, strsect,
1927 strindex) | INIT_OFFSET_MASK;
1928 DEBUGP("\t%s\n", secstrings + strsect->sh_name);
1929
1930 /* Append room for core symbols' strings at end of core part. */
1931 *pstroffs = mod->core_size;
1932 __set_bit(0, strmap);
1933 mod->core_size += bitmap_weight(strmap, strsect->sh_size);
1934
1913 return symoffs; 1935 return symoffs;
1914 } 1936 }
1915 1937
1916 static void add_kallsyms(struct module *mod, 1938 static void add_kallsyms(struct module *mod,
1917 Elf_Shdr *sechdrs, 1939 Elf_Shdr *sechdrs,
1918 unsigned int shnum, 1940 unsigned int shnum,
1919 unsigned int symindex, 1941 unsigned int symindex,
1920 unsigned int strindex, 1942 unsigned int strindex,
1921 unsigned long symoffs, 1943 unsigned long symoffs,
1922 const char *secstrings) 1944 unsigned long stroffs,
1945 const char *secstrings,
1946 unsigned long *strmap)
1923 { 1947 {
1924 unsigned int i, ndst; 1948 unsigned int i, ndst;
1925 const Elf_Sym *src; 1949 const Elf_Sym *src;
1926 Elf_Sym *dst; 1950 Elf_Sym *dst;
1951 char *s;
1927 1952
1928 mod->symtab = (void *)sechdrs[symindex].sh_addr; 1953 mod->symtab = (void *)sechdrs[symindex].sh_addr;
1929 mod->num_symtab = sechdrs[symindex].sh_size / sizeof(Elf_Sym); 1954 mod->num_symtab = sechdrs[symindex].sh_size / sizeof(Elf_Sym);
1930 mod->strtab = (void *)sechdrs[strindex].sh_addr; 1955 mod->strtab = (void *)sechdrs[strindex].sh_addr;
1931 1956
1932 /* Set types up while we still have access to sections. */ 1957 /* Set types up while we still have access to sections. */
1933 for (i = 0; i < mod->num_symtab; i++) 1958 for (i = 0; i < mod->num_symtab; i++)
1934 mod->symtab[i].st_info 1959 mod->symtab[i].st_info
1935 = elf_type(&mod->symtab[i], sechdrs, secstrings, mod); 1960 = elf_type(&mod->symtab[i], sechdrs, secstrings, mod);
1936 1961
1937 mod->core_symtab = dst = mod->module_core + symoffs; 1962 mod->core_symtab = dst = mod->module_core + symoffs;
1938 src = mod->symtab; 1963 src = mod->symtab;
1939 *dst = *src; 1964 *dst = *src;
1940 for (ndst = i = 1; i < mod->num_symtab; ++i, ++src) { 1965 for (ndst = i = 1; i < mod->num_symtab; ++i, ++src) {
1941 if (!is_core_symbol(src, sechdrs, shnum)) 1966 if (!is_core_symbol(src, sechdrs, shnum))
1942 continue; 1967 continue;
1943 dst[ndst] = *src; 1968 dst[ndst] = *src;
1969 dst[ndst].st_name = bitmap_weight(strmap, dst[ndst].st_name);
1944 ++ndst; 1970 ++ndst;
1945 } 1971 }
1946 mod->core_num_syms = ndst; 1972 mod->core_num_syms = ndst;
1973
1974 mod->core_strtab = s = mod->module_core + stroffs;
1975 for (*s = 0, i = 1; i < sechdrs[strindex].sh_size; ++i)
1976 if (test_bit(i, strmap))
1977 *++s = mod->strtab[i];
1947 } 1978 }
1948 #else 1979 #else
1949 static inline unsigned long layout_symtab(struct module *mod, 1980 static inline unsigned long layout_symtab(struct module *mod,
1950 Elf_Shdr *sechdrs, 1981 Elf_Shdr *sechdrs,
1951 unsigned int symindex, 1982 unsigned int symindex,
1983 unsigned int strindex,
1952 const Elf_Hdr *hdr, 1984 const Elf_Hdr *hdr,
1953 const char *secstrings) 1985 const char *secstrings,
1986 unsigned long *pstroffs,
1987 unsigned long *strmap)
1954 { 1988 {
1955 } 1989 }
1956 static inline void add_kallsyms(struct module *mod, 1990 static inline void add_kallsyms(struct module *mod,
1957 Elf_Shdr *sechdrs, 1991 Elf_Shdr *sechdrs,
1958 unsigned int shnum, 1992 unsigned int shnum,
1959 unsigned int symindex, 1993 unsigned int symindex,
1960 unsigned int strindex, 1994 unsigned int strindex,
1961 unsigned long symoffs, 1995 unsigned long symoffs,
1962 const char *secstrings) 1996 unsigned long stroffs,
1997 const char *secstrings,
1998 const unsigned long *strmap)
1963 { 1999 {
1964 } 2000 }
1965 #endif /* CONFIG_KALLSYMS */ 2001 #endif /* CONFIG_KALLSYMS */
1966 2002
1967 static void dynamic_debug_setup(struct _ddebug *debug, unsigned int num) 2003 static void dynamic_debug_setup(struct _ddebug *debug, unsigned int num)
1968 { 2004 {
1969 #ifdef CONFIG_DYNAMIC_DEBUG 2005 #ifdef CONFIG_DYNAMIC_DEBUG
1970 if (ddebug_add_module(debug, num, debug->modname)) 2006 if (ddebug_add_module(debug, num, debug->modname))
1971 printk(KERN_ERR "dynamic debug error adding module: %s\n", 2007 printk(KERN_ERR "dynamic debug error adding module: %s\n",
1972 debug->modname); 2008 debug->modname);
1973 #endif 2009 #endif
1974 } 2010 }
1975 2011
1976 static void *module_alloc_update_bounds(unsigned long size) 2012 static void *module_alloc_update_bounds(unsigned long size)
1977 { 2013 {
1978 void *ret = module_alloc(size); 2014 void *ret = module_alloc(size);
1979 2015
1980 if (ret) { 2016 if (ret) {
1981 /* Update module bounds. */ 2017 /* Update module bounds. */
1982 if ((unsigned long)ret < module_addr_min) 2018 if ((unsigned long)ret < module_addr_min)
1983 module_addr_min = (unsigned long)ret; 2019 module_addr_min = (unsigned long)ret;
1984 if ((unsigned long)ret + size > module_addr_max) 2020 if ((unsigned long)ret + size > module_addr_max)
1985 module_addr_max = (unsigned long)ret + size; 2021 module_addr_max = (unsigned long)ret + size;
1986 } 2022 }
1987 return ret; 2023 return ret;
1988 } 2024 }
1989 2025
1990 #ifdef CONFIG_DEBUG_KMEMLEAK 2026 #ifdef CONFIG_DEBUG_KMEMLEAK
1991 static void kmemleak_load_module(struct module *mod, Elf_Ehdr *hdr, 2027 static void kmemleak_load_module(struct module *mod, Elf_Ehdr *hdr,
1992 Elf_Shdr *sechdrs, char *secstrings) 2028 Elf_Shdr *sechdrs, char *secstrings)
1993 { 2029 {
1994 unsigned int i; 2030 unsigned int i;
1995 2031
1996 /* only scan the sections containing data */ 2032 /* only scan the sections containing data */
1997 kmemleak_scan_area(mod->module_core, (unsigned long)mod - 2033 kmemleak_scan_area(mod->module_core, (unsigned long)mod -
1998 (unsigned long)mod->module_core, 2034 (unsigned long)mod->module_core,
1999 sizeof(struct module), GFP_KERNEL); 2035 sizeof(struct module), GFP_KERNEL);
2000 2036
2001 for (i = 1; i < hdr->e_shnum; i++) { 2037 for (i = 1; i < hdr->e_shnum; i++) {
2002 if (!(sechdrs[i].sh_flags & SHF_ALLOC)) 2038 if (!(sechdrs[i].sh_flags & SHF_ALLOC))
2003 continue; 2039 continue;
2004 if (strncmp(secstrings + sechdrs[i].sh_name, ".data", 5) != 0 2040 if (strncmp(secstrings + sechdrs[i].sh_name, ".data", 5) != 0
2005 && strncmp(secstrings + sechdrs[i].sh_name, ".bss", 4) != 0) 2041 && strncmp(secstrings + sechdrs[i].sh_name, ".bss", 4) != 0)
2006 continue; 2042 continue;
2007 2043
2008 kmemleak_scan_area(mod->module_core, sechdrs[i].sh_addr - 2044 kmemleak_scan_area(mod->module_core, sechdrs[i].sh_addr -
2009 (unsigned long)mod->module_core, 2045 (unsigned long)mod->module_core,
2010 sechdrs[i].sh_size, GFP_KERNEL); 2046 sechdrs[i].sh_size, GFP_KERNEL);
2011 } 2047 }
2012 } 2048 }
2013 #else 2049 #else
2014 static inline void kmemleak_load_module(struct module *mod, Elf_Ehdr *hdr, 2050 static inline void kmemleak_load_module(struct module *mod, Elf_Ehdr *hdr,
2015 Elf_Shdr *sechdrs, char *secstrings) 2051 Elf_Shdr *sechdrs, char *secstrings)
2016 { 2052 {
2017 } 2053 }
2018 #endif 2054 #endif
2019 2055
2020 /* Allocate and load the module: note that size of section 0 is always 2056 /* Allocate and load the module: note that size of section 0 is always
2021 zero, and we rely on this for optional sections. */ 2057 zero, and we rely on this for optional sections. */
2022 static noinline struct module *load_module(void __user *umod, 2058 static noinline struct module *load_module(void __user *umod,
2023 unsigned long len, 2059 unsigned long len,
2024 const char __user *uargs) 2060 const char __user *uargs)
2025 { 2061 {
2026 Elf_Ehdr *hdr; 2062 Elf_Ehdr *hdr;
2027 Elf_Shdr *sechdrs; 2063 Elf_Shdr *sechdrs;
2028 char *secstrings, *args, *modmagic, *strtab = NULL; 2064 char *secstrings, *args, *modmagic, *strtab = NULL;
2029 char *staging; 2065 char *staging;
2030 unsigned int i; 2066 unsigned int i;
2031 unsigned int symindex = 0; 2067 unsigned int symindex = 0;
2032 unsigned int strindex = 0; 2068 unsigned int strindex = 0;
2033 unsigned int modindex, versindex, infoindex, pcpuindex; 2069 unsigned int modindex, versindex, infoindex, pcpuindex;
2034 struct module *mod; 2070 struct module *mod;
2035 long err = 0; 2071 long err = 0;
2036 void *percpu = NULL, *ptr = NULL; /* Stops spurious gcc warning */ 2072 void *percpu = NULL, *ptr = NULL; /* Stops spurious gcc warning */
2037 #ifdef CONFIG_KALLSYMS 2073 #ifdef CONFIG_KALLSYMS
2038 unsigned long symoffs; 2074 unsigned long symoffs, stroffs, *strmap;
2039 #endif 2075 #endif
2040 mm_segment_t old_fs; 2076 mm_segment_t old_fs;
2041 2077
2042 DEBUGP("load_module: umod=%p, len=%lu, uargs=%p\n", 2078 DEBUGP("load_module: umod=%p, len=%lu, uargs=%p\n",
2043 umod, len, uargs); 2079 umod, len, uargs);
2044 if (len < sizeof(*hdr)) 2080 if (len < sizeof(*hdr))
2045 return ERR_PTR(-ENOEXEC); 2081 return ERR_PTR(-ENOEXEC);
2046 2082
2047 /* Suck in entire file: we'll want most of it. */ 2083 /* Suck in entire file: we'll want most of it. */
2048 /* vmalloc barfs on "unusual" numbers. Check here */ 2084 /* vmalloc barfs on "unusual" numbers. Check here */
2049 if (len > 64 * 1024 * 1024 || (hdr = vmalloc(len)) == NULL) 2085 if (len > 64 * 1024 * 1024 || (hdr = vmalloc(len)) == NULL)
2050 return ERR_PTR(-ENOMEM); 2086 return ERR_PTR(-ENOMEM);
2051 2087
2052 if (copy_from_user(hdr, umod, len) != 0) { 2088 if (copy_from_user(hdr, umod, len) != 0) {
2053 err = -EFAULT; 2089 err = -EFAULT;
2054 goto free_hdr; 2090 goto free_hdr;
2055 } 2091 }
2056 2092
2057 /* Sanity checks against insmoding binaries or wrong arch, 2093 /* Sanity checks against insmoding binaries or wrong arch,
2058 weird elf version */ 2094 weird elf version */
2059 if (memcmp(hdr->e_ident, ELFMAG, SELFMAG) != 0 2095 if (memcmp(hdr->e_ident, ELFMAG, SELFMAG) != 0
2060 || hdr->e_type != ET_REL 2096 || hdr->e_type != ET_REL
2061 || !elf_check_arch(hdr) 2097 || !elf_check_arch(hdr)
2062 || hdr->e_shentsize != sizeof(*sechdrs)) { 2098 || hdr->e_shentsize != sizeof(*sechdrs)) {
2063 err = -ENOEXEC; 2099 err = -ENOEXEC;
2064 goto free_hdr; 2100 goto free_hdr;
2065 } 2101 }
2066 2102
2067 if (len < hdr->e_shoff + hdr->e_shnum * sizeof(Elf_Shdr)) 2103 if (len < hdr->e_shoff + hdr->e_shnum * sizeof(Elf_Shdr))
2068 goto truncated; 2104 goto truncated;
2069 2105
2070 /* Convenience variables */ 2106 /* Convenience variables */
2071 sechdrs = (void *)hdr + hdr->e_shoff; 2107 sechdrs = (void *)hdr + hdr->e_shoff;
2072 secstrings = (void *)hdr + sechdrs[hdr->e_shstrndx].sh_offset; 2108 secstrings = (void *)hdr + sechdrs[hdr->e_shstrndx].sh_offset;
2073 sechdrs[0].sh_addr = 0; 2109 sechdrs[0].sh_addr = 0;
2074 2110
2075 for (i = 1; i < hdr->e_shnum; i++) { 2111 for (i = 1; i < hdr->e_shnum; i++) {
2076 if (sechdrs[i].sh_type != SHT_NOBITS 2112 if (sechdrs[i].sh_type != SHT_NOBITS
2077 && len < sechdrs[i].sh_offset + sechdrs[i].sh_size) 2113 && len < sechdrs[i].sh_offset + sechdrs[i].sh_size)
2078 goto truncated; 2114 goto truncated;
2079 2115
2080 /* Mark all sections sh_addr with their address in the 2116 /* Mark all sections sh_addr with their address in the
2081 temporary image. */ 2117 temporary image. */
2082 sechdrs[i].sh_addr = (size_t)hdr + sechdrs[i].sh_offset; 2118 sechdrs[i].sh_addr = (size_t)hdr + sechdrs[i].sh_offset;
2083 2119
2084 /* Internal symbols and strings. */ 2120 /* Internal symbols and strings. */
2085 if (sechdrs[i].sh_type == SHT_SYMTAB) { 2121 if (sechdrs[i].sh_type == SHT_SYMTAB) {
2086 symindex = i; 2122 symindex = i;
2087 strindex = sechdrs[i].sh_link; 2123 strindex = sechdrs[i].sh_link;
2088 strtab = (char *)hdr + sechdrs[strindex].sh_offset; 2124 strtab = (char *)hdr + sechdrs[strindex].sh_offset;
2089 } 2125 }
2090 #ifndef CONFIG_MODULE_UNLOAD 2126 #ifndef CONFIG_MODULE_UNLOAD
2091 /* Don't load .exit sections */ 2127 /* Don't load .exit sections */
2092 if (strstarts(secstrings+sechdrs[i].sh_name, ".exit")) 2128 if (strstarts(secstrings+sechdrs[i].sh_name, ".exit"))
2093 sechdrs[i].sh_flags &= ~(unsigned long)SHF_ALLOC; 2129 sechdrs[i].sh_flags &= ~(unsigned long)SHF_ALLOC;
2094 #endif 2130 #endif
2095 } 2131 }
2096 2132
2097 modindex = find_sec(hdr, sechdrs, secstrings, 2133 modindex = find_sec(hdr, sechdrs, secstrings,
2098 ".gnu.linkonce.this_module"); 2134 ".gnu.linkonce.this_module");
2099 if (!modindex) { 2135 if (!modindex) {
2100 printk(KERN_WARNING "No module found in object\n"); 2136 printk(KERN_WARNING "No module found in object\n");
2101 err = -ENOEXEC; 2137 err = -ENOEXEC;
2102 goto free_hdr; 2138 goto free_hdr;
2103 } 2139 }
2104 /* This is temporary: point mod into copy of data. */ 2140 /* This is temporary: point mod into copy of data. */
2105 mod = (void *)sechdrs[modindex].sh_addr; 2141 mod = (void *)sechdrs[modindex].sh_addr;
2106 2142
2107 if (symindex == 0) { 2143 if (symindex == 0) {
2108 printk(KERN_WARNING "%s: module has no symbols (stripped?)\n", 2144 printk(KERN_WARNING "%s: module has no symbols (stripped?)\n",
2109 mod->name); 2145 mod->name);
2110 err = -ENOEXEC; 2146 err = -ENOEXEC;
2111 goto free_hdr; 2147 goto free_hdr;
2112 } 2148 }
2113 2149
2114 versindex = find_sec(hdr, sechdrs, secstrings, "__versions"); 2150 versindex = find_sec(hdr, sechdrs, secstrings, "__versions");
2115 infoindex = find_sec(hdr, sechdrs, secstrings, ".modinfo"); 2151 infoindex = find_sec(hdr, sechdrs, secstrings, ".modinfo");
2116 pcpuindex = find_pcpusec(hdr, sechdrs, secstrings); 2152 pcpuindex = find_pcpusec(hdr, sechdrs, secstrings);
2117 2153
2118 /* Don't keep modinfo and version sections. */ 2154 /* Don't keep modinfo and version sections. */
2119 sechdrs[infoindex].sh_flags &= ~(unsigned long)SHF_ALLOC; 2155 sechdrs[infoindex].sh_flags &= ~(unsigned long)SHF_ALLOC;
2120 sechdrs[versindex].sh_flags &= ~(unsigned long)SHF_ALLOC; 2156 sechdrs[versindex].sh_flags &= ~(unsigned long)SHF_ALLOC;
2121 #ifdef CONFIG_KALLSYMS
2122 /* Keep string table for decoding later. */
2123 sechdrs[strindex].sh_flags |= SHF_ALLOC;
2124 #endif
2125 2157
2126 /* Check module struct version now, before we try to use module. */ 2158 /* Check module struct version now, before we try to use module. */
2127 if (!check_modstruct_version(sechdrs, versindex, mod)) { 2159 if (!check_modstruct_version(sechdrs, versindex, mod)) {
2128 err = -ENOEXEC; 2160 err = -ENOEXEC;
2129 goto free_hdr; 2161 goto free_hdr;
2130 } 2162 }
2131 2163
2132 modmagic = get_modinfo(sechdrs, infoindex, "vermagic"); 2164 modmagic = get_modinfo(sechdrs, infoindex, "vermagic");
2133 /* This is allowed: modprobe --force will invalidate it. */ 2165 /* This is allowed: modprobe --force will invalidate it. */
2134 if (!modmagic) { 2166 if (!modmagic) {
2135 err = try_to_force_load(mod, "bad vermagic"); 2167 err = try_to_force_load(mod, "bad vermagic");
2136 if (err) 2168 if (err)
2137 goto free_hdr; 2169 goto free_hdr;
2138 } else if (!same_magic(modmagic, vermagic, versindex)) { 2170 } else if (!same_magic(modmagic, vermagic, versindex)) {
2139 printk(KERN_ERR "%s: version magic '%s' should be '%s'\n", 2171 printk(KERN_ERR "%s: version magic '%s' should be '%s'\n",
2140 mod->name, modmagic, vermagic); 2172 mod->name, modmagic, vermagic);
2141 err = -ENOEXEC; 2173 err = -ENOEXEC;
2142 goto free_hdr; 2174 goto free_hdr;
2143 } 2175 }
2144 2176
2145 staging = get_modinfo(sechdrs, infoindex, "staging"); 2177 staging = get_modinfo(sechdrs, infoindex, "staging");
2146 if (staging) { 2178 if (staging) {
2147 add_taint_module(mod, TAINT_CRAP); 2179 add_taint_module(mod, TAINT_CRAP);
2148 printk(KERN_WARNING "%s: module is from the staging directory," 2180 printk(KERN_WARNING "%s: module is from the staging directory,"
2149 " the quality is unknown, you have been warned.\n", 2181 " the quality is unknown, you have been warned.\n",
2150 mod->name); 2182 mod->name);
2151 } 2183 }
2152 2184
2153 /* Now copy in args */ 2185 /* Now copy in args */
2154 args = strndup_user(uargs, ~0UL >> 1); 2186 args = strndup_user(uargs, ~0UL >> 1);
2155 if (IS_ERR(args)) { 2187 if (IS_ERR(args)) {
2156 err = PTR_ERR(args); 2188 err = PTR_ERR(args);
2157 goto free_hdr; 2189 goto free_hdr;
2158 } 2190 }
2159 2191
2192 strmap = kzalloc(BITS_TO_LONGS(sechdrs[strindex].sh_size)
2193 * sizeof(long), GFP_KERNEL);
2194 if (!strmap) {
2195 err = -ENOMEM;
2196 goto free_mod;
2197 }
2198
2160 if (find_module(mod->name)) { 2199 if (find_module(mod->name)) {
2161 err = -EEXIST; 2200 err = -EEXIST;
2162 goto free_mod; 2201 goto free_mod;
2163 } 2202 }
2164 2203
2165 mod->state = MODULE_STATE_COMING; 2204 mod->state = MODULE_STATE_COMING;
2166 2205
2167 /* Allow arches to frob section contents and sizes. */ 2206 /* Allow arches to frob section contents and sizes. */
2168 err = module_frob_arch_sections(hdr, sechdrs, secstrings, mod); 2207 err = module_frob_arch_sections(hdr, sechdrs, secstrings, mod);
2169 if (err < 0) 2208 if (err < 0)
2170 goto free_mod; 2209 goto free_mod;
2171 2210
2172 if (pcpuindex) { 2211 if (pcpuindex) {
2173 /* We have a special allocation for this section. */ 2212 /* We have a special allocation for this section. */
2174 percpu = percpu_modalloc(sechdrs[pcpuindex].sh_size, 2213 percpu = percpu_modalloc(sechdrs[pcpuindex].sh_size,
2175 sechdrs[pcpuindex].sh_addralign, 2214 sechdrs[pcpuindex].sh_addralign,
2176 mod->name); 2215 mod->name);
2177 if (!percpu) { 2216 if (!percpu) {
2178 err = -ENOMEM; 2217 err = -ENOMEM;
2179 goto free_mod; 2218 goto free_mod;
2180 } 2219 }
2181 sechdrs[pcpuindex].sh_flags &= ~(unsigned long)SHF_ALLOC; 2220 sechdrs[pcpuindex].sh_flags &= ~(unsigned long)SHF_ALLOC;
2182 mod->percpu = percpu; 2221 mod->percpu = percpu;
2183 } 2222 }
2184 2223
2185 /* Determine total sizes, and put offsets in sh_entsize. For now 2224 /* Determine total sizes, and put offsets in sh_entsize. For now
2186 this is done generically; there doesn't appear to be any 2225 this is done generically; there doesn't appear to be any
2187 special cases for the architectures. */ 2226 special cases for the architectures. */
2188 layout_sections(mod, hdr, sechdrs, secstrings); 2227 layout_sections(mod, hdr, sechdrs, secstrings);
2189 symoffs = layout_symtab(mod, sechdrs, symindex, hdr, secstrings); 2228 symoffs = layout_symtab(mod, sechdrs, symindex, strindex, hdr,
2229 secstrings, &stroffs, strmap);
2190 2230
2191 /* Do the allocs. */ 2231 /* Do the allocs. */
2192 ptr = module_alloc_update_bounds(mod->core_size); 2232 ptr = module_alloc_update_bounds(mod->core_size);
2193 /* 2233 /*
2194 * The pointer to this block is stored in the module structure 2234 * The pointer to this block is stored in the module structure
2195 * which is inside the block. Just mark it as not being a 2235 * which is inside the block. Just mark it as not being a
2196 * leak. 2236 * leak.
2197 */ 2237 */
2198 kmemleak_not_leak(ptr); 2238 kmemleak_not_leak(ptr);
2199 if (!ptr) { 2239 if (!ptr) {
2200 err = -ENOMEM; 2240 err = -ENOMEM;
2201 goto free_percpu; 2241 goto free_percpu;
2202 } 2242 }
2203 memset(ptr, 0, mod->core_size); 2243 memset(ptr, 0, mod->core_size);
2204 mod->module_core = ptr; 2244 mod->module_core = ptr;
2205 2245
2206 ptr = module_alloc_update_bounds(mod->init_size); 2246 ptr = module_alloc_update_bounds(mod->init_size);
2207 /* 2247 /*
2208 * The pointer to this block is stored in the module structure 2248 * The pointer to this block is stored in the module structure
2209 * which is inside the block. This block doesn't need to be 2249 * which is inside the block. This block doesn't need to be
2210 * scanned as it contains data and code that will be freed 2250 * scanned as it contains data and code that will be freed
2211 * after the module is initialized. 2251 * after the module is initialized.
2212 */ 2252 */
2213 kmemleak_ignore(ptr); 2253 kmemleak_ignore(ptr);
2214 if (!ptr && mod->init_size) { 2254 if (!ptr && mod->init_size) {
2215 err = -ENOMEM; 2255 err = -ENOMEM;
2216 goto free_core; 2256 goto free_core;
2217 } 2257 }
2218 memset(ptr, 0, mod->init_size); 2258 memset(ptr, 0, mod->init_size);
2219 mod->module_init = ptr; 2259 mod->module_init = ptr;
2220 2260
2221 /* Transfer each section which specifies SHF_ALLOC */ 2261 /* Transfer each section which specifies SHF_ALLOC */
2222 DEBUGP("final section addresses:\n"); 2262 DEBUGP("final section addresses:\n");
2223 for (i = 0; i < hdr->e_shnum; i++) { 2263 for (i = 0; i < hdr->e_shnum; i++) {
2224 void *dest; 2264 void *dest;
2225 2265
2226 if (!(sechdrs[i].sh_flags & SHF_ALLOC)) 2266 if (!(sechdrs[i].sh_flags & SHF_ALLOC))
2227 continue; 2267 continue;
2228 2268
2229 if (sechdrs[i].sh_entsize & INIT_OFFSET_MASK) 2269 if (sechdrs[i].sh_entsize & INIT_OFFSET_MASK)
2230 dest = mod->module_init 2270 dest = mod->module_init
2231 + (sechdrs[i].sh_entsize & ~INIT_OFFSET_MASK); 2271 + (sechdrs[i].sh_entsize & ~INIT_OFFSET_MASK);
2232 else 2272 else
2233 dest = mod->module_core + sechdrs[i].sh_entsize; 2273 dest = mod->module_core + sechdrs[i].sh_entsize;
2234 2274
2235 if (sechdrs[i].sh_type != SHT_NOBITS) 2275 if (sechdrs[i].sh_type != SHT_NOBITS)
2236 memcpy(dest, (void *)sechdrs[i].sh_addr, 2276 memcpy(dest, (void *)sechdrs[i].sh_addr,
2237 sechdrs[i].sh_size); 2277 sechdrs[i].sh_size);
2238 /* Update sh_addr to point to copy in image. */ 2278 /* Update sh_addr to point to copy in image. */
2239 sechdrs[i].sh_addr = (unsigned long)dest; 2279 sechdrs[i].sh_addr = (unsigned long)dest;
2240 DEBUGP("\t0x%lx %s\n", sechdrs[i].sh_addr, secstrings + sechdrs[i].sh_name); 2280 DEBUGP("\t0x%lx %s\n", sechdrs[i].sh_addr, secstrings + sechdrs[i].sh_name);
2241 } 2281 }
2242 /* Module has been moved. */ 2282 /* Module has been moved. */
2243 mod = (void *)sechdrs[modindex].sh_addr; 2283 mod = (void *)sechdrs[modindex].sh_addr;
2244 kmemleak_load_module(mod, hdr, sechdrs, secstrings); 2284 kmemleak_load_module(mod, hdr, sechdrs, secstrings);
2245 2285
2246 #if defined(CONFIG_MODULE_UNLOAD) && defined(CONFIG_SMP) 2286 #if defined(CONFIG_MODULE_UNLOAD) && defined(CONFIG_SMP)
2247 mod->refptr = percpu_modalloc(sizeof(local_t), __alignof__(local_t), 2287 mod->refptr = percpu_modalloc(sizeof(local_t), __alignof__(local_t),
2248 mod->name); 2288 mod->name);
2249 if (!mod->refptr) { 2289 if (!mod->refptr) {
2250 err = -ENOMEM; 2290 err = -ENOMEM;
2251 goto free_init; 2291 goto free_init;
2252 } 2292 }
2253 #endif 2293 #endif
2254 /* Now we've moved module, initialize linked lists, etc. */ 2294 /* Now we've moved module, initialize linked lists, etc. */
2255 module_unload_init(mod); 2295 module_unload_init(mod);
2256 2296
2257 /* add kobject, so we can reference it. */ 2297 /* add kobject, so we can reference it. */
2258 err = mod_sysfs_init(mod); 2298 err = mod_sysfs_init(mod);
2259 if (err) 2299 if (err)
2260 goto free_unload; 2300 goto free_unload;
2261 2301
2262 /* Set up license info based on the info section */ 2302 /* Set up license info based on the info section */
2263 set_license(mod, get_modinfo(sechdrs, infoindex, "license")); 2303 set_license(mod, get_modinfo(sechdrs, infoindex, "license"));
2264 2304
2265 /* 2305 /*
2266 * ndiswrapper is under GPL by itself, but loads proprietary modules. 2306 * ndiswrapper is under GPL by itself, but loads proprietary modules.
2267 * Don't use add_taint_module(), as it would prevent ndiswrapper from 2307 * Don't use add_taint_module(), as it would prevent ndiswrapper from
2268 * using GPL-only symbols it needs. 2308 * using GPL-only symbols it needs.
2269 */ 2309 */
2270 if (strcmp(mod->name, "ndiswrapper") == 0) 2310 if (strcmp(mod->name, "ndiswrapper") == 0)
2271 add_taint(TAINT_PROPRIETARY_MODULE); 2311 add_taint(TAINT_PROPRIETARY_MODULE);
2272 2312
2273 /* driverloader was caught wrongly pretending to be under GPL */ 2313 /* driverloader was caught wrongly pretending to be under GPL */
2274 if (strcmp(mod->name, "driverloader") == 0) 2314 if (strcmp(mod->name, "driverloader") == 0)
2275 add_taint_module(mod, TAINT_PROPRIETARY_MODULE); 2315 add_taint_module(mod, TAINT_PROPRIETARY_MODULE);
2276 2316
2277 /* Set up MODINFO_ATTR fields */ 2317 /* Set up MODINFO_ATTR fields */
2278 setup_modinfo(mod, sechdrs, infoindex); 2318 setup_modinfo(mod, sechdrs, infoindex);
2279 2319
2280 /* Fix up syms, so that st_value is a pointer to location. */ 2320 /* Fix up syms, so that st_value is a pointer to location. */
2281 err = simplify_symbols(sechdrs, symindex, strtab, versindex, pcpuindex, 2321 err = simplify_symbols(sechdrs, symindex, strtab, versindex, pcpuindex,
2282 mod); 2322 mod);
2283 if (err < 0) 2323 if (err < 0)
2284 goto cleanup; 2324 goto cleanup;
2285 2325
2286 /* Now we've got everything in the final locations, we can 2326 /* Now we've got everything in the final locations, we can
2287 * find optional sections. */ 2327 * find optional sections. */
2288 mod->kp = section_objs(hdr, sechdrs, secstrings, "__param", 2328 mod->kp = section_objs(hdr, sechdrs, secstrings, "__param",
2289 sizeof(*mod->kp), &mod->num_kp); 2329 sizeof(*mod->kp), &mod->num_kp);
2290 mod->syms = section_objs(hdr, sechdrs, secstrings, "__ksymtab", 2330 mod->syms = section_objs(hdr, sechdrs, secstrings, "__ksymtab",
2291 sizeof(*mod->syms), &mod->num_syms); 2331 sizeof(*mod->syms), &mod->num_syms);
2292 mod->crcs = section_addr(hdr, sechdrs, secstrings, "__kcrctab"); 2332 mod->crcs = section_addr(hdr, sechdrs, secstrings, "__kcrctab");
2293 mod->gpl_syms = section_objs(hdr, sechdrs, secstrings, "__ksymtab_gpl", 2333 mod->gpl_syms = section_objs(hdr, sechdrs, secstrings, "__ksymtab_gpl",
2294 sizeof(*mod->gpl_syms), 2334 sizeof(*mod->gpl_syms),
2295 &mod->num_gpl_syms); 2335 &mod->num_gpl_syms);
2296 mod->gpl_crcs = section_addr(hdr, sechdrs, secstrings, "__kcrctab_gpl"); 2336 mod->gpl_crcs = section_addr(hdr, sechdrs, secstrings, "__kcrctab_gpl");
2297 mod->gpl_future_syms = section_objs(hdr, sechdrs, secstrings, 2337 mod->gpl_future_syms = section_objs(hdr, sechdrs, secstrings,
2298 "__ksymtab_gpl_future", 2338 "__ksymtab_gpl_future",
2299 sizeof(*mod->gpl_future_syms), 2339 sizeof(*mod->gpl_future_syms),
2300 &mod->num_gpl_future_syms); 2340 &mod->num_gpl_future_syms);
2301 mod->gpl_future_crcs = section_addr(hdr, sechdrs, secstrings, 2341 mod->gpl_future_crcs = section_addr(hdr, sechdrs, secstrings,
2302 "__kcrctab_gpl_future"); 2342 "__kcrctab_gpl_future");
2303 2343
2304 #ifdef CONFIG_UNUSED_SYMBOLS 2344 #ifdef CONFIG_UNUSED_SYMBOLS
2305 mod->unused_syms = section_objs(hdr, sechdrs, secstrings, 2345 mod->unused_syms = section_objs(hdr, sechdrs, secstrings,
2306 "__ksymtab_unused", 2346 "__ksymtab_unused",
2307 sizeof(*mod->unused_syms), 2347 sizeof(*mod->unused_syms),
2308 &mod->num_unused_syms); 2348 &mod->num_unused_syms);
2309 mod->unused_crcs = section_addr(hdr, sechdrs, secstrings, 2349 mod->unused_crcs = section_addr(hdr, sechdrs, secstrings,
2310 "__kcrctab_unused"); 2350 "__kcrctab_unused");
2311 mod->unused_gpl_syms = section_objs(hdr, sechdrs, secstrings, 2351 mod->unused_gpl_syms = section_objs(hdr, sechdrs, secstrings,
2312 "__ksymtab_unused_gpl", 2352 "__ksymtab_unused_gpl",
2313 sizeof(*mod->unused_gpl_syms), 2353 sizeof(*mod->unused_gpl_syms),
2314 &mod->num_unused_gpl_syms); 2354 &mod->num_unused_gpl_syms);
2315 mod->unused_gpl_crcs = section_addr(hdr, sechdrs, secstrings, 2355 mod->unused_gpl_crcs = section_addr(hdr, sechdrs, secstrings,
2316 "__kcrctab_unused_gpl"); 2356 "__kcrctab_unused_gpl");
2317 #endif 2357 #endif
2318 #ifdef CONFIG_CONSTRUCTORS 2358 #ifdef CONFIG_CONSTRUCTORS
2319 mod->ctors = section_objs(hdr, sechdrs, secstrings, ".ctors", 2359 mod->ctors = section_objs(hdr, sechdrs, secstrings, ".ctors",
2320 sizeof(*mod->ctors), &mod->num_ctors); 2360 sizeof(*mod->ctors), &mod->num_ctors);
2321 #endif 2361 #endif
2322 2362
2323 #ifdef CONFIG_TRACEPOINTS 2363 #ifdef CONFIG_TRACEPOINTS
2324 mod->tracepoints = section_objs(hdr, sechdrs, secstrings, 2364 mod->tracepoints = section_objs(hdr, sechdrs, secstrings,
2325 "__tracepoints", 2365 "__tracepoints",
2326 sizeof(*mod->tracepoints), 2366 sizeof(*mod->tracepoints),
2327 &mod->num_tracepoints); 2367 &mod->num_tracepoints);
2328 #endif 2368 #endif
2329 #ifdef CONFIG_EVENT_TRACING 2369 #ifdef CONFIG_EVENT_TRACING
2330 mod->trace_events = section_objs(hdr, sechdrs, secstrings, 2370 mod->trace_events = section_objs(hdr, sechdrs, secstrings,
2331 "_ftrace_events", 2371 "_ftrace_events",
2332 sizeof(*mod->trace_events), 2372 sizeof(*mod->trace_events),
2333 &mod->num_trace_events); 2373 &mod->num_trace_events);
2334 #endif 2374 #endif
2335 #ifdef CONFIG_FTRACE_MCOUNT_RECORD 2375 #ifdef CONFIG_FTRACE_MCOUNT_RECORD
2336 /* sechdrs[0].sh_size is always zero */ 2376 /* sechdrs[0].sh_size is always zero */
2337 mod->ftrace_callsites = section_objs(hdr, sechdrs, secstrings, 2377 mod->ftrace_callsites = section_objs(hdr, sechdrs, secstrings,
2338 "__mcount_loc", 2378 "__mcount_loc",
2339 sizeof(*mod->ftrace_callsites), 2379 sizeof(*mod->ftrace_callsites),
2340 &mod->num_ftrace_callsites); 2380 &mod->num_ftrace_callsites);
2341 #endif 2381 #endif
2342 #ifdef CONFIG_MODVERSIONS 2382 #ifdef CONFIG_MODVERSIONS
2343 if ((mod->num_syms && !mod->crcs) 2383 if ((mod->num_syms && !mod->crcs)
2344 || (mod->num_gpl_syms && !mod->gpl_crcs) 2384 || (mod->num_gpl_syms && !mod->gpl_crcs)
2345 || (mod->num_gpl_future_syms && !mod->gpl_future_crcs) 2385 || (mod->num_gpl_future_syms && !mod->gpl_future_crcs)
2346 #ifdef CONFIG_UNUSED_SYMBOLS 2386 #ifdef CONFIG_UNUSED_SYMBOLS
2347 || (mod->num_unused_syms && !mod->unused_crcs) 2387 || (mod->num_unused_syms && !mod->unused_crcs)
2348 || (mod->num_unused_gpl_syms && !mod->unused_gpl_crcs) 2388 || (mod->num_unused_gpl_syms && !mod->unused_gpl_crcs)
2349 #endif 2389 #endif
2350 ) { 2390 ) {
2351 err = try_to_force_load(mod, 2391 err = try_to_force_load(mod,
2352 "no versions for exported symbols"); 2392 "no versions for exported symbols");
2353 if (err) 2393 if (err)
2354 goto cleanup; 2394 goto cleanup;
2355 } 2395 }
2356 #endif 2396 #endif
2357 2397
2358 /* Now do relocations. */ 2398 /* Now do relocations. */
2359 for (i = 1; i < hdr->e_shnum; i++) { 2399 for (i = 1; i < hdr->e_shnum; i++) {
2360 const char *strtab = (char *)sechdrs[strindex].sh_addr; 2400 const char *strtab = (char *)sechdrs[strindex].sh_addr;
2361 unsigned int info = sechdrs[i].sh_info; 2401 unsigned int info = sechdrs[i].sh_info;
2362 2402
2363 /* Not a valid relocation section? */ 2403 /* Not a valid relocation section? */
2364 if (info >= hdr->e_shnum) 2404 if (info >= hdr->e_shnum)
2365 continue; 2405 continue;
2366 2406
2367 /* Don't bother with non-allocated sections */ 2407 /* Don't bother with non-allocated sections */
2368 if (!(sechdrs[info].sh_flags & SHF_ALLOC)) 2408 if (!(sechdrs[info].sh_flags & SHF_ALLOC))
2369 continue; 2409 continue;
2370 2410
2371 if (sechdrs[i].sh_type == SHT_REL) 2411 if (sechdrs[i].sh_type == SHT_REL)
2372 err = apply_relocate(sechdrs, strtab, symindex, i,mod); 2412 err = apply_relocate(sechdrs, strtab, symindex, i,mod);
2373 else if (sechdrs[i].sh_type == SHT_RELA) 2413 else if (sechdrs[i].sh_type == SHT_RELA)
2374 err = apply_relocate_add(sechdrs, strtab, symindex, i, 2414 err = apply_relocate_add(sechdrs, strtab, symindex, i,
2375 mod); 2415 mod);
2376 if (err < 0) 2416 if (err < 0)
2377 goto cleanup; 2417 goto cleanup;
2378 } 2418 }
2379 2419
2380 /* Find duplicate symbols */ 2420 /* Find duplicate symbols */
2381 err = verify_export_symbols(mod); 2421 err = verify_export_symbols(mod);
2382 if (err < 0) 2422 if (err < 0)
2383 goto cleanup; 2423 goto cleanup;
2384 2424
2385 /* Set up and sort exception table */ 2425 /* Set up and sort exception table */
2386 mod->extable = section_objs(hdr, sechdrs, secstrings, "__ex_table", 2426 mod->extable = section_objs(hdr, sechdrs, secstrings, "__ex_table",
2387 sizeof(*mod->extable), &mod->num_exentries); 2427 sizeof(*mod->extable), &mod->num_exentries);
2388 sort_extable(mod->extable, mod->extable + mod->num_exentries); 2428 sort_extable(mod->extable, mod->extable + mod->num_exentries);
2389 2429
2390 /* Finally, copy percpu area over. */ 2430 /* Finally, copy percpu area over. */
2391 percpu_modcopy(mod->percpu, (void *)sechdrs[pcpuindex].sh_addr, 2431 percpu_modcopy(mod->percpu, (void *)sechdrs[pcpuindex].sh_addr,
2392 sechdrs[pcpuindex].sh_size); 2432 sechdrs[pcpuindex].sh_size);
2393 2433
2394 add_kallsyms(mod, sechdrs, hdr->e_shnum, symindex, strindex, 2434 add_kallsyms(mod, sechdrs, hdr->e_shnum, symindex, strindex,
2395 symoffs, secstrings); 2435 symoffs, stroffs, secstrings, strmap);
2436 kfree(strmap);
2437 strmap = NULL;
2396 2438
2397 if (!mod->taints) { 2439 if (!mod->taints) {
2398 struct _ddebug *debug; 2440 struct _ddebug *debug;
2399 unsigned int num_debug; 2441 unsigned int num_debug;
2400 2442
2401 debug = section_objs(hdr, sechdrs, secstrings, "__verbose", 2443 debug = section_objs(hdr, sechdrs, secstrings, "__verbose",
2402 sizeof(*debug), &num_debug); 2444 sizeof(*debug), &num_debug);
2403 if (debug) 2445 if (debug)
2404 dynamic_debug_setup(debug, num_debug); 2446 dynamic_debug_setup(debug, num_debug);
2405 } 2447 }
2406 2448
2407 err = module_finalize(hdr, sechdrs, mod); 2449 err = module_finalize(hdr, sechdrs, mod);
2408 if (err < 0) 2450 if (err < 0)
2409 goto cleanup; 2451 goto cleanup;
2410 2452
2411 /* flush the icache in correct context */ 2453 /* flush the icache in correct context */
2412 old_fs = get_fs(); 2454 old_fs = get_fs();
2413 set_fs(KERNEL_DS); 2455 set_fs(KERNEL_DS);
2414 2456
2415 /* 2457 /*
2416 * Flush the instruction cache, since we've played with text. 2458 * Flush the instruction cache, since we've played with text.
2417 * Do it before processing of module parameters, so the module 2459 * Do it before processing of module parameters, so the module
2418 * can provide parameter accessor functions of its own. 2460 * can provide parameter accessor functions of its own.
2419 */ 2461 */
2420 if (mod->module_init) 2462 if (mod->module_init)
2421 flush_icache_range((unsigned long)mod->module_init, 2463 flush_icache_range((unsigned long)mod->module_init,
2422 (unsigned long)mod->module_init 2464 (unsigned long)mod->module_init
2423 + mod->init_size); 2465 + mod->init_size);
2424 flush_icache_range((unsigned long)mod->module_core, 2466 flush_icache_range((unsigned long)mod->module_core,
2425 (unsigned long)mod->module_core + mod->core_size); 2467 (unsigned long)mod->module_core + mod->core_size);
2426 2468
2427 set_fs(old_fs); 2469 set_fs(old_fs);
2428 2470
2429 mod->args = args; 2471 mod->args = args;
2430 if (section_addr(hdr, sechdrs, secstrings, "__obsparm")) 2472 if (section_addr(hdr, sechdrs, secstrings, "__obsparm"))
2431 printk(KERN_WARNING "%s: Ignoring obsolete parameters\n", 2473 printk(KERN_WARNING "%s: Ignoring obsolete parameters\n",
2432 mod->name); 2474 mod->name);
2433 2475
2434 /* Now sew it into the lists so we can get lockdep and oops 2476 /* Now sew it into the lists so we can get lockdep and oops
2435 * info during argument parsing. Noone should access us, since 2477 * info during argument parsing. Noone should access us, since
2436 * strong_try_module_get() will fail. 2478 * strong_try_module_get() will fail.
2437 * lockdep/oops can run asynchronous, so use the RCU list insertion 2479 * lockdep/oops can run asynchronous, so use the RCU list insertion
2438 * function to insert in a way safe to concurrent readers. 2480 * function to insert in a way safe to concurrent readers.
2439 * The mutex protects against concurrent writers. 2481 * The mutex protects against concurrent writers.
2440 */ 2482 */
2441 list_add_rcu(&mod->list, &modules); 2483 list_add_rcu(&mod->list, &modules);
2442 2484
2443 err = parse_args(mod->name, mod->args, mod->kp, mod->num_kp, NULL); 2485 err = parse_args(mod->name, mod->args, mod->kp, mod->num_kp, NULL);
2444 if (err < 0) 2486 if (err < 0)
2445 goto unlink; 2487 goto unlink;
2446 2488
2447 err = mod_sysfs_setup(mod, mod->kp, mod->num_kp); 2489 err = mod_sysfs_setup(mod, mod->kp, mod->num_kp);
2448 if (err < 0) 2490 if (err < 0)
2449 goto unlink; 2491 goto unlink;
2450 add_sect_attrs(mod, hdr->e_shnum, secstrings, sechdrs); 2492 add_sect_attrs(mod, hdr->e_shnum, secstrings, sechdrs);
2451 add_notes_attrs(mod, hdr->e_shnum, secstrings, sechdrs); 2493 add_notes_attrs(mod, hdr->e_shnum, secstrings, sechdrs);
2452 2494
2453 /* Get rid of temporary copy */ 2495 /* Get rid of temporary copy */
2454 vfree(hdr); 2496 vfree(hdr);
2455 2497
2456 trace_module_load(mod); 2498 trace_module_load(mod);
2457 2499
2458 /* Done! */ 2500 /* Done! */
2459 return mod; 2501 return mod;
2460 2502
2461 unlink: 2503 unlink:
2462 /* Unlink carefully: kallsyms could be walking list. */ 2504 /* Unlink carefully: kallsyms could be walking list. */
2463 list_del_rcu(&mod->list); 2505 list_del_rcu(&mod->list);
2464 synchronize_sched(); 2506 synchronize_sched();
2465 module_arch_cleanup(mod); 2507 module_arch_cleanup(mod);
2466 cleanup: 2508 cleanup:
2467 kobject_del(&mod->mkobj.kobj); 2509 kobject_del(&mod->mkobj.kobj);
2468 kobject_put(&mod->mkobj.kobj); 2510 kobject_put(&mod->mkobj.kobj);
2469 free_unload: 2511 free_unload:
2470 module_unload_free(mod); 2512 module_unload_free(mod);
2471 #if defined(CONFIG_MODULE_UNLOAD) && defined(CONFIG_SMP) 2513 #if defined(CONFIG_MODULE_UNLOAD) && defined(CONFIG_SMP)
2472 free_init: 2514 free_init:
2473 percpu_modfree(mod->refptr); 2515 percpu_modfree(mod->refptr);
2474 #endif 2516 #endif
2475 module_free(mod, mod->module_init); 2517 module_free(mod, mod->module_init);
2476 free_core: 2518 free_core:
2477 module_free(mod, mod->module_core); 2519 module_free(mod, mod->module_core);
2478 /* mod will be freed with core. Don't access it beyond this line! */ 2520 /* mod will be freed with core. Don't access it beyond this line! */
2479 free_percpu: 2521 free_percpu:
2480 if (percpu) 2522 if (percpu)
2481 percpu_modfree(percpu); 2523 percpu_modfree(percpu);
2482 free_mod: 2524 free_mod:
2483 kfree(args); 2525 kfree(args);
2526 kfree(strmap);
2484 free_hdr: 2527 free_hdr:
2485 vfree(hdr); 2528 vfree(hdr);
2486 return ERR_PTR(err); 2529 return ERR_PTR(err);
2487 2530
2488 truncated: 2531 truncated:
2489 printk(KERN_ERR "Module len %lu truncated\n", len); 2532 printk(KERN_ERR "Module len %lu truncated\n", len);
2490 err = -ENOEXEC; 2533 err = -ENOEXEC;
2491 goto free_hdr; 2534 goto free_hdr;
2492 } 2535 }
2493 2536
2494 /* Call module constructors. */ 2537 /* Call module constructors. */
2495 static void do_mod_ctors(struct module *mod) 2538 static void do_mod_ctors(struct module *mod)
2496 { 2539 {
2497 #ifdef CONFIG_CONSTRUCTORS 2540 #ifdef CONFIG_CONSTRUCTORS
2498 unsigned long i; 2541 unsigned long i;
2499 2542
2500 for (i = 0; i < mod->num_ctors; i++) 2543 for (i = 0; i < mod->num_ctors; i++)
2501 mod->ctors[i](); 2544 mod->ctors[i]();
2502 #endif 2545 #endif
2503 } 2546 }
2504 2547
2505 /* This is where the real work happens */ 2548 /* This is where the real work happens */
2506 SYSCALL_DEFINE3(init_module, void __user *, umod, 2549 SYSCALL_DEFINE3(init_module, void __user *, umod,
2507 unsigned long, len, const char __user *, uargs) 2550 unsigned long, len, const char __user *, uargs)
2508 { 2551 {
2509 struct module *mod; 2552 struct module *mod;
2510 int ret = 0; 2553 int ret = 0;
2511 2554
2512 /* Must have permission */ 2555 /* Must have permission */
2513 if (!capable(CAP_SYS_MODULE) || modules_disabled) 2556 if (!capable(CAP_SYS_MODULE) || modules_disabled)
2514 return -EPERM; 2557 return -EPERM;
2515 2558
2516 /* Only one module load at a time, please */ 2559 /* Only one module load at a time, please */
2517 if (mutex_lock_interruptible(&module_mutex) != 0) 2560 if (mutex_lock_interruptible(&module_mutex) != 0)
2518 return -EINTR; 2561 return -EINTR;
2519 2562
2520 /* Do all the hard work */ 2563 /* Do all the hard work */
2521 mod = load_module(umod, len, uargs); 2564 mod = load_module(umod, len, uargs);
2522 if (IS_ERR(mod)) { 2565 if (IS_ERR(mod)) {
2523 mutex_unlock(&module_mutex); 2566 mutex_unlock(&module_mutex);
2524 return PTR_ERR(mod); 2567 return PTR_ERR(mod);
2525 } 2568 }
2526 2569
2527 /* Drop lock so they can recurse */ 2570 /* Drop lock so they can recurse */
2528 mutex_unlock(&module_mutex); 2571 mutex_unlock(&module_mutex);
2529 2572
2530 blocking_notifier_call_chain(&module_notify_list, 2573 blocking_notifier_call_chain(&module_notify_list,
2531 MODULE_STATE_COMING, mod); 2574 MODULE_STATE_COMING, mod);
2532 2575
2533 do_mod_ctors(mod); 2576 do_mod_ctors(mod);
2534 /* Start the module */ 2577 /* Start the module */
2535 if (mod->init != NULL) 2578 if (mod->init != NULL)
2536 ret = do_one_initcall(mod->init); 2579 ret = do_one_initcall(mod->init);
2537 if (ret < 0) { 2580 if (ret < 0) {
2538 /* Init routine failed: abort. Try to protect us from 2581 /* Init routine failed: abort. Try to protect us from
2539 buggy refcounters. */ 2582 buggy refcounters. */
2540 mod->state = MODULE_STATE_GOING; 2583 mod->state = MODULE_STATE_GOING;
2541 synchronize_sched(); 2584 synchronize_sched();
2542 module_put(mod); 2585 module_put(mod);
2543 blocking_notifier_call_chain(&module_notify_list, 2586 blocking_notifier_call_chain(&module_notify_list,
2544 MODULE_STATE_GOING, mod); 2587 MODULE_STATE_GOING, mod);
2545 mutex_lock(&module_mutex); 2588 mutex_lock(&module_mutex);
2546 free_module(mod); 2589 free_module(mod);
2547 mutex_unlock(&module_mutex); 2590 mutex_unlock(&module_mutex);
2548 wake_up(&module_wq); 2591 wake_up(&module_wq);
2549 return ret; 2592 return ret;
2550 } 2593 }
2551 if (ret > 0) { 2594 if (ret > 0) {
2552 printk(KERN_WARNING 2595 printk(KERN_WARNING
2553 "%s: '%s'->init suspiciously returned %d, it should follow 0/-E convention\n" 2596 "%s: '%s'->init suspiciously returned %d, it should follow 0/-E convention\n"
2554 "%s: loading module anyway...\n", 2597 "%s: loading module anyway...\n",
2555 __func__, mod->name, ret, 2598 __func__, mod->name, ret,
2556 __func__); 2599 __func__);
2557 dump_stack(); 2600 dump_stack();
2558 } 2601 }
2559 2602
2560 /* Now it's a first class citizen! Wake up anyone waiting for it. */ 2603 /* Now it's a first class citizen! Wake up anyone waiting for it. */
2561 mod->state = MODULE_STATE_LIVE; 2604 mod->state = MODULE_STATE_LIVE;
2562 wake_up(&module_wq); 2605 wake_up(&module_wq);
2563 blocking_notifier_call_chain(&module_notify_list, 2606 blocking_notifier_call_chain(&module_notify_list,
2564 MODULE_STATE_LIVE, mod); 2607 MODULE_STATE_LIVE, mod);
2565 2608
2566 /* We need to finish all async code before the module init sequence is done */ 2609 /* We need to finish all async code before the module init sequence is done */
2567 async_synchronize_full(); 2610 async_synchronize_full();
2568 2611
2569 mutex_lock(&module_mutex); 2612 mutex_lock(&module_mutex);
2570 /* Drop initial reference. */ 2613 /* Drop initial reference. */
2571 module_put(mod); 2614 module_put(mod);
2572 trim_init_extable(mod); 2615 trim_init_extable(mod);
2573 #ifdef CONFIG_KALLSYMS 2616 #ifdef CONFIG_KALLSYMS
2574 mod->num_symtab = mod->core_num_syms; 2617 mod->num_symtab = mod->core_num_syms;
2575 mod->symtab = mod->core_symtab; 2618 mod->symtab = mod->core_symtab;
2619 mod->strtab = mod->core_strtab;
2576 #endif 2620 #endif
2577 module_free(mod, mod->module_init); 2621 module_free(mod, mod->module_init);
2578 mod->module_init = NULL; 2622 mod->module_init = NULL;
2579 mod->init_size = 0; 2623 mod->init_size = 0;
2580 mod->init_text_size = 0; 2624 mod->init_text_size = 0;
2581 mutex_unlock(&module_mutex); 2625 mutex_unlock(&module_mutex);
2582 2626
2583 return 0; 2627 return 0;
2584 } 2628 }
2585 2629
2586 static inline int within(unsigned long addr, void *start, unsigned long size) 2630 static inline int within(unsigned long addr, void *start, unsigned long size)
2587 { 2631 {
2588 return ((void *)addr >= start && (void *)addr < start + size); 2632 return ((void *)addr >= start && (void *)addr < start + size);
2589 } 2633 }
2590 2634
2591 #ifdef CONFIG_KALLSYMS 2635 #ifdef CONFIG_KALLSYMS
2592 /* 2636 /*
2593 * This ignores the intensely annoying "mapping symbols" found 2637 * This ignores the intensely annoying "mapping symbols" found
2594 * in ARM ELF files: $a, $t and $d. 2638 * in ARM ELF files: $a, $t and $d.
2595 */ 2639 */
2596 static inline int is_arm_mapping_symbol(const char *str) 2640 static inline int is_arm_mapping_symbol(const char *str)
2597 { 2641 {
2598 return str[0] == '$' && strchr("atd", str[1]) 2642 return str[0] == '$' && strchr("atd", str[1])
2599 && (str[2] == '\0' || str[2] == '.'); 2643 && (str[2] == '\0' || str[2] == '.');
2600 } 2644 }
2601 2645
2602 static const char *get_ksymbol(struct module *mod, 2646 static const char *get_ksymbol(struct module *mod,
2603 unsigned long addr, 2647 unsigned long addr,
2604 unsigned long *size, 2648 unsigned long *size,
2605 unsigned long *offset) 2649 unsigned long *offset)
2606 { 2650 {
2607 unsigned int i, best = 0; 2651 unsigned int i, best = 0;
2608 unsigned long nextval; 2652 unsigned long nextval;
2609 2653
2610 /* At worse, next value is at end of module */ 2654 /* At worse, next value is at end of module */
2611 if (within_module_init(addr, mod)) 2655 if (within_module_init(addr, mod))
2612 nextval = (unsigned long)mod->module_init+mod->init_text_size; 2656 nextval = (unsigned long)mod->module_init+mod->init_text_size;
2613 else 2657 else
2614 nextval = (unsigned long)mod->module_core+mod->core_text_size; 2658 nextval = (unsigned long)mod->module_core+mod->core_text_size;
2615 2659
2616 /* Scan for closest preceeding symbol, and next symbol. (ELF 2660 /* Scan for closest preceeding symbol, and next symbol. (ELF
2617 starts real symbols at 1). */ 2661 starts real symbols at 1). */
2618 for (i = 1; i < mod->num_symtab; i++) { 2662 for (i = 1; i < mod->num_symtab; i++) {
2619 if (mod->symtab[i].st_shndx == SHN_UNDEF) 2663 if (mod->symtab[i].st_shndx == SHN_UNDEF)
2620 continue; 2664 continue;
2621 2665
2622 /* We ignore unnamed symbols: they're uninformative 2666 /* We ignore unnamed symbols: they're uninformative
2623 * and inserted at a whim. */ 2667 * and inserted at a whim. */
2624 if (mod->symtab[i].st_value <= addr 2668 if (mod->symtab[i].st_value <= addr
2625 && mod->symtab[i].st_value > mod->symtab[best].st_value 2669 && mod->symtab[i].st_value > mod->symtab[best].st_value
2626 && *(mod->strtab + mod->symtab[i].st_name) != '\0' 2670 && *(mod->strtab + mod->symtab[i].st_name) != '\0'
2627 && !is_arm_mapping_symbol(mod->strtab + mod->symtab[i].st_name)) 2671 && !is_arm_mapping_symbol(mod->strtab + mod->symtab[i].st_name))
2628 best = i; 2672 best = i;
2629 if (mod->symtab[i].st_value > addr 2673 if (mod->symtab[i].st_value > addr
2630 && mod->symtab[i].st_value < nextval 2674 && mod->symtab[i].st_value < nextval
2631 && *(mod->strtab + mod->symtab[i].st_name) != '\0' 2675 && *(mod->strtab + mod->symtab[i].st_name) != '\0'
2632 && !is_arm_mapping_symbol(mod->strtab + mod->symtab[i].st_name)) 2676 && !is_arm_mapping_symbol(mod->strtab + mod->symtab[i].st_name))
2633 nextval = mod->symtab[i].st_value; 2677 nextval = mod->symtab[i].st_value;
2634 } 2678 }
2635 2679
2636 if (!best) 2680 if (!best)
2637 return NULL; 2681 return NULL;
2638 2682
2639 if (size) 2683 if (size)
2640 *size = nextval - mod->symtab[best].st_value; 2684 *size = nextval - mod->symtab[best].st_value;
2641 if (offset) 2685 if (offset)
2642 *offset = addr - mod->symtab[best].st_value; 2686 *offset = addr - mod->symtab[best].st_value;
2643 return mod->strtab + mod->symtab[best].st_name; 2687 return mod->strtab + mod->symtab[best].st_name;
2644 } 2688 }
2645 2689
2646 /* For kallsyms to ask for address resolution. NULL means not found. Careful 2690 /* For kallsyms to ask for address resolution. NULL means not found. Careful
2647 * not to lock to avoid deadlock on oopses, simply disable preemption. */ 2691 * not to lock to avoid deadlock on oopses, simply disable preemption. */
2648 const char *module_address_lookup(unsigned long addr, 2692 const char *module_address_lookup(unsigned long addr,
2649 unsigned long *size, 2693 unsigned long *size,
2650 unsigned long *offset, 2694 unsigned long *offset,
2651 char **modname, 2695 char **modname,
2652 char *namebuf) 2696 char *namebuf)
2653 { 2697 {
2654 struct module *mod; 2698 struct module *mod;
2655 const char *ret = NULL; 2699 const char *ret = NULL;
2656 2700
2657 preempt_disable(); 2701 preempt_disable();
2658 list_for_each_entry_rcu(mod, &modules, list) { 2702 list_for_each_entry_rcu(mod, &modules, list) {
2659 if (within_module_init(addr, mod) || 2703 if (within_module_init(addr, mod) ||
2660 within_module_core(addr, mod)) { 2704 within_module_core(addr, mod)) {
2661 if (modname) 2705 if (modname)
2662 *modname = mod->name; 2706 *modname = mod->name;
2663 ret = get_ksymbol(mod, addr, size, offset); 2707 ret = get_ksymbol(mod, addr, size, offset);
2664 break; 2708 break;
2665 } 2709 }
2666 } 2710 }
2667 /* Make a copy in here where it's safe */ 2711 /* Make a copy in here where it's safe */
2668 if (ret) { 2712 if (ret) {
2669 strncpy(namebuf, ret, KSYM_NAME_LEN - 1); 2713 strncpy(namebuf, ret, KSYM_NAME_LEN - 1);
2670 ret = namebuf; 2714 ret = namebuf;
2671 } 2715 }
2672 preempt_enable(); 2716 preempt_enable();
2673 return ret; 2717 return ret;
2674 } 2718 }
2675 2719
2676 int lookup_module_symbol_name(unsigned long addr, char *symname) 2720 int lookup_module_symbol_name(unsigned long addr, char *symname)
2677 { 2721 {
2678 struct module *mod; 2722 struct module *mod;
2679 2723
2680 preempt_disable(); 2724 preempt_disable();
2681 list_for_each_entry_rcu(mod, &modules, list) { 2725 list_for_each_entry_rcu(mod, &modules, list) {
2682 if (within_module_init(addr, mod) || 2726 if (within_module_init(addr, mod) ||
2683 within_module_core(addr, mod)) { 2727 within_module_core(addr, mod)) {
2684 const char *sym; 2728 const char *sym;
2685 2729
2686 sym = get_ksymbol(mod, addr, NULL, NULL); 2730 sym = get_ksymbol(mod, addr, NULL, NULL);
2687 if (!sym) 2731 if (!sym)
2688 goto out; 2732 goto out;
2689 strlcpy(symname, sym, KSYM_NAME_LEN); 2733 strlcpy(symname, sym, KSYM_NAME_LEN);
2690 preempt_enable(); 2734 preempt_enable();
2691 return 0; 2735 return 0;
2692 } 2736 }
2693 } 2737 }
2694 out: 2738 out:
2695 preempt_enable(); 2739 preempt_enable();
2696 return -ERANGE; 2740 return -ERANGE;
2697 } 2741 }
2698 2742
2699 int lookup_module_symbol_attrs(unsigned long addr, unsigned long *size, 2743 int lookup_module_symbol_attrs(unsigned long addr, unsigned long *size,
2700 unsigned long *offset, char *modname, char *name) 2744 unsigned long *offset, char *modname, char *name)
2701 { 2745 {
2702 struct module *mod; 2746 struct module *mod;
2703 2747
2704 preempt_disable(); 2748 preempt_disable();
2705 list_for_each_entry_rcu(mod, &modules, list) { 2749 list_for_each_entry_rcu(mod, &modules, list) {
2706 if (within_module_init(addr, mod) || 2750 if (within_module_init(addr, mod) ||
2707 within_module_core(addr, mod)) { 2751 within_module_core(addr, mod)) {
2708 const char *sym; 2752 const char *sym;
2709 2753
2710 sym = get_ksymbol(mod, addr, size, offset); 2754 sym = get_ksymbol(mod, addr, size, offset);
2711 if (!sym) 2755 if (!sym)
2712 goto out; 2756 goto out;
2713 if (modname) 2757 if (modname)
2714 strlcpy(modname, mod->name, MODULE_NAME_LEN); 2758 strlcpy(modname, mod->name, MODULE_NAME_LEN);
2715 if (name) 2759 if (name)
2716 strlcpy(name, sym, KSYM_NAME_LEN); 2760 strlcpy(name, sym, KSYM_NAME_LEN);
2717 preempt_enable(); 2761 preempt_enable();
2718 return 0; 2762 return 0;
2719 } 2763 }
2720 } 2764 }
2721 out: 2765 out:
2722 preempt_enable(); 2766 preempt_enable();
2723 return -ERANGE; 2767 return -ERANGE;
2724 } 2768 }
2725 2769
2726 int module_get_kallsym(unsigned int symnum, unsigned long *value, char *type, 2770 int module_get_kallsym(unsigned int symnum, unsigned long *value, char *type,
2727 char *name, char *module_name, int *exported) 2771 char *name, char *module_name, int *exported)
2728 { 2772 {
2729 struct module *mod; 2773 struct module *mod;
2730 2774
2731 preempt_disable(); 2775 preempt_disable();
2732 list_for_each_entry_rcu(mod, &modules, list) { 2776 list_for_each_entry_rcu(mod, &modules, list) {
2733 if (symnum < mod->num_symtab) { 2777 if (symnum < mod->num_symtab) {
2734 *value = mod->symtab[symnum].st_value; 2778 *value = mod->symtab[symnum].st_value;
2735 *type = mod->symtab[symnum].st_info; 2779 *type = mod->symtab[symnum].st_info;
2736 strlcpy(name, mod->strtab + mod->symtab[symnum].st_name, 2780 strlcpy(name, mod->strtab + mod->symtab[symnum].st_name,
2737 KSYM_NAME_LEN); 2781 KSYM_NAME_LEN);
2738 strlcpy(module_name, mod->name, MODULE_NAME_LEN); 2782 strlcpy(module_name, mod->name, MODULE_NAME_LEN);
2739 *exported = is_exported(name, *value, mod); 2783 *exported = is_exported(name, *value, mod);
2740 preempt_enable(); 2784 preempt_enable();
2741 return 0; 2785 return 0;
2742 } 2786 }
2743 symnum -= mod->num_symtab; 2787 symnum -= mod->num_symtab;
2744 } 2788 }
2745 preempt_enable(); 2789 preempt_enable();
2746 return -ERANGE; 2790 return -ERANGE;
2747 } 2791 }
2748 2792
2749 static unsigned long mod_find_symname(struct module *mod, const char *name) 2793 static unsigned long mod_find_symname(struct module *mod, const char *name)
2750 { 2794 {
2751 unsigned int i; 2795 unsigned int i;
2752 2796
2753 for (i = 0; i < mod->num_symtab; i++) 2797 for (i = 0; i < mod->num_symtab; i++)
2754 if (strcmp(name, mod->strtab+mod->symtab[i].st_name) == 0 && 2798 if (strcmp(name, mod->strtab+mod->symtab[i].st_name) == 0 &&
2755 mod->symtab[i].st_info != 'U') 2799 mod->symtab[i].st_info != 'U')
2756 return mod->symtab[i].st_value; 2800 return mod->symtab[i].st_value;
2757 return 0; 2801 return 0;
2758 } 2802 }
2759 2803
2760 /* Look for this name: can be of form module:name. */ 2804 /* Look for this name: can be of form module:name. */
2761 unsigned long module_kallsyms_lookup_name(const char *name) 2805 unsigned long module_kallsyms_lookup_name(const char *name)
2762 { 2806 {
2763 struct module *mod; 2807 struct module *mod;
2764 char *colon; 2808 char *colon;
2765 unsigned long ret = 0; 2809 unsigned long ret = 0;
2766 2810
2767 /* Don't lock: we're in enough trouble already. */ 2811 /* Don't lock: we're in enough trouble already. */
2768 preempt_disable(); 2812 preempt_disable();
2769 if ((colon = strchr(name, ':')) != NULL) { 2813 if ((colon = strchr(name, ':')) != NULL) {
2770 *colon = '\0'; 2814 *colon = '\0';
2771 if ((mod = find_module(name)) != NULL) 2815 if ((mod = find_module(name)) != NULL)
2772 ret = mod_find_symname(mod, colon+1); 2816 ret = mod_find_symname(mod, colon+1);
2773 *colon = ':'; 2817 *colon = ':';
2774 } else { 2818 } else {
2775 list_for_each_entry_rcu(mod, &modules, list) 2819 list_for_each_entry_rcu(mod, &modules, list)
2776 if ((ret = mod_find_symname(mod, name)) != 0) 2820 if ((ret = mod_find_symname(mod, name)) != 0)
2777 break; 2821 break;
2778 } 2822 }
2779 preempt_enable(); 2823 preempt_enable();
2780 return ret; 2824 return ret;
2781 } 2825 }
2782 2826
2783 int module_kallsyms_on_each_symbol(int (*fn)(void *, const char *, 2827 int module_kallsyms_on_each_symbol(int (*fn)(void *, const char *,
2784 struct module *, unsigned long), 2828 struct module *, unsigned long),
2785 void *data) 2829 void *data)
2786 { 2830 {
2787 struct module *mod; 2831 struct module *mod;
2788 unsigned int i; 2832 unsigned int i;
2789 int ret; 2833 int ret;
2790 2834
2791 list_for_each_entry(mod, &modules, list) { 2835 list_for_each_entry(mod, &modules, list) {
2792 for (i = 0; i < mod->num_symtab; i++) { 2836 for (i = 0; i < mod->num_symtab; i++) {
2793 ret = fn(data, mod->strtab + mod->symtab[i].st_name, 2837 ret = fn(data, mod->strtab + mod->symtab[i].st_name,
2794 mod, mod->symtab[i].st_value); 2838 mod, mod->symtab[i].st_value);
2795 if (ret != 0) 2839 if (ret != 0)
2796 return ret; 2840 return ret;
2797 } 2841 }
2798 } 2842 }
2799 return 0; 2843 return 0;
2800 } 2844 }
2801 #endif /* CONFIG_KALLSYMS */ 2845 #endif /* CONFIG_KALLSYMS */
2802 2846
2803 static char *module_flags(struct module *mod, char *buf) 2847 static char *module_flags(struct module *mod, char *buf)
2804 { 2848 {
2805 int bx = 0; 2849 int bx = 0;
2806 2850
2807 if (mod->taints || 2851 if (mod->taints ||
2808 mod->state == MODULE_STATE_GOING || 2852 mod->state == MODULE_STATE_GOING ||
2809 mod->state == MODULE_STATE_COMING) { 2853 mod->state == MODULE_STATE_COMING) {
2810 buf[bx++] = '('; 2854 buf[bx++] = '(';
2811 if (mod->taints & (1 << TAINT_PROPRIETARY_MODULE)) 2855 if (mod->taints & (1 << TAINT_PROPRIETARY_MODULE))
2812 buf[bx++] = 'P'; 2856 buf[bx++] = 'P';
2813 if (mod->taints & (1 << TAINT_FORCED_MODULE)) 2857 if (mod->taints & (1 << TAINT_FORCED_MODULE))
2814 buf[bx++] = 'F'; 2858 buf[bx++] = 'F';
2815 if (mod->taints & (1 << TAINT_CRAP)) 2859 if (mod->taints & (1 << TAINT_CRAP))
2816 buf[bx++] = 'C'; 2860 buf[bx++] = 'C';
2817 /* 2861 /*
2818 * TAINT_FORCED_RMMOD: could be added. 2862 * TAINT_FORCED_RMMOD: could be added.
2819 * TAINT_UNSAFE_SMP, TAINT_MACHINE_CHECK, TAINT_BAD_PAGE don't 2863 * TAINT_UNSAFE_SMP, TAINT_MACHINE_CHECK, TAINT_BAD_PAGE don't
2820 * apply to modules. 2864 * apply to modules.
2821 */ 2865 */
2822 2866
2823 /* Show a - for module-is-being-unloaded */ 2867 /* Show a - for module-is-being-unloaded */
2824 if (mod->state == MODULE_STATE_GOING) 2868 if (mod->state == MODULE_STATE_GOING)
2825 buf[bx++] = '-'; 2869 buf[bx++] = '-';
2826 /* Show a + for module-is-being-loaded */ 2870 /* Show a + for module-is-being-loaded */
2827 if (mod->state == MODULE_STATE_COMING) 2871 if (mod->state == MODULE_STATE_COMING)
2828 buf[bx++] = '+'; 2872 buf[bx++] = '+';
2829 buf[bx++] = ')'; 2873 buf[bx++] = ')';
2830 } 2874 }
2831 buf[bx] = '\0'; 2875 buf[bx] = '\0';
2832 2876
2833 return buf; 2877 return buf;
2834 } 2878 }
2835 2879
2836 #ifdef CONFIG_PROC_FS 2880 #ifdef CONFIG_PROC_FS
2837 /* Called by the /proc file system to return a list of modules. */ 2881 /* Called by the /proc file system to return a list of modules. */
2838 static void *m_start(struct seq_file *m, loff_t *pos) 2882 static void *m_start(struct seq_file *m, loff_t *pos)
2839 { 2883 {
2840 mutex_lock(&module_mutex); 2884 mutex_lock(&module_mutex);
2841 return seq_list_start(&modules, *pos); 2885 return seq_list_start(&modules, *pos);
2842 } 2886 }
2843 2887
2844 static void *m_next(struct seq_file *m, void *p, loff_t *pos) 2888 static void *m_next(struct seq_file *m, void *p, loff_t *pos)
2845 { 2889 {
2846 return seq_list_next(p, &modules, pos); 2890 return seq_list_next(p, &modules, pos);
2847 } 2891 }
2848 2892
2849 static void m_stop(struct seq_file *m, void *p) 2893 static void m_stop(struct seq_file *m, void *p)
2850 { 2894 {
2851 mutex_unlock(&module_mutex); 2895 mutex_unlock(&module_mutex);
2852 } 2896 }
2853 2897
2854 static int m_show(struct seq_file *m, void *p) 2898 static int m_show(struct seq_file *m, void *p)
2855 { 2899 {
2856 struct module *mod = list_entry(p, struct module, list); 2900 struct module *mod = list_entry(p, struct module, list);
2857 char buf[8]; 2901 char buf[8];
2858 2902
2859 seq_printf(m, "%s %u", 2903 seq_printf(m, "%s %u",
2860 mod->name, mod->init_size + mod->core_size); 2904 mod->name, mod->init_size + mod->core_size);
2861 print_unload_info(m, mod); 2905 print_unload_info(m, mod);
2862 2906
2863 /* Informative for users. */ 2907 /* Informative for users. */
2864 seq_printf(m, " %s", 2908 seq_printf(m, " %s",
2865 mod->state == MODULE_STATE_GOING ? "Unloading": 2909 mod->state == MODULE_STATE_GOING ? "Unloading":
2866 mod->state == MODULE_STATE_COMING ? "Loading": 2910 mod->state == MODULE_STATE_COMING ? "Loading":
2867 "Live"); 2911 "Live");
2868 /* Used by oprofile and other similar tools. */ 2912 /* Used by oprofile and other similar tools. */
2869 seq_printf(m, " 0x%p", mod->module_core); 2913 seq_printf(m, " 0x%p", mod->module_core);
2870 2914
2871 /* Taints info */ 2915 /* Taints info */
2872 if (mod->taints) 2916 if (mod->taints)
2873 seq_printf(m, " %s", module_flags(mod, buf)); 2917 seq_printf(m, " %s", module_flags(mod, buf));
2874 2918
2875 seq_printf(m, "\n"); 2919 seq_printf(m, "\n");
2876 return 0; 2920 return 0;
2877 } 2921 }
2878 2922
2879 /* Format: modulename size refcount deps address 2923 /* Format: modulename size refcount deps address
2880 2924
2881 Where refcount is a number or -, and deps is a comma-separated list 2925 Where refcount is a number or -, and deps is a comma-separated list
2882 of depends or -. 2926 of depends or -.
2883 */ 2927 */
2884 static const struct seq_operations modules_op = { 2928 static const struct seq_operations modules_op = {
2885 .start = m_start, 2929 .start = m_start,
2886 .next = m_next, 2930 .next = m_next,
2887 .stop = m_stop, 2931 .stop = m_stop,
2888 .show = m_show 2932 .show = m_show
2889 }; 2933 };
2890 2934
2891 static int modules_open(struct inode *inode, struct file *file) 2935 static int modules_open(struct inode *inode, struct file *file)
2892 { 2936 {
2893 return seq_open(file, &modules_op); 2937 return seq_open(file, &modules_op);
2894 } 2938 }
2895 2939
2896 static const struct file_operations proc_modules_operations = { 2940 static const struct file_operations proc_modules_operations = {
2897 .open = modules_open, 2941 .open = modules_open,
2898 .read = seq_read, 2942 .read = seq_read,
2899 .llseek = seq_lseek, 2943 .llseek = seq_lseek,
2900 .release = seq_release, 2944 .release = seq_release,
2901 }; 2945 };
2902 2946
2903 static int __init proc_modules_init(void) 2947 static int __init proc_modules_init(void)
2904 { 2948 {
2905 proc_create("modules", 0, NULL, &proc_modules_operations); 2949 proc_create("modules", 0, NULL, &proc_modules_operations);
2906 return 0; 2950 return 0;
2907 } 2951 }
2908 module_init(proc_modules_init); 2952 module_init(proc_modules_init);
2909 #endif 2953 #endif
2910 2954
2911 /* Given an address, look for it in the module exception tables. */ 2955 /* Given an address, look for it in the module exception tables. */
2912 const struct exception_table_entry *search_module_extables(unsigned long addr) 2956 const struct exception_table_entry *search_module_extables(unsigned long addr)
2913 { 2957 {
2914 const struct exception_table_entry *e = NULL; 2958 const struct exception_table_entry *e = NULL;
2915 struct module *mod; 2959 struct module *mod;
2916 2960
2917 preempt_disable(); 2961 preempt_disable();
2918 list_for_each_entry_rcu(mod, &modules, list) { 2962 list_for_each_entry_rcu(mod, &modules, list) {
2919 if (mod->num_exentries == 0) 2963 if (mod->num_exentries == 0)
2920 continue; 2964 continue;
2921 2965
2922 e = search_extable(mod->extable, 2966 e = search_extable(mod->extable,
2923 mod->extable + mod->num_exentries - 1, 2967 mod->extable + mod->num_exentries - 1,
2924 addr); 2968 addr);
2925 if (e) 2969 if (e)
2926 break; 2970 break;
2927 } 2971 }
2928 preempt_enable(); 2972 preempt_enable();
2929 2973
2930 /* Now, if we found one, we are running inside it now, hence 2974 /* Now, if we found one, we are running inside it now, hence
2931 we cannot unload the module, hence no refcnt needed. */ 2975 we cannot unload the module, hence no refcnt needed. */
2932 return e; 2976 return e;
2933 } 2977 }
2934 2978
2935 /* 2979 /*
2936 * is_module_address - is this address inside a module? 2980 * is_module_address - is this address inside a module?
2937 * @addr: the address to check. 2981 * @addr: the address to check.
2938 * 2982 *
2939 * See is_module_text_address() if you simply want to see if the address 2983 * See is_module_text_address() if you simply want to see if the address
2940 * is code (not data). 2984 * is code (not data).
2941 */ 2985 */
2942 bool is_module_address(unsigned long addr) 2986 bool is_module_address(unsigned long addr)
2943 { 2987 {
2944 bool ret; 2988 bool ret;
2945 2989
2946 preempt_disable(); 2990 preempt_disable();
2947 ret = __module_address(addr) != NULL; 2991 ret = __module_address(addr) != NULL;
2948 preempt_enable(); 2992 preempt_enable();
2949 2993
2950 return ret; 2994 return ret;
2951 } 2995 }
2952 2996
2953 /* 2997 /*
2954 * __module_address - get the module which contains an address. 2998 * __module_address - get the module which contains an address.
2955 * @addr: the address. 2999 * @addr: the address.
2956 * 3000 *
2957 * Must be called with preempt disabled or module mutex held so that 3001 * Must be called with preempt disabled or module mutex held so that
2958 * module doesn't get freed during this. 3002 * module doesn't get freed during this.
2959 */ 3003 */
2960 struct module *__module_address(unsigned long addr) 3004 struct module *__module_address(unsigned long addr)
2961 { 3005 {
2962 struct module *mod; 3006 struct module *mod;
2963 3007
2964 if (addr < module_addr_min || addr > module_addr_max) 3008 if (addr < module_addr_min || addr > module_addr_max)
2965 return NULL; 3009 return NULL;
2966 3010
2967 list_for_each_entry_rcu(mod, &modules, list) 3011 list_for_each_entry_rcu(mod, &modules, list)
2968 if (within_module_core(addr, mod) 3012 if (within_module_core(addr, mod)
2969 || within_module_init(addr, mod)) 3013 || within_module_init(addr, mod))
2970 return mod; 3014 return mod;
2971 return NULL; 3015 return NULL;
2972 } 3016 }
2973 EXPORT_SYMBOL_GPL(__module_address); 3017 EXPORT_SYMBOL_GPL(__module_address);
2974 3018
2975 /* 3019 /*
2976 * is_module_text_address - is this address inside module code? 3020 * is_module_text_address - is this address inside module code?
2977 * @addr: the address to check. 3021 * @addr: the address to check.
2978 * 3022 *
2979 * See is_module_address() if you simply want to see if the address is 3023 * See is_module_address() if you simply want to see if the address is
2980 * anywhere in a module. See kernel_text_address() for testing if an 3024 * anywhere in a module. See kernel_text_address() for testing if an
2981 * address corresponds to kernel or module code. 3025 * address corresponds to kernel or module code.
2982 */ 3026 */
2983 bool is_module_text_address(unsigned long addr) 3027 bool is_module_text_address(unsigned long addr)
2984 { 3028 {
2985 bool ret; 3029 bool ret;
2986 3030
2987 preempt_disable(); 3031 preempt_disable();
2988 ret = __module_text_address(addr) != NULL; 3032 ret = __module_text_address(addr) != NULL;
2989 preempt_enable(); 3033 preempt_enable();
2990 3034
2991 return ret; 3035 return ret;
2992 } 3036 }
2993 3037
2994 /* 3038 /*
2995 * __module_text_address - get the module whose code contains an address. 3039 * __module_text_address - get the module whose code contains an address.
2996 * @addr: the address. 3040 * @addr: the address.
2997 * 3041 *
2998 * Must be called with preempt disabled or module mutex held so that 3042 * Must be called with preempt disabled or module mutex held so that
2999 * module doesn't get freed during this. 3043 * module doesn't get freed during this.
3000 */ 3044 */
3001 struct module *__module_text_address(unsigned long addr) 3045 struct module *__module_text_address(unsigned long addr)
3002 { 3046 {
3003 struct module *mod = __module_address(addr); 3047 struct module *mod = __module_address(addr);
3004 if (mod) { 3048 if (mod) {
3005 /* Make sure it's within the text section. */ 3049 /* Make sure it's within the text section. */
3006 if (!within(addr, mod->module_init, mod->init_text_size) 3050 if (!within(addr, mod->module_init, mod->init_text_size)
3007 && !within(addr, mod->module_core, mod->core_text_size)) 3051 && !within(addr, mod->module_core, mod->core_text_size))
3008 mod = NULL; 3052 mod = NULL;
3009 } 3053 }
3010 return mod; 3054 return mod;
3011 } 3055 }
3012 EXPORT_SYMBOL_GPL(__module_text_address); 3056 EXPORT_SYMBOL_GPL(__module_text_address);
3013 3057
3014 /* Don't grab lock, we're oopsing. */ 3058 /* Don't grab lock, we're oopsing. */
3015 void print_modules(void) 3059 void print_modules(void)
3016 { 3060 {
3017 struct module *mod; 3061 struct module *mod;
3018 char buf[8]; 3062 char buf[8];
3019 3063
3020 printk(KERN_DEFAULT "Modules linked in:"); 3064 printk(KERN_DEFAULT "Modules linked in:");
3021 /* Most callers should already have preempt disabled, but make sure */ 3065 /* Most callers should already have preempt disabled, but make sure */
3022 preempt_disable(); 3066 preempt_disable();
3023 list_for_each_entry_rcu(mod, &modules, list) 3067 list_for_each_entry_rcu(mod, &modules, list)
3024 printk(" %s%s", mod->name, module_flags(mod, buf)); 3068 printk(" %s%s", mod->name, module_flags(mod, buf));
3025 preempt_enable(); 3069 preempt_enable();
3026 if (last_unloaded_module[0]) 3070 if (last_unloaded_module[0])
3027 printk(" [last unloaded: %s]", last_unloaded_module); 3071 printk(" [last unloaded: %s]", last_unloaded_module);
3028 printk("\n"); 3072 printk("\n");
3029 } 3073 }
3030 3074
3031 #ifdef CONFIG_MODVERSIONS 3075 #ifdef CONFIG_MODVERSIONS
3032 /* Generate the signature for all relevant module structures here. 3076 /* Generate the signature for all relevant module structures here.
3033 * If these change, we don't want to try to parse the module. */ 3077 * If these change, we don't want to try to parse the module. */
3034 void module_layout(struct module *mod, 3078 void module_layout(struct module *mod,
3035 struct modversion_info *ver, 3079 struct modversion_info *ver,
3036 struct kernel_param *kp, 3080 struct kernel_param *kp,
3037 struct kernel_symbol *ks, 3081 struct kernel_symbol *ks,
3038 struct marker *marker, 3082 struct marker *marker,
3039 struct tracepoint *tp) 3083 struct tracepoint *tp)
3040 { 3084 {
3041 } 3085 }
3042 EXPORT_SYMBOL(module_layout); 3086 EXPORT_SYMBOL(module_layout);
3043 #endif 3087 #endif
3044 3088
3045 #ifdef CONFIG_TRACEPOINTS 3089 #ifdef CONFIG_TRACEPOINTS
3046 void module_update_tracepoints(void) 3090 void module_update_tracepoints(void)
3047 { 3091 {
3048 struct module *mod; 3092 struct module *mod;
3049 3093
3050 mutex_lock(&module_mutex); 3094 mutex_lock(&module_mutex);
3051 list_for_each_entry(mod, &modules, list) 3095 list_for_each_entry(mod, &modules, list)
3052 if (!mod->taints) 3096 if (!mod->taints)
3053 tracepoint_update_probe_range(mod->tracepoints, 3097 tracepoint_update_probe_range(mod->tracepoints,
3054 mod->tracepoints + mod->num_tracepoints); 3098 mod->tracepoints + mod->num_tracepoints);
3055 mutex_unlock(&module_mutex); 3099 mutex_unlock(&module_mutex);
3056 } 3100 }
3057 3101
3058 /* 3102 /*
3059 * Returns 0 if current not found. 3103 * Returns 0 if current not found.
3060 * Returns 1 if current found. 3104 * Returns 1 if current found.
3061 */ 3105 */
3062 int module_get_iter_tracepoints(struct tracepoint_iter *iter) 3106 int module_get_iter_tracepoints(struct tracepoint_iter *iter)
3063 { 3107 {
3064 struct module *iter_mod; 3108 struct module *iter_mod;
3065 int found = 0; 3109 int found = 0;
3066 3110
3067 mutex_lock(&module_mutex); 3111 mutex_lock(&module_mutex);
3068 list_for_each_entry(iter_mod, &modules, list) { 3112 list_for_each_entry(iter_mod, &modules, list) {
3069 if (!iter_mod->taints) { 3113 if (!iter_mod->taints) {
3070 /* 3114 /*
3071 * Sorted module list 3115 * Sorted module list
3072 */ 3116 */
3073 if (iter_mod < iter->module) 3117 if (iter_mod < iter->module)
3074 continue; 3118 continue;
3075 else if (iter_mod > iter->module) 3119 else if (iter_mod > iter->module)
3076 iter->tracepoint = NULL; 3120 iter->tracepoint = NULL;
3077 found = tracepoint_get_iter_range(&iter->tracepoint, 3121 found = tracepoint_get_iter_range(&iter->tracepoint,
3078 iter_mod->tracepoints, 3122 iter_mod->tracepoints,
3079 iter_mod->tracepoints 3123 iter_mod->tracepoints
3080 + iter_mod->num_tracepoints); 3124 + iter_mod->num_tracepoints);
3081 if (found) { 3125 if (found) {
3082 iter->module = iter_mod; 3126 iter->module = iter_mod;
3083 break; 3127 break;
3084 } 3128 }
3085 } 3129 }
3086 } 3130 }
3087 mutex_unlock(&module_mutex); 3131 mutex_unlock(&module_mutex);