diff options
Diffstat (limited to 'kernel/posix-timers.c')
-rw-r--r-- | kernel/posix-timers.c | 46 |
1 files changed, 26 insertions, 20 deletions
diff --git a/kernel/posix-timers.c b/kernel/posix-timers.c index 5e79c662294b..887c63787de6 100644 --- a/kernel/posix-timers.c +++ b/kernel/posix-timers.c | |||
@@ -116,7 +116,7 @@ static DEFINE_SPINLOCK(idr_lock); | |||
116 | * must supply functions here, even if the function just returns | 116 | * must supply functions here, even if the function just returns |
117 | * ENOSYS. The standard POSIX timer management code assumes the | 117 | * ENOSYS. The standard POSIX timer management code assumes the |
118 | * following: 1.) The k_itimer struct (sched.h) is used for the | 118 | * following: 1.) The k_itimer struct (sched.h) is used for the |
119 | * timer. 2.) The list, it_lock, it_clock, it_id and it_process | 119 | * timer. 2.) The list, it_lock, it_clock, it_id and it_pid |
120 | * fields are not modified by timer code. | 120 | * fields are not modified by timer code. |
121 | * | 121 | * |
122 | * At this time all functions EXCEPT clock_nanosleep can be | 122 | * At this time all functions EXCEPT clock_nanosleep can be |
@@ -197,6 +197,11 @@ static int common_timer_create(struct k_itimer *new_timer) | |||
197 | return 0; | 197 | return 0; |
198 | } | 198 | } |
199 | 199 | ||
200 | static int no_timer_create(struct k_itimer *new_timer) | ||
201 | { | ||
202 | return -EOPNOTSUPP; | ||
203 | } | ||
204 | |||
200 | /* | 205 | /* |
201 | * Return nonzero if we know a priori this clockid_t value is bogus. | 206 | * Return nonzero if we know a priori this clockid_t value is bogus. |
202 | */ | 207 | */ |
@@ -248,6 +253,7 @@ static __init int init_posix_timers(void) | |||
248 | .clock_getres = hrtimer_get_res, | 253 | .clock_getres = hrtimer_get_res, |
249 | .clock_get = posix_get_monotonic_raw, | 254 | .clock_get = posix_get_monotonic_raw, |
250 | .clock_set = do_posix_clock_nosettime, | 255 | .clock_set = do_posix_clock_nosettime, |
256 | .timer_create = no_timer_create, | ||
251 | }; | 257 | }; |
252 | 258 | ||
253 | register_posix_clock(CLOCK_REALTIME, &clock_realtime); | 259 | register_posix_clock(CLOCK_REALTIME, &clock_realtime); |
@@ -313,7 +319,8 @@ void do_schedule_next_timer(struct siginfo *info) | |||
313 | 319 | ||
314 | int posix_timer_event(struct k_itimer *timr, int si_private) | 320 | int posix_timer_event(struct k_itimer *timr, int si_private) |
315 | { | 321 | { |
316 | int shared, ret; | 322 | struct task_struct *task; |
323 | int shared, ret = -1; | ||
317 | /* | 324 | /* |
318 | * FIXME: if ->sigq is queued we can race with | 325 | * FIXME: if ->sigq is queued we can race with |
319 | * dequeue_signal()->do_schedule_next_timer(). | 326 | * dequeue_signal()->do_schedule_next_timer(). |
@@ -327,8 +334,13 @@ int posix_timer_event(struct k_itimer *timr, int si_private) | |||
327 | */ | 334 | */ |
328 | timr->sigq->info.si_sys_private = si_private; | 335 | timr->sigq->info.si_sys_private = si_private; |
329 | 336 | ||
330 | shared = !(timr->it_sigev_notify & SIGEV_THREAD_ID); | 337 | rcu_read_lock(); |
331 | ret = send_sigqueue(timr->sigq, timr->it_process, shared); | 338 | task = pid_task(timr->it_pid, PIDTYPE_PID); |
339 | if (task) { | ||
340 | shared = !(timr->it_sigev_notify & SIGEV_THREAD_ID); | ||
341 | ret = send_sigqueue(timr->sigq, task, shared); | ||
342 | } | ||
343 | rcu_read_unlock(); | ||
332 | /* If we failed to send the signal the timer stops. */ | 344 | /* If we failed to send the signal the timer stops. */ |
333 | return ret > 0; | 345 | return ret > 0; |
334 | } | 346 | } |
@@ -405,7 +417,7 @@ static enum hrtimer_restart posix_timer_fn(struct hrtimer *timer) | |||
405 | return ret; | 417 | return ret; |
406 | } | 418 | } |
407 | 419 | ||
408 | static struct task_struct * good_sigevent(sigevent_t * event) | 420 | static struct pid *good_sigevent(sigevent_t * event) |
409 | { | 421 | { |
410 | struct task_struct *rtn = current->group_leader; | 422 | struct task_struct *rtn = current->group_leader; |
411 | 423 | ||
@@ -419,7 +431,7 @@ static struct task_struct * good_sigevent(sigevent_t * event) | |||
419 | ((event->sigev_signo <= 0) || (event->sigev_signo > SIGRTMAX))) | 431 | ((event->sigev_signo <= 0) || (event->sigev_signo > SIGRTMAX))) |
420 | return NULL; | 432 | return NULL; |
421 | 433 | ||
422 | return rtn; | 434 | return task_pid(rtn); |
423 | } | 435 | } |
424 | 436 | ||
425 | void register_posix_clock(const clockid_t clock_id, struct k_clock *new_clock) | 437 | void register_posix_clock(const clockid_t clock_id, struct k_clock *new_clock) |
@@ -458,6 +470,7 @@ static void release_posix_timer(struct k_itimer *tmr, int it_id_set) | |||
458 | idr_remove(&posix_timers_id, tmr->it_id); | 470 | idr_remove(&posix_timers_id, tmr->it_id); |
459 | spin_unlock_irqrestore(&idr_lock, flags); | 471 | spin_unlock_irqrestore(&idr_lock, flags); |
460 | } | 472 | } |
473 | put_pid(tmr->it_pid); | ||
461 | sigqueue_free(tmr->sigq); | 474 | sigqueue_free(tmr->sigq); |
462 | kmem_cache_free(posix_timers_cache, tmr); | 475 | kmem_cache_free(posix_timers_cache, tmr); |
463 | } | 476 | } |
@@ -471,7 +484,6 @@ sys_timer_create(const clockid_t which_clock, | |||
471 | { | 484 | { |
472 | struct k_itimer *new_timer; | 485 | struct k_itimer *new_timer; |
473 | int error, new_timer_id; | 486 | int error, new_timer_id; |
474 | struct task_struct *process; | ||
475 | sigevent_t event; | 487 | sigevent_t event; |
476 | int it_id_set = IT_ID_NOT_SET; | 488 | int it_id_set = IT_ID_NOT_SET; |
477 | 489 | ||
@@ -525,11 +537,9 @@ sys_timer_create(const clockid_t which_clock, | |||
525 | goto out; | 537 | goto out; |
526 | } | 538 | } |
527 | rcu_read_lock(); | 539 | rcu_read_lock(); |
528 | process = good_sigevent(&event); | 540 | new_timer->it_pid = get_pid(good_sigevent(&event)); |
529 | if (process) | ||
530 | get_task_struct(process); | ||
531 | rcu_read_unlock(); | 541 | rcu_read_unlock(); |
532 | if (!process) { | 542 | if (!new_timer->it_pid) { |
533 | error = -EINVAL; | 543 | error = -EINVAL; |
534 | goto out; | 544 | goto out; |
535 | } | 545 | } |
@@ -537,8 +547,7 @@ sys_timer_create(const clockid_t which_clock, | |||
537 | event.sigev_notify = SIGEV_SIGNAL; | 547 | event.sigev_notify = SIGEV_SIGNAL; |
538 | event.sigev_signo = SIGALRM; | 548 | event.sigev_signo = SIGALRM; |
539 | event.sigev_value.sival_int = new_timer->it_id; | 549 | event.sigev_value.sival_int = new_timer->it_id; |
540 | process = current->group_leader; | 550 | new_timer->it_pid = get_pid(task_tgid(current)); |
541 | get_task_struct(process); | ||
542 | } | 551 | } |
543 | 552 | ||
544 | new_timer->it_sigev_notify = event.sigev_notify; | 553 | new_timer->it_sigev_notify = event.sigev_notify; |
@@ -548,7 +557,7 @@ sys_timer_create(const clockid_t which_clock, | |||
548 | new_timer->sigq->info.si_code = SI_TIMER; | 557 | new_timer->sigq->info.si_code = SI_TIMER; |
549 | 558 | ||
550 | spin_lock_irq(¤t->sighand->siglock); | 559 | spin_lock_irq(¤t->sighand->siglock); |
551 | new_timer->it_process = process; | 560 | new_timer->it_signal = current->signal; |
552 | list_add(&new_timer->list, ¤t->signal->posix_timers); | 561 | list_add(&new_timer->list, ¤t->signal->posix_timers); |
553 | spin_unlock_irq(¤t->sighand->siglock); | 562 | spin_unlock_irq(¤t->sighand->siglock); |
554 | 563 | ||
@@ -583,8 +592,7 @@ static struct k_itimer *lock_timer(timer_t timer_id, unsigned long *flags) | |||
583 | timr = idr_find(&posix_timers_id, (int)timer_id); | 592 | timr = idr_find(&posix_timers_id, (int)timer_id); |
584 | if (timr) { | 593 | if (timr) { |
585 | spin_lock(&timr->it_lock); | 594 | spin_lock(&timr->it_lock); |
586 | if (timr->it_process && | 595 | if (timr->it_signal == current->signal) { |
587 | same_thread_group(timr->it_process, current)) { | ||
588 | spin_unlock(&idr_lock); | 596 | spin_unlock(&idr_lock); |
589 | return timr; | 597 | return timr; |
590 | } | 598 | } |
@@ -831,8 +839,7 @@ retry_delete: | |||
831 | * This keeps any tasks waiting on the spin lock from thinking | 839 | * This keeps any tasks waiting on the spin lock from thinking |
832 | * they got something (see the lock code above). | 840 | * they got something (see the lock code above). |
833 | */ | 841 | */ |
834 | put_task_struct(timer->it_process); | 842 | timer->it_signal = NULL; |
835 | timer->it_process = NULL; | ||
836 | 843 | ||
837 | unlock_timer(timer, flags); | 844 | unlock_timer(timer, flags); |
838 | release_posix_timer(timer, IT_ID_SET); | 845 | release_posix_timer(timer, IT_ID_SET); |
@@ -858,8 +865,7 @@ retry_delete: | |||
858 | * This keeps any tasks waiting on the spin lock from thinking | 865 | * This keeps any tasks waiting on the spin lock from thinking |
859 | * they got something (see the lock code above). | 866 | * they got something (see the lock code above). |
860 | */ | 867 | */ |
861 | put_task_struct(timer->it_process); | 868 | timer->it_signal = NULL; |
862 | timer->it_process = NULL; | ||
863 | 869 | ||
864 | unlock_timer(timer, flags); | 870 | unlock_timer(timer, flags); |
865 | release_posix_timer(timer, IT_ID_SET); | 871 | release_posix_timer(timer, IT_ID_SET); |