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

From: Suren Baghdasaryan

Date: Sun Jul 26 2026 - 23:25:46 EST


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: Suren Baghdasaryan <surenb@xxxxxxxxxx>

> ---
> kernel/sched/psi.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/kernel/sched/psi.c b/kernel/sched/psi.c
> index 8e4df8b17c25..f0a5976f49dc 100644
> --- a/kernel/sched/psi.c
> +++ b/kernel/sched/psi.c
> @@ -1391,8 +1391,8 @@ struct psi_trigger *psi_trigger_create(struct psi_group *group, char *buf,
>
> t->group = group;
> t->state = state;
> - t->threshold = threshold_us * NSEC_PER_USEC;
> - t->win.size = window_us * NSEC_PER_USEC;
> + t->threshold = (u64)threshold_us * NSEC_PER_USEC;
> + t->win.size = (u64)window_us * NSEC_PER_USEC;
> window_reset(&t->win, sched_clock(),
> group->total[PSI_POLL][t->state], 0);
>
> --
> 2.43.0