All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] fix the issue that the tick_nohz_get_sleep_length() function could return a negative value
@ 2021-01-20 23:49 Zhou Ti (x2019cwm)
  2021-02-01 13:47 ` Frederic Weisbecker
  2021-02-19 12:09 ` Frederic Weisbecker
  0 siblings, 2 replies; 5+ messages in thread
From: Zhou Ti (x2019cwm) @ 2021-01-20 23:49 UTC (permalink / raw)
  To: fweisbec, tglx, mingo, linux-kernel

Fix the issue that the tick_nohz_get_sleep_length() function could return a 
negative value.

The variable "dev->next_event" has a small possibility to be smaller than 
the variable "now" during running, which would result in a negative value 
of "*delta_next". The variable "next_event" also has a small posibility to 
be smaller than the variable "now". Both case could lead to a negative 
return of function tick_nohz_get_sleep_length().

Signed-off-by: Ti Zhou <x2019cwm@stfx.ca>
---
--- tip/kernel/time/tick-sched.c.orig	2021-01-20 05:34:25.151325912 -0400
+++ tip/kernel/time/tick-sched.c	2021-01-20 19:44:28.238538380 -0400
@@ -1142,6 +1142,9 @@ ktime_t tick_nohz_get_sleep_length(ktime
 
 	*delta_next = ktime_sub(dev->next_event, now);
 
+	if (unlikely(*delta_next < 0))
+		*delta_next = 0;
+
 	if (!can_stop_idle_tick(cpu, ts))
 		return *delta_next;
 
@@ -1156,6 +1159,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);
 }
 

^ permalink raw reply	[flat|nested] 5+ messages in thread
* [PATCH] fix the issue that the tick_nohz_get_sleep_length() function could return a negative value
@ 2021-01-20 18:58 Zhou Ti (x2019cwm)
  2021-01-20 22:11 ` Randy Dunlap
  0 siblings, 1 reply; 5+ messages in thread
From: Zhou Ti (x2019cwm) @ 2021-01-20 18:58 UTC (permalink / raw)
  To: linux-kernel

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@stfx.ca>
---
--- 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);
 }

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2021-02-19 12:10 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-01-20 23:49 [PATCH] fix the issue that the tick_nohz_get_sleep_length() function could return a negative value Zhou Ti (x2019cwm)
2021-02-01 13:47 ` Frederic Weisbecker
2021-02-19 12:09 ` Frederic Weisbecker
  -- strict thread matches above, loose matches on Subject: below --
2021-01-20 18:58 Zhou Ti (x2019cwm)
2021-01-20 22:11 ` Randy Dunlap

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.