Commit f1883f86dea84fe47a71a39fc1afccc005915ed8
Committed by
Linus Torvalds
1 parent
eaccbfa564
Exists in
master
and in
4 other branches
Remove remaining unwinder code
Signed-off-by: Alexey Dobriyan <adobriyan@gmail.com> Cc: Gabor Gombas <gombasg@sztaki.hu> Cc: Jan Beulich <jbeulich@novell.com> Cc: Andi Kleen <andi@firstfloor.org> Cc: Ingo Molnar <mingo@elte.hu>, Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Showing 7 changed files with 0 additions and 105 deletions Inline Diff
arch/x86/include/asm/unwind.h
1 | #ifndef _ASM_X86_UNWIND_H | File was deleted | |
2 | #define _ASM_X86_UNWIND_H | ||
3 | |||
4 | #define UNW_PC(frame) ((void)(frame), 0UL) | ||
5 | #define UNW_SP(frame) ((void)(frame), 0UL) | ||
6 | #define UNW_FP(frame) ((void)(frame), 0UL) | ||
7 | |||
8 | static inline int arch_unw_user_mode(const void *info) | ||
9 | { | ||
10 | return 0; | ||
11 | } | ||
12 | |||
13 | #endif /* _ASM_X86_UNWIND_H */ | ||
14 | 1 | #ifndef _ASM_X86_UNWIND_H |
arch/x86/kernel/traps.c
1 | /* | 1 | /* |
2 | * Copyright (C) 1991, 1992 Linus Torvalds | 2 | * Copyright (C) 1991, 1992 Linus Torvalds |
3 | * Copyright (C) 2000, 2001, 2002 Andi Kleen, SuSE Labs | 3 | * Copyright (C) 2000, 2001, 2002 Andi Kleen, SuSE Labs |
4 | * | 4 | * |
5 | * Pentium III FXSR, SSE support | 5 | * Pentium III FXSR, SSE support |
6 | * Gareth Hughes <gareth@valinux.com>, May 2000 | 6 | * Gareth Hughes <gareth@valinux.com>, May 2000 |
7 | */ | 7 | */ |
8 | 8 | ||
9 | /* | 9 | /* |
10 | * Handle hardware traps and faults. | 10 | * Handle hardware traps and faults. |
11 | */ | 11 | */ |
12 | #include <linux/interrupt.h> | 12 | #include <linux/interrupt.h> |
13 | #include <linux/kallsyms.h> | 13 | #include <linux/kallsyms.h> |
14 | #include <linux/spinlock.h> | 14 | #include <linux/spinlock.h> |
15 | #include <linux/kprobes.h> | 15 | #include <linux/kprobes.h> |
16 | #include <linux/uaccess.h> | 16 | #include <linux/uaccess.h> |
17 | #include <linux/utsname.h> | 17 | #include <linux/utsname.h> |
18 | #include <linux/kdebug.h> | 18 | #include <linux/kdebug.h> |
19 | #include <linux/kernel.h> | 19 | #include <linux/kernel.h> |
20 | #include <linux/module.h> | 20 | #include <linux/module.h> |
21 | #include <linux/ptrace.h> | 21 | #include <linux/ptrace.h> |
22 | #include <linux/string.h> | 22 | #include <linux/string.h> |
23 | #include <linux/unwind.h> | ||
24 | #include <linux/delay.h> | 23 | #include <linux/delay.h> |
25 | #include <linux/errno.h> | 24 | #include <linux/errno.h> |
26 | #include <linux/kexec.h> | 25 | #include <linux/kexec.h> |
27 | #include <linux/sched.h> | 26 | #include <linux/sched.h> |
28 | #include <linux/timer.h> | 27 | #include <linux/timer.h> |
29 | #include <linux/init.h> | 28 | #include <linux/init.h> |
30 | #include <linux/bug.h> | 29 | #include <linux/bug.h> |
31 | #include <linux/nmi.h> | 30 | #include <linux/nmi.h> |
32 | #include <linux/mm.h> | 31 | #include <linux/mm.h> |
33 | #include <linux/smp.h> | 32 | #include <linux/smp.h> |
34 | #include <linux/io.h> | 33 | #include <linux/io.h> |
35 | 34 | ||
36 | #ifdef CONFIG_EISA | 35 | #ifdef CONFIG_EISA |
37 | #include <linux/ioport.h> | 36 | #include <linux/ioport.h> |
38 | #include <linux/eisa.h> | 37 | #include <linux/eisa.h> |
39 | #endif | 38 | #endif |
40 | 39 | ||
41 | #ifdef CONFIG_MCA | 40 | #ifdef CONFIG_MCA |
42 | #include <linux/mca.h> | 41 | #include <linux/mca.h> |
43 | #endif | 42 | #endif |
44 | 43 | ||
45 | #if defined(CONFIG_EDAC) | 44 | #if defined(CONFIG_EDAC) |
46 | #include <linux/edac.h> | 45 | #include <linux/edac.h> |
47 | #endif | 46 | #endif |
48 | 47 | ||
49 | #include <asm/stacktrace.h> | 48 | #include <asm/stacktrace.h> |
50 | #include <asm/processor.h> | 49 | #include <asm/processor.h> |
51 | #include <asm/debugreg.h> | 50 | #include <asm/debugreg.h> |
52 | #include <asm/atomic.h> | 51 | #include <asm/atomic.h> |
53 | #include <asm/system.h> | 52 | #include <asm/system.h> |
54 | #include <asm/unwind.h> | ||
55 | #include <asm/traps.h> | 53 | #include <asm/traps.h> |
56 | #include <asm/desc.h> | 54 | #include <asm/desc.h> |
57 | #include <asm/i387.h> | 55 | #include <asm/i387.h> |
58 | 56 | ||
59 | #include <mach_traps.h> | 57 | #include <mach_traps.h> |
60 | 58 | ||
61 | #ifdef CONFIG_X86_64 | 59 | #ifdef CONFIG_X86_64 |
62 | #include <asm/pgalloc.h> | 60 | #include <asm/pgalloc.h> |
63 | #include <asm/proto.h> | 61 | #include <asm/proto.h> |
64 | #include <asm/pda.h> | 62 | #include <asm/pda.h> |
65 | #else | 63 | #else |
66 | #include <asm/processor-flags.h> | 64 | #include <asm/processor-flags.h> |
67 | #include <asm/arch_hooks.h> | 65 | #include <asm/arch_hooks.h> |
68 | #include <asm/nmi.h> | 66 | #include <asm/nmi.h> |
69 | #include <asm/smp.h> | 67 | #include <asm/smp.h> |
70 | #include <asm/io.h> | 68 | #include <asm/io.h> |
71 | #include <asm/traps.h> | 69 | #include <asm/traps.h> |
72 | 70 | ||
73 | #include "cpu/mcheck/mce.h" | 71 | #include "cpu/mcheck/mce.h" |
74 | 72 | ||
75 | asmlinkage int system_call(void); | 73 | asmlinkage int system_call(void); |
76 | 74 | ||
77 | /* Do we ignore FPU interrupts ? */ | 75 | /* Do we ignore FPU interrupts ? */ |
78 | char ignore_fpu_irq; | 76 | char ignore_fpu_irq; |
79 | 77 | ||
80 | /* | 78 | /* |
81 | * The IDT has to be page-aligned to simplify the Pentium | 79 | * The IDT has to be page-aligned to simplify the Pentium |
82 | * F0 0F bug workaround.. We have a special link segment | 80 | * F0 0F bug workaround.. We have a special link segment |
83 | * for this. | 81 | * for this. |
84 | */ | 82 | */ |
85 | gate_desc idt_table[256] | 83 | gate_desc idt_table[256] |
86 | __attribute__((__section__(".data.idt"))) = { { { { 0, 0 } } }, }; | 84 | __attribute__((__section__(".data.idt"))) = { { { { 0, 0 } } }, }; |
87 | #endif | 85 | #endif |
88 | 86 | ||
89 | DECLARE_BITMAP(used_vectors, NR_VECTORS); | 87 | DECLARE_BITMAP(used_vectors, NR_VECTORS); |
90 | EXPORT_SYMBOL_GPL(used_vectors); | 88 | EXPORT_SYMBOL_GPL(used_vectors); |
91 | 89 | ||
92 | static int ignore_nmis; | 90 | static int ignore_nmis; |
93 | 91 | ||
94 | static inline void conditional_sti(struct pt_regs *regs) | 92 | static inline void conditional_sti(struct pt_regs *regs) |
95 | { | 93 | { |
96 | if (regs->flags & X86_EFLAGS_IF) | 94 | if (regs->flags & X86_EFLAGS_IF) |
97 | local_irq_enable(); | 95 | local_irq_enable(); |
98 | } | 96 | } |
99 | 97 | ||
100 | static inline void preempt_conditional_sti(struct pt_regs *regs) | 98 | static inline void preempt_conditional_sti(struct pt_regs *regs) |
101 | { | 99 | { |
102 | inc_preempt_count(); | 100 | inc_preempt_count(); |
103 | if (regs->flags & X86_EFLAGS_IF) | 101 | if (regs->flags & X86_EFLAGS_IF) |
104 | local_irq_enable(); | 102 | local_irq_enable(); |
105 | } | 103 | } |
106 | 104 | ||
107 | static inline void preempt_conditional_cli(struct pt_regs *regs) | 105 | static inline void preempt_conditional_cli(struct pt_regs *regs) |
108 | { | 106 | { |
109 | if (regs->flags & X86_EFLAGS_IF) | 107 | if (regs->flags & X86_EFLAGS_IF) |
110 | local_irq_disable(); | 108 | local_irq_disable(); |
111 | dec_preempt_count(); | 109 | dec_preempt_count(); |
112 | } | 110 | } |
113 | 111 | ||
114 | #ifdef CONFIG_X86_32 | 112 | #ifdef CONFIG_X86_32 |
115 | static inline void | 113 | static inline void |
116 | die_if_kernel(const char *str, struct pt_regs *regs, long err) | 114 | die_if_kernel(const char *str, struct pt_regs *regs, long err) |
117 | { | 115 | { |
118 | if (!user_mode_vm(regs)) | 116 | if (!user_mode_vm(regs)) |
119 | die(str, regs, err); | 117 | die(str, regs, err); |
120 | } | 118 | } |
121 | 119 | ||
122 | /* | 120 | /* |
123 | * Perform the lazy TSS's I/O bitmap copy. If the TSS has an | 121 | * Perform the lazy TSS's I/O bitmap copy. If the TSS has an |
124 | * invalid offset set (the LAZY one) and the faulting thread has | 122 | * invalid offset set (the LAZY one) and the faulting thread has |
125 | * a valid I/O bitmap pointer, we copy the I/O bitmap in the TSS, | 123 | * a valid I/O bitmap pointer, we copy the I/O bitmap in the TSS, |
126 | * we set the offset field correctly and return 1. | 124 | * we set the offset field correctly and return 1. |
127 | */ | 125 | */ |
128 | static int lazy_iobitmap_copy(void) | 126 | static int lazy_iobitmap_copy(void) |
129 | { | 127 | { |
130 | struct thread_struct *thread; | 128 | struct thread_struct *thread; |
131 | struct tss_struct *tss; | 129 | struct tss_struct *tss; |
132 | int cpu; | 130 | int cpu; |
133 | 131 | ||
134 | cpu = get_cpu(); | 132 | cpu = get_cpu(); |
135 | tss = &per_cpu(init_tss, cpu); | 133 | tss = &per_cpu(init_tss, cpu); |
136 | thread = ¤t->thread; | 134 | thread = ¤t->thread; |
137 | 135 | ||
138 | if (tss->x86_tss.io_bitmap_base == INVALID_IO_BITMAP_OFFSET_LAZY && | 136 | if (tss->x86_tss.io_bitmap_base == INVALID_IO_BITMAP_OFFSET_LAZY && |
139 | thread->io_bitmap_ptr) { | 137 | thread->io_bitmap_ptr) { |
140 | memcpy(tss->io_bitmap, thread->io_bitmap_ptr, | 138 | memcpy(tss->io_bitmap, thread->io_bitmap_ptr, |
141 | thread->io_bitmap_max); | 139 | thread->io_bitmap_max); |
142 | /* | 140 | /* |
143 | * If the previously set map was extending to higher ports | 141 | * If the previously set map was extending to higher ports |
144 | * than the current one, pad extra space with 0xff (no access). | 142 | * than the current one, pad extra space with 0xff (no access). |
145 | */ | 143 | */ |
146 | if (thread->io_bitmap_max < tss->io_bitmap_max) { | 144 | if (thread->io_bitmap_max < tss->io_bitmap_max) { |
147 | memset((char *) tss->io_bitmap + | 145 | memset((char *) tss->io_bitmap + |
148 | thread->io_bitmap_max, 0xff, | 146 | thread->io_bitmap_max, 0xff, |
149 | tss->io_bitmap_max - thread->io_bitmap_max); | 147 | tss->io_bitmap_max - thread->io_bitmap_max); |
150 | } | 148 | } |
151 | tss->io_bitmap_max = thread->io_bitmap_max; | 149 | tss->io_bitmap_max = thread->io_bitmap_max; |
152 | tss->x86_tss.io_bitmap_base = IO_BITMAP_OFFSET; | 150 | tss->x86_tss.io_bitmap_base = IO_BITMAP_OFFSET; |
153 | tss->io_bitmap_owner = thread; | 151 | tss->io_bitmap_owner = thread; |
154 | put_cpu(); | 152 | put_cpu(); |
155 | 153 | ||
156 | return 1; | 154 | return 1; |
157 | } | 155 | } |
158 | put_cpu(); | 156 | put_cpu(); |
159 | 157 | ||
160 | return 0; | 158 | return 0; |
161 | } | 159 | } |
162 | #endif | 160 | #endif |
163 | 161 | ||
164 | static void __kprobes | 162 | static void __kprobes |
165 | do_trap(int trapnr, int signr, char *str, struct pt_regs *regs, | 163 | do_trap(int trapnr, int signr, char *str, struct pt_regs *regs, |
166 | long error_code, siginfo_t *info) | 164 | long error_code, siginfo_t *info) |
167 | { | 165 | { |
168 | struct task_struct *tsk = current; | 166 | struct task_struct *tsk = current; |
169 | 167 | ||
170 | #ifdef CONFIG_X86_32 | 168 | #ifdef CONFIG_X86_32 |
171 | if (regs->flags & X86_VM_MASK) { | 169 | if (regs->flags & X86_VM_MASK) { |
172 | /* | 170 | /* |
173 | * traps 0, 1, 3, 4, and 5 should be forwarded to vm86. | 171 | * traps 0, 1, 3, 4, and 5 should be forwarded to vm86. |
174 | * On nmi (interrupt 2), do_trap should not be called. | 172 | * On nmi (interrupt 2), do_trap should not be called. |
175 | */ | 173 | */ |
176 | if (trapnr < 6) | 174 | if (trapnr < 6) |
177 | goto vm86_trap; | 175 | goto vm86_trap; |
178 | goto trap_signal; | 176 | goto trap_signal; |
179 | } | 177 | } |
180 | #endif | 178 | #endif |
181 | 179 | ||
182 | if (!user_mode(regs)) | 180 | if (!user_mode(regs)) |
183 | goto kernel_trap; | 181 | goto kernel_trap; |
184 | 182 | ||
185 | #ifdef CONFIG_X86_32 | 183 | #ifdef CONFIG_X86_32 |
186 | trap_signal: | 184 | trap_signal: |
187 | #endif | 185 | #endif |
188 | /* | 186 | /* |
189 | * We want error_code and trap_no set for userspace faults and | 187 | * We want error_code and trap_no set for userspace faults and |
190 | * kernelspace faults which result in die(), but not | 188 | * kernelspace faults which result in die(), but not |
191 | * kernelspace faults which are fixed up. die() gives the | 189 | * kernelspace faults which are fixed up. die() gives the |
192 | * process no chance to handle the signal and notice the | 190 | * process no chance to handle the signal and notice the |
193 | * kernel fault information, so that won't result in polluting | 191 | * kernel fault information, so that won't result in polluting |
194 | * the information about previously queued, but not yet | 192 | * the information about previously queued, but not yet |
195 | * delivered, faults. See also do_general_protection below. | 193 | * delivered, faults. See also do_general_protection below. |
196 | */ | 194 | */ |
197 | tsk->thread.error_code = error_code; | 195 | tsk->thread.error_code = error_code; |
198 | tsk->thread.trap_no = trapnr; | 196 | tsk->thread.trap_no = trapnr; |
199 | 197 | ||
200 | #ifdef CONFIG_X86_64 | 198 | #ifdef CONFIG_X86_64 |
201 | if (show_unhandled_signals && unhandled_signal(tsk, signr) && | 199 | if (show_unhandled_signals && unhandled_signal(tsk, signr) && |
202 | printk_ratelimit()) { | 200 | printk_ratelimit()) { |
203 | printk(KERN_INFO | 201 | printk(KERN_INFO |
204 | "%s[%d] trap %s ip:%lx sp:%lx error:%lx", | 202 | "%s[%d] trap %s ip:%lx sp:%lx error:%lx", |
205 | tsk->comm, tsk->pid, str, | 203 | tsk->comm, tsk->pid, str, |
206 | regs->ip, regs->sp, error_code); | 204 | regs->ip, regs->sp, error_code); |
207 | print_vma_addr(" in ", regs->ip); | 205 | print_vma_addr(" in ", regs->ip); |
208 | printk("\n"); | 206 | printk("\n"); |
209 | } | 207 | } |
210 | #endif | 208 | #endif |
211 | 209 | ||
212 | if (info) | 210 | if (info) |
213 | force_sig_info(signr, info, tsk); | 211 | force_sig_info(signr, info, tsk); |
214 | else | 212 | else |
215 | force_sig(signr, tsk); | 213 | force_sig(signr, tsk); |
216 | return; | 214 | return; |
217 | 215 | ||
218 | kernel_trap: | 216 | kernel_trap: |
219 | if (!fixup_exception(regs)) { | 217 | if (!fixup_exception(regs)) { |
220 | tsk->thread.error_code = error_code; | 218 | tsk->thread.error_code = error_code; |
221 | tsk->thread.trap_no = trapnr; | 219 | tsk->thread.trap_no = trapnr; |
222 | die(str, regs, error_code); | 220 | die(str, regs, error_code); |
223 | } | 221 | } |
224 | return; | 222 | return; |
225 | 223 | ||
226 | #ifdef CONFIG_X86_32 | 224 | #ifdef CONFIG_X86_32 |
227 | vm86_trap: | 225 | vm86_trap: |
228 | if (handle_vm86_trap((struct kernel_vm86_regs *) regs, | 226 | if (handle_vm86_trap((struct kernel_vm86_regs *) regs, |
229 | error_code, trapnr)) | 227 | error_code, trapnr)) |
230 | goto trap_signal; | 228 | goto trap_signal; |
231 | return; | 229 | return; |
232 | #endif | 230 | #endif |
233 | } | 231 | } |
234 | 232 | ||
235 | #define DO_ERROR(trapnr, signr, str, name) \ | 233 | #define DO_ERROR(trapnr, signr, str, name) \ |
236 | dotraplinkage void do_##name(struct pt_regs *regs, long error_code) \ | 234 | dotraplinkage void do_##name(struct pt_regs *regs, long error_code) \ |
237 | { \ | 235 | { \ |
238 | if (notify_die(DIE_TRAP, str, regs, error_code, trapnr, signr) \ | 236 | if (notify_die(DIE_TRAP, str, regs, error_code, trapnr, signr) \ |
239 | == NOTIFY_STOP) \ | 237 | == NOTIFY_STOP) \ |
240 | return; \ | 238 | return; \ |
241 | conditional_sti(regs); \ | 239 | conditional_sti(regs); \ |
242 | do_trap(trapnr, signr, str, regs, error_code, NULL); \ | 240 | do_trap(trapnr, signr, str, regs, error_code, NULL); \ |
243 | } | 241 | } |
244 | 242 | ||
245 | #define DO_ERROR_INFO(trapnr, signr, str, name, sicode, siaddr) \ | 243 | #define DO_ERROR_INFO(trapnr, signr, str, name, sicode, siaddr) \ |
246 | dotraplinkage void do_##name(struct pt_regs *regs, long error_code) \ | 244 | dotraplinkage void do_##name(struct pt_regs *regs, long error_code) \ |
247 | { \ | 245 | { \ |
248 | siginfo_t info; \ | 246 | siginfo_t info; \ |
249 | info.si_signo = signr; \ | 247 | info.si_signo = signr; \ |
250 | info.si_errno = 0; \ | 248 | info.si_errno = 0; \ |
251 | info.si_code = sicode; \ | 249 | info.si_code = sicode; \ |
252 | info.si_addr = (void __user *)siaddr; \ | 250 | info.si_addr = (void __user *)siaddr; \ |
253 | if (notify_die(DIE_TRAP, str, regs, error_code, trapnr, signr) \ | 251 | if (notify_die(DIE_TRAP, str, regs, error_code, trapnr, signr) \ |
254 | == NOTIFY_STOP) \ | 252 | == NOTIFY_STOP) \ |
255 | return; \ | 253 | return; \ |
256 | conditional_sti(regs); \ | 254 | conditional_sti(regs); \ |
257 | do_trap(trapnr, signr, str, regs, error_code, &info); \ | 255 | do_trap(trapnr, signr, str, regs, error_code, &info); \ |
258 | } | 256 | } |
259 | 257 | ||
260 | DO_ERROR_INFO(0, SIGFPE, "divide error", divide_error, FPE_INTDIV, regs->ip) | 258 | DO_ERROR_INFO(0, SIGFPE, "divide error", divide_error, FPE_INTDIV, regs->ip) |
261 | DO_ERROR(4, SIGSEGV, "overflow", overflow) | 259 | DO_ERROR(4, SIGSEGV, "overflow", overflow) |
262 | DO_ERROR(5, SIGSEGV, "bounds", bounds) | 260 | DO_ERROR(5, SIGSEGV, "bounds", bounds) |
263 | DO_ERROR_INFO(6, SIGILL, "invalid opcode", invalid_op, ILL_ILLOPN, regs->ip) | 261 | DO_ERROR_INFO(6, SIGILL, "invalid opcode", invalid_op, ILL_ILLOPN, regs->ip) |
264 | DO_ERROR(9, SIGFPE, "coprocessor segment overrun", coprocessor_segment_overrun) | 262 | DO_ERROR(9, SIGFPE, "coprocessor segment overrun", coprocessor_segment_overrun) |
265 | DO_ERROR(10, SIGSEGV, "invalid TSS", invalid_TSS) | 263 | DO_ERROR(10, SIGSEGV, "invalid TSS", invalid_TSS) |
266 | DO_ERROR(11, SIGBUS, "segment not present", segment_not_present) | 264 | DO_ERROR(11, SIGBUS, "segment not present", segment_not_present) |
267 | #ifdef CONFIG_X86_32 | 265 | #ifdef CONFIG_X86_32 |
268 | DO_ERROR(12, SIGBUS, "stack segment", stack_segment) | 266 | DO_ERROR(12, SIGBUS, "stack segment", stack_segment) |
269 | #endif | 267 | #endif |
270 | DO_ERROR_INFO(17, SIGBUS, "alignment check", alignment_check, BUS_ADRALN, 0) | 268 | DO_ERROR_INFO(17, SIGBUS, "alignment check", alignment_check, BUS_ADRALN, 0) |
271 | 269 | ||
272 | #ifdef CONFIG_X86_64 | 270 | #ifdef CONFIG_X86_64 |
273 | /* Runs on IST stack */ | 271 | /* Runs on IST stack */ |
274 | dotraplinkage void do_stack_segment(struct pt_regs *regs, long error_code) | 272 | dotraplinkage void do_stack_segment(struct pt_regs *regs, long error_code) |
275 | { | 273 | { |
276 | if (notify_die(DIE_TRAP, "stack segment", regs, error_code, | 274 | if (notify_die(DIE_TRAP, "stack segment", regs, error_code, |
277 | 12, SIGBUS) == NOTIFY_STOP) | 275 | 12, SIGBUS) == NOTIFY_STOP) |
278 | return; | 276 | return; |
279 | preempt_conditional_sti(regs); | 277 | preempt_conditional_sti(regs); |
280 | do_trap(12, SIGBUS, "stack segment", regs, error_code, NULL); | 278 | do_trap(12, SIGBUS, "stack segment", regs, error_code, NULL); |
281 | preempt_conditional_cli(regs); | 279 | preempt_conditional_cli(regs); |
282 | } | 280 | } |
283 | 281 | ||
284 | dotraplinkage void do_double_fault(struct pt_regs *regs, long error_code) | 282 | dotraplinkage void do_double_fault(struct pt_regs *regs, long error_code) |
285 | { | 283 | { |
286 | static const char str[] = "double fault"; | 284 | static const char str[] = "double fault"; |
287 | struct task_struct *tsk = current; | 285 | struct task_struct *tsk = current; |
288 | 286 | ||
289 | /* Return not checked because double check cannot be ignored */ | 287 | /* Return not checked because double check cannot be ignored */ |
290 | notify_die(DIE_TRAP, str, regs, error_code, 8, SIGSEGV); | 288 | notify_die(DIE_TRAP, str, regs, error_code, 8, SIGSEGV); |
291 | 289 | ||
292 | tsk->thread.error_code = error_code; | 290 | tsk->thread.error_code = error_code; |
293 | tsk->thread.trap_no = 8; | 291 | tsk->thread.trap_no = 8; |
294 | 292 | ||
295 | /* | 293 | /* |
296 | * This is always a kernel trap and never fixable (and thus must | 294 | * This is always a kernel trap and never fixable (and thus must |
297 | * never return). | 295 | * never return). |
298 | */ | 296 | */ |
299 | for (;;) | 297 | for (;;) |
300 | die(str, regs, error_code); | 298 | die(str, regs, error_code); |
301 | } | 299 | } |
302 | #endif | 300 | #endif |
303 | 301 | ||
304 | dotraplinkage void __kprobes | 302 | dotraplinkage void __kprobes |
305 | do_general_protection(struct pt_regs *regs, long error_code) | 303 | do_general_protection(struct pt_regs *regs, long error_code) |
306 | { | 304 | { |
307 | struct task_struct *tsk; | 305 | struct task_struct *tsk; |
308 | 306 | ||
309 | conditional_sti(regs); | 307 | conditional_sti(regs); |
310 | 308 | ||
311 | #ifdef CONFIG_X86_32 | 309 | #ifdef CONFIG_X86_32 |
312 | if (lazy_iobitmap_copy()) { | 310 | if (lazy_iobitmap_copy()) { |
313 | /* restart the faulting instruction */ | 311 | /* restart the faulting instruction */ |
314 | return; | 312 | return; |
315 | } | 313 | } |
316 | 314 | ||
317 | if (regs->flags & X86_VM_MASK) | 315 | if (regs->flags & X86_VM_MASK) |
318 | goto gp_in_vm86; | 316 | goto gp_in_vm86; |
319 | #endif | 317 | #endif |
320 | 318 | ||
321 | tsk = current; | 319 | tsk = current; |
322 | if (!user_mode(regs)) | 320 | if (!user_mode(regs)) |
323 | goto gp_in_kernel; | 321 | goto gp_in_kernel; |
324 | 322 | ||
325 | tsk->thread.error_code = error_code; | 323 | tsk->thread.error_code = error_code; |
326 | tsk->thread.trap_no = 13; | 324 | tsk->thread.trap_no = 13; |
327 | 325 | ||
328 | if (show_unhandled_signals && unhandled_signal(tsk, SIGSEGV) && | 326 | if (show_unhandled_signals && unhandled_signal(tsk, SIGSEGV) && |
329 | printk_ratelimit()) { | 327 | printk_ratelimit()) { |
330 | printk(KERN_INFO | 328 | printk(KERN_INFO |
331 | "%s[%d] general protection ip:%lx sp:%lx error:%lx", | 329 | "%s[%d] general protection ip:%lx sp:%lx error:%lx", |
332 | tsk->comm, task_pid_nr(tsk), | 330 | tsk->comm, task_pid_nr(tsk), |
333 | regs->ip, regs->sp, error_code); | 331 | regs->ip, regs->sp, error_code); |
334 | print_vma_addr(" in ", regs->ip); | 332 | print_vma_addr(" in ", regs->ip); |
335 | printk("\n"); | 333 | printk("\n"); |
336 | } | 334 | } |
337 | 335 | ||
338 | force_sig(SIGSEGV, tsk); | 336 | force_sig(SIGSEGV, tsk); |
339 | return; | 337 | return; |
340 | 338 | ||
341 | #ifdef CONFIG_X86_32 | 339 | #ifdef CONFIG_X86_32 |
342 | gp_in_vm86: | 340 | gp_in_vm86: |
343 | local_irq_enable(); | 341 | local_irq_enable(); |
344 | handle_vm86_fault((struct kernel_vm86_regs *) regs, error_code); | 342 | handle_vm86_fault((struct kernel_vm86_regs *) regs, error_code); |
345 | return; | 343 | return; |
346 | #endif | 344 | #endif |
347 | 345 | ||
348 | gp_in_kernel: | 346 | gp_in_kernel: |
349 | if (fixup_exception(regs)) | 347 | if (fixup_exception(regs)) |
350 | return; | 348 | return; |
351 | 349 | ||
352 | tsk->thread.error_code = error_code; | 350 | tsk->thread.error_code = error_code; |
353 | tsk->thread.trap_no = 13; | 351 | tsk->thread.trap_no = 13; |
354 | if (notify_die(DIE_GPF, "general protection fault", regs, | 352 | if (notify_die(DIE_GPF, "general protection fault", regs, |
355 | error_code, 13, SIGSEGV) == NOTIFY_STOP) | 353 | error_code, 13, SIGSEGV) == NOTIFY_STOP) |
356 | return; | 354 | return; |
357 | die("general protection fault", regs, error_code); | 355 | die("general protection fault", regs, error_code); |
358 | } | 356 | } |
359 | 357 | ||
360 | static notrace __kprobes void | 358 | static notrace __kprobes void |
361 | mem_parity_error(unsigned char reason, struct pt_regs *regs) | 359 | mem_parity_error(unsigned char reason, struct pt_regs *regs) |
362 | { | 360 | { |
363 | printk(KERN_EMERG | 361 | printk(KERN_EMERG |
364 | "Uhhuh. NMI received for unknown reason %02x on CPU %d.\n", | 362 | "Uhhuh. NMI received for unknown reason %02x on CPU %d.\n", |
365 | reason, smp_processor_id()); | 363 | reason, smp_processor_id()); |
366 | 364 | ||
367 | printk(KERN_EMERG | 365 | printk(KERN_EMERG |
368 | "You have some hardware problem, likely on the PCI bus.\n"); | 366 | "You have some hardware problem, likely on the PCI bus.\n"); |
369 | 367 | ||
370 | #if defined(CONFIG_EDAC) | 368 | #if defined(CONFIG_EDAC) |
371 | if (edac_handler_set()) { | 369 | if (edac_handler_set()) { |
372 | edac_atomic_assert_error(); | 370 | edac_atomic_assert_error(); |
373 | return; | 371 | return; |
374 | } | 372 | } |
375 | #endif | 373 | #endif |
376 | 374 | ||
377 | if (panic_on_unrecovered_nmi) | 375 | if (panic_on_unrecovered_nmi) |
378 | panic("NMI: Not continuing"); | 376 | panic("NMI: Not continuing"); |
379 | 377 | ||
380 | printk(KERN_EMERG "Dazed and confused, but trying to continue\n"); | 378 | printk(KERN_EMERG "Dazed and confused, but trying to continue\n"); |
381 | 379 | ||
382 | /* Clear and disable the memory parity error line. */ | 380 | /* Clear and disable the memory parity error line. */ |
383 | reason = (reason & 0xf) | 4; | 381 | reason = (reason & 0xf) | 4; |
384 | outb(reason, 0x61); | 382 | outb(reason, 0x61); |
385 | } | 383 | } |
386 | 384 | ||
387 | static notrace __kprobes void | 385 | static notrace __kprobes void |
388 | io_check_error(unsigned char reason, struct pt_regs *regs) | 386 | io_check_error(unsigned char reason, struct pt_regs *regs) |
389 | { | 387 | { |
390 | unsigned long i; | 388 | unsigned long i; |
391 | 389 | ||
392 | printk(KERN_EMERG "NMI: IOCK error (debug interrupt?)\n"); | 390 | printk(KERN_EMERG "NMI: IOCK error (debug interrupt?)\n"); |
393 | show_registers(regs); | 391 | show_registers(regs); |
394 | 392 | ||
395 | /* Re-enable the IOCK line, wait for a few seconds */ | 393 | /* Re-enable the IOCK line, wait for a few seconds */ |
396 | reason = (reason & 0xf) | 8; | 394 | reason = (reason & 0xf) | 8; |
397 | outb(reason, 0x61); | 395 | outb(reason, 0x61); |
398 | 396 | ||
399 | i = 2000; | 397 | i = 2000; |
400 | while (--i) | 398 | while (--i) |
401 | udelay(1000); | 399 | udelay(1000); |
402 | 400 | ||
403 | reason &= ~8; | 401 | reason &= ~8; |
404 | outb(reason, 0x61); | 402 | outb(reason, 0x61); |
405 | } | 403 | } |
406 | 404 | ||
407 | static notrace __kprobes void | 405 | static notrace __kprobes void |
408 | unknown_nmi_error(unsigned char reason, struct pt_regs *regs) | 406 | unknown_nmi_error(unsigned char reason, struct pt_regs *regs) |
409 | { | 407 | { |
410 | if (notify_die(DIE_NMIUNKNOWN, "nmi", regs, reason, 2, SIGINT) == | 408 | if (notify_die(DIE_NMIUNKNOWN, "nmi", regs, reason, 2, SIGINT) == |
411 | NOTIFY_STOP) | 409 | NOTIFY_STOP) |
412 | return; | 410 | return; |
413 | #ifdef CONFIG_MCA | 411 | #ifdef CONFIG_MCA |
414 | /* | 412 | /* |
415 | * Might actually be able to figure out what the guilty party | 413 | * Might actually be able to figure out what the guilty party |
416 | * is: | 414 | * is: |
417 | */ | 415 | */ |
418 | if (MCA_bus) { | 416 | if (MCA_bus) { |
419 | mca_handle_nmi(); | 417 | mca_handle_nmi(); |
420 | return; | 418 | return; |
421 | } | 419 | } |
422 | #endif | 420 | #endif |
423 | printk(KERN_EMERG | 421 | printk(KERN_EMERG |
424 | "Uhhuh. NMI received for unknown reason %02x on CPU %d.\n", | 422 | "Uhhuh. NMI received for unknown reason %02x on CPU %d.\n", |
425 | reason, smp_processor_id()); | 423 | reason, smp_processor_id()); |
426 | 424 | ||
427 | printk(KERN_EMERG "Do you have a strange power saving mode enabled?\n"); | 425 | printk(KERN_EMERG "Do you have a strange power saving mode enabled?\n"); |
428 | if (panic_on_unrecovered_nmi) | 426 | if (panic_on_unrecovered_nmi) |
429 | panic("NMI: Not continuing"); | 427 | panic("NMI: Not continuing"); |
430 | 428 | ||
431 | printk(KERN_EMERG "Dazed and confused, but trying to continue\n"); | 429 | printk(KERN_EMERG "Dazed and confused, but trying to continue\n"); |
432 | } | 430 | } |
433 | 431 | ||
434 | static notrace __kprobes void default_do_nmi(struct pt_regs *regs) | 432 | static notrace __kprobes void default_do_nmi(struct pt_regs *regs) |
435 | { | 433 | { |
436 | unsigned char reason = 0; | 434 | unsigned char reason = 0; |
437 | int cpu; | 435 | int cpu; |
438 | 436 | ||
439 | cpu = smp_processor_id(); | 437 | cpu = smp_processor_id(); |
440 | 438 | ||
441 | /* Only the BSP gets external NMIs from the system. */ | 439 | /* Only the BSP gets external NMIs from the system. */ |
442 | if (!cpu) | 440 | if (!cpu) |
443 | reason = get_nmi_reason(); | 441 | reason = get_nmi_reason(); |
444 | 442 | ||
445 | if (!(reason & 0xc0)) { | 443 | if (!(reason & 0xc0)) { |
446 | if (notify_die(DIE_NMI_IPI, "nmi_ipi", regs, reason, 2, SIGINT) | 444 | if (notify_die(DIE_NMI_IPI, "nmi_ipi", regs, reason, 2, SIGINT) |
447 | == NOTIFY_STOP) | 445 | == NOTIFY_STOP) |
448 | return; | 446 | return; |
449 | #ifdef CONFIG_X86_LOCAL_APIC | 447 | #ifdef CONFIG_X86_LOCAL_APIC |
450 | /* | 448 | /* |
451 | * Ok, so this is none of the documented NMI sources, | 449 | * Ok, so this is none of the documented NMI sources, |
452 | * so it must be the NMI watchdog. | 450 | * so it must be the NMI watchdog. |
453 | */ | 451 | */ |
454 | if (nmi_watchdog_tick(regs, reason)) | 452 | if (nmi_watchdog_tick(regs, reason)) |
455 | return; | 453 | return; |
456 | if (!do_nmi_callback(regs, cpu)) | 454 | if (!do_nmi_callback(regs, cpu)) |
457 | unknown_nmi_error(reason, regs); | 455 | unknown_nmi_error(reason, regs); |
458 | #else | 456 | #else |
459 | unknown_nmi_error(reason, regs); | 457 | unknown_nmi_error(reason, regs); |
460 | #endif | 458 | #endif |
461 | 459 | ||
462 | return; | 460 | return; |
463 | } | 461 | } |
464 | if (notify_die(DIE_NMI, "nmi", regs, reason, 2, SIGINT) == NOTIFY_STOP) | 462 | if (notify_die(DIE_NMI, "nmi", regs, reason, 2, SIGINT) == NOTIFY_STOP) |
465 | return; | 463 | return; |
466 | 464 | ||
467 | /* AK: following checks seem to be broken on modern chipsets. FIXME */ | 465 | /* AK: following checks seem to be broken on modern chipsets. FIXME */ |
468 | if (reason & 0x80) | 466 | if (reason & 0x80) |
469 | mem_parity_error(reason, regs); | 467 | mem_parity_error(reason, regs); |
470 | if (reason & 0x40) | 468 | if (reason & 0x40) |
471 | io_check_error(reason, regs); | 469 | io_check_error(reason, regs); |
472 | #ifdef CONFIG_X86_32 | 470 | #ifdef CONFIG_X86_32 |
473 | /* | 471 | /* |
474 | * Reassert NMI in case it became active meanwhile | 472 | * Reassert NMI in case it became active meanwhile |
475 | * as it's edge-triggered: | 473 | * as it's edge-triggered: |
476 | */ | 474 | */ |
477 | reassert_nmi(); | 475 | reassert_nmi(); |
478 | #endif | 476 | #endif |
479 | } | 477 | } |
480 | 478 | ||
481 | dotraplinkage notrace __kprobes void | 479 | dotraplinkage notrace __kprobes void |
482 | do_nmi(struct pt_regs *regs, long error_code) | 480 | do_nmi(struct pt_regs *regs, long error_code) |
483 | { | 481 | { |
484 | nmi_enter(); | 482 | nmi_enter(); |
485 | 483 | ||
486 | inc_irq_stat(__nmi_count); | 484 | inc_irq_stat(__nmi_count); |
487 | 485 | ||
488 | if (!ignore_nmis) | 486 | if (!ignore_nmis) |
489 | default_do_nmi(regs); | 487 | default_do_nmi(regs); |
490 | 488 | ||
491 | nmi_exit(); | 489 | nmi_exit(); |
492 | } | 490 | } |
493 | 491 | ||
494 | void stop_nmi(void) | 492 | void stop_nmi(void) |
495 | { | 493 | { |
496 | acpi_nmi_disable(); | 494 | acpi_nmi_disable(); |
497 | ignore_nmis++; | 495 | ignore_nmis++; |
498 | } | 496 | } |
499 | 497 | ||
500 | void restart_nmi(void) | 498 | void restart_nmi(void) |
501 | { | 499 | { |
502 | ignore_nmis--; | 500 | ignore_nmis--; |
503 | acpi_nmi_enable(); | 501 | acpi_nmi_enable(); |
504 | } | 502 | } |
505 | 503 | ||
506 | /* May run on IST stack. */ | 504 | /* May run on IST stack. */ |
507 | dotraplinkage void __kprobes do_int3(struct pt_regs *regs, long error_code) | 505 | dotraplinkage void __kprobes do_int3(struct pt_regs *regs, long error_code) |
508 | { | 506 | { |
509 | #ifdef CONFIG_KPROBES | 507 | #ifdef CONFIG_KPROBES |
510 | if (notify_die(DIE_INT3, "int3", regs, error_code, 3, SIGTRAP) | 508 | if (notify_die(DIE_INT3, "int3", regs, error_code, 3, SIGTRAP) |
511 | == NOTIFY_STOP) | 509 | == NOTIFY_STOP) |
512 | return; | 510 | return; |
513 | #else | 511 | #else |
514 | if (notify_die(DIE_TRAP, "int3", regs, error_code, 3, SIGTRAP) | 512 | if (notify_die(DIE_TRAP, "int3", regs, error_code, 3, SIGTRAP) |
515 | == NOTIFY_STOP) | 513 | == NOTIFY_STOP) |
516 | return; | 514 | return; |
517 | #endif | 515 | #endif |
518 | 516 | ||
519 | preempt_conditional_sti(regs); | 517 | preempt_conditional_sti(regs); |
520 | do_trap(3, SIGTRAP, "int3", regs, error_code, NULL); | 518 | do_trap(3, SIGTRAP, "int3", regs, error_code, NULL); |
521 | preempt_conditional_cli(regs); | 519 | preempt_conditional_cli(regs); |
522 | } | 520 | } |
523 | 521 | ||
524 | #ifdef CONFIG_X86_64 | 522 | #ifdef CONFIG_X86_64 |
525 | /* | 523 | /* |
526 | * Help handler running on IST stack to switch back to user stack | 524 | * Help handler running on IST stack to switch back to user stack |
527 | * for scheduling or signal handling. The actual stack switch is done in | 525 | * for scheduling or signal handling. The actual stack switch is done in |
528 | * entry.S | 526 | * entry.S |
529 | */ | 527 | */ |
530 | asmlinkage __kprobes struct pt_regs *sync_regs(struct pt_regs *eregs) | 528 | asmlinkage __kprobes struct pt_regs *sync_regs(struct pt_regs *eregs) |
531 | { | 529 | { |
532 | struct pt_regs *regs = eregs; | 530 | struct pt_regs *regs = eregs; |
533 | /* Did already sync */ | 531 | /* Did already sync */ |
534 | if (eregs == (struct pt_regs *)eregs->sp) | 532 | if (eregs == (struct pt_regs *)eregs->sp) |
535 | ; | 533 | ; |
536 | /* Exception from user space */ | 534 | /* Exception from user space */ |
537 | else if (user_mode(eregs)) | 535 | else if (user_mode(eregs)) |
538 | regs = task_pt_regs(current); | 536 | regs = task_pt_regs(current); |
539 | /* | 537 | /* |
540 | * Exception from kernel and interrupts are enabled. Move to | 538 | * Exception from kernel and interrupts are enabled. Move to |
541 | * kernel process stack. | 539 | * kernel process stack. |
542 | */ | 540 | */ |
543 | else if (eregs->flags & X86_EFLAGS_IF) | 541 | else if (eregs->flags & X86_EFLAGS_IF) |
544 | regs = (struct pt_regs *)(eregs->sp -= sizeof(struct pt_regs)); | 542 | regs = (struct pt_regs *)(eregs->sp -= sizeof(struct pt_regs)); |
545 | if (eregs != regs) | 543 | if (eregs != regs) |
546 | *regs = *eregs; | 544 | *regs = *eregs; |
547 | return regs; | 545 | return regs; |
548 | } | 546 | } |
549 | #endif | 547 | #endif |
550 | 548 | ||
551 | /* | 549 | /* |
552 | * Our handling of the processor debug registers is non-trivial. | 550 | * Our handling of the processor debug registers is non-trivial. |
553 | * We do not clear them on entry and exit from the kernel. Therefore | 551 | * We do not clear them on entry and exit from the kernel. Therefore |
554 | * it is possible to get a watchpoint trap here from inside the kernel. | 552 | * it is possible to get a watchpoint trap here from inside the kernel. |
555 | * However, the code in ./ptrace.c has ensured that the user can | 553 | * However, the code in ./ptrace.c has ensured that the user can |
556 | * only set watchpoints on userspace addresses. Therefore the in-kernel | 554 | * only set watchpoints on userspace addresses. Therefore the in-kernel |
557 | * watchpoint trap can only occur in code which is reading/writing | 555 | * watchpoint trap can only occur in code which is reading/writing |
558 | * from user space. Such code must not hold kernel locks (since it | 556 | * from user space. Such code must not hold kernel locks (since it |
559 | * can equally take a page fault), therefore it is safe to call | 557 | * can equally take a page fault), therefore it is safe to call |
560 | * force_sig_info even though that claims and releases locks. | 558 | * force_sig_info even though that claims and releases locks. |
561 | * | 559 | * |
562 | * Code in ./signal.c ensures that the debug control register | 560 | * Code in ./signal.c ensures that the debug control register |
563 | * is restored before we deliver any signal, and therefore that | 561 | * is restored before we deliver any signal, and therefore that |
564 | * user code runs with the correct debug control register even though | 562 | * user code runs with the correct debug control register even though |
565 | * we clear it here. | 563 | * we clear it here. |
566 | * | 564 | * |
567 | * Being careful here means that we don't have to be as careful in a | 565 | * Being careful here means that we don't have to be as careful in a |
568 | * lot of more complicated places (task switching can be a bit lazy | 566 | * lot of more complicated places (task switching can be a bit lazy |
569 | * about restoring all the debug state, and ptrace doesn't have to | 567 | * about restoring all the debug state, and ptrace doesn't have to |
570 | * find every occurrence of the TF bit that could be saved away even | 568 | * find every occurrence of the TF bit that could be saved away even |
571 | * by user code) | 569 | * by user code) |
572 | * | 570 | * |
573 | * May run on IST stack. | 571 | * May run on IST stack. |
574 | */ | 572 | */ |
575 | dotraplinkage void __kprobes do_debug(struct pt_regs *regs, long error_code) | 573 | dotraplinkage void __kprobes do_debug(struct pt_regs *regs, long error_code) |
576 | { | 574 | { |
577 | struct task_struct *tsk = current; | 575 | struct task_struct *tsk = current; |
578 | unsigned long condition; | 576 | unsigned long condition; |
579 | int si_code; | 577 | int si_code; |
580 | 578 | ||
581 | get_debugreg(condition, 6); | 579 | get_debugreg(condition, 6); |
582 | 580 | ||
583 | /* | 581 | /* |
584 | * The processor cleared BTF, so don't mark that we need it set. | 582 | * The processor cleared BTF, so don't mark that we need it set. |
585 | */ | 583 | */ |
586 | clear_tsk_thread_flag(tsk, TIF_DEBUGCTLMSR); | 584 | clear_tsk_thread_flag(tsk, TIF_DEBUGCTLMSR); |
587 | tsk->thread.debugctlmsr = 0; | 585 | tsk->thread.debugctlmsr = 0; |
588 | 586 | ||
589 | if (notify_die(DIE_DEBUG, "debug", regs, condition, error_code, | 587 | if (notify_die(DIE_DEBUG, "debug", regs, condition, error_code, |
590 | SIGTRAP) == NOTIFY_STOP) | 588 | SIGTRAP) == NOTIFY_STOP) |
591 | return; | 589 | return; |
592 | 590 | ||
593 | /* It's safe to allow irq's after DR6 has been saved */ | 591 | /* It's safe to allow irq's after DR6 has been saved */ |
594 | preempt_conditional_sti(regs); | 592 | preempt_conditional_sti(regs); |
595 | 593 | ||
596 | /* Mask out spurious debug traps due to lazy DR7 setting */ | 594 | /* Mask out spurious debug traps due to lazy DR7 setting */ |
597 | if (condition & (DR_TRAP0|DR_TRAP1|DR_TRAP2|DR_TRAP3)) { | 595 | if (condition & (DR_TRAP0|DR_TRAP1|DR_TRAP2|DR_TRAP3)) { |
598 | if (!tsk->thread.debugreg7) | 596 | if (!tsk->thread.debugreg7) |
599 | goto clear_dr7; | 597 | goto clear_dr7; |
600 | } | 598 | } |
601 | 599 | ||
602 | #ifdef CONFIG_X86_32 | 600 | #ifdef CONFIG_X86_32 |
603 | if (regs->flags & X86_VM_MASK) | 601 | if (regs->flags & X86_VM_MASK) |
604 | goto debug_vm86; | 602 | goto debug_vm86; |
605 | #endif | 603 | #endif |
606 | 604 | ||
607 | /* Save debug status register where ptrace can see it */ | 605 | /* Save debug status register where ptrace can see it */ |
608 | tsk->thread.debugreg6 = condition; | 606 | tsk->thread.debugreg6 = condition; |
609 | 607 | ||
610 | /* | 608 | /* |
611 | * Single-stepping through TF: make sure we ignore any events in | 609 | * Single-stepping through TF: make sure we ignore any events in |
612 | * kernel space (but re-enable TF when returning to user mode). | 610 | * kernel space (but re-enable TF when returning to user mode). |
613 | */ | 611 | */ |
614 | if (condition & DR_STEP) { | 612 | if (condition & DR_STEP) { |
615 | if (!user_mode(regs)) | 613 | if (!user_mode(regs)) |
616 | goto clear_TF_reenable; | 614 | goto clear_TF_reenable; |
617 | } | 615 | } |
618 | 616 | ||
619 | si_code = get_si_code(condition); | 617 | si_code = get_si_code(condition); |
620 | /* Ok, finally something we can handle */ | 618 | /* Ok, finally something we can handle */ |
621 | send_sigtrap(tsk, regs, error_code, si_code); | 619 | send_sigtrap(tsk, regs, error_code, si_code); |
622 | 620 | ||
623 | /* | 621 | /* |
624 | * Disable additional traps. They'll be re-enabled when | 622 | * Disable additional traps. They'll be re-enabled when |
625 | * the signal is delivered. | 623 | * the signal is delivered. |
626 | */ | 624 | */ |
627 | clear_dr7: | 625 | clear_dr7: |
628 | set_debugreg(0, 7); | 626 | set_debugreg(0, 7); |
629 | preempt_conditional_cli(regs); | 627 | preempt_conditional_cli(regs); |
630 | return; | 628 | return; |
631 | 629 | ||
632 | #ifdef CONFIG_X86_32 | 630 | #ifdef CONFIG_X86_32 |
633 | debug_vm86: | 631 | debug_vm86: |
634 | handle_vm86_trap((struct kernel_vm86_regs *) regs, error_code, 1); | 632 | handle_vm86_trap((struct kernel_vm86_regs *) regs, error_code, 1); |
635 | preempt_conditional_cli(regs); | 633 | preempt_conditional_cli(regs); |
636 | return; | 634 | return; |
637 | #endif | 635 | #endif |
638 | 636 | ||
639 | clear_TF_reenable: | 637 | clear_TF_reenable: |
640 | set_tsk_thread_flag(tsk, TIF_SINGLESTEP); | 638 | set_tsk_thread_flag(tsk, TIF_SINGLESTEP); |
641 | regs->flags &= ~X86_EFLAGS_TF; | 639 | regs->flags &= ~X86_EFLAGS_TF; |
642 | preempt_conditional_cli(regs); | 640 | preempt_conditional_cli(regs); |
643 | return; | 641 | return; |
644 | } | 642 | } |
645 | 643 | ||
646 | #ifdef CONFIG_X86_64 | 644 | #ifdef CONFIG_X86_64 |
647 | static int kernel_math_error(struct pt_regs *regs, const char *str, int trapnr) | 645 | static int kernel_math_error(struct pt_regs *regs, const char *str, int trapnr) |
648 | { | 646 | { |
649 | if (fixup_exception(regs)) | 647 | if (fixup_exception(regs)) |
650 | return 1; | 648 | return 1; |
651 | 649 | ||
652 | notify_die(DIE_GPF, str, regs, 0, trapnr, SIGFPE); | 650 | notify_die(DIE_GPF, str, regs, 0, trapnr, SIGFPE); |
653 | /* Illegal floating point operation in the kernel */ | 651 | /* Illegal floating point operation in the kernel */ |
654 | current->thread.trap_no = trapnr; | 652 | current->thread.trap_no = trapnr; |
655 | die(str, regs, 0); | 653 | die(str, regs, 0); |
656 | return 0; | 654 | return 0; |
657 | } | 655 | } |
658 | #endif | 656 | #endif |
659 | 657 | ||
660 | /* | 658 | /* |
661 | * Note that we play around with the 'TS' bit in an attempt to get | 659 | * Note that we play around with the 'TS' bit in an attempt to get |
662 | * the correct behaviour even in the presence of the asynchronous | 660 | * the correct behaviour even in the presence of the asynchronous |
663 | * IRQ13 behaviour | 661 | * IRQ13 behaviour |
664 | */ | 662 | */ |
665 | void math_error(void __user *ip) | 663 | void math_error(void __user *ip) |
666 | { | 664 | { |
667 | struct task_struct *task; | 665 | struct task_struct *task; |
668 | siginfo_t info; | 666 | siginfo_t info; |
669 | unsigned short cwd, swd, err; | 667 | unsigned short cwd, swd, err; |
670 | 668 | ||
671 | /* | 669 | /* |
672 | * Save the info for the exception handler and clear the error. | 670 | * Save the info for the exception handler and clear the error. |
673 | */ | 671 | */ |
674 | task = current; | 672 | task = current; |
675 | save_init_fpu(task); | 673 | save_init_fpu(task); |
676 | task->thread.trap_no = 16; | 674 | task->thread.trap_no = 16; |
677 | task->thread.error_code = 0; | 675 | task->thread.error_code = 0; |
678 | info.si_signo = SIGFPE; | 676 | info.si_signo = SIGFPE; |
679 | info.si_errno = 0; | 677 | info.si_errno = 0; |
680 | info.si_addr = ip; | 678 | info.si_addr = ip; |
681 | /* | 679 | /* |
682 | * (~cwd & swd) will mask out exceptions that are not set to unmasked | 680 | * (~cwd & swd) will mask out exceptions that are not set to unmasked |
683 | * status. 0x3f is the exception bits in these regs, 0x200 is the | 681 | * status. 0x3f is the exception bits in these regs, 0x200 is the |
684 | * C1 reg you need in case of a stack fault, 0x040 is the stack | 682 | * C1 reg you need in case of a stack fault, 0x040 is the stack |
685 | * fault bit. We should only be taking one exception at a time, | 683 | * fault bit. We should only be taking one exception at a time, |
686 | * so if this combination doesn't produce any single exception, | 684 | * so if this combination doesn't produce any single exception, |
687 | * then we have a bad program that isn't synchronizing its FPU usage | 685 | * then we have a bad program that isn't synchronizing its FPU usage |
688 | * and it will suffer the consequences since we won't be able to | 686 | * and it will suffer the consequences since we won't be able to |
689 | * fully reproduce the context of the exception | 687 | * fully reproduce the context of the exception |
690 | */ | 688 | */ |
691 | cwd = get_fpu_cwd(task); | 689 | cwd = get_fpu_cwd(task); |
692 | swd = get_fpu_swd(task); | 690 | swd = get_fpu_swd(task); |
693 | 691 | ||
694 | err = swd & ~cwd; | 692 | err = swd & ~cwd; |
695 | 693 | ||
696 | if (err & 0x001) { /* Invalid op */ | 694 | if (err & 0x001) { /* Invalid op */ |
697 | /* | 695 | /* |
698 | * swd & 0x240 == 0x040: Stack Underflow | 696 | * swd & 0x240 == 0x040: Stack Underflow |
699 | * swd & 0x240 == 0x240: Stack Overflow | 697 | * swd & 0x240 == 0x240: Stack Overflow |
700 | * User must clear the SF bit (0x40) if set | 698 | * User must clear the SF bit (0x40) if set |
701 | */ | 699 | */ |
702 | info.si_code = FPE_FLTINV; | 700 | info.si_code = FPE_FLTINV; |
703 | } else if (err & 0x004) { /* Divide by Zero */ | 701 | } else if (err & 0x004) { /* Divide by Zero */ |
704 | info.si_code = FPE_FLTDIV; | 702 | info.si_code = FPE_FLTDIV; |
705 | } else if (err & 0x008) { /* Overflow */ | 703 | } else if (err & 0x008) { /* Overflow */ |
706 | info.si_code = FPE_FLTOVF; | 704 | info.si_code = FPE_FLTOVF; |
707 | } else if (err & 0x012) { /* Denormal, Underflow */ | 705 | } else if (err & 0x012) { /* Denormal, Underflow */ |
708 | info.si_code = FPE_FLTUND; | 706 | info.si_code = FPE_FLTUND; |
709 | } else if (err & 0x020) { /* Precision */ | 707 | } else if (err & 0x020) { /* Precision */ |
710 | info.si_code = FPE_FLTRES; | 708 | info.si_code = FPE_FLTRES; |
711 | } else { | 709 | } else { |
712 | /* | 710 | /* |
713 | * If we're using IRQ 13, or supposedly even some trap 16 | 711 | * If we're using IRQ 13, or supposedly even some trap 16 |
714 | * implementations, it's possible we get a spurious trap... | 712 | * implementations, it's possible we get a spurious trap... |
715 | */ | 713 | */ |
716 | return; /* Spurious trap, no error */ | 714 | return; /* Spurious trap, no error */ |
717 | } | 715 | } |
718 | force_sig_info(SIGFPE, &info, task); | 716 | force_sig_info(SIGFPE, &info, task); |
719 | } | 717 | } |
720 | 718 | ||
721 | dotraplinkage void do_coprocessor_error(struct pt_regs *regs, long error_code) | 719 | dotraplinkage void do_coprocessor_error(struct pt_regs *regs, long error_code) |
722 | { | 720 | { |
723 | conditional_sti(regs); | 721 | conditional_sti(regs); |
724 | 722 | ||
725 | #ifdef CONFIG_X86_32 | 723 | #ifdef CONFIG_X86_32 |
726 | ignore_fpu_irq = 1; | 724 | ignore_fpu_irq = 1; |
727 | #else | 725 | #else |
728 | if (!user_mode(regs) && | 726 | if (!user_mode(regs) && |
729 | kernel_math_error(regs, "kernel x87 math error", 16)) | 727 | kernel_math_error(regs, "kernel x87 math error", 16)) |
730 | return; | 728 | return; |
731 | #endif | 729 | #endif |
732 | 730 | ||
733 | math_error((void __user *)regs->ip); | 731 | math_error((void __user *)regs->ip); |
734 | } | 732 | } |
735 | 733 | ||
736 | static void simd_math_error(void __user *ip) | 734 | static void simd_math_error(void __user *ip) |
737 | { | 735 | { |
738 | struct task_struct *task; | 736 | struct task_struct *task; |
739 | siginfo_t info; | 737 | siginfo_t info; |
740 | unsigned short mxcsr; | 738 | unsigned short mxcsr; |
741 | 739 | ||
742 | /* | 740 | /* |
743 | * Save the info for the exception handler and clear the error. | 741 | * Save the info for the exception handler and clear the error. |
744 | */ | 742 | */ |
745 | task = current; | 743 | task = current; |
746 | save_init_fpu(task); | 744 | save_init_fpu(task); |
747 | task->thread.trap_no = 19; | 745 | task->thread.trap_no = 19; |
748 | task->thread.error_code = 0; | 746 | task->thread.error_code = 0; |
749 | info.si_signo = SIGFPE; | 747 | info.si_signo = SIGFPE; |
750 | info.si_errno = 0; | 748 | info.si_errno = 0; |
751 | info.si_code = __SI_FAULT; | 749 | info.si_code = __SI_FAULT; |
752 | info.si_addr = ip; | 750 | info.si_addr = ip; |
753 | /* | 751 | /* |
754 | * The SIMD FPU exceptions are handled a little differently, as there | 752 | * The SIMD FPU exceptions are handled a little differently, as there |
755 | * is only a single status/control register. Thus, to determine which | 753 | * is only a single status/control register. Thus, to determine which |
756 | * unmasked exception was caught we must mask the exception mask bits | 754 | * unmasked exception was caught we must mask the exception mask bits |
757 | * at 0x1f80, and then use these to mask the exception bits at 0x3f. | 755 | * at 0x1f80, and then use these to mask the exception bits at 0x3f. |
758 | */ | 756 | */ |
759 | mxcsr = get_fpu_mxcsr(task); | 757 | mxcsr = get_fpu_mxcsr(task); |
760 | switch (~((mxcsr & 0x1f80) >> 7) & (mxcsr & 0x3f)) { | 758 | switch (~((mxcsr & 0x1f80) >> 7) & (mxcsr & 0x3f)) { |
761 | case 0x000: | 759 | case 0x000: |
762 | default: | 760 | default: |
763 | break; | 761 | break; |
764 | case 0x001: /* Invalid Op */ | 762 | case 0x001: /* Invalid Op */ |
765 | info.si_code = FPE_FLTINV; | 763 | info.si_code = FPE_FLTINV; |
766 | break; | 764 | break; |
767 | case 0x002: /* Denormalize */ | 765 | case 0x002: /* Denormalize */ |
768 | case 0x010: /* Underflow */ | 766 | case 0x010: /* Underflow */ |
769 | info.si_code = FPE_FLTUND; | 767 | info.si_code = FPE_FLTUND; |
770 | break; | 768 | break; |
771 | case 0x004: /* Zero Divide */ | 769 | case 0x004: /* Zero Divide */ |
772 | info.si_code = FPE_FLTDIV; | 770 | info.si_code = FPE_FLTDIV; |
773 | break; | 771 | break; |
774 | case 0x008: /* Overflow */ | 772 | case 0x008: /* Overflow */ |
775 | info.si_code = FPE_FLTOVF; | 773 | info.si_code = FPE_FLTOVF; |
776 | break; | 774 | break; |
777 | case 0x020: /* Precision */ | 775 | case 0x020: /* Precision */ |
778 | info.si_code = FPE_FLTRES; | 776 | info.si_code = FPE_FLTRES; |
779 | break; | 777 | break; |
780 | } | 778 | } |
781 | force_sig_info(SIGFPE, &info, task); | 779 | force_sig_info(SIGFPE, &info, task); |
782 | } | 780 | } |
783 | 781 | ||
784 | dotraplinkage void | 782 | dotraplinkage void |
785 | do_simd_coprocessor_error(struct pt_regs *regs, long error_code) | 783 | do_simd_coprocessor_error(struct pt_regs *regs, long error_code) |
786 | { | 784 | { |
787 | conditional_sti(regs); | 785 | conditional_sti(regs); |
788 | 786 | ||
789 | #ifdef CONFIG_X86_32 | 787 | #ifdef CONFIG_X86_32 |
790 | if (cpu_has_xmm) { | 788 | if (cpu_has_xmm) { |
791 | /* Handle SIMD FPU exceptions on PIII+ processors. */ | 789 | /* Handle SIMD FPU exceptions on PIII+ processors. */ |
792 | ignore_fpu_irq = 1; | 790 | ignore_fpu_irq = 1; |
793 | simd_math_error((void __user *)regs->ip); | 791 | simd_math_error((void __user *)regs->ip); |
794 | return; | 792 | return; |
795 | } | 793 | } |
796 | /* | 794 | /* |
797 | * Handle strange cache flush from user space exception | 795 | * Handle strange cache flush from user space exception |
798 | * in all other cases. This is undocumented behaviour. | 796 | * in all other cases. This is undocumented behaviour. |
799 | */ | 797 | */ |
800 | if (regs->flags & X86_VM_MASK) { | 798 | if (regs->flags & X86_VM_MASK) { |
801 | handle_vm86_fault((struct kernel_vm86_regs *)regs, error_code); | 799 | handle_vm86_fault((struct kernel_vm86_regs *)regs, error_code); |
802 | return; | 800 | return; |
803 | } | 801 | } |
804 | current->thread.trap_no = 19; | 802 | current->thread.trap_no = 19; |
805 | current->thread.error_code = error_code; | 803 | current->thread.error_code = error_code; |
806 | die_if_kernel("cache flush denied", regs, error_code); | 804 | die_if_kernel("cache flush denied", regs, error_code); |
807 | force_sig(SIGSEGV, current); | 805 | force_sig(SIGSEGV, current); |
808 | #else | 806 | #else |
809 | if (!user_mode(regs) && | 807 | if (!user_mode(regs) && |
810 | kernel_math_error(regs, "kernel simd math error", 19)) | 808 | kernel_math_error(regs, "kernel simd math error", 19)) |
811 | return; | 809 | return; |
812 | simd_math_error((void __user *)regs->ip); | 810 | simd_math_error((void __user *)regs->ip); |
813 | #endif | 811 | #endif |
814 | } | 812 | } |
815 | 813 | ||
816 | dotraplinkage void | 814 | dotraplinkage void |
817 | do_spurious_interrupt_bug(struct pt_regs *regs, long error_code) | 815 | do_spurious_interrupt_bug(struct pt_regs *regs, long error_code) |
818 | { | 816 | { |
819 | conditional_sti(regs); | 817 | conditional_sti(regs); |
820 | #if 0 | 818 | #if 0 |
821 | /* No need to warn about this any longer. */ | 819 | /* No need to warn about this any longer. */ |
822 | printk(KERN_INFO "Ignoring P6 Local APIC Spurious Interrupt Bug...\n"); | 820 | printk(KERN_INFO "Ignoring P6 Local APIC Spurious Interrupt Bug...\n"); |
823 | #endif | 821 | #endif |
824 | } | 822 | } |
825 | 823 | ||
826 | #ifdef CONFIG_X86_32 | 824 | #ifdef CONFIG_X86_32 |
827 | unsigned long patch_espfix_desc(unsigned long uesp, unsigned long kesp) | 825 | unsigned long patch_espfix_desc(unsigned long uesp, unsigned long kesp) |
828 | { | 826 | { |
829 | struct desc_struct *gdt = get_cpu_gdt_table(smp_processor_id()); | 827 | struct desc_struct *gdt = get_cpu_gdt_table(smp_processor_id()); |
830 | unsigned long base = (kesp - uesp) & -THREAD_SIZE; | 828 | unsigned long base = (kesp - uesp) & -THREAD_SIZE; |
831 | unsigned long new_kesp = kesp - base; | 829 | unsigned long new_kesp = kesp - base; |
832 | unsigned long lim_pages = (new_kesp | (THREAD_SIZE - 1)) >> PAGE_SHIFT; | 830 | unsigned long lim_pages = (new_kesp | (THREAD_SIZE - 1)) >> PAGE_SHIFT; |
833 | __u64 desc = *(__u64 *)&gdt[GDT_ENTRY_ESPFIX_SS]; | 831 | __u64 desc = *(__u64 *)&gdt[GDT_ENTRY_ESPFIX_SS]; |
834 | 832 | ||
835 | /* Set up base for espfix segment */ | 833 | /* Set up base for espfix segment */ |
836 | desc &= 0x00f0ff0000000000ULL; | 834 | desc &= 0x00f0ff0000000000ULL; |
837 | desc |= ((((__u64)base) << 16) & 0x000000ffffff0000ULL) | | 835 | desc |= ((((__u64)base) << 16) & 0x000000ffffff0000ULL) | |
838 | ((((__u64)base) << 32) & 0xff00000000000000ULL) | | 836 | ((((__u64)base) << 32) & 0xff00000000000000ULL) | |
839 | ((((__u64)lim_pages) << 32) & 0x000f000000000000ULL) | | 837 | ((((__u64)lim_pages) << 32) & 0x000f000000000000ULL) | |
840 | (lim_pages & 0xffff); | 838 | (lim_pages & 0xffff); |
841 | *(__u64 *)&gdt[GDT_ENTRY_ESPFIX_SS] = desc; | 839 | *(__u64 *)&gdt[GDT_ENTRY_ESPFIX_SS] = desc; |
842 | 840 | ||
843 | return new_kesp; | 841 | return new_kesp; |
844 | } | 842 | } |
845 | #else | 843 | #else |
846 | asmlinkage void __attribute__((weak)) smp_thermal_interrupt(void) | 844 | asmlinkage void __attribute__((weak)) smp_thermal_interrupt(void) |
847 | { | 845 | { |
848 | } | 846 | } |
849 | 847 | ||
850 | asmlinkage void __attribute__((weak)) mce_threshold_interrupt(void) | 848 | asmlinkage void __attribute__((weak)) mce_threshold_interrupt(void) |
851 | { | 849 | { |
852 | } | 850 | } |
853 | #endif | 851 | #endif |
854 | 852 | ||
855 | /* | 853 | /* |
856 | * 'math_state_restore()' saves the current math information in the | 854 | * 'math_state_restore()' saves the current math information in the |
857 | * old math state array, and gets the new ones from the current task | 855 | * old math state array, and gets the new ones from the current task |
858 | * | 856 | * |
859 | * Careful.. There are problems with IBM-designed IRQ13 behaviour. | 857 | * Careful.. There are problems with IBM-designed IRQ13 behaviour. |
860 | * Don't touch unless you *really* know how it works. | 858 | * Don't touch unless you *really* know how it works. |
861 | * | 859 | * |
862 | * Must be called with kernel preemption disabled (in this case, | 860 | * Must be called with kernel preemption disabled (in this case, |
863 | * local interrupts are disabled at the call-site in entry.S). | 861 | * local interrupts are disabled at the call-site in entry.S). |
864 | */ | 862 | */ |
865 | asmlinkage void math_state_restore(void) | 863 | asmlinkage void math_state_restore(void) |
866 | { | 864 | { |
867 | struct thread_info *thread = current_thread_info(); | 865 | struct thread_info *thread = current_thread_info(); |
868 | struct task_struct *tsk = thread->task; | 866 | struct task_struct *tsk = thread->task; |
869 | 867 | ||
870 | if (!tsk_used_math(tsk)) { | 868 | if (!tsk_used_math(tsk)) { |
871 | local_irq_enable(); | 869 | local_irq_enable(); |
872 | /* | 870 | /* |
873 | * does a slab alloc which can sleep | 871 | * does a slab alloc which can sleep |
874 | */ | 872 | */ |
875 | if (init_fpu(tsk)) { | 873 | if (init_fpu(tsk)) { |
876 | /* | 874 | /* |
877 | * ran out of memory! | 875 | * ran out of memory! |
878 | */ | 876 | */ |
879 | do_group_exit(SIGKILL); | 877 | do_group_exit(SIGKILL); |
880 | return; | 878 | return; |
881 | } | 879 | } |
882 | local_irq_disable(); | 880 | local_irq_disable(); |
883 | } | 881 | } |
884 | 882 | ||
885 | clts(); /* Allow maths ops (or we recurse) */ | 883 | clts(); /* Allow maths ops (or we recurse) */ |
886 | #ifdef CONFIG_X86_32 | 884 | #ifdef CONFIG_X86_32 |
887 | restore_fpu(tsk); | 885 | restore_fpu(tsk); |
888 | #else | 886 | #else |
889 | /* | 887 | /* |
890 | * Paranoid restore. send a SIGSEGV if we fail to restore the state. | 888 | * Paranoid restore. send a SIGSEGV if we fail to restore the state. |
891 | */ | 889 | */ |
892 | if (unlikely(restore_fpu_checking(tsk))) { | 890 | if (unlikely(restore_fpu_checking(tsk))) { |
893 | stts(); | 891 | stts(); |
894 | force_sig(SIGSEGV, tsk); | 892 | force_sig(SIGSEGV, tsk); |
895 | return; | 893 | return; |
896 | } | 894 | } |
897 | #endif | 895 | #endif |
898 | thread->status |= TS_USEDFPU; /* So we fnsave on switch_to() */ | 896 | thread->status |= TS_USEDFPU; /* So we fnsave on switch_to() */ |
899 | tsk->fpu_counter++; | 897 | tsk->fpu_counter++; |
900 | } | 898 | } |
901 | EXPORT_SYMBOL_GPL(math_state_restore); | 899 | EXPORT_SYMBOL_GPL(math_state_restore); |
902 | 900 | ||
903 | #ifndef CONFIG_MATH_EMULATION | 901 | #ifndef CONFIG_MATH_EMULATION |
904 | asmlinkage void math_emulate(long arg) | 902 | asmlinkage void math_emulate(long arg) |
905 | { | 903 | { |
906 | printk(KERN_EMERG | 904 | printk(KERN_EMERG |
907 | "math-emulation not enabled and no coprocessor found.\n"); | 905 | "math-emulation not enabled and no coprocessor found.\n"); |
908 | printk(KERN_EMERG "killing %s.\n", current->comm); | 906 | printk(KERN_EMERG "killing %s.\n", current->comm); |
909 | force_sig(SIGFPE, current); | 907 | force_sig(SIGFPE, current); |
910 | schedule(); | 908 | schedule(); |
911 | } | 909 | } |
912 | #endif /* CONFIG_MATH_EMULATION */ | 910 | #endif /* CONFIG_MATH_EMULATION */ |
913 | 911 | ||
914 | dotraplinkage void __kprobes | 912 | dotraplinkage void __kprobes |
915 | do_device_not_available(struct pt_regs *regs, long error) | 913 | do_device_not_available(struct pt_regs *regs, long error) |
916 | { | 914 | { |
917 | #ifdef CONFIG_X86_32 | 915 | #ifdef CONFIG_X86_32 |
918 | if (read_cr0() & X86_CR0_EM) { | 916 | if (read_cr0() & X86_CR0_EM) { |
919 | conditional_sti(regs); | 917 | conditional_sti(regs); |
920 | math_emulate(0); | 918 | math_emulate(0); |
921 | } else { | 919 | } else { |
922 | math_state_restore(); /* interrupts still off */ | 920 | math_state_restore(); /* interrupts still off */ |
923 | conditional_sti(regs); | 921 | conditional_sti(regs); |
924 | } | 922 | } |
925 | #else | 923 | #else |
926 | math_state_restore(); | 924 | math_state_restore(); |
927 | #endif | 925 | #endif |
928 | } | 926 | } |
929 | 927 | ||
930 | #ifdef CONFIG_X86_32 | 928 | #ifdef CONFIG_X86_32 |
931 | dotraplinkage void do_iret_error(struct pt_regs *regs, long error_code) | 929 | dotraplinkage void do_iret_error(struct pt_regs *regs, long error_code) |
932 | { | 930 | { |
933 | siginfo_t info; | 931 | siginfo_t info; |
934 | local_irq_enable(); | 932 | local_irq_enable(); |
935 | 933 | ||
936 | info.si_signo = SIGILL; | 934 | info.si_signo = SIGILL; |
937 | info.si_errno = 0; | 935 | info.si_errno = 0; |
938 | info.si_code = ILL_BADSTK; | 936 | info.si_code = ILL_BADSTK; |
939 | info.si_addr = 0; | 937 | info.si_addr = 0; |
940 | if (notify_die(DIE_TRAP, "iret exception", | 938 | if (notify_die(DIE_TRAP, "iret exception", |
941 | regs, error_code, 32, SIGILL) == NOTIFY_STOP) | 939 | regs, error_code, 32, SIGILL) == NOTIFY_STOP) |
942 | return; | 940 | return; |
943 | do_trap(32, SIGILL, "iret exception", regs, error_code, &info); | 941 | do_trap(32, SIGILL, "iret exception", regs, error_code, &info); |
944 | } | 942 | } |
945 | #endif | 943 | #endif |
946 | 944 | ||
947 | void __init trap_init(void) | 945 | void __init trap_init(void) |
948 | { | 946 | { |
949 | int i; | 947 | int i; |
950 | 948 | ||
951 | #ifdef CONFIG_EISA | 949 | #ifdef CONFIG_EISA |
952 | void __iomem *p = early_ioremap(0x0FFFD9, 4); | 950 | void __iomem *p = early_ioremap(0x0FFFD9, 4); |
953 | 951 | ||
954 | if (readl(p) == 'E' + ('I'<<8) + ('S'<<16) + ('A'<<24)) | 952 | if (readl(p) == 'E' + ('I'<<8) + ('S'<<16) + ('A'<<24)) |
955 | EISA_bus = 1; | 953 | EISA_bus = 1; |
956 | early_iounmap(p, 4); | 954 | early_iounmap(p, 4); |
957 | #endif | 955 | #endif |
958 | 956 | ||
959 | set_intr_gate(0, ÷_error); | 957 | set_intr_gate(0, ÷_error); |
960 | set_intr_gate_ist(1, &debug, DEBUG_STACK); | 958 | set_intr_gate_ist(1, &debug, DEBUG_STACK); |
961 | set_intr_gate_ist(2, &nmi, NMI_STACK); | 959 | set_intr_gate_ist(2, &nmi, NMI_STACK); |
962 | /* int3 can be called from all */ | 960 | /* int3 can be called from all */ |
963 | set_system_intr_gate_ist(3, &int3, DEBUG_STACK); | 961 | set_system_intr_gate_ist(3, &int3, DEBUG_STACK); |
964 | /* int4 can be called from all */ | 962 | /* int4 can be called from all */ |
965 | set_system_intr_gate(4, &overflow); | 963 | set_system_intr_gate(4, &overflow); |
966 | set_intr_gate(5, &bounds); | 964 | set_intr_gate(5, &bounds); |
967 | set_intr_gate(6, &invalid_op); | 965 | set_intr_gate(6, &invalid_op); |
968 | set_intr_gate(7, &device_not_available); | 966 | set_intr_gate(7, &device_not_available); |
969 | #ifdef CONFIG_X86_32 | 967 | #ifdef CONFIG_X86_32 |
970 | set_task_gate(8, GDT_ENTRY_DOUBLEFAULT_TSS); | 968 | set_task_gate(8, GDT_ENTRY_DOUBLEFAULT_TSS); |
971 | #else | 969 | #else |
972 | set_intr_gate_ist(8, &double_fault, DOUBLEFAULT_STACK); | 970 | set_intr_gate_ist(8, &double_fault, DOUBLEFAULT_STACK); |
973 | #endif | 971 | #endif |
974 | set_intr_gate(9, &coprocessor_segment_overrun); | 972 | set_intr_gate(9, &coprocessor_segment_overrun); |
975 | set_intr_gate(10, &invalid_TSS); | 973 | set_intr_gate(10, &invalid_TSS); |
976 | set_intr_gate(11, &segment_not_present); | 974 | set_intr_gate(11, &segment_not_present); |
977 | set_intr_gate_ist(12, &stack_segment, STACKFAULT_STACK); | 975 | set_intr_gate_ist(12, &stack_segment, STACKFAULT_STACK); |
978 | set_intr_gate(13, &general_protection); | 976 | set_intr_gate(13, &general_protection); |
979 | set_intr_gate(14, &page_fault); | 977 | set_intr_gate(14, &page_fault); |
980 | set_intr_gate(15, &spurious_interrupt_bug); | 978 | set_intr_gate(15, &spurious_interrupt_bug); |
981 | set_intr_gate(16, &coprocessor_error); | 979 | set_intr_gate(16, &coprocessor_error); |
982 | set_intr_gate(17, &alignment_check); | 980 | set_intr_gate(17, &alignment_check); |
983 | #ifdef CONFIG_X86_MCE | 981 | #ifdef CONFIG_X86_MCE |
984 | set_intr_gate_ist(18, &machine_check, MCE_STACK); | 982 | set_intr_gate_ist(18, &machine_check, MCE_STACK); |
985 | #endif | 983 | #endif |
986 | set_intr_gate(19, &simd_coprocessor_error); | 984 | set_intr_gate(19, &simd_coprocessor_error); |
987 | 985 | ||
988 | #ifdef CONFIG_IA32_EMULATION | 986 | #ifdef CONFIG_IA32_EMULATION |
989 | set_system_intr_gate(IA32_SYSCALL_VECTOR, ia32_syscall); | 987 | set_system_intr_gate(IA32_SYSCALL_VECTOR, ia32_syscall); |
990 | #endif | 988 | #endif |
991 | 989 | ||
992 | #ifdef CONFIG_X86_32 | 990 | #ifdef CONFIG_X86_32 |
993 | if (cpu_has_fxsr) { | 991 | if (cpu_has_fxsr) { |
994 | printk(KERN_INFO "Enabling fast FPU save and restore... "); | 992 | printk(KERN_INFO "Enabling fast FPU save and restore... "); |
995 | set_in_cr4(X86_CR4_OSFXSR); | 993 | set_in_cr4(X86_CR4_OSFXSR); |
996 | printk("done.\n"); | 994 | printk("done.\n"); |
997 | } | 995 | } |
998 | if (cpu_has_xmm) { | 996 | if (cpu_has_xmm) { |
999 | printk(KERN_INFO | 997 | printk(KERN_INFO |
1000 | "Enabling unmasked SIMD FPU exception support... "); | 998 | "Enabling unmasked SIMD FPU exception support... "); |
1001 | set_in_cr4(X86_CR4_OSXMMEXCPT); | 999 | set_in_cr4(X86_CR4_OSXMMEXCPT); |
1002 | printk("done.\n"); | 1000 | printk("done.\n"); |
1003 | } | 1001 | } |
1004 | 1002 | ||
1005 | set_system_trap_gate(SYSCALL_VECTOR, &system_call); | 1003 | set_system_trap_gate(SYSCALL_VECTOR, &system_call); |
1006 | #endif | 1004 | #endif |
1007 | 1005 | ||
1008 | /* Reserve all the builtin and the syscall vector: */ | 1006 | /* Reserve all the builtin and the syscall vector: */ |
1009 | for (i = 0; i < FIRST_EXTERNAL_VECTOR; i++) | 1007 | for (i = 0; i < FIRST_EXTERNAL_VECTOR; i++) |
1010 | set_bit(i, used_vectors); | 1008 | set_bit(i, used_vectors); |
1011 | 1009 | ||
1012 | #ifdef CONFIG_X86_64 | 1010 | #ifdef CONFIG_X86_64 |
1013 | set_bit(IA32_SYSCALL_VECTOR, used_vectors); | 1011 | set_bit(IA32_SYSCALL_VECTOR, used_vectors); |
1014 | #else | 1012 | #else |
1015 | set_bit(SYSCALL_VECTOR, used_vectors); | 1013 | set_bit(SYSCALL_VECTOR, used_vectors); |
1016 | #endif | 1014 | #endif |
1017 | /* | 1015 | /* |
1018 | * Should be a barrier for any external CPU state: | 1016 | * Should be a barrier for any external CPU state: |
1019 | */ | 1017 | */ |
1020 | cpu_init(); | 1018 | cpu_init(); |
1021 | 1019 | ||
1022 | #ifdef CONFIG_X86_32 | 1020 | #ifdef CONFIG_X86_32 |
1023 | trap_init_hook(); | 1021 | trap_init_hook(); |
1024 | #endif | 1022 | #endif |
1025 | } | 1023 | } |
1026 | 1024 |
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/marker.h> | 18 | #include <linux/marker.h> |
19 | #include <linux/tracepoint.h> | 19 | #include <linux/tracepoint.h> |
20 | #include <asm/local.h> | 20 | #include <asm/local.h> |
21 | 21 | ||
22 | #include <asm/module.h> | 22 | #include <asm/module.h> |
23 | 23 | ||
24 | /* Not Yet Implemented */ | 24 | /* Not Yet Implemented */ |
25 | #define MODULE_SUPPORTED_DEVICE(name) | 25 | #define MODULE_SUPPORTED_DEVICE(name) |
26 | 26 | ||
27 | /* some toolchains uses a `_' prefix for all user symbols */ | 27 | /* some toolchains uses a `_' prefix for all user symbols */ |
28 | #ifndef MODULE_SYMBOL_PREFIX | 28 | #ifndef MODULE_SYMBOL_PREFIX |
29 | #define MODULE_SYMBOL_PREFIX "" | 29 | #define MODULE_SYMBOL_PREFIX "" |
30 | #endif | 30 | #endif |
31 | 31 | ||
32 | #define MODULE_NAME_LEN MAX_PARAM_PREFIX_LEN | 32 | #define MODULE_NAME_LEN MAX_PARAM_PREFIX_LEN |
33 | 33 | ||
34 | struct kernel_symbol | 34 | struct kernel_symbol |
35 | { | 35 | { |
36 | unsigned long value; | 36 | unsigned long value; |
37 | const char *name; | 37 | const char *name; |
38 | }; | 38 | }; |
39 | 39 | ||
40 | struct modversion_info | 40 | struct modversion_info |
41 | { | 41 | { |
42 | unsigned long crc; | 42 | unsigned long crc; |
43 | char name[MODULE_NAME_LEN]; | 43 | char name[MODULE_NAME_LEN]; |
44 | }; | 44 | }; |
45 | 45 | ||
46 | struct module; | 46 | struct module; |
47 | 47 | ||
48 | struct module_attribute { | 48 | struct module_attribute { |
49 | struct attribute attr; | 49 | struct attribute attr; |
50 | ssize_t (*show)(struct module_attribute *, struct module *, char *); | 50 | ssize_t (*show)(struct module_attribute *, struct module *, char *); |
51 | ssize_t (*store)(struct module_attribute *, struct module *, | 51 | ssize_t (*store)(struct module_attribute *, struct module *, |
52 | const char *, size_t count); | 52 | const char *, size_t count); |
53 | void (*setup)(struct module *, const char *); | 53 | void (*setup)(struct module *, const char *); |
54 | int (*test)(struct module *); | 54 | int (*test)(struct module *); |
55 | void (*free)(struct module *); | 55 | void (*free)(struct module *); |
56 | }; | 56 | }; |
57 | 57 | ||
58 | struct module_kobject | 58 | struct module_kobject |
59 | { | 59 | { |
60 | struct kobject kobj; | 60 | struct kobject kobj; |
61 | struct module *mod; | 61 | struct module *mod; |
62 | struct kobject *drivers_dir; | 62 | struct kobject *drivers_dir; |
63 | struct module_param_attrs *mp; | 63 | struct module_param_attrs *mp; |
64 | }; | 64 | }; |
65 | 65 | ||
66 | /* These are either module local, or the kernel's dummy ones. */ | 66 | /* These are either module local, or the kernel's dummy ones. */ |
67 | extern int init_module(void); | 67 | extern int init_module(void); |
68 | extern void cleanup_module(void); | 68 | extern void cleanup_module(void); |
69 | 69 | ||
70 | /* Archs provide a method of finding the correct exception table. */ | 70 | /* Archs provide a method of finding the correct exception table. */ |
71 | struct exception_table_entry; | 71 | struct exception_table_entry; |
72 | 72 | ||
73 | const struct exception_table_entry * | 73 | const struct exception_table_entry * |
74 | search_extable(const struct exception_table_entry *first, | 74 | search_extable(const struct exception_table_entry *first, |
75 | const struct exception_table_entry *last, | 75 | const struct exception_table_entry *last, |
76 | unsigned long value); | 76 | unsigned long value); |
77 | void sort_extable(struct exception_table_entry *start, | 77 | void sort_extable(struct exception_table_entry *start, |
78 | struct exception_table_entry *finish); | 78 | struct exception_table_entry *finish); |
79 | void sort_main_extable(void); | 79 | void sort_main_extable(void); |
80 | 80 | ||
81 | #ifdef MODULE | 81 | #ifdef MODULE |
82 | #define MODULE_GENERIC_TABLE(gtype,name) \ | 82 | #define MODULE_GENERIC_TABLE(gtype,name) \ |
83 | extern const struct gtype##_id __mod_##gtype##_table \ | 83 | extern const struct gtype##_id __mod_##gtype##_table \ |
84 | __attribute__ ((unused, alias(__stringify(name)))) | 84 | __attribute__ ((unused, alias(__stringify(name)))) |
85 | 85 | ||
86 | extern struct module __this_module; | 86 | extern struct module __this_module; |
87 | #define THIS_MODULE (&__this_module) | 87 | #define THIS_MODULE (&__this_module) |
88 | #else /* !MODULE */ | 88 | #else /* !MODULE */ |
89 | #define MODULE_GENERIC_TABLE(gtype,name) | 89 | #define MODULE_GENERIC_TABLE(gtype,name) |
90 | #define THIS_MODULE ((struct module *)0) | 90 | #define THIS_MODULE ((struct module *)0) |
91 | #endif | 91 | #endif |
92 | 92 | ||
93 | /* Generic info of form tag = "info" */ | 93 | /* Generic info of form tag = "info" */ |
94 | #define MODULE_INFO(tag, info) __MODULE_INFO(tag, tag, info) | 94 | #define MODULE_INFO(tag, info) __MODULE_INFO(tag, tag, info) |
95 | 95 | ||
96 | /* For userspace: you can also call me... */ | 96 | /* For userspace: you can also call me... */ |
97 | #define MODULE_ALIAS(_alias) MODULE_INFO(alias, _alias) | 97 | #define MODULE_ALIAS(_alias) MODULE_INFO(alias, _alias) |
98 | 98 | ||
99 | /* | 99 | /* |
100 | * The following license idents are currently accepted as indicating free | 100 | * The following license idents are currently accepted as indicating free |
101 | * software modules | 101 | * software modules |
102 | * | 102 | * |
103 | * "GPL" [GNU Public License v2 or later] | 103 | * "GPL" [GNU Public License v2 or later] |
104 | * "GPL v2" [GNU Public License v2] | 104 | * "GPL v2" [GNU Public License v2] |
105 | * "GPL and additional rights" [GNU Public License v2 rights and more] | 105 | * "GPL and additional rights" [GNU Public License v2 rights and more] |
106 | * "Dual BSD/GPL" [GNU Public License v2 | 106 | * "Dual BSD/GPL" [GNU Public License v2 |
107 | * or BSD license choice] | 107 | * or BSD license choice] |
108 | * "Dual MIT/GPL" [GNU Public License v2 | 108 | * "Dual MIT/GPL" [GNU Public License v2 |
109 | * or MIT license choice] | 109 | * or MIT license choice] |
110 | * "Dual MPL/GPL" [GNU Public License v2 | 110 | * "Dual MPL/GPL" [GNU Public License v2 |
111 | * or Mozilla license choice] | 111 | * or Mozilla license choice] |
112 | * | 112 | * |
113 | * The following other idents are available | 113 | * The following other idents are available |
114 | * | 114 | * |
115 | * "Proprietary" [Non free products] | 115 | * "Proprietary" [Non free products] |
116 | * | 116 | * |
117 | * There are dual licensed components, but when running with Linux it is the | 117 | * There are dual licensed components, but when running with Linux it is the |
118 | * GPL that is relevant so this is a non issue. Similarly LGPL linked with GPL | 118 | * GPL that is relevant so this is a non issue. Similarly LGPL linked with GPL |
119 | * is a GPL combined work. | 119 | * is a GPL combined work. |
120 | * | 120 | * |
121 | * This exists for several reasons | 121 | * This exists for several reasons |
122 | * 1. So modinfo can show license info for users wanting to vet their setup | 122 | * 1. So modinfo can show license info for users wanting to vet their setup |
123 | * is free | 123 | * is free |
124 | * 2. So the community can ignore bug reports including proprietary modules | 124 | * 2. So the community can ignore bug reports including proprietary modules |
125 | * 3. So vendors can do likewise based on their own policies | 125 | * 3. So vendors can do likewise based on their own policies |
126 | */ | 126 | */ |
127 | #define MODULE_LICENSE(_license) MODULE_INFO(license, _license) | 127 | #define MODULE_LICENSE(_license) MODULE_INFO(license, _license) |
128 | 128 | ||
129 | /* Author, ideally of form NAME[, NAME]*[ and NAME] */ | 129 | /* Author, ideally of form NAME[, NAME]*[ and NAME] */ |
130 | #define MODULE_AUTHOR(_author) MODULE_INFO(author, _author) | 130 | #define MODULE_AUTHOR(_author) MODULE_INFO(author, _author) |
131 | 131 | ||
132 | /* What your module does. */ | 132 | /* What your module does. */ |
133 | #define MODULE_DESCRIPTION(_description) MODULE_INFO(description, _description) | 133 | #define MODULE_DESCRIPTION(_description) MODULE_INFO(description, _description) |
134 | 134 | ||
135 | /* One for each parameter, describing how to use it. Some files do | 135 | /* One for each parameter, describing how to use it. Some files do |
136 | multiple of these per line, so can't just use MODULE_INFO. */ | 136 | multiple of these per line, so can't just use MODULE_INFO. */ |
137 | #define MODULE_PARM_DESC(_parm, desc) \ | 137 | #define MODULE_PARM_DESC(_parm, desc) \ |
138 | __MODULE_INFO(parm, _parm, #_parm ":" desc) | 138 | __MODULE_INFO(parm, _parm, #_parm ":" desc) |
139 | 139 | ||
140 | #define MODULE_DEVICE_TABLE(type,name) \ | 140 | #define MODULE_DEVICE_TABLE(type,name) \ |
141 | MODULE_GENERIC_TABLE(type##_device,name) | 141 | MODULE_GENERIC_TABLE(type##_device,name) |
142 | 142 | ||
143 | /* Version of form [<epoch>:]<version>[-<extra-version>]. | 143 | /* Version of form [<epoch>:]<version>[-<extra-version>]. |
144 | Or for CVS/RCS ID version, everything but the number is stripped. | 144 | Or for CVS/RCS ID version, everything but the number is stripped. |
145 | <epoch>: A (small) unsigned integer which allows you to start versions | 145 | <epoch>: A (small) unsigned integer which allows you to start versions |
146 | anew. If not mentioned, it's zero. eg. "2:1.0" is after | 146 | anew. If not mentioned, it's zero. eg. "2:1.0" is after |
147 | "1:2.0". | 147 | "1:2.0". |
148 | <version>: The <version> may contain only alphanumerics and the | 148 | <version>: The <version> may contain only alphanumerics and the |
149 | character `.'. Ordered by numeric sort for numeric parts, | 149 | character `.'. Ordered by numeric sort for numeric parts, |
150 | ascii sort for ascii parts (as per RPM or DEB algorithm). | 150 | ascii sort for ascii parts (as per RPM or DEB algorithm). |
151 | <extraversion>: Like <version>, but inserted for local | 151 | <extraversion>: Like <version>, but inserted for local |
152 | customizations, eg "rh3" or "rusty1". | 152 | customizations, eg "rh3" or "rusty1". |
153 | 153 | ||
154 | Using this automatically adds a checksum of the .c files and the | 154 | Using this automatically adds a checksum of the .c files and the |
155 | local headers in "srcversion". | 155 | local headers in "srcversion". |
156 | */ | 156 | */ |
157 | #define MODULE_VERSION(_version) MODULE_INFO(version, _version) | 157 | #define MODULE_VERSION(_version) MODULE_INFO(version, _version) |
158 | 158 | ||
159 | /* Optional firmware file (or files) needed by the module | 159 | /* Optional firmware file (or files) needed by the module |
160 | * format is simply firmware file name. Multiple firmware | 160 | * format is simply firmware file name. Multiple firmware |
161 | * files require multiple MODULE_FIRMWARE() specifiers */ | 161 | * files require multiple MODULE_FIRMWARE() specifiers */ |
162 | #define MODULE_FIRMWARE(_firmware) MODULE_INFO(firmware, _firmware) | 162 | #define MODULE_FIRMWARE(_firmware) MODULE_INFO(firmware, _firmware) |
163 | 163 | ||
164 | /* Given an address, look for it in the exception tables */ | 164 | /* Given an address, look for it in the exception tables */ |
165 | const struct exception_table_entry *search_exception_tables(unsigned long add); | 165 | const struct exception_table_entry *search_exception_tables(unsigned long add); |
166 | 166 | ||
167 | struct notifier_block; | 167 | struct notifier_block; |
168 | 168 | ||
169 | #ifdef CONFIG_MODULES | 169 | #ifdef CONFIG_MODULES |
170 | 170 | ||
171 | /* Get/put a kernel symbol (calls must be symmetric) */ | 171 | /* Get/put a kernel symbol (calls must be symmetric) */ |
172 | void *__symbol_get(const char *symbol); | 172 | void *__symbol_get(const char *symbol); |
173 | void *__symbol_get_gpl(const char *symbol); | 173 | void *__symbol_get_gpl(const char *symbol); |
174 | #define symbol_get(x) ((typeof(&x))(__symbol_get(MODULE_SYMBOL_PREFIX #x))) | 174 | #define symbol_get(x) ((typeof(&x))(__symbol_get(MODULE_SYMBOL_PREFIX #x))) |
175 | 175 | ||
176 | #ifndef __GENKSYMS__ | 176 | #ifndef __GENKSYMS__ |
177 | #ifdef CONFIG_MODVERSIONS | 177 | #ifdef CONFIG_MODVERSIONS |
178 | /* Mark the CRC weak since genksyms apparently decides not to | 178 | /* Mark the CRC weak since genksyms apparently decides not to |
179 | * generate a checksums for some symbols */ | 179 | * generate a checksums for some symbols */ |
180 | #define __CRC_SYMBOL(sym, sec) \ | 180 | #define __CRC_SYMBOL(sym, sec) \ |
181 | extern void *__crc_##sym __attribute__((weak)); \ | 181 | extern void *__crc_##sym __attribute__((weak)); \ |
182 | static const unsigned long __kcrctab_##sym \ | 182 | static const unsigned long __kcrctab_##sym \ |
183 | __used \ | 183 | __used \ |
184 | __attribute__((section("__kcrctab" sec), unused)) \ | 184 | __attribute__((section("__kcrctab" sec), unused)) \ |
185 | = (unsigned long) &__crc_##sym; | 185 | = (unsigned long) &__crc_##sym; |
186 | #else | 186 | #else |
187 | #define __CRC_SYMBOL(sym, sec) | 187 | #define __CRC_SYMBOL(sym, sec) |
188 | #endif | 188 | #endif |
189 | 189 | ||
190 | /* For every exported symbol, place a struct in the __ksymtab section */ | 190 | /* For every exported symbol, place a struct in the __ksymtab section */ |
191 | #define __EXPORT_SYMBOL(sym, sec) \ | 191 | #define __EXPORT_SYMBOL(sym, sec) \ |
192 | extern typeof(sym) sym; \ | 192 | extern typeof(sym) sym; \ |
193 | __CRC_SYMBOL(sym, sec) \ | 193 | __CRC_SYMBOL(sym, sec) \ |
194 | static const char __kstrtab_##sym[] \ | 194 | static const char __kstrtab_##sym[] \ |
195 | __attribute__((section("__ksymtab_strings"), aligned(1))) \ | 195 | __attribute__((section("__ksymtab_strings"), aligned(1))) \ |
196 | = MODULE_SYMBOL_PREFIX #sym; \ | 196 | = MODULE_SYMBOL_PREFIX #sym; \ |
197 | static const struct kernel_symbol __ksymtab_##sym \ | 197 | static const struct kernel_symbol __ksymtab_##sym \ |
198 | __used \ | 198 | __used \ |
199 | __attribute__((section("__ksymtab" sec), unused)) \ | 199 | __attribute__((section("__ksymtab" sec), unused)) \ |
200 | = { (unsigned long)&sym, __kstrtab_##sym } | 200 | = { (unsigned long)&sym, __kstrtab_##sym } |
201 | 201 | ||
202 | #define EXPORT_SYMBOL(sym) \ | 202 | #define EXPORT_SYMBOL(sym) \ |
203 | __EXPORT_SYMBOL(sym, "") | 203 | __EXPORT_SYMBOL(sym, "") |
204 | 204 | ||
205 | #define EXPORT_SYMBOL_GPL(sym) \ | 205 | #define EXPORT_SYMBOL_GPL(sym) \ |
206 | __EXPORT_SYMBOL(sym, "_gpl") | 206 | __EXPORT_SYMBOL(sym, "_gpl") |
207 | 207 | ||
208 | #define EXPORT_SYMBOL_GPL_FUTURE(sym) \ | 208 | #define EXPORT_SYMBOL_GPL_FUTURE(sym) \ |
209 | __EXPORT_SYMBOL(sym, "_gpl_future") | 209 | __EXPORT_SYMBOL(sym, "_gpl_future") |
210 | 210 | ||
211 | 211 | ||
212 | #ifdef CONFIG_UNUSED_SYMBOLS | 212 | #ifdef CONFIG_UNUSED_SYMBOLS |
213 | #define EXPORT_UNUSED_SYMBOL(sym) __EXPORT_SYMBOL(sym, "_unused") | 213 | #define EXPORT_UNUSED_SYMBOL(sym) __EXPORT_SYMBOL(sym, "_unused") |
214 | #define EXPORT_UNUSED_SYMBOL_GPL(sym) __EXPORT_SYMBOL(sym, "_unused_gpl") | 214 | #define EXPORT_UNUSED_SYMBOL_GPL(sym) __EXPORT_SYMBOL(sym, "_unused_gpl") |
215 | #else | 215 | #else |
216 | #define EXPORT_UNUSED_SYMBOL(sym) | 216 | #define EXPORT_UNUSED_SYMBOL(sym) |
217 | #define EXPORT_UNUSED_SYMBOL_GPL(sym) | 217 | #define EXPORT_UNUSED_SYMBOL_GPL(sym) |
218 | #endif | 218 | #endif |
219 | 219 | ||
220 | #endif | 220 | #endif |
221 | 221 | ||
222 | struct module_ref | 222 | struct module_ref |
223 | { | 223 | { |
224 | local_t count; | 224 | local_t count; |
225 | } ____cacheline_aligned; | 225 | } ____cacheline_aligned; |
226 | 226 | ||
227 | enum module_state | 227 | enum module_state |
228 | { | 228 | { |
229 | MODULE_STATE_LIVE, | 229 | MODULE_STATE_LIVE, |
230 | MODULE_STATE_COMING, | 230 | MODULE_STATE_COMING, |
231 | MODULE_STATE_GOING, | 231 | MODULE_STATE_GOING, |
232 | }; | 232 | }; |
233 | 233 | ||
234 | struct module | 234 | struct module |
235 | { | 235 | { |
236 | enum module_state state; | 236 | enum module_state state; |
237 | 237 | ||
238 | /* Member of list of modules */ | 238 | /* Member of list of modules */ |
239 | struct list_head list; | 239 | struct list_head list; |
240 | 240 | ||
241 | /* Unique handle for this module */ | 241 | /* Unique handle for this module */ |
242 | char name[MODULE_NAME_LEN]; | 242 | char name[MODULE_NAME_LEN]; |
243 | 243 | ||
244 | /* Sysfs stuff. */ | 244 | /* Sysfs stuff. */ |
245 | struct module_kobject mkobj; | 245 | struct module_kobject mkobj; |
246 | struct module_attribute *modinfo_attrs; | 246 | struct module_attribute *modinfo_attrs; |
247 | const char *version; | 247 | const char *version; |
248 | const char *srcversion; | 248 | const char *srcversion; |
249 | struct kobject *holders_dir; | 249 | struct kobject *holders_dir; |
250 | 250 | ||
251 | /* Exported symbols */ | 251 | /* Exported symbols */ |
252 | const struct kernel_symbol *syms; | 252 | const struct kernel_symbol *syms; |
253 | const unsigned long *crcs; | 253 | const unsigned long *crcs; |
254 | unsigned int num_syms; | 254 | unsigned int num_syms; |
255 | 255 | ||
256 | /* GPL-only exported symbols. */ | 256 | /* GPL-only exported symbols. */ |
257 | unsigned int num_gpl_syms; | 257 | unsigned int num_gpl_syms; |
258 | const struct kernel_symbol *gpl_syms; | 258 | const struct kernel_symbol *gpl_syms; |
259 | const unsigned long *gpl_crcs; | 259 | const unsigned long *gpl_crcs; |
260 | 260 | ||
261 | #ifdef CONFIG_UNUSED_SYMBOLS | 261 | #ifdef CONFIG_UNUSED_SYMBOLS |
262 | /* unused exported symbols. */ | 262 | /* unused exported symbols. */ |
263 | const struct kernel_symbol *unused_syms; | 263 | const struct kernel_symbol *unused_syms; |
264 | const unsigned long *unused_crcs; | 264 | const unsigned long *unused_crcs; |
265 | unsigned int num_unused_syms; | 265 | unsigned int num_unused_syms; |
266 | 266 | ||
267 | /* GPL-only, unused exported symbols. */ | 267 | /* GPL-only, unused exported symbols. */ |
268 | unsigned int num_unused_gpl_syms; | 268 | unsigned int num_unused_gpl_syms; |
269 | const struct kernel_symbol *unused_gpl_syms; | 269 | const struct kernel_symbol *unused_gpl_syms; |
270 | const unsigned long *unused_gpl_crcs; | 270 | const unsigned long *unused_gpl_crcs; |
271 | #endif | 271 | #endif |
272 | 272 | ||
273 | /* symbols that will be GPL-only in the near future. */ | 273 | /* symbols that will be GPL-only in the near future. */ |
274 | const struct kernel_symbol *gpl_future_syms; | 274 | const struct kernel_symbol *gpl_future_syms; |
275 | const unsigned long *gpl_future_crcs; | 275 | const unsigned long *gpl_future_crcs; |
276 | unsigned int num_gpl_future_syms; | 276 | unsigned int num_gpl_future_syms; |
277 | 277 | ||
278 | /* Exception table */ | 278 | /* Exception table */ |
279 | unsigned int num_exentries; | 279 | unsigned int num_exentries; |
280 | struct exception_table_entry *extable; | 280 | struct exception_table_entry *extable; |
281 | 281 | ||
282 | /* Startup function. */ | 282 | /* Startup function. */ |
283 | int (*init)(void); | 283 | int (*init)(void); |
284 | 284 | ||
285 | /* If this is non-NULL, vfree after init() returns */ | 285 | /* If this is non-NULL, vfree after init() returns */ |
286 | void *module_init; | 286 | void *module_init; |
287 | 287 | ||
288 | /* Here is the actual code + data, vfree'd on unload. */ | 288 | /* Here is the actual code + data, vfree'd on unload. */ |
289 | void *module_core; | 289 | void *module_core; |
290 | 290 | ||
291 | /* Here are the sizes of the init and core sections */ | 291 | /* Here are the sizes of the init and core sections */ |
292 | unsigned int init_size, core_size; | 292 | unsigned int init_size, core_size; |
293 | 293 | ||
294 | /* The size of the executable code in each section. */ | 294 | /* The size of the executable code in each section. */ |
295 | unsigned int init_text_size, core_text_size; | 295 | unsigned int init_text_size, core_text_size; |
296 | 296 | ||
297 | /* The handle returned from unwind_add_table. */ | ||
298 | void *unwind_info; | ||
299 | |||
300 | /* Arch-specific module values */ | 297 | /* Arch-specific module values */ |
301 | struct mod_arch_specific arch; | 298 | struct mod_arch_specific arch; |
302 | 299 | ||
303 | unsigned int taints; /* same bits as kernel:tainted */ | 300 | unsigned int taints; /* same bits as kernel:tainted */ |
304 | 301 | ||
305 | #ifdef CONFIG_GENERIC_BUG | 302 | #ifdef CONFIG_GENERIC_BUG |
306 | /* Support for BUG */ | 303 | /* Support for BUG */ |
307 | unsigned num_bugs; | 304 | unsigned num_bugs; |
308 | struct list_head bug_list; | 305 | struct list_head bug_list; |
309 | struct bug_entry *bug_table; | 306 | struct bug_entry *bug_table; |
310 | #endif | 307 | #endif |
311 | 308 | ||
312 | #ifdef CONFIG_KALLSYMS | 309 | #ifdef CONFIG_KALLSYMS |
313 | /* We keep the symbol and string tables for kallsyms. */ | 310 | /* We keep the symbol and string tables for kallsyms. */ |
314 | Elf_Sym *symtab; | 311 | Elf_Sym *symtab; |
315 | unsigned int num_symtab; | 312 | unsigned int num_symtab; |
316 | char *strtab; | 313 | char *strtab; |
317 | 314 | ||
318 | /* Section attributes */ | 315 | /* Section attributes */ |
319 | struct module_sect_attrs *sect_attrs; | 316 | struct module_sect_attrs *sect_attrs; |
320 | 317 | ||
321 | /* Notes attributes */ | 318 | /* Notes attributes */ |
322 | struct module_notes_attrs *notes_attrs; | 319 | struct module_notes_attrs *notes_attrs; |
323 | #endif | 320 | #endif |
324 | 321 | ||
325 | /* Per-cpu data. */ | 322 | /* Per-cpu data. */ |
326 | void *percpu; | 323 | void *percpu; |
327 | 324 | ||
328 | /* The command line arguments (may be mangled). People like | 325 | /* The command line arguments (may be mangled). People like |
329 | keeping pointers to this stuff */ | 326 | keeping pointers to this stuff */ |
330 | char *args; | 327 | char *args; |
331 | #ifdef CONFIG_MARKERS | 328 | #ifdef CONFIG_MARKERS |
332 | struct marker *markers; | 329 | struct marker *markers; |
333 | unsigned int num_markers; | 330 | unsigned int num_markers; |
334 | #endif | 331 | #endif |
335 | #ifdef CONFIG_TRACEPOINTS | 332 | #ifdef CONFIG_TRACEPOINTS |
336 | struct tracepoint *tracepoints; | 333 | struct tracepoint *tracepoints; |
337 | unsigned int num_tracepoints; | 334 | unsigned int num_tracepoints; |
338 | #endif | 335 | #endif |
339 | 336 | ||
340 | #ifdef CONFIG_MODULE_UNLOAD | 337 | #ifdef CONFIG_MODULE_UNLOAD |
341 | /* What modules depend on me? */ | 338 | /* What modules depend on me? */ |
342 | struct list_head modules_which_use_me; | 339 | struct list_head modules_which_use_me; |
343 | 340 | ||
344 | /* Who is waiting for us to be unloaded */ | 341 | /* Who is waiting for us to be unloaded */ |
345 | struct task_struct *waiter; | 342 | struct task_struct *waiter; |
346 | 343 | ||
347 | /* Destruction function. */ | 344 | /* Destruction function. */ |
348 | void (*exit)(void); | 345 | void (*exit)(void); |
349 | 346 | ||
350 | /* Reference counts */ | 347 | /* Reference counts */ |
351 | struct module_ref ref[NR_CPUS]; | 348 | struct module_ref ref[NR_CPUS]; |
352 | #endif | 349 | #endif |
353 | }; | 350 | }; |
354 | #ifndef MODULE_ARCH_INIT | 351 | #ifndef MODULE_ARCH_INIT |
355 | #define MODULE_ARCH_INIT {} | 352 | #define MODULE_ARCH_INIT {} |
356 | #endif | 353 | #endif |
357 | 354 | ||
358 | /* FIXME: It'd be nice to isolate modules during init, too, so they | 355 | /* FIXME: It'd be nice to isolate modules during init, too, so they |
359 | aren't used before they (may) fail. But presently too much code | 356 | aren't used before they (may) fail. But presently too much code |
360 | (IDE & SCSI) require entry into the module during init.*/ | 357 | (IDE & SCSI) require entry into the module during init.*/ |
361 | static inline int module_is_live(struct module *mod) | 358 | static inline int module_is_live(struct module *mod) |
362 | { | 359 | { |
363 | return mod->state != MODULE_STATE_GOING; | 360 | return mod->state != MODULE_STATE_GOING; |
364 | } | 361 | } |
365 | 362 | ||
366 | /* Is this address in a module? (second is with no locks, for oops) */ | 363 | /* Is this address in a module? (second is with no locks, for oops) */ |
367 | struct module *module_text_address(unsigned long addr); | 364 | struct module *module_text_address(unsigned long addr); |
368 | struct module *__module_text_address(unsigned long addr); | 365 | struct module *__module_text_address(unsigned long addr); |
369 | int is_module_address(unsigned long addr); | 366 | int is_module_address(unsigned long addr); |
370 | 367 | ||
371 | /* Returns 0 and fills in value, defined and namebuf, or -ERANGE if | 368 | /* Returns 0 and fills in value, defined and namebuf, or -ERANGE if |
372 | symnum out of range. */ | 369 | symnum out of range. */ |
373 | int module_get_kallsym(unsigned int symnum, unsigned long *value, char *type, | 370 | int module_get_kallsym(unsigned int symnum, unsigned long *value, char *type, |
374 | char *name, char *module_name, int *exported); | 371 | char *name, char *module_name, int *exported); |
375 | 372 | ||
376 | /* Look for this name: can be of form module:name. */ | 373 | /* Look for this name: can be of form module:name. */ |
377 | unsigned long module_kallsyms_lookup_name(const char *name); | 374 | unsigned long module_kallsyms_lookup_name(const char *name); |
378 | 375 | ||
379 | extern void __module_put_and_exit(struct module *mod, long code) | 376 | extern void __module_put_and_exit(struct module *mod, long code) |
380 | __attribute__((noreturn)); | 377 | __attribute__((noreturn)); |
381 | #define module_put_and_exit(code) __module_put_and_exit(THIS_MODULE, code); | 378 | #define module_put_and_exit(code) __module_put_and_exit(THIS_MODULE, code); |
382 | 379 | ||
383 | #ifdef CONFIG_MODULE_UNLOAD | 380 | #ifdef CONFIG_MODULE_UNLOAD |
384 | unsigned int module_refcount(struct module *mod); | 381 | unsigned int module_refcount(struct module *mod); |
385 | void __symbol_put(const char *symbol); | 382 | void __symbol_put(const char *symbol); |
386 | #define symbol_put(x) __symbol_put(MODULE_SYMBOL_PREFIX #x) | 383 | #define symbol_put(x) __symbol_put(MODULE_SYMBOL_PREFIX #x) |
387 | void symbol_put_addr(void *addr); | 384 | void symbol_put_addr(void *addr); |
388 | 385 | ||
389 | /* Sometimes we know we already have a refcount, and it's easier not | 386 | /* Sometimes we know we already have a refcount, and it's easier not |
390 | to handle the error case (which only happens with rmmod --wait). */ | 387 | to handle the error case (which only happens with rmmod --wait). */ |
391 | static inline void __module_get(struct module *module) | 388 | static inline void __module_get(struct module *module) |
392 | { | 389 | { |
393 | if (module) { | 390 | if (module) { |
394 | BUG_ON(module_refcount(module) == 0); | 391 | BUG_ON(module_refcount(module) == 0); |
395 | local_inc(&module->ref[get_cpu()].count); | 392 | local_inc(&module->ref[get_cpu()].count); |
396 | put_cpu(); | 393 | put_cpu(); |
397 | } | 394 | } |
398 | } | 395 | } |
399 | 396 | ||
400 | static inline int try_module_get(struct module *module) | 397 | static inline int try_module_get(struct module *module) |
401 | { | 398 | { |
402 | int ret = 1; | 399 | int ret = 1; |
403 | 400 | ||
404 | if (module) { | 401 | if (module) { |
405 | unsigned int cpu = get_cpu(); | 402 | unsigned int cpu = get_cpu(); |
406 | if (likely(module_is_live(module))) | 403 | if (likely(module_is_live(module))) |
407 | local_inc(&module->ref[cpu].count); | 404 | local_inc(&module->ref[cpu].count); |
408 | else | 405 | else |
409 | ret = 0; | 406 | ret = 0; |
410 | put_cpu(); | 407 | put_cpu(); |
411 | } | 408 | } |
412 | return ret; | 409 | return ret; |
413 | } | 410 | } |
414 | 411 | ||
415 | extern void module_put(struct module *module); | 412 | extern void module_put(struct module *module); |
416 | 413 | ||
417 | #else /*!CONFIG_MODULE_UNLOAD*/ | 414 | #else /*!CONFIG_MODULE_UNLOAD*/ |
418 | static inline int try_module_get(struct module *module) | 415 | static inline int try_module_get(struct module *module) |
419 | { | 416 | { |
420 | return !module || module_is_live(module); | 417 | return !module || module_is_live(module); |
421 | } | 418 | } |
422 | static inline void module_put(struct module *module) | 419 | static inline void module_put(struct module *module) |
423 | { | 420 | { |
424 | } | 421 | } |
425 | static inline void __module_get(struct module *module) | 422 | static inline void __module_get(struct module *module) |
426 | { | 423 | { |
427 | } | 424 | } |
428 | #define symbol_put(x) do { } while(0) | 425 | #define symbol_put(x) do { } while(0) |
429 | #define symbol_put_addr(p) do { } while(0) | 426 | #define symbol_put_addr(p) do { } while(0) |
430 | 427 | ||
431 | #endif /* CONFIG_MODULE_UNLOAD */ | 428 | #endif /* CONFIG_MODULE_UNLOAD */ |
432 | 429 | ||
433 | /* This is a #define so the string doesn't get put in every .o file */ | 430 | /* This is a #define so the string doesn't get put in every .o file */ |
434 | #define module_name(mod) \ | 431 | #define module_name(mod) \ |
435 | ({ \ | 432 | ({ \ |
436 | struct module *__mod = (mod); \ | 433 | struct module *__mod = (mod); \ |
437 | __mod ? __mod->name : "kernel"; \ | 434 | __mod ? __mod->name : "kernel"; \ |
438 | }) | 435 | }) |
439 | 436 | ||
440 | /* For kallsyms to ask for address resolution. namebuf should be at | 437 | /* For kallsyms to ask for address resolution. namebuf should be at |
441 | * least KSYM_NAME_LEN long: a pointer to namebuf is returned if | 438 | * least KSYM_NAME_LEN long: a pointer to namebuf is returned if |
442 | * found, otherwise NULL. */ | 439 | * found, otherwise NULL. */ |
443 | const char *module_address_lookup(unsigned long addr, | 440 | const char *module_address_lookup(unsigned long addr, |
444 | unsigned long *symbolsize, | 441 | unsigned long *symbolsize, |
445 | unsigned long *offset, | 442 | unsigned long *offset, |
446 | char **modname, | 443 | char **modname, |
447 | char *namebuf); | 444 | char *namebuf); |
448 | int lookup_module_symbol_name(unsigned long addr, char *symname); | 445 | int lookup_module_symbol_name(unsigned long addr, char *symname); |
449 | int lookup_module_symbol_attrs(unsigned long addr, unsigned long *size, unsigned long *offset, char *modname, char *name); | 446 | int lookup_module_symbol_attrs(unsigned long addr, unsigned long *size, unsigned long *offset, char *modname, char *name); |
450 | 447 | ||
451 | /* For extable.c to search modules' exception tables. */ | 448 | /* For extable.c to search modules' exception tables. */ |
452 | const struct exception_table_entry *search_module_extables(unsigned long addr); | 449 | const struct exception_table_entry *search_module_extables(unsigned long addr); |
453 | 450 | ||
454 | int register_module_notifier(struct notifier_block * nb); | 451 | int register_module_notifier(struct notifier_block * nb); |
455 | int unregister_module_notifier(struct notifier_block * nb); | 452 | int unregister_module_notifier(struct notifier_block * nb); |
456 | 453 | ||
457 | extern void print_modules(void); | 454 | extern void print_modules(void); |
458 | 455 | ||
459 | extern void module_update_markers(void); | 456 | extern void module_update_markers(void); |
460 | 457 | ||
461 | extern void module_update_tracepoints(void); | 458 | extern void module_update_tracepoints(void); |
462 | extern int module_get_iter_tracepoints(struct tracepoint_iter *iter); | 459 | extern int module_get_iter_tracepoints(struct tracepoint_iter *iter); |
463 | 460 | ||
464 | #else /* !CONFIG_MODULES... */ | 461 | #else /* !CONFIG_MODULES... */ |
465 | #define EXPORT_SYMBOL(sym) | 462 | #define EXPORT_SYMBOL(sym) |
466 | #define EXPORT_SYMBOL_GPL(sym) | 463 | #define EXPORT_SYMBOL_GPL(sym) |
467 | #define EXPORT_SYMBOL_GPL_FUTURE(sym) | 464 | #define EXPORT_SYMBOL_GPL_FUTURE(sym) |
468 | #define EXPORT_UNUSED_SYMBOL(sym) | 465 | #define EXPORT_UNUSED_SYMBOL(sym) |
469 | #define EXPORT_UNUSED_SYMBOL_GPL(sym) | 466 | #define EXPORT_UNUSED_SYMBOL_GPL(sym) |
470 | 467 | ||
471 | /* Given an address, look for it in the exception tables. */ | 468 | /* Given an address, look for it in the exception tables. */ |
472 | static inline const struct exception_table_entry * | 469 | static inline const struct exception_table_entry * |
473 | search_module_extables(unsigned long addr) | 470 | search_module_extables(unsigned long addr) |
474 | { | 471 | { |
475 | return NULL; | 472 | return NULL; |
476 | } | 473 | } |
477 | 474 | ||
478 | /* Is this address in a module? */ | 475 | /* Is this address in a module? */ |
479 | static inline struct module *module_text_address(unsigned long addr) | 476 | static inline struct module *module_text_address(unsigned long addr) |
480 | { | 477 | { |
481 | return NULL; | 478 | return NULL; |
482 | } | 479 | } |
483 | 480 | ||
484 | /* Is this address in a module? (don't take a lock, we're oopsing) */ | 481 | /* Is this address in a module? (don't take a lock, we're oopsing) */ |
485 | static inline struct module *__module_text_address(unsigned long addr) | 482 | static inline struct module *__module_text_address(unsigned long addr) |
486 | { | 483 | { |
487 | return NULL; | 484 | return NULL; |
488 | } | 485 | } |
489 | 486 | ||
490 | static inline int is_module_address(unsigned long addr) | 487 | static inline int is_module_address(unsigned long addr) |
491 | { | 488 | { |
492 | return 0; | 489 | return 0; |
493 | } | 490 | } |
494 | 491 | ||
495 | /* Get/put a kernel symbol (calls should be symmetric) */ | 492 | /* Get/put a kernel symbol (calls should be symmetric) */ |
496 | #define symbol_get(x) ({ extern typeof(x) x __attribute__((weak)); &(x); }) | 493 | #define symbol_get(x) ({ extern typeof(x) x __attribute__((weak)); &(x); }) |
497 | #define symbol_put(x) do { } while(0) | 494 | #define symbol_put(x) do { } while(0) |
498 | #define symbol_put_addr(x) do { } while(0) | 495 | #define symbol_put_addr(x) do { } while(0) |
499 | 496 | ||
500 | static inline void __module_get(struct module *module) | 497 | static inline void __module_get(struct module *module) |
501 | { | 498 | { |
502 | } | 499 | } |
503 | 500 | ||
504 | static inline int try_module_get(struct module *module) | 501 | static inline int try_module_get(struct module *module) |
505 | { | 502 | { |
506 | return 1; | 503 | return 1; |
507 | } | 504 | } |
508 | 505 | ||
509 | static inline void module_put(struct module *module) | 506 | static inline void module_put(struct module *module) |
510 | { | 507 | { |
511 | } | 508 | } |
512 | 509 | ||
513 | #define module_name(mod) "kernel" | 510 | #define module_name(mod) "kernel" |
514 | 511 | ||
515 | /* For kallsyms to ask for address resolution. NULL means not found. */ | 512 | /* For kallsyms to ask for address resolution. NULL means not found. */ |
516 | static inline const char *module_address_lookup(unsigned long addr, | 513 | static inline const char *module_address_lookup(unsigned long addr, |
517 | unsigned long *symbolsize, | 514 | unsigned long *symbolsize, |
518 | unsigned long *offset, | 515 | unsigned long *offset, |
519 | char **modname, | 516 | char **modname, |
520 | char *namebuf) | 517 | char *namebuf) |
521 | { | 518 | { |
522 | return NULL; | 519 | return NULL; |
523 | } | 520 | } |
524 | 521 | ||
525 | static inline int lookup_module_symbol_name(unsigned long addr, char *symname) | 522 | static inline int lookup_module_symbol_name(unsigned long addr, char *symname) |
526 | { | 523 | { |
527 | return -ERANGE; | 524 | return -ERANGE; |
528 | } | 525 | } |
529 | 526 | ||
530 | static inline int lookup_module_symbol_attrs(unsigned long addr, unsigned long *size, unsigned long *offset, char *modname, char *name) | 527 | static inline int lookup_module_symbol_attrs(unsigned long addr, unsigned long *size, unsigned long *offset, char *modname, char *name) |
531 | { | 528 | { |
532 | return -ERANGE; | 529 | return -ERANGE; |
533 | } | 530 | } |
534 | 531 | ||
535 | static inline int module_get_kallsym(unsigned int symnum, unsigned long *value, | 532 | static inline int module_get_kallsym(unsigned int symnum, unsigned long *value, |
536 | char *type, char *name, | 533 | char *type, char *name, |
537 | char *module_name, int *exported) | 534 | char *module_name, int *exported) |
538 | { | 535 | { |
539 | return -ERANGE; | 536 | return -ERANGE; |
540 | } | 537 | } |
541 | 538 | ||
542 | static inline unsigned long module_kallsyms_lookup_name(const char *name) | 539 | static inline unsigned long module_kallsyms_lookup_name(const char *name) |
543 | { | 540 | { |
544 | return 0; | 541 | return 0; |
545 | } | 542 | } |
546 | 543 | ||
547 | static inline int register_module_notifier(struct notifier_block * nb) | 544 | static inline int register_module_notifier(struct notifier_block * nb) |
548 | { | 545 | { |
549 | /* no events will happen anyway, so this can always succeed */ | 546 | /* no events will happen anyway, so this can always succeed */ |
550 | return 0; | 547 | return 0; |
551 | } | 548 | } |
552 | 549 | ||
553 | static inline int unregister_module_notifier(struct notifier_block * nb) | 550 | static inline int unregister_module_notifier(struct notifier_block * nb) |
554 | { | 551 | { |
555 | return 0; | 552 | return 0; |
556 | } | 553 | } |
557 | 554 | ||
558 | #define module_put_and_exit(code) do_exit(code) | 555 | #define module_put_and_exit(code) do_exit(code) |
559 | 556 | ||
560 | static inline void print_modules(void) | 557 | static inline void print_modules(void) |
561 | { | 558 | { |
562 | } | 559 | } |
563 | 560 | ||
564 | static inline void module_update_markers(void) | 561 | static inline void module_update_markers(void) |
565 | { | 562 | { |
566 | } | 563 | } |
567 | 564 | ||
568 | static inline void module_update_tracepoints(void) | 565 | static inline void module_update_tracepoints(void) |
569 | { | 566 | { |
570 | } | 567 | } |
571 | 568 | ||
572 | static inline int module_get_iter_tracepoints(struct tracepoint_iter *iter) | 569 | static inline int module_get_iter_tracepoints(struct tracepoint_iter *iter) |
573 | { | 570 | { |
574 | return 0; | 571 | return 0; |
575 | } | 572 | } |
576 | 573 | ||
577 | #endif /* CONFIG_MODULES */ | 574 | #endif /* CONFIG_MODULES */ |
578 | 575 | ||
579 | struct device_driver; | 576 | struct device_driver; |
580 | #ifdef CONFIG_SYSFS | 577 | #ifdef CONFIG_SYSFS |
581 | struct module; | 578 | struct module; |
582 | 579 | ||
583 | extern struct kset *module_kset; | 580 | extern struct kset *module_kset; |
584 | extern struct kobj_type module_ktype; | 581 | extern struct kobj_type module_ktype; |
585 | extern int module_sysfs_initialized; | 582 | extern int module_sysfs_initialized; |
586 | 583 | ||
587 | int mod_sysfs_init(struct module *mod); | 584 | int mod_sysfs_init(struct module *mod); |
588 | int mod_sysfs_setup(struct module *mod, | 585 | int mod_sysfs_setup(struct module *mod, |
589 | struct kernel_param *kparam, | 586 | struct kernel_param *kparam, |
590 | unsigned int num_params); | 587 | unsigned int num_params); |
591 | int module_add_modinfo_attrs(struct module *mod); | 588 | int module_add_modinfo_attrs(struct module *mod); |
592 | void module_remove_modinfo_attrs(struct module *mod); | 589 | void module_remove_modinfo_attrs(struct module *mod); |
593 | 590 | ||
594 | #else /* !CONFIG_SYSFS */ | 591 | #else /* !CONFIG_SYSFS */ |
595 | 592 | ||
596 | static inline int mod_sysfs_init(struct module *mod) | 593 | static inline int mod_sysfs_init(struct module *mod) |
597 | { | 594 | { |
598 | return 0; | 595 | return 0; |
599 | } | 596 | } |
600 | 597 | ||
601 | static inline int mod_sysfs_setup(struct module *mod, | 598 | static inline int mod_sysfs_setup(struct module *mod, |
602 | struct kernel_param *kparam, | 599 | struct kernel_param *kparam, |
603 | unsigned int num_params) | 600 | unsigned int num_params) |
604 | { | 601 | { |
605 | return 0; | 602 | return 0; |
606 | } | 603 | } |
607 | 604 | ||
608 | static inline int module_add_modinfo_attrs(struct module *mod) | 605 | static inline int module_add_modinfo_attrs(struct module *mod) |
609 | { | 606 | { |
610 | return 0; | 607 | return 0; |
611 | } | 608 | } |
612 | 609 | ||
613 | static inline void module_remove_modinfo_attrs(struct module *mod) | 610 | static inline void module_remove_modinfo_attrs(struct module *mod) |
614 | { } | 611 | { } |
615 | 612 | ||
616 | #endif /* CONFIG_SYSFS */ | 613 | #endif /* CONFIG_SYSFS */ |
617 | 614 | ||
618 | #define symbol_request(x) try_then_request_module(symbol_get(x), "symbol:" #x) | 615 | #define symbol_request(x) try_then_request_module(symbol_get(x), "symbol:" #x) |
619 | 616 | ||
620 | /* BELOW HERE ALL THESE ARE OBSOLETE AND WILL VANISH */ | 617 | /* BELOW HERE ALL THESE ARE OBSOLETE AND WILL VANISH */ |
621 | 618 | ||
622 | #define __MODULE_STRING(x) __stringify(x) | 619 | #define __MODULE_STRING(x) __stringify(x) |
623 | 620 | ||
624 | #endif /* _LINUX_MODULE_H */ | 621 | #endif /* _LINUX_MODULE_H */ |
625 | 622 |
include/linux/unwind.h
1 | #ifndef _LINUX_UNWIND_H | File was deleted | |
2 | #define _LINUX_UNWIND_H | ||
3 | |||
4 | /* | ||
5 | * Copyright (C) 2002-2006 Novell, Inc. | ||
6 | * Jan Beulich <jbeulich@novell.com> | ||
7 | * This code is released under version 2 of the GNU GPL. | ||
8 | * | ||
9 | * A simple API for unwinding kernel stacks. This is used for | ||
10 | * debugging and error reporting purposes. The kernel doesn't need | ||
11 | * full-blown stack unwinding with all the bells and whistles, so there | ||
12 | * is not much point in implementing the full Dwarf2 unwind API. | ||
13 | */ | ||
14 | |||
15 | struct module; | ||
16 | |||
17 | struct unwind_frame_info {}; | ||
18 | |||
19 | static inline void unwind_init(void) {} | ||
20 | static inline void unwind_setup(void) {} | ||
21 | |||
22 | #ifdef CONFIG_MODULES | ||
23 | |||
24 | static inline void *unwind_add_table(struct module *mod, | ||
25 | const void *table_start, | ||
26 | unsigned long table_size) | ||
27 | { | ||
28 | return NULL; | ||
29 | } | ||
30 | |||
31 | static inline void unwind_remove_table(void *handle, int init_only) | ||
32 | { | ||
33 | } | ||
34 | |||
35 | #endif | ||
36 | |||
37 | static inline int unwind_init_frame_info(struct unwind_frame_info *info, | ||
38 | struct task_struct *tsk, | ||
39 | const struct pt_regs *regs) | ||
40 | { | ||
41 | return -ENOSYS; | ||
42 | } | ||
43 | |||
44 | static inline int unwind_init_blocked(struct unwind_frame_info *info, | ||
45 | struct task_struct *tsk) | ||
46 | { | ||
47 | return -ENOSYS; | ||
48 | } | ||
49 | |||
50 | static inline int unwind_init_running(struct unwind_frame_info *info, | ||
51 | asmlinkage int (*cb)(struct unwind_frame_info *, | ||
52 | void *arg), | ||
53 | void *arg) | ||
54 | { | ||
55 | return -ENOSYS; | ||
56 | } | ||
57 | |||
58 | static inline int unwind(struct unwind_frame_info *info) | ||
59 | { | ||
60 | return -ENOSYS; | ||
61 | } | ||
62 | |||
63 | static inline int unwind_to_user(struct unwind_frame_info *info) | ||
64 | { | ||
65 | return -ENOSYS; | ||
66 | } | ||
67 | |||
68 | #endif /* _LINUX_UNWIND_H */ | ||
69 | 1 | #ifndef _LINUX_UNWIND_H |
init/main.c
1 | /* | 1 | /* |
2 | * linux/init/main.c | 2 | * linux/init/main.c |
3 | * | 3 | * |
4 | * Copyright (C) 1991, 1992 Linus Torvalds | 4 | * Copyright (C) 1991, 1992 Linus Torvalds |
5 | * | 5 | * |
6 | * GK 2/5/95 - Changed to support mounting root fs via NFS | 6 | * GK 2/5/95 - Changed to support mounting root fs via NFS |
7 | * Added initrd & change_root: Werner Almesberger & Hans Lermen, Feb '96 | 7 | * Added initrd & change_root: Werner Almesberger & Hans Lermen, Feb '96 |
8 | * Moan early if gcc is old, avoiding bogus kernels - Paul Gortmaker, May '96 | 8 | * Moan early if gcc is old, avoiding bogus kernels - Paul Gortmaker, May '96 |
9 | * Simplified starting of init: Michael A. Griffith <grif@acm.org> | 9 | * Simplified starting of init: Michael A. Griffith <grif@acm.org> |
10 | */ | 10 | */ |
11 | 11 | ||
12 | #include <linux/types.h> | 12 | #include <linux/types.h> |
13 | #include <linux/module.h> | 13 | #include <linux/module.h> |
14 | #include <linux/proc_fs.h> | 14 | #include <linux/proc_fs.h> |
15 | #include <linux/kernel.h> | 15 | #include <linux/kernel.h> |
16 | #include <linux/syscalls.h> | 16 | #include <linux/syscalls.h> |
17 | #include <linux/string.h> | 17 | #include <linux/string.h> |
18 | #include <linux/ctype.h> | 18 | #include <linux/ctype.h> |
19 | #include <linux/delay.h> | 19 | #include <linux/delay.h> |
20 | #include <linux/utsname.h> | 20 | #include <linux/utsname.h> |
21 | #include <linux/ioport.h> | 21 | #include <linux/ioport.h> |
22 | #include <linux/init.h> | 22 | #include <linux/init.h> |
23 | #include <linux/smp_lock.h> | 23 | #include <linux/smp_lock.h> |
24 | #include <linux/initrd.h> | 24 | #include <linux/initrd.h> |
25 | #include <linux/bootmem.h> | 25 | #include <linux/bootmem.h> |
26 | #include <linux/tty.h> | 26 | #include <linux/tty.h> |
27 | #include <linux/gfp.h> | 27 | #include <linux/gfp.h> |
28 | #include <linux/percpu.h> | 28 | #include <linux/percpu.h> |
29 | #include <linux/kmod.h> | 29 | #include <linux/kmod.h> |
30 | #include <linux/vmalloc.h> | 30 | #include <linux/vmalloc.h> |
31 | #include <linux/kernel_stat.h> | 31 | #include <linux/kernel_stat.h> |
32 | #include <linux/start_kernel.h> | 32 | #include <linux/start_kernel.h> |
33 | #include <linux/security.h> | 33 | #include <linux/security.h> |
34 | #include <linux/smp.h> | 34 | #include <linux/smp.h> |
35 | #include <linux/workqueue.h> | 35 | #include <linux/workqueue.h> |
36 | #include <linux/profile.h> | 36 | #include <linux/profile.h> |
37 | #include <linux/rcupdate.h> | 37 | #include <linux/rcupdate.h> |
38 | #include <linux/moduleparam.h> | 38 | #include <linux/moduleparam.h> |
39 | #include <linux/kallsyms.h> | 39 | #include <linux/kallsyms.h> |
40 | #include <linux/writeback.h> | 40 | #include <linux/writeback.h> |
41 | #include <linux/cpu.h> | 41 | #include <linux/cpu.h> |
42 | #include <linux/cpuset.h> | 42 | #include <linux/cpuset.h> |
43 | #include <linux/cgroup.h> | 43 | #include <linux/cgroup.h> |
44 | #include <linux/efi.h> | 44 | #include <linux/efi.h> |
45 | #include <linux/tick.h> | 45 | #include <linux/tick.h> |
46 | #include <linux/interrupt.h> | 46 | #include <linux/interrupt.h> |
47 | #include <linux/taskstats_kern.h> | 47 | #include <linux/taskstats_kern.h> |
48 | #include <linux/delayacct.h> | 48 | #include <linux/delayacct.h> |
49 | #include <linux/unistd.h> | 49 | #include <linux/unistd.h> |
50 | #include <linux/rmap.h> | 50 | #include <linux/rmap.h> |
51 | #include <linux/mempolicy.h> | 51 | #include <linux/mempolicy.h> |
52 | #include <linux/key.h> | 52 | #include <linux/key.h> |
53 | #include <linux/unwind.h> | ||
54 | #include <linux/buffer_head.h> | 53 | #include <linux/buffer_head.h> |
55 | #include <linux/page_cgroup.h> | 54 | #include <linux/page_cgroup.h> |
56 | #include <linux/debug_locks.h> | 55 | #include <linux/debug_locks.h> |
57 | #include <linux/debugobjects.h> | 56 | #include <linux/debugobjects.h> |
58 | #include <linux/lockdep.h> | 57 | #include <linux/lockdep.h> |
59 | #include <linux/pid_namespace.h> | 58 | #include <linux/pid_namespace.h> |
60 | #include <linux/device.h> | 59 | #include <linux/device.h> |
61 | #include <linux/kthread.h> | 60 | #include <linux/kthread.h> |
62 | #include <linux/sched.h> | 61 | #include <linux/sched.h> |
63 | #include <linux/signal.h> | 62 | #include <linux/signal.h> |
64 | #include <linux/idr.h> | 63 | #include <linux/idr.h> |
65 | #include <linux/ftrace.h> | 64 | #include <linux/ftrace.h> |
66 | #include <trace/boot.h> | 65 | #include <trace/boot.h> |
67 | 66 | ||
68 | #include <asm/io.h> | 67 | #include <asm/io.h> |
69 | #include <asm/bugs.h> | 68 | #include <asm/bugs.h> |
70 | #include <asm/setup.h> | 69 | #include <asm/setup.h> |
71 | #include <asm/sections.h> | 70 | #include <asm/sections.h> |
72 | #include <asm/cacheflush.h> | 71 | #include <asm/cacheflush.h> |
73 | 72 | ||
74 | #ifdef CONFIG_X86_LOCAL_APIC | 73 | #ifdef CONFIG_X86_LOCAL_APIC |
75 | #include <asm/smp.h> | 74 | #include <asm/smp.h> |
76 | #endif | 75 | #endif |
77 | 76 | ||
78 | static int kernel_init(void *); | 77 | static int kernel_init(void *); |
79 | 78 | ||
80 | extern void init_IRQ(void); | 79 | extern void init_IRQ(void); |
81 | extern void fork_init(unsigned long); | 80 | extern void fork_init(unsigned long); |
82 | extern void mca_init(void); | 81 | extern void mca_init(void); |
83 | extern void sbus_init(void); | 82 | extern void sbus_init(void); |
84 | extern void prio_tree_init(void); | 83 | extern void prio_tree_init(void); |
85 | extern void radix_tree_init(void); | 84 | extern void radix_tree_init(void); |
86 | extern void free_initmem(void); | 85 | extern void free_initmem(void); |
87 | #ifdef CONFIG_ACPI | 86 | #ifdef CONFIG_ACPI |
88 | extern void acpi_early_init(void); | 87 | extern void acpi_early_init(void); |
89 | #else | 88 | #else |
90 | static inline void acpi_early_init(void) { } | 89 | static inline void acpi_early_init(void) { } |
91 | #endif | 90 | #endif |
92 | #ifndef CONFIG_DEBUG_RODATA | 91 | #ifndef CONFIG_DEBUG_RODATA |
93 | static inline void mark_rodata_ro(void) { } | 92 | static inline void mark_rodata_ro(void) { } |
94 | #endif | 93 | #endif |
95 | 94 | ||
96 | #ifdef CONFIG_TC | 95 | #ifdef CONFIG_TC |
97 | extern void tc_init(void); | 96 | extern void tc_init(void); |
98 | #endif | 97 | #endif |
99 | 98 | ||
100 | enum system_states system_state; | 99 | enum system_states system_state; |
101 | EXPORT_SYMBOL(system_state); | 100 | EXPORT_SYMBOL(system_state); |
102 | 101 | ||
103 | /* | 102 | /* |
104 | * Boot command-line arguments | 103 | * Boot command-line arguments |
105 | */ | 104 | */ |
106 | #define MAX_INIT_ARGS CONFIG_INIT_ENV_ARG_LIMIT | 105 | #define MAX_INIT_ARGS CONFIG_INIT_ENV_ARG_LIMIT |
107 | #define MAX_INIT_ENVS CONFIG_INIT_ENV_ARG_LIMIT | 106 | #define MAX_INIT_ENVS CONFIG_INIT_ENV_ARG_LIMIT |
108 | 107 | ||
109 | extern void time_init(void); | 108 | extern void time_init(void); |
110 | /* Default late time init is NULL. archs can override this later. */ | 109 | /* Default late time init is NULL. archs can override this later. */ |
111 | void (*late_time_init)(void); | 110 | void (*late_time_init)(void); |
112 | extern void softirq_init(void); | 111 | extern void softirq_init(void); |
113 | 112 | ||
114 | /* Untouched command line saved by arch-specific code. */ | 113 | /* Untouched command line saved by arch-specific code. */ |
115 | char __initdata boot_command_line[COMMAND_LINE_SIZE]; | 114 | char __initdata boot_command_line[COMMAND_LINE_SIZE]; |
116 | /* Untouched saved command line (eg. for /proc) */ | 115 | /* Untouched saved command line (eg. for /proc) */ |
117 | char *saved_command_line; | 116 | char *saved_command_line; |
118 | /* Command line for parameter parsing */ | 117 | /* Command line for parameter parsing */ |
119 | static char *static_command_line; | 118 | static char *static_command_line; |
120 | 119 | ||
121 | static char *execute_command; | 120 | static char *execute_command; |
122 | static char *ramdisk_execute_command; | 121 | static char *ramdisk_execute_command; |
123 | 122 | ||
124 | #ifdef CONFIG_SMP | 123 | #ifdef CONFIG_SMP |
125 | /* Setup configured maximum number of CPUs to activate */ | 124 | /* Setup configured maximum number of CPUs to activate */ |
126 | unsigned int __initdata setup_max_cpus = NR_CPUS; | 125 | unsigned int __initdata setup_max_cpus = NR_CPUS; |
127 | 126 | ||
128 | /* | 127 | /* |
129 | * Setup routine for controlling SMP activation | 128 | * Setup routine for controlling SMP activation |
130 | * | 129 | * |
131 | * Command-line option of "nosmp" or "maxcpus=0" will disable SMP | 130 | * Command-line option of "nosmp" or "maxcpus=0" will disable SMP |
132 | * activation entirely (the MPS table probe still happens, though). | 131 | * activation entirely (the MPS table probe still happens, though). |
133 | * | 132 | * |
134 | * Command-line option of "maxcpus=<NUM>", where <NUM> is an integer | 133 | * Command-line option of "maxcpus=<NUM>", where <NUM> is an integer |
135 | * greater than 0, limits the maximum number of CPUs activated in | 134 | * greater than 0, limits the maximum number of CPUs activated in |
136 | * SMP mode to <NUM>. | 135 | * SMP mode to <NUM>. |
137 | */ | 136 | */ |
138 | #ifndef CONFIG_X86_IO_APIC | 137 | #ifndef CONFIG_X86_IO_APIC |
139 | static inline void disable_ioapic_setup(void) {}; | 138 | static inline void disable_ioapic_setup(void) {}; |
140 | #endif | 139 | #endif |
141 | 140 | ||
142 | static int __init nosmp(char *str) | 141 | static int __init nosmp(char *str) |
143 | { | 142 | { |
144 | setup_max_cpus = 0; | 143 | setup_max_cpus = 0; |
145 | disable_ioapic_setup(); | 144 | disable_ioapic_setup(); |
146 | return 0; | 145 | return 0; |
147 | } | 146 | } |
148 | 147 | ||
149 | early_param("nosmp", nosmp); | 148 | early_param("nosmp", nosmp); |
150 | 149 | ||
151 | static int __init maxcpus(char *str) | 150 | static int __init maxcpus(char *str) |
152 | { | 151 | { |
153 | get_option(&str, &setup_max_cpus); | 152 | get_option(&str, &setup_max_cpus); |
154 | if (setup_max_cpus == 0) | 153 | if (setup_max_cpus == 0) |
155 | disable_ioapic_setup(); | 154 | disable_ioapic_setup(); |
156 | 155 | ||
157 | return 0; | 156 | return 0; |
158 | } | 157 | } |
159 | 158 | ||
160 | early_param("maxcpus", maxcpus); | 159 | early_param("maxcpus", maxcpus); |
161 | #else | 160 | #else |
162 | #define setup_max_cpus NR_CPUS | 161 | #define setup_max_cpus NR_CPUS |
163 | #endif | 162 | #endif |
164 | 163 | ||
165 | /* | 164 | /* |
166 | * If set, this is an indication to the drivers that reset the underlying | 165 | * If set, this is an indication to the drivers that reset the underlying |
167 | * device before going ahead with the initialization otherwise driver might | 166 | * device before going ahead with the initialization otherwise driver might |
168 | * rely on the BIOS and skip the reset operation. | 167 | * rely on the BIOS and skip the reset operation. |
169 | * | 168 | * |
170 | * This is useful if kernel is booting in an unreliable environment. | 169 | * This is useful if kernel is booting in an unreliable environment. |
171 | * For ex. kdump situaiton where previous kernel has crashed, BIOS has been | 170 | * For ex. kdump situaiton where previous kernel has crashed, BIOS has been |
172 | * skipped and devices will be in unknown state. | 171 | * skipped and devices will be in unknown state. |
173 | */ | 172 | */ |
174 | unsigned int reset_devices; | 173 | unsigned int reset_devices; |
175 | EXPORT_SYMBOL(reset_devices); | 174 | EXPORT_SYMBOL(reset_devices); |
176 | 175 | ||
177 | static int __init set_reset_devices(char *str) | 176 | static int __init set_reset_devices(char *str) |
178 | { | 177 | { |
179 | reset_devices = 1; | 178 | reset_devices = 1; |
180 | return 1; | 179 | return 1; |
181 | } | 180 | } |
182 | 181 | ||
183 | __setup("reset_devices", set_reset_devices); | 182 | __setup("reset_devices", set_reset_devices); |
184 | 183 | ||
185 | static char * argv_init[MAX_INIT_ARGS+2] = { "init", NULL, }; | 184 | static char * argv_init[MAX_INIT_ARGS+2] = { "init", NULL, }; |
186 | char * envp_init[MAX_INIT_ENVS+2] = { "HOME=/", "TERM=linux", NULL, }; | 185 | char * envp_init[MAX_INIT_ENVS+2] = { "HOME=/", "TERM=linux", NULL, }; |
187 | static const char *panic_later, *panic_param; | 186 | static const char *panic_later, *panic_param; |
188 | 187 | ||
189 | extern struct obs_kernel_param __setup_start[], __setup_end[]; | 188 | extern struct obs_kernel_param __setup_start[], __setup_end[]; |
190 | 189 | ||
191 | static int __init obsolete_checksetup(char *line) | 190 | static int __init obsolete_checksetup(char *line) |
192 | { | 191 | { |
193 | struct obs_kernel_param *p; | 192 | struct obs_kernel_param *p; |
194 | int had_early_param = 0; | 193 | int had_early_param = 0; |
195 | 194 | ||
196 | p = __setup_start; | 195 | p = __setup_start; |
197 | do { | 196 | do { |
198 | int n = strlen(p->str); | 197 | int n = strlen(p->str); |
199 | if (!strncmp(line, p->str, n)) { | 198 | if (!strncmp(line, p->str, n)) { |
200 | if (p->early) { | 199 | if (p->early) { |
201 | /* Already done in parse_early_param? | 200 | /* Already done in parse_early_param? |
202 | * (Needs exact match on param part). | 201 | * (Needs exact match on param part). |
203 | * Keep iterating, as we can have early | 202 | * Keep iterating, as we can have early |
204 | * params and __setups of same names 8( */ | 203 | * params and __setups of same names 8( */ |
205 | if (line[n] == '\0' || line[n] == '=') | 204 | if (line[n] == '\0' || line[n] == '=') |
206 | had_early_param = 1; | 205 | had_early_param = 1; |
207 | } else if (!p->setup_func) { | 206 | } else if (!p->setup_func) { |
208 | printk(KERN_WARNING "Parameter %s is obsolete," | 207 | printk(KERN_WARNING "Parameter %s is obsolete," |
209 | " ignored\n", p->str); | 208 | " ignored\n", p->str); |
210 | return 1; | 209 | return 1; |
211 | } else if (p->setup_func(line + n)) | 210 | } else if (p->setup_func(line + n)) |
212 | return 1; | 211 | return 1; |
213 | } | 212 | } |
214 | p++; | 213 | p++; |
215 | } while (p < __setup_end); | 214 | } while (p < __setup_end); |
216 | 215 | ||
217 | return had_early_param; | 216 | return had_early_param; |
218 | } | 217 | } |
219 | 218 | ||
220 | /* | 219 | /* |
221 | * This should be approx 2 Bo*oMips to start (note initial shift), and will | 220 | * This should be approx 2 Bo*oMips to start (note initial shift), and will |
222 | * still work even if initially too large, it will just take slightly longer | 221 | * still work even if initially too large, it will just take slightly longer |
223 | */ | 222 | */ |
224 | unsigned long loops_per_jiffy = (1<<12); | 223 | unsigned long loops_per_jiffy = (1<<12); |
225 | 224 | ||
226 | EXPORT_SYMBOL(loops_per_jiffy); | 225 | EXPORT_SYMBOL(loops_per_jiffy); |
227 | 226 | ||
228 | static int __init debug_kernel(char *str) | 227 | static int __init debug_kernel(char *str) |
229 | { | 228 | { |
230 | console_loglevel = 10; | 229 | console_loglevel = 10; |
231 | return 0; | 230 | return 0; |
232 | } | 231 | } |
233 | 232 | ||
234 | static int __init quiet_kernel(char *str) | 233 | static int __init quiet_kernel(char *str) |
235 | { | 234 | { |
236 | console_loglevel = 4; | 235 | console_loglevel = 4; |
237 | return 0; | 236 | return 0; |
238 | } | 237 | } |
239 | 238 | ||
240 | early_param("debug", debug_kernel); | 239 | early_param("debug", debug_kernel); |
241 | early_param("quiet", quiet_kernel); | 240 | early_param("quiet", quiet_kernel); |
242 | 241 | ||
243 | static int __init loglevel(char *str) | 242 | static int __init loglevel(char *str) |
244 | { | 243 | { |
245 | get_option(&str, &console_loglevel); | 244 | get_option(&str, &console_loglevel); |
246 | return 0; | 245 | return 0; |
247 | } | 246 | } |
248 | 247 | ||
249 | early_param("loglevel", loglevel); | 248 | early_param("loglevel", loglevel); |
250 | 249 | ||
251 | /* | 250 | /* |
252 | * Unknown boot options get handed to init, unless they look like | 251 | * Unknown boot options get handed to init, unless they look like |
253 | * failed parameters | 252 | * failed parameters |
254 | */ | 253 | */ |
255 | static int __init unknown_bootoption(char *param, char *val) | 254 | static int __init unknown_bootoption(char *param, char *val) |
256 | { | 255 | { |
257 | /* Change NUL term back to "=", to make "param" the whole string. */ | 256 | /* Change NUL term back to "=", to make "param" the whole string. */ |
258 | if (val) { | 257 | if (val) { |
259 | /* param=val or param="val"? */ | 258 | /* param=val or param="val"? */ |
260 | if (val == param+strlen(param)+1) | 259 | if (val == param+strlen(param)+1) |
261 | val[-1] = '='; | 260 | val[-1] = '='; |
262 | else if (val == param+strlen(param)+2) { | 261 | else if (val == param+strlen(param)+2) { |
263 | val[-2] = '='; | 262 | val[-2] = '='; |
264 | memmove(val-1, val, strlen(val)+1); | 263 | memmove(val-1, val, strlen(val)+1); |
265 | val--; | 264 | val--; |
266 | } else | 265 | } else |
267 | BUG(); | 266 | BUG(); |
268 | } | 267 | } |
269 | 268 | ||
270 | /* Handle obsolete-style parameters */ | 269 | /* Handle obsolete-style parameters */ |
271 | if (obsolete_checksetup(param)) | 270 | if (obsolete_checksetup(param)) |
272 | return 0; | 271 | return 0; |
273 | 272 | ||
274 | /* | 273 | /* |
275 | * Preemptive maintenance for "why didn't my misspelled command | 274 | * Preemptive maintenance for "why didn't my misspelled command |
276 | * line work?" | 275 | * line work?" |
277 | */ | 276 | */ |
278 | if (strchr(param, '.') && (!val || strchr(param, '.') < val)) { | 277 | if (strchr(param, '.') && (!val || strchr(param, '.') < val)) { |
279 | printk(KERN_ERR "Unknown boot option `%s': ignoring\n", param); | 278 | printk(KERN_ERR "Unknown boot option `%s': ignoring\n", param); |
280 | return 0; | 279 | return 0; |
281 | } | 280 | } |
282 | 281 | ||
283 | if (panic_later) | 282 | if (panic_later) |
284 | return 0; | 283 | return 0; |
285 | 284 | ||
286 | if (val) { | 285 | if (val) { |
287 | /* Environment option */ | 286 | /* Environment option */ |
288 | unsigned int i; | 287 | unsigned int i; |
289 | for (i = 0; envp_init[i]; i++) { | 288 | for (i = 0; envp_init[i]; i++) { |
290 | if (i == MAX_INIT_ENVS) { | 289 | if (i == MAX_INIT_ENVS) { |
291 | panic_later = "Too many boot env vars at `%s'"; | 290 | panic_later = "Too many boot env vars at `%s'"; |
292 | panic_param = param; | 291 | panic_param = param; |
293 | } | 292 | } |
294 | if (!strncmp(param, envp_init[i], val - param)) | 293 | if (!strncmp(param, envp_init[i], val - param)) |
295 | break; | 294 | break; |
296 | } | 295 | } |
297 | envp_init[i] = param; | 296 | envp_init[i] = param; |
298 | } else { | 297 | } else { |
299 | /* Command line option */ | 298 | /* Command line option */ |
300 | unsigned int i; | 299 | unsigned int i; |
301 | for (i = 0; argv_init[i]; i++) { | 300 | for (i = 0; argv_init[i]; i++) { |
302 | if (i == MAX_INIT_ARGS) { | 301 | if (i == MAX_INIT_ARGS) { |
303 | panic_later = "Too many boot init vars at `%s'"; | 302 | panic_later = "Too many boot init vars at `%s'"; |
304 | panic_param = param; | 303 | panic_param = param; |
305 | } | 304 | } |
306 | } | 305 | } |
307 | argv_init[i] = param; | 306 | argv_init[i] = param; |
308 | } | 307 | } |
309 | return 0; | 308 | return 0; |
310 | } | 309 | } |
311 | 310 | ||
312 | #ifdef CONFIG_DEBUG_PAGEALLOC | 311 | #ifdef CONFIG_DEBUG_PAGEALLOC |
313 | int __read_mostly debug_pagealloc_enabled = 0; | 312 | int __read_mostly debug_pagealloc_enabled = 0; |
314 | #endif | 313 | #endif |
315 | 314 | ||
316 | static int __init init_setup(char *str) | 315 | static int __init init_setup(char *str) |
317 | { | 316 | { |
318 | unsigned int i; | 317 | unsigned int i; |
319 | 318 | ||
320 | execute_command = str; | 319 | execute_command = str; |
321 | /* | 320 | /* |
322 | * In case LILO is going to boot us with default command line, | 321 | * In case LILO is going to boot us with default command line, |
323 | * it prepends "auto" before the whole cmdline which makes | 322 | * it prepends "auto" before the whole cmdline which makes |
324 | * the shell think it should execute a script with such name. | 323 | * the shell think it should execute a script with such name. |
325 | * So we ignore all arguments entered _before_ init=... [MJ] | 324 | * So we ignore all arguments entered _before_ init=... [MJ] |
326 | */ | 325 | */ |
327 | for (i = 1; i < MAX_INIT_ARGS; i++) | 326 | for (i = 1; i < MAX_INIT_ARGS; i++) |
328 | argv_init[i] = NULL; | 327 | argv_init[i] = NULL; |
329 | return 1; | 328 | return 1; |
330 | } | 329 | } |
331 | __setup("init=", init_setup); | 330 | __setup("init=", init_setup); |
332 | 331 | ||
333 | static int __init rdinit_setup(char *str) | 332 | static int __init rdinit_setup(char *str) |
334 | { | 333 | { |
335 | unsigned int i; | 334 | unsigned int i; |
336 | 335 | ||
337 | ramdisk_execute_command = str; | 336 | ramdisk_execute_command = str; |
338 | /* See "auto" comment in init_setup */ | 337 | /* See "auto" comment in init_setup */ |
339 | for (i = 1; i < MAX_INIT_ARGS; i++) | 338 | for (i = 1; i < MAX_INIT_ARGS; i++) |
340 | argv_init[i] = NULL; | 339 | argv_init[i] = NULL; |
341 | return 1; | 340 | return 1; |
342 | } | 341 | } |
343 | __setup("rdinit=", rdinit_setup); | 342 | __setup("rdinit=", rdinit_setup); |
344 | 343 | ||
345 | #ifndef CONFIG_SMP | 344 | #ifndef CONFIG_SMP |
346 | 345 | ||
347 | #ifdef CONFIG_X86_LOCAL_APIC | 346 | #ifdef CONFIG_X86_LOCAL_APIC |
348 | static void __init smp_init(void) | 347 | static void __init smp_init(void) |
349 | { | 348 | { |
350 | APIC_init_uniprocessor(); | 349 | APIC_init_uniprocessor(); |
351 | } | 350 | } |
352 | #else | 351 | #else |
353 | #define smp_init() do { } while (0) | 352 | #define smp_init() do { } while (0) |
354 | #endif | 353 | #endif |
355 | 354 | ||
356 | static inline void setup_per_cpu_areas(void) { } | 355 | static inline void setup_per_cpu_areas(void) { } |
357 | static inline void setup_nr_cpu_ids(void) { } | 356 | static inline void setup_nr_cpu_ids(void) { } |
358 | static inline void smp_prepare_cpus(unsigned int maxcpus) { } | 357 | static inline void smp_prepare_cpus(unsigned int maxcpus) { } |
359 | 358 | ||
360 | #else | 359 | #else |
361 | 360 | ||
362 | #if NR_CPUS > BITS_PER_LONG | 361 | #if NR_CPUS > BITS_PER_LONG |
363 | cpumask_t cpu_mask_all __read_mostly = CPU_MASK_ALL; | 362 | cpumask_t cpu_mask_all __read_mostly = CPU_MASK_ALL; |
364 | EXPORT_SYMBOL(cpu_mask_all); | 363 | EXPORT_SYMBOL(cpu_mask_all); |
365 | #endif | 364 | #endif |
366 | 365 | ||
367 | /* Setup number of possible processor ids */ | 366 | /* Setup number of possible processor ids */ |
368 | int nr_cpu_ids __read_mostly = NR_CPUS; | 367 | int nr_cpu_ids __read_mostly = NR_CPUS; |
369 | EXPORT_SYMBOL(nr_cpu_ids); | 368 | EXPORT_SYMBOL(nr_cpu_ids); |
370 | 369 | ||
371 | /* An arch may set nr_cpu_ids earlier if needed, so this would be redundant */ | 370 | /* An arch may set nr_cpu_ids earlier if needed, so this would be redundant */ |
372 | static void __init setup_nr_cpu_ids(void) | 371 | static void __init setup_nr_cpu_ids(void) |
373 | { | 372 | { |
374 | nr_cpu_ids = find_last_bit(cpumask_bits(cpu_possible_mask),NR_CPUS) + 1; | 373 | nr_cpu_ids = find_last_bit(cpumask_bits(cpu_possible_mask),NR_CPUS) + 1; |
375 | } | 374 | } |
376 | 375 | ||
377 | #ifndef CONFIG_HAVE_SETUP_PER_CPU_AREA | 376 | #ifndef CONFIG_HAVE_SETUP_PER_CPU_AREA |
378 | unsigned long __per_cpu_offset[NR_CPUS] __read_mostly; | 377 | unsigned long __per_cpu_offset[NR_CPUS] __read_mostly; |
379 | 378 | ||
380 | EXPORT_SYMBOL(__per_cpu_offset); | 379 | EXPORT_SYMBOL(__per_cpu_offset); |
381 | 380 | ||
382 | static void __init setup_per_cpu_areas(void) | 381 | static void __init setup_per_cpu_areas(void) |
383 | { | 382 | { |
384 | unsigned long size, i; | 383 | unsigned long size, i; |
385 | char *ptr; | 384 | char *ptr; |
386 | unsigned long nr_possible_cpus = num_possible_cpus(); | 385 | unsigned long nr_possible_cpus = num_possible_cpus(); |
387 | 386 | ||
388 | /* Copy section for each CPU (we discard the original) */ | 387 | /* Copy section for each CPU (we discard the original) */ |
389 | size = ALIGN(PERCPU_ENOUGH_ROOM, PAGE_SIZE); | 388 | size = ALIGN(PERCPU_ENOUGH_ROOM, PAGE_SIZE); |
390 | ptr = alloc_bootmem_pages(size * nr_possible_cpus); | 389 | ptr = alloc_bootmem_pages(size * nr_possible_cpus); |
391 | 390 | ||
392 | for_each_possible_cpu(i) { | 391 | for_each_possible_cpu(i) { |
393 | __per_cpu_offset[i] = ptr - __per_cpu_start; | 392 | __per_cpu_offset[i] = ptr - __per_cpu_start; |
394 | memcpy(ptr, __per_cpu_start, __per_cpu_end - __per_cpu_start); | 393 | memcpy(ptr, __per_cpu_start, __per_cpu_end - __per_cpu_start); |
395 | ptr += size; | 394 | ptr += size; |
396 | } | 395 | } |
397 | } | 396 | } |
398 | #endif /* CONFIG_HAVE_SETUP_PER_CPU_AREA */ | 397 | #endif /* CONFIG_HAVE_SETUP_PER_CPU_AREA */ |
399 | 398 | ||
400 | /* Called by boot processor to activate the rest. */ | 399 | /* Called by boot processor to activate the rest. */ |
401 | static void __init smp_init(void) | 400 | static void __init smp_init(void) |
402 | { | 401 | { |
403 | unsigned int cpu; | 402 | unsigned int cpu; |
404 | 403 | ||
405 | /* | 404 | /* |
406 | * Set up the current CPU as possible to migrate to. | 405 | * Set up the current CPU as possible to migrate to. |
407 | * The other ones will be done by cpu_up/cpu_down() | 406 | * The other ones will be done by cpu_up/cpu_down() |
408 | */ | 407 | */ |
409 | cpu = smp_processor_id(); | 408 | cpu = smp_processor_id(); |
410 | cpu_set(cpu, cpu_active_map); | 409 | cpu_set(cpu, cpu_active_map); |
411 | 410 | ||
412 | /* FIXME: This should be done in userspace --RR */ | 411 | /* FIXME: This should be done in userspace --RR */ |
413 | for_each_present_cpu(cpu) { | 412 | for_each_present_cpu(cpu) { |
414 | if (num_online_cpus() >= setup_max_cpus) | 413 | if (num_online_cpus() >= setup_max_cpus) |
415 | break; | 414 | break; |
416 | if (!cpu_online(cpu)) | 415 | if (!cpu_online(cpu)) |
417 | cpu_up(cpu); | 416 | cpu_up(cpu); |
418 | } | 417 | } |
419 | 418 | ||
420 | /* Any cleanup work */ | 419 | /* Any cleanup work */ |
421 | printk(KERN_INFO "Brought up %ld CPUs\n", (long)num_online_cpus()); | 420 | printk(KERN_INFO "Brought up %ld CPUs\n", (long)num_online_cpus()); |
422 | smp_cpus_done(setup_max_cpus); | 421 | smp_cpus_done(setup_max_cpus); |
423 | } | 422 | } |
424 | 423 | ||
425 | #endif | 424 | #endif |
426 | 425 | ||
427 | /* | 426 | /* |
428 | * We need to store the untouched command line for future reference. | 427 | * We need to store the untouched command line for future reference. |
429 | * We also need to store the touched command line since the parameter | 428 | * We also need to store the touched command line since the parameter |
430 | * parsing is performed in place, and we should allow a component to | 429 | * parsing is performed in place, and we should allow a component to |
431 | * store reference of name/value for future reference. | 430 | * store reference of name/value for future reference. |
432 | */ | 431 | */ |
433 | static void __init setup_command_line(char *command_line) | 432 | static void __init setup_command_line(char *command_line) |
434 | { | 433 | { |
435 | saved_command_line = alloc_bootmem(strlen (boot_command_line)+1); | 434 | saved_command_line = alloc_bootmem(strlen (boot_command_line)+1); |
436 | static_command_line = alloc_bootmem(strlen (command_line)+1); | 435 | static_command_line = alloc_bootmem(strlen (command_line)+1); |
437 | strcpy (saved_command_line, boot_command_line); | 436 | strcpy (saved_command_line, boot_command_line); |
438 | strcpy (static_command_line, command_line); | 437 | strcpy (static_command_line, command_line); |
439 | } | 438 | } |
440 | 439 | ||
441 | /* | 440 | /* |
442 | * We need to finalize in a non-__init function or else race conditions | 441 | * We need to finalize in a non-__init function or else race conditions |
443 | * between the root thread and the init thread may cause start_kernel to | 442 | * between the root thread and the init thread may cause start_kernel to |
444 | * be reaped by free_initmem before the root thread has proceeded to | 443 | * be reaped by free_initmem before the root thread has proceeded to |
445 | * cpu_idle. | 444 | * cpu_idle. |
446 | * | 445 | * |
447 | * gcc-3.4 accidentally inlines this function, so use noinline. | 446 | * gcc-3.4 accidentally inlines this function, so use noinline. |
448 | */ | 447 | */ |
449 | 448 | ||
450 | static noinline void __init_refok rest_init(void) | 449 | static noinline void __init_refok rest_init(void) |
451 | __releases(kernel_lock) | 450 | __releases(kernel_lock) |
452 | { | 451 | { |
453 | int pid; | 452 | int pid; |
454 | 453 | ||
455 | kernel_thread(kernel_init, NULL, CLONE_FS | CLONE_SIGHAND); | 454 | kernel_thread(kernel_init, NULL, CLONE_FS | CLONE_SIGHAND); |
456 | numa_default_policy(); | 455 | numa_default_policy(); |
457 | pid = kernel_thread(kthreadd, NULL, CLONE_FS | CLONE_FILES); | 456 | pid = kernel_thread(kthreadd, NULL, CLONE_FS | CLONE_FILES); |
458 | kthreadd_task = find_task_by_pid_ns(pid, &init_pid_ns); | 457 | kthreadd_task = find_task_by_pid_ns(pid, &init_pid_ns); |
459 | unlock_kernel(); | 458 | unlock_kernel(); |
460 | 459 | ||
461 | /* | 460 | /* |
462 | * The boot idle thread must execute schedule() | 461 | * The boot idle thread must execute schedule() |
463 | * at least once to get things moving: | 462 | * at least once to get things moving: |
464 | */ | 463 | */ |
465 | init_idle_bootup_task(current); | 464 | init_idle_bootup_task(current); |
466 | preempt_enable_no_resched(); | 465 | preempt_enable_no_resched(); |
467 | schedule(); | 466 | schedule(); |
468 | preempt_disable(); | 467 | preempt_disable(); |
469 | 468 | ||
470 | /* Call into cpu_idle with preempt disabled */ | 469 | /* Call into cpu_idle with preempt disabled */ |
471 | cpu_idle(); | 470 | cpu_idle(); |
472 | } | 471 | } |
473 | 472 | ||
474 | /* Check for early params. */ | 473 | /* Check for early params. */ |
475 | static int __init do_early_param(char *param, char *val) | 474 | static int __init do_early_param(char *param, char *val) |
476 | { | 475 | { |
477 | struct obs_kernel_param *p; | 476 | struct obs_kernel_param *p; |
478 | 477 | ||
479 | for (p = __setup_start; p < __setup_end; p++) { | 478 | for (p = __setup_start; p < __setup_end; p++) { |
480 | if ((p->early && strcmp(param, p->str) == 0) || | 479 | if ((p->early && strcmp(param, p->str) == 0) || |
481 | (strcmp(param, "console") == 0 && | 480 | (strcmp(param, "console") == 0 && |
482 | strcmp(p->str, "earlycon") == 0) | 481 | strcmp(p->str, "earlycon") == 0) |
483 | ) { | 482 | ) { |
484 | if (p->setup_func(val) != 0) | 483 | if (p->setup_func(val) != 0) |
485 | printk(KERN_WARNING | 484 | printk(KERN_WARNING |
486 | "Malformed early option '%s'\n", param); | 485 | "Malformed early option '%s'\n", param); |
487 | } | 486 | } |
488 | } | 487 | } |
489 | /* We accept everything at this stage. */ | 488 | /* We accept everything at this stage. */ |
490 | return 0; | 489 | return 0; |
491 | } | 490 | } |
492 | 491 | ||
493 | /* Arch code calls this early on, or if not, just before other parsing. */ | 492 | /* Arch code calls this early on, or if not, just before other parsing. */ |
494 | void __init parse_early_param(void) | 493 | void __init parse_early_param(void) |
495 | { | 494 | { |
496 | static __initdata int done = 0; | 495 | static __initdata int done = 0; |
497 | static __initdata char tmp_cmdline[COMMAND_LINE_SIZE]; | 496 | static __initdata char tmp_cmdline[COMMAND_LINE_SIZE]; |
498 | 497 | ||
499 | if (done) | 498 | if (done) |
500 | return; | 499 | return; |
501 | 500 | ||
502 | /* All fall through to do_early_param. */ | 501 | /* All fall through to do_early_param. */ |
503 | strlcpy(tmp_cmdline, boot_command_line, COMMAND_LINE_SIZE); | 502 | strlcpy(tmp_cmdline, boot_command_line, COMMAND_LINE_SIZE); |
504 | parse_args("early options", tmp_cmdline, NULL, 0, do_early_param); | 503 | parse_args("early options", tmp_cmdline, NULL, 0, do_early_param); |
505 | done = 1; | 504 | done = 1; |
506 | } | 505 | } |
507 | 506 | ||
508 | /* | 507 | /* |
509 | * Activate the first processor. | 508 | * Activate the first processor. |
510 | */ | 509 | */ |
511 | 510 | ||
512 | static void __init boot_cpu_init(void) | 511 | static void __init boot_cpu_init(void) |
513 | { | 512 | { |
514 | int cpu = smp_processor_id(); | 513 | int cpu = smp_processor_id(); |
515 | /* Mark the boot cpu "present", "online" etc for SMP and UP case */ | 514 | /* Mark the boot cpu "present", "online" etc for SMP and UP case */ |
516 | set_cpu_online(cpu, true); | 515 | set_cpu_online(cpu, true); |
517 | set_cpu_present(cpu, true); | 516 | set_cpu_present(cpu, true); |
518 | set_cpu_possible(cpu, true); | 517 | set_cpu_possible(cpu, true); |
519 | } | 518 | } |
520 | 519 | ||
521 | void __init __weak smp_setup_processor_id(void) | 520 | void __init __weak smp_setup_processor_id(void) |
522 | { | 521 | { |
523 | } | 522 | } |
524 | 523 | ||
525 | void __init __weak thread_info_cache_init(void) | 524 | void __init __weak thread_info_cache_init(void) |
526 | { | 525 | { |
527 | } | 526 | } |
528 | 527 | ||
529 | asmlinkage void __init start_kernel(void) | 528 | asmlinkage void __init start_kernel(void) |
530 | { | 529 | { |
531 | char * command_line; | 530 | char * command_line; |
532 | extern struct kernel_param __start___param[], __stop___param[]; | 531 | extern struct kernel_param __start___param[], __stop___param[]; |
533 | 532 | ||
534 | smp_setup_processor_id(); | 533 | smp_setup_processor_id(); |
535 | 534 | ||
536 | /* | 535 | /* |
537 | * Need to run as early as possible, to initialize the | 536 | * Need to run as early as possible, to initialize the |
538 | * lockdep hash: | 537 | * lockdep hash: |
539 | */ | 538 | */ |
540 | unwind_init(); | ||
541 | lockdep_init(); | 539 | lockdep_init(); |
542 | debug_objects_early_init(); | 540 | debug_objects_early_init(); |
543 | cgroup_init_early(); | 541 | cgroup_init_early(); |
544 | 542 | ||
545 | local_irq_disable(); | 543 | local_irq_disable(); |
546 | early_boot_irqs_off(); | 544 | early_boot_irqs_off(); |
547 | early_init_irq_lock_class(); | 545 | early_init_irq_lock_class(); |
548 | 546 | ||
549 | /* | 547 | /* |
550 | * Interrupts are still disabled. Do necessary setups, then | 548 | * Interrupts are still disabled. Do necessary setups, then |
551 | * enable them | 549 | * enable them |
552 | */ | 550 | */ |
553 | lock_kernel(); | 551 | lock_kernel(); |
554 | tick_init(); | 552 | tick_init(); |
555 | boot_cpu_init(); | 553 | boot_cpu_init(); |
556 | page_address_init(); | 554 | page_address_init(); |
557 | printk(KERN_NOTICE); | 555 | printk(KERN_NOTICE); |
558 | printk(linux_banner); | 556 | printk(linux_banner); |
559 | setup_arch(&command_line); | 557 | setup_arch(&command_line); |
560 | mm_init_owner(&init_mm, &init_task); | 558 | mm_init_owner(&init_mm, &init_task); |
561 | setup_command_line(command_line); | 559 | setup_command_line(command_line); |
562 | unwind_setup(); | ||
563 | setup_per_cpu_areas(); | 560 | setup_per_cpu_areas(); |
564 | setup_nr_cpu_ids(); | 561 | setup_nr_cpu_ids(); |
565 | smp_prepare_boot_cpu(); /* arch-specific boot-cpu hooks */ | 562 | smp_prepare_boot_cpu(); /* arch-specific boot-cpu hooks */ |
566 | 563 | ||
567 | /* | 564 | /* |
568 | * Set up the scheduler prior starting any interrupts (such as the | 565 | * Set up the scheduler prior starting any interrupts (such as the |
569 | * timer interrupt). Full topology setup happens at smp_init() | 566 | * timer interrupt). Full topology setup happens at smp_init() |
570 | * time - but meanwhile we still have a functioning scheduler. | 567 | * time - but meanwhile we still have a functioning scheduler. |
571 | */ | 568 | */ |
572 | sched_init(); | 569 | sched_init(); |
573 | /* | 570 | /* |
574 | * Disable preemption - early bootup scheduling is extremely | 571 | * Disable preemption - early bootup scheduling is extremely |
575 | * fragile until we cpu_idle() for the first time. | 572 | * fragile until we cpu_idle() for the first time. |
576 | */ | 573 | */ |
577 | preempt_disable(); | 574 | preempt_disable(); |
578 | build_all_zonelists(); | 575 | build_all_zonelists(); |
579 | page_alloc_init(); | 576 | page_alloc_init(); |
580 | printk(KERN_NOTICE "Kernel command line: %s\n", boot_command_line); | 577 | printk(KERN_NOTICE "Kernel command line: %s\n", boot_command_line); |
581 | parse_early_param(); | 578 | parse_early_param(); |
582 | parse_args("Booting kernel", static_command_line, __start___param, | 579 | parse_args("Booting kernel", static_command_line, __start___param, |
583 | __stop___param - __start___param, | 580 | __stop___param - __start___param, |
584 | &unknown_bootoption); | 581 | &unknown_bootoption); |
585 | if (!irqs_disabled()) { | 582 | if (!irqs_disabled()) { |
586 | printk(KERN_WARNING "start_kernel(): bug: interrupts were " | 583 | printk(KERN_WARNING "start_kernel(): bug: interrupts were " |
587 | "enabled *very* early, fixing it\n"); | 584 | "enabled *very* early, fixing it\n"); |
588 | local_irq_disable(); | 585 | local_irq_disable(); |
589 | } | 586 | } |
590 | sort_main_extable(); | 587 | sort_main_extable(); |
591 | trap_init(); | 588 | trap_init(); |
592 | rcu_init(); | 589 | rcu_init(); |
593 | /* init some links before init_ISA_irqs() */ | 590 | /* init some links before init_ISA_irqs() */ |
594 | early_irq_init(); | 591 | early_irq_init(); |
595 | init_IRQ(); | 592 | init_IRQ(); |
596 | pidhash_init(); | 593 | pidhash_init(); |
597 | init_timers(); | 594 | init_timers(); |
598 | hrtimers_init(); | 595 | hrtimers_init(); |
599 | softirq_init(); | 596 | softirq_init(); |
600 | timekeeping_init(); | 597 | timekeeping_init(); |
601 | time_init(); | 598 | time_init(); |
602 | sched_clock_init(); | 599 | sched_clock_init(); |
603 | profile_init(); | 600 | profile_init(); |
604 | if (!irqs_disabled()) | 601 | if (!irqs_disabled()) |
605 | printk("start_kernel(): bug: interrupts were enabled early\n"); | 602 | printk("start_kernel(): bug: interrupts were enabled early\n"); |
606 | early_boot_irqs_on(); | 603 | early_boot_irqs_on(); |
607 | local_irq_enable(); | 604 | local_irq_enable(); |
608 | 605 | ||
609 | /* | 606 | /* |
610 | * HACK ALERT! This is early. We're enabling the console before | 607 | * HACK ALERT! This is early. We're enabling the console before |
611 | * we've done PCI setups etc, and console_init() must be aware of | 608 | * we've done PCI setups etc, and console_init() must be aware of |
612 | * this. But we do want output early, in case something goes wrong. | 609 | * this. But we do want output early, in case something goes wrong. |
613 | */ | 610 | */ |
614 | console_init(); | 611 | console_init(); |
615 | if (panic_later) | 612 | if (panic_later) |
616 | panic(panic_later, panic_param); | 613 | panic(panic_later, panic_param); |
617 | 614 | ||
618 | lockdep_info(); | 615 | lockdep_info(); |
619 | 616 | ||
620 | /* | 617 | /* |
621 | * Need to run this when irqs are enabled, because it wants | 618 | * Need to run this when irqs are enabled, because it wants |
622 | * to self-test [hard/soft]-irqs on/off lock inversion bugs | 619 | * to self-test [hard/soft]-irqs on/off lock inversion bugs |
623 | * too: | 620 | * too: |
624 | */ | 621 | */ |
625 | locking_selftest(); | 622 | locking_selftest(); |
626 | 623 | ||
627 | #ifdef CONFIG_BLK_DEV_INITRD | 624 | #ifdef CONFIG_BLK_DEV_INITRD |
628 | if (initrd_start && !initrd_below_start_ok && | 625 | if (initrd_start && !initrd_below_start_ok && |
629 | page_to_pfn(virt_to_page((void *)initrd_start)) < min_low_pfn) { | 626 | page_to_pfn(virt_to_page((void *)initrd_start)) < min_low_pfn) { |
630 | printk(KERN_CRIT "initrd overwritten (0x%08lx < 0x%08lx) - " | 627 | printk(KERN_CRIT "initrd overwritten (0x%08lx < 0x%08lx) - " |
631 | "disabling it.\n", | 628 | "disabling it.\n", |
632 | page_to_pfn(virt_to_page((void *)initrd_start)), | 629 | page_to_pfn(virt_to_page((void *)initrd_start)), |
633 | min_low_pfn); | 630 | min_low_pfn); |
634 | initrd_start = 0; | 631 | initrd_start = 0; |
635 | } | 632 | } |
636 | #endif | 633 | #endif |
637 | vmalloc_init(); | 634 | vmalloc_init(); |
638 | vfs_caches_init_early(); | 635 | vfs_caches_init_early(); |
639 | cpuset_init_early(); | 636 | cpuset_init_early(); |
640 | page_cgroup_init(); | 637 | page_cgroup_init(); |
641 | mem_init(); | 638 | mem_init(); |
642 | enable_debug_pagealloc(); | 639 | enable_debug_pagealloc(); |
643 | cpu_hotplug_init(); | 640 | cpu_hotplug_init(); |
644 | kmem_cache_init(); | 641 | kmem_cache_init(); |
645 | debug_objects_mem_init(); | 642 | debug_objects_mem_init(); |
646 | idr_init_cache(); | 643 | idr_init_cache(); |
647 | setup_per_cpu_pageset(); | 644 | setup_per_cpu_pageset(); |
648 | numa_policy_init(); | 645 | numa_policy_init(); |
649 | if (late_time_init) | 646 | if (late_time_init) |
650 | late_time_init(); | 647 | late_time_init(); |
651 | calibrate_delay(); | 648 | calibrate_delay(); |
652 | pidmap_init(); | 649 | pidmap_init(); |
653 | pgtable_cache_init(); | 650 | pgtable_cache_init(); |
654 | prio_tree_init(); | 651 | prio_tree_init(); |
655 | anon_vma_init(); | 652 | anon_vma_init(); |
656 | #ifdef CONFIG_X86 | 653 | #ifdef CONFIG_X86 |
657 | if (efi_enabled) | 654 | if (efi_enabled) |
658 | efi_enter_virtual_mode(); | 655 | efi_enter_virtual_mode(); |
659 | #endif | 656 | #endif |
660 | thread_info_cache_init(); | 657 | thread_info_cache_init(); |
661 | cred_init(); | 658 | cred_init(); |
662 | fork_init(num_physpages); | 659 | fork_init(num_physpages); |
663 | proc_caches_init(); | 660 | proc_caches_init(); |
664 | buffer_init(); | 661 | buffer_init(); |
665 | key_init(); | 662 | key_init(); |
666 | security_init(); | 663 | security_init(); |
667 | vfs_caches_init(num_physpages); | 664 | vfs_caches_init(num_physpages); |
668 | radix_tree_init(); | 665 | radix_tree_init(); |
669 | signals_init(); | 666 | signals_init(); |
670 | /* rootfs populating might need page-writeback */ | 667 | /* rootfs populating might need page-writeback */ |
671 | page_writeback_init(); | 668 | page_writeback_init(); |
672 | #ifdef CONFIG_PROC_FS | 669 | #ifdef CONFIG_PROC_FS |
673 | proc_root_init(); | 670 | proc_root_init(); |
674 | #endif | 671 | #endif |
675 | cgroup_init(); | 672 | cgroup_init(); |
676 | cpuset_init(); | 673 | cpuset_init(); |
677 | taskstats_init_early(); | 674 | taskstats_init_early(); |
678 | delayacct_init(); | 675 | delayacct_init(); |
679 | 676 | ||
680 | check_bugs(); | 677 | check_bugs(); |
681 | 678 | ||
682 | acpi_early_init(); /* before LAPIC and SMP init */ | 679 | acpi_early_init(); /* before LAPIC and SMP init */ |
683 | 680 | ||
684 | ftrace_init(); | 681 | ftrace_init(); |
685 | 682 | ||
686 | /* Do the rest non-__init'ed, we're now alive */ | 683 | /* Do the rest non-__init'ed, we're now alive */ |
687 | rest_init(); | 684 | rest_init(); |
688 | } | 685 | } |
689 | 686 | ||
690 | static int initcall_debug; | 687 | static int initcall_debug; |
691 | core_param(initcall_debug, initcall_debug, bool, 0644); | 688 | core_param(initcall_debug, initcall_debug, bool, 0644); |
692 | 689 | ||
693 | int do_one_initcall(initcall_t fn) | 690 | int do_one_initcall(initcall_t fn) |
694 | { | 691 | { |
695 | int count = preempt_count(); | 692 | int count = preempt_count(); |
696 | ktime_t calltime, delta, rettime; | 693 | ktime_t calltime, delta, rettime; |
697 | char msgbuf[64]; | 694 | char msgbuf[64]; |
698 | struct boot_trace_call call; | 695 | struct boot_trace_call call; |
699 | struct boot_trace_ret ret; | 696 | struct boot_trace_ret ret; |
700 | 697 | ||
701 | if (initcall_debug) { | 698 | if (initcall_debug) { |
702 | call.caller = task_pid_nr(current); | 699 | call.caller = task_pid_nr(current); |
703 | printk("calling %pF @ %i\n", fn, call.caller); | 700 | printk("calling %pF @ %i\n", fn, call.caller); |
704 | calltime = ktime_get(); | 701 | calltime = ktime_get(); |
705 | trace_boot_call(&call, fn); | 702 | trace_boot_call(&call, fn); |
706 | enable_boot_trace(); | 703 | enable_boot_trace(); |
707 | } | 704 | } |
708 | 705 | ||
709 | ret.result = fn(); | 706 | ret.result = fn(); |
710 | 707 | ||
711 | if (initcall_debug) { | 708 | if (initcall_debug) { |
712 | disable_boot_trace(); | 709 | disable_boot_trace(); |
713 | rettime = ktime_get(); | 710 | rettime = ktime_get(); |
714 | delta = ktime_sub(rettime, calltime); | 711 | delta = ktime_sub(rettime, calltime); |
715 | ret.duration = (unsigned long long) ktime_to_ns(delta) >> 10; | 712 | ret.duration = (unsigned long long) ktime_to_ns(delta) >> 10; |
716 | trace_boot_ret(&ret, fn); | 713 | trace_boot_ret(&ret, fn); |
717 | printk("initcall %pF returned %d after %Ld usecs\n", fn, | 714 | printk("initcall %pF returned %d after %Ld usecs\n", fn, |
718 | ret.result, ret.duration); | 715 | ret.result, ret.duration); |
719 | } | 716 | } |
720 | 717 | ||
721 | msgbuf[0] = 0; | 718 | msgbuf[0] = 0; |
722 | 719 | ||
723 | if (ret.result && ret.result != -ENODEV && initcall_debug) | 720 | if (ret.result && ret.result != -ENODEV && initcall_debug) |
724 | sprintf(msgbuf, "error code %d ", ret.result); | 721 | sprintf(msgbuf, "error code %d ", ret.result); |
725 | 722 | ||
726 | if (preempt_count() != count) { | 723 | if (preempt_count() != count) { |
727 | strlcat(msgbuf, "preemption imbalance ", sizeof(msgbuf)); | 724 | strlcat(msgbuf, "preemption imbalance ", sizeof(msgbuf)); |
728 | preempt_count() = count; | 725 | preempt_count() = count; |
729 | } | 726 | } |
730 | if (irqs_disabled()) { | 727 | if (irqs_disabled()) { |
731 | strlcat(msgbuf, "disabled interrupts ", sizeof(msgbuf)); | 728 | strlcat(msgbuf, "disabled interrupts ", sizeof(msgbuf)); |
732 | local_irq_enable(); | 729 | local_irq_enable(); |
733 | } | 730 | } |
734 | if (msgbuf[0]) { | 731 | if (msgbuf[0]) { |
735 | printk("initcall %pF returned with %s\n", fn, msgbuf); | 732 | printk("initcall %pF returned with %s\n", fn, msgbuf); |
736 | } | 733 | } |
737 | 734 | ||
738 | return ret.result; | 735 | return ret.result; |
739 | } | 736 | } |
740 | 737 | ||
741 | 738 | ||
742 | extern initcall_t __initcall_start[], __initcall_end[], __early_initcall_end[]; | 739 | extern initcall_t __initcall_start[], __initcall_end[], __early_initcall_end[]; |
743 | 740 | ||
744 | static void __init do_initcalls(void) | 741 | static void __init do_initcalls(void) |
745 | { | 742 | { |
746 | initcall_t *call; | 743 | initcall_t *call; |
747 | 744 | ||
748 | for (call = __early_initcall_end; call < __initcall_end; call++) | 745 | for (call = __early_initcall_end; call < __initcall_end; call++) |
749 | do_one_initcall(*call); | 746 | do_one_initcall(*call); |
750 | 747 | ||
751 | /* Make sure there is no pending stuff from the initcall sequence */ | 748 | /* Make sure there is no pending stuff from the initcall sequence */ |
752 | flush_scheduled_work(); | 749 | flush_scheduled_work(); |
753 | } | 750 | } |
754 | 751 | ||
755 | /* | 752 | /* |
756 | * Ok, the machine is now initialized. None of the devices | 753 | * Ok, the machine is now initialized. None of the devices |
757 | * have been touched yet, but the CPU subsystem is up and | 754 | * have been touched yet, but the CPU subsystem is up and |
758 | * running, and memory and process management works. | 755 | * running, and memory and process management works. |
759 | * | 756 | * |
760 | * Now we can finally start doing some real work.. | 757 | * Now we can finally start doing some real work.. |
761 | */ | 758 | */ |
762 | static void __init do_basic_setup(void) | 759 | static void __init do_basic_setup(void) |
763 | { | 760 | { |
764 | rcu_init_sched(); /* needed by module_init stage. */ | 761 | rcu_init_sched(); /* needed by module_init stage. */ |
765 | init_workqueues(); | 762 | init_workqueues(); |
766 | usermodehelper_init(); | 763 | usermodehelper_init(); |
767 | driver_init(); | 764 | driver_init(); |
768 | init_irq_proc(); | 765 | init_irq_proc(); |
769 | do_initcalls(); | 766 | do_initcalls(); |
770 | } | 767 | } |
771 | 768 | ||
772 | static void __init do_pre_smp_initcalls(void) | 769 | static void __init do_pre_smp_initcalls(void) |
773 | { | 770 | { |
774 | initcall_t *call; | 771 | initcall_t *call; |
775 | 772 | ||
776 | for (call = __initcall_start; call < __early_initcall_end; call++) | 773 | for (call = __initcall_start; call < __early_initcall_end; call++) |
777 | do_one_initcall(*call); | 774 | do_one_initcall(*call); |
778 | } | 775 | } |
779 | 776 | ||
780 | static void run_init_process(char *init_filename) | 777 | static void run_init_process(char *init_filename) |
781 | { | 778 | { |
782 | argv_init[0] = init_filename; | 779 | argv_init[0] = init_filename; |
783 | kernel_execve(init_filename, argv_init, envp_init); | 780 | kernel_execve(init_filename, argv_init, envp_init); |
784 | } | 781 | } |
785 | 782 | ||
786 | /* This is a non __init function. Force it to be noinline otherwise gcc | 783 | /* This is a non __init function. Force it to be noinline otherwise gcc |
787 | * makes it inline to init() and it becomes part of init.text section | 784 | * makes it inline to init() and it becomes part of init.text section |
788 | */ | 785 | */ |
789 | static noinline int init_post(void) | 786 | static noinline int init_post(void) |
790 | { | 787 | { |
791 | free_initmem(); | 788 | free_initmem(); |
792 | unlock_kernel(); | 789 | unlock_kernel(); |
793 | mark_rodata_ro(); | 790 | mark_rodata_ro(); |
794 | system_state = SYSTEM_RUNNING; | 791 | system_state = SYSTEM_RUNNING; |
795 | numa_default_policy(); | 792 | numa_default_policy(); |
796 | 793 | ||
797 | if (sys_open((const char __user *) "/dev/console", O_RDWR, 0) < 0) | 794 | if (sys_open((const char __user *) "/dev/console", O_RDWR, 0) < 0) |
798 | printk(KERN_WARNING "Warning: unable to open an initial console.\n"); | 795 | printk(KERN_WARNING "Warning: unable to open an initial console.\n"); |
799 | 796 | ||
800 | (void) sys_dup(0); | 797 | (void) sys_dup(0); |
801 | (void) sys_dup(0); | 798 | (void) sys_dup(0); |
802 | 799 | ||
803 | current->signal->flags |= SIGNAL_UNKILLABLE; | 800 | current->signal->flags |= SIGNAL_UNKILLABLE; |
804 | 801 | ||
805 | if (ramdisk_execute_command) { | 802 | if (ramdisk_execute_command) { |
806 | run_init_process(ramdisk_execute_command); | 803 | run_init_process(ramdisk_execute_command); |
807 | printk(KERN_WARNING "Failed to execute %s\n", | 804 | printk(KERN_WARNING "Failed to execute %s\n", |
808 | ramdisk_execute_command); | 805 | ramdisk_execute_command); |
809 | } | 806 | } |
810 | 807 | ||
811 | /* | 808 | /* |
812 | * We try each of these until one succeeds. | 809 | * We try each of these until one succeeds. |
813 | * | 810 | * |
814 | * The Bourne shell can be used instead of init if we are | 811 | * The Bourne shell can be used instead of init if we are |
815 | * trying to recover a really broken machine. | 812 | * trying to recover a really broken machine. |
816 | */ | 813 | */ |
817 | if (execute_command) { | 814 | if (execute_command) { |
818 | run_init_process(execute_command); | 815 | run_init_process(execute_command); |
819 | printk(KERN_WARNING "Failed to execute %s. Attempting " | 816 | printk(KERN_WARNING "Failed to execute %s. Attempting " |
820 | "defaults...\n", execute_command); | 817 | "defaults...\n", execute_command); |
821 | } | 818 | } |
822 | run_init_process("/sbin/init"); | 819 | run_init_process("/sbin/init"); |
823 | run_init_process("/etc/init"); | 820 | run_init_process("/etc/init"); |
824 | run_init_process("/bin/init"); | 821 | run_init_process("/bin/init"); |
825 | run_init_process("/bin/sh"); | 822 | run_init_process("/bin/sh"); |
826 | 823 | ||
827 | panic("No init found. Try passing init= option to kernel."); | 824 | panic("No init found. Try passing init= option to kernel."); |
828 | } | 825 | } |
829 | 826 | ||
830 | static int __init kernel_init(void * unused) | 827 | static int __init kernel_init(void * unused) |
831 | { | 828 | { |
832 | lock_kernel(); | 829 | lock_kernel(); |
833 | /* | 830 | /* |
834 | * init can run on any cpu. | 831 | * init can run on any cpu. |
835 | */ | 832 | */ |
836 | set_cpus_allowed_ptr(current, CPU_MASK_ALL_PTR); | 833 | set_cpus_allowed_ptr(current, CPU_MASK_ALL_PTR); |
837 | /* | 834 | /* |
838 | * Tell the world that we're going to be the grim | 835 | * Tell the world that we're going to be the grim |
839 | * reaper of innocent orphaned children. | 836 | * reaper of innocent orphaned children. |
840 | * | 837 | * |
841 | * We don't want people to have to make incorrect | 838 | * We don't want people to have to make incorrect |
842 | * assumptions about where in the task array this | 839 | * assumptions about where in the task array this |
843 | * can be found. | 840 | * can be found. |
844 | */ | 841 | */ |
845 | init_pid_ns.child_reaper = current; | 842 | init_pid_ns.child_reaper = current; |
846 | 843 | ||
847 | cad_pid = task_pid(current); | 844 | cad_pid = task_pid(current); |
848 | 845 | ||
849 | smp_prepare_cpus(setup_max_cpus); | 846 | smp_prepare_cpus(setup_max_cpus); |
850 | 847 | ||
851 | do_pre_smp_initcalls(); | 848 | do_pre_smp_initcalls(); |
852 | start_boot_trace(); | 849 | start_boot_trace(); |
853 | 850 | ||
854 | smp_init(); | 851 | smp_init(); |
855 | sched_init_smp(); | 852 | sched_init_smp(); |
856 | 853 | ||
857 | cpuset_init_smp(); | 854 | cpuset_init_smp(); |
858 | 855 | ||
859 | do_basic_setup(); | 856 | do_basic_setup(); |
860 | 857 | ||
861 | /* | 858 | /* |
862 | * check if there is an early userspace init. If yes, let it do all | 859 | * check if there is an early userspace init. If yes, let it do all |
863 | * the work | 860 | * the work |
864 | */ | 861 | */ |
865 | 862 | ||
866 | if (!ramdisk_execute_command) | 863 | if (!ramdisk_execute_command) |
867 | ramdisk_execute_command = "/init"; | 864 | ramdisk_execute_command = "/init"; |
868 | 865 | ||
869 | if (sys_access((const char __user *) ramdisk_execute_command, 0) != 0) { | 866 | if (sys_access((const char __user *) ramdisk_execute_command, 0) != 0) { |
870 | ramdisk_execute_command = NULL; | 867 | ramdisk_execute_command = NULL; |
871 | prepare_namespace(); | 868 | prepare_namespace(); |
872 | } | 869 | } |
873 | 870 | ||
874 | /* | 871 | /* |
875 | * Ok, we have completed the initial bootup, and | 872 | * Ok, we have completed the initial bootup, and |
876 | * we're essentially up and running. Get rid of the | 873 | * we're essentially up and running. Get rid of the |
877 | * initmem segments and start the user-mode stuff.. | 874 | * initmem segments and start the user-mode stuff.. |
878 | */ | 875 | */ |
879 | 876 | ||
880 | init_post(); | 877 | init_post(); |
881 | return 0; | 878 | return 0; |
882 | } | 879 | } |
883 | 880 |
kernel/module.c
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/init.h> | 21 | #include <linux/init.h> |
22 | #include <linux/kallsyms.h> | 22 | #include <linux/kallsyms.h> |
23 | #include <linux/fs.h> | 23 | #include <linux/fs.h> |
24 | #include <linux/sysfs.h> | 24 | #include <linux/sysfs.h> |
25 | #include <linux/kernel.h> | 25 | #include <linux/kernel.h> |
26 | #include <linux/slab.h> | 26 | #include <linux/slab.h> |
27 | #include <linux/vmalloc.h> | 27 | #include <linux/vmalloc.h> |
28 | #include <linux/elf.h> | 28 | #include <linux/elf.h> |
29 | #include <linux/proc_fs.h> | 29 | #include <linux/proc_fs.h> |
30 | #include <linux/seq_file.h> | 30 | #include <linux/seq_file.h> |
31 | #include <linux/syscalls.h> | 31 | #include <linux/syscalls.h> |
32 | #include <linux/fcntl.h> | 32 | #include <linux/fcntl.h> |
33 | #include <linux/rcupdate.h> | 33 | #include <linux/rcupdate.h> |
34 | #include <linux/capability.h> | 34 | #include <linux/capability.h> |
35 | #include <linux/cpu.h> | 35 | #include <linux/cpu.h> |
36 | #include <linux/moduleparam.h> | 36 | #include <linux/moduleparam.h> |
37 | #include <linux/errno.h> | 37 | #include <linux/errno.h> |
38 | #include <linux/err.h> | 38 | #include <linux/err.h> |
39 | #include <linux/vermagic.h> | 39 | #include <linux/vermagic.h> |
40 | #include <linux/notifier.h> | 40 | #include <linux/notifier.h> |
41 | #include <linux/sched.h> | 41 | #include <linux/sched.h> |
42 | #include <linux/stop_machine.h> | 42 | #include <linux/stop_machine.h> |
43 | #include <linux/device.h> | 43 | #include <linux/device.h> |
44 | #include <linux/string.h> | 44 | #include <linux/string.h> |
45 | #include <linux/mutex.h> | 45 | #include <linux/mutex.h> |
46 | #include <linux/unwind.h> | ||
47 | #include <linux/rculist.h> | 46 | #include <linux/rculist.h> |
48 | #include <asm/uaccess.h> | 47 | #include <asm/uaccess.h> |
49 | #include <asm/cacheflush.h> | 48 | #include <asm/cacheflush.h> |
50 | #include <linux/license.h> | 49 | #include <linux/license.h> |
51 | #include <asm/sections.h> | 50 | #include <asm/sections.h> |
52 | #include <linux/tracepoint.h> | 51 | #include <linux/tracepoint.h> |
53 | #include <linux/ftrace.h> | 52 | #include <linux/ftrace.h> |
54 | 53 | ||
55 | #if 0 | 54 | #if 0 |
56 | #define DEBUGP printk | 55 | #define DEBUGP printk |
57 | #else | 56 | #else |
58 | #define DEBUGP(fmt , a...) | 57 | #define DEBUGP(fmt , a...) |
59 | #endif | 58 | #endif |
60 | 59 | ||
61 | #ifndef ARCH_SHF_SMALL | 60 | #ifndef ARCH_SHF_SMALL |
62 | #define ARCH_SHF_SMALL 0 | 61 | #define ARCH_SHF_SMALL 0 |
63 | #endif | 62 | #endif |
64 | 63 | ||
65 | /* If this is set, the section belongs in the init part of the module */ | 64 | /* If this is set, the section belongs in the init part of the module */ |
66 | #define INIT_OFFSET_MASK (1UL << (BITS_PER_LONG-1)) | 65 | #define INIT_OFFSET_MASK (1UL << (BITS_PER_LONG-1)) |
67 | 66 | ||
68 | /* List of modules, protected by module_mutex or preempt_disable | 67 | /* List of modules, protected by module_mutex or preempt_disable |
69 | * (delete uses stop_machine/add uses RCU list operations). */ | 68 | * (delete uses stop_machine/add uses RCU list operations). */ |
70 | static DEFINE_MUTEX(module_mutex); | 69 | static DEFINE_MUTEX(module_mutex); |
71 | static LIST_HEAD(modules); | 70 | static LIST_HEAD(modules); |
72 | 71 | ||
73 | /* Waiting for a module to finish initializing? */ | 72 | /* Waiting for a module to finish initializing? */ |
74 | static DECLARE_WAIT_QUEUE_HEAD(module_wq); | 73 | static DECLARE_WAIT_QUEUE_HEAD(module_wq); |
75 | 74 | ||
76 | static BLOCKING_NOTIFIER_HEAD(module_notify_list); | 75 | static BLOCKING_NOTIFIER_HEAD(module_notify_list); |
77 | 76 | ||
78 | /* Bounds of module allocation, for speeding __module_text_address */ | 77 | /* Bounds of module allocation, for speeding __module_text_address */ |
79 | static unsigned long module_addr_min = -1UL, module_addr_max = 0; | 78 | static unsigned long module_addr_min = -1UL, module_addr_max = 0; |
80 | 79 | ||
81 | int register_module_notifier(struct notifier_block * nb) | 80 | int register_module_notifier(struct notifier_block * nb) |
82 | { | 81 | { |
83 | return blocking_notifier_chain_register(&module_notify_list, nb); | 82 | return blocking_notifier_chain_register(&module_notify_list, nb); |
84 | } | 83 | } |
85 | EXPORT_SYMBOL(register_module_notifier); | 84 | EXPORT_SYMBOL(register_module_notifier); |
86 | 85 | ||
87 | int unregister_module_notifier(struct notifier_block * nb) | 86 | int unregister_module_notifier(struct notifier_block * nb) |
88 | { | 87 | { |
89 | return blocking_notifier_chain_unregister(&module_notify_list, nb); | 88 | return blocking_notifier_chain_unregister(&module_notify_list, nb); |
90 | } | 89 | } |
91 | EXPORT_SYMBOL(unregister_module_notifier); | 90 | EXPORT_SYMBOL(unregister_module_notifier); |
92 | 91 | ||
93 | /* We require a truly strong try_module_get(): 0 means failure due to | 92 | /* We require a truly strong try_module_get(): 0 means failure due to |
94 | ongoing or failed initialization etc. */ | 93 | ongoing or failed initialization etc. */ |
95 | static inline int strong_try_module_get(struct module *mod) | 94 | static inline int strong_try_module_get(struct module *mod) |
96 | { | 95 | { |
97 | if (mod && mod->state == MODULE_STATE_COMING) | 96 | if (mod && mod->state == MODULE_STATE_COMING) |
98 | return -EBUSY; | 97 | return -EBUSY; |
99 | if (try_module_get(mod)) | 98 | if (try_module_get(mod)) |
100 | return 0; | 99 | return 0; |
101 | else | 100 | else |
102 | return -ENOENT; | 101 | return -ENOENT; |
103 | } | 102 | } |
104 | 103 | ||
105 | static inline void add_taint_module(struct module *mod, unsigned flag) | 104 | static inline void add_taint_module(struct module *mod, unsigned flag) |
106 | { | 105 | { |
107 | add_taint(flag); | 106 | add_taint(flag); |
108 | mod->taints |= (1U << flag); | 107 | mod->taints |= (1U << flag); |
109 | } | 108 | } |
110 | 109 | ||
111 | /* | 110 | /* |
112 | * A thread that wants to hold a reference to a module only while it | 111 | * A thread that wants to hold a reference to a module only while it |
113 | * is running can call this to safely exit. nfsd and lockd use this. | 112 | * is running can call this to safely exit. nfsd and lockd use this. |
114 | */ | 113 | */ |
115 | void __module_put_and_exit(struct module *mod, long code) | 114 | void __module_put_and_exit(struct module *mod, long code) |
116 | { | 115 | { |
117 | module_put(mod); | 116 | module_put(mod); |
118 | do_exit(code); | 117 | do_exit(code); |
119 | } | 118 | } |
120 | EXPORT_SYMBOL(__module_put_and_exit); | 119 | EXPORT_SYMBOL(__module_put_and_exit); |
121 | 120 | ||
122 | /* Find a module section: 0 means not found. */ | 121 | /* Find a module section: 0 means not found. */ |
123 | static unsigned int find_sec(Elf_Ehdr *hdr, | 122 | static unsigned int find_sec(Elf_Ehdr *hdr, |
124 | Elf_Shdr *sechdrs, | 123 | Elf_Shdr *sechdrs, |
125 | const char *secstrings, | 124 | const char *secstrings, |
126 | const char *name) | 125 | const char *name) |
127 | { | 126 | { |
128 | unsigned int i; | 127 | unsigned int i; |
129 | 128 | ||
130 | for (i = 1; i < hdr->e_shnum; i++) | 129 | for (i = 1; i < hdr->e_shnum; i++) |
131 | /* Alloc bit cleared means "ignore it." */ | 130 | /* Alloc bit cleared means "ignore it." */ |
132 | if ((sechdrs[i].sh_flags & SHF_ALLOC) | 131 | if ((sechdrs[i].sh_flags & SHF_ALLOC) |
133 | && strcmp(secstrings+sechdrs[i].sh_name, name) == 0) | 132 | && strcmp(secstrings+sechdrs[i].sh_name, name) == 0) |
134 | return i; | 133 | return i; |
135 | return 0; | 134 | return 0; |
136 | } | 135 | } |
137 | 136 | ||
138 | /* Find a module section, or NULL. */ | 137 | /* Find a module section, or NULL. */ |
139 | static void *section_addr(Elf_Ehdr *hdr, Elf_Shdr *shdrs, | 138 | static void *section_addr(Elf_Ehdr *hdr, Elf_Shdr *shdrs, |
140 | const char *secstrings, const char *name) | 139 | const char *secstrings, const char *name) |
141 | { | 140 | { |
142 | /* Section 0 has sh_addr 0. */ | 141 | /* Section 0 has sh_addr 0. */ |
143 | return (void *)shdrs[find_sec(hdr, shdrs, secstrings, name)].sh_addr; | 142 | return (void *)shdrs[find_sec(hdr, shdrs, secstrings, name)].sh_addr; |
144 | } | 143 | } |
145 | 144 | ||
146 | /* Find a module section, or NULL. Fill in number of "objects" in section. */ | 145 | /* Find a module section, or NULL. Fill in number of "objects" in section. */ |
147 | static void *section_objs(Elf_Ehdr *hdr, | 146 | static void *section_objs(Elf_Ehdr *hdr, |
148 | Elf_Shdr *sechdrs, | 147 | Elf_Shdr *sechdrs, |
149 | const char *secstrings, | 148 | const char *secstrings, |
150 | const char *name, | 149 | const char *name, |
151 | size_t object_size, | 150 | size_t object_size, |
152 | unsigned int *num) | 151 | unsigned int *num) |
153 | { | 152 | { |
154 | unsigned int sec = find_sec(hdr, sechdrs, secstrings, name); | 153 | unsigned int sec = find_sec(hdr, sechdrs, secstrings, name); |
155 | 154 | ||
156 | /* Section 0 has sh_addr 0 and sh_size 0. */ | 155 | /* Section 0 has sh_addr 0 and sh_size 0. */ |
157 | *num = sechdrs[sec].sh_size / object_size; | 156 | *num = sechdrs[sec].sh_size / object_size; |
158 | return (void *)sechdrs[sec].sh_addr; | 157 | return (void *)sechdrs[sec].sh_addr; |
159 | } | 158 | } |
160 | 159 | ||
161 | /* Provided by the linker */ | 160 | /* Provided by the linker */ |
162 | extern const struct kernel_symbol __start___ksymtab[]; | 161 | extern const struct kernel_symbol __start___ksymtab[]; |
163 | extern const struct kernel_symbol __stop___ksymtab[]; | 162 | extern const struct kernel_symbol __stop___ksymtab[]; |
164 | extern const struct kernel_symbol __start___ksymtab_gpl[]; | 163 | extern const struct kernel_symbol __start___ksymtab_gpl[]; |
165 | extern const struct kernel_symbol __stop___ksymtab_gpl[]; | 164 | extern const struct kernel_symbol __stop___ksymtab_gpl[]; |
166 | extern const struct kernel_symbol __start___ksymtab_gpl_future[]; | 165 | extern const struct kernel_symbol __start___ksymtab_gpl_future[]; |
167 | extern const struct kernel_symbol __stop___ksymtab_gpl_future[]; | 166 | extern const struct kernel_symbol __stop___ksymtab_gpl_future[]; |
168 | extern const struct kernel_symbol __start___ksymtab_gpl_future[]; | 167 | extern const struct kernel_symbol __start___ksymtab_gpl_future[]; |
169 | extern const struct kernel_symbol __stop___ksymtab_gpl_future[]; | 168 | extern const struct kernel_symbol __stop___ksymtab_gpl_future[]; |
170 | extern const unsigned long __start___kcrctab[]; | 169 | extern const unsigned long __start___kcrctab[]; |
171 | extern const unsigned long __start___kcrctab_gpl[]; | 170 | extern const unsigned long __start___kcrctab_gpl[]; |
172 | extern const unsigned long __start___kcrctab_gpl_future[]; | 171 | extern const unsigned long __start___kcrctab_gpl_future[]; |
173 | #ifdef CONFIG_UNUSED_SYMBOLS | 172 | #ifdef CONFIG_UNUSED_SYMBOLS |
174 | extern const struct kernel_symbol __start___ksymtab_unused[]; | 173 | extern const struct kernel_symbol __start___ksymtab_unused[]; |
175 | extern const struct kernel_symbol __stop___ksymtab_unused[]; | 174 | extern const struct kernel_symbol __stop___ksymtab_unused[]; |
176 | extern const struct kernel_symbol __start___ksymtab_unused_gpl[]; | 175 | extern const struct kernel_symbol __start___ksymtab_unused_gpl[]; |
177 | extern const struct kernel_symbol __stop___ksymtab_unused_gpl[]; | 176 | extern const struct kernel_symbol __stop___ksymtab_unused_gpl[]; |
178 | extern const unsigned long __start___kcrctab_unused[]; | 177 | extern const unsigned long __start___kcrctab_unused[]; |
179 | extern const unsigned long __start___kcrctab_unused_gpl[]; | 178 | extern const unsigned long __start___kcrctab_unused_gpl[]; |
180 | #endif | 179 | #endif |
181 | 180 | ||
182 | #ifndef CONFIG_MODVERSIONS | 181 | #ifndef CONFIG_MODVERSIONS |
183 | #define symversion(base, idx) NULL | 182 | #define symversion(base, idx) NULL |
184 | #else | 183 | #else |
185 | #define symversion(base, idx) ((base != NULL) ? ((base) + (idx)) : NULL) | 184 | #define symversion(base, idx) ((base != NULL) ? ((base) + (idx)) : NULL) |
186 | #endif | 185 | #endif |
187 | 186 | ||
188 | struct symsearch { | 187 | struct symsearch { |
189 | const struct kernel_symbol *start, *stop; | 188 | const struct kernel_symbol *start, *stop; |
190 | const unsigned long *crcs; | 189 | const unsigned long *crcs; |
191 | enum { | 190 | enum { |
192 | NOT_GPL_ONLY, | 191 | NOT_GPL_ONLY, |
193 | GPL_ONLY, | 192 | GPL_ONLY, |
194 | WILL_BE_GPL_ONLY, | 193 | WILL_BE_GPL_ONLY, |
195 | } licence; | 194 | } licence; |
196 | bool unused; | 195 | bool unused; |
197 | }; | 196 | }; |
198 | 197 | ||
199 | static bool each_symbol_in_section(const struct symsearch *arr, | 198 | static bool each_symbol_in_section(const struct symsearch *arr, |
200 | unsigned int arrsize, | 199 | unsigned int arrsize, |
201 | struct module *owner, | 200 | struct module *owner, |
202 | bool (*fn)(const struct symsearch *syms, | 201 | bool (*fn)(const struct symsearch *syms, |
203 | struct module *owner, | 202 | struct module *owner, |
204 | unsigned int symnum, void *data), | 203 | unsigned int symnum, void *data), |
205 | void *data) | 204 | void *data) |
206 | { | 205 | { |
207 | unsigned int i, j; | 206 | unsigned int i, j; |
208 | 207 | ||
209 | for (j = 0; j < arrsize; j++) { | 208 | for (j = 0; j < arrsize; j++) { |
210 | for (i = 0; i < arr[j].stop - arr[j].start; i++) | 209 | for (i = 0; i < arr[j].stop - arr[j].start; i++) |
211 | if (fn(&arr[j], owner, i, data)) | 210 | if (fn(&arr[j], owner, i, data)) |
212 | return true; | 211 | return true; |
213 | } | 212 | } |
214 | 213 | ||
215 | return false; | 214 | return false; |
216 | } | 215 | } |
217 | 216 | ||
218 | /* Returns true as soon as fn returns true, otherwise false. */ | 217 | /* Returns true as soon as fn returns true, otherwise false. */ |
219 | static bool each_symbol(bool (*fn)(const struct symsearch *arr, | 218 | static bool each_symbol(bool (*fn)(const struct symsearch *arr, |
220 | struct module *owner, | 219 | struct module *owner, |
221 | unsigned int symnum, void *data), | 220 | unsigned int symnum, void *data), |
222 | void *data) | 221 | void *data) |
223 | { | 222 | { |
224 | struct module *mod; | 223 | struct module *mod; |
225 | const struct symsearch arr[] = { | 224 | const struct symsearch arr[] = { |
226 | { __start___ksymtab, __stop___ksymtab, __start___kcrctab, | 225 | { __start___ksymtab, __stop___ksymtab, __start___kcrctab, |
227 | NOT_GPL_ONLY, false }, | 226 | NOT_GPL_ONLY, false }, |
228 | { __start___ksymtab_gpl, __stop___ksymtab_gpl, | 227 | { __start___ksymtab_gpl, __stop___ksymtab_gpl, |
229 | __start___kcrctab_gpl, | 228 | __start___kcrctab_gpl, |
230 | GPL_ONLY, false }, | 229 | GPL_ONLY, false }, |
231 | { __start___ksymtab_gpl_future, __stop___ksymtab_gpl_future, | 230 | { __start___ksymtab_gpl_future, __stop___ksymtab_gpl_future, |
232 | __start___kcrctab_gpl_future, | 231 | __start___kcrctab_gpl_future, |
233 | WILL_BE_GPL_ONLY, false }, | 232 | WILL_BE_GPL_ONLY, false }, |
234 | #ifdef CONFIG_UNUSED_SYMBOLS | 233 | #ifdef CONFIG_UNUSED_SYMBOLS |
235 | { __start___ksymtab_unused, __stop___ksymtab_unused, | 234 | { __start___ksymtab_unused, __stop___ksymtab_unused, |
236 | __start___kcrctab_unused, | 235 | __start___kcrctab_unused, |
237 | NOT_GPL_ONLY, true }, | 236 | NOT_GPL_ONLY, true }, |
238 | { __start___ksymtab_unused_gpl, __stop___ksymtab_unused_gpl, | 237 | { __start___ksymtab_unused_gpl, __stop___ksymtab_unused_gpl, |
239 | __start___kcrctab_unused_gpl, | 238 | __start___kcrctab_unused_gpl, |
240 | GPL_ONLY, true }, | 239 | GPL_ONLY, true }, |
241 | #endif | 240 | #endif |
242 | }; | 241 | }; |
243 | 242 | ||
244 | if (each_symbol_in_section(arr, ARRAY_SIZE(arr), NULL, fn, data)) | 243 | if (each_symbol_in_section(arr, ARRAY_SIZE(arr), NULL, fn, data)) |
245 | return true; | 244 | return true; |
246 | 245 | ||
247 | list_for_each_entry_rcu(mod, &modules, list) { | 246 | list_for_each_entry_rcu(mod, &modules, list) { |
248 | struct symsearch arr[] = { | 247 | struct symsearch arr[] = { |
249 | { mod->syms, mod->syms + mod->num_syms, mod->crcs, | 248 | { mod->syms, mod->syms + mod->num_syms, mod->crcs, |
250 | NOT_GPL_ONLY, false }, | 249 | NOT_GPL_ONLY, false }, |
251 | { mod->gpl_syms, mod->gpl_syms + mod->num_gpl_syms, | 250 | { mod->gpl_syms, mod->gpl_syms + mod->num_gpl_syms, |
252 | mod->gpl_crcs, | 251 | mod->gpl_crcs, |
253 | GPL_ONLY, false }, | 252 | GPL_ONLY, false }, |
254 | { mod->gpl_future_syms, | 253 | { mod->gpl_future_syms, |
255 | mod->gpl_future_syms + mod->num_gpl_future_syms, | 254 | mod->gpl_future_syms + mod->num_gpl_future_syms, |
256 | mod->gpl_future_crcs, | 255 | mod->gpl_future_crcs, |
257 | WILL_BE_GPL_ONLY, false }, | 256 | WILL_BE_GPL_ONLY, false }, |
258 | #ifdef CONFIG_UNUSED_SYMBOLS | 257 | #ifdef CONFIG_UNUSED_SYMBOLS |
259 | { mod->unused_syms, | 258 | { mod->unused_syms, |
260 | mod->unused_syms + mod->num_unused_syms, | 259 | mod->unused_syms + mod->num_unused_syms, |
261 | mod->unused_crcs, | 260 | mod->unused_crcs, |
262 | NOT_GPL_ONLY, true }, | 261 | NOT_GPL_ONLY, true }, |
263 | { mod->unused_gpl_syms, | 262 | { mod->unused_gpl_syms, |
264 | mod->unused_gpl_syms + mod->num_unused_gpl_syms, | 263 | mod->unused_gpl_syms + mod->num_unused_gpl_syms, |
265 | mod->unused_gpl_crcs, | 264 | mod->unused_gpl_crcs, |
266 | GPL_ONLY, true }, | 265 | GPL_ONLY, true }, |
267 | #endif | 266 | #endif |
268 | }; | 267 | }; |
269 | 268 | ||
270 | if (each_symbol_in_section(arr, ARRAY_SIZE(arr), mod, fn, data)) | 269 | if (each_symbol_in_section(arr, ARRAY_SIZE(arr), mod, fn, data)) |
271 | return true; | 270 | return true; |
272 | } | 271 | } |
273 | return false; | 272 | return false; |
274 | } | 273 | } |
275 | 274 | ||
276 | struct find_symbol_arg { | 275 | struct find_symbol_arg { |
277 | /* Input */ | 276 | /* Input */ |
278 | const char *name; | 277 | const char *name; |
279 | bool gplok; | 278 | bool gplok; |
280 | bool warn; | 279 | bool warn; |
281 | 280 | ||
282 | /* Output */ | 281 | /* Output */ |
283 | struct module *owner; | 282 | struct module *owner; |
284 | const unsigned long *crc; | 283 | const unsigned long *crc; |
285 | unsigned long value; | 284 | unsigned long value; |
286 | }; | 285 | }; |
287 | 286 | ||
288 | static bool find_symbol_in_section(const struct symsearch *syms, | 287 | static bool find_symbol_in_section(const struct symsearch *syms, |
289 | struct module *owner, | 288 | struct module *owner, |
290 | unsigned int symnum, void *data) | 289 | unsigned int symnum, void *data) |
291 | { | 290 | { |
292 | struct find_symbol_arg *fsa = data; | 291 | struct find_symbol_arg *fsa = data; |
293 | 292 | ||
294 | if (strcmp(syms->start[symnum].name, fsa->name) != 0) | 293 | if (strcmp(syms->start[symnum].name, fsa->name) != 0) |
295 | return false; | 294 | return false; |
296 | 295 | ||
297 | if (!fsa->gplok) { | 296 | if (!fsa->gplok) { |
298 | if (syms->licence == GPL_ONLY) | 297 | if (syms->licence == GPL_ONLY) |
299 | return false; | 298 | return false; |
300 | if (syms->licence == WILL_BE_GPL_ONLY && fsa->warn) { | 299 | if (syms->licence == WILL_BE_GPL_ONLY && fsa->warn) { |
301 | printk(KERN_WARNING "Symbol %s is being used " | 300 | printk(KERN_WARNING "Symbol %s is being used " |
302 | "by a non-GPL module, which will not " | 301 | "by a non-GPL module, which will not " |
303 | "be allowed in the future\n", fsa->name); | 302 | "be allowed in the future\n", fsa->name); |
304 | printk(KERN_WARNING "Please see the file " | 303 | printk(KERN_WARNING "Please see the file " |
305 | "Documentation/feature-removal-schedule.txt " | 304 | "Documentation/feature-removal-schedule.txt " |
306 | "in the kernel source tree for more details.\n"); | 305 | "in the kernel source tree for more details.\n"); |
307 | } | 306 | } |
308 | } | 307 | } |
309 | 308 | ||
310 | #ifdef CONFIG_UNUSED_SYMBOLS | 309 | #ifdef CONFIG_UNUSED_SYMBOLS |
311 | if (syms->unused && fsa->warn) { | 310 | if (syms->unused && fsa->warn) { |
312 | printk(KERN_WARNING "Symbol %s is marked as UNUSED, " | 311 | printk(KERN_WARNING "Symbol %s is marked as UNUSED, " |
313 | "however this module is using it.\n", fsa->name); | 312 | "however this module is using it.\n", fsa->name); |
314 | printk(KERN_WARNING | 313 | printk(KERN_WARNING |
315 | "This symbol will go away in the future.\n"); | 314 | "This symbol will go away in the future.\n"); |
316 | printk(KERN_WARNING | 315 | printk(KERN_WARNING |
317 | "Please evalute if this is the right api to use and if " | 316 | "Please evalute if this is the right api to use and if " |
318 | "it really is, submit a report the linux kernel " | 317 | "it really is, submit a report the linux kernel " |
319 | "mailinglist together with submitting your code for " | 318 | "mailinglist together with submitting your code for " |
320 | "inclusion.\n"); | 319 | "inclusion.\n"); |
321 | } | 320 | } |
322 | #endif | 321 | #endif |
323 | 322 | ||
324 | fsa->owner = owner; | 323 | fsa->owner = owner; |
325 | fsa->crc = symversion(syms->crcs, symnum); | 324 | fsa->crc = symversion(syms->crcs, symnum); |
326 | fsa->value = syms->start[symnum].value; | 325 | fsa->value = syms->start[symnum].value; |
327 | return true; | 326 | return true; |
328 | } | 327 | } |
329 | 328 | ||
330 | /* Find a symbol, return value, (optional) crc and (optional) module | 329 | /* Find a symbol, return value, (optional) crc and (optional) module |
331 | * which owns it */ | 330 | * which owns it */ |
332 | static unsigned long find_symbol(const char *name, | 331 | static unsigned long find_symbol(const char *name, |
333 | struct module **owner, | 332 | struct module **owner, |
334 | const unsigned long **crc, | 333 | const unsigned long **crc, |
335 | bool gplok, | 334 | bool gplok, |
336 | bool warn) | 335 | bool warn) |
337 | { | 336 | { |
338 | struct find_symbol_arg fsa; | 337 | struct find_symbol_arg fsa; |
339 | 338 | ||
340 | fsa.name = name; | 339 | fsa.name = name; |
341 | fsa.gplok = gplok; | 340 | fsa.gplok = gplok; |
342 | fsa.warn = warn; | 341 | fsa.warn = warn; |
343 | 342 | ||
344 | if (each_symbol(find_symbol_in_section, &fsa)) { | 343 | if (each_symbol(find_symbol_in_section, &fsa)) { |
345 | if (owner) | 344 | if (owner) |
346 | *owner = fsa.owner; | 345 | *owner = fsa.owner; |
347 | if (crc) | 346 | if (crc) |
348 | *crc = fsa.crc; | 347 | *crc = fsa.crc; |
349 | return fsa.value; | 348 | return fsa.value; |
350 | } | 349 | } |
351 | 350 | ||
352 | DEBUGP("Failed to find symbol %s\n", name); | 351 | DEBUGP("Failed to find symbol %s\n", name); |
353 | return -ENOENT; | 352 | return -ENOENT; |
354 | } | 353 | } |
355 | 354 | ||
356 | /* Search for module by name: must hold module_mutex. */ | 355 | /* Search for module by name: must hold module_mutex. */ |
357 | static struct module *find_module(const char *name) | 356 | static struct module *find_module(const char *name) |
358 | { | 357 | { |
359 | struct module *mod; | 358 | struct module *mod; |
360 | 359 | ||
361 | list_for_each_entry(mod, &modules, list) { | 360 | list_for_each_entry(mod, &modules, list) { |
362 | if (strcmp(mod->name, name) == 0) | 361 | if (strcmp(mod->name, name) == 0) |
363 | return mod; | 362 | return mod; |
364 | } | 363 | } |
365 | return NULL; | 364 | return NULL; |
366 | } | 365 | } |
367 | 366 | ||
368 | #ifdef CONFIG_SMP | 367 | #ifdef CONFIG_SMP |
369 | /* Number of blocks used and allocated. */ | 368 | /* Number of blocks used and allocated. */ |
370 | static unsigned int pcpu_num_used, pcpu_num_allocated; | 369 | static unsigned int pcpu_num_used, pcpu_num_allocated; |
371 | /* Size of each block. -ve means used. */ | 370 | /* Size of each block. -ve means used. */ |
372 | static int *pcpu_size; | 371 | static int *pcpu_size; |
373 | 372 | ||
374 | static int split_block(unsigned int i, unsigned short size) | 373 | static int split_block(unsigned int i, unsigned short size) |
375 | { | 374 | { |
376 | /* Reallocation required? */ | 375 | /* Reallocation required? */ |
377 | if (pcpu_num_used + 1 > pcpu_num_allocated) { | 376 | if (pcpu_num_used + 1 > pcpu_num_allocated) { |
378 | int *new; | 377 | int *new; |
379 | 378 | ||
380 | new = krealloc(pcpu_size, sizeof(new[0])*pcpu_num_allocated*2, | 379 | new = krealloc(pcpu_size, sizeof(new[0])*pcpu_num_allocated*2, |
381 | GFP_KERNEL); | 380 | GFP_KERNEL); |
382 | if (!new) | 381 | if (!new) |
383 | return 0; | 382 | return 0; |
384 | 383 | ||
385 | pcpu_num_allocated *= 2; | 384 | pcpu_num_allocated *= 2; |
386 | pcpu_size = new; | 385 | pcpu_size = new; |
387 | } | 386 | } |
388 | 387 | ||
389 | /* Insert a new subblock */ | 388 | /* Insert a new subblock */ |
390 | memmove(&pcpu_size[i+1], &pcpu_size[i], | 389 | memmove(&pcpu_size[i+1], &pcpu_size[i], |
391 | sizeof(pcpu_size[0]) * (pcpu_num_used - i)); | 390 | sizeof(pcpu_size[0]) * (pcpu_num_used - i)); |
392 | pcpu_num_used++; | 391 | pcpu_num_used++; |
393 | 392 | ||
394 | pcpu_size[i+1] -= size; | 393 | pcpu_size[i+1] -= size; |
395 | pcpu_size[i] = size; | 394 | pcpu_size[i] = size; |
396 | return 1; | 395 | return 1; |
397 | } | 396 | } |
398 | 397 | ||
399 | static inline unsigned int block_size(int val) | 398 | static inline unsigned int block_size(int val) |
400 | { | 399 | { |
401 | if (val < 0) | 400 | if (val < 0) |
402 | return -val; | 401 | return -val; |
403 | return val; | 402 | return val; |
404 | } | 403 | } |
405 | 404 | ||
406 | static void *percpu_modalloc(unsigned long size, unsigned long align, | 405 | static void *percpu_modalloc(unsigned long size, unsigned long align, |
407 | const char *name) | 406 | const char *name) |
408 | { | 407 | { |
409 | unsigned long extra; | 408 | unsigned long extra; |
410 | unsigned int i; | 409 | unsigned int i; |
411 | void *ptr; | 410 | void *ptr; |
412 | 411 | ||
413 | if (align > PAGE_SIZE) { | 412 | if (align > PAGE_SIZE) { |
414 | printk(KERN_WARNING "%s: per-cpu alignment %li > %li\n", | 413 | printk(KERN_WARNING "%s: per-cpu alignment %li > %li\n", |
415 | name, align, PAGE_SIZE); | 414 | name, align, PAGE_SIZE); |
416 | align = PAGE_SIZE; | 415 | align = PAGE_SIZE; |
417 | } | 416 | } |
418 | 417 | ||
419 | ptr = __per_cpu_start; | 418 | ptr = __per_cpu_start; |
420 | for (i = 0; i < pcpu_num_used; ptr += block_size(pcpu_size[i]), i++) { | 419 | for (i = 0; i < pcpu_num_used; ptr += block_size(pcpu_size[i]), i++) { |
421 | /* Extra for alignment requirement. */ | 420 | /* Extra for alignment requirement. */ |
422 | extra = ALIGN((unsigned long)ptr, align) - (unsigned long)ptr; | 421 | extra = ALIGN((unsigned long)ptr, align) - (unsigned long)ptr; |
423 | BUG_ON(i == 0 && extra != 0); | 422 | BUG_ON(i == 0 && extra != 0); |
424 | 423 | ||
425 | if (pcpu_size[i] < 0 || pcpu_size[i] < extra + size) | 424 | if (pcpu_size[i] < 0 || pcpu_size[i] < extra + size) |
426 | continue; | 425 | continue; |
427 | 426 | ||
428 | /* Transfer extra to previous block. */ | 427 | /* Transfer extra to previous block. */ |
429 | if (pcpu_size[i-1] < 0) | 428 | if (pcpu_size[i-1] < 0) |
430 | pcpu_size[i-1] -= extra; | 429 | pcpu_size[i-1] -= extra; |
431 | else | 430 | else |
432 | pcpu_size[i-1] += extra; | 431 | pcpu_size[i-1] += extra; |
433 | pcpu_size[i] -= extra; | 432 | pcpu_size[i] -= extra; |
434 | ptr += extra; | 433 | ptr += extra; |
435 | 434 | ||
436 | /* Split block if warranted */ | 435 | /* Split block if warranted */ |
437 | if (pcpu_size[i] - size > sizeof(unsigned long)) | 436 | if (pcpu_size[i] - size > sizeof(unsigned long)) |
438 | if (!split_block(i, size)) | 437 | if (!split_block(i, size)) |
439 | return NULL; | 438 | return NULL; |
440 | 439 | ||
441 | /* Mark allocated */ | 440 | /* Mark allocated */ |
442 | pcpu_size[i] = -pcpu_size[i]; | 441 | pcpu_size[i] = -pcpu_size[i]; |
443 | return ptr; | 442 | return ptr; |
444 | } | 443 | } |
445 | 444 | ||
446 | printk(KERN_WARNING "Could not allocate %lu bytes percpu data\n", | 445 | printk(KERN_WARNING "Could not allocate %lu bytes percpu data\n", |
447 | size); | 446 | size); |
448 | return NULL; | 447 | return NULL; |
449 | } | 448 | } |
450 | 449 | ||
451 | static void percpu_modfree(void *freeme) | 450 | static void percpu_modfree(void *freeme) |
452 | { | 451 | { |
453 | unsigned int i; | 452 | unsigned int i; |
454 | void *ptr = __per_cpu_start + block_size(pcpu_size[0]); | 453 | void *ptr = __per_cpu_start + block_size(pcpu_size[0]); |
455 | 454 | ||
456 | /* First entry is core kernel percpu data. */ | 455 | /* First entry is core kernel percpu data. */ |
457 | for (i = 1; i < pcpu_num_used; ptr += block_size(pcpu_size[i]), i++) { | 456 | for (i = 1; i < pcpu_num_used; ptr += block_size(pcpu_size[i]), i++) { |
458 | if (ptr == freeme) { | 457 | if (ptr == freeme) { |
459 | pcpu_size[i] = -pcpu_size[i]; | 458 | pcpu_size[i] = -pcpu_size[i]; |
460 | goto free; | 459 | goto free; |
461 | } | 460 | } |
462 | } | 461 | } |
463 | BUG(); | 462 | BUG(); |
464 | 463 | ||
465 | free: | 464 | free: |
466 | /* Merge with previous? */ | 465 | /* Merge with previous? */ |
467 | if (pcpu_size[i-1] >= 0) { | 466 | if (pcpu_size[i-1] >= 0) { |
468 | pcpu_size[i-1] += pcpu_size[i]; | 467 | pcpu_size[i-1] += pcpu_size[i]; |
469 | pcpu_num_used--; | 468 | pcpu_num_used--; |
470 | memmove(&pcpu_size[i], &pcpu_size[i+1], | 469 | memmove(&pcpu_size[i], &pcpu_size[i+1], |
471 | (pcpu_num_used - i) * sizeof(pcpu_size[0])); | 470 | (pcpu_num_used - i) * sizeof(pcpu_size[0])); |
472 | i--; | 471 | i--; |
473 | } | 472 | } |
474 | /* Merge with next? */ | 473 | /* Merge with next? */ |
475 | if (i+1 < pcpu_num_used && pcpu_size[i+1] >= 0) { | 474 | if (i+1 < pcpu_num_used && pcpu_size[i+1] >= 0) { |
476 | pcpu_size[i] += pcpu_size[i+1]; | 475 | pcpu_size[i] += pcpu_size[i+1]; |
477 | pcpu_num_used--; | 476 | pcpu_num_used--; |
478 | memmove(&pcpu_size[i+1], &pcpu_size[i+2], | 477 | memmove(&pcpu_size[i+1], &pcpu_size[i+2], |
479 | (pcpu_num_used - (i+1)) * sizeof(pcpu_size[0])); | 478 | (pcpu_num_used - (i+1)) * sizeof(pcpu_size[0])); |
480 | } | 479 | } |
481 | } | 480 | } |
482 | 481 | ||
483 | static unsigned int find_pcpusec(Elf_Ehdr *hdr, | 482 | static unsigned int find_pcpusec(Elf_Ehdr *hdr, |
484 | Elf_Shdr *sechdrs, | 483 | Elf_Shdr *sechdrs, |
485 | const char *secstrings) | 484 | const char *secstrings) |
486 | { | 485 | { |
487 | return find_sec(hdr, sechdrs, secstrings, ".data.percpu"); | 486 | return find_sec(hdr, sechdrs, secstrings, ".data.percpu"); |
488 | } | 487 | } |
489 | 488 | ||
490 | static void percpu_modcopy(void *pcpudest, const void *from, unsigned long size) | 489 | static void percpu_modcopy(void *pcpudest, const void *from, unsigned long size) |
491 | { | 490 | { |
492 | int cpu; | 491 | int cpu; |
493 | 492 | ||
494 | for_each_possible_cpu(cpu) | 493 | for_each_possible_cpu(cpu) |
495 | memcpy(pcpudest + per_cpu_offset(cpu), from, size); | 494 | memcpy(pcpudest + per_cpu_offset(cpu), from, size); |
496 | } | 495 | } |
497 | 496 | ||
498 | static int percpu_modinit(void) | 497 | static int percpu_modinit(void) |
499 | { | 498 | { |
500 | pcpu_num_used = 2; | 499 | pcpu_num_used = 2; |
501 | pcpu_num_allocated = 2; | 500 | pcpu_num_allocated = 2; |
502 | pcpu_size = kmalloc(sizeof(pcpu_size[0]) * pcpu_num_allocated, | 501 | pcpu_size = kmalloc(sizeof(pcpu_size[0]) * pcpu_num_allocated, |
503 | GFP_KERNEL); | 502 | GFP_KERNEL); |
504 | /* Static in-kernel percpu data (used). */ | 503 | /* Static in-kernel percpu data (used). */ |
505 | pcpu_size[0] = -(__per_cpu_end-__per_cpu_start); | 504 | pcpu_size[0] = -(__per_cpu_end-__per_cpu_start); |
506 | /* Free room. */ | 505 | /* Free room. */ |
507 | pcpu_size[1] = PERCPU_ENOUGH_ROOM + pcpu_size[0]; | 506 | pcpu_size[1] = PERCPU_ENOUGH_ROOM + pcpu_size[0]; |
508 | if (pcpu_size[1] < 0) { | 507 | if (pcpu_size[1] < 0) { |
509 | printk(KERN_ERR "No per-cpu room for modules.\n"); | 508 | printk(KERN_ERR "No per-cpu room for modules.\n"); |
510 | pcpu_num_used = 1; | 509 | pcpu_num_used = 1; |
511 | } | 510 | } |
512 | 511 | ||
513 | return 0; | 512 | return 0; |
514 | } | 513 | } |
515 | __initcall(percpu_modinit); | 514 | __initcall(percpu_modinit); |
516 | #else /* ... !CONFIG_SMP */ | 515 | #else /* ... !CONFIG_SMP */ |
517 | static inline void *percpu_modalloc(unsigned long size, unsigned long align, | 516 | static inline void *percpu_modalloc(unsigned long size, unsigned long align, |
518 | const char *name) | 517 | const char *name) |
519 | { | 518 | { |
520 | return NULL; | 519 | return NULL; |
521 | } | 520 | } |
522 | static inline void percpu_modfree(void *pcpuptr) | 521 | static inline void percpu_modfree(void *pcpuptr) |
523 | { | 522 | { |
524 | BUG(); | 523 | BUG(); |
525 | } | 524 | } |
526 | static inline unsigned int find_pcpusec(Elf_Ehdr *hdr, | 525 | static inline unsigned int find_pcpusec(Elf_Ehdr *hdr, |
527 | Elf_Shdr *sechdrs, | 526 | Elf_Shdr *sechdrs, |
528 | const char *secstrings) | 527 | const char *secstrings) |
529 | { | 528 | { |
530 | return 0; | 529 | return 0; |
531 | } | 530 | } |
532 | static inline void percpu_modcopy(void *pcpudst, const void *src, | 531 | static inline void percpu_modcopy(void *pcpudst, const void *src, |
533 | unsigned long size) | 532 | unsigned long size) |
534 | { | 533 | { |
535 | /* pcpusec should be 0, and size of that section should be 0. */ | 534 | /* pcpusec should be 0, and size of that section should be 0. */ |
536 | BUG_ON(size != 0); | 535 | BUG_ON(size != 0); |
537 | } | 536 | } |
538 | #endif /* CONFIG_SMP */ | 537 | #endif /* CONFIG_SMP */ |
539 | 538 | ||
540 | #define MODINFO_ATTR(field) \ | 539 | #define MODINFO_ATTR(field) \ |
541 | static void setup_modinfo_##field(struct module *mod, const char *s) \ | 540 | static void setup_modinfo_##field(struct module *mod, const char *s) \ |
542 | { \ | 541 | { \ |
543 | mod->field = kstrdup(s, GFP_KERNEL); \ | 542 | mod->field = kstrdup(s, GFP_KERNEL); \ |
544 | } \ | 543 | } \ |
545 | static ssize_t show_modinfo_##field(struct module_attribute *mattr, \ | 544 | static ssize_t show_modinfo_##field(struct module_attribute *mattr, \ |
546 | struct module *mod, char *buffer) \ | 545 | struct module *mod, char *buffer) \ |
547 | { \ | 546 | { \ |
548 | return sprintf(buffer, "%s\n", mod->field); \ | 547 | return sprintf(buffer, "%s\n", mod->field); \ |
549 | } \ | 548 | } \ |
550 | static int modinfo_##field##_exists(struct module *mod) \ | 549 | static int modinfo_##field##_exists(struct module *mod) \ |
551 | { \ | 550 | { \ |
552 | return mod->field != NULL; \ | 551 | return mod->field != NULL; \ |
553 | } \ | 552 | } \ |
554 | static void free_modinfo_##field(struct module *mod) \ | 553 | static void free_modinfo_##field(struct module *mod) \ |
555 | { \ | 554 | { \ |
556 | kfree(mod->field); \ | 555 | kfree(mod->field); \ |
557 | mod->field = NULL; \ | 556 | mod->field = NULL; \ |
558 | } \ | 557 | } \ |
559 | static struct module_attribute modinfo_##field = { \ | 558 | static struct module_attribute modinfo_##field = { \ |
560 | .attr = { .name = __stringify(field), .mode = 0444 }, \ | 559 | .attr = { .name = __stringify(field), .mode = 0444 }, \ |
561 | .show = show_modinfo_##field, \ | 560 | .show = show_modinfo_##field, \ |
562 | .setup = setup_modinfo_##field, \ | 561 | .setup = setup_modinfo_##field, \ |
563 | .test = modinfo_##field##_exists, \ | 562 | .test = modinfo_##field##_exists, \ |
564 | .free = free_modinfo_##field, \ | 563 | .free = free_modinfo_##field, \ |
565 | }; | 564 | }; |
566 | 565 | ||
567 | MODINFO_ATTR(version); | 566 | MODINFO_ATTR(version); |
568 | MODINFO_ATTR(srcversion); | 567 | MODINFO_ATTR(srcversion); |
569 | 568 | ||
570 | static char last_unloaded_module[MODULE_NAME_LEN+1]; | 569 | static char last_unloaded_module[MODULE_NAME_LEN+1]; |
571 | 570 | ||
572 | #ifdef CONFIG_MODULE_UNLOAD | 571 | #ifdef CONFIG_MODULE_UNLOAD |
573 | /* Init the unload section of the module. */ | 572 | /* Init the unload section of the module. */ |
574 | static void module_unload_init(struct module *mod) | 573 | static void module_unload_init(struct module *mod) |
575 | { | 574 | { |
576 | unsigned int i; | 575 | unsigned int i; |
577 | 576 | ||
578 | INIT_LIST_HEAD(&mod->modules_which_use_me); | 577 | INIT_LIST_HEAD(&mod->modules_which_use_me); |
579 | for (i = 0; i < NR_CPUS; i++) | 578 | for (i = 0; i < NR_CPUS; i++) |
580 | local_set(&mod->ref[i].count, 0); | 579 | local_set(&mod->ref[i].count, 0); |
581 | /* Hold reference count during initialization. */ | 580 | /* Hold reference count during initialization. */ |
582 | local_set(&mod->ref[raw_smp_processor_id()].count, 1); | 581 | local_set(&mod->ref[raw_smp_processor_id()].count, 1); |
583 | /* Backwards compatibility macros put refcount during init. */ | 582 | /* Backwards compatibility macros put refcount during init. */ |
584 | mod->waiter = current; | 583 | mod->waiter = current; |
585 | } | 584 | } |
586 | 585 | ||
587 | /* modules using other modules */ | 586 | /* modules using other modules */ |
588 | struct module_use | 587 | struct module_use |
589 | { | 588 | { |
590 | struct list_head list; | 589 | struct list_head list; |
591 | struct module *module_which_uses; | 590 | struct module *module_which_uses; |
592 | }; | 591 | }; |
593 | 592 | ||
594 | /* Does a already use b? */ | 593 | /* Does a already use b? */ |
595 | static int already_uses(struct module *a, struct module *b) | 594 | static int already_uses(struct module *a, struct module *b) |
596 | { | 595 | { |
597 | struct module_use *use; | 596 | struct module_use *use; |
598 | 597 | ||
599 | list_for_each_entry(use, &b->modules_which_use_me, list) { | 598 | list_for_each_entry(use, &b->modules_which_use_me, list) { |
600 | if (use->module_which_uses == a) { | 599 | if (use->module_which_uses == a) { |
601 | DEBUGP("%s uses %s!\n", a->name, b->name); | 600 | DEBUGP("%s uses %s!\n", a->name, b->name); |
602 | return 1; | 601 | return 1; |
603 | } | 602 | } |
604 | } | 603 | } |
605 | DEBUGP("%s does not use %s!\n", a->name, b->name); | 604 | DEBUGP("%s does not use %s!\n", a->name, b->name); |
606 | return 0; | 605 | return 0; |
607 | } | 606 | } |
608 | 607 | ||
609 | /* Module a uses b */ | 608 | /* Module a uses b */ |
610 | static int use_module(struct module *a, struct module *b) | 609 | static int use_module(struct module *a, struct module *b) |
611 | { | 610 | { |
612 | struct module_use *use; | 611 | struct module_use *use; |
613 | int no_warn, err; | 612 | int no_warn, err; |
614 | 613 | ||
615 | if (b == NULL || already_uses(a, b)) return 1; | 614 | if (b == NULL || already_uses(a, b)) return 1; |
616 | 615 | ||
617 | /* If we're interrupted or time out, we fail. */ | 616 | /* If we're interrupted or time out, we fail. */ |
618 | if (wait_event_interruptible_timeout( | 617 | if (wait_event_interruptible_timeout( |
619 | module_wq, (err = strong_try_module_get(b)) != -EBUSY, | 618 | module_wq, (err = strong_try_module_get(b)) != -EBUSY, |
620 | 30 * HZ) <= 0) { | 619 | 30 * HZ) <= 0) { |
621 | printk("%s: gave up waiting for init of module %s.\n", | 620 | printk("%s: gave up waiting for init of module %s.\n", |
622 | a->name, b->name); | 621 | a->name, b->name); |
623 | return 0; | 622 | return 0; |
624 | } | 623 | } |
625 | 624 | ||
626 | /* If strong_try_module_get() returned a different error, we fail. */ | 625 | /* If strong_try_module_get() returned a different error, we fail. */ |
627 | if (err) | 626 | if (err) |
628 | return 0; | 627 | return 0; |
629 | 628 | ||
630 | DEBUGP("Allocating new usage for %s.\n", a->name); | 629 | DEBUGP("Allocating new usage for %s.\n", a->name); |
631 | use = kmalloc(sizeof(*use), GFP_ATOMIC); | 630 | use = kmalloc(sizeof(*use), GFP_ATOMIC); |
632 | if (!use) { | 631 | if (!use) { |
633 | printk("%s: out of memory loading\n", a->name); | 632 | printk("%s: out of memory loading\n", a->name); |
634 | module_put(b); | 633 | module_put(b); |
635 | return 0; | 634 | return 0; |
636 | } | 635 | } |
637 | 636 | ||
638 | use->module_which_uses = a; | 637 | use->module_which_uses = a; |
639 | list_add(&use->list, &b->modules_which_use_me); | 638 | list_add(&use->list, &b->modules_which_use_me); |
640 | no_warn = sysfs_create_link(b->holders_dir, &a->mkobj.kobj, a->name); | 639 | no_warn = sysfs_create_link(b->holders_dir, &a->mkobj.kobj, a->name); |
641 | return 1; | 640 | return 1; |
642 | } | 641 | } |
643 | 642 | ||
644 | /* Clear the unload stuff of the module. */ | 643 | /* Clear the unload stuff of the module. */ |
645 | static void module_unload_free(struct module *mod) | 644 | static void module_unload_free(struct module *mod) |
646 | { | 645 | { |
647 | struct module *i; | 646 | struct module *i; |
648 | 647 | ||
649 | list_for_each_entry(i, &modules, list) { | 648 | list_for_each_entry(i, &modules, list) { |
650 | struct module_use *use; | 649 | struct module_use *use; |
651 | 650 | ||
652 | list_for_each_entry(use, &i->modules_which_use_me, list) { | 651 | list_for_each_entry(use, &i->modules_which_use_me, list) { |
653 | if (use->module_which_uses == mod) { | 652 | if (use->module_which_uses == mod) { |
654 | DEBUGP("%s unusing %s\n", mod->name, i->name); | 653 | DEBUGP("%s unusing %s\n", mod->name, i->name); |
655 | module_put(i); | 654 | module_put(i); |
656 | list_del(&use->list); | 655 | list_del(&use->list); |
657 | kfree(use); | 656 | kfree(use); |
658 | sysfs_remove_link(i->holders_dir, mod->name); | 657 | sysfs_remove_link(i->holders_dir, mod->name); |
659 | /* There can be at most one match. */ | 658 | /* There can be at most one match. */ |
660 | break; | 659 | break; |
661 | } | 660 | } |
662 | } | 661 | } |
663 | } | 662 | } |
664 | } | 663 | } |
665 | 664 | ||
666 | #ifdef CONFIG_MODULE_FORCE_UNLOAD | 665 | #ifdef CONFIG_MODULE_FORCE_UNLOAD |
667 | static inline int try_force_unload(unsigned int flags) | 666 | static inline int try_force_unload(unsigned int flags) |
668 | { | 667 | { |
669 | int ret = (flags & O_TRUNC); | 668 | int ret = (flags & O_TRUNC); |
670 | if (ret) | 669 | if (ret) |
671 | add_taint(TAINT_FORCED_RMMOD); | 670 | add_taint(TAINT_FORCED_RMMOD); |
672 | return ret; | 671 | return ret; |
673 | } | 672 | } |
674 | #else | 673 | #else |
675 | static inline int try_force_unload(unsigned int flags) | 674 | static inline int try_force_unload(unsigned int flags) |
676 | { | 675 | { |
677 | return 0; | 676 | return 0; |
678 | } | 677 | } |
679 | #endif /* CONFIG_MODULE_FORCE_UNLOAD */ | 678 | #endif /* CONFIG_MODULE_FORCE_UNLOAD */ |
680 | 679 | ||
681 | struct stopref | 680 | struct stopref |
682 | { | 681 | { |
683 | struct module *mod; | 682 | struct module *mod; |
684 | int flags; | 683 | int flags; |
685 | int *forced; | 684 | int *forced; |
686 | }; | 685 | }; |
687 | 686 | ||
688 | /* Whole machine is stopped with interrupts off when this runs. */ | 687 | /* Whole machine is stopped with interrupts off when this runs. */ |
689 | static int __try_stop_module(void *_sref) | 688 | static int __try_stop_module(void *_sref) |
690 | { | 689 | { |
691 | struct stopref *sref = _sref; | 690 | struct stopref *sref = _sref; |
692 | 691 | ||
693 | /* If it's not unused, quit unless we're forcing. */ | 692 | /* If it's not unused, quit unless we're forcing. */ |
694 | if (module_refcount(sref->mod) != 0) { | 693 | if (module_refcount(sref->mod) != 0) { |
695 | if (!(*sref->forced = try_force_unload(sref->flags))) | 694 | if (!(*sref->forced = try_force_unload(sref->flags))) |
696 | return -EWOULDBLOCK; | 695 | return -EWOULDBLOCK; |
697 | } | 696 | } |
698 | 697 | ||
699 | /* Mark it as dying. */ | 698 | /* Mark it as dying. */ |
700 | sref->mod->state = MODULE_STATE_GOING; | 699 | sref->mod->state = MODULE_STATE_GOING; |
701 | return 0; | 700 | return 0; |
702 | } | 701 | } |
703 | 702 | ||
704 | static int try_stop_module(struct module *mod, int flags, int *forced) | 703 | static int try_stop_module(struct module *mod, int flags, int *forced) |
705 | { | 704 | { |
706 | if (flags & O_NONBLOCK) { | 705 | if (flags & O_NONBLOCK) { |
707 | struct stopref sref = { mod, flags, forced }; | 706 | struct stopref sref = { mod, flags, forced }; |
708 | 707 | ||
709 | return stop_machine(__try_stop_module, &sref, NULL); | 708 | return stop_machine(__try_stop_module, &sref, NULL); |
710 | } else { | 709 | } else { |
711 | /* We don't need to stop the machine for this. */ | 710 | /* We don't need to stop the machine for this. */ |
712 | mod->state = MODULE_STATE_GOING; | 711 | mod->state = MODULE_STATE_GOING; |
713 | synchronize_sched(); | 712 | synchronize_sched(); |
714 | return 0; | 713 | return 0; |
715 | } | 714 | } |
716 | } | 715 | } |
717 | 716 | ||
718 | unsigned int module_refcount(struct module *mod) | 717 | unsigned int module_refcount(struct module *mod) |
719 | { | 718 | { |
720 | unsigned int i, total = 0; | 719 | unsigned int i, total = 0; |
721 | 720 | ||
722 | for (i = 0; i < NR_CPUS; i++) | 721 | for (i = 0; i < NR_CPUS; i++) |
723 | total += local_read(&mod->ref[i].count); | 722 | total += local_read(&mod->ref[i].count); |
724 | return total; | 723 | return total; |
725 | } | 724 | } |
726 | EXPORT_SYMBOL(module_refcount); | 725 | EXPORT_SYMBOL(module_refcount); |
727 | 726 | ||
728 | /* This exists whether we can unload or not */ | 727 | /* This exists whether we can unload or not */ |
729 | static void free_module(struct module *mod); | 728 | static void free_module(struct module *mod); |
730 | 729 | ||
731 | static void wait_for_zero_refcount(struct module *mod) | 730 | static void wait_for_zero_refcount(struct module *mod) |
732 | { | 731 | { |
733 | /* Since we might sleep for some time, release the mutex first */ | 732 | /* Since we might sleep for some time, release the mutex first */ |
734 | mutex_unlock(&module_mutex); | 733 | mutex_unlock(&module_mutex); |
735 | for (;;) { | 734 | for (;;) { |
736 | DEBUGP("Looking at refcount...\n"); | 735 | DEBUGP("Looking at refcount...\n"); |
737 | set_current_state(TASK_UNINTERRUPTIBLE); | 736 | set_current_state(TASK_UNINTERRUPTIBLE); |
738 | if (module_refcount(mod) == 0) | 737 | if (module_refcount(mod) == 0) |
739 | break; | 738 | break; |
740 | schedule(); | 739 | schedule(); |
741 | } | 740 | } |
742 | current->state = TASK_RUNNING; | 741 | current->state = TASK_RUNNING; |
743 | mutex_lock(&module_mutex); | 742 | mutex_lock(&module_mutex); |
744 | } | 743 | } |
745 | 744 | ||
746 | asmlinkage long | 745 | asmlinkage long |
747 | sys_delete_module(const char __user *name_user, unsigned int flags) | 746 | sys_delete_module(const char __user *name_user, unsigned int flags) |
748 | { | 747 | { |
749 | struct module *mod; | 748 | struct module *mod; |
750 | char name[MODULE_NAME_LEN]; | 749 | char name[MODULE_NAME_LEN]; |
751 | int ret, forced = 0; | 750 | int ret, forced = 0; |
752 | 751 | ||
753 | if (!capable(CAP_SYS_MODULE)) | 752 | if (!capable(CAP_SYS_MODULE)) |
754 | return -EPERM; | 753 | return -EPERM; |
755 | 754 | ||
756 | if (strncpy_from_user(name, name_user, MODULE_NAME_LEN-1) < 0) | 755 | if (strncpy_from_user(name, name_user, MODULE_NAME_LEN-1) < 0) |
757 | return -EFAULT; | 756 | return -EFAULT; |
758 | name[MODULE_NAME_LEN-1] = '\0'; | 757 | name[MODULE_NAME_LEN-1] = '\0'; |
759 | 758 | ||
760 | /* Create stop_machine threads since free_module relies on | 759 | /* Create stop_machine threads since free_module relies on |
761 | * a non-failing stop_machine call. */ | 760 | * a non-failing stop_machine call. */ |
762 | ret = stop_machine_create(); | 761 | ret = stop_machine_create(); |
763 | if (ret) | 762 | if (ret) |
764 | return ret; | 763 | return ret; |
765 | 764 | ||
766 | if (mutex_lock_interruptible(&module_mutex) != 0) { | 765 | if (mutex_lock_interruptible(&module_mutex) != 0) { |
767 | ret = -EINTR; | 766 | ret = -EINTR; |
768 | goto out_stop; | 767 | goto out_stop; |
769 | } | 768 | } |
770 | 769 | ||
771 | mod = find_module(name); | 770 | mod = find_module(name); |
772 | if (!mod) { | 771 | if (!mod) { |
773 | ret = -ENOENT; | 772 | ret = -ENOENT; |
774 | goto out; | 773 | goto out; |
775 | } | 774 | } |
776 | 775 | ||
777 | if (!list_empty(&mod->modules_which_use_me)) { | 776 | if (!list_empty(&mod->modules_which_use_me)) { |
778 | /* Other modules depend on us: get rid of them first. */ | 777 | /* Other modules depend on us: get rid of them first. */ |
779 | ret = -EWOULDBLOCK; | 778 | ret = -EWOULDBLOCK; |
780 | goto out; | 779 | goto out; |
781 | } | 780 | } |
782 | 781 | ||
783 | /* Doing init or already dying? */ | 782 | /* Doing init or already dying? */ |
784 | if (mod->state != MODULE_STATE_LIVE) { | 783 | if (mod->state != MODULE_STATE_LIVE) { |
785 | /* FIXME: if (force), slam module count and wake up | 784 | /* FIXME: if (force), slam module count and wake up |
786 | waiter --RR */ | 785 | waiter --RR */ |
787 | DEBUGP("%s already dying\n", mod->name); | 786 | DEBUGP("%s already dying\n", mod->name); |
788 | ret = -EBUSY; | 787 | ret = -EBUSY; |
789 | goto out; | 788 | goto out; |
790 | } | 789 | } |
791 | 790 | ||
792 | /* If it has an init func, it must have an exit func to unload */ | 791 | /* If it has an init func, it must have an exit func to unload */ |
793 | if (mod->init && !mod->exit) { | 792 | if (mod->init && !mod->exit) { |
794 | forced = try_force_unload(flags); | 793 | forced = try_force_unload(flags); |
795 | if (!forced) { | 794 | if (!forced) { |
796 | /* This module can't be removed */ | 795 | /* This module can't be removed */ |
797 | ret = -EBUSY; | 796 | ret = -EBUSY; |
798 | goto out; | 797 | goto out; |
799 | } | 798 | } |
800 | } | 799 | } |
801 | 800 | ||
802 | /* Set this up before setting mod->state */ | 801 | /* Set this up before setting mod->state */ |
803 | mod->waiter = current; | 802 | mod->waiter = current; |
804 | 803 | ||
805 | /* Stop the machine so refcounts can't move and disable module. */ | 804 | /* Stop the machine so refcounts can't move and disable module. */ |
806 | ret = try_stop_module(mod, flags, &forced); | 805 | ret = try_stop_module(mod, flags, &forced); |
807 | if (ret != 0) | 806 | if (ret != 0) |
808 | goto out; | 807 | goto out; |
809 | 808 | ||
810 | /* Never wait if forced. */ | 809 | /* Never wait if forced. */ |
811 | if (!forced && module_refcount(mod) != 0) | 810 | if (!forced && module_refcount(mod) != 0) |
812 | wait_for_zero_refcount(mod); | 811 | wait_for_zero_refcount(mod); |
813 | 812 | ||
814 | mutex_unlock(&module_mutex); | 813 | mutex_unlock(&module_mutex); |
815 | /* Final destruction now noone is using it. */ | 814 | /* Final destruction now noone is using it. */ |
816 | if (mod->exit != NULL) | 815 | if (mod->exit != NULL) |
817 | mod->exit(); | 816 | mod->exit(); |
818 | blocking_notifier_call_chain(&module_notify_list, | 817 | blocking_notifier_call_chain(&module_notify_list, |
819 | MODULE_STATE_GOING, mod); | 818 | MODULE_STATE_GOING, mod); |
820 | mutex_lock(&module_mutex); | 819 | mutex_lock(&module_mutex); |
821 | /* Store the name of the last unloaded module for diagnostic purposes */ | 820 | /* Store the name of the last unloaded module for diagnostic purposes */ |
822 | strlcpy(last_unloaded_module, mod->name, sizeof(last_unloaded_module)); | 821 | strlcpy(last_unloaded_module, mod->name, sizeof(last_unloaded_module)); |
823 | unregister_dynamic_debug_module(mod->name); | 822 | unregister_dynamic_debug_module(mod->name); |
824 | free_module(mod); | 823 | free_module(mod); |
825 | 824 | ||
826 | out: | 825 | out: |
827 | mutex_unlock(&module_mutex); | 826 | mutex_unlock(&module_mutex); |
828 | out_stop: | 827 | out_stop: |
829 | stop_machine_destroy(); | 828 | stop_machine_destroy(); |
830 | return ret; | 829 | return ret; |
831 | } | 830 | } |
832 | 831 | ||
833 | static inline void print_unload_info(struct seq_file *m, struct module *mod) | 832 | static inline void print_unload_info(struct seq_file *m, struct module *mod) |
834 | { | 833 | { |
835 | struct module_use *use; | 834 | struct module_use *use; |
836 | int printed_something = 0; | 835 | int printed_something = 0; |
837 | 836 | ||
838 | seq_printf(m, " %u ", module_refcount(mod)); | 837 | seq_printf(m, " %u ", module_refcount(mod)); |
839 | 838 | ||
840 | /* Always include a trailing , so userspace can differentiate | 839 | /* Always include a trailing , so userspace can differentiate |
841 | between this and the old multi-field proc format. */ | 840 | between this and the old multi-field proc format. */ |
842 | list_for_each_entry(use, &mod->modules_which_use_me, list) { | 841 | list_for_each_entry(use, &mod->modules_which_use_me, list) { |
843 | printed_something = 1; | 842 | printed_something = 1; |
844 | seq_printf(m, "%s,", use->module_which_uses->name); | 843 | seq_printf(m, "%s,", use->module_which_uses->name); |
845 | } | 844 | } |
846 | 845 | ||
847 | if (mod->init != NULL && mod->exit == NULL) { | 846 | if (mod->init != NULL && mod->exit == NULL) { |
848 | printed_something = 1; | 847 | printed_something = 1; |
849 | seq_printf(m, "[permanent],"); | 848 | seq_printf(m, "[permanent],"); |
850 | } | 849 | } |
851 | 850 | ||
852 | if (!printed_something) | 851 | if (!printed_something) |
853 | seq_printf(m, "-"); | 852 | seq_printf(m, "-"); |
854 | } | 853 | } |
855 | 854 | ||
856 | void __symbol_put(const char *symbol) | 855 | void __symbol_put(const char *symbol) |
857 | { | 856 | { |
858 | struct module *owner; | 857 | struct module *owner; |
859 | 858 | ||
860 | preempt_disable(); | 859 | preempt_disable(); |
861 | if (IS_ERR_VALUE(find_symbol(symbol, &owner, NULL, true, false))) | 860 | if (IS_ERR_VALUE(find_symbol(symbol, &owner, NULL, true, false))) |
862 | BUG(); | 861 | BUG(); |
863 | module_put(owner); | 862 | module_put(owner); |
864 | preempt_enable(); | 863 | preempt_enable(); |
865 | } | 864 | } |
866 | EXPORT_SYMBOL(__symbol_put); | 865 | EXPORT_SYMBOL(__symbol_put); |
867 | 866 | ||
868 | void symbol_put_addr(void *addr) | 867 | void symbol_put_addr(void *addr) |
869 | { | 868 | { |
870 | struct module *modaddr; | 869 | struct module *modaddr; |
871 | 870 | ||
872 | if (core_kernel_text((unsigned long)addr)) | 871 | if (core_kernel_text((unsigned long)addr)) |
873 | return; | 872 | return; |
874 | 873 | ||
875 | if (!(modaddr = module_text_address((unsigned long)addr))) | 874 | if (!(modaddr = module_text_address((unsigned long)addr))) |
876 | BUG(); | 875 | BUG(); |
877 | module_put(modaddr); | 876 | module_put(modaddr); |
878 | } | 877 | } |
879 | EXPORT_SYMBOL_GPL(symbol_put_addr); | 878 | EXPORT_SYMBOL_GPL(symbol_put_addr); |
880 | 879 | ||
881 | static ssize_t show_refcnt(struct module_attribute *mattr, | 880 | static ssize_t show_refcnt(struct module_attribute *mattr, |
882 | struct module *mod, char *buffer) | 881 | struct module *mod, char *buffer) |
883 | { | 882 | { |
884 | return sprintf(buffer, "%u\n", module_refcount(mod)); | 883 | return sprintf(buffer, "%u\n", module_refcount(mod)); |
885 | } | 884 | } |
886 | 885 | ||
887 | static struct module_attribute refcnt = { | 886 | static struct module_attribute refcnt = { |
888 | .attr = { .name = "refcnt", .mode = 0444 }, | 887 | .attr = { .name = "refcnt", .mode = 0444 }, |
889 | .show = show_refcnt, | 888 | .show = show_refcnt, |
890 | }; | 889 | }; |
891 | 890 | ||
892 | void module_put(struct module *module) | 891 | void module_put(struct module *module) |
893 | { | 892 | { |
894 | if (module) { | 893 | if (module) { |
895 | unsigned int cpu = get_cpu(); | 894 | unsigned int cpu = get_cpu(); |
896 | local_dec(&module->ref[cpu].count); | 895 | local_dec(&module->ref[cpu].count); |
897 | /* Maybe they're waiting for us to drop reference? */ | 896 | /* Maybe they're waiting for us to drop reference? */ |
898 | if (unlikely(!module_is_live(module))) | 897 | if (unlikely(!module_is_live(module))) |
899 | wake_up_process(module->waiter); | 898 | wake_up_process(module->waiter); |
900 | put_cpu(); | 899 | put_cpu(); |
901 | } | 900 | } |
902 | } | 901 | } |
903 | EXPORT_SYMBOL(module_put); | 902 | EXPORT_SYMBOL(module_put); |
904 | 903 | ||
905 | #else /* !CONFIG_MODULE_UNLOAD */ | 904 | #else /* !CONFIG_MODULE_UNLOAD */ |
906 | static inline void print_unload_info(struct seq_file *m, struct module *mod) | 905 | static inline void print_unload_info(struct seq_file *m, struct module *mod) |
907 | { | 906 | { |
908 | /* We don't know the usage count, or what modules are using. */ | 907 | /* We don't know the usage count, or what modules are using. */ |
909 | seq_printf(m, " - -"); | 908 | seq_printf(m, " - -"); |
910 | } | 909 | } |
911 | 910 | ||
912 | static inline void module_unload_free(struct module *mod) | 911 | static inline void module_unload_free(struct module *mod) |
913 | { | 912 | { |
914 | } | 913 | } |
915 | 914 | ||
916 | static inline int use_module(struct module *a, struct module *b) | 915 | static inline int use_module(struct module *a, struct module *b) |
917 | { | 916 | { |
918 | return strong_try_module_get(b) == 0; | 917 | return strong_try_module_get(b) == 0; |
919 | } | 918 | } |
920 | 919 | ||
921 | static inline void module_unload_init(struct module *mod) | 920 | static inline void module_unload_init(struct module *mod) |
922 | { | 921 | { |
923 | } | 922 | } |
924 | #endif /* CONFIG_MODULE_UNLOAD */ | 923 | #endif /* CONFIG_MODULE_UNLOAD */ |
925 | 924 | ||
926 | static ssize_t show_initstate(struct module_attribute *mattr, | 925 | static ssize_t show_initstate(struct module_attribute *mattr, |
927 | struct module *mod, char *buffer) | 926 | struct module *mod, char *buffer) |
928 | { | 927 | { |
929 | const char *state = "unknown"; | 928 | const char *state = "unknown"; |
930 | 929 | ||
931 | switch (mod->state) { | 930 | switch (mod->state) { |
932 | case MODULE_STATE_LIVE: | 931 | case MODULE_STATE_LIVE: |
933 | state = "live"; | 932 | state = "live"; |
934 | break; | 933 | break; |
935 | case MODULE_STATE_COMING: | 934 | case MODULE_STATE_COMING: |
936 | state = "coming"; | 935 | state = "coming"; |
937 | break; | 936 | break; |
938 | case MODULE_STATE_GOING: | 937 | case MODULE_STATE_GOING: |
939 | state = "going"; | 938 | state = "going"; |
940 | break; | 939 | break; |
941 | } | 940 | } |
942 | return sprintf(buffer, "%s\n", state); | 941 | return sprintf(buffer, "%s\n", state); |
943 | } | 942 | } |
944 | 943 | ||
945 | static struct module_attribute initstate = { | 944 | static struct module_attribute initstate = { |
946 | .attr = { .name = "initstate", .mode = 0444 }, | 945 | .attr = { .name = "initstate", .mode = 0444 }, |
947 | .show = show_initstate, | 946 | .show = show_initstate, |
948 | }; | 947 | }; |
949 | 948 | ||
950 | static struct module_attribute *modinfo_attrs[] = { | 949 | static struct module_attribute *modinfo_attrs[] = { |
951 | &modinfo_version, | 950 | &modinfo_version, |
952 | &modinfo_srcversion, | 951 | &modinfo_srcversion, |
953 | &initstate, | 952 | &initstate, |
954 | #ifdef CONFIG_MODULE_UNLOAD | 953 | #ifdef CONFIG_MODULE_UNLOAD |
955 | &refcnt, | 954 | &refcnt, |
956 | #endif | 955 | #endif |
957 | NULL, | 956 | NULL, |
958 | }; | 957 | }; |
959 | 958 | ||
960 | static const char vermagic[] = VERMAGIC_STRING; | 959 | static const char vermagic[] = VERMAGIC_STRING; |
961 | 960 | ||
962 | static int try_to_force_load(struct module *mod, const char *symname) | 961 | static int try_to_force_load(struct module *mod, const char *symname) |
963 | { | 962 | { |
964 | #ifdef CONFIG_MODULE_FORCE_LOAD | 963 | #ifdef CONFIG_MODULE_FORCE_LOAD |
965 | if (!test_taint(TAINT_FORCED_MODULE)) | 964 | if (!test_taint(TAINT_FORCED_MODULE)) |
966 | printk("%s: no version for \"%s\" found: kernel tainted.\n", | 965 | printk("%s: no version for \"%s\" found: kernel tainted.\n", |
967 | mod->name, symname); | 966 | mod->name, symname); |
968 | add_taint_module(mod, TAINT_FORCED_MODULE); | 967 | add_taint_module(mod, TAINT_FORCED_MODULE); |
969 | return 0; | 968 | return 0; |
970 | #else | 969 | #else |
971 | return -ENOEXEC; | 970 | return -ENOEXEC; |
972 | #endif | 971 | #endif |
973 | } | 972 | } |
974 | 973 | ||
975 | #ifdef CONFIG_MODVERSIONS | 974 | #ifdef CONFIG_MODVERSIONS |
976 | static int check_version(Elf_Shdr *sechdrs, | 975 | static int check_version(Elf_Shdr *sechdrs, |
977 | unsigned int versindex, | 976 | unsigned int versindex, |
978 | const char *symname, | 977 | const char *symname, |
979 | struct module *mod, | 978 | struct module *mod, |
980 | const unsigned long *crc) | 979 | const unsigned long *crc) |
981 | { | 980 | { |
982 | unsigned int i, num_versions; | 981 | unsigned int i, num_versions; |
983 | struct modversion_info *versions; | 982 | struct modversion_info *versions; |
984 | 983 | ||
985 | /* Exporting module didn't supply crcs? OK, we're already tainted. */ | 984 | /* Exporting module didn't supply crcs? OK, we're already tainted. */ |
986 | if (!crc) | 985 | if (!crc) |
987 | return 1; | 986 | return 1; |
988 | 987 | ||
989 | /* No versions at all? modprobe --force does this. */ | 988 | /* No versions at all? modprobe --force does this. */ |
990 | if (versindex == 0) | 989 | if (versindex == 0) |
991 | return try_to_force_load(mod, symname) == 0; | 990 | return try_to_force_load(mod, symname) == 0; |
992 | 991 | ||
993 | versions = (void *) sechdrs[versindex].sh_addr; | 992 | versions = (void *) sechdrs[versindex].sh_addr; |
994 | num_versions = sechdrs[versindex].sh_size | 993 | num_versions = sechdrs[versindex].sh_size |
995 | / sizeof(struct modversion_info); | 994 | / sizeof(struct modversion_info); |
996 | 995 | ||
997 | for (i = 0; i < num_versions; i++) { | 996 | for (i = 0; i < num_versions; i++) { |
998 | if (strcmp(versions[i].name, symname) != 0) | 997 | if (strcmp(versions[i].name, symname) != 0) |
999 | continue; | 998 | continue; |
1000 | 999 | ||
1001 | if (versions[i].crc == *crc) | 1000 | if (versions[i].crc == *crc) |
1002 | return 1; | 1001 | return 1; |
1003 | DEBUGP("Found checksum %lX vs module %lX\n", | 1002 | DEBUGP("Found checksum %lX vs module %lX\n", |
1004 | *crc, versions[i].crc); | 1003 | *crc, versions[i].crc); |
1005 | goto bad_version; | 1004 | goto bad_version; |
1006 | } | 1005 | } |
1007 | 1006 | ||
1008 | printk(KERN_WARNING "%s: no symbol version for %s\n", | 1007 | printk(KERN_WARNING "%s: no symbol version for %s\n", |
1009 | mod->name, symname); | 1008 | mod->name, symname); |
1010 | return 0; | 1009 | return 0; |
1011 | 1010 | ||
1012 | bad_version: | 1011 | bad_version: |
1013 | printk("%s: disagrees about version of symbol %s\n", | 1012 | printk("%s: disagrees about version of symbol %s\n", |
1014 | mod->name, symname); | 1013 | mod->name, symname); |
1015 | return 0; | 1014 | return 0; |
1016 | } | 1015 | } |
1017 | 1016 | ||
1018 | static inline int check_modstruct_version(Elf_Shdr *sechdrs, | 1017 | static inline int check_modstruct_version(Elf_Shdr *sechdrs, |
1019 | unsigned int versindex, | 1018 | unsigned int versindex, |
1020 | struct module *mod) | 1019 | struct module *mod) |
1021 | { | 1020 | { |
1022 | const unsigned long *crc; | 1021 | const unsigned long *crc; |
1023 | 1022 | ||
1024 | if (IS_ERR_VALUE(find_symbol("struct_module", NULL, &crc, true, false))) | 1023 | if (IS_ERR_VALUE(find_symbol("struct_module", NULL, &crc, true, false))) |
1025 | BUG(); | 1024 | BUG(); |
1026 | return check_version(sechdrs, versindex, "struct_module", mod, crc); | 1025 | return check_version(sechdrs, versindex, "struct_module", mod, crc); |
1027 | } | 1026 | } |
1028 | 1027 | ||
1029 | /* First part is kernel version, which we ignore if module has crcs. */ | 1028 | /* First part is kernel version, which we ignore if module has crcs. */ |
1030 | static inline int same_magic(const char *amagic, const char *bmagic, | 1029 | static inline int same_magic(const char *amagic, const char *bmagic, |
1031 | bool has_crcs) | 1030 | bool has_crcs) |
1032 | { | 1031 | { |
1033 | if (has_crcs) { | 1032 | if (has_crcs) { |
1034 | amagic += strcspn(amagic, " "); | 1033 | amagic += strcspn(amagic, " "); |
1035 | bmagic += strcspn(bmagic, " "); | 1034 | bmagic += strcspn(bmagic, " "); |
1036 | } | 1035 | } |
1037 | return strcmp(amagic, bmagic) == 0; | 1036 | return strcmp(amagic, bmagic) == 0; |
1038 | } | 1037 | } |
1039 | #else | 1038 | #else |
1040 | static inline int check_version(Elf_Shdr *sechdrs, | 1039 | static inline int check_version(Elf_Shdr *sechdrs, |
1041 | unsigned int versindex, | 1040 | unsigned int versindex, |
1042 | const char *symname, | 1041 | const char *symname, |
1043 | struct module *mod, | 1042 | struct module *mod, |
1044 | const unsigned long *crc) | 1043 | const unsigned long *crc) |
1045 | { | 1044 | { |
1046 | return 1; | 1045 | return 1; |
1047 | } | 1046 | } |
1048 | 1047 | ||
1049 | static inline int check_modstruct_version(Elf_Shdr *sechdrs, | 1048 | static inline int check_modstruct_version(Elf_Shdr *sechdrs, |
1050 | unsigned int versindex, | 1049 | unsigned int versindex, |
1051 | struct module *mod) | 1050 | struct module *mod) |
1052 | { | 1051 | { |
1053 | return 1; | 1052 | return 1; |
1054 | } | 1053 | } |
1055 | 1054 | ||
1056 | static inline int same_magic(const char *amagic, const char *bmagic, | 1055 | static inline int same_magic(const char *amagic, const char *bmagic, |
1057 | bool has_crcs) | 1056 | bool has_crcs) |
1058 | { | 1057 | { |
1059 | return strcmp(amagic, bmagic) == 0; | 1058 | return strcmp(amagic, bmagic) == 0; |
1060 | } | 1059 | } |
1061 | #endif /* CONFIG_MODVERSIONS */ | 1060 | #endif /* CONFIG_MODVERSIONS */ |
1062 | 1061 | ||
1063 | /* Resolve a symbol for this module. I.e. if we find one, record usage. | 1062 | /* Resolve a symbol for this module. I.e. if we find one, record usage. |
1064 | Must be holding module_mutex. */ | 1063 | Must be holding module_mutex. */ |
1065 | static unsigned long resolve_symbol(Elf_Shdr *sechdrs, | 1064 | static unsigned long resolve_symbol(Elf_Shdr *sechdrs, |
1066 | unsigned int versindex, | 1065 | unsigned int versindex, |
1067 | const char *name, | 1066 | const char *name, |
1068 | struct module *mod) | 1067 | struct module *mod) |
1069 | { | 1068 | { |
1070 | struct module *owner; | 1069 | struct module *owner; |
1071 | unsigned long ret; | 1070 | unsigned long ret; |
1072 | const unsigned long *crc; | 1071 | const unsigned long *crc; |
1073 | 1072 | ||
1074 | ret = find_symbol(name, &owner, &crc, | 1073 | ret = find_symbol(name, &owner, &crc, |
1075 | !(mod->taints & (1 << TAINT_PROPRIETARY_MODULE)), true); | 1074 | !(mod->taints & (1 << TAINT_PROPRIETARY_MODULE)), true); |
1076 | if (!IS_ERR_VALUE(ret)) { | 1075 | if (!IS_ERR_VALUE(ret)) { |
1077 | /* use_module can fail due to OOM, | 1076 | /* use_module can fail due to OOM, |
1078 | or module initialization or unloading */ | 1077 | or module initialization or unloading */ |
1079 | if (!check_version(sechdrs, versindex, name, mod, crc) || | 1078 | if (!check_version(sechdrs, versindex, name, mod, crc) || |
1080 | !use_module(mod, owner)) | 1079 | !use_module(mod, owner)) |
1081 | ret = -EINVAL; | 1080 | ret = -EINVAL; |
1082 | } | 1081 | } |
1083 | return ret; | 1082 | return ret; |
1084 | } | 1083 | } |
1085 | 1084 | ||
1086 | /* | 1085 | /* |
1087 | * /sys/module/foo/sections stuff | 1086 | * /sys/module/foo/sections stuff |
1088 | * J. Corbet <corbet@lwn.net> | 1087 | * J. Corbet <corbet@lwn.net> |
1089 | */ | 1088 | */ |
1090 | #if defined(CONFIG_KALLSYMS) && defined(CONFIG_SYSFS) | 1089 | #if defined(CONFIG_KALLSYMS) && defined(CONFIG_SYSFS) |
1091 | struct module_sect_attr | 1090 | struct module_sect_attr |
1092 | { | 1091 | { |
1093 | struct module_attribute mattr; | 1092 | struct module_attribute mattr; |
1094 | char *name; | 1093 | char *name; |
1095 | unsigned long address; | 1094 | unsigned long address; |
1096 | }; | 1095 | }; |
1097 | 1096 | ||
1098 | struct module_sect_attrs | 1097 | struct module_sect_attrs |
1099 | { | 1098 | { |
1100 | struct attribute_group grp; | 1099 | struct attribute_group grp; |
1101 | unsigned int nsections; | 1100 | unsigned int nsections; |
1102 | struct module_sect_attr attrs[0]; | 1101 | struct module_sect_attr attrs[0]; |
1103 | }; | 1102 | }; |
1104 | 1103 | ||
1105 | static ssize_t module_sect_show(struct module_attribute *mattr, | 1104 | static ssize_t module_sect_show(struct module_attribute *mattr, |
1106 | struct module *mod, char *buf) | 1105 | struct module *mod, char *buf) |
1107 | { | 1106 | { |
1108 | struct module_sect_attr *sattr = | 1107 | struct module_sect_attr *sattr = |
1109 | container_of(mattr, struct module_sect_attr, mattr); | 1108 | container_of(mattr, struct module_sect_attr, mattr); |
1110 | return sprintf(buf, "0x%lx\n", sattr->address); | 1109 | return sprintf(buf, "0x%lx\n", sattr->address); |
1111 | } | 1110 | } |
1112 | 1111 | ||
1113 | static void free_sect_attrs(struct module_sect_attrs *sect_attrs) | 1112 | static void free_sect_attrs(struct module_sect_attrs *sect_attrs) |
1114 | { | 1113 | { |
1115 | unsigned int section; | 1114 | unsigned int section; |
1116 | 1115 | ||
1117 | for (section = 0; section < sect_attrs->nsections; section++) | 1116 | for (section = 0; section < sect_attrs->nsections; section++) |
1118 | kfree(sect_attrs->attrs[section].name); | 1117 | kfree(sect_attrs->attrs[section].name); |
1119 | kfree(sect_attrs); | 1118 | kfree(sect_attrs); |
1120 | } | 1119 | } |
1121 | 1120 | ||
1122 | static void add_sect_attrs(struct module *mod, unsigned int nsect, | 1121 | static void add_sect_attrs(struct module *mod, unsigned int nsect, |
1123 | char *secstrings, Elf_Shdr *sechdrs) | 1122 | char *secstrings, Elf_Shdr *sechdrs) |
1124 | { | 1123 | { |
1125 | unsigned int nloaded = 0, i, size[2]; | 1124 | unsigned int nloaded = 0, i, size[2]; |
1126 | struct module_sect_attrs *sect_attrs; | 1125 | struct module_sect_attrs *sect_attrs; |
1127 | struct module_sect_attr *sattr; | 1126 | struct module_sect_attr *sattr; |
1128 | struct attribute **gattr; | 1127 | struct attribute **gattr; |
1129 | 1128 | ||
1130 | /* Count loaded sections and allocate structures */ | 1129 | /* Count loaded sections and allocate structures */ |
1131 | for (i = 0; i < nsect; i++) | 1130 | for (i = 0; i < nsect; i++) |
1132 | if (sechdrs[i].sh_flags & SHF_ALLOC) | 1131 | if (sechdrs[i].sh_flags & SHF_ALLOC) |
1133 | nloaded++; | 1132 | nloaded++; |
1134 | size[0] = ALIGN(sizeof(*sect_attrs) | 1133 | size[0] = ALIGN(sizeof(*sect_attrs) |
1135 | + nloaded * sizeof(sect_attrs->attrs[0]), | 1134 | + nloaded * sizeof(sect_attrs->attrs[0]), |
1136 | sizeof(sect_attrs->grp.attrs[0])); | 1135 | sizeof(sect_attrs->grp.attrs[0])); |
1137 | size[1] = (nloaded + 1) * sizeof(sect_attrs->grp.attrs[0]); | 1136 | size[1] = (nloaded + 1) * sizeof(sect_attrs->grp.attrs[0]); |
1138 | sect_attrs = kzalloc(size[0] + size[1], GFP_KERNEL); | 1137 | sect_attrs = kzalloc(size[0] + size[1], GFP_KERNEL); |
1139 | if (sect_attrs == NULL) | 1138 | if (sect_attrs == NULL) |
1140 | return; | 1139 | return; |
1141 | 1140 | ||
1142 | /* Setup section attributes. */ | 1141 | /* Setup section attributes. */ |
1143 | sect_attrs->grp.name = "sections"; | 1142 | sect_attrs->grp.name = "sections"; |
1144 | sect_attrs->grp.attrs = (void *)sect_attrs + size[0]; | 1143 | sect_attrs->grp.attrs = (void *)sect_attrs + size[0]; |
1145 | 1144 | ||
1146 | sect_attrs->nsections = 0; | 1145 | sect_attrs->nsections = 0; |
1147 | sattr = §_attrs->attrs[0]; | 1146 | sattr = §_attrs->attrs[0]; |
1148 | gattr = §_attrs->grp.attrs[0]; | 1147 | gattr = §_attrs->grp.attrs[0]; |
1149 | for (i = 0; i < nsect; i++) { | 1148 | for (i = 0; i < nsect; i++) { |
1150 | if (! (sechdrs[i].sh_flags & SHF_ALLOC)) | 1149 | if (! (sechdrs[i].sh_flags & SHF_ALLOC)) |
1151 | continue; | 1150 | continue; |
1152 | sattr->address = sechdrs[i].sh_addr; | 1151 | sattr->address = sechdrs[i].sh_addr; |
1153 | sattr->name = kstrdup(secstrings + sechdrs[i].sh_name, | 1152 | sattr->name = kstrdup(secstrings + sechdrs[i].sh_name, |
1154 | GFP_KERNEL); | 1153 | GFP_KERNEL); |
1155 | if (sattr->name == NULL) | 1154 | if (sattr->name == NULL) |
1156 | goto out; | 1155 | goto out; |
1157 | sect_attrs->nsections++; | 1156 | sect_attrs->nsections++; |
1158 | sattr->mattr.show = module_sect_show; | 1157 | sattr->mattr.show = module_sect_show; |
1159 | sattr->mattr.store = NULL; | 1158 | sattr->mattr.store = NULL; |
1160 | sattr->mattr.attr.name = sattr->name; | 1159 | sattr->mattr.attr.name = sattr->name; |
1161 | sattr->mattr.attr.mode = S_IRUGO; | 1160 | sattr->mattr.attr.mode = S_IRUGO; |
1162 | *(gattr++) = &(sattr++)->mattr.attr; | 1161 | *(gattr++) = &(sattr++)->mattr.attr; |
1163 | } | 1162 | } |
1164 | *gattr = NULL; | 1163 | *gattr = NULL; |
1165 | 1164 | ||
1166 | if (sysfs_create_group(&mod->mkobj.kobj, §_attrs->grp)) | 1165 | if (sysfs_create_group(&mod->mkobj.kobj, §_attrs->grp)) |
1167 | goto out; | 1166 | goto out; |
1168 | 1167 | ||
1169 | mod->sect_attrs = sect_attrs; | 1168 | mod->sect_attrs = sect_attrs; |
1170 | return; | 1169 | return; |
1171 | out: | 1170 | out: |
1172 | free_sect_attrs(sect_attrs); | 1171 | free_sect_attrs(sect_attrs); |
1173 | } | 1172 | } |
1174 | 1173 | ||
1175 | static void remove_sect_attrs(struct module *mod) | 1174 | static void remove_sect_attrs(struct module *mod) |
1176 | { | 1175 | { |
1177 | if (mod->sect_attrs) { | 1176 | if (mod->sect_attrs) { |
1178 | sysfs_remove_group(&mod->mkobj.kobj, | 1177 | sysfs_remove_group(&mod->mkobj.kobj, |
1179 | &mod->sect_attrs->grp); | 1178 | &mod->sect_attrs->grp); |
1180 | /* We are positive that no one is using any sect attrs | 1179 | /* We are positive that no one is using any sect attrs |
1181 | * at this point. Deallocate immediately. */ | 1180 | * at this point. Deallocate immediately. */ |
1182 | free_sect_attrs(mod->sect_attrs); | 1181 | free_sect_attrs(mod->sect_attrs); |
1183 | mod->sect_attrs = NULL; | 1182 | mod->sect_attrs = NULL; |
1184 | } | 1183 | } |
1185 | } | 1184 | } |
1186 | 1185 | ||
1187 | /* | 1186 | /* |
1188 | * /sys/module/foo/notes/.section.name gives contents of SHT_NOTE sections. | 1187 | * /sys/module/foo/notes/.section.name gives contents of SHT_NOTE sections. |
1189 | */ | 1188 | */ |
1190 | 1189 | ||
1191 | struct module_notes_attrs { | 1190 | struct module_notes_attrs { |
1192 | struct kobject *dir; | 1191 | struct kobject *dir; |
1193 | unsigned int notes; | 1192 | unsigned int notes; |
1194 | struct bin_attribute attrs[0]; | 1193 | struct bin_attribute attrs[0]; |
1195 | }; | 1194 | }; |
1196 | 1195 | ||
1197 | static ssize_t module_notes_read(struct kobject *kobj, | 1196 | static ssize_t module_notes_read(struct kobject *kobj, |
1198 | struct bin_attribute *bin_attr, | 1197 | struct bin_attribute *bin_attr, |
1199 | char *buf, loff_t pos, size_t count) | 1198 | char *buf, loff_t pos, size_t count) |
1200 | { | 1199 | { |
1201 | /* | 1200 | /* |
1202 | * The caller checked the pos and count against our size. | 1201 | * The caller checked the pos and count against our size. |
1203 | */ | 1202 | */ |
1204 | memcpy(buf, bin_attr->private + pos, count); | 1203 | memcpy(buf, bin_attr->private + pos, count); |
1205 | return count; | 1204 | return count; |
1206 | } | 1205 | } |
1207 | 1206 | ||
1208 | static void free_notes_attrs(struct module_notes_attrs *notes_attrs, | 1207 | static void free_notes_attrs(struct module_notes_attrs *notes_attrs, |
1209 | unsigned int i) | 1208 | unsigned int i) |
1210 | { | 1209 | { |
1211 | if (notes_attrs->dir) { | 1210 | if (notes_attrs->dir) { |
1212 | while (i-- > 0) | 1211 | while (i-- > 0) |
1213 | sysfs_remove_bin_file(notes_attrs->dir, | 1212 | sysfs_remove_bin_file(notes_attrs->dir, |
1214 | ¬es_attrs->attrs[i]); | 1213 | ¬es_attrs->attrs[i]); |
1215 | kobject_put(notes_attrs->dir); | 1214 | kobject_put(notes_attrs->dir); |
1216 | } | 1215 | } |
1217 | kfree(notes_attrs); | 1216 | kfree(notes_attrs); |
1218 | } | 1217 | } |
1219 | 1218 | ||
1220 | static void add_notes_attrs(struct module *mod, unsigned int nsect, | 1219 | static void add_notes_attrs(struct module *mod, unsigned int nsect, |
1221 | char *secstrings, Elf_Shdr *sechdrs) | 1220 | char *secstrings, Elf_Shdr *sechdrs) |
1222 | { | 1221 | { |
1223 | unsigned int notes, loaded, i; | 1222 | unsigned int notes, loaded, i; |
1224 | struct module_notes_attrs *notes_attrs; | 1223 | struct module_notes_attrs *notes_attrs; |
1225 | struct bin_attribute *nattr; | 1224 | struct bin_attribute *nattr; |
1226 | 1225 | ||
1227 | /* Count notes sections and allocate structures. */ | 1226 | /* Count notes sections and allocate structures. */ |
1228 | notes = 0; | 1227 | notes = 0; |
1229 | for (i = 0; i < nsect; i++) | 1228 | for (i = 0; i < nsect; i++) |
1230 | if ((sechdrs[i].sh_flags & SHF_ALLOC) && | 1229 | if ((sechdrs[i].sh_flags & SHF_ALLOC) && |
1231 | (sechdrs[i].sh_type == SHT_NOTE)) | 1230 | (sechdrs[i].sh_type == SHT_NOTE)) |
1232 | ++notes; | 1231 | ++notes; |
1233 | 1232 | ||
1234 | if (notes == 0) | 1233 | if (notes == 0) |
1235 | return; | 1234 | return; |
1236 | 1235 | ||
1237 | notes_attrs = kzalloc(sizeof(*notes_attrs) | 1236 | notes_attrs = kzalloc(sizeof(*notes_attrs) |
1238 | + notes * sizeof(notes_attrs->attrs[0]), | 1237 | + notes * sizeof(notes_attrs->attrs[0]), |
1239 | GFP_KERNEL); | 1238 | GFP_KERNEL); |
1240 | if (notes_attrs == NULL) | 1239 | if (notes_attrs == NULL) |
1241 | return; | 1240 | return; |
1242 | 1241 | ||
1243 | notes_attrs->notes = notes; | 1242 | notes_attrs->notes = notes; |
1244 | nattr = ¬es_attrs->attrs[0]; | 1243 | nattr = ¬es_attrs->attrs[0]; |
1245 | for (loaded = i = 0; i < nsect; ++i) { | 1244 | for (loaded = i = 0; i < nsect; ++i) { |
1246 | if (!(sechdrs[i].sh_flags & SHF_ALLOC)) | 1245 | if (!(sechdrs[i].sh_flags & SHF_ALLOC)) |
1247 | continue; | 1246 | continue; |
1248 | if (sechdrs[i].sh_type == SHT_NOTE) { | 1247 | if (sechdrs[i].sh_type == SHT_NOTE) { |
1249 | nattr->attr.name = mod->sect_attrs->attrs[loaded].name; | 1248 | nattr->attr.name = mod->sect_attrs->attrs[loaded].name; |
1250 | nattr->attr.mode = S_IRUGO; | 1249 | nattr->attr.mode = S_IRUGO; |
1251 | nattr->size = sechdrs[i].sh_size; | 1250 | nattr->size = sechdrs[i].sh_size; |
1252 | nattr->private = (void *) sechdrs[i].sh_addr; | 1251 | nattr->private = (void *) sechdrs[i].sh_addr; |
1253 | nattr->read = module_notes_read; | 1252 | nattr->read = module_notes_read; |
1254 | ++nattr; | 1253 | ++nattr; |
1255 | } | 1254 | } |
1256 | ++loaded; | 1255 | ++loaded; |
1257 | } | 1256 | } |
1258 | 1257 | ||
1259 | notes_attrs->dir = kobject_create_and_add("notes", &mod->mkobj.kobj); | 1258 | notes_attrs->dir = kobject_create_and_add("notes", &mod->mkobj.kobj); |
1260 | if (!notes_attrs->dir) | 1259 | if (!notes_attrs->dir) |
1261 | goto out; | 1260 | goto out; |
1262 | 1261 | ||
1263 | for (i = 0; i < notes; ++i) | 1262 | for (i = 0; i < notes; ++i) |
1264 | if (sysfs_create_bin_file(notes_attrs->dir, | 1263 | if (sysfs_create_bin_file(notes_attrs->dir, |
1265 | ¬es_attrs->attrs[i])) | 1264 | ¬es_attrs->attrs[i])) |
1266 | goto out; | 1265 | goto out; |
1267 | 1266 | ||
1268 | mod->notes_attrs = notes_attrs; | 1267 | mod->notes_attrs = notes_attrs; |
1269 | return; | 1268 | return; |
1270 | 1269 | ||
1271 | out: | 1270 | out: |
1272 | free_notes_attrs(notes_attrs, i); | 1271 | free_notes_attrs(notes_attrs, i); |
1273 | } | 1272 | } |
1274 | 1273 | ||
1275 | static void remove_notes_attrs(struct module *mod) | 1274 | static void remove_notes_attrs(struct module *mod) |
1276 | { | 1275 | { |
1277 | if (mod->notes_attrs) | 1276 | if (mod->notes_attrs) |
1278 | free_notes_attrs(mod->notes_attrs, mod->notes_attrs->notes); | 1277 | free_notes_attrs(mod->notes_attrs, mod->notes_attrs->notes); |
1279 | } | 1278 | } |
1280 | 1279 | ||
1281 | #else | 1280 | #else |
1282 | 1281 | ||
1283 | static inline void add_sect_attrs(struct module *mod, unsigned int nsect, | 1282 | static inline void add_sect_attrs(struct module *mod, unsigned int nsect, |
1284 | char *sectstrings, Elf_Shdr *sechdrs) | 1283 | char *sectstrings, Elf_Shdr *sechdrs) |
1285 | { | 1284 | { |
1286 | } | 1285 | } |
1287 | 1286 | ||
1288 | static inline void remove_sect_attrs(struct module *mod) | 1287 | static inline void remove_sect_attrs(struct module *mod) |
1289 | { | 1288 | { |
1290 | } | 1289 | } |
1291 | 1290 | ||
1292 | static inline void add_notes_attrs(struct module *mod, unsigned int nsect, | 1291 | static inline void add_notes_attrs(struct module *mod, unsigned int nsect, |
1293 | char *sectstrings, Elf_Shdr *sechdrs) | 1292 | char *sectstrings, Elf_Shdr *sechdrs) |
1294 | { | 1293 | { |
1295 | } | 1294 | } |
1296 | 1295 | ||
1297 | static inline void remove_notes_attrs(struct module *mod) | 1296 | static inline void remove_notes_attrs(struct module *mod) |
1298 | { | 1297 | { |
1299 | } | 1298 | } |
1300 | #endif | 1299 | #endif |
1301 | 1300 | ||
1302 | #ifdef CONFIG_SYSFS | 1301 | #ifdef CONFIG_SYSFS |
1303 | int module_add_modinfo_attrs(struct module *mod) | 1302 | int module_add_modinfo_attrs(struct module *mod) |
1304 | { | 1303 | { |
1305 | struct module_attribute *attr; | 1304 | struct module_attribute *attr; |
1306 | struct module_attribute *temp_attr; | 1305 | struct module_attribute *temp_attr; |
1307 | int error = 0; | 1306 | int error = 0; |
1308 | int i; | 1307 | int i; |
1309 | 1308 | ||
1310 | mod->modinfo_attrs = kzalloc((sizeof(struct module_attribute) * | 1309 | mod->modinfo_attrs = kzalloc((sizeof(struct module_attribute) * |
1311 | (ARRAY_SIZE(modinfo_attrs) + 1)), | 1310 | (ARRAY_SIZE(modinfo_attrs) + 1)), |
1312 | GFP_KERNEL); | 1311 | GFP_KERNEL); |
1313 | if (!mod->modinfo_attrs) | 1312 | if (!mod->modinfo_attrs) |
1314 | return -ENOMEM; | 1313 | return -ENOMEM; |
1315 | 1314 | ||
1316 | temp_attr = mod->modinfo_attrs; | 1315 | temp_attr = mod->modinfo_attrs; |
1317 | for (i = 0; (attr = modinfo_attrs[i]) && !error; i++) { | 1316 | for (i = 0; (attr = modinfo_attrs[i]) && !error; i++) { |
1318 | if (!attr->test || | 1317 | if (!attr->test || |
1319 | (attr->test && attr->test(mod))) { | 1318 | (attr->test && attr->test(mod))) { |
1320 | memcpy(temp_attr, attr, sizeof(*temp_attr)); | 1319 | memcpy(temp_attr, attr, sizeof(*temp_attr)); |
1321 | error = sysfs_create_file(&mod->mkobj.kobj,&temp_attr->attr); | 1320 | error = sysfs_create_file(&mod->mkobj.kobj,&temp_attr->attr); |
1322 | ++temp_attr; | 1321 | ++temp_attr; |
1323 | } | 1322 | } |
1324 | } | 1323 | } |
1325 | return error; | 1324 | return error; |
1326 | } | 1325 | } |
1327 | 1326 | ||
1328 | void module_remove_modinfo_attrs(struct module *mod) | 1327 | void module_remove_modinfo_attrs(struct module *mod) |
1329 | { | 1328 | { |
1330 | struct module_attribute *attr; | 1329 | struct module_attribute *attr; |
1331 | int i; | 1330 | int i; |
1332 | 1331 | ||
1333 | for (i = 0; (attr = &mod->modinfo_attrs[i]); i++) { | 1332 | for (i = 0; (attr = &mod->modinfo_attrs[i]); i++) { |
1334 | /* pick a field to test for end of list */ | 1333 | /* pick a field to test for end of list */ |
1335 | if (!attr->attr.name) | 1334 | if (!attr->attr.name) |
1336 | break; | 1335 | break; |
1337 | sysfs_remove_file(&mod->mkobj.kobj,&attr->attr); | 1336 | sysfs_remove_file(&mod->mkobj.kobj,&attr->attr); |
1338 | if (attr->free) | 1337 | if (attr->free) |
1339 | attr->free(mod); | 1338 | attr->free(mod); |
1340 | } | 1339 | } |
1341 | kfree(mod->modinfo_attrs); | 1340 | kfree(mod->modinfo_attrs); |
1342 | } | 1341 | } |
1343 | 1342 | ||
1344 | int mod_sysfs_init(struct module *mod) | 1343 | int mod_sysfs_init(struct module *mod) |
1345 | { | 1344 | { |
1346 | int err; | 1345 | int err; |
1347 | struct kobject *kobj; | 1346 | struct kobject *kobj; |
1348 | 1347 | ||
1349 | if (!module_sysfs_initialized) { | 1348 | if (!module_sysfs_initialized) { |
1350 | printk(KERN_ERR "%s: module sysfs not initialized\n", | 1349 | printk(KERN_ERR "%s: module sysfs not initialized\n", |
1351 | mod->name); | 1350 | mod->name); |
1352 | err = -EINVAL; | 1351 | err = -EINVAL; |
1353 | goto out; | 1352 | goto out; |
1354 | } | 1353 | } |
1355 | 1354 | ||
1356 | kobj = kset_find_obj(module_kset, mod->name); | 1355 | kobj = kset_find_obj(module_kset, mod->name); |
1357 | if (kobj) { | 1356 | if (kobj) { |
1358 | printk(KERN_ERR "%s: module is already loaded\n", mod->name); | 1357 | printk(KERN_ERR "%s: module is already loaded\n", mod->name); |
1359 | kobject_put(kobj); | 1358 | kobject_put(kobj); |
1360 | err = -EINVAL; | 1359 | err = -EINVAL; |
1361 | goto out; | 1360 | goto out; |
1362 | } | 1361 | } |
1363 | 1362 | ||
1364 | mod->mkobj.mod = mod; | 1363 | mod->mkobj.mod = mod; |
1365 | 1364 | ||
1366 | memset(&mod->mkobj.kobj, 0, sizeof(mod->mkobj.kobj)); | 1365 | memset(&mod->mkobj.kobj, 0, sizeof(mod->mkobj.kobj)); |
1367 | mod->mkobj.kobj.kset = module_kset; | 1366 | mod->mkobj.kobj.kset = module_kset; |
1368 | err = kobject_init_and_add(&mod->mkobj.kobj, &module_ktype, NULL, | 1367 | err = kobject_init_and_add(&mod->mkobj.kobj, &module_ktype, NULL, |
1369 | "%s", mod->name); | 1368 | "%s", mod->name); |
1370 | if (err) | 1369 | if (err) |
1371 | kobject_put(&mod->mkobj.kobj); | 1370 | kobject_put(&mod->mkobj.kobj); |
1372 | 1371 | ||
1373 | /* delay uevent until full sysfs population */ | 1372 | /* delay uevent until full sysfs population */ |
1374 | out: | 1373 | out: |
1375 | return err; | 1374 | return err; |
1376 | } | 1375 | } |
1377 | 1376 | ||
1378 | int mod_sysfs_setup(struct module *mod, | 1377 | int mod_sysfs_setup(struct module *mod, |
1379 | struct kernel_param *kparam, | 1378 | struct kernel_param *kparam, |
1380 | unsigned int num_params) | 1379 | unsigned int num_params) |
1381 | { | 1380 | { |
1382 | int err; | 1381 | int err; |
1383 | 1382 | ||
1384 | mod->holders_dir = kobject_create_and_add("holders", &mod->mkobj.kobj); | 1383 | mod->holders_dir = kobject_create_and_add("holders", &mod->mkobj.kobj); |
1385 | if (!mod->holders_dir) { | 1384 | if (!mod->holders_dir) { |
1386 | err = -ENOMEM; | 1385 | err = -ENOMEM; |
1387 | goto out_unreg; | 1386 | goto out_unreg; |
1388 | } | 1387 | } |
1389 | 1388 | ||
1390 | err = module_param_sysfs_setup(mod, kparam, num_params); | 1389 | err = module_param_sysfs_setup(mod, kparam, num_params); |
1391 | if (err) | 1390 | if (err) |
1392 | goto out_unreg_holders; | 1391 | goto out_unreg_holders; |
1393 | 1392 | ||
1394 | err = module_add_modinfo_attrs(mod); | 1393 | err = module_add_modinfo_attrs(mod); |
1395 | if (err) | 1394 | if (err) |
1396 | goto out_unreg_param; | 1395 | goto out_unreg_param; |
1397 | 1396 | ||
1398 | kobject_uevent(&mod->mkobj.kobj, KOBJ_ADD); | 1397 | kobject_uevent(&mod->mkobj.kobj, KOBJ_ADD); |
1399 | return 0; | 1398 | return 0; |
1400 | 1399 | ||
1401 | out_unreg_param: | 1400 | out_unreg_param: |
1402 | module_param_sysfs_remove(mod); | 1401 | module_param_sysfs_remove(mod); |
1403 | out_unreg_holders: | 1402 | out_unreg_holders: |
1404 | kobject_put(mod->holders_dir); | 1403 | kobject_put(mod->holders_dir); |
1405 | out_unreg: | 1404 | out_unreg: |
1406 | kobject_put(&mod->mkobj.kobj); | 1405 | kobject_put(&mod->mkobj.kobj); |
1407 | return err; | 1406 | return err; |
1408 | } | 1407 | } |
1409 | 1408 | ||
1410 | static void mod_sysfs_fini(struct module *mod) | 1409 | static void mod_sysfs_fini(struct module *mod) |
1411 | { | 1410 | { |
1412 | kobject_put(&mod->mkobj.kobj); | 1411 | kobject_put(&mod->mkobj.kobj); |
1413 | } | 1412 | } |
1414 | 1413 | ||
1415 | #else /* CONFIG_SYSFS */ | 1414 | #else /* CONFIG_SYSFS */ |
1416 | 1415 | ||
1417 | static void mod_sysfs_fini(struct module *mod) | 1416 | static void mod_sysfs_fini(struct module *mod) |
1418 | { | 1417 | { |
1419 | } | 1418 | } |
1420 | 1419 | ||
1421 | #endif /* CONFIG_SYSFS */ | 1420 | #endif /* CONFIG_SYSFS */ |
1422 | 1421 | ||
1423 | static void mod_kobject_remove(struct module *mod) | 1422 | static void mod_kobject_remove(struct module *mod) |
1424 | { | 1423 | { |
1425 | module_remove_modinfo_attrs(mod); | 1424 | module_remove_modinfo_attrs(mod); |
1426 | module_param_sysfs_remove(mod); | 1425 | module_param_sysfs_remove(mod); |
1427 | kobject_put(mod->mkobj.drivers_dir); | 1426 | kobject_put(mod->mkobj.drivers_dir); |
1428 | kobject_put(mod->holders_dir); | 1427 | kobject_put(mod->holders_dir); |
1429 | mod_sysfs_fini(mod); | 1428 | mod_sysfs_fini(mod); |
1430 | } | 1429 | } |
1431 | 1430 | ||
1432 | /* | 1431 | /* |
1433 | * unlink the module with the whole machine is stopped with interrupts off | 1432 | * unlink the module with the whole machine is stopped with interrupts off |
1434 | * - this defends against kallsyms not taking locks | 1433 | * - this defends against kallsyms not taking locks |
1435 | */ | 1434 | */ |
1436 | static int __unlink_module(void *_mod) | 1435 | static int __unlink_module(void *_mod) |
1437 | { | 1436 | { |
1438 | struct module *mod = _mod; | 1437 | struct module *mod = _mod; |
1439 | list_del(&mod->list); | 1438 | list_del(&mod->list); |
1440 | return 0; | 1439 | return 0; |
1441 | } | 1440 | } |
1442 | 1441 | ||
1443 | /* Free a module, remove from lists, etc (must hold module_mutex). */ | 1442 | /* Free a module, remove from lists, etc (must hold module_mutex). */ |
1444 | static void free_module(struct module *mod) | 1443 | static void free_module(struct module *mod) |
1445 | { | 1444 | { |
1446 | /* Delete from various lists */ | 1445 | /* Delete from various lists */ |
1447 | stop_machine(__unlink_module, mod, NULL); | 1446 | stop_machine(__unlink_module, mod, NULL); |
1448 | remove_notes_attrs(mod); | 1447 | remove_notes_attrs(mod); |
1449 | remove_sect_attrs(mod); | 1448 | remove_sect_attrs(mod); |
1450 | mod_kobject_remove(mod); | 1449 | mod_kobject_remove(mod); |
1451 | 1450 | ||
1452 | unwind_remove_table(mod->unwind_info, 0); | ||
1453 | |||
1454 | /* Arch-specific cleanup. */ | 1451 | /* Arch-specific cleanup. */ |
1455 | module_arch_cleanup(mod); | 1452 | module_arch_cleanup(mod); |
1456 | 1453 | ||
1457 | /* Module unload stuff */ | 1454 | /* Module unload stuff */ |
1458 | module_unload_free(mod); | 1455 | module_unload_free(mod); |
1459 | 1456 | ||
1460 | /* release any pointers to mcount in this module */ | 1457 | /* release any pointers to mcount in this module */ |
1461 | ftrace_release(mod->module_core, mod->core_size); | 1458 | ftrace_release(mod->module_core, mod->core_size); |
1462 | 1459 | ||
1463 | /* This may be NULL, but that's OK */ | 1460 | /* This may be NULL, but that's OK */ |
1464 | module_free(mod, mod->module_init); | 1461 | module_free(mod, mod->module_init); |
1465 | kfree(mod->args); | 1462 | kfree(mod->args); |
1466 | if (mod->percpu) | 1463 | if (mod->percpu) |
1467 | percpu_modfree(mod->percpu); | 1464 | percpu_modfree(mod->percpu); |
1468 | 1465 | ||
1469 | /* Free lock-classes: */ | 1466 | /* Free lock-classes: */ |
1470 | lockdep_free_key_range(mod->module_core, mod->core_size); | 1467 | lockdep_free_key_range(mod->module_core, mod->core_size); |
1471 | 1468 | ||
1472 | /* Finally, free the core (containing the module structure) */ | 1469 | /* Finally, free the core (containing the module structure) */ |
1473 | module_free(mod, mod->module_core); | 1470 | module_free(mod, mod->module_core); |
1474 | } | 1471 | } |
1475 | 1472 | ||
1476 | void *__symbol_get(const char *symbol) | 1473 | void *__symbol_get(const char *symbol) |
1477 | { | 1474 | { |
1478 | struct module *owner; | 1475 | struct module *owner; |
1479 | unsigned long value; | 1476 | unsigned long value; |
1480 | 1477 | ||
1481 | preempt_disable(); | 1478 | preempt_disable(); |
1482 | value = find_symbol(symbol, &owner, NULL, true, true); | 1479 | value = find_symbol(symbol, &owner, NULL, true, true); |
1483 | if (IS_ERR_VALUE(value)) | 1480 | if (IS_ERR_VALUE(value)) |
1484 | value = 0; | 1481 | value = 0; |
1485 | else if (strong_try_module_get(owner)) | 1482 | else if (strong_try_module_get(owner)) |
1486 | value = 0; | 1483 | value = 0; |
1487 | preempt_enable(); | 1484 | preempt_enable(); |
1488 | 1485 | ||
1489 | return (void *)value; | 1486 | return (void *)value; |
1490 | } | 1487 | } |
1491 | EXPORT_SYMBOL_GPL(__symbol_get); | 1488 | EXPORT_SYMBOL_GPL(__symbol_get); |
1492 | 1489 | ||
1493 | /* | 1490 | /* |
1494 | * Ensure that an exported symbol [global namespace] does not already exist | 1491 | * Ensure that an exported symbol [global namespace] does not already exist |
1495 | * in the kernel or in some other module's exported symbol table. | 1492 | * in the kernel or in some other module's exported symbol table. |
1496 | */ | 1493 | */ |
1497 | static int verify_export_symbols(struct module *mod) | 1494 | static int verify_export_symbols(struct module *mod) |
1498 | { | 1495 | { |
1499 | unsigned int i; | 1496 | unsigned int i; |
1500 | struct module *owner; | 1497 | struct module *owner; |
1501 | const struct kernel_symbol *s; | 1498 | const struct kernel_symbol *s; |
1502 | struct { | 1499 | struct { |
1503 | const struct kernel_symbol *sym; | 1500 | const struct kernel_symbol *sym; |
1504 | unsigned int num; | 1501 | unsigned int num; |
1505 | } arr[] = { | 1502 | } arr[] = { |
1506 | { mod->syms, mod->num_syms }, | 1503 | { mod->syms, mod->num_syms }, |
1507 | { mod->gpl_syms, mod->num_gpl_syms }, | 1504 | { mod->gpl_syms, mod->num_gpl_syms }, |
1508 | { mod->gpl_future_syms, mod->num_gpl_future_syms }, | 1505 | { mod->gpl_future_syms, mod->num_gpl_future_syms }, |
1509 | #ifdef CONFIG_UNUSED_SYMBOLS | 1506 | #ifdef CONFIG_UNUSED_SYMBOLS |
1510 | { mod->unused_syms, mod->num_unused_syms }, | 1507 | { mod->unused_syms, mod->num_unused_syms }, |
1511 | { mod->unused_gpl_syms, mod->num_unused_gpl_syms }, | 1508 | { mod->unused_gpl_syms, mod->num_unused_gpl_syms }, |
1512 | #endif | 1509 | #endif |
1513 | }; | 1510 | }; |
1514 | 1511 | ||
1515 | for (i = 0; i < ARRAY_SIZE(arr); i++) { | 1512 | for (i = 0; i < ARRAY_SIZE(arr); i++) { |
1516 | for (s = arr[i].sym; s < arr[i].sym + arr[i].num; s++) { | 1513 | for (s = arr[i].sym; s < arr[i].sym + arr[i].num; s++) { |
1517 | if (!IS_ERR_VALUE(find_symbol(s->name, &owner, | 1514 | if (!IS_ERR_VALUE(find_symbol(s->name, &owner, |
1518 | NULL, true, false))) { | 1515 | NULL, true, false))) { |
1519 | printk(KERN_ERR | 1516 | printk(KERN_ERR |
1520 | "%s: exports duplicate symbol %s" | 1517 | "%s: exports duplicate symbol %s" |
1521 | " (owned by %s)\n", | 1518 | " (owned by %s)\n", |
1522 | mod->name, s->name, module_name(owner)); | 1519 | mod->name, s->name, module_name(owner)); |
1523 | return -ENOEXEC; | 1520 | return -ENOEXEC; |
1524 | } | 1521 | } |
1525 | } | 1522 | } |
1526 | } | 1523 | } |
1527 | return 0; | 1524 | return 0; |
1528 | } | 1525 | } |
1529 | 1526 | ||
1530 | /* Change all symbols so that st_value encodes the pointer directly. */ | 1527 | /* Change all symbols so that st_value encodes the pointer directly. */ |
1531 | static int simplify_symbols(Elf_Shdr *sechdrs, | 1528 | static int simplify_symbols(Elf_Shdr *sechdrs, |
1532 | unsigned int symindex, | 1529 | unsigned int symindex, |
1533 | const char *strtab, | 1530 | const char *strtab, |
1534 | unsigned int versindex, | 1531 | unsigned int versindex, |
1535 | unsigned int pcpuindex, | 1532 | unsigned int pcpuindex, |
1536 | struct module *mod) | 1533 | struct module *mod) |
1537 | { | 1534 | { |
1538 | Elf_Sym *sym = (void *)sechdrs[symindex].sh_addr; | 1535 | Elf_Sym *sym = (void *)sechdrs[symindex].sh_addr; |
1539 | unsigned long secbase; | 1536 | unsigned long secbase; |
1540 | unsigned int i, n = sechdrs[symindex].sh_size / sizeof(Elf_Sym); | 1537 | unsigned int i, n = sechdrs[symindex].sh_size / sizeof(Elf_Sym); |
1541 | int ret = 0; | 1538 | int ret = 0; |
1542 | 1539 | ||
1543 | for (i = 1; i < n; i++) { | 1540 | for (i = 1; i < n; i++) { |
1544 | switch (sym[i].st_shndx) { | 1541 | switch (sym[i].st_shndx) { |
1545 | case SHN_COMMON: | 1542 | case SHN_COMMON: |
1546 | /* We compiled with -fno-common. These are not | 1543 | /* We compiled with -fno-common. These are not |
1547 | supposed to happen. */ | 1544 | supposed to happen. */ |
1548 | DEBUGP("Common symbol: %s\n", strtab + sym[i].st_name); | 1545 | DEBUGP("Common symbol: %s\n", strtab + sym[i].st_name); |
1549 | printk("%s: please compile with -fno-common\n", | 1546 | printk("%s: please compile with -fno-common\n", |
1550 | mod->name); | 1547 | mod->name); |
1551 | ret = -ENOEXEC; | 1548 | ret = -ENOEXEC; |
1552 | break; | 1549 | break; |
1553 | 1550 | ||
1554 | case SHN_ABS: | 1551 | case SHN_ABS: |
1555 | /* Don't need to do anything */ | 1552 | /* Don't need to do anything */ |
1556 | DEBUGP("Absolute symbol: 0x%08lx\n", | 1553 | DEBUGP("Absolute symbol: 0x%08lx\n", |
1557 | (long)sym[i].st_value); | 1554 | (long)sym[i].st_value); |
1558 | break; | 1555 | break; |
1559 | 1556 | ||
1560 | case SHN_UNDEF: | 1557 | case SHN_UNDEF: |
1561 | sym[i].st_value | 1558 | sym[i].st_value |
1562 | = resolve_symbol(sechdrs, versindex, | 1559 | = resolve_symbol(sechdrs, versindex, |
1563 | strtab + sym[i].st_name, mod); | 1560 | strtab + sym[i].st_name, mod); |
1564 | 1561 | ||
1565 | /* Ok if resolved. */ | 1562 | /* Ok if resolved. */ |
1566 | if (!IS_ERR_VALUE(sym[i].st_value)) | 1563 | if (!IS_ERR_VALUE(sym[i].st_value)) |
1567 | break; | 1564 | break; |
1568 | /* Ok if weak. */ | 1565 | /* Ok if weak. */ |
1569 | if (ELF_ST_BIND(sym[i].st_info) == STB_WEAK) | 1566 | if (ELF_ST_BIND(sym[i].st_info) == STB_WEAK) |
1570 | break; | 1567 | break; |
1571 | 1568 | ||
1572 | printk(KERN_WARNING "%s: Unknown symbol %s\n", | 1569 | printk(KERN_WARNING "%s: Unknown symbol %s\n", |
1573 | mod->name, strtab + sym[i].st_name); | 1570 | mod->name, strtab + sym[i].st_name); |
1574 | ret = -ENOENT; | 1571 | ret = -ENOENT; |
1575 | break; | 1572 | break; |
1576 | 1573 | ||
1577 | default: | 1574 | default: |
1578 | /* Divert to percpu allocation if a percpu var. */ | 1575 | /* Divert to percpu allocation if a percpu var. */ |
1579 | if (sym[i].st_shndx == pcpuindex) | 1576 | if (sym[i].st_shndx == pcpuindex) |
1580 | secbase = (unsigned long)mod->percpu; | 1577 | secbase = (unsigned long)mod->percpu; |
1581 | else | 1578 | else |
1582 | secbase = sechdrs[sym[i].st_shndx].sh_addr; | 1579 | secbase = sechdrs[sym[i].st_shndx].sh_addr; |
1583 | sym[i].st_value += secbase; | 1580 | sym[i].st_value += secbase; |
1584 | break; | 1581 | break; |
1585 | } | 1582 | } |
1586 | } | 1583 | } |
1587 | 1584 | ||
1588 | return ret; | 1585 | return ret; |
1589 | } | 1586 | } |
1590 | 1587 | ||
1591 | /* Additional bytes needed by arch in front of individual sections */ | 1588 | /* Additional bytes needed by arch in front of individual sections */ |
1592 | unsigned int __weak arch_mod_section_prepend(struct module *mod, | 1589 | unsigned int __weak arch_mod_section_prepend(struct module *mod, |
1593 | unsigned int section) | 1590 | unsigned int section) |
1594 | { | 1591 | { |
1595 | /* default implementation just returns zero */ | 1592 | /* default implementation just returns zero */ |
1596 | return 0; | 1593 | return 0; |
1597 | } | 1594 | } |
1598 | 1595 | ||
1599 | /* Update size with this section: return offset. */ | 1596 | /* Update size with this section: return offset. */ |
1600 | static long get_offset(struct module *mod, unsigned int *size, | 1597 | static long get_offset(struct module *mod, unsigned int *size, |
1601 | Elf_Shdr *sechdr, unsigned int section) | 1598 | Elf_Shdr *sechdr, unsigned int section) |
1602 | { | 1599 | { |
1603 | long ret; | 1600 | long ret; |
1604 | 1601 | ||
1605 | *size += arch_mod_section_prepend(mod, section); | 1602 | *size += arch_mod_section_prepend(mod, section); |
1606 | ret = ALIGN(*size, sechdr->sh_addralign ?: 1); | 1603 | ret = ALIGN(*size, sechdr->sh_addralign ?: 1); |
1607 | *size = ret + sechdr->sh_size; | 1604 | *size = ret + sechdr->sh_size; |
1608 | return ret; | 1605 | return ret; |
1609 | } | 1606 | } |
1610 | 1607 | ||
1611 | /* Lay out the SHF_ALLOC sections in a way not dissimilar to how ld | 1608 | /* Lay out the SHF_ALLOC sections in a way not dissimilar to how ld |
1612 | might -- code, read-only data, read-write data, small data. Tally | 1609 | might -- code, read-only data, read-write data, small data. Tally |
1613 | sizes, and place the offsets into sh_entsize fields: high bit means it | 1610 | sizes, and place the offsets into sh_entsize fields: high bit means it |
1614 | belongs in init. */ | 1611 | belongs in init. */ |
1615 | static void layout_sections(struct module *mod, | 1612 | static void layout_sections(struct module *mod, |
1616 | const Elf_Ehdr *hdr, | 1613 | const Elf_Ehdr *hdr, |
1617 | Elf_Shdr *sechdrs, | 1614 | Elf_Shdr *sechdrs, |
1618 | const char *secstrings) | 1615 | const char *secstrings) |
1619 | { | 1616 | { |
1620 | static unsigned long const masks[][2] = { | 1617 | static unsigned long const masks[][2] = { |
1621 | /* NOTE: all executable code must be the first section | 1618 | /* NOTE: all executable code must be the first section |
1622 | * in this array; otherwise modify the text_size | 1619 | * in this array; otherwise modify the text_size |
1623 | * finder in the two loops below */ | 1620 | * finder in the two loops below */ |
1624 | { SHF_EXECINSTR | SHF_ALLOC, ARCH_SHF_SMALL }, | 1621 | { SHF_EXECINSTR | SHF_ALLOC, ARCH_SHF_SMALL }, |
1625 | { SHF_ALLOC, SHF_WRITE | ARCH_SHF_SMALL }, | 1622 | { SHF_ALLOC, SHF_WRITE | ARCH_SHF_SMALL }, |
1626 | { SHF_WRITE | SHF_ALLOC, ARCH_SHF_SMALL }, | 1623 | { SHF_WRITE | SHF_ALLOC, ARCH_SHF_SMALL }, |
1627 | { ARCH_SHF_SMALL | SHF_ALLOC, 0 } | 1624 | { ARCH_SHF_SMALL | SHF_ALLOC, 0 } |
1628 | }; | 1625 | }; |
1629 | unsigned int m, i; | 1626 | unsigned int m, i; |
1630 | 1627 | ||
1631 | for (i = 0; i < hdr->e_shnum; i++) | 1628 | for (i = 0; i < hdr->e_shnum; i++) |
1632 | sechdrs[i].sh_entsize = ~0UL; | 1629 | sechdrs[i].sh_entsize = ~0UL; |
1633 | 1630 | ||
1634 | DEBUGP("Core section allocation order:\n"); | 1631 | DEBUGP("Core section allocation order:\n"); |
1635 | for (m = 0; m < ARRAY_SIZE(masks); ++m) { | 1632 | for (m = 0; m < ARRAY_SIZE(masks); ++m) { |
1636 | for (i = 0; i < hdr->e_shnum; ++i) { | 1633 | for (i = 0; i < hdr->e_shnum; ++i) { |
1637 | Elf_Shdr *s = &sechdrs[i]; | 1634 | Elf_Shdr *s = &sechdrs[i]; |
1638 | 1635 | ||
1639 | if ((s->sh_flags & masks[m][0]) != masks[m][0] | 1636 | if ((s->sh_flags & masks[m][0]) != masks[m][0] |
1640 | || (s->sh_flags & masks[m][1]) | 1637 | || (s->sh_flags & masks[m][1]) |
1641 | || s->sh_entsize != ~0UL | 1638 | || s->sh_entsize != ~0UL |
1642 | || strncmp(secstrings + s->sh_name, | 1639 | || strncmp(secstrings + s->sh_name, |
1643 | ".init", 5) == 0) | 1640 | ".init", 5) == 0) |
1644 | continue; | 1641 | continue; |
1645 | s->sh_entsize = get_offset(mod, &mod->core_size, s, i); | 1642 | s->sh_entsize = get_offset(mod, &mod->core_size, s, i); |
1646 | DEBUGP("\t%s\n", secstrings + s->sh_name); | 1643 | DEBUGP("\t%s\n", secstrings + s->sh_name); |
1647 | } | 1644 | } |
1648 | if (m == 0) | 1645 | if (m == 0) |
1649 | mod->core_text_size = mod->core_size; | 1646 | mod->core_text_size = mod->core_size; |
1650 | } | 1647 | } |
1651 | 1648 | ||
1652 | DEBUGP("Init section allocation order:\n"); | 1649 | DEBUGP("Init section allocation order:\n"); |
1653 | for (m = 0; m < ARRAY_SIZE(masks); ++m) { | 1650 | for (m = 0; m < ARRAY_SIZE(masks); ++m) { |
1654 | for (i = 0; i < hdr->e_shnum; ++i) { | 1651 | for (i = 0; i < hdr->e_shnum; ++i) { |
1655 | Elf_Shdr *s = &sechdrs[i]; | 1652 | Elf_Shdr *s = &sechdrs[i]; |
1656 | 1653 | ||
1657 | if ((s->sh_flags & masks[m][0]) != masks[m][0] | 1654 | if ((s->sh_flags & masks[m][0]) != masks[m][0] |
1658 | || (s->sh_flags & masks[m][1]) | 1655 | || (s->sh_flags & masks[m][1]) |
1659 | || s->sh_entsize != ~0UL | 1656 | || s->sh_entsize != ~0UL |
1660 | || strncmp(secstrings + s->sh_name, | 1657 | || strncmp(secstrings + s->sh_name, |
1661 | ".init", 5) != 0) | 1658 | ".init", 5) != 0) |
1662 | continue; | 1659 | continue; |
1663 | s->sh_entsize = (get_offset(mod, &mod->init_size, s, i) | 1660 | s->sh_entsize = (get_offset(mod, &mod->init_size, s, i) |
1664 | | INIT_OFFSET_MASK); | 1661 | | INIT_OFFSET_MASK); |
1665 | DEBUGP("\t%s\n", secstrings + s->sh_name); | 1662 | DEBUGP("\t%s\n", secstrings + s->sh_name); |
1666 | } | 1663 | } |
1667 | if (m == 0) | 1664 | if (m == 0) |
1668 | mod->init_text_size = mod->init_size; | 1665 | mod->init_text_size = mod->init_size; |
1669 | } | 1666 | } |
1670 | } | 1667 | } |
1671 | 1668 | ||
1672 | static void set_license(struct module *mod, const char *license) | 1669 | static void set_license(struct module *mod, const char *license) |
1673 | { | 1670 | { |
1674 | if (!license) | 1671 | if (!license) |
1675 | license = "unspecified"; | 1672 | license = "unspecified"; |
1676 | 1673 | ||
1677 | if (!license_is_gpl_compatible(license)) { | 1674 | if (!license_is_gpl_compatible(license)) { |
1678 | if (!test_taint(TAINT_PROPRIETARY_MODULE)) | 1675 | if (!test_taint(TAINT_PROPRIETARY_MODULE)) |
1679 | printk(KERN_WARNING "%s: module license '%s' taints " | 1676 | printk(KERN_WARNING "%s: module license '%s' taints " |
1680 | "kernel.\n", mod->name, license); | 1677 | "kernel.\n", mod->name, license); |
1681 | add_taint_module(mod, TAINT_PROPRIETARY_MODULE); | 1678 | add_taint_module(mod, TAINT_PROPRIETARY_MODULE); |
1682 | } | 1679 | } |
1683 | } | 1680 | } |
1684 | 1681 | ||
1685 | /* Parse tag=value strings from .modinfo section */ | 1682 | /* Parse tag=value strings from .modinfo section */ |
1686 | static char *next_string(char *string, unsigned long *secsize) | 1683 | static char *next_string(char *string, unsigned long *secsize) |
1687 | { | 1684 | { |
1688 | /* Skip non-zero chars */ | 1685 | /* Skip non-zero chars */ |
1689 | while (string[0]) { | 1686 | while (string[0]) { |
1690 | string++; | 1687 | string++; |
1691 | if ((*secsize)-- <= 1) | 1688 | if ((*secsize)-- <= 1) |
1692 | return NULL; | 1689 | return NULL; |
1693 | } | 1690 | } |
1694 | 1691 | ||
1695 | /* Skip any zero padding. */ | 1692 | /* Skip any zero padding. */ |
1696 | while (!string[0]) { | 1693 | while (!string[0]) { |
1697 | string++; | 1694 | string++; |
1698 | if ((*secsize)-- <= 1) | 1695 | if ((*secsize)-- <= 1) |
1699 | return NULL; | 1696 | return NULL; |
1700 | } | 1697 | } |
1701 | return string; | 1698 | return string; |
1702 | } | 1699 | } |
1703 | 1700 | ||
1704 | static char *get_modinfo(Elf_Shdr *sechdrs, | 1701 | static char *get_modinfo(Elf_Shdr *sechdrs, |
1705 | unsigned int info, | 1702 | unsigned int info, |
1706 | const char *tag) | 1703 | const char *tag) |
1707 | { | 1704 | { |
1708 | char *p; | 1705 | char *p; |
1709 | unsigned int taglen = strlen(tag); | 1706 | unsigned int taglen = strlen(tag); |
1710 | unsigned long size = sechdrs[info].sh_size; | 1707 | unsigned long size = sechdrs[info].sh_size; |
1711 | 1708 | ||
1712 | for (p = (char *)sechdrs[info].sh_addr; p; p = next_string(p, &size)) { | 1709 | for (p = (char *)sechdrs[info].sh_addr; p; p = next_string(p, &size)) { |
1713 | if (strncmp(p, tag, taglen) == 0 && p[taglen] == '=') | 1710 | if (strncmp(p, tag, taglen) == 0 && p[taglen] == '=') |
1714 | return p + taglen + 1; | 1711 | return p + taglen + 1; |
1715 | } | 1712 | } |
1716 | return NULL; | 1713 | return NULL; |
1717 | } | 1714 | } |
1718 | 1715 | ||
1719 | static void setup_modinfo(struct module *mod, Elf_Shdr *sechdrs, | 1716 | static void setup_modinfo(struct module *mod, Elf_Shdr *sechdrs, |
1720 | unsigned int infoindex) | 1717 | unsigned int infoindex) |
1721 | { | 1718 | { |
1722 | struct module_attribute *attr; | 1719 | struct module_attribute *attr; |
1723 | int i; | 1720 | int i; |
1724 | 1721 | ||
1725 | for (i = 0; (attr = modinfo_attrs[i]); i++) { | 1722 | for (i = 0; (attr = modinfo_attrs[i]); i++) { |
1726 | if (attr->setup) | 1723 | if (attr->setup) |
1727 | attr->setup(mod, | 1724 | attr->setup(mod, |
1728 | get_modinfo(sechdrs, | 1725 | get_modinfo(sechdrs, |
1729 | infoindex, | 1726 | infoindex, |
1730 | attr->attr.name)); | 1727 | attr->attr.name)); |
1731 | } | 1728 | } |
1732 | } | 1729 | } |
1733 | 1730 | ||
1734 | #ifdef CONFIG_KALLSYMS | 1731 | #ifdef CONFIG_KALLSYMS |
1735 | 1732 | ||
1736 | /* lookup symbol in given range of kernel_symbols */ | 1733 | /* lookup symbol in given range of kernel_symbols */ |
1737 | static const struct kernel_symbol *lookup_symbol(const char *name, | 1734 | static const struct kernel_symbol *lookup_symbol(const char *name, |
1738 | const struct kernel_symbol *start, | 1735 | const struct kernel_symbol *start, |
1739 | const struct kernel_symbol *stop) | 1736 | const struct kernel_symbol *stop) |
1740 | { | 1737 | { |
1741 | const struct kernel_symbol *ks = start; | 1738 | const struct kernel_symbol *ks = start; |
1742 | for (; ks < stop; ks++) | 1739 | for (; ks < stop; ks++) |
1743 | if (strcmp(ks->name, name) == 0) | 1740 | if (strcmp(ks->name, name) == 0) |
1744 | return ks; | 1741 | return ks; |
1745 | return NULL; | 1742 | return NULL; |
1746 | } | 1743 | } |
1747 | 1744 | ||
1748 | static int is_exported(const char *name, unsigned long value, | 1745 | static int is_exported(const char *name, unsigned long value, |
1749 | const struct module *mod) | 1746 | const struct module *mod) |
1750 | { | 1747 | { |
1751 | const struct kernel_symbol *ks; | 1748 | const struct kernel_symbol *ks; |
1752 | if (!mod) | 1749 | if (!mod) |
1753 | ks = lookup_symbol(name, __start___ksymtab, __stop___ksymtab); | 1750 | ks = lookup_symbol(name, __start___ksymtab, __stop___ksymtab); |
1754 | else | 1751 | else |
1755 | ks = lookup_symbol(name, mod->syms, mod->syms + mod->num_syms); | 1752 | ks = lookup_symbol(name, mod->syms, mod->syms + mod->num_syms); |
1756 | return ks != NULL && ks->value == value; | 1753 | return ks != NULL && ks->value == value; |
1757 | } | 1754 | } |
1758 | 1755 | ||
1759 | /* As per nm */ | 1756 | /* As per nm */ |
1760 | static char elf_type(const Elf_Sym *sym, | 1757 | static char elf_type(const Elf_Sym *sym, |
1761 | Elf_Shdr *sechdrs, | 1758 | Elf_Shdr *sechdrs, |
1762 | const char *secstrings, | 1759 | const char *secstrings, |
1763 | struct module *mod) | 1760 | struct module *mod) |
1764 | { | 1761 | { |
1765 | if (ELF_ST_BIND(sym->st_info) == STB_WEAK) { | 1762 | if (ELF_ST_BIND(sym->st_info) == STB_WEAK) { |
1766 | if (ELF_ST_TYPE(sym->st_info) == STT_OBJECT) | 1763 | if (ELF_ST_TYPE(sym->st_info) == STT_OBJECT) |
1767 | return 'v'; | 1764 | return 'v'; |
1768 | else | 1765 | else |
1769 | return 'w'; | 1766 | return 'w'; |
1770 | } | 1767 | } |
1771 | if (sym->st_shndx == SHN_UNDEF) | 1768 | if (sym->st_shndx == SHN_UNDEF) |
1772 | return 'U'; | 1769 | return 'U'; |
1773 | if (sym->st_shndx == SHN_ABS) | 1770 | if (sym->st_shndx == SHN_ABS) |
1774 | return 'a'; | 1771 | return 'a'; |
1775 | if (sym->st_shndx >= SHN_LORESERVE) | 1772 | if (sym->st_shndx >= SHN_LORESERVE) |
1776 | return '?'; | 1773 | return '?'; |
1777 | if (sechdrs[sym->st_shndx].sh_flags & SHF_EXECINSTR) | 1774 | if (sechdrs[sym->st_shndx].sh_flags & SHF_EXECINSTR) |
1778 | return 't'; | 1775 | return 't'; |
1779 | if (sechdrs[sym->st_shndx].sh_flags & SHF_ALLOC | 1776 | if (sechdrs[sym->st_shndx].sh_flags & SHF_ALLOC |
1780 | && sechdrs[sym->st_shndx].sh_type != SHT_NOBITS) { | 1777 | && sechdrs[sym->st_shndx].sh_type != SHT_NOBITS) { |
1781 | if (!(sechdrs[sym->st_shndx].sh_flags & SHF_WRITE)) | 1778 | if (!(sechdrs[sym->st_shndx].sh_flags & SHF_WRITE)) |
1782 | return 'r'; | 1779 | return 'r'; |
1783 | else if (sechdrs[sym->st_shndx].sh_flags & ARCH_SHF_SMALL) | 1780 | else if (sechdrs[sym->st_shndx].sh_flags & ARCH_SHF_SMALL) |
1784 | return 'g'; | 1781 | return 'g'; |
1785 | else | 1782 | else |
1786 | return 'd'; | 1783 | return 'd'; |
1787 | } | 1784 | } |
1788 | if (sechdrs[sym->st_shndx].sh_type == SHT_NOBITS) { | 1785 | if (sechdrs[sym->st_shndx].sh_type == SHT_NOBITS) { |
1789 | if (sechdrs[sym->st_shndx].sh_flags & ARCH_SHF_SMALL) | 1786 | if (sechdrs[sym->st_shndx].sh_flags & ARCH_SHF_SMALL) |
1790 | return 's'; | 1787 | return 's'; |
1791 | else | 1788 | else |
1792 | return 'b'; | 1789 | return 'b'; |
1793 | } | 1790 | } |
1794 | if (strncmp(secstrings + sechdrs[sym->st_shndx].sh_name, | 1791 | if (strncmp(secstrings + sechdrs[sym->st_shndx].sh_name, |
1795 | ".debug", strlen(".debug")) == 0) | 1792 | ".debug", strlen(".debug")) == 0) |
1796 | return 'n'; | 1793 | return 'n'; |
1797 | return '?'; | 1794 | return '?'; |
1798 | } | 1795 | } |
1799 | 1796 | ||
1800 | static void add_kallsyms(struct module *mod, | 1797 | static void add_kallsyms(struct module *mod, |
1801 | Elf_Shdr *sechdrs, | 1798 | Elf_Shdr *sechdrs, |
1802 | unsigned int symindex, | 1799 | unsigned int symindex, |
1803 | unsigned int strindex, | 1800 | unsigned int strindex, |
1804 | const char *secstrings) | 1801 | const char *secstrings) |
1805 | { | 1802 | { |
1806 | unsigned int i; | 1803 | unsigned int i; |
1807 | 1804 | ||
1808 | mod->symtab = (void *)sechdrs[symindex].sh_addr; | 1805 | mod->symtab = (void *)sechdrs[symindex].sh_addr; |
1809 | mod->num_symtab = sechdrs[symindex].sh_size / sizeof(Elf_Sym); | 1806 | mod->num_symtab = sechdrs[symindex].sh_size / sizeof(Elf_Sym); |
1810 | mod->strtab = (void *)sechdrs[strindex].sh_addr; | 1807 | mod->strtab = (void *)sechdrs[strindex].sh_addr; |
1811 | 1808 | ||
1812 | /* Set types up while we still have access to sections. */ | 1809 | /* Set types up while we still have access to sections. */ |
1813 | for (i = 0; i < mod->num_symtab; i++) | 1810 | for (i = 0; i < mod->num_symtab; i++) |
1814 | mod->symtab[i].st_info | 1811 | mod->symtab[i].st_info |
1815 | = elf_type(&mod->symtab[i], sechdrs, secstrings, mod); | 1812 | = elf_type(&mod->symtab[i], sechdrs, secstrings, mod); |
1816 | } | 1813 | } |
1817 | #else | 1814 | #else |
1818 | static inline void add_kallsyms(struct module *mod, | 1815 | static inline void add_kallsyms(struct module *mod, |
1819 | Elf_Shdr *sechdrs, | 1816 | Elf_Shdr *sechdrs, |
1820 | unsigned int symindex, | 1817 | unsigned int symindex, |
1821 | unsigned int strindex, | 1818 | unsigned int strindex, |
1822 | const char *secstrings) | 1819 | const char *secstrings) |
1823 | { | 1820 | { |
1824 | } | 1821 | } |
1825 | #endif /* CONFIG_KALLSYMS */ | 1822 | #endif /* CONFIG_KALLSYMS */ |
1826 | 1823 | ||
1827 | static void dynamic_printk_setup(struct mod_debug *debug, unsigned int num) | 1824 | static void dynamic_printk_setup(struct mod_debug *debug, unsigned int num) |
1828 | { | 1825 | { |
1829 | #ifdef CONFIG_DYNAMIC_PRINTK_DEBUG | 1826 | #ifdef CONFIG_DYNAMIC_PRINTK_DEBUG |
1830 | unsigned int i; | 1827 | unsigned int i; |
1831 | 1828 | ||
1832 | for (i = 0; i < num; i++) { | 1829 | for (i = 0; i < num; i++) { |
1833 | register_dynamic_debug_module(debug[i].modname, | 1830 | register_dynamic_debug_module(debug[i].modname, |
1834 | debug[i].type, | 1831 | debug[i].type, |
1835 | debug[i].logical_modname, | 1832 | debug[i].logical_modname, |
1836 | debug[i].flag_names, | 1833 | debug[i].flag_names, |
1837 | debug[i].hash, debug[i].hash2); | 1834 | debug[i].hash, debug[i].hash2); |
1838 | } | 1835 | } |
1839 | #endif /* CONFIG_DYNAMIC_PRINTK_DEBUG */ | 1836 | #endif /* CONFIG_DYNAMIC_PRINTK_DEBUG */ |
1840 | } | 1837 | } |
1841 | 1838 | ||
1842 | static void *module_alloc_update_bounds(unsigned long size) | 1839 | static void *module_alloc_update_bounds(unsigned long size) |
1843 | { | 1840 | { |
1844 | void *ret = module_alloc(size); | 1841 | void *ret = module_alloc(size); |
1845 | 1842 | ||
1846 | if (ret) { | 1843 | if (ret) { |
1847 | /* Update module bounds. */ | 1844 | /* Update module bounds. */ |
1848 | if ((unsigned long)ret < module_addr_min) | 1845 | if ((unsigned long)ret < module_addr_min) |
1849 | module_addr_min = (unsigned long)ret; | 1846 | module_addr_min = (unsigned long)ret; |
1850 | if ((unsigned long)ret + size > module_addr_max) | 1847 | if ((unsigned long)ret + size > module_addr_max) |
1851 | module_addr_max = (unsigned long)ret + size; | 1848 | module_addr_max = (unsigned long)ret + size; |
1852 | } | 1849 | } |
1853 | return ret; | 1850 | return ret; |
1854 | } | 1851 | } |
1855 | 1852 | ||
1856 | /* Allocate and load the module: note that size of section 0 is always | 1853 | /* Allocate and load the module: note that size of section 0 is always |
1857 | zero, and we rely on this for optional sections. */ | 1854 | zero, and we rely on this for optional sections. */ |
1858 | static noinline struct module *load_module(void __user *umod, | 1855 | static noinline struct module *load_module(void __user *umod, |
1859 | unsigned long len, | 1856 | unsigned long len, |
1860 | const char __user *uargs) | 1857 | const char __user *uargs) |
1861 | { | 1858 | { |
1862 | Elf_Ehdr *hdr; | 1859 | Elf_Ehdr *hdr; |
1863 | Elf_Shdr *sechdrs; | 1860 | Elf_Shdr *sechdrs; |
1864 | char *secstrings, *args, *modmagic, *strtab = NULL; | 1861 | char *secstrings, *args, *modmagic, *strtab = NULL; |
1865 | char *staging; | 1862 | char *staging; |
1866 | unsigned int i; | 1863 | unsigned int i; |
1867 | unsigned int symindex = 0; | 1864 | unsigned int symindex = 0; |
1868 | unsigned int strindex = 0; | 1865 | unsigned int strindex = 0; |
1869 | unsigned int modindex, versindex, infoindex, pcpuindex; | 1866 | unsigned int modindex, versindex, infoindex, pcpuindex; |
1870 | unsigned int unwindex = 0; | ||
1871 | unsigned int num_kp, num_mcount; | 1867 | unsigned int num_kp, num_mcount; |
1872 | struct kernel_param *kp; | 1868 | struct kernel_param *kp; |
1873 | struct module *mod; | 1869 | struct module *mod; |
1874 | long err = 0; | 1870 | long err = 0; |
1875 | void *percpu = NULL, *ptr = NULL; /* Stops spurious gcc warning */ | 1871 | void *percpu = NULL, *ptr = NULL; /* Stops spurious gcc warning */ |
1876 | unsigned long *mseg; | 1872 | unsigned long *mseg; |
1877 | mm_segment_t old_fs; | 1873 | mm_segment_t old_fs; |
1878 | 1874 | ||
1879 | DEBUGP("load_module: umod=%p, len=%lu, uargs=%p\n", | 1875 | DEBUGP("load_module: umod=%p, len=%lu, uargs=%p\n", |
1880 | umod, len, uargs); | 1876 | umod, len, uargs); |
1881 | if (len < sizeof(*hdr)) | 1877 | if (len < sizeof(*hdr)) |
1882 | return ERR_PTR(-ENOEXEC); | 1878 | return ERR_PTR(-ENOEXEC); |
1883 | 1879 | ||
1884 | /* Suck in entire file: we'll want most of it. */ | 1880 | /* Suck in entire file: we'll want most of it. */ |
1885 | /* vmalloc barfs on "unusual" numbers. Check here */ | 1881 | /* vmalloc barfs on "unusual" numbers. Check here */ |
1886 | if (len > 64 * 1024 * 1024 || (hdr = vmalloc(len)) == NULL) | 1882 | if (len > 64 * 1024 * 1024 || (hdr = vmalloc(len)) == NULL) |
1887 | return ERR_PTR(-ENOMEM); | 1883 | return ERR_PTR(-ENOMEM); |
1888 | 1884 | ||
1889 | /* Create stop_machine threads since the error path relies on | 1885 | /* Create stop_machine threads since the error path relies on |
1890 | * a non-failing stop_machine call. */ | 1886 | * a non-failing stop_machine call. */ |
1891 | err = stop_machine_create(); | 1887 | err = stop_machine_create(); |
1892 | if (err) | 1888 | if (err) |
1893 | goto free_hdr; | 1889 | goto free_hdr; |
1894 | 1890 | ||
1895 | if (copy_from_user(hdr, umod, len) != 0) { | 1891 | if (copy_from_user(hdr, umod, len) != 0) { |
1896 | err = -EFAULT; | 1892 | err = -EFAULT; |
1897 | goto free_hdr; | 1893 | goto free_hdr; |
1898 | } | 1894 | } |
1899 | 1895 | ||
1900 | /* Sanity checks against insmoding binaries or wrong arch, | 1896 | /* Sanity checks against insmoding binaries or wrong arch, |
1901 | weird elf version */ | 1897 | weird elf version */ |
1902 | if (memcmp(hdr->e_ident, ELFMAG, SELFMAG) != 0 | 1898 | if (memcmp(hdr->e_ident, ELFMAG, SELFMAG) != 0 |
1903 | || hdr->e_type != ET_REL | 1899 | || hdr->e_type != ET_REL |
1904 | || !elf_check_arch(hdr) | 1900 | || !elf_check_arch(hdr) |
1905 | || hdr->e_shentsize != sizeof(*sechdrs)) { | 1901 | || hdr->e_shentsize != sizeof(*sechdrs)) { |
1906 | err = -ENOEXEC; | 1902 | err = -ENOEXEC; |
1907 | goto free_hdr; | 1903 | goto free_hdr; |
1908 | } | 1904 | } |
1909 | 1905 | ||
1910 | if (len < hdr->e_shoff + hdr->e_shnum * sizeof(Elf_Shdr)) | 1906 | if (len < hdr->e_shoff + hdr->e_shnum * sizeof(Elf_Shdr)) |
1911 | goto truncated; | 1907 | goto truncated; |
1912 | 1908 | ||
1913 | /* Convenience variables */ | 1909 | /* Convenience variables */ |
1914 | sechdrs = (void *)hdr + hdr->e_shoff; | 1910 | sechdrs = (void *)hdr + hdr->e_shoff; |
1915 | secstrings = (void *)hdr + sechdrs[hdr->e_shstrndx].sh_offset; | 1911 | secstrings = (void *)hdr + sechdrs[hdr->e_shstrndx].sh_offset; |
1916 | sechdrs[0].sh_addr = 0; | 1912 | sechdrs[0].sh_addr = 0; |
1917 | 1913 | ||
1918 | for (i = 1; i < hdr->e_shnum; i++) { | 1914 | for (i = 1; i < hdr->e_shnum; i++) { |
1919 | if (sechdrs[i].sh_type != SHT_NOBITS | 1915 | if (sechdrs[i].sh_type != SHT_NOBITS |
1920 | && len < sechdrs[i].sh_offset + sechdrs[i].sh_size) | 1916 | && len < sechdrs[i].sh_offset + sechdrs[i].sh_size) |
1921 | goto truncated; | 1917 | goto truncated; |
1922 | 1918 | ||
1923 | /* Mark all sections sh_addr with their address in the | 1919 | /* Mark all sections sh_addr with their address in the |
1924 | temporary image. */ | 1920 | temporary image. */ |
1925 | sechdrs[i].sh_addr = (size_t)hdr + sechdrs[i].sh_offset; | 1921 | sechdrs[i].sh_addr = (size_t)hdr + sechdrs[i].sh_offset; |
1926 | 1922 | ||
1927 | /* Internal symbols and strings. */ | 1923 | /* Internal symbols and strings. */ |
1928 | if (sechdrs[i].sh_type == SHT_SYMTAB) { | 1924 | if (sechdrs[i].sh_type == SHT_SYMTAB) { |
1929 | symindex = i; | 1925 | symindex = i; |
1930 | strindex = sechdrs[i].sh_link; | 1926 | strindex = sechdrs[i].sh_link; |
1931 | strtab = (char *)hdr + sechdrs[strindex].sh_offset; | 1927 | strtab = (char *)hdr + sechdrs[strindex].sh_offset; |
1932 | } | 1928 | } |
1933 | #ifndef CONFIG_MODULE_UNLOAD | 1929 | #ifndef CONFIG_MODULE_UNLOAD |
1934 | /* Don't load .exit sections */ | 1930 | /* Don't load .exit sections */ |
1935 | if (strncmp(secstrings+sechdrs[i].sh_name, ".exit", 5) == 0) | 1931 | if (strncmp(secstrings+sechdrs[i].sh_name, ".exit", 5) == 0) |
1936 | sechdrs[i].sh_flags &= ~(unsigned long)SHF_ALLOC; | 1932 | sechdrs[i].sh_flags &= ~(unsigned long)SHF_ALLOC; |
1937 | #endif | 1933 | #endif |
1938 | } | 1934 | } |
1939 | 1935 | ||
1940 | modindex = find_sec(hdr, sechdrs, secstrings, | 1936 | modindex = find_sec(hdr, sechdrs, secstrings, |
1941 | ".gnu.linkonce.this_module"); | 1937 | ".gnu.linkonce.this_module"); |
1942 | if (!modindex) { | 1938 | if (!modindex) { |
1943 | printk(KERN_WARNING "No module found in object\n"); | 1939 | printk(KERN_WARNING "No module found in object\n"); |
1944 | err = -ENOEXEC; | 1940 | err = -ENOEXEC; |
1945 | goto free_hdr; | 1941 | goto free_hdr; |
1946 | } | 1942 | } |
1947 | /* This is temporary: point mod into copy of data. */ | 1943 | /* This is temporary: point mod into copy of data. */ |
1948 | mod = (void *)sechdrs[modindex].sh_addr; | 1944 | mod = (void *)sechdrs[modindex].sh_addr; |
1949 | 1945 | ||
1950 | if (symindex == 0) { | 1946 | if (symindex == 0) { |
1951 | printk(KERN_WARNING "%s: module has no symbols (stripped?)\n", | 1947 | printk(KERN_WARNING "%s: module has no symbols (stripped?)\n", |
1952 | mod->name); | 1948 | mod->name); |
1953 | err = -ENOEXEC; | 1949 | err = -ENOEXEC; |
1954 | goto free_hdr; | 1950 | goto free_hdr; |
1955 | } | 1951 | } |
1956 | 1952 | ||
1957 | versindex = find_sec(hdr, sechdrs, secstrings, "__versions"); | 1953 | versindex = find_sec(hdr, sechdrs, secstrings, "__versions"); |
1958 | infoindex = find_sec(hdr, sechdrs, secstrings, ".modinfo"); | 1954 | infoindex = find_sec(hdr, sechdrs, secstrings, ".modinfo"); |
1959 | pcpuindex = find_pcpusec(hdr, sechdrs, secstrings); | 1955 | pcpuindex = find_pcpusec(hdr, sechdrs, secstrings); |
1960 | #ifdef ARCH_UNWIND_SECTION_NAME | ||
1961 | unwindex = find_sec(hdr, sechdrs, secstrings, ARCH_UNWIND_SECTION_NAME); | ||
1962 | #endif | ||
1963 | 1956 | ||
1964 | /* Don't keep modinfo and version sections. */ | 1957 | /* Don't keep modinfo and version sections. */ |
1965 | sechdrs[infoindex].sh_flags &= ~(unsigned long)SHF_ALLOC; | 1958 | sechdrs[infoindex].sh_flags &= ~(unsigned long)SHF_ALLOC; |
1966 | sechdrs[versindex].sh_flags &= ~(unsigned long)SHF_ALLOC; | 1959 | sechdrs[versindex].sh_flags &= ~(unsigned long)SHF_ALLOC; |
1967 | #ifdef CONFIG_KALLSYMS | 1960 | #ifdef CONFIG_KALLSYMS |
1968 | /* Keep symbol and string tables for decoding later. */ | 1961 | /* Keep symbol and string tables for decoding later. */ |
1969 | sechdrs[symindex].sh_flags |= SHF_ALLOC; | 1962 | sechdrs[symindex].sh_flags |= SHF_ALLOC; |
1970 | sechdrs[strindex].sh_flags |= SHF_ALLOC; | 1963 | sechdrs[strindex].sh_flags |= SHF_ALLOC; |
1971 | #endif | 1964 | #endif |
1972 | if (unwindex) | ||
1973 | sechdrs[unwindex].sh_flags |= SHF_ALLOC; | ||
1974 | 1965 | ||
1975 | /* Check module struct version now, before we try to use module. */ | 1966 | /* Check module struct version now, before we try to use module. */ |
1976 | if (!check_modstruct_version(sechdrs, versindex, mod)) { | 1967 | if (!check_modstruct_version(sechdrs, versindex, mod)) { |
1977 | err = -ENOEXEC; | 1968 | err = -ENOEXEC; |
1978 | goto free_hdr; | 1969 | goto free_hdr; |
1979 | } | 1970 | } |
1980 | 1971 | ||
1981 | modmagic = get_modinfo(sechdrs, infoindex, "vermagic"); | 1972 | modmagic = get_modinfo(sechdrs, infoindex, "vermagic"); |
1982 | /* This is allowed: modprobe --force will invalidate it. */ | 1973 | /* This is allowed: modprobe --force will invalidate it. */ |
1983 | if (!modmagic) { | 1974 | if (!modmagic) { |
1984 | err = try_to_force_load(mod, "magic"); | 1975 | err = try_to_force_load(mod, "magic"); |
1985 | if (err) | 1976 | if (err) |
1986 | goto free_hdr; | 1977 | goto free_hdr; |
1987 | } else if (!same_magic(modmagic, vermagic, versindex)) { | 1978 | } else if (!same_magic(modmagic, vermagic, versindex)) { |
1988 | printk(KERN_ERR "%s: version magic '%s' should be '%s'\n", | 1979 | printk(KERN_ERR "%s: version magic '%s' should be '%s'\n", |
1989 | mod->name, modmagic, vermagic); | 1980 | mod->name, modmagic, vermagic); |
1990 | err = -ENOEXEC; | 1981 | err = -ENOEXEC; |
1991 | goto free_hdr; | 1982 | goto free_hdr; |
1992 | } | 1983 | } |
1993 | 1984 | ||
1994 | staging = get_modinfo(sechdrs, infoindex, "staging"); | 1985 | staging = get_modinfo(sechdrs, infoindex, "staging"); |
1995 | if (staging) { | 1986 | if (staging) { |
1996 | add_taint_module(mod, TAINT_CRAP); | 1987 | add_taint_module(mod, TAINT_CRAP); |
1997 | printk(KERN_WARNING "%s: module is from the staging directory," | 1988 | printk(KERN_WARNING "%s: module is from the staging directory," |
1998 | " the quality is unknown, you have been warned.\n", | 1989 | " the quality is unknown, you have been warned.\n", |
1999 | mod->name); | 1990 | mod->name); |
2000 | } | 1991 | } |
2001 | 1992 | ||
2002 | /* Now copy in args */ | 1993 | /* Now copy in args */ |
2003 | args = strndup_user(uargs, ~0UL >> 1); | 1994 | args = strndup_user(uargs, ~0UL >> 1); |
2004 | if (IS_ERR(args)) { | 1995 | if (IS_ERR(args)) { |
2005 | err = PTR_ERR(args); | 1996 | err = PTR_ERR(args); |
2006 | goto free_hdr; | 1997 | goto free_hdr; |
2007 | } | 1998 | } |
2008 | 1999 | ||
2009 | if (find_module(mod->name)) { | 2000 | if (find_module(mod->name)) { |
2010 | err = -EEXIST; | 2001 | err = -EEXIST; |
2011 | goto free_mod; | 2002 | goto free_mod; |
2012 | } | 2003 | } |
2013 | 2004 | ||
2014 | mod->state = MODULE_STATE_COMING; | 2005 | mod->state = MODULE_STATE_COMING; |
2015 | 2006 | ||
2016 | /* Allow arches to frob section contents and sizes. */ | 2007 | /* Allow arches to frob section contents and sizes. */ |
2017 | err = module_frob_arch_sections(hdr, sechdrs, secstrings, mod); | 2008 | err = module_frob_arch_sections(hdr, sechdrs, secstrings, mod); |
2018 | if (err < 0) | 2009 | if (err < 0) |
2019 | goto free_mod; | 2010 | goto free_mod; |
2020 | 2011 | ||
2021 | if (pcpuindex) { | 2012 | if (pcpuindex) { |
2022 | /* We have a special allocation for this section. */ | 2013 | /* We have a special allocation for this section. */ |
2023 | percpu = percpu_modalloc(sechdrs[pcpuindex].sh_size, | 2014 | percpu = percpu_modalloc(sechdrs[pcpuindex].sh_size, |
2024 | sechdrs[pcpuindex].sh_addralign, | 2015 | sechdrs[pcpuindex].sh_addralign, |
2025 | mod->name); | 2016 | mod->name); |
2026 | if (!percpu) { | 2017 | if (!percpu) { |
2027 | err = -ENOMEM; | 2018 | err = -ENOMEM; |
2028 | goto free_mod; | 2019 | goto free_mod; |
2029 | } | 2020 | } |
2030 | sechdrs[pcpuindex].sh_flags &= ~(unsigned long)SHF_ALLOC; | 2021 | sechdrs[pcpuindex].sh_flags &= ~(unsigned long)SHF_ALLOC; |
2031 | mod->percpu = percpu; | 2022 | mod->percpu = percpu; |
2032 | } | 2023 | } |
2033 | 2024 | ||
2034 | /* Determine total sizes, and put offsets in sh_entsize. For now | 2025 | /* Determine total sizes, and put offsets in sh_entsize. For now |
2035 | this is done generically; there doesn't appear to be any | 2026 | this is done generically; there doesn't appear to be any |
2036 | special cases for the architectures. */ | 2027 | special cases for the architectures. */ |
2037 | layout_sections(mod, hdr, sechdrs, secstrings); | 2028 | layout_sections(mod, hdr, sechdrs, secstrings); |
2038 | 2029 | ||
2039 | /* Do the allocs. */ | 2030 | /* Do the allocs. */ |
2040 | ptr = module_alloc_update_bounds(mod->core_size); | 2031 | ptr = module_alloc_update_bounds(mod->core_size); |
2041 | if (!ptr) { | 2032 | if (!ptr) { |
2042 | err = -ENOMEM; | 2033 | err = -ENOMEM; |
2043 | goto free_percpu; | 2034 | goto free_percpu; |
2044 | } | 2035 | } |
2045 | memset(ptr, 0, mod->core_size); | 2036 | memset(ptr, 0, mod->core_size); |
2046 | mod->module_core = ptr; | 2037 | mod->module_core = ptr; |
2047 | 2038 | ||
2048 | ptr = module_alloc_update_bounds(mod->init_size); | 2039 | ptr = module_alloc_update_bounds(mod->init_size); |
2049 | if (!ptr && mod->init_size) { | 2040 | if (!ptr && mod->init_size) { |
2050 | err = -ENOMEM; | 2041 | err = -ENOMEM; |
2051 | goto free_core; | 2042 | goto free_core; |
2052 | } | 2043 | } |
2053 | memset(ptr, 0, mod->init_size); | 2044 | memset(ptr, 0, mod->init_size); |
2054 | mod->module_init = ptr; | 2045 | mod->module_init = ptr; |
2055 | 2046 | ||
2056 | /* Transfer each section which specifies SHF_ALLOC */ | 2047 | /* Transfer each section which specifies SHF_ALLOC */ |
2057 | DEBUGP("final section addresses:\n"); | 2048 | DEBUGP("final section addresses:\n"); |
2058 | for (i = 0; i < hdr->e_shnum; i++) { | 2049 | for (i = 0; i < hdr->e_shnum; i++) { |
2059 | void *dest; | 2050 | void *dest; |
2060 | 2051 | ||
2061 | if (!(sechdrs[i].sh_flags & SHF_ALLOC)) | 2052 | if (!(sechdrs[i].sh_flags & SHF_ALLOC)) |
2062 | continue; | 2053 | continue; |
2063 | 2054 | ||
2064 | if (sechdrs[i].sh_entsize & INIT_OFFSET_MASK) | 2055 | if (sechdrs[i].sh_entsize & INIT_OFFSET_MASK) |
2065 | dest = mod->module_init | 2056 | dest = mod->module_init |
2066 | + (sechdrs[i].sh_entsize & ~INIT_OFFSET_MASK); | 2057 | + (sechdrs[i].sh_entsize & ~INIT_OFFSET_MASK); |
2067 | else | 2058 | else |
2068 | dest = mod->module_core + sechdrs[i].sh_entsize; | 2059 | dest = mod->module_core + sechdrs[i].sh_entsize; |
2069 | 2060 | ||
2070 | if (sechdrs[i].sh_type != SHT_NOBITS) | 2061 | if (sechdrs[i].sh_type != SHT_NOBITS) |
2071 | memcpy(dest, (void *)sechdrs[i].sh_addr, | 2062 | memcpy(dest, (void *)sechdrs[i].sh_addr, |
2072 | sechdrs[i].sh_size); | 2063 | sechdrs[i].sh_size); |
2073 | /* Update sh_addr to point to copy in image. */ | 2064 | /* Update sh_addr to point to copy in image. */ |
2074 | sechdrs[i].sh_addr = (unsigned long)dest; | 2065 | sechdrs[i].sh_addr = (unsigned long)dest; |
2075 | DEBUGP("\t0x%lx %s\n", sechdrs[i].sh_addr, secstrings + sechdrs[i].sh_name); | 2066 | DEBUGP("\t0x%lx %s\n", sechdrs[i].sh_addr, secstrings + sechdrs[i].sh_name); |
2076 | } | 2067 | } |
2077 | /* Module has been moved. */ | 2068 | /* Module has been moved. */ |
2078 | mod = (void *)sechdrs[modindex].sh_addr; | 2069 | mod = (void *)sechdrs[modindex].sh_addr; |
2079 | 2070 | ||
2080 | /* Now we've moved module, initialize linked lists, etc. */ | 2071 | /* Now we've moved module, initialize linked lists, etc. */ |
2081 | module_unload_init(mod); | 2072 | module_unload_init(mod); |
2082 | 2073 | ||
2083 | /* add kobject, so we can reference it. */ | 2074 | /* add kobject, so we can reference it. */ |
2084 | err = mod_sysfs_init(mod); | 2075 | err = mod_sysfs_init(mod); |
2085 | if (err) | 2076 | if (err) |
2086 | goto free_unload; | 2077 | goto free_unload; |
2087 | 2078 | ||
2088 | /* Set up license info based on the info section */ | 2079 | /* Set up license info based on the info section */ |
2089 | set_license(mod, get_modinfo(sechdrs, infoindex, "license")); | 2080 | set_license(mod, get_modinfo(sechdrs, infoindex, "license")); |
2090 | 2081 | ||
2091 | /* | 2082 | /* |
2092 | * ndiswrapper is under GPL by itself, but loads proprietary modules. | 2083 | * ndiswrapper is under GPL by itself, but loads proprietary modules. |
2093 | * Don't use add_taint_module(), as it would prevent ndiswrapper from | 2084 | * Don't use add_taint_module(), as it would prevent ndiswrapper from |
2094 | * using GPL-only symbols it needs. | 2085 | * using GPL-only symbols it needs. |
2095 | */ | 2086 | */ |
2096 | if (strcmp(mod->name, "ndiswrapper") == 0) | 2087 | if (strcmp(mod->name, "ndiswrapper") == 0) |
2097 | add_taint(TAINT_PROPRIETARY_MODULE); | 2088 | add_taint(TAINT_PROPRIETARY_MODULE); |
2098 | 2089 | ||
2099 | /* driverloader was caught wrongly pretending to be under GPL */ | 2090 | /* driverloader was caught wrongly pretending to be under GPL */ |
2100 | if (strcmp(mod->name, "driverloader") == 0) | 2091 | if (strcmp(mod->name, "driverloader") == 0) |
2101 | add_taint_module(mod, TAINT_PROPRIETARY_MODULE); | 2092 | add_taint_module(mod, TAINT_PROPRIETARY_MODULE); |
2102 | 2093 | ||
2103 | /* Set up MODINFO_ATTR fields */ | 2094 | /* Set up MODINFO_ATTR fields */ |
2104 | setup_modinfo(mod, sechdrs, infoindex); | 2095 | setup_modinfo(mod, sechdrs, infoindex); |
2105 | 2096 | ||
2106 | /* Fix up syms, so that st_value is a pointer to location. */ | 2097 | /* Fix up syms, so that st_value is a pointer to location. */ |
2107 | err = simplify_symbols(sechdrs, symindex, strtab, versindex, pcpuindex, | 2098 | err = simplify_symbols(sechdrs, symindex, strtab, versindex, pcpuindex, |
2108 | mod); | 2099 | mod); |
2109 | if (err < 0) | 2100 | if (err < 0) |
2110 | goto cleanup; | 2101 | goto cleanup; |
2111 | 2102 | ||
2112 | /* Now we've got everything in the final locations, we can | 2103 | /* Now we've got everything in the final locations, we can |
2113 | * find optional sections. */ | 2104 | * find optional sections. */ |
2114 | kp = section_objs(hdr, sechdrs, secstrings, "__param", sizeof(*kp), | 2105 | kp = section_objs(hdr, sechdrs, secstrings, "__param", sizeof(*kp), |
2115 | &num_kp); | 2106 | &num_kp); |
2116 | mod->syms = section_objs(hdr, sechdrs, secstrings, "__ksymtab", | 2107 | mod->syms = section_objs(hdr, sechdrs, secstrings, "__ksymtab", |
2117 | sizeof(*mod->syms), &mod->num_syms); | 2108 | sizeof(*mod->syms), &mod->num_syms); |
2118 | mod->crcs = section_addr(hdr, sechdrs, secstrings, "__kcrctab"); | 2109 | mod->crcs = section_addr(hdr, sechdrs, secstrings, "__kcrctab"); |
2119 | mod->gpl_syms = section_objs(hdr, sechdrs, secstrings, "__ksymtab_gpl", | 2110 | mod->gpl_syms = section_objs(hdr, sechdrs, secstrings, "__ksymtab_gpl", |
2120 | sizeof(*mod->gpl_syms), | 2111 | sizeof(*mod->gpl_syms), |
2121 | &mod->num_gpl_syms); | 2112 | &mod->num_gpl_syms); |
2122 | mod->gpl_crcs = section_addr(hdr, sechdrs, secstrings, "__kcrctab_gpl"); | 2113 | mod->gpl_crcs = section_addr(hdr, sechdrs, secstrings, "__kcrctab_gpl"); |
2123 | mod->gpl_future_syms = section_objs(hdr, sechdrs, secstrings, | 2114 | mod->gpl_future_syms = section_objs(hdr, sechdrs, secstrings, |
2124 | "__ksymtab_gpl_future", | 2115 | "__ksymtab_gpl_future", |
2125 | sizeof(*mod->gpl_future_syms), | 2116 | sizeof(*mod->gpl_future_syms), |
2126 | &mod->num_gpl_future_syms); | 2117 | &mod->num_gpl_future_syms); |
2127 | mod->gpl_future_crcs = section_addr(hdr, sechdrs, secstrings, | 2118 | mod->gpl_future_crcs = section_addr(hdr, sechdrs, secstrings, |
2128 | "__kcrctab_gpl_future"); | 2119 | "__kcrctab_gpl_future"); |
2129 | 2120 | ||
2130 | #ifdef CONFIG_UNUSED_SYMBOLS | 2121 | #ifdef CONFIG_UNUSED_SYMBOLS |
2131 | mod->unused_syms = section_objs(hdr, sechdrs, secstrings, | 2122 | mod->unused_syms = section_objs(hdr, sechdrs, secstrings, |
2132 | "__ksymtab_unused", | 2123 | "__ksymtab_unused", |
2133 | sizeof(*mod->unused_syms), | 2124 | sizeof(*mod->unused_syms), |
2134 | &mod->num_unused_syms); | 2125 | &mod->num_unused_syms); |
2135 | mod->unused_crcs = section_addr(hdr, sechdrs, secstrings, | 2126 | mod->unused_crcs = section_addr(hdr, sechdrs, secstrings, |
2136 | "__kcrctab_unused"); | 2127 | "__kcrctab_unused"); |
2137 | mod->unused_gpl_syms = section_objs(hdr, sechdrs, secstrings, | 2128 | mod->unused_gpl_syms = section_objs(hdr, sechdrs, secstrings, |
2138 | "__ksymtab_unused_gpl", | 2129 | "__ksymtab_unused_gpl", |
2139 | sizeof(*mod->unused_gpl_syms), | 2130 | sizeof(*mod->unused_gpl_syms), |
2140 | &mod->num_unused_gpl_syms); | 2131 | &mod->num_unused_gpl_syms); |
2141 | mod->unused_gpl_crcs = section_addr(hdr, sechdrs, secstrings, | 2132 | mod->unused_gpl_crcs = section_addr(hdr, sechdrs, secstrings, |
2142 | "__kcrctab_unused_gpl"); | 2133 | "__kcrctab_unused_gpl"); |
2143 | #endif | 2134 | #endif |
2144 | 2135 | ||
2145 | #ifdef CONFIG_MARKERS | 2136 | #ifdef CONFIG_MARKERS |
2146 | mod->markers = section_objs(hdr, sechdrs, secstrings, "__markers", | 2137 | mod->markers = section_objs(hdr, sechdrs, secstrings, "__markers", |
2147 | sizeof(*mod->markers), &mod->num_markers); | 2138 | sizeof(*mod->markers), &mod->num_markers); |
2148 | #endif | 2139 | #endif |
2149 | #ifdef CONFIG_TRACEPOINTS | 2140 | #ifdef CONFIG_TRACEPOINTS |
2150 | mod->tracepoints = section_objs(hdr, sechdrs, secstrings, | 2141 | mod->tracepoints = section_objs(hdr, sechdrs, secstrings, |
2151 | "__tracepoints", | 2142 | "__tracepoints", |
2152 | sizeof(*mod->tracepoints), | 2143 | sizeof(*mod->tracepoints), |
2153 | &mod->num_tracepoints); | 2144 | &mod->num_tracepoints); |
2154 | #endif | 2145 | #endif |
2155 | 2146 | ||
2156 | #ifdef CONFIG_MODVERSIONS | 2147 | #ifdef CONFIG_MODVERSIONS |
2157 | if ((mod->num_syms && !mod->crcs) | 2148 | if ((mod->num_syms && !mod->crcs) |
2158 | || (mod->num_gpl_syms && !mod->gpl_crcs) | 2149 | || (mod->num_gpl_syms && !mod->gpl_crcs) |
2159 | || (mod->num_gpl_future_syms && !mod->gpl_future_crcs) | 2150 | || (mod->num_gpl_future_syms && !mod->gpl_future_crcs) |
2160 | #ifdef CONFIG_UNUSED_SYMBOLS | 2151 | #ifdef CONFIG_UNUSED_SYMBOLS |
2161 | || (mod->num_unused_syms && !mod->unused_crcs) | 2152 | || (mod->num_unused_syms && !mod->unused_crcs) |
2162 | || (mod->num_unused_gpl_syms && !mod->unused_gpl_crcs) | 2153 | || (mod->num_unused_gpl_syms && !mod->unused_gpl_crcs) |
2163 | #endif | 2154 | #endif |
2164 | ) { | 2155 | ) { |
2165 | printk(KERN_WARNING "%s: No versions for exported symbols.\n", mod->name); | 2156 | printk(KERN_WARNING "%s: No versions for exported symbols.\n", mod->name); |
2166 | err = try_to_force_load(mod, "nocrc"); | 2157 | err = try_to_force_load(mod, "nocrc"); |
2167 | if (err) | 2158 | if (err) |
2168 | goto cleanup; | 2159 | goto cleanup; |
2169 | } | 2160 | } |
2170 | #endif | 2161 | #endif |
2171 | 2162 | ||
2172 | /* Now do relocations. */ | 2163 | /* Now do relocations. */ |
2173 | for (i = 1; i < hdr->e_shnum; i++) { | 2164 | for (i = 1; i < hdr->e_shnum; i++) { |
2174 | const char *strtab = (char *)sechdrs[strindex].sh_addr; | 2165 | const char *strtab = (char *)sechdrs[strindex].sh_addr; |
2175 | unsigned int info = sechdrs[i].sh_info; | 2166 | unsigned int info = sechdrs[i].sh_info; |
2176 | 2167 | ||
2177 | /* Not a valid relocation section? */ | 2168 | /* Not a valid relocation section? */ |
2178 | if (info >= hdr->e_shnum) | 2169 | if (info >= hdr->e_shnum) |
2179 | continue; | 2170 | continue; |
2180 | 2171 | ||
2181 | /* Don't bother with non-allocated sections */ | 2172 | /* Don't bother with non-allocated sections */ |
2182 | if (!(sechdrs[info].sh_flags & SHF_ALLOC)) | 2173 | if (!(sechdrs[info].sh_flags & SHF_ALLOC)) |
2183 | continue; | 2174 | continue; |
2184 | 2175 | ||
2185 | if (sechdrs[i].sh_type == SHT_REL) | 2176 | if (sechdrs[i].sh_type == SHT_REL) |
2186 | err = apply_relocate(sechdrs, strtab, symindex, i,mod); | 2177 | err = apply_relocate(sechdrs, strtab, symindex, i,mod); |
2187 | else if (sechdrs[i].sh_type == SHT_RELA) | 2178 | else if (sechdrs[i].sh_type == SHT_RELA) |
2188 | err = apply_relocate_add(sechdrs, strtab, symindex, i, | 2179 | err = apply_relocate_add(sechdrs, strtab, symindex, i, |
2189 | mod); | 2180 | mod); |
2190 | if (err < 0) | 2181 | if (err < 0) |
2191 | goto cleanup; | 2182 | goto cleanup; |
2192 | } | 2183 | } |
2193 | 2184 | ||
2194 | /* Find duplicate symbols */ | 2185 | /* Find duplicate symbols */ |
2195 | err = verify_export_symbols(mod); | 2186 | err = verify_export_symbols(mod); |
2196 | if (err < 0) | 2187 | if (err < 0) |
2197 | goto cleanup; | 2188 | goto cleanup; |
2198 | 2189 | ||
2199 | /* Set up and sort exception table */ | 2190 | /* Set up and sort exception table */ |
2200 | mod->extable = section_objs(hdr, sechdrs, secstrings, "__ex_table", | 2191 | mod->extable = section_objs(hdr, sechdrs, secstrings, "__ex_table", |
2201 | sizeof(*mod->extable), &mod->num_exentries); | 2192 | sizeof(*mod->extable), &mod->num_exentries); |
2202 | sort_extable(mod->extable, mod->extable + mod->num_exentries); | 2193 | sort_extable(mod->extable, mod->extable + mod->num_exentries); |
2203 | 2194 | ||
2204 | /* Finally, copy percpu area over. */ | 2195 | /* Finally, copy percpu area over. */ |
2205 | percpu_modcopy(mod->percpu, (void *)sechdrs[pcpuindex].sh_addr, | 2196 | percpu_modcopy(mod->percpu, (void *)sechdrs[pcpuindex].sh_addr, |
2206 | sechdrs[pcpuindex].sh_size); | 2197 | sechdrs[pcpuindex].sh_size); |
2207 | 2198 | ||
2208 | add_kallsyms(mod, sechdrs, symindex, strindex, secstrings); | 2199 | add_kallsyms(mod, sechdrs, symindex, strindex, secstrings); |
2209 | 2200 | ||
2210 | if (!mod->taints) { | 2201 | if (!mod->taints) { |
2211 | struct mod_debug *debug; | 2202 | struct mod_debug *debug; |
2212 | unsigned int num_debug; | 2203 | unsigned int num_debug; |
2213 | 2204 | ||
2214 | debug = section_objs(hdr, sechdrs, secstrings, "__verbose", | 2205 | debug = section_objs(hdr, sechdrs, secstrings, "__verbose", |
2215 | sizeof(*debug), &num_debug); | 2206 | sizeof(*debug), &num_debug); |
2216 | dynamic_printk_setup(debug, num_debug); | 2207 | dynamic_printk_setup(debug, num_debug); |
2217 | } | 2208 | } |
2218 | 2209 | ||
2219 | /* sechdrs[0].sh_size is always zero */ | 2210 | /* sechdrs[0].sh_size is always zero */ |
2220 | mseg = section_objs(hdr, sechdrs, secstrings, "__mcount_loc", | 2211 | mseg = section_objs(hdr, sechdrs, secstrings, "__mcount_loc", |
2221 | sizeof(*mseg), &num_mcount); | 2212 | sizeof(*mseg), &num_mcount); |
2222 | ftrace_init_module(mod, mseg, mseg + num_mcount); | 2213 | ftrace_init_module(mod, mseg, mseg + num_mcount); |
2223 | 2214 | ||
2224 | err = module_finalize(hdr, sechdrs, mod); | 2215 | err = module_finalize(hdr, sechdrs, mod); |
2225 | if (err < 0) | 2216 | if (err < 0) |
2226 | goto cleanup; | 2217 | goto cleanup; |
2227 | 2218 | ||
2228 | /* flush the icache in correct context */ | 2219 | /* flush the icache in correct context */ |
2229 | old_fs = get_fs(); | 2220 | old_fs = get_fs(); |
2230 | set_fs(KERNEL_DS); | 2221 | set_fs(KERNEL_DS); |
2231 | 2222 | ||
2232 | /* | 2223 | /* |
2233 | * Flush the instruction cache, since we've played with text. | 2224 | * Flush the instruction cache, since we've played with text. |
2234 | * Do it before processing of module parameters, so the module | 2225 | * Do it before processing of module parameters, so the module |
2235 | * can provide parameter accessor functions of its own. | 2226 | * can provide parameter accessor functions of its own. |
2236 | */ | 2227 | */ |
2237 | if (mod->module_init) | 2228 | if (mod->module_init) |
2238 | flush_icache_range((unsigned long)mod->module_init, | 2229 | flush_icache_range((unsigned long)mod->module_init, |
2239 | (unsigned long)mod->module_init | 2230 | (unsigned long)mod->module_init |
2240 | + mod->init_size); | 2231 | + mod->init_size); |
2241 | flush_icache_range((unsigned long)mod->module_core, | 2232 | flush_icache_range((unsigned long)mod->module_core, |
2242 | (unsigned long)mod->module_core + mod->core_size); | 2233 | (unsigned long)mod->module_core + mod->core_size); |
2243 | 2234 | ||
2244 | set_fs(old_fs); | 2235 | set_fs(old_fs); |
2245 | 2236 | ||
2246 | mod->args = args; | 2237 | mod->args = args; |
2247 | if (section_addr(hdr, sechdrs, secstrings, "__obsparm")) | 2238 | if (section_addr(hdr, sechdrs, secstrings, "__obsparm")) |
2248 | printk(KERN_WARNING "%s: Ignoring obsolete parameters\n", | 2239 | printk(KERN_WARNING "%s: Ignoring obsolete parameters\n", |
2249 | mod->name); | 2240 | mod->name); |
2250 | 2241 | ||
2251 | /* Now sew it into the lists so we can get lockdep and oops | 2242 | /* Now sew it into the lists so we can get lockdep and oops |
2252 | * info during argument parsing. Noone should access us, since | 2243 | * info during argument parsing. Noone should access us, since |
2253 | * strong_try_module_get() will fail. | 2244 | * strong_try_module_get() will fail. |
2254 | * lockdep/oops can run asynchronous, so use the RCU list insertion | 2245 | * lockdep/oops can run asynchronous, so use the RCU list insertion |
2255 | * function to insert in a way safe to concurrent readers. | 2246 | * function to insert in a way safe to concurrent readers. |
2256 | * The mutex protects against concurrent writers. | 2247 | * The mutex protects against concurrent writers. |
2257 | */ | 2248 | */ |
2258 | list_add_rcu(&mod->list, &modules); | 2249 | list_add_rcu(&mod->list, &modules); |
2259 | 2250 | ||
2260 | err = parse_args(mod->name, mod->args, kp, num_kp, NULL); | 2251 | err = parse_args(mod->name, mod->args, kp, num_kp, NULL); |
2261 | if (err < 0) | 2252 | if (err < 0) |
2262 | goto unlink; | 2253 | goto unlink; |
2263 | 2254 | ||
2264 | err = mod_sysfs_setup(mod, kp, num_kp); | 2255 | err = mod_sysfs_setup(mod, kp, num_kp); |
2265 | if (err < 0) | 2256 | if (err < 0) |
2266 | goto unlink; | 2257 | goto unlink; |
2267 | add_sect_attrs(mod, hdr->e_shnum, secstrings, sechdrs); | 2258 | add_sect_attrs(mod, hdr->e_shnum, secstrings, sechdrs); |
2268 | add_notes_attrs(mod, hdr->e_shnum, secstrings, sechdrs); | 2259 | add_notes_attrs(mod, hdr->e_shnum, secstrings, sechdrs); |
2269 | 2260 | ||
2270 | /* Size of section 0 is 0, so this works well if no unwind info. */ | ||
2271 | mod->unwind_info = unwind_add_table(mod, | ||
2272 | (void *)sechdrs[unwindex].sh_addr, | ||
2273 | sechdrs[unwindex].sh_size); | ||
2274 | |||
2275 | /* Get rid of temporary copy */ | 2261 | /* Get rid of temporary copy */ |
2276 | vfree(hdr); | 2262 | vfree(hdr); |
2277 | 2263 | ||
2278 | stop_machine_destroy(); | 2264 | stop_machine_destroy(); |
2279 | /* Done! */ | 2265 | /* Done! */ |
2280 | return mod; | 2266 | return mod; |
2281 | 2267 | ||
2282 | unlink: | 2268 | unlink: |
2283 | stop_machine(__unlink_module, mod, NULL); | 2269 | stop_machine(__unlink_module, mod, NULL); |
2284 | module_arch_cleanup(mod); | 2270 | module_arch_cleanup(mod); |
2285 | cleanup: | 2271 | cleanup: |
2286 | kobject_del(&mod->mkobj.kobj); | 2272 | kobject_del(&mod->mkobj.kobj); |
2287 | kobject_put(&mod->mkobj.kobj); | 2273 | kobject_put(&mod->mkobj.kobj); |
2288 | ftrace_release(mod->module_core, mod->core_size); | 2274 | ftrace_release(mod->module_core, mod->core_size); |
2289 | free_unload: | 2275 | free_unload: |
2290 | module_unload_free(mod); | 2276 | module_unload_free(mod); |
2291 | module_free(mod, mod->module_init); | 2277 | module_free(mod, mod->module_init); |
2292 | free_core: | 2278 | free_core: |
2293 | module_free(mod, mod->module_core); | 2279 | module_free(mod, mod->module_core); |
2294 | free_percpu: | 2280 | free_percpu: |
2295 | if (percpu) | 2281 | if (percpu) |
2296 | percpu_modfree(percpu); | 2282 | percpu_modfree(percpu); |
2297 | free_mod: | 2283 | free_mod: |
2298 | kfree(args); | 2284 | kfree(args); |
2299 | free_hdr: | 2285 | free_hdr: |
2300 | vfree(hdr); | 2286 | vfree(hdr); |
2301 | stop_machine_destroy(); | 2287 | stop_machine_destroy(); |
2302 | return ERR_PTR(err); | 2288 | return ERR_PTR(err); |
2303 | 2289 | ||
2304 | truncated: | 2290 | truncated: |
2305 | printk(KERN_ERR "Module len %lu truncated\n", len); | 2291 | printk(KERN_ERR "Module len %lu truncated\n", len); |
2306 | err = -ENOEXEC; | 2292 | err = -ENOEXEC; |
2307 | goto free_hdr; | 2293 | goto free_hdr; |
2308 | } | 2294 | } |
2309 | 2295 | ||
2310 | /* This is where the real work happens */ | 2296 | /* This is where the real work happens */ |
2311 | asmlinkage long | 2297 | asmlinkage long |
2312 | sys_init_module(void __user *umod, | 2298 | sys_init_module(void __user *umod, |
2313 | unsigned long len, | 2299 | unsigned long len, |
2314 | const char __user *uargs) | 2300 | const char __user *uargs) |
2315 | { | 2301 | { |
2316 | struct module *mod; | 2302 | struct module *mod; |
2317 | int ret = 0; | 2303 | int ret = 0; |
2318 | 2304 | ||
2319 | /* Must have permission */ | 2305 | /* Must have permission */ |
2320 | if (!capable(CAP_SYS_MODULE)) | 2306 | if (!capable(CAP_SYS_MODULE)) |
2321 | return -EPERM; | 2307 | return -EPERM; |
2322 | 2308 | ||
2323 | /* Only one module load at a time, please */ | 2309 | /* Only one module load at a time, please */ |
2324 | if (mutex_lock_interruptible(&module_mutex) != 0) | 2310 | if (mutex_lock_interruptible(&module_mutex) != 0) |
2325 | return -EINTR; | 2311 | return -EINTR; |
2326 | 2312 | ||
2327 | /* Do all the hard work */ | 2313 | /* Do all the hard work */ |
2328 | mod = load_module(umod, len, uargs); | 2314 | mod = load_module(umod, len, uargs); |
2329 | if (IS_ERR(mod)) { | 2315 | if (IS_ERR(mod)) { |
2330 | mutex_unlock(&module_mutex); | 2316 | mutex_unlock(&module_mutex); |
2331 | return PTR_ERR(mod); | 2317 | return PTR_ERR(mod); |
2332 | } | 2318 | } |
2333 | 2319 | ||
2334 | /* Drop lock so they can recurse */ | 2320 | /* Drop lock so they can recurse */ |
2335 | mutex_unlock(&module_mutex); | 2321 | mutex_unlock(&module_mutex); |
2336 | 2322 | ||
2337 | blocking_notifier_call_chain(&module_notify_list, | 2323 | blocking_notifier_call_chain(&module_notify_list, |
2338 | MODULE_STATE_COMING, mod); | 2324 | MODULE_STATE_COMING, mod); |
2339 | 2325 | ||
2340 | /* Start the module */ | 2326 | /* Start the module */ |
2341 | if (mod->init != NULL) | 2327 | if (mod->init != NULL) |
2342 | ret = do_one_initcall(mod->init); | 2328 | ret = do_one_initcall(mod->init); |
2343 | if (ret < 0) { | 2329 | if (ret < 0) { |
2344 | /* Init routine failed: abort. Try to protect us from | 2330 | /* Init routine failed: abort. Try to protect us from |
2345 | buggy refcounters. */ | 2331 | buggy refcounters. */ |
2346 | mod->state = MODULE_STATE_GOING; | 2332 | mod->state = MODULE_STATE_GOING; |
2347 | synchronize_sched(); | 2333 | synchronize_sched(); |
2348 | module_put(mod); | 2334 | module_put(mod); |
2349 | blocking_notifier_call_chain(&module_notify_list, | 2335 | blocking_notifier_call_chain(&module_notify_list, |
2350 | MODULE_STATE_GOING, mod); | 2336 | MODULE_STATE_GOING, mod); |
2351 | mutex_lock(&module_mutex); | 2337 | mutex_lock(&module_mutex); |
2352 | free_module(mod); | 2338 | free_module(mod); |
2353 | mutex_unlock(&module_mutex); | 2339 | mutex_unlock(&module_mutex); |
2354 | wake_up(&module_wq); | 2340 | wake_up(&module_wq); |
2355 | return ret; | 2341 | return ret; |
2356 | } | 2342 | } |
2357 | if (ret > 0) { | 2343 | if (ret > 0) { |
2358 | printk(KERN_WARNING "%s: '%s'->init suspiciously returned %d, " | 2344 | printk(KERN_WARNING "%s: '%s'->init suspiciously returned %d, " |
2359 | "it should follow 0/-E convention\n" | 2345 | "it should follow 0/-E convention\n" |
2360 | KERN_WARNING "%s: loading module anyway...\n", | 2346 | KERN_WARNING "%s: loading module anyway...\n", |
2361 | __func__, mod->name, ret, | 2347 | __func__, mod->name, ret, |
2362 | __func__); | 2348 | __func__); |
2363 | dump_stack(); | 2349 | dump_stack(); |
2364 | } | 2350 | } |
2365 | 2351 | ||
2366 | /* Now it's a first class citizen! Wake up anyone waiting for it. */ | 2352 | /* Now it's a first class citizen! Wake up anyone waiting for it. */ |
2367 | mod->state = MODULE_STATE_LIVE; | 2353 | mod->state = MODULE_STATE_LIVE; |
2368 | wake_up(&module_wq); | 2354 | wake_up(&module_wq); |
2369 | 2355 | ||
2370 | mutex_lock(&module_mutex); | 2356 | mutex_lock(&module_mutex); |
2371 | /* Drop initial reference. */ | 2357 | /* Drop initial reference. */ |
2372 | module_put(mod); | 2358 | module_put(mod); |
2373 | unwind_remove_table(mod->unwind_info, 1); | ||
2374 | module_free(mod, mod->module_init); | 2359 | module_free(mod, mod->module_init); |
2375 | mod->module_init = NULL; | 2360 | mod->module_init = NULL; |
2376 | mod->init_size = 0; | 2361 | mod->init_size = 0; |
2377 | mod->init_text_size = 0; | 2362 | mod->init_text_size = 0; |
2378 | mutex_unlock(&module_mutex); | 2363 | mutex_unlock(&module_mutex); |
2379 | 2364 | ||
2380 | return 0; | 2365 | return 0; |
2381 | } | 2366 | } |
2382 | 2367 | ||
2383 | static inline int within(unsigned long addr, void *start, unsigned long size) | 2368 | static inline int within(unsigned long addr, void *start, unsigned long size) |
2384 | { | 2369 | { |
2385 | return ((void *)addr >= start && (void *)addr < start + size); | 2370 | return ((void *)addr >= start && (void *)addr < start + size); |
2386 | } | 2371 | } |
2387 | 2372 | ||
2388 | #ifdef CONFIG_KALLSYMS | 2373 | #ifdef CONFIG_KALLSYMS |
2389 | /* | 2374 | /* |
2390 | * This ignores the intensely annoying "mapping symbols" found | 2375 | * This ignores the intensely annoying "mapping symbols" found |
2391 | * in ARM ELF files: $a, $t and $d. | 2376 | * in ARM ELF files: $a, $t and $d. |
2392 | */ | 2377 | */ |
2393 | static inline int is_arm_mapping_symbol(const char *str) | 2378 | static inline int is_arm_mapping_symbol(const char *str) |
2394 | { | 2379 | { |
2395 | return str[0] == '$' && strchr("atd", str[1]) | 2380 | return str[0] == '$' && strchr("atd", str[1]) |
2396 | && (str[2] == '\0' || str[2] == '.'); | 2381 | && (str[2] == '\0' || str[2] == '.'); |
2397 | } | 2382 | } |
2398 | 2383 | ||
2399 | static const char *get_ksymbol(struct module *mod, | 2384 | static const char *get_ksymbol(struct module *mod, |
2400 | unsigned long addr, | 2385 | unsigned long addr, |
2401 | unsigned long *size, | 2386 | unsigned long *size, |
2402 | unsigned long *offset) | 2387 | unsigned long *offset) |
2403 | { | 2388 | { |
2404 | unsigned int i, best = 0; | 2389 | unsigned int i, best = 0; |
2405 | unsigned long nextval; | 2390 | unsigned long nextval; |
2406 | 2391 | ||
2407 | /* At worse, next value is at end of module */ | 2392 | /* At worse, next value is at end of module */ |
2408 | if (within(addr, mod->module_init, mod->init_size)) | 2393 | if (within(addr, mod->module_init, mod->init_size)) |
2409 | nextval = (unsigned long)mod->module_init+mod->init_text_size; | 2394 | nextval = (unsigned long)mod->module_init+mod->init_text_size; |
2410 | else | 2395 | else |
2411 | nextval = (unsigned long)mod->module_core+mod->core_text_size; | 2396 | nextval = (unsigned long)mod->module_core+mod->core_text_size; |
2412 | 2397 | ||
2413 | /* Scan for closest preceeding symbol, and next symbol. (ELF | 2398 | /* Scan for closest preceeding symbol, and next symbol. (ELF |
2414 | starts real symbols at 1). */ | 2399 | starts real symbols at 1). */ |
2415 | for (i = 1; i < mod->num_symtab; i++) { | 2400 | for (i = 1; i < mod->num_symtab; i++) { |
2416 | if (mod->symtab[i].st_shndx == SHN_UNDEF) | 2401 | if (mod->symtab[i].st_shndx == SHN_UNDEF) |
2417 | continue; | 2402 | continue; |
2418 | 2403 | ||
2419 | /* We ignore unnamed symbols: they're uninformative | 2404 | /* We ignore unnamed symbols: they're uninformative |
2420 | * and inserted at a whim. */ | 2405 | * and inserted at a whim. */ |
2421 | if (mod->symtab[i].st_value <= addr | 2406 | if (mod->symtab[i].st_value <= addr |
2422 | && mod->symtab[i].st_value > mod->symtab[best].st_value | 2407 | && mod->symtab[i].st_value > mod->symtab[best].st_value |
2423 | && *(mod->strtab + mod->symtab[i].st_name) != '\0' | 2408 | && *(mod->strtab + mod->symtab[i].st_name) != '\0' |
2424 | && !is_arm_mapping_symbol(mod->strtab + mod->symtab[i].st_name)) | 2409 | && !is_arm_mapping_symbol(mod->strtab + mod->symtab[i].st_name)) |
2425 | best = i; | 2410 | best = i; |
2426 | if (mod->symtab[i].st_value > addr | 2411 | if (mod->symtab[i].st_value > addr |
2427 | && mod->symtab[i].st_value < nextval | 2412 | && mod->symtab[i].st_value < nextval |
2428 | && *(mod->strtab + mod->symtab[i].st_name) != '\0' | 2413 | && *(mod->strtab + mod->symtab[i].st_name) != '\0' |
2429 | && !is_arm_mapping_symbol(mod->strtab + mod->symtab[i].st_name)) | 2414 | && !is_arm_mapping_symbol(mod->strtab + mod->symtab[i].st_name)) |
2430 | nextval = mod->symtab[i].st_value; | 2415 | nextval = mod->symtab[i].st_value; |
2431 | } | 2416 | } |
2432 | 2417 | ||
2433 | if (!best) | 2418 | if (!best) |
2434 | return NULL; | 2419 | return NULL; |
2435 | 2420 | ||
2436 | if (size) | 2421 | if (size) |
2437 | *size = nextval - mod->symtab[best].st_value; | 2422 | *size = nextval - mod->symtab[best].st_value; |
2438 | if (offset) | 2423 | if (offset) |
2439 | *offset = addr - mod->symtab[best].st_value; | 2424 | *offset = addr - mod->symtab[best].st_value; |
2440 | return mod->strtab + mod->symtab[best].st_name; | 2425 | return mod->strtab + mod->symtab[best].st_name; |
2441 | } | 2426 | } |
2442 | 2427 | ||
2443 | /* For kallsyms to ask for address resolution. NULL means not found. Careful | 2428 | /* For kallsyms to ask for address resolution. NULL means not found. Careful |
2444 | * not to lock to avoid deadlock on oopses, simply disable preemption. */ | 2429 | * not to lock to avoid deadlock on oopses, simply disable preemption. */ |
2445 | const char *module_address_lookup(unsigned long addr, | 2430 | const char *module_address_lookup(unsigned long addr, |
2446 | unsigned long *size, | 2431 | unsigned long *size, |
2447 | unsigned long *offset, | 2432 | unsigned long *offset, |
2448 | char **modname, | 2433 | char **modname, |
2449 | char *namebuf) | 2434 | char *namebuf) |
2450 | { | 2435 | { |
2451 | struct module *mod; | 2436 | struct module *mod; |
2452 | const char *ret = NULL; | 2437 | const char *ret = NULL; |
2453 | 2438 | ||
2454 | preempt_disable(); | 2439 | preempt_disable(); |
2455 | list_for_each_entry_rcu(mod, &modules, list) { | 2440 | list_for_each_entry_rcu(mod, &modules, list) { |
2456 | if (within(addr, mod->module_init, mod->init_size) | 2441 | if (within(addr, mod->module_init, mod->init_size) |
2457 | || within(addr, mod->module_core, mod->core_size)) { | 2442 | || within(addr, mod->module_core, mod->core_size)) { |
2458 | if (modname) | 2443 | if (modname) |
2459 | *modname = mod->name; | 2444 | *modname = mod->name; |
2460 | ret = get_ksymbol(mod, addr, size, offset); | 2445 | ret = get_ksymbol(mod, addr, size, offset); |
2461 | break; | 2446 | break; |
2462 | } | 2447 | } |
2463 | } | 2448 | } |
2464 | /* Make a copy in here where it's safe */ | 2449 | /* Make a copy in here where it's safe */ |
2465 | if (ret) { | 2450 | if (ret) { |
2466 | strncpy(namebuf, ret, KSYM_NAME_LEN - 1); | 2451 | strncpy(namebuf, ret, KSYM_NAME_LEN - 1); |
2467 | ret = namebuf; | 2452 | ret = namebuf; |
2468 | } | 2453 | } |
2469 | preempt_enable(); | 2454 | preempt_enable(); |
2470 | return ret; | 2455 | return ret; |
2471 | } | 2456 | } |
2472 | 2457 | ||
2473 | int lookup_module_symbol_name(unsigned long addr, char *symname) | 2458 | int lookup_module_symbol_name(unsigned long addr, char *symname) |
2474 | { | 2459 | { |
2475 | struct module *mod; | 2460 | struct module *mod; |
2476 | 2461 | ||
2477 | preempt_disable(); | 2462 | preempt_disable(); |
2478 | list_for_each_entry_rcu(mod, &modules, list) { | 2463 | list_for_each_entry_rcu(mod, &modules, list) { |
2479 | if (within(addr, mod->module_init, mod->init_size) || | 2464 | if (within(addr, mod->module_init, mod->init_size) || |
2480 | within(addr, mod->module_core, mod->core_size)) { | 2465 | within(addr, mod->module_core, mod->core_size)) { |
2481 | const char *sym; | 2466 | const char *sym; |
2482 | 2467 | ||
2483 | sym = get_ksymbol(mod, addr, NULL, NULL); | 2468 | sym = get_ksymbol(mod, addr, NULL, NULL); |
2484 | if (!sym) | 2469 | if (!sym) |
2485 | goto out; | 2470 | goto out; |
2486 | strlcpy(symname, sym, KSYM_NAME_LEN); | 2471 | strlcpy(symname, sym, KSYM_NAME_LEN); |
2487 | preempt_enable(); | 2472 | preempt_enable(); |
2488 | return 0; | 2473 | return 0; |
2489 | } | 2474 | } |
2490 | } | 2475 | } |
2491 | out: | 2476 | out: |
2492 | preempt_enable(); | 2477 | preempt_enable(); |
2493 | return -ERANGE; | 2478 | return -ERANGE; |
2494 | } | 2479 | } |
2495 | 2480 | ||
2496 | int lookup_module_symbol_attrs(unsigned long addr, unsigned long *size, | 2481 | int lookup_module_symbol_attrs(unsigned long addr, unsigned long *size, |
2497 | unsigned long *offset, char *modname, char *name) | 2482 | unsigned long *offset, char *modname, char *name) |
2498 | { | 2483 | { |
2499 | struct module *mod; | 2484 | struct module *mod; |
2500 | 2485 | ||
2501 | preempt_disable(); | 2486 | preempt_disable(); |
2502 | list_for_each_entry_rcu(mod, &modules, list) { | 2487 | list_for_each_entry_rcu(mod, &modules, list) { |
2503 | if (within(addr, mod->module_init, mod->init_size) || | 2488 | if (within(addr, mod->module_init, mod->init_size) || |
2504 | within(addr, mod->module_core, mod->core_size)) { | 2489 | within(addr, mod->module_core, mod->core_size)) { |
2505 | const char *sym; | 2490 | const char *sym; |
2506 | 2491 | ||
2507 | sym = get_ksymbol(mod, addr, size, offset); | 2492 | sym = get_ksymbol(mod, addr, size, offset); |
2508 | if (!sym) | 2493 | if (!sym) |
2509 | goto out; | 2494 | goto out; |
2510 | if (modname) | 2495 | if (modname) |
2511 | strlcpy(modname, mod->name, MODULE_NAME_LEN); | 2496 | strlcpy(modname, mod->name, MODULE_NAME_LEN); |
2512 | if (name) | 2497 | if (name) |
2513 | strlcpy(name, sym, KSYM_NAME_LEN); | 2498 | strlcpy(name, sym, KSYM_NAME_LEN); |
2514 | preempt_enable(); | 2499 | preempt_enable(); |
2515 | return 0; | 2500 | return 0; |
2516 | } | 2501 | } |
2517 | } | 2502 | } |
2518 | out: | 2503 | out: |
2519 | preempt_enable(); | 2504 | preempt_enable(); |
2520 | return -ERANGE; | 2505 | return -ERANGE; |
2521 | } | 2506 | } |
2522 | 2507 | ||
2523 | int module_get_kallsym(unsigned int symnum, unsigned long *value, char *type, | 2508 | int module_get_kallsym(unsigned int symnum, unsigned long *value, char *type, |
2524 | char *name, char *module_name, int *exported) | 2509 | char *name, char *module_name, int *exported) |
2525 | { | 2510 | { |
2526 | struct module *mod; | 2511 | struct module *mod; |
2527 | 2512 | ||
2528 | preempt_disable(); | 2513 | preempt_disable(); |
2529 | list_for_each_entry_rcu(mod, &modules, list) { | 2514 | list_for_each_entry_rcu(mod, &modules, list) { |
2530 | if (symnum < mod->num_symtab) { | 2515 | if (symnum < mod->num_symtab) { |
2531 | *value = mod->symtab[symnum].st_value; | 2516 | *value = mod->symtab[symnum].st_value; |
2532 | *type = mod->symtab[symnum].st_info; | 2517 | *type = mod->symtab[symnum].st_info; |
2533 | strlcpy(name, mod->strtab + mod->symtab[symnum].st_name, | 2518 | strlcpy(name, mod->strtab + mod->symtab[symnum].st_name, |
2534 | KSYM_NAME_LEN); | 2519 | KSYM_NAME_LEN); |
2535 | strlcpy(module_name, mod->name, MODULE_NAME_LEN); | 2520 | strlcpy(module_name, mod->name, MODULE_NAME_LEN); |
2536 | *exported = is_exported(name, *value, mod); | 2521 | *exported = is_exported(name, *value, mod); |
2537 | preempt_enable(); | 2522 | preempt_enable(); |
2538 | return 0; | 2523 | return 0; |
2539 | } | 2524 | } |
2540 | symnum -= mod->num_symtab; | 2525 | symnum -= mod->num_symtab; |
2541 | } | 2526 | } |
2542 | preempt_enable(); | 2527 | preempt_enable(); |
2543 | return -ERANGE; | 2528 | return -ERANGE; |
2544 | } | 2529 | } |
2545 | 2530 | ||
2546 | static unsigned long mod_find_symname(struct module *mod, const char *name) | 2531 | static unsigned long mod_find_symname(struct module *mod, const char *name) |
2547 | { | 2532 | { |
2548 | unsigned int i; | 2533 | unsigned int i; |
2549 | 2534 | ||
2550 | for (i = 0; i < mod->num_symtab; i++) | 2535 | for (i = 0; i < mod->num_symtab; i++) |
2551 | if (strcmp(name, mod->strtab+mod->symtab[i].st_name) == 0 && | 2536 | if (strcmp(name, mod->strtab+mod->symtab[i].st_name) == 0 && |
2552 | mod->symtab[i].st_info != 'U') | 2537 | mod->symtab[i].st_info != 'U') |
2553 | return mod->symtab[i].st_value; | 2538 | return mod->symtab[i].st_value; |
2554 | return 0; | 2539 | return 0; |
2555 | } | 2540 | } |
2556 | 2541 | ||
2557 | /* Look for this name: can be of form module:name. */ | 2542 | /* Look for this name: can be of form module:name. */ |
2558 | unsigned long module_kallsyms_lookup_name(const char *name) | 2543 | unsigned long module_kallsyms_lookup_name(const char *name) |
2559 | { | 2544 | { |
2560 | struct module *mod; | 2545 | struct module *mod; |
2561 | char *colon; | 2546 | char *colon; |
2562 | unsigned long ret = 0; | 2547 | unsigned long ret = 0; |
2563 | 2548 | ||
2564 | /* Don't lock: we're in enough trouble already. */ | 2549 | /* Don't lock: we're in enough trouble already. */ |
2565 | preempt_disable(); | 2550 | preempt_disable(); |
2566 | if ((colon = strchr(name, ':')) != NULL) { | 2551 | if ((colon = strchr(name, ':')) != NULL) { |
2567 | *colon = '\0'; | 2552 | *colon = '\0'; |
2568 | if ((mod = find_module(name)) != NULL) | 2553 | if ((mod = find_module(name)) != NULL) |
2569 | ret = mod_find_symname(mod, colon+1); | 2554 | ret = mod_find_symname(mod, colon+1); |
2570 | *colon = ':'; | 2555 | *colon = ':'; |
2571 | } else { | 2556 | } else { |
2572 | list_for_each_entry_rcu(mod, &modules, list) | 2557 | list_for_each_entry_rcu(mod, &modules, list) |
2573 | if ((ret = mod_find_symname(mod, name)) != 0) | 2558 | if ((ret = mod_find_symname(mod, name)) != 0) |
2574 | break; | 2559 | break; |
2575 | } | 2560 | } |
2576 | preempt_enable(); | 2561 | preempt_enable(); |
2577 | return ret; | 2562 | return ret; |
2578 | } | 2563 | } |
2579 | #endif /* CONFIG_KALLSYMS */ | 2564 | #endif /* CONFIG_KALLSYMS */ |
2580 | 2565 | ||
2581 | static char *module_flags(struct module *mod, char *buf) | 2566 | static char *module_flags(struct module *mod, char *buf) |
2582 | { | 2567 | { |
2583 | int bx = 0; | 2568 | int bx = 0; |
2584 | 2569 | ||
2585 | if (mod->taints || | 2570 | if (mod->taints || |
2586 | mod->state == MODULE_STATE_GOING || | 2571 | mod->state == MODULE_STATE_GOING || |
2587 | mod->state == MODULE_STATE_COMING) { | 2572 | mod->state == MODULE_STATE_COMING) { |
2588 | buf[bx++] = '('; | 2573 | buf[bx++] = '('; |
2589 | if (mod->taints & (1 << TAINT_PROPRIETARY_MODULE)) | 2574 | if (mod->taints & (1 << TAINT_PROPRIETARY_MODULE)) |
2590 | buf[bx++] = 'P'; | 2575 | buf[bx++] = 'P'; |
2591 | if (mod->taints & (1 << TAINT_FORCED_MODULE)) | 2576 | if (mod->taints & (1 << TAINT_FORCED_MODULE)) |
2592 | buf[bx++] = 'F'; | 2577 | buf[bx++] = 'F'; |
2593 | if (mod->taints & (1 << TAINT_CRAP)) | 2578 | if (mod->taints & (1 << TAINT_CRAP)) |
2594 | buf[bx++] = 'C'; | 2579 | buf[bx++] = 'C'; |
2595 | /* | 2580 | /* |
2596 | * TAINT_FORCED_RMMOD: could be added. | 2581 | * TAINT_FORCED_RMMOD: could be added. |
2597 | * TAINT_UNSAFE_SMP, TAINT_MACHINE_CHECK, TAINT_BAD_PAGE don't | 2582 | * TAINT_UNSAFE_SMP, TAINT_MACHINE_CHECK, TAINT_BAD_PAGE don't |
2598 | * apply to modules. | 2583 | * apply to modules. |
2599 | */ | 2584 | */ |
2600 | 2585 | ||
2601 | /* Show a - for module-is-being-unloaded */ | 2586 | /* Show a - for module-is-being-unloaded */ |
2602 | if (mod->state == MODULE_STATE_GOING) | 2587 | if (mod->state == MODULE_STATE_GOING) |
2603 | buf[bx++] = '-'; | 2588 | buf[bx++] = '-'; |
2604 | /* Show a + for module-is-being-loaded */ | 2589 | /* Show a + for module-is-being-loaded */ |
2605 | if (mod->state == MODULE_STATE_COMING) | 2590 | if (mod->state == MODULE_STATE_COMING) |
2606 | buf[bx++] = '+'; | 2591 | buf[bx++] = '+'; |
2607 | buf[bx++] = ')'; | 2592 | buf[bx++] = ')'; |
2608 | } | 2593 | } |
2609 | buf[bx] = '\0'; | 2594 | buf[bx] = '\0'; |
2610 | 2595 | ||
2611 | return buf; | 2596 | return buf; |
2612 | } | 2597 | } |
2613 | 2598 | ||
2614 | #ifdef CONFIG_PROC_FS | 2599 | #ifdef CONFIG_PROC_FS |
2615 | /* Called by the /proc file system to return a list of modules. */ | 2600 | /* Called by the /proc file system to return a list of modules. */ |
2616 | static void *m_start(struct seq_file *m, loff_t *pos) | 2601 | static void *m_start(struct seq_file *m, loff_t *pos) |
2617 | { | 2602 | { |
2618 | mutex_lock(&module_mutex); | 2603 | mutex_lock(&module_mutex); |
2619 | return seq_list_start(&modules, *pos); | 2604 | return seq_list_start(&modules, *pos); |
2620 | } | 2605 | } |
2621 | 2606 | ||
2622 | static void *m_next(struct seq_file *m, void *p, loff_t *pos) | 2607 | static void *m_next(struct seq_file *m, void *p, loff_t *pos) |
2623 | { | 2608 | { |
2624 | return seq_list_next(p, &modules, pos); | 2609 | return seq_list_next(p, &modules, pos); |
2625 | } | 2610 | } |
2626 | 2611 | ||
2627 | static void m_stop(struct seq_file *m, void *p) | 2612 | static void m_stop(struct seq_file *m, void *p) |
2628 | { | 2613 | { |
2629 | mutex_unlock(&module_mutex); | 2614 | mutex_unlock(&module_mutex); |
2630 | } | 2615 | } |
2631 | 2616 | ||
2632 | static int m_show(struct seq_file *m, void *p) | 2617 | static int m_show(struct seq_file *m, void *p) |
2633 | { | 2618 | { |
2634 | struct module *mod = list_entry(p, struct module, list); | 2619 | struct module *mod = list_entry(p, struct module, list); |
2635 | char buf[8]; | 2620 | char buf[8]; |
2636 | 2621 | ||
2637 | seq_printf(m, "%s %u", | 2622 | seq_printf(m, "%s %u", |
2638 | mod->name, mod->init_size + mod->core_size); | 2623 | mod->name, mod->init_size + mod->core_size); |
2639 | print_unload_info(m, mod); | 2624 | print_unload_info(m, mod); |
2640 | 2625 | ||
2641 | /* Informative for users. */ | 2626 | /* Informative for users. */ |
2642 | seq_printf(m, " %s", | 2627 | seq_printf(m, " %s", |
2643 | mod->state == MODULE_STATE_GOING ? "Unloading": | 2628 | mod->state == MODULE_STATE_GOING ? "Unloading": |
2644 | mod->state == MODULE_STATE_COMING ? "Loading": | 2629 | mod->state == MODULE_STATE_COMING ? "Loading": |
2645 | "Live"); | 2630 | "Live"); |
2646 | /* Used by oprofile and other similar tools. */ | 2631 | /* Used by oprofile and other similar tools. */ |
2647 | seq_printf(m, " 0x%p", mod->module_core); | 2632 | seq_printf(m, " 0x%p", mod->module_core); |
2648 | 2633 | ||
2649 | /* Taints info */ | 2634 | /* Taints info */ |
2650 | if (mod->taints) | 2635 | if (mod->taints) |
2651 | seq_printf(m, " %s", module_flags(mod, buf)); | 2636 | seq_printf(m, " %s", module_flags(mod, buf)); |
2652 | 2637 | ||
2653 | seq_printf(m, "\n"); | 2638 | seq_printf(m, "\n"); |
2654 | return 0; | 2639 | return 0; |
2655 | } | 2640 | } |
2656 | 2641 | ||
2657 | /* Format: modulename size refcount deps address | 2642 | /* Format: modulename size refcount deps address |
2658 | 2643 | ||
2659 | Where refcount is a number or -, and deps is a comma-separated list | 2644 | Where refcount is a number or -, and deps is a comma-separated list |
2660 | of depends or -. | 2645 | of depends or -. |
2661 | */ | 2646 | */ |
2662 | static const struct seq_operations modules_op = { | 2647 | static const struct seq_operations modules_op = { |
2663 | .start = m_start, | 2648 | .start = m_start, |
2664 | .next = m_next, | 2649 | .next = m_next, |
2665 | .stop = m_stop, | 2650 | .stop = m_stop, |
2666 | .show = m_show | 2651 | .show = m_show |
2667 | }; | 2652 | }; |
2668 | 2653 | ||
2669 | static int modules_open(struct inode *inode, struct file *file) | 2654 | static int modules_open(struct inode *inode, struct file *file) |
2670 | { | 2655 | { |
2671 | return seq_open(file, &modules_op); | 2656 | return seq_open(file, &modules_op); |
2672 | } | 2657 | } |
2673 | 2658 | ||
2674 | static const struct file_operations proc_modules_operations = { | 2659 | static const struct file_operations proc_modules_operations = { |
2675 | .open = modules_open, | 2660 | .open = modules_open, |
2676 | .read = seq_read, | 2661 | .read = seq_read, |
2677 | .llseek = seq_lseek, | 2662 | .llseek = seq_lseek, |
2678 | .release = seq_release, | 2663 | .release = seq_release, |
2679 | }; | 2664 | }; |
2680 | 2665 | ||
2681 | static int __init proc_modules_init(void) | 2666 | static int __init proc_modules_init(void) |
2682 | { | 2667 | { |
2683 | proc_create("modules", 0, NULL, &proc_modules_operations); | 2668 | proc_create("modules", 0, NULL, &proc_modules_operations); |
2684 | return 0; | 2669 | return 0; |
2685 | } | 2670 | } |
2686 | module_init(proc_modules_init); | 2671 | module_init(proc_modules_init); |
2687 | #endif | 2672 | #endif |
2688 | 2673 | ||
2689 | /* Given an address, look for it in the module exception tables. */ | 2674 | /* Given an address, look for it in the module exception tables. */ |
2690 | const struct exception_table_entry *search_module_extables(unsigned long addr) | 2675 | const struct exception_table_entry *search_module_extables(unsigned long addr) |
2691 | { | 2676 | { |
2692 | const struct exception_table_entry *e = NULL; | 2677 | const struct exception_table_entry *e = NULL; |
2693 | struct module *mod; | 2678 | struct module *mod; |
2694 | 2679 | ||
2695 | preempt_disable(); | 2680 | preempt_disable(); |
2696 | list_for_each_entry_rcu(mod, &modules, list) { | 2681 | list_for_each_entry_rcu(mod, &modules, list) { |
2697 | if (mod->num_exentries == 0) | 2682 | if (mod->num_exentries == 0) |
2698 | continue; | 2683 | continue; |
2699 | 2684 | ||
2700 | e = search_extable(mod->extable, | 2685 | e = search_extable(mod->extable, |
2701 | mod->extable + mod->num_exentries - 1, | 2686 | mod->extable + mod->num_exentries - 1, |
2702 | addr); | 2687 | addr); |
2703 | if (e) | 2688 | if (e) |
2704 | break; | 2689 | break; |
2705 | } | 2690 | } |
2706 | preempt_enable(); | 2691 | preempt_enable(); |
2707 | 2692 | ||
2708 | /* Now, if we found one, we are running inside it now, hence | 2693 | /* Now, if we found one, we are running inside it now, hence |
2709 | we cannot unload the module, hence no refcnt needed. */ | 2694 | we cannot unload the module, hence no refcnt needed. */ |
2710 | return e; | 2695 | return e; |
2711 | } | 2696 | } |
2712 | 2697 | ||
2713 | /* | 2698 | /* |
2714 | * Is this a valid module address? | 2699 | * Is this a valid module address? |
2715 | */ | 2700 | */ |
2716 | int is_module_address(unsigned long addr) | 2701 | int is_module_address(unsigned long addr) |
2717 | { | 2702 | { |
2718 | struct module *mod; | 2703 | struct module *mod; |
2719 | 2704 | ||
2720 | preempt_disable(); | 2705 | preempt_disable(); |
2721 | 2706 | ||
2722 | list_for_each_entry_rcu(mod, &modules, list) { | 2707 | list_for_each_entry_rcu(mod, &modules, list) { |
2723 | if (within(addr, mod->module_core, mod->core_size)) { | 2708 | if (within(addr, mod->module_core, mod->core_size)) { |
2724 | preempt_enable(); | 2709 | preempt_enable(); |
2725 | return 1; | 2710 | return 1; |
2726 | } | 2711 | } |
2727 | } | 2712 | } |
2728 | 2713 | ||
2729 | preempt_enable(); | 2714 | preempt_enable(); |
2730 | 2715 | ||
2731 | return 0; | 2716 | return 0; |
2732 | } | 2717 | } |
2733 | 2718 | ||
2734 | 2719 | ||
2735 | /* Is this a valid kernel address? */ | 2720 | /* Is this a valid kernel address? */ |
2736 | __notrace_funcgraph struct module *__module_text_address(unsigned long addr) | 2721 | __notrace_funcgraph struct module *__module_text_address(unsigned long addr) |
2737 | { | 2722 | { |
2738 | struct module *mod; | 2723 | struct module *mod; |
2739 | 2724 | ||
2740 | if (addr < module_addr_min || addr > module_addr_max) | 2725 | if (addr < module_addr_min || addr > module_addr_max) |
2741 | return NULL; | 2726 | return NULL; |
2742 | 2727 | ||
2743 | list_for_each_entry_rcu(mod, &modules, list) | 2728 | list_for_each_entry_rcu(mod, &modules, list) |
2744 | if (within(addr, mod->module_init, mod->init_text_size) | 2729 | if (within(addr, mod->module_init, mod->init_text_size) |
2745 | || within(addr, mod->module_core, mod->core_text_size)) | 2730 | || within(addr, mod->module_core, mod->core_text_size)) |
2746 | return mod; | 2731 | return mod; |
2747 | return NULL; | 2732 | return NULL; |
2748 | } | 2733 | } |
2749 | 2734 | ||
2750 | struct module *module_text_address(unsigned long addr) | 2735 | struct module *module_text_address(unsigned long addr) |
2751 | { | 2736 | { |
2752 | struct module *mod; | 2737 | struct module *mod; |
2753 | 2738 | ||
2754 | preempt_disable(); | 2739 | preempt_disable(); |
2755 | mod = __module_text_address(addr); | 2740 | mod = __module_text_address(addr); |
2756 | preempt_enable(); | 2741 | preempt_enable(); |
2757 | 2742 | ||
2758 | return mod; | 2743 | return mod; |
2759 | } | 2744 | } |
2760 | 2745 | ||
2761 | /* Don't grab lock, we're oopsing. */ | 2746 | /* Don't grab lock, we're oopsing. */ |
2762 | void print_modules(void) | 2747 | void print_modules(void) |
2763 | { | 2748 | { |
2764 | struct module *mod; | 2749 | struct module *mod; |
2765 | char buf[8]; | 2750 | char buf[8]; |
2766 | 2751 | ||
2767 | printk("Modules linked in:"); | 2752 | printk("Modules linked in:"); |
2768 | /* Most callers should already have preempt disabled, but make sure */ | 2753 | /* Most callers should already have preempt disabled, but make sure */ |
2769 | preempt_disable(); | 2754 | preempt_disable(); |
2770 | list_for_each_entry_rcu(mod, &modules, list) | 2755 | list_for_each_entry_rcu(mod, &modules, list) |
2771 | printk(" %s%s", mod->name, module_flags(mod, buf)); | 2756 | printk(" %s%s", mod->name, module_flags(mod, buf)); |
2772 | preempt_enable(); | 2757 | preempt_enable(); |
2773 | if (last_unloaded_module[0]) | 2758 | if (last_unloaded_module[0]) |
2774 | printk(" [last unloaded: %s]", last_unloaded_module); | 2759 | printk(" [last unloaded: %s]", last_unloaded_module); |
2775 | printk("\n"); | 2760 | printk("\n"); |
2776 | } | 2761 | } |
2777 | 2762 | ||
2778 | #ifdef CONFIG_MODVERSIONS | 2763 | #ifdef CONFIG_MODVERSIONS |
2779 | /* Generate the signature for struct module here, too, for modversions. */ | 2764 | /* Generate the signature for struct module here, too, for modversions. */ |
2780 | void struct_module(struct module *mod) { return; } | 2765 | void struct_module(struct module *mod) { return; } |
2781 | EXPORT_SYMBOL(struct_module); | 2766 | EXPORT_SYMBOL(struct_module); |
2782 | #endif | 2767 | #endif |
2783 | 2768 | ||
2784 | #ifdef CONFIG_MARKERS | 2769 | #ifdef CONFIG_MARKERS |
2785 | void module_update_markers(void) | 2770 | void module_update_markers(void) |
2786 | { | 2771 | { |
2787 | struct module *mod; | 2772 | struct module *mod; |
2788 | 2773 | ||
2789 | mutex_lock(&module_mutex); | 2774 | mutex_lock(&module_mutex); |
2790 | list_for_each_entry(mod, &modules, list) | 2775 | list_for_each_entry(mod, &modules, list) |
2791 | if (!mod->taints) | 2776 | if (!mod->taints) |
2792 | marker_update_probe_range(mod->markers, | 2777 | marker_update_probe_range(mod->markers, |
2793 | mod->markers + mod->num_markers); | 2778 | mod->markers + mod->num_markers); |
2794 | mutex_unlock(&module_mutex); | 2779 | mutex_unlock(&module_mutex); |
2795 | } | 2780 | } |
2796 | #endif | 2781 | #endif |
2797 | 2782 | ||
2798 | #ifdef CONFIG_TRACEPOINTS | 2783 | #ifdef CONFIG_TRACEPOINTS |
2799 | void module_update_tracepoints(void) | 2784 | void module_update_tracepoints(void) |
2800 | { | 2785 | { |
2801 | struct module *mod; | 2786 | struct module *mod; |
2802 | 2787 | ||
2803 | mutex_lock(&module_mutex); | 2788 | mutex_lock(&module_mutex); |
2804 | list_for_each_entry(mod, &modules, list) | 2789 | list_for_each_entry(mod, &modules, list) |
2805 | if (!mod->taints) | 2790 | if (!mod->taints) |
2806 | tracepoint_update_probe_range(mod->tracepoints, | 2791 | tracepoint_update_probe_range(mod->tracepoints, |
2807 | mod->tracepoints + mod->num_tracepoints); | 2792 | mod->tracepoints + mod->num_tracepoints); |
2808 | mutex_unlock(&module_mutex); | 2793 | mutex_unlock(&module_mutex); |
2809 | } | 2794 | } |
2810 | 2795 | ||
2811 | /* | 2796 | /* |
2812 | * Returns 0 if current not found. | 2797 | * Returns 0 if current not found. |
2813 | * Returns 1 if current found. | 2798 | * Returns 1 if current found. |
2814 | */ | 2799 | */ |
2815 | int module_get_iter_tracepoints(struct tracepoint_iter *iter) | 2800 | int module_get_iter_tracepoints(struct tracepoint_iter *iter) |
2816 | { | 2801 | { |
2817 | struct module *iter_mod; | 2802 | struct module *iter_mod; |
2818 | int found = 0; | 2803 | int found = 0; |
2819 | 2804 | ||
2820 | mutex_lock(&module_mutex); | 2805 | mutex_lock(&module_mutex); |
2821 | list_for_each_entry(iter_mod, &modules, list) { | 2806 | list_for_each_entry(iter_mod, &modules, list) { |
2822 | if (!iter_mod->taints) { | 2807 | if (!iter_mod->taints) { |
2823 | /* | 2808 | /* |
2824 | * Sorted module list | 2809 | * Sorted module list |
2825 | */ | 2810 | */ |
2826 | if (iter_mod < iter->module) | 2811 | if (iter_mod < iter->module) |
2827 | continue; | 2812 | continue; |
2828 | else if (iter_mod > iter->module) | 2813 | else if (iter_mod > iter->module) |
2829 | iter->tracepoint = NULL; | 2814 | iter->tracepoint = NULL; |
2830 | found = tracepoint_get_iter_range(&iter->tracepoint, | 2815 | found = tracepoint_get_iter_range(&iter->tracepoint, |
2831 | iter_mod->tracepoints, | 2816 | iter_mod->tracepoints, |
2832 | iter_mod->tracepoints | 2817 | iter_mod->tracepoints |
2833 | + iter_mod->num_tracepoints); | 2818 | + iter_mod->num_tracepoints); |
2834 | if (found) { | 2819 | if (found) { |
2835 | iter->module = iter_mod; | 2820 | iter->module = iter_mod; |
2836 | break; | 2821 | break; |
2837 | } | 2822 | } |
2838 | } | 2823 | } |
2839 | } | 2824 | } |
2840 | mutex_unlock(&module_mutex); | 2825 | mutex_unlock(&module_mutex); |
2841 | return found; | 2826 | return found; |
2842 | } | 2827 | } |
2843 | #endif | 2828 | #endif |
2844 | 2829 |
lib/fault-inject.c
1 | #include <linux/kernel.h> | 1 | #include <linux/kernel.h> |
2 | #include <linux/init.h> | 2 | #include <linux/init.h> |
3 | #include <linux/random.h> | 3 | #include <linux/random.h> |
4 | #include <linux/stat.h> | 4 | #include <linux/stat.h> |
5 | #include <linux/types.h> | 5 | #include <linux/types.h> |
6 | #include <linux/fs.h> | 6 | #include <linux/fs.h> |
7 | #include <linux/module.h> | 7 | #include <linux/module.h> |
8 | #include <linux/interrupt.h> | 8 | #include <linux/interrupt.h> |
9 | #include <linux/unwind.h> | ||
10 | #include <linux/stacktrace.h> | 9 | #include <linux/stacktrace.h> |
11 | #include <linux/kallsyms.h> | 10 | #include <linux/kallsyms.h> |
12 | #include <linux/fault-inject.h> | 11 | #include <linux/fault-inject.h> |
13 | 12 | ||
14 | /* | 13 | /* |
15 | * setup_fault_attr() is a helper function for various __setup handlers, so it | 14 | * setup_fault_attr() is a helper function for various __setup handlers, so it |
16 | * returns 0 on error, because that is what __setup handlers do. | 15 | * returns 0 on error, because that is what __setup handlers do. |
17 | */ | 16 | */ |
18 | int __init setup_fault_attr(struct fault_attr *attr, char *str) | 17 | int __init setup_fault_attr(struct fault_attr *attr, char *str) |
19 | { | 18 | { |
20 | unsigned long probability; | 19 | unsigned long probability; |
21 | unsigned long interval; | 20 | unsigned long interval; |
22 | int times; | 21 | int times; |
23 | int space; | 22 | int space; |
24 | 23 | ||
25 | /* "<interval>,<probability>,<space>,<times>" */ | 24 | /* "<interval>,<probability>,<space>,<times>" */ |
26 | if (sscanf(str, "%lu,%lu,%d,%d", | 25 | if (sscanf(str, "%lu,%lu,%d,%d", |
27 | &interval, &probability, &space, ×) < 4) { | 26 | &interval, &probability, &space, ×) < 4) { |
28 | printk(KERN_WARNING | 27 | printk(KERN_WARNING |
29 | "FAULT_INJECTION: failed to parse arguments\n"); | 28 | "FAULT_INJECTION: failed to parse arguments\n"); |
30 | return 0; | 29 | return 0; |
31 | } | 30 | } |
32 | 31 | ||
33 | attr->probability = probability; | 32 | attr->probability = probability; |
34 | attr->interval = interval; | 33 | attr->interval = interval; |
35 | atomic_set(&attr->times, times); | 34 | atomic_set(&attr->times, times); |
36 | atomic_set(&attr->space, space); | 35 | atomic_set(&attr->space, space); |
37 | 36 | ||
38 | return 1; | 37 | return 1; |
39 | } | 38 | } |
40 | 39 | ||
41 | static void fail_dump(struct fault_attr *attr) | 40 | static void fail_dump(struct fault_attr *attr) |
42 | { | 41 | { |
43 | if (attr->verbose > 0) | 42 | if (attr->verbose > 0) |
44 | printk(KERN_NOTICE "FAULT_INJECTION: forcing a failure\n"); | 43 | printk(KERN_NOTICE "FAULT_INJECTION: forcing a failure\n"); |
45 | if (attr->verbose > 1) | 44 | if (attr->verbose > 1) |
46 | dump_stack(); | 45 | dump_stack(); |
47 | } | 46 | } |
48 | 47 | ||
49 | #define atomic_dec_not_zero(v) atomic_add_unless((v), -1, 0) | 48 | #define atomic_dec_not_zero(v) atomic_add_unless((v), -1, 0) |
50 | 49 | ||
51 | static bool fail_task(struct fault_attr *attr, struct task_struct *task) | 50 | static bool fail_task(struct fault_attr *attr, struct task_struct *task) |
52 | { | 51 | { |
53 | return !in_interrupt() && task->make_it_fail; | 52 | return !in_interrupt() && task->make_it_fail; |
54 | } | 53 | } |
55 | 54 | ||
56 | #define MAX_STACK_TRACE_DEPTH 32 | 55 | #define MAX_STACK_TRACE_DEPTH 32 |
57 | 56 | ||
58 | #ifdef CONFIG_FAULT_INJECTION_STACKTRACE_FILTER | 57 | #ifdef CONFIG_FAULT_INJECTION_STACKTRACE_FILTER |
59 | 58 | ||
60 | static bool fail_stacktrace(struct fault_attr *attr) | 59 | static bool fail_stacktrace(struct fault_attr *attr) |
61 | { | 60 | { |
62 | struct stack_trace trace; | 61 | struct stack_trace trace; |
63 | int depth = attr->stacktrace_depth; | 62 | int depth = attr->stacktrace_depth; |
64 | unsigned long entries[MAX_STACK_TRACE_DEPTH]; | 63 | unsigned long entries[MAX_STACK_TRACE_DEPTH]; |
65 | int n; | 64 | int n; |
66 | bool found = (attr->require_start == 0 && attr->require_end == ULONG_MAX); | 65 | bool found = (attr->require_start == 0 && attr->require_end == ULONG_MAX); |
67 | 66 | ||
68 | if (depth == 0) | 67 | if (depth == 0) |
69 | return found; | 68 | return found; |
70 | 69 | ||
71 | trace.nr_entries = 0; | 70 | trace.nr_entries = 0; |
72 | trace.entries = entries; | 71 | trace.entries = entries; |
73 | trace.max_entries = depth; | 72 | trace.max_entries = depth; |
74 | trace.skip = 1; | 73 | trace.skip = 1; |
75 | 74 | ||
76 | save_stack_trace(&trace); | 75 | save_stack_trace(&trace); |
77 | for (n = 0; n < trace.nr_entries; n++) { | 76 | for (n = 0; n < trace.nr_entries; n++) { |
78 | if (attr->reject_start <= entries[n] && | 77 | if (attr->reject_start <= entries[n] && |
79 | entries[n] < attr->reject_end) | 78 | entries[n] < attr->reject_end) |
80 | return false; | 79 | return false; |
81 | if (attr->require_start <= entries[n] && | 80 | if (attr->require_start <= entries[n] && |
82 | entries[n] < attr->require_end) | 81 | entries[n] < attr->require_end) |
83 | found = true; | 82 | found = true; |
84 | } | 83 | } |
85 | return found; | 84 | return found; |
86 | } | 85 | } |
87 | 86 | ||
88 | #else | 87 | #else |
89 | 88 | ||
90 | static inline bool fail_stacktrace(struct fault_attr *attr) | 89 | static inline bool fail_stacktrace(struct fault_attr *attr) |
91 | { | 90 | { |
92 | return true; | 91 | return true; |
93 | } | 92 | } |
94 | 93 | ||
95 | #endif /* CONFIG_FAULT_INJECTION_STACKTRACE_FILTER */ | 94 | #endif /* CONFIG_FAULT_INJECTION_STACKTRACE_FILTER */ |
96 | 95 | ||
97 | /* | 96 | /* |
98 | * This code is stolen from failmalloc-1.0 | 97 | * This code is stolen from failmalloc-1.0 |
99 | * http://www.nongnu.org/failmalloc/ | 98 | * http://www.nongnu.org/failmalloc/ |
100 | */ | 99 | */ |
101 | 100 | ||
102 | bool should_fail(struct fault_attr *attr, ssize_t size) | 101 | bool should_fail(struct fault_attr *attr, ssize_t size) |
103 | { | 102 | { |
104 | if (attr->task_filter && !fail_task(attr, current)) | 103 | if (attr->task_filter && !fail_task(attr, current)) |
105 | return false; | 104 | return false; |
106 | 105 | ||
107 | if (atomic_read(&attr->times) == 0) | 106 | if (atomic_read(&attr->times) == 0) |
108 | return false; | 107 | return false; |
109 | 108 | ||
110 | if (atomic_read(&attr->space) > size) { | 109 | if (atomic_read(&attr->space) > size) { |
111 | atomic_sub(size, &attr->space); | 110 | atomic_sub(size, &attr->space); |
112 | return false; | 111 | return false; |
113 | } | 112 | } |
114 | 113 | ||
115 | if (attr->interval > 1) { | 114 | if (attr->interval > 1) { |
116 | attr->count++; | 115 | attr->count++; |
117 | if (attr->count % attr->interval) | 116 | if (attr->count % attr->interval) |
118 | return false; | 117 | return false; |
119 | } | 118 | } |
120 | 119 | ||
121 | if (attr->probability <= random32() % 100) | 120 | if (attr->probability <= random32() % 100) |
122 | return false; | 121 | return false; |
123 | 122 | ||
124 | if (!fail_stacktrace(attr)) | 123 | if (!fail_stacktrace(attr)) |
125 | return false; | 124 | return false; |
126 | 125 | ||
127 | fail_dump(attr); | 126 | fail_dump(attr); |
128 | 127 | ||
129 | if (atomic_read(&attr->times) != -1) | 128 | if (atomic_read(&attr->times) != -1) |
130 | atomic_dec_not_zero(&attr->times); | 129 | atomic_dec_not_zero(&attr->times); |
131 | 130 | ||
132 | return true; | 131 | return true; |
133 | } | 132 | } |
134 | 133 | ||
135 | #ifdef CONFIG_FAULT_INJECTION_DEBUG_FS | 134 | #ifdef CONFIG_FAULT_INJECTION_DEBUG_FS |
136 | 135 | ||
137 | static int debugfs_ul_set(void *data, u64 val) | 136 | static int debugfs_ul_set(void *data, u64 val) |
138 | { | 137 | { |
139 | *(unsigned long *)data = val; | 138 | *(unsigned long *)data = val; |
140 | return 0; | 139 | return 0; |
141 | } | 140 | } |
142 | 141 | ||
143 | #ifdef CONFIG_FAULT_INJECTION_STACKTRACE_FILTER | 142 | #ifdef CONFIG_FAULT_INJECTION_STACKTRACE_FILTER |
144 | static int debugfs_ul_set_MAX_STACK_TRACE_DEPTH(void *data, u64 val) | 143 | static int debugfs_ul_set_MAX_STACK_TRACE_DEPTH(void *data, u64 val) |
145 | { | 144 | { |
146 | *(unsigned long *)data = | 145 | *(unsigned long *)data = |
147 | val < MAX_STACK_TRACE_DEPTH ? | 146 | val < MAX_STACK_TRACE_DEPTH ? |
148 | val : MAX_STACK_TRACE_DEPTH; | 147 | val : MAX_STACK_TRACE_DEPTH; |
149 | return 0; | 148 | return 0; |
150 | } | 149 | } |
151 | #endif /* CONFIG_FAULT_INJECTION_STACKTRACE_FILTER */ | 150 | #endif /* CONFIG_FAULT_INJECTION_STACKTRACE_FILTER */ |
152 | 151 | ||
153 | static int debugfs_ul_get(void *data, u64 *val) | 152 | static int debugfs_ul_get(void *data, u64 *val) |
154 | { | 153 | { |
155 | *val = *(unsigned long *)data; | 154 | *val = *(unsigned long *)data; |
156 | return 0; | 155 | return 0; |
157 | } | 156 | } |
158 | 157 | ||
159 | DEFINE_SIMPLE_ATTRIBUTE(fops_ul, debugfs_ul_get, debugfs_ul_set, "%llu\n"); | 158 | DEFINE_SIMPLE_ATTRIBUTE(fops_ul, debugfs_ul_get, debugfs_ul_set, "%llu\n"); |
160 | 159 | ||
161 | static struct dentry *debugfs_create_ul(const char *name, mode_t mode, | 160 | static struct dentry *debugfs_create_ul(const char *name, mode_t mode, |
162 | struct dentry *parent, unsigned long *value) | 161 | struct dentry *parent, unsigned long *value) |
163 | { | 162 | { |
164 | return debugfs_create_file(name, mode, parent, value, &fops_ul); | 163 | return debugfs_create_file(name, mode, parent, value, &fops_ul); |
165 | } | 164 | } |
166 | 165 | ||
167 | #ifdef CONFIG_FAULT_INJECTION_STACKTRACE_FILTER | 166 | #ifdef CONFIG_FAULT_INJECTION_STACKTRACE_FILTER |
168 | DEFINE_SIMPLE_ATTRIBUTE(fops_ul_MAX_STACK_TRACE_DEPTH, debugfs_ul_get, | 167 | DEFINE_SIMPLE_ATTRIBUTE(fops_ul_MAX_STACK_TRACE_DEPTH, debugfs_ul_get, |
169 | debugfs_ul_set_MAX_STACK_TRACE_DEPTH, "%llu\n"); | 168 | debugfs_ul_set_MAX_STACK_TRACE_DEPTH, "%llu\n"); |
170 | 169 | ||
171 | static struct dentry *debugfs_create_ul_MAX_STACK_TRACE_DEPTH( | 170 | static struct dentry *debugfs_create_ul_MAX_STACK_TRACE_DEPTH( |
172 | const char *name, mode_t mode, | 171 | const char *name, mode_t mode, |
173 | struct dentry *parent, unsigned long *value) | 172 | struct dentry *parent, unsigned long *value) |
174 | { | 173 | { |
175 | return debugfs_create_file(name, mode, parent, value, | 174 | return debugfs_create_file(name, mode, parent, value, |
176 | &fops_ul_MAX_STACK_TRACE_DEPTH); | 175 | &fops_ul_MAX_STACK_TRACE_DEPTH); |
177 | } | 176 | } |
178 | #endif /* CONFIG_FAULT_INJECTION_STACKTRACE_FILTER */ | 177 | #endif /* CONFIG_FAULT_INJECTION_STACKTRACE_FILTER */ |
179 | 178 | ||
180 | static int debugfs_atomic_t_set(void *data, u64 val) | 179 | static int debugfs_atomic_t_set(void *data, u64 val) |
181 | { | 180 | { |
182 | atomic_set((atomic_t *)data, val); | 181 | atomic_set((atomic_t *)data, val); |
183 | return 0; | 182 | return 0; |
184 | } | 183 | } |
185 | 184 | ||
186 | static int debugfs_atomic_t_get(void *data, u64 *val) | 185 | static int debugfs_atomic_t_get(void *data, u64 *val) |
187 | { | 186 | { |
188 | *val = atomic_read((atomic_t *)data); | 187 | *val = atomic_read((atomic_t *)data); |
189 | return 0; | 188 | return 0; |
190 | } | 189 | } |
191 | 190 | ||
192 | DEFINE_SIMPLE_ATTRIBUTE(fops_atomic_t, debugfs_atomic_t_get, | 191 | DEFINE_SIMPLE_ATTRIBUTE(fops_atomic_t, debugfs_atomic_t_get, |
193 | debugfs_atomic_t_set, "%lld\n"); | 192 | debugfs_atomic_t_set, "%lld\n"); |
194 | 193 | ||
195 | static struct dentry *debugfs_create_atomic_t(const char *name, mode_t mode, | 194 | static struct dentry *debugfs_create_atomic_t(const char *name, mode_t mode, |
196 | struct dentry *parent, atomic_t *value) | 195 | struct dentry *parent, atomic_t *value) |
197 | { | 196 | { |
198 | return debugfs_create_file(name, mode, parent, value, &fops_atomic_t); | 197 | return debugfs_create_file(name, mode, parent, value, &fops_atomic_t); |
199 | } | 198 | } |
200 | 199 | ||
201 | void cleanup_fault_attr_dentries(struct fault_attr *attr) | 200 | void cleanup_fault_attr_dentries(struct fault_attr *attr) |
202 | { | 201 | { |
203 | debugfs_remove(attr->dentries.probability_file); | 202 | debugfs_remove(attr->dentries.probability_file); |
204 | attr->dentries.probability_file = NULL; | 203 | attr->dentries.probability_file = NULL; |
205 | 204 | ||
206 | debugfs_remove(attr->dentries.interval_file); | 205 | debugfs_remove(attr->dentries.interval_file); |
207 | attr->dentries.interval_file = NULL; | 206 | attr->dentries.interval_file = NULL; |
208 | 207 | ||
209 | debugfs_remove(attr->dentries.times_file); | 208 | debugfs_remove(attr->dentries.times_file); |
210 | attr->dentries.times_file = NULL; | 209 | attr->dentries.times_file = NULL; |
211 | 210 | ||
212 | debugfs_remove(attr->dentries.space_file); | 211 | debugfs_remove(attr->dentries.space_file); |
213 | attr->dentries.space_file = NULL; | 212 | attr->dentries.space_file = NULL; |
214 | 213 | ||
215 | debugfs_remove(attr->dentries.verbose_file); | 214 | debugfs_remove(attr->dentries.verbose_file); |
216 | attr->dentries.verbose_file = NULL; | 215 | attr->dentries.verbose_file = NULL; |
217 | 216 | ||
218 | debugfs_remove(attr->dentries.task_filter_file); | 217 | debugfs_remove(attr->dentries.task_filter_file); |
219 | attr->dentries.task_filter_file = NULL; | 218 | attr->dentries.task_filter_file = NULL; |
220 | 219 | ||
221 | #ifdef CONFIG_FAULT_INJECTION_STACKTRACE_FILTER | 220 | #ifdef CONFIG_FAULT_INJECTION_STACKTRACE_FILTER |
222 | 221 | ||
223 | debugfs_remove(attr->dentries.stacktrace_depth_file); | 222 | debugfs_remove(attr->dentries.stacktrace_depth_file); |
224 | attr->dentries.stacktrace_depth_file = NULL; | 223 | attr->dentries.stacktrace_depth_file = NULL; |
225 | 224 | ||
226 | debugfs_remove(attr->dentries.require_start_file); | 225 | debugfs_remove(attr->dentries.require_start_file); |
227 | attr->dentries.require_start_file = NULL; | 226 | attr->dentries.require_start_file = NULL; |
228 | 227 | ||
229 | debugfs_remove(attr->dentries.require_end_file); | 228 | debugfs_remove(attr->dentries.require_end_file); |
230 | attr->dentries.require_end_file = NULL; | 229 | attr->dentries.require_end_file = NULL; |
231 | 230 | ||
232 | debugfs_remove(attr->dentries.reject_start_file); | 231 | debugfs_remove(attr->dentries.reject_start_file); |
233 | attr->dentries.reject_start_file = NULL; | 232 | attr->dentries.reject_start_file = NULL; |
234 | 233 | ||
235 | debugfs_remove(attr->dentries.reject_end_file); | 234 | debugfs_remove(attr->dentries.reject_end_file); |
236 | attr->dentries.reject_end_file = NULL; | 235 | attr->dentries.reject_end_file = NULL; |
237 | 236 | ||
238 | #endif /* CONFIG_FAULT_INJECTION_STACKTRACE_FILTER */ | 237 | #endif /* CONFIG_FAULT_INJECTION_STACKTRACE_FILTER */ |
239 | 238 | ||
240 | if (attr->dentries.dir) | 239 | if (attr->dentries.dir) |
241 | WARN_ON(!simple_empty(attr->dentries.dir)); | 240 | WARN_ON(!simple_empty(attr->dentries.dir)); |
242 | 241 | ||
243 | debugfs_remove(attr->dentries.dir); | 242 | debugfs_remove(attr->dentries.dir); |
244 | attr->dentries.dir = NULL; | 243 | attr->dentries.dir = NULL; |
245 | } | 244 | } |
246 | 245 | ||
247 | int init_fault_attr_dentries(struct fault_attr *attr, const char *name) | 246 | int init_fault_attr_dentries(struct fault_attr *attr, const char *name) |
248 | { | 247 | { |
249 | mode_t mode = S_IFREG | S_IRUSR | S_IWUSR; | 248 | mode_t mode = S_IFREG | S_IRUSR | S_IWUSR; |
250 | struct dentry *dir; | 249 | struct dentry *dir; |
251 | 250 | ||
252 | memset(&attr->dentries, 0, sizeof(attr->dentries)); | 251 | memset(&attr->dentries, 0, sizeof(attr->dentries)); |
253 | 252 | ||
254 | dir = debugfs_create_dir(name, NULL); | 253 | dir = debugfs_create_dir(name, NULL); |
255 | if (!dir) | 254 | if (!dir) |
256 | goto fail; | 255 | goto fail; |
257 | attr->dentries.dir = dir; | 256 | attr->dentries.dir = dir; |
258 | 257 | ||
259 | attr->dentries.probability_file = | 258 | attr->dentries.probability_file = |
260 | debugfs_create_ul("probability", mode, dir, &attr->probability); | 259 | debugfs_create_ul("probability", mode, dir, &attr->probability); |
261 | 260 | ||
262 | attr->dentries.interval_file = | 261 | attr->dentries.interval_file = |
263 | debugfs_create_ul("interval", mode, dir, &attr->interval); | 262 | debugfs_create_ul("interval", mode, dir, &attr->interval); |
264 | 263 | ||
265 | attr->dentries.times_file = | 264 | attr->dentries.times_file = |
266 | debugfs_create_atomic_t("times", mode, dir, &attr->times); | 265 | debugfs_create_atomic_t("times", mode, dir, &attr->times); |
267 | 266 | ||
268 | attr->dentries.space_file = | 267 | attr->dentries.space_file = |
269 | debugfs_create_atomic_t("space", mode, dir, &attr->space); | 268 | debugfs_create_atomic_t("space", mode, dir, &attr->space); |
270 | 269 | ||
271 | attr->dentries.verbose_file = | 270 | attr->dentries.verbose_file = |
272 | debugfs_create_ul("verbose", mode, dir, &attr->verbose); | 271 | debugfs_create_ul("verbose", mode, dir, &attr->verbose); |
273 | 272 | ||
274 | attr->dentries.task_filter_file = debugfs_create_bool("task-filter", | 273 | attr->dentries.task_filter_file = debugfs_create_bool("task-filter", |
275 | mode, dir, &attr->task_filter); | 274 | mode, dir, &attr->task_filter); |
276 | 275 | ||
277 | if (!attr->dentries.probability_file || !attr->dentries.interval_file || | 276 | if (!attr->dentries.probability_file || !attr->dentries.interval_file || |
278 | !attr->dentries.times_file || !attr->dentries.space_file || | 277 | !attr->dentries.times_file || !attr->dentries.space_file || |
279 | !attr->dentries.verbose_file || !attr->dentries.task_filter_file) | 278 | !attr->dentries.verbose_file || !attr->dentries.task_filter_file) |
280 | goto fail; | 279 | goto fail; |
281 | 280 | ||
282 | #ifdef CONFIG_FAULT_INJECTION_STACKTRACE_FILTER | 281 | #ifdef CONFIG_FAULT_INJECTION_STACKTRACE_FILTER |
283 | 282 | ||
284 | attr->dentries.stacktrace_depth_file = | 283 | attr->dentries.stacktrace_depth_file = |
285 | debugfs_create_ul_MAX_STACK_TRACE_DEPTH( | 284 | debugfs_create_ul_MAX_STACK_TRACE_DEPTH( |
286 | "stacktrace-depth", mode, dir, &attr->stacktrace_depth); | 285 | "stacktrace-depth", mode, dir, &attr->stacktrace_depth); |
287 | 286 | ||
288 | attr->dentries.require_start_file = | 287 | attr->dentries.require_start_file = |
289 | debugfs_create_ul("require-start", mode, dir, &attr->require_start); | 288 | debugfs_create_ul("require-start", mode, dir, &attr->require_start); |
290 | 289 | ||
291 | attr->dentries.require_end_file = | 290 | attr->dentries.require_end_file = |
292 | debugfs_create_ul("require-end", mode, dir, &attr->require_end); | 291 | debugfs_create_ul("require-end", mode, dir, &attr->require_end); |
293 | 292 | ||
294 | attr->dentries.reject_start_file = | 293 | attr->dentries.reject_start_file = |
295 | debugfs_create_ul("reject-start", mode, dir, &attr->reject_start); | 294 | debugfs_create_ul("reject-start", mode, dir, &attr->reject_start); |
296 | 295 | ||
297 | attr->dentries.reject_end_file = | 296 | attr->dentries.reject_end_file = |
298 | debugfs_create_ul("reject-end", mode, dir, &attr->reject_end); | 297 | debugfs_create_ul("reject-end", mode, dir, &attr->reject_end); |
299 | 298 | ||
300 | if (!attr->dentries.stacktrace_depth_file || | 299 | if (!attr->dentries.stacktrace_depth_file || |
301 | !attr->dentries.require_start_file || | 300 | !attr->dentries.require_start_file || |
302 | !attr->dentries.require_end_file || | 301 | !attr->dentries.require_end_file || |
303 | !attr->dentries.reject_start_file || | 302 | !attr->dentries.reject_start_file || |
304 | !attr->dentries.reject_end_file) | 303 | !attr->dentries.reject_end_file) |
305 | goto fail; | 304 | goto fail; |
306 | 305 | ||
307 | #endif /* CONFIG_FAULT_INJECTION_STACKTRACE_FILTER */ | 306 | #endif /* CONFIG_FAULT_INJECTION_STACKTRACE_FILTER */ |
308 | 307 | ||
309 | return 0; | 308 | return 0; |
310 | fail: | 309 | fail: |
311 | cleanup_fault_attr_dentries(attr); | 310 | cleanup_fault_attr_dentries(attr); |
312 | return -ENOMEM; | 311 | return -ENOMEM; |
313 | } | 312 | } |
314 | 313 | ||
315 | #endif /* CONFIG_FAULT_INJECTION_DEBUG_FS */ | 314 | #endif /* CONFIG_FAULT_INJECTION_DEBUG_FS */ |
316 | 315 |