Re: [patch V2 25/50] signal: Confine POSIX_TIMERS properly

From: Anna-Maria Behnsen
Date: Wed Apr 17 2024 - 08:09:17 EST


Thomas Gleixner <tglx@xxxxxxxxxxxxx> writes:

> Move the itimer rearming out of the signal code and consolidate all posix
> timer related functions in the signal code under one ifdef.

It would be easier to read, when it is splitted. But I made it :)

With the typo fix below feel free to add:

Reviewed-by: Anna-Maria Behnsen <anna-maria@xxxxxxxxxxxxx>


> Signed-off-by: Thomas Gleixner <tglx@xxxxxxxxxxxxx>
> ---
> include/linux/posix-timers.h | 5 +
> kernel/signal.c | 125 +++++++++++++++----------------------------
> kernel/time/itimer.c | 22 +++++++
> kernel/time/posix-timers.c | 15 ++++-
> 4 files changed, 82 insertions(+), 85 deletions(-)
>
> --- a/include/linux/posix-timers.h
> +++ b/include/linux/posix-timers.h

[...]

> @@ -151,7 +151,27 @@ COMPAT_SYSCALL_DEFINE2(getitimer, int, w
> #endif
>
> /*
> - * The timer is automagically restarted, when interval != 0
> + * Invoked from dequeue_signal() when SIG_ALRM is delivered.

s/SIG_ALRM/SIGALRM


> + *
> + * Restart the ITIMER_REAL timer if it is armed as periodic timer. Doing
> + * this in the signal delivery path instead of self rearming prevents a DoS
> + * with small increments in the high reolution timer case and reduces timer
> + * noise in general.
> + */
> +void posixtimer_rearm_itimer(struct task_struct *tsk)
> +{
> + struct hrtimer *tmr = &tsk->signal->real_timer;
> +
> + if (!hrtimer_is_queued(tmr) && tsk->signal->it_real_incr != 0) {
> + hrtimer_forward(tmr, tmr->base->get_time(),
> + tsk->signal->it_real_incr);
> + hrtimer_restart(tmr);
> + }
> +}
> +
> +/*
> + * Interval timers are restarted in the signal delivery path. See
> + * posixtimer_rearm_itimer().
> */
> enum hrtimer_restart it_real_fn(struct hrtimer *timer)
> {