diff options
Diffstat (limited to 'kernel/sys.c')
-rw-r--r-- | kernel/sys.c | 531 |
1 files changed, 0 insertions, 531 deletions
diff --git a/kernel/sys.c b/kernel/sys.c index bc8879c822a5..b8fcbc640193 100644 --- a/kernel/sys.c +++ b/kernel/sys.c | |||
@@ -106,537 +106,6 @@ EXPORT_SYMBOL(cad_pid); | |||
106 | 106 | ||
107 | void (*pm_power_off_prepare)(void); | 107 | void (*pm_power_off_prepare)(void); |
108 | 108 | ||
109 | /* | ||
110 | * Notifier list for kernel code which wants to be called | ||
111 | * at shutdown. This is used to stop any idling DMA operations | ||
112 | * and the like. | ||
113 | */ | ||
114 | |||
115 | static BLOCKING_NOTIFIER_HEAD(reboot_notifier_list); | ||
116 | |||
117 | /* | ||
118 | * Notifier chain core routines. The exported routines below | ||
119 | * are layered on top of these, with appropriate locking added. | ||
120 | */ | ||
121 | |||
122 | static int notifier_chain_register(struct notifier_block **nl, | ||
123 | struct notifier_block *n) | ||
124 | { | ||
125 | while ((*nl) != NULL) { | ||
126 | if (n->priority > (*nl)->priority) | ||
127 | break; | ||
128 | nl = &((*nl)->next); | ||
129 | } | ||
130 | n->next = *nl; | ||
131 | rcu_assign_pointer(*nl, n); | ||
132 | return 0; | ||
133 | } | ||
134 | |||
135 | static int notifier_chain_unregister(struct notifier_block **nl, | ||
136 | struct notifier_block *n) | ||
137 | { | ||
138 | while ((*nl) != NULL) { | ||
139 | if ((*nl) == n) { | ||
140 | rcu_assign_pointer(*nl, n->next); | ||
141 | return 0; | ||
142 | } | ||
143 | nl = &((*nl)->next); | ||
144 | } | ||
145 | return -ENOENT; | ||
146 | } | ||
147 | |||
148 | /** | ||
149 | * notifier_call_chain - Informs the registered notifiers about an event. | ||
150 | * @nl: Pointer to head of the blocking notifier chain | ||
151 | * @val: Value passed unmodified to notifier function | ||
152 | * @v: Pointer passed unmodified to notifier function | ||
153 | * @nr_to_call: Number of notifier functions to be called. Don't care | ||
154 | * value of this parameter is -1. | ||
155 | * @nr_calls: Records the number of notifications sent. Don't care | ||
156 | * value of this field is NULL. | ||
157 | * @returns: notifier_call_chain returns the value returned by the | ||
158 | * last notifier function called. | ||
159 | */ | ||
160 | |||
161 | static int __kprobes notifier_call_chain(struct notifier_block **nl, | ||
162 | unsigned long val, void *v, | ||
163 | int nr_to_call, int *nr_calls) | ||
164 | { | ||
165 | int ret = NOTIFY_DONE; | ||
166 | struct notifier_block *nb, *next_nb; | ||
167 | |||
168 | nb = rcu_dereference(*nl); | ||
169 | |||
170 | while (nb && nr_to_call) { | ||
171 | next_nb = rcu_dereference(nb->next); | ||
172 | ret = nb->notifier_call(nb, val, v); | ||
173 | |||
174 | if (nr_calls) | ||
175 | (*nr_calls)++; | ||
176 | |||
177 | if ((ret & NOTIFY_STOP_MASK) == NOTIFY_STOP_MASK) | ||
178 | break; | ||
179 | nb = next_nb; | ||
180 | nr_to_call--; | ||
181 | } | ||
182 | return ret; | ||
183 | } | ||
184 | |||
185 | /* | ||
186 | * Atomic notifier chain routines. Registration and unregistration | ||
187 | * use a spinlock, and call_chain is synchronized by RCU (no locks). | ||
188 | */ | ||
189 | |||
190 | /** | ||
191 | * atomic_notifier_chain_register - Add notifier to an atomic notifier chain | ||
192 | * @nh: Pointer to head of the atomic notifier chain | ||
193 | * @n: New entry in notifier chain | ||
194 | * | ||
195 | * Adds a notifier to an atomic notifier chain. | ||
196 | * | ||
197 | * Currently always returns zero. | ||
198 | */ | ||
199 | |||
200 | int atomic_notifier_chain_register(struct atomic_notifier_head *nh, | ||
201 | struct notifier_block *n) | ||
202 | { | ||
203 | unsigned long flags; | ||
204 | int ret; | ||
205 | |||
206 | spin_lock_irqsave(&nh->lock, flags); | ||
207 | ret = notifier_chain_register(&nh->head, n); | ||
208 | spin_unlock_irqrestore(&nh->lock, flags); | ||
209 | return ret; | ||
210 | } | ||
211 | |||
212 | EXPORT_SYMBOL_GPL(atomic_notifier_chain_register); | ||
213 | |||
214 | /** | ||
215 | * atomic_notifier_chain_unregister - Remove notifier from an atomic notifier chain | ||
216 | * @nh: Pointer to head of the atomic notifier chain | ||
217 | * @n: Entry to remove from notifier chain | ||
218 | * | ||
219 | * Removes a notifier from an atomic notifier chain. | ||
220 | * | ||
221 | * Returns zero on success or %-ENOENT on failure. | ||
222 | */ | ||
223 | int atomic_notifier_chain_unregister(struct atomic_notifier_head *nh, | ||
224 | struct notifier_block *n) | ||
225 | { | ||
226 | unsigned long flags; | ||
227 | int ret; | ||
228 | |||
229 | spin_lock_irqsave(&nh->lock, flags); | ||
230 | ret = notifier_chain_unregister(&nh->head, n); | ||
231 | spin_unlock_irqrestore(&nh->lock, flags); | ||
232 | synchronize_rcu(); | ||
233 | return ret; | ||
234 | } | ||
235 | |||
236 | EXPORT_SYMBOL_GPL(atomic_notifier_chain_unregister); | ||
237 | |||
238 | /** | ||
239 | * __atomic_notifier_call_chain - Call functions in an atomic notifier chain | ||
240 | * @nh: Pointer to head of the atomic notifier chain | ||
241 | * @val: Value passed unmodified to notifier function | ||
242 | * @v: Pointer passed unmodified to notifier function | ||
243 | * @nr_to_call: See the comment for notifier_call_chain. | ||
244 | * @nr_calls: See the comment for notifier_call_chain. | ||
245 | * | ||
246 | * Calls each function in a notifier chain in turn. The functions | ||
247 | * run in an atomic context, so they must not block. | ||
248 | * This routine uses RCU to synchronize with changes to the chain. | ||
249 | * | ||
250 | * If the return value of the notifier can be and'ed | ||
251 | * with %NOTIFY_STOP_MASK then atomic_notifier_call_chain() | ||
252 | * will return immediately, with the return value of | ||
253 | * the notifier function which halted execution. | ||
254 | * Otherwise the return value is the return value | ||
255 | * of the last notifier function called. | ||
256 | */ | ||
257 | |||
258 | int __kprobes __atomic_notifier_call_chain(struct atomic_notifier_head *nh, | ||
259 | unsigned long val, void *v, | ||
260 | int nr_to_call, int *nr_calls) | ||
261 | { | ||
262 | int ret; | ||
263 | |||
264 | rcu_read_lock(); | ||
265 | ret = notifier_call_chain(&nh->head, val, v, nr_to_call, nr_calls); | ||
266 | rcu_read_unlock(); | ||
267 | return ret; | ||
268 | } | ||
269 | |||
270 | EXPORT_SYMBOL_GPL(__atomic_notifier_call_chain); | ||
271 | |||
272 | int __kprobes atomic_notifier_call_chain(struct atomic_notifier_head *nh, | ||
273 | unsigned long val, void *v) | ||
274 | { | ||
275 | return __atomic_notifier_call_chain(nh, val, v, -1, NULL); | ||
276 | } | ||
277 | |||
278 | EXPORT_SYMBOL_GPL(atomic_notifier_call_chain); | ||
279 | /* | ||
280 | * Blocking notifier chain routines. All access to the chain is | ||
281 | * synchronized by an rwsem. | ||
282 | */ | ||
283 | |||
284 | /** | ||
285 | * blocking_notifier_chain_register - Add notifier to a blocking notifier chain | ||
286 | * @nh: Pointer to head of the blocking notifier chain | ||
287 | * @n: New entry in notifier chain | ||
288 | * | ||
289 | * Adds a notifier to a blocking notifier chain. | ||
290 | * Must be called in process context. | ||
291 | * | ||
292 | * Currently always returns zero. | ||
293 | */ | ||
294 | |||
295 | int blocking_notifier_chain_register(struct blocking_notifier_head *nh, | ||
296 | struct notifier_block *n) | ||
297 | { | ||
298 | int ret; | ||
299 | |||
300 | /* | ||
301 | * This code gets used during boot-up, when task switching is | ||
302 | * not yet working and interrupts must remain disabled. At | ||
303 | * such times we must not call down_write(). | ||
304 | */ | ||
305 | if (unlikely(system_state == SYSTEM_BOOTING)) | ||
306 | return notifier_chain_register(&nh->head, n); | ||
307 | |||
308 | down_write(&nh->rwsem); | ||
309 | ret = notifier_chain_register(&nh->head, n); | ||
310 | up_write(&nh->rwsem); | ||
311 | return ret; | ||
312 | } | ||
313 | |||
314 | EXPORT_SYMBOL_GPL(blocking_notifier_chain_register); | ||
315 | |||
316 | /** | ||
317 | * blocking_notifier_chain_unregister - Remove notifier from a blocking notifier chain | ||
318 | * @nh: Pointer to head of the blocking notifier chain | ||
319 | * @n: Entry to remove from notifier chain | ||
320 | * | ||
321 | * Removes a notifier from a blocking notifier chain. | ||
322 | * Must be called from process context. | ||
323 | * | ||
324 | * Returns zero on success or %-ENOENT on failure. | ||
325 | */ | ||
326 | int blocking_notifier_chain_unregister(struct blocking_notifier_head *nh, | ||
327 | struct notifier_block *n) | ||
328 | { | ||
329 | int ret; | ||
330 | |||
331 | /* | ||
332 | * This code gets used during boot-up, when task switching is | ||
333 | * not yet working and interrupts must remain disabled. At | ||
334 | * such times we must not call down_write(). | ||
335 | */ | ||
336 | if (unlikely(system_state == SYSTEM_BOOTING)) | ||
337 | return notifier_chain_unregister(&nh->head, n); | ||
338 | |||
339 | down_write(&nh->rwsem); | ||
340 | ret = notifier_chain_unregister(&nh->head, n); | ||
341 | up_write(&nh->rwsem); | ||
342 | return ret; | ||
343 | } | ||
344 | |||
345 | EXPORT_SYMBOL_GPL(blocking_notifier_chain_unregister); | ||
346 | |||
347 | /** | ||
348 | * __blocking_notifier_call_chain - Call functions in a blocking notifier chain | ||
349 | * @nh: Pointer to head of the blocking notifier chain | ||
350 | * @val: Value passed unmodified to notifier function | ||
351 | * @v: Pointer passed unmodified to notifier function | ||
352 | * @nr_to_call: See comment for notifier_call_chain. | ||
353 | * @nr_calls: See comment for notifier_call_chain. | ||
354 | * | ||
355 | * Calls each function in a notifier chain in turn. The functions | ||
356 | * run in a process context, so they are allowed to block. | ||
357 | * | ||
358 | * If the return value of the notifier can be and'ed | ||
359 | * with %NOTIFY_STOP_MASK then blocking_notifier_call_chain() | ||
360 | * will return immediately, with the return value of | ||
361 | * the notifier function which halted execution. | ||
362 | * Otherwise the return value is the return value | ||
363 | * of the last notifier function called. | ||
364 | */ | ||
365 | |||
366 | int __blocking_notifier_call_chain(struct blocking_notifier_head *nh, | ||
367 | unsigned long val, void *v, | ||
368 | int nr_to_call, int *nr_calls) | ||
369 | { | ||
370 | int ret = NOTIFY_DONE; | ||
371 | |||
372 | /* | ||
373 | * We check the head outside the lock, but if this access is | ||
374 | * racy then it does not matter what the result of the test | ||
375 | * is, we re-check the list after having taken the lock anyway: | ||
376 | */ | ||
377 | if (rcu_dereference(nh->head)) { | ||
378 | down_read(&nh->rwsem); | ||
379 | ret = notifier_call_chain(&nh->head, val, v, nr_to_call, | ||
380 | nr_calls); | ||
381 | up_read(&nh->rwsem); | ||
382 | } | ||
383 | return ret; | ||
384 | } | ||
385 | EXPORT_SYMBOL_GPL(__blocking_notifier_call_chain); | ||
386 | |||
387 | int blocking_notifier_call_chain(struct blocking_notifier_head *nh, | ||
388 | unsigned long val, void *v) | ||
389 | { | ||
390 | return __blocking_notifier_call_chain(nh, val, v, -1, NULL); | ||
391 | } | ||
392 | EXPORT_SYMBOL_GPL(blocking_notifier_call_chain); | ||
393 | |||
394 | /* | ||
395 | * Raw notifier chain routines. There is no protection; | ||
396 | * the caller must provide it. Use at your own risk! | ||
397 | */ | ||
398 | |||
399 | /** | ||
400 | * raw_notifier_chain_register - Add notifier to a raw notifier chain | ||
401 | * @nh: Pointer to head of the raw notifier chain | ||
402 | * @n: New entry in notifier chain | ||
403 | * | ||
404 | * Adds a notifier to a raw notifier chain. | ||
405 | * All locking must be provided by the caller. | ||
406 | * | ||
407 | * Currently always returns zero. | ||
408 | */ | ||
409 | |||
410 | int raw_notifier_chain_register(struct raw_notifier_head *nh, | ||
411 | struct notifier_block *n) | ||
412 | { | ||
413 | return notifier_chain_register(&nh->head, n); | ||
414 | } | ||
415 | |||
416 | EXPORT_SYMBOL_GPL(raw_notifier_chain_register); | ||
417 | |||
418 | /** | ||
419 | * raw_notifier_chain_unregister - Remove notifier from a raw notifier chain | ||
420 | * @nh: Pointer to head of the raw notifier chain | ||
421 | * @n: Entry to remove from notifier chain | ||
422 | * | ||
423 | * Removes a notifier from a raw notifier chain. | ||
424 | * All locking must be provided by the caller. | ||
425 | * | ||
426 | * Returns zero on success or %-ENOENT on failure. | ||
427 | */ | ||
428 | int raw_notifier_chain_unregister(struct raw_notifier_head *nh, | ||
429 | struct notifier_block *n) | ||
430 | { | ||
431 | return notifier_chain_unregister(&nh->head, n); | ||
432 | } | ||
433 | |||
434 | EXPORT_SYMBOL_GPL(raw_notifier_chain_unregister); | ||
435 | |||
436 | /** | ||
437 | * __raw_notifier_call_chain - Call functions in a raw notifier chain | ||
438 | * @nh: Pointer to head of the raw notifier chain | ||
439 | * @val: Value passed unmodified to notifier function | ||
440 | * @v: Pointer passed unmodified to notifier function | ||
441 | * @nr_to_call: See comment for notifier_call_chain. | ||
442 | * @nr_calls: See comment for notifier_call_chain | ||
443 | * | ||
444 | * Calls each function in a notifier chain in turn. The functions | ||
445 | * run in an undefined context. | ||
446 | * All locking must be provided by the caller. | ||
447 | * | ||
448 | * If the return value of the notifier can be and'ed | ||
449 | * with %NOTIFY_STOP_MASK then raw_notifier_call_chain() | ||
450 | * will return immediately, with the return value of | ||
451 | * the notifier function which halted execution. | ||
452 | * Otherwise the return value is the return value | ||
453 | * of the last notifier function called. | ||
454 | */ | ||
455 | |||
456 | int __raw_notifier_call_chain(struct raw_notifier_head *nh, | ||
457 | unsigned long val, void *v, | ||
458 | int nr_to_call, int *nr_calls) | ||
459 | { | ||
460 | return notifier_call_chain(&nh->head, val, v, nr_to_call, nr_calls); | ||
461 | } | ||
462 | |||
463 | EXPORT_SYMBOL_GPL(__raw_notifier_call_chain); | ||
464 | |||
465 | int raw_notifier_call_chain(struct raw_notifier_head *nh, | ||
466 | unsigned long val, void *v) | ||
467 | { | ||
468 | return __raw_notifier_call_chain(nh, val, v, -1, NULL); | ||
469 | } | ||
470 | |||
471 | EXPORT_SYMBOL_GPL(raw_notifier_call_chain); | ||
472 | |||
473 | /* | ||
474 | * SRCU notifier chain routines. Registration and unregistration | ||
475 | * use a mutex, and call_chain is synchronized by SRCU (no locks). | ||
476 | */ | ||
477 | |||
478 | /** | ||
479 | * srcu_notifier_chain_register - Add notifier to an SRCU notifier chain | ||
480 | * @nh: Pointer to head of the SRCU notifier chain | ||
481 | * @n: New entry in notifier chain | ||
482 | * | ||
483 | * Adds a notifier to an SRCU notifier chain. | ||
484 | * Must be called in process context. | ||
485 | * | ||
486 | * Currently always returns zero. | ||
487 | */ | ||
488 | |||
489 | int srcu_notifier_chain_register(struct srcu_notifier_head *nh, | ||
490 | struct notifier_block *n) | ||
491 | { | ||
492 | int ret; | ||
493 | |||
494 | /* | ||
495 | * This code gets used during boot-up, when task switching is | ||
496 | * not yet working and interrupts must remain disabled. At | ||
497 | * such times we must not call mutex_lock(). | ||
498 | */ | ||
499 | if (unlikely(system_state == SYSTEM_BOOTING)) | ||
500 | return notifier_chain_register(&nh->head, n); | ||
501 | |||
502 | mutex_lock(&nh->mutex); | ||
503 | ret = notifier_chain_register(&nh->head, n); | ||
504 | mutex_unlock(&nh->mutex); | ||
505 | return ret; | ||
506 | } | ||
507 | |||
508 | EXPORT_SYMBOL_GPL(srcu_notifier_chain_register); | ||
509 | |||
510 | /** | ||
511 | * srcu_notifier_chain_unregister - Remove notifier from an SRCU notifier chain | ||
512 | * @nh: Pointer to head of the SRCU notifier chain | ||
513 | * @n: Entry to remove from notifier chain | ||
514 | * | ||
515 | * Removes a notifier from an SRCU notifier chain. | ||
516 | * Must be called from process context. | ||
517 | * | ||
518 | * Returns zero on success or %-ENOENT on failure. | ||
519 | */ | ||
520 | int srcu_notifier_chain_unregister(struct srcu_notifier_head *nh, | ||
521 | struct notifier_block *n) | ||
522 | { | ||
523 | int ret; | ||
524 | |||
525 | /* | ||
526 | * This code gets used during boot-up, when task switching is | ||
527 | * not yet working and interrupts must remain disabled. At | ||
528 | * such times we must not call mutex_lock(). | ||
529 | */ | ||
530 | if (unlikely(system_state == SYSTEM_BOOTING)) | ||
531 | return notifier_chain_unregister(&nh->head, n); | ||
532 | |||
533 | mutex_lock(&nh->mutex); | ||
534 | ret = notifier_chain_unregister(&nh->head, n); | ||
535 | mutex_unlock(&nh->mutex); | ||
536 | synchronize_srcu(&nh->srcu); | ||
537 | return ret; | ||
538 | } | ||
539 | |||
540 | EXPORT_SYMBOL_GPL(srcu_notifier_chain_unregister); | ||
541 | |||
542 | /** | ||
543 | * __srcu_notifier_call_chain - Call functions in an SRCU notifier chain | ||
544 | * @nh: Pointer to head of the SRCU notifier chain | ||
545 | * @val: Value passed unmodified to notifier function | ||
546 | * @v: Pointer passed unmodified to notifier function | ||
547 | * @nr_to_call: See comment for notifier_call_chain. | ||
548 | * @nr_calls: See comment for notifier_call_chain | ||
549 | * | ||
550 | * Calls each function in a notifier chain in turn. The functions | ||
551 | * run in a process context, so they are allowed to block. | ||
552 | * | ||
553 | * If the return value of the notifier can be and'ed | ||
554 | * with %NOTIFY_STOP_MASK then srcu_notifier_call_chain() | ||
555 | * will return immediately, with the return value of | ||
556 | * the notifier function which halted execution. | ||
557 | * Otherwise the return value is the return value | ||
558 | * of the last notifier function called. | ||
559 | */ | ||
560 | |||
561 | int __srcu_notifier_call_chain(struct srcu_notifier_head *nh, | ||
562 | unsigned long val, void *v, | ||
563 | int nr_to_call, int *nr_calls) | ||
564 | { | ||
565 | int ret; | ||
566 | int idx; | ||
567 | |||
568 | idx = srcu_read_lock(&nh->srcu); | ||
569 | ret = notifier_call_chain(&nh->head, val, v, nr_to_call, nr_calls); | ||
570 | srcu_read_unlock(&nh->srcu, idx); | ||
571 | return ret; | ||
572 | } | ||
573 | EXPORT_SYMBOL_GPL(__srcu_notifier_call_chain); | ||
574 | |||
575 | int srcu_notifier_call_chain(struct srcu_notifier_head *nh, | ||
576 | unsigned long val, void *v) | ||
577 | { | ||
578 | return __srcu_notifier_call_chain(nh, val, v, -1, NULL); | ||
579 | } | ||
580 | EXPORT_SYMBOL_GPL(srcu_notifier_call_chain); | ||
581 | |||
582 | /** | ||
583 | * srcu_init_notifier_head - Initialize an SRCU notifier head | ||
584 | * @nh: Pointer to head of the srcu notifier chain | ||
585 | * | ||
586 | * Unlike other sorts of notifier heads, SRCU notifier heads require | ||
587 | * dynamic initialization. Be sure to call this routine before | ||
588 | * calling any of the other SRCU notifier routines for this head. | ||
589 | * | ||
590 | * If an SRCU notifier head is deallocated, it must first be cleaned | ||
591 | * up by calling srcu_cleanup_notifier_head(). Otherwise the head's | ||
592 | * per-cpu data (used by the SRCU mechanism) will leak. | ||
593 | */ | ||
594 | |||
595 | void srcu_init_notifier_head(struct srcu_notifier_head *nh) | ||
596 | { | ||
597 | mutex_init(&nh->mutex); | ||
598 | if (init_srcu_struct(&nh->srcu) < 0) | ||
599 | BUG(); | ||
600 | nh->head = NULL; | ||
601 | } | ||
602 | |||
603 | EXPORT_SYMBOL_GPL(srcu_init_notifier_head); | ||
604 | |||
605 | /** | ||
606 | * register_reboot_notifier - Register function to be called at reboot time | ||
607 | * @nb: Info about notifier function to be called | ||
608 | * | ||
609 | * Registers a function with the list of functions | ||
610 | * to be called at reboot time. | ||
611 | * | ||
612 | * Currently always returns zero, as blocking_notifier_chain_register() | ||
613 | * always returns zero. | ||
614 | */ | ||
615 | |||
616 | int register_reboot_notifier(struct notifier_block * nb) | ||
617 | { | ||
618 | return blocking_notifier_chain_register(&reboot_notifier_list, nb); | ||
619 | } | ||
620 | |||
621 | EXPORT_SYMBOL(register_reboot_notifier); | ||
622 | |||
623 | /** | ||
624 | * unregister_reboot_notifier - Unregister previously registered reboot notifier | ||
625 | * @nb: Hook to be unregistered | ||
626 | * | ||
627 | * Unregisters a previously registered reboot | ||
628 | * notifier function. | ||
629 | * | ||
630 | * Returns zero on success, or %-ENOENT on failure. | ||
631 | */ | ||
632 | |||
633 | int unregister_reboot_notifier(struct notifier_block * nb) | ||
634 | { | ||
635 | return blocking_notifier_chain_unregister(&reboot_notifier_list, nb); | ||
636 | } | ||
637 | |||
638 | EXPORT_SYMBOL(unregister_reboot_notifier); | ||
639 | |||
640 | static int set_one_prio(struct task_struct *p, int niceval, int error) | 109 | static int set_one_prio(struct task_struct *p, int niceval, int error) |
641 | { | 110 | { |
642 | int no_nice; | 111 | int no_nice; |