Re: [PATCH RFC] block, bfq: switch 'bfqg->ref' to use atomic refcount apis

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Tue 27-12-22 14:09:40, Yu Kuai wrote:
> Hi, Jan!
> 
> 在 2022/12/27 11:15, Yu Kuai 写道:
> > From: Yu Kuai <yukuai3@xxxxxxxxxx>
> > 
> > The updating of 'bfqg->ref' should be protected by 'bfqd->lock', however,
> > during code review, we found that bfq_pd_free() update 'bfqg->ref'
> > without holding the lock, which is problematic:
> > 
> > 1) bfq_pd_free() triggered by removing cgroup is called asynchronously;
> > 2) bfqq will grab bfqg reference, and exit bfqq will drop the reference,
> > which can concurrenty with 1).
> > 
> > Unfortunately, 'bfqd->lock' can't be held here because 'bfqd' might already
> > be freed in bfq_pd_free(). Fix the problem by using atomic refcount apis.
> > 
> > Signed-off-by: Yu Kuai <yukuai3@xxxxxxxxxx>
> > ---
> >   block/bfq-cgroup.c  | 8 +++-----
> >   block/bfq-iosched.h | 2 +-
> >   2 files changed, 4 insertions(+), 6 deletions(-)
> > 
> > diff --git a/block/bfq-cgroup.c b/block/bfq-cgroup.c
> > index 1b2829e99dad..aa9c4f02e3a3 100644
> > --- a/block/bfq-cgroup.c
> > +++ b/block/bfq-cgroup.c
> > @@ -316,14 +316,12 @@ struct bfq_group *bfqq_group(struct bfq_queue *bfqq)
> >   static void bfqg_get(struct bfq_group *bfqg)
> >   {
> > -	bfqg->ref++;
> > +	refcount_inc(&bfqg->ref);
> >   }
> >   static void bfqg_put(struct bfq_group *bfqg)
> >   {
> > -	bfqg->ref--;
> > -
> > -	if (bfqg->ref == 0)
> > +	if (refcount_dec_and_test(bfqg->ref))
> Sorry that here should be '&bfqg->ref'.
> 
> Anyway, I'll wait for you, and send a new version if you think this
> patch make sense.

Yes, the patch makes sense to me so feel free to send fixed version.

								Honza
-- 
Jan Kara <jack@xxxxxxxx>
SUSE Labs, CR



[Index of Archives]     [Linux ARM Kernel]     [Linux ARM]     [Linux Omap]     [Fedora ARM]     [IETF Annouce]     [Security]     [Bugtraq]     [Linux OMAP]     [Linux MIPS]     [eCos]     [Asterisk Internet PBX]     [Linux API]     [Monitors]

  Powered by Linux