Re: [PATCH V2] sched,psi: fix the 'int' underflow for psi

From: Peter Zijlstra
Date: Fri Apr 16 2021 - 13:23:06 EST


On Fri, Apr 16, 2021 at 11:11:04AM -0400, Johannes Weiner wrote:
> On Fri, Apr 16, 2021 at 08:32:16PM +0530, Charan Teja Reddy wrote:
> > psi_group_cpu->tasks, represented by the unsigned int, stores the number
> > of tasks that could be stalled on a psi resource(io/mem/cpu).
> > Decrementing these counters at zero leads to wrapping which further
> > leads to the psi_group_cpu->state_mask is being set with the respective
> > pressure state. This could result into the unnecessary time sampling for
> > the pressure state thus cause the spurious psi events. This can further
> > lead to wrong actions being taken at the user land based on these psi
> > events.
> > Though psi_bug is set under these conditions but that just for debug
> > purpose. Fix it by decrementing the ->tasks count only when it is
> > non-zero.
> >
> > Signed-off-by: Charan Teja Reddy <charante@xxxxxxxxxxxxxx>
>
> The subject should be
>
> psi: handle potential task count underflow bugs more gracefully

Done.

> since it's not fixing a known bug at this point. Otherwise,
>
> Acked-by: Johannes Weiner <hannes@xxxxxxxxxxx>

Thanks!