From: Jens Axboe <axboe@kernel.dk>
To: Shaohua Li <shli@kernel.org>
Cc: Paul Bolle <pebolle@tiscali.nl>, linux-kernel@vger.kernel.org
Subject: Re: block: ioc->refcount accessed twice in put_io_context()?
Date: Mon, 11 Apr 2011 09:42:51 +0200 [thread overview]
Message-ID: <4DA2B0FB.8020302@kernel.dk> (raw)
In-Reply-To: <BANLkTi=ma7WDo9=kKwZGwuhi=qUEB8EW5g@mail.gmail.com>
On 2011-04-11 03:54, Shaohua Li wrote:
> 2011/4/10 Paul Bolle <pebolle@tiscali.nl>:
>> 0) Looking for clues to solve a problem I ran into, I noticed something
>> odd in block/blk-ioc.c:put_io_context(). It seems it accesses the atomic
>> variable ioc->refcount twice in a way which suggests things might race.
>>
>> 1) Code is more exact than words, so this (entirely untested) patch to
>> solve this possible race might describe better what this is all about:
>>
>> @@ -33,12 +33,16 @@ static void cfq_dtor(struct io_context *ioc)
>> */
>> int put_io_context(struct io_context *ioc)
>> {
>> + int new;
>> +
>> if (ioc == NULL)
>> return 1;
>>
>> - BUG_ON(atomic_long_read(&ioc->refcount) == 0);
>> + new = atomic_long_dec_return(&ioc->refcount);
>> +
>> + BUG_ON(new < 0);
>>
>> - if (atomic_long_dec_and_test(&ioc->refcount)) {
>> + if (new == 0) {
>> rcu_read_lock();
>> cfq_dtor(ioc);
>> rcu_read_unlock();
>>
> so you hit this line?
> BUG_ON(atomic_long_read(&ioc->refcount) == 0);
> this suggests something else is already wrong, you should fix that.
Indeed, there is nothing wrong with having the BUG_ON() there first and
doing the decrement later. If the BUG_ON() is hit, then it's not a race
conditon - it's a plain bug in the code.
--
Jens Axboe
next prev parent reply other threads:[~2011-04-11 7:42 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-04-10 13:41 block: ioc->refcount accessed twice in put_io_context()? Paul Bolle
2011-04-11 1:54 ` Shaohua Li
2011-04-11 7:42 ` Jens Axboe [this message]
2011-04-11 8:45 ` Paul Bolle
2011-04-11 8:53 ` Jens Axboe
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=4DA2B0FB.8020302@kernel.dk \
--to=axboe@kernel.dk \
--cc=linux-kernel@vger.kernel.org \
--cc=pebolle@tiscali.nl \
--cc=shli@kernel.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.