From: Vivek Goyal <vgoyal@redhat.com>
To: Jens Axboe <axboe@kernel.dk>
Cc: Andi Kleen <andi@firstfloor.org>,
torvalds@linux-foundation.org, linux-kernel@vger.kernel.org,
Andi Kleen <ak@linux.intel.com>
Subject: Re: [PATCH] Fix array overflow in CFQ
Date: Tue, 19 Oct 2010 08:33:20 -0400 [thread overview]
Message-ID: <20101019123320.GB857@redhat.com> (raw)
In-Reply-To: <20101019114933.GA857@redhat.com>
On Tue, Oct 19, 2010 at 07:49:33AM -0400, Vivek Goyal wrote:
> On Tue, Oct 19, 2010 at 12:01:40PM +0200, Jens Axboe wrote:
> > On 2010-10-19 11:10, Andi Kleen wrote:
> > > From: Andi Kleen <ak@linux.intel.com>
> > >
> > > gcc 4.5 complains when compiling a recent rc with
> > >
> > > linux/block/cfq-iosched.c: In function ‘cfq_dispatch_requests’:
> > > linux/block/cfq-iosched.c:2156:3: warning: array subscript is above array bounds
> > >
> > > and it is right:
> > >
> > > slice = group_slice * count /
> > > max_t(unsigned, cfqg->busy_queues_avg[cfqd->serving_prio],
> > > cfq_group_busy_queues_wl(cfqd->serving_prio, cfqd, cfqg));
> > >
> > > busy_queues_avg can be indexed by this enum
> > >
> > > enum wl_prio_t {
> > > BE_WORKLOAD = 0,
> > > RT_WORKLOAD = 1,
> > > IDLE_WORKLOAD = 2,
> > > };
> > >
> > > in cfqd->serving_prio, but is only declared as
> > >
> > > unsigned int busy_queues_avg[2];
> > >
> > > which is clearly off by one. Fix this here.
> >
> > Indeed, that is definitely buggy. ->service_trees[][] looks buggy, too.
> > WTF?!
>
> Hi Jens,
>
> busy_queues_avg[] definitely looks buggy. Looks like I introduced this bug
> while converting corrado's logic to group logic. I will fix it in a while.
> Sorry for the goof up here.
Jens,
Staring at the code for some more time, it looks like that busy_queues_avg[]
is also not buggy (at least at run time).
We maintain busy_queues_avg() only for RT and BE class. For IDLE class, we
expire the workload immediately after a jiffy.
/* Choose next priority. RT > BE > IDLE */
if (cfq_group_busy_queues_wl(RT_WORKLOAD, cfqd, cfqg))
cfqd->serving_prio = RT_WORKLOAD;
else if (cfq_group_busy_queues_wl(BE_WORKLOAD, cfqd, cfqg))
cfqd->serving_prio = BE_WORKLOAD;
else {
cfqd->serving_prio = IDLE_WORKLOAD;
cfqd->workload_expires = jiffies + 1;
return;
}
...
...
...
slice = group_slice * count /
max_t(unsigned, cfqg->busy_queues_avg[cfqd->serving_prio],
cfq_group_busy_queues_wl(cfqd->serving_prio, cfqd,
cfqg));
So for IDLE class, we return immediately from the function and never
execute cfqg->busy_queues_avg[IDLE].
Now to remove the gcc warning we can increase the size of busy_queues_avg[]
array but third field should always remain unused.
Thanks
Vivek
next prev parent reply other threads:[~2010-10-19 12:33 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-10-19 9:10 [PATCH] Fix array overflow in CFQ Andi Kleen
2010-10-19 10:01 ` Jens Axboe
2010-10-19 11:49 ` Vivek Goyal
2010-10-19 11:55 ` Jens Axboe
2010-10-19 12:33 ` Vivek Goyal [this message]
2010-10-19 13:23 ` Andi Kleen
2010-10-19 15:05 ` Vivek Goyal
2010-10-21 16:53 ` Jeff Moyer
2010-10-21 17:16 ` Andi Kleen
2010-10-21 17:15 ` Jeff Moyer
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=20101019123320.GB857@redhat.com \
--to=vgoyal@redhat.com \
--cc=ak@linux.intel.com \
--cc=andi@firstfloor.org \
--cc=axboe@kernel.dk \
--cc=linux-kernel@vger.kernel.org \
--cc=torvalds@linux-foundation.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox