On Wed, Jun 3, 2026 at 12:55 AM Wake Liu <[email protected]> wrote:
>
> Several timer tests use NSEC_PER_SEC for arithmetic. Since NSEC_PER_SEC
> is defined as 1000000000L in vdso/time64.h, it is 32-bit on 32-bit
> architectures. Multiplications like NSEC_PER_SEC * 10 or 5 * NSEC_PER_SEC
> overflow 32-bit signed long.
>
> Fix this by using LL suffixes or casting NSEC_PER_SEC to long long to
> force 64-bit multiplication.
>
> Signed-off-by: Wake Liu <[email protected]>
I feel like this has come up a few ways since commit 80fa614e2fbc
("selftests: timers: Remove local NSEC_PER_SEC and USEC_PER_SEC
defines"), and I definitely missed in that patch that the
include/vdso/time64.h NSEC_PER_SEC is defined as a long instead of a
long long.
Setting include/vdso/time64.h NSEC_PER_SEC to a long long probably
isn't a great idea as its a value that gets divided & used as a
divisor, so we want to keep it cheaper on 32bit systems, but anywhere
its multiplied you are really close to an overflow without explicit
casts (which has been a pretty good foot gun over the years).
So I'm wondering if it would be simpler to just revert 80fa614e2fbc
for the selftests as we don't have to worry about the performance cost
of doing the 64bit math everywhere there?
thanks
-john