From: Tejun Heo <tj@kernel.org>
To: David Chen <tuxoko@gmail.com>
Cc: Shaohua Li <shli@fb.com>, lkml <linux-kernel@vger.kernel.org>
Subject: Re: blk_mq_freeze_queue hang and possible race in percpu-refcount
Date: Wed, 14 Mar 2018 08:43:12 -0700 [thread overview]
Message-ID: <20180314154312.GZ2943022@devbig577.frc2.facebook.com> (raw)
In-Reply-To: <CAK1sfuYAQf0irGzGxusNg-PdqLSzJ6tSHMENG2Vp8gH1c0FG9w@mail.gmail.com>
Hello, David.
On Tue, Mar 13, 2018 at 03:50:47PM -0700, David Chen wrote:
> ====
> CPU A CPU B
> ----- -----
> percpu_ref_kill() percpu_ref_tryget_live()
> {
> if (__ref_is_percpu())
> set __PERCPU_REF_DEAD;
> __percpu_ref_switch_mode();
> ^ sum up current percpu_count
> this_cpu_inc(*percpu_count); <- this
> increment got leaked.
>
> ====
>
> So if later CPU B later does percpu_ref_put, it will cause ref->count
> to drop to -1.
> And thus causing the above hung task issue.
>
> Do you think this theory is correct, or am I missing something?
> Please tell me what do you think.
The switching to atomic mode does something like the following.
1. Mark the refcnt so that __ref_is_percpu() is false.
2. Wait for RCU grace period so that everyone including
percpu_ref_tryget_live() which has seen true __ref_is_percpu() is
done with its operation.
3. Now that it knows nobody is operating on the assumption that the
counter is in percpu mode, it adds up all the percpu counters.
So, provided there aren't some silly bugs, what you described
shouldn't happen. Can you force the refcnt into atomic mode w/
PERCPU_REF_INIT_ATOMIC and see whether the problem persists?
Thanks.
--
tejun
next prev parent reply other threads:[~2018-03-14 15:43 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-03-13 22:50 David Chen
2018-03-14 15:43 ` Tejun Heo [this message]
2018-03-14 17:42 ` David Chen
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=20180314154312.GZ2943022@devbig577.frc2.facebook.com \
--to=tj@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=shli@fb.com \
--cc=tuxoko@gmail.com \
/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
Powered by JetHome