aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorOleg Nesterov <oleg@tv-sign.ru>2008-09-22 17:42:48 -0400
committerThomas Gleixner <tglx@linutronix.de>2008-09-24 09:45:48 -0400
commit36b2f046000b358b62b9d116cb10a2b1c5be5cbf (patch)
tree577f367d2408d6ed2618d49f412afa91bcb915e8
parent2cd499e38ec241691e4bce50bddc8f57e4cc9bd0 (diff)
posix-timers: sys_timer_create: simplify and s/tasklist/rcu/
- Change the code to do rcu_read_lock() instead of taking tasklist_lock, it is safe to get_task_struct(p) if p was found under RCU. However, now we must not use process's sighand/signal, they may be NULL. We can use current->sighand/signal instead, this "process" must belong to the current's thread-group. - Factor out the common code for 2 "if (timer_event_spec)" branches, the !timer_event_spec case can use current too. - use spin_lock_irq() instead of _irqsave(), kill "flags". Signed-off-by: Oleg Nesterov <oleg@tv-sign.ru> Cc: mingo@elte.hu Cc: Roland McGrath <roland@redhat.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
-rw-r--r--kernel/posix-timers.c23
1 files changed, 8 insertions, 15 deletions
diff --git a/kernel/posix-timers.c b/kernel/posix-timers.c
index 60b262051d1d..5b761903b49a 100644
--- a/kernel/posix-timers.c
+++ b/kernel/posix-timers.c
@@ -463,7 +463,6 @@ sys_timer_create(const clockid_t which_clock,
463 struct k_itimer *new_timer; 463 struct k_itimer *new_timer;
464 int new_timer_id; 464 int new_timer_id;
465 struct task_struct *process; 465 struct task_struct *process;
466 unsigned long flags;
467 sigevent_t event; 466 sigevent_t event;
468 int it_id_set = IT_ID_NOT_SET; 467 int it_id_set = IT_ID_NOT_SET;
469 468
@@ -521,16 +520,11 @@ sys_timer_create(const clockid_t which_clock,
521 new_timer->it_sigev_signo = event.sigev_signo; 520 new_timer->it_sigev_signo = event.sigev_signo;
522 new_timer->it_sigev_value = event.sigev_value; 521 new_timer->it_sigev_value = event.sigev_value;
523 522
524 read_lock(&tasklist_lock); 523 rcu_read_lock();
525 if ((process = good_sigevent(&event))) { 524 process = good_sigevent(&event);
525 if (process)
526 get_task_struct(process); 526 get_task_struct(process);
527 spin_lock_irqsave(&process->sighand->siglock, flags); 527 rcu_read_unlock();
528 new_timer->it_process = process;
529 list_add(&new_timer->list,
530 &process->signal->posix_timers);
531 spin_unlock_irqrestore(&process->sighand->siglock, flags);
532 }
533 read_unlock(&tasklist_lock);
534 if (!process) { 528 if (!process) {
535 error = -EINVAL; 529 error = -EINVAL;
536 goto out; 530 goto out;
@@ -541,19 +535,18 @@ sys_timer_create(const clockid_t which_clock,
541 new_timer->it_sigev_value.sival_int = new_timer->it_id; 535 new_timer->it_sigev_value.sival_int = new_timer->it_id;
542 process = current->group_leader; 536 process = current->group_leader;
543 get_task_struct(process); 537 get_task_struct(process);
544 spin_lock_irqsave(&process->sighand->siglock, flags);
545 new_timer->it_process = process;
546 list_add(&new_timer->list, &process->signal->posix_timers);
547 spin_unlock_irqrestore(&process->sighand->siglock, flags);
548 } 538 }
549 539
540 spin_lock_irq(&current->sighand->siglock);
541 new_timer->it_process = process;
542 list_add(&new_timer->list, &current->signal->posix_timers);
543 spin_unlock_irq(&current->sighand->siglock);
550 /* 544 /*
551 * In the case of the timer belonging to another task, after 545 * In the case of the timer belonging to another task, after
552 * the task is unlocked, the timer is owned by the other task 546 * the task is unlocked, the timer is owned by the other task
553 * and may cease to exist at any time. Don't use or modify 547 * and may cease to exist at any time. Don't use or modify
554 * new_timer after the unlock call. 548 * new_timer after the unlock call.
555 */ 549 */
556
557out: 550out:
558 if (error) 551 if (error)
559 release_posix_timer(new_timer, it_id_set); 552 release_posix_timer(new_timer, it_id_set);