From: Coly Li <colyli@suse.de>
To: tang.junhui@zte.com.cn
Cc: mlyle@lyle.org, linux-bcache@vger.kernel.org,
linux-block@vger.kernel.org
Subject: Re: [PATCH] bcache: lock in btree_flush_write() to avoid races
Date: Wed, 24 Jan 2018 17:13:31 +0800 [thread overview]
Message-ID: <bfa1be99-05fd-ffae-3d6d-0d9cae140415@suse.de> (raw)
In-Reply-To: <1516776864-26993-1-git-send-email-tang.junhui@zte.com.cn>
On 24/01/2018 2:54 PM, tang.junhui@zte.com.cn wrote:
> From: Tang Junhui <tang.junhui@zte.com.cn>
>
> In btree_flush_write(), two places need to take a locker to
> avoid races:
>
> Firstly, we need take rcu read locker to protect the bucket_hash
> traverse, since hlist_for_each_entry_rcu() must be called under
> the protection of rcu read locker.
>
> Secondly, we need take b->write_lock locker to protect journal
> of the btree node, otherwise, the btree node may have been
> written, and the journal have been assign to NULL.
>
> Signed-off-by: Tang Junhui <tang.junhui@zte.com.cn>
> ---
> drivers/md/bcache/journal.c | 7 ++++++-
> 1 file changed, 6 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/md/bcache/journal.c b/drivers/md/bcache/journal.c
> index 02a98dd..505f9f3 100644
> --- a/drivers/md/bcache/journal.c
> +++ b/drivers/md/bcache/journal.c
> @@ -375,7 +375,9 @@ static void btree_flush_write(struct cache_set *c)
> retry:
> best = NULL;
>
> - for_each_cached_btree(b, c, i)
> + rcu_read_lock();
> + for_each_cached_btree(b, c, i) {
> + mutex_lock(&b->write_lock);
> if (btree_current_write(b)->journal) {
> if (!best)
> best = b;
> @@ -385,6 +387,9 @@ static void btree_flush_write(struct cache_set *c)
> best = b;
> }
> }
> + mutex_unlock(&b->write_lock);
> + }
> + rcu_read_unlock();
>
> b = best;
> if (b) {
>
Hi Junhui,
Do you run into some real problem ? The patch looks good to me at first
glance, but I need time to dig it more before I provide my response.
Thanks.
Coly Li
next prev parent reply other threads:[~2018-01-24 9:13 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-01-24 6:54 [PATCH] bcache: lock in btree_flush_write() to avoid races tang.junhui
2018-01-24 9:13 ` Coly Li [this message]
2018-01-24 10:30 ` Nikolay Borisov
-- strict thread matches above, loose matches on Subject: below --
2018-01-24 9:45 tang.junhui
2018-01-24 9:49 ` Coly Li
2018-01-25 1:50 tang.junhui
2018-01-25 1:58 ` Kent Overstreet
2018-01-25 2:30 tang.junhui
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=bfa1be99-05fd-ffae-3d6d-0d9cae140415@suse.de \
--to=colyli@suse.de \
--cc=linux-bcache@vger.kernel.org \
--cc=linux-block@vger.kernel.org \
--cc=mlyle@lyle.org \
--cc=tang.junhui@zte.com.cn \
/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;
as well as URLs for NNTP newsgroup(s).