Re: [PATCH] fix the issue that the tick_nohz_get_sleep_length() function could return a negative value

From: Randy Dunlap
Date: Wed Jan 20 2021 - 19:12:16 EST


On 1/20/21 10:58 AM, Zhou Ti (x2019cwm) wrote:
> Fix the issue that the tick_nohz_get_sleep_length() function could return
> a negative value.
>
> The variable "next_event" has a small possibility to be smaller than the
> variable "now" during running. Since both the menu idle governor and the
> teo idle governor use u64 to store the return value of the function, this
> may result in an extremely large and invalid value.
>
> One can easily detect the existence of this issue by using printk to
> output a warning.
>
> Signed-off-by: Ti Zhou <x2019cwm@xxxxxxx>
> ---
> --- tip/kernel/time/tick-sched.c.orig 2021-01-20 05:34:25.151325912 -0400
> +++ tip/kernel/time/tick-sched.c 2021-01-20 07:09:15.060980886 -0400
> @@ -1156,6 +1156,9 @@ ktime_t tick_nohz_get_sleep_length(ktime
> next_event = min_t(u64, next_event,
> hrtimer_next_event_without(&ts->sched_timer));
>
> + if (unlikely(next_event < now))
> + next_event = now;
> +
> return ktime_sub(next_event, now);
> }
>

Hi,

You need to send this to some maintainer who can apply/merge it.
Just sending it to a mailing list is not sufficient.

thanks.
--
~Randy