Adrian Hunter 7e90ffb716 x86/vdso: Make delta calculation overflow safe
Kernel timekeeping is designed to keep the change in cycles (since the last
timer interrupt) below max_cycles, which prevents multiplication overflow
when converting cycles to nanoseconds. However, if timer interrupts stop,
the calculation will eventually overflow.

Add protection against that. Select GENERIC_VDSO_OVERFLOW_PROTECT so that
max_cycles is made available in the VDSO data page. Check against
max_cycles, falling back to a slower higher precision calculation. Take
advantage of the opportunity to move masking and negative motion check
into the slow path.

The result is a calculation that has similar performance as before. Newer
machines showed performance benefit, whereas older Skylake-based hardware
such as Intel Kaby Lake was seen <1% worse.

Suggested-by: Thomas Gleixner <tglx@linutronix.de>
Signed-off-by: Adrian Hunter <adrian.hunter@intel.com>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Link: https://lore.kernel.org/r/20240325064023.2997-9-adrian.hunter@intel.com
2024-04-08 15:03:07 +02:00
..
2024-03-21 14:41:00 -07:00
2024-03-22 10:22:45 -07:00
2024-03-21 12:44:10 -07:00
2024-03-14 15:53:10 -07:00
2024-04-05 13:09:48 -07:00
2024-04-08 15:03:06 +02:00
2024-03-21 10:13:47 -07:00
2024-03-15 12:37:59 -07:00
2024-03-23 08:43:21 -07:00