All of lore.kernel.org
 help / color / mirror / Atom feed
From: Quentin Perret <qperret@google.com>
To: Vincent Guittot <vincent.guittot@linaro.org>
Cc: Ingo Molnar <mingo@redhat.com>,
	Peter Zijlstra <peterz@infradead.org>,
	Juri Lelli <juri.lelli@redhat.com>,
	Dietmar Eggemann <dietmar.eggemann@arm.com>,
	Steven Rostedt <rostedt@goodmis.org>,
	Ben Segall <bsegall@google.com>, Mel Gorman <mgorman@suse.de>,
	Daniel Bristot de Oliveira <bristot@redhat.com>,
	Qais Yousef <qais.yousef@arm.com>,
	Android Kernel Team <kernel-team@android.com>,
	linux-kernel <linux-kernel@vger.kernel.org>,
	Patrick Bellasi <patrick.bellasi@matbug.net>
Subject: Re: [PATCH v2] sched: Fix out-of-bound access in uclamp
Date: Fri, 30 Apr 2021 08:25:54 +0000	[thread overview]
Message-ID: <YIu/EjZ8QsEl9sum@google.com> (raw)
In-Reply-To: <CAKfTPtAfgVnMYkY_M+SDmNQDb_EsxSctQw-fkt2WJhczZakOjQ@mail.gmail.com>

On Friday 30 Apr 2021 at 09:45:32 (+0200), Vincent Guittot wrote:
> On Thu, 29 Apr 2021 at 17:27, Quentin Perret <qperret@google.com> wrote:
> >
> > Util-clamp places tasks in different buckets based on their clamp values
> > for performance reasons. However, the size of buckets is currently
> > computed using a rounding division, which can lead to an off-by-one
> > error in some configurations.
> >
> > For instance, with 20 buckets, the bucket size will be 1024/20=51. A
> > task with a clamp of 1024 will be mapped to bucket id 1024/51=20. Sadly,
> > correct indexes are in range [0,19], hence leading to an out of bound
> > memory access.
> >
> > Fix the math to compute the bucket size.
> >
> > Fixes: 69842cba9ace ("sched/uclamp: Add CPU's clamp buckets refcounting")
> > Suggested-by: Qais Yousef <qais.yousef@arm.com>
> > Signed-off-by: Quentin Perret <qperret@google.com>
> >
> > ---
> >
> > Changes in v2:
> >  - replaced the DIV_ROUND_UP(a,b) with a/b+1 (Dietmar)
> 
> Doesn't this create unfairness between buckets ?
> 
> If we take your example above of 20 buckets, delta is now 52. Then we
> expect the last bucket to get the range [972-1024] but values lower
> than 988 will go in the idx 18.

Well, that's just the limitation of integer arithmetics isn't it?

> And the more bucket you will have, the
> worse it will be

Sure, but 20 is a hard limit, and if we ever need more than that then
maybe we should think about getting rid of the buckets altogether.

> Your problem comes from the fact that we use 1025 values instead of
> 1024.

I don't understand what you mean here. Right now we'll assign bucket id
20 for any clamp in the range [1020-1024], so I don't think we can
special case 1024.

> Wouldn't it be easier to have a special condition for
> SCHED_CAPACITY_SCALE value

As per the above, I don't see how that'll work.

Thanks,
Quentin

  reply	other threads:[~2021-04-30  8:26 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-04-29 15:26 [PATCH v2] sched: Fix out-of-bound access in uclamp Quentin Perret
2021-04-30  7:45 ` Vincent Guittot
2021-04-30  8:25   ` Quentin Perret [this message]
2021-04-30  8:49     ` Vincent Guittot
2021-04-30  9:40       ` Quentin Perret
2021-04-30 12:03         ` Vincent Guittot
2021-04-30 13:00           ` Dietmar Eggemann
2021-04-30 13:14             ` Quentin Perret
2021-04-30 14:16               ` Vincent Guittot
2021-04-30 15:04                 ` Dietmar Eggemann

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=YIu/EjZ8QsEl9sum@google.com \
    --to=qperret@google.com \
    --cc=bristot@redhat.com \
    --cc=bsegall@google.com \
    --cc=dietmar.eggemann@arm.com \
    --cc=juri.lelli@redhat.com \
    --cc=kernel-team@android.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mgorman@suse.de \
    --cc=mingo@redhat.com \
    --cc=patrick.bellasi@matbug.net \
    --cc=peterz@infradead.org \
    --cc=qais.yousef@arm.com \
    --cc=rostedt@goodmis.org \
    --cc=vincent.guittot@linaro.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.