diff options
Diffstat (limited to 'kernel/sys.c')
-rw-r--r-- | kernel/sys.c | 586 |
1 files changed, 33 insertions, 553 deletions
diff --git a/kernel/sys.c b/kernel/sys.c index bc8879c822a5..304b5410d746 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; |
@@ -683,7 +152,7 @@ asmlinkage long sys_setpriority(int which, int who, int niceval) | |||
683 | switch (which) { | 152 | switch (which) { |
684 | case PRIO_PROCESS: | 153 | case PRIO_PROCESS: |
685 | if (who) | 154 | if (who) |
686 | p = find_task_by_pid(who); | 155 | p = find_task_by_vpid(who); |
687 | else | 156 | else |
688 | p = current; | 157 | p = current; |
689 | if (p) | 158 | if (p) |
@@ -691,7 +160,7 @@ asmlinkage long sys_setpriority(int which, int who, int niceval) | |||
691 | break; | 160 | break; |
692 | case PRIO_PGRP: | 161 | case PRIO_PGRP: |
693 | if (who) | 162 | if (who) |
694 | pgrp = find_pid(who); | 163 | pgrp = find_vpid(who); |
695 | else | 164 | else |
696 | pgrp = task_pgrp(current); | 165 | pgrp = task_pgrp(current); |
697 | do_each_pid_task(pgrp, PIDTYPE_PGID, p) { | 166 | do_each_pid_task(pgrp, PIDTYPE_PGID, p) { |
@@ -740,7 +209,7 @@ asmlinkage long sys_getpriority(int which, int who) | |||
740 | switch (which) { | 209 | switch (which) { |
741 | case PRIO_PROCESS: | 210 | case PRIO_PROCESS: |
742 | if (who) | 211 | if (who) |
743 | p = find_task_by_pid(who); | 212 | p = find_task_by_vpid(who); |
744 | else | 213 | else |
745 | p = current; | 214 | p = current; |
746 | if (p) { | 215 | if (p) { |
@@ -751,7 +220,7 @@ asmlinkage long sys_getpriority(int which, int who) | |||
751 | break; | 220 | break; |
752 | case PRIO_PGRP: | 221 | case PRIO_PGRP: |
753 | if (who) | 222 | if (who) |
754 | pgrp = find_pid(who); | 223 | pgrp = find_vpid(who); |
755 | else | 224 | else |
756 | pgrp = task_pgrp(current); | 225 | pgrp = task_pgrp(current); |
757 | do_each_pid_task(pgrp, PIDTYPE_PGID, p) { | 226 | do_each_pid_task(pgrp, PIDTYPE_PGID, p) { |
@@ -1448,9 +917,10 @@ asmlinkage long sys_setpgid(pid_t pid, pid_t pgid) | |||
1448 | struct task_struct *p; | 917 | struct task_struct *p; |
1449 | struct task_struct *group_leader = current->group_leader; | 918 | struct task_struct *group_leader = current->group_leader; |
1450 | int err = -EINVAL; | 919 | int err = -EINVAL; |
920 | struct pid_namespace *ns; | ||
1451 | 921 | ||
1452 | if (!pid) | 922 | if (!pid) |
1453 | pid = group_leader->pid; | 923 | pid = task_pid_vnr(group_leader); |
1454 | if (!pgid) | 924 | if (!pgid) |
1455 | pgid = pid; | 925 | pgid = pid; |
1456 | if (pgid < 0) | 926 | if (pgid < 0) |
@@ -1459,10 +929,12 @@ asmlinkage long sys_setpgid(pid_t pid, pid_t pgid) | |||
1459 | /* From this point forward we keep holding onto the tasklist lock | 929 | /* From this point forward we keep holding onto the tasklist lock |
1460 | * so that our parent does not change from under us. -DaveM | 930 | * so that our parent does not change from under us. -DaveM |
1461 | */ | 931 | */ |
932 | ns = current->nsproxy->pid_ns; | ||
933 | |||
1462 | write_lock_irq(&tasklist_lock); | 934 | write_lock_irq(&tasklist_lock); |
1463 | 935 | ||
1464 | err = -ESRCH; | 936 | err = -ESRCH; |
1465 | p = find_task_by_pid(pid); | 937 | p = find_task_by_pid_ns(pid, ns); |
1466 | if (!p) | 938 | if (!p) |
1467 | goto out; | 939 | goto out; |
1468 | 940 | ||
@@ -1488,9 +960,9 @@ asmlinkage long sys_setpgid(pid_t pid, pid_t pgid) | |||
1488 | goto out; | 960 | goto out; |
1489 | 961 | ||
1490 | if (pgid != pid) { | 962 | if (pgid != pid) { |
1491 | struct task_struct *g = | 963 | struct task_struct *g; |
1492 | find_task_by_pid_type(PIDTYPE_PGID, pgid); | ||
1493 | 964 | ||
965 | g = find_task_by_pid_type_ns(PIDTYPE_PGID, pgid, ns); | ||
1494 | if (!g || task_session(g) != task_session(group_leader)) | 966 | if (!g || task_session(g) != task_session(group_leader)) |
1495 | goto out; | 967 | goto out; |
1496 | } | 968 | } |
@@ -1499,10 +971,13 @@ asmlinkage long sys_setpgid(pid_t pid, pid_t pgid) | |||
1499 | if (err) | 971 | if (err) |
1500 | goto out; | 972 | goto out; |
1501 | 973 | ||
1502 | if (process_group(p) != pgid) { | 974 | if (task_pgrp_nr_ns(p, ns) != pgid) { |
975 | struct pid *pid; | ||
976 | |||
1503 | detach_pid(p, PIDTYPE_PGID); | 977 | detach_pid(p, PIDTYPE_PGID); |
1504 | p->signal->pgrp = pgid; | 978 | pid = find_vpid(pgid); |
1505 | attach_pid(p, PIDTYPE_PGID, find_pid(pgid)); | 979 | attach_pid(p, PIDTYPE_PGID, pid); |
980 | set_task_pgrp(p, pid_nr(pid)); | ||
1506 | } | 981 | } |
1507 | 982 | ||
1508 | err = 0; | 983 | err = 0; |
@@ -1515,19 +990,21 @@ out: | |||
1515 | asmlinkage long sys_getpgid(pid_t pid) | 990 | asmlinkage long sys_getpgid(pid_t pid) |
1516 | { | 991 | { |
1517 | if (!pid) | 992 | if (!pid) |
1518 | return process_group(current); | 993 | return task_pgrp_vnr(current); |
1519 | else { | 994 | else { |
1520 | int retval; | 995 | int retval; |
1521 | struct task_struct *p; | 996 | struct task_struct *p; |
997 | struct pid_namespace *ns; | ||
1522 | 998 | ||
1523 | read_lock(&tasklist_lock); | 999 | ns = current->nsproxy->pid_ns; |
1524 | p = find_task_by_pid(pid); | ||
1525 | 1000 | ||
1001 | read_lock(&tasklist_lock); | ||
1002 | p = find_task_by_pid_ns(pid, ns); | ||
1526 | retval = -ESRCH; | 1003 | retval = -ESRCH; |
1527 | if (p) { | 1004 | if (p) { |
1528 | retval = security_task_getpgid(p); | 1005 | retval = security_task_getpgid(p); |
1529 | if (!retval) | 1006 | if (!retval) |
1530 | retval = process_group(p); | 1007 | retval = task_pgrp_nr_ns(p, ns); |
1531 | } | 1008 | } |
1532 | read_unlock(&tasklist_lock); | 1009 | read_unlock(&tasklist_lock); |
1533 | return retval; | 1010 | return retval; |
@@ -1539,7 +1016,7 @@ asmlinkage long sys_getpgid(pid_t pid) | |||
1539 | asmlinkage long sys_getpgrp(void) | 1016 | asmlinkage long sys_getpgrp(void) |
1540 | { | 1017 | { |
1541 | /* SMP - assuming writes are word atomic this is fine */ | 1018 | /* SMP - assuming writes are word atomic this is fine */ |
1542 | return process_group(current); | 1019 | return task_pgrp_vnr(current); |
1543 | } | 1020 | } |
1544 | 1021 | ||
1545 | #endif | 1022 | #endif |
@@ -1547,19 +1024,21 @@ asmlinkage long sys_getpgrp(void) | |||
1547 | asmlinkage long sys_getsid(pid_t pid) | 1024 | asmlinkage long sys_getsid(pid_t pid) |
1548 | { | 1025 | { |
1549 | if (!pid) | 1026 | if (!pid) |
1550 | return process_session(current); | 1027 | return task_session_vnr(current); |
1551 | else { | 1028 | else { |
1552 | int retval; | 1029 | int retval; |
1553 | struct task_struct *p; | 1030 | struct task_struct *p; |
1031 | struct pid_namespace *ns; | ||
1554 | 1032 | ||
1555 | read_lock(&tasklist_lock); | 1033 | ns = current->nsproxy->pid_ns; |
1556 | p = find_task_by_pid(pid); | ||
1557 | 1034 | ||
1035 | read_lock(&tasklist_lock); | ||
1036 | p = find_task_by_pid_ns(pid, ns); | ||
1558 | retval = -ESRCH; | 1037 | retval = -ESRCH; |
1559 | if (p) { | 1038 | if (p) { |
1560 | retval = security_task_getsid(p); | 1039 | retval = security_task_getsid(p); |
1561 | if (!retval) | 1040 | if (!retval) |
1562 | retval = process_session(p); | 1041 | retval = task_session_nr_ns(p, ns); |
1563 | } | 1042 | } |
1564 | read_unlock(&tasklist_lock); | 1043 | read_unlock(&tasklist_lock); |
1565 | return retval; | 1044 | return retval; |
@@ -1586,7 +1065,8 @@ asmlinkage long sys_setsid(void) | |||
1586 | * session id and so the check will always fail and make it so | 1065 | * session id and so the check will always fail and make it so |
1587 | * init cannot successfully call setsid. | 1066 | * init cannot successfully call setsid. |
1588 | */ | 1067 | */ |
1589 | if (session > 1 && find_task_by_pid_type(PIDTYPE_PGID, session)) | 1068 | if (session > 1 && find_task_by_pid_type_ns(PIDTYPE_PGID, |
1069 | session, &init_pid_ns)) | ||
1590 | goto out; | 1070 | goto out; |
1591 | 1071 | ||
1592 | group_leader->signal->leader = 1; | 1072 | group_leader->signal->leader = 1; |
@@ -1596,7 +1076,7 @@ asmlinkage long sys_setsid(void) | |||
1596 | group_leader->signal->tty = NULL; | 1076 | group_leader->signal->tty = NULL; |
1597 | spin_unlock(&group_leader->sighand->siglock); | 1077 | spin_unlock(&group_leader->sighand->siglock); |
1598 | 1078 | ||
1599 | err = process_group(group_leader); | 1079 | err = task_pgrp_vnr(group_leader); |
1600 | out: | 1080 | out: |
1601 | write_unlock_irq(&tasklist_lock); | 1081 | write_unlock_irq(&tasklist_lock); |
1602 | return err; | 1082 | return err; |