From: Boqun Feng <boqun.feng@gmail.com>
To: Lai Jiangshan <jiangshanlai@gmail.com>
Cc: LKML <linux-kernel@vger.kernel.org>,
Josef Bacik <josef@toxicpanda.com>,
Peter Zijlstra <peterz@infradead.org>, Tejun Heo <tj@kernel.org>
Subject: Re: [RFC] workqueue: Fix irq inversion deadlock in manage_workers()
Date: Mon, 9 Oct 2017 20:40:09 +0800 [thread overview]
Message-ID: <20171009124009.o2b6s2et6itquwyd@tardis> (raw)
In-Reply-To: <CAJhGHyAqKWJHT=_38338bQmqG4HZuz=5-J3J0H4yM3GVDK319w@mail.gmail.com>
[-- Attachment #1: Type: text/plain, Size: 3773 bytes --]
On Mon, Oct 09, 2017 at 09:40:43AM +0000, Lai Jiangshan wrote:
[...]
> > Reported-by: Josef Bacik <josef@toxicpanda.com>
> > Signed-off-by: Boqun Feng <boqun.feng@gmail.com>
> > Cc: Peter Zijlstra <peterz@infradead.org>
> > ---
> > kernel/workqueue.c | 35 ++++++++++++++++++++++++++++++++++-
> > 1 file changed, 34 insertions(+), 1 deletion(-)
> >
> > diff --git a/kernel/workqueue.c b/kernel/workqueue.c
> > index 64d0edf428f8..2ea7b04cc48b 100644
> > --- a/kernel/workqueue.c
> > +++ b/kernel/workqueue.c
> > @@ -1997,7 +1997,40 @@ static bool manage_workers(struct worker *worker)
> > maybe_create_worker(pool);
> >
> > pool->manager = NULL;
> > +
> > + /*
> > + * Put the manager back to ->idle_list, this allows us to drop the
> > + * pool->lock safely without racing with put_unbound_pool()
> > + *
> > + * <in "manager worker" thread>
> > + * worker_thread():
> > + * spin_lock_irq(&pool->lock);
> > + * worker_leave_idle();
> > + * manage_workers(): // return true
> > + * mutex_trylock(&pool->manager_arb);
> > + * <without entering idle here>
> > + * spin_unlock_irq(&pool->lock);
> > + * mutex_unlock(&pool->manager_arb);
> > + *
> > + * put_unbound_pool():
> > + * mutex_lock(&pool->manager_arb);
> > + * spin_lock_irq(&pool->lock);
> > + * <set ILDE worker to DIE>
> > + * <the manager worker is not set to be DIE, because it's not IDLE>
> > + * ...
> > + * wait_for_completion(&pool->detach_completion);
> > + * <no one will complete() because pool->workers is not empty>
> > + *
> > + * spin_lock_irq(&pool->lock);
> > + * <pool->worklist is empty, go to sleep>
> > + *
> > + * No one is going to wake up the manager worker, even so, it won't
> > + * complete(->detach_completion), since it's not a DIE worker.
> > + */
> > + worker_enter_idle(worker);
> > + spin_unlock_irq(&pool->lock);
> > mutex_unlock(&pool->manager_arb);
> > + spin_lock_irq(&pool->lock);
> > return true;
> > }
> >
> > @@ -2202,6 +2235,7 @@ static int worker_thread(void *__worker)
> > woke_up:
> > spin_lock_irq(&pool->lock);
> >
> > +recheck:
> > /* am I supposed to die? */
> > if (unlikely(worker->flags & WORKER_DIE)) {
> > spin_unlock_irq(&pool->lock);
> > @@ -2216,7 +2250,6 @@ static int worker_thread(void *__worker)
> > }
> >
> > worker_leave_idle(worker);
>
> I think worker_leave_idle() might be called multiple times,
"Multiple times" is not a problem, the problem is unbalanced
enter/leave, right?
> which might cause bugs, since recheck is moved up.
>
And that's impossible, as we only goto recheck if manage_workers()
return true, and that means the worker got the manager_arb and set
itself idle again. So it's fine.
Regards,
Boqun
> > -recheck:
> > /* no more worker necessary? */
> > if (!need_more_worker(pool))
> > goto sleep;
> > --
> > 2.14.1
> >
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]
next prev parent reply other threads:[~2017-10-09 12:39 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-10-08 9:02 Boqun Feng
2017-10-08 19:03 ` Tejun Heo
2017-10-09 3:24 ` Boqun Feng
2017-10-09 6:42 ` Peter Zijlstra
2017-10-09 13:07 ` Tejun Heo
2017-10-09 9:40 ` Lai Jiangshan
2017-10-09 12:40 ` Boqun Feng [this message]
2017-10-09 15:24 ` Peter Zijlstra
2017-10-09 15:29 ` Tejun Heo
2017-10-09 13:21 ` [PATCH workqueue/for-4.14-fixes] workqueue: replace pool->manager_arb mutex with a flag Tejun Heo
2017-10-09 14:21 ` Boqun Feng
2017-10-09 14:47 ` Tejun Heo
2017-10-09 15:02 ` Lai Jiangshan
2017-10-09 15:08 ` Tejun Heo
2017-10-09 15:14 ` Lai Jiangshan
2017-10-09 15:33 ` Tejun Heo
2017-10-09 15:04 ` [PATCH v2 " Tejun Heo
2017-10-10 9:55 ` Lai Jiangshan
2017-10-10 14:15 ` Tejun Heo
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=20171009124009.o2b6s2et6itquwyd@tardis \
--to=boqun.feng@gmail.com \
--cc=jiangshanlai@gmail.com \
--cc=josef@toxicpanda.com \
--cc=linux-kernel@vger.kernel.org \
--cc=peterz@infradead.org \
--cc=tj@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®