Skip to contentSkip to conversation

timer: Fix wheel index calculation on last level

PATCH New Frederic Weisbecker 1 participant 1 message Jul 15, 2020

Subsystems (2)
lore
Share & tools
lore

Frederic Weisbecker

author maintainer
#0 lore raw

PATCH 1/1 timer: Fix wheel index calculation on last level

When an expiration delta falls into the last level of the wheel, we want to compare that delta against the maximum possible delay and reduce our delta to fit in if necessary.

However instead of comparing the delta against the maximum, we are comparing the actual expiry against the maximum. Then instead of fixing the delta to fit in, we set the maximum delta as the expiry value.

This can result in various undesired outcomes, the worst possible one being a timer expiring 15 days ahead to fire immediately.

Fixes 500462a9de65 ("timers: Switch to a non-cascading wheel")
Cc Peter Zijlstra <[email protected]>
Cc Anna-Maria Behnsen <[email protected]>
Cc Juri Lelli <[email protected]>
Cc Thomas Gleixner <[email protected]>
---
 kernel/time/timer.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
kernel/time/timer.c +2 -2
index 9a838d38dbe6..df1ff803acc4 100644
@@ -521,8 +521,8 @@ static int calc_wheel_index(unsigned long expires, unsigned long clk)
 		 * Force expire obscene large timeouts to expire at the
 		 * capacity limit of the wheel.
 		 */
-		if (expires >= WHEEL_TIMEOUT_CUTOFF)
-			expires = WHEEL_TIMEOUT_MAX;
+		if (delta >= WHEEL_TIMEOUT_CUTOFF)
+			expires = clk + WHEEL_TIMEOUT_MAX;
 
 		idx = calc_index(expires, LVL_DEPTH - 1);
 	}
Signature · 1 line
2.26.2