Re: [PATCH 2/2] sched/psi: Fix overflow in trigger time conversion on 32-bit

From: Tao Cui

Date: Tue Jul 28 2026 - 05:19:31 EST


From: Tao Cui <cuitao@xxxxxxxxxx>

On Fri, Jul 17, 2026 at 3:29 AM Guopeng Zhang <guopeng.zhang@xxxxxxxxx> wrote:
>
> From: Guopeng Zhang <zhangguopeng@xxxxxxxxxx>
>
> threshold_us and window_us are u32, while NSEC_PER_USEC is 1000L. On
> 32-bit architectures, multiplication by NSEC_PER_USEC is evaluated
> using 32-bit unsigned arithmetic and can wrap before the result is
> assigned to the u64 trigger fields.
>
> For a valid 4,000,000 us threshold and 6,000,000 us window, the
> threshold is stored as 4,000,000,000 ns, while the window wraps to
> 1,705,032,704 ns. The stored window is therefore shorter than the
> threshold, so the trigger no longer monitors the requested 4-second
> threshold over a 6-second window.
>
> Cast both values to u64 before the multiplication so that the
> conversion to nanoseconds is performed using 64-bit arithmetic.
>
> Fixes: 0e94682b73bf ("psi: introduce psi monitor")
> Signed-off-by: Guopeng Zhang <zhangguopeng@xxxxxxxxxx>

Acked-by: Tao Cui <cuitao@xxxxxxxxxx>