mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Valentin Schneider <vschneid@redhat.com>
To: Lai Jiangshan <jiangshanlai@gmail.com>
Cc: linux-kernel@vger.kernel.org, Tejun Heo <tj@kernel.org>,
	Peter Zijlstra <peterz@infradead.org>,
	Frederic Weisbecker <frederic@kernel.org>,
	Juri Lelli <juri.lelli@redhat.com>, Phil Auld <pauld@redhat.com>,
	Marcelo Tosatti <mtosatti@redhat.com>
Subject: Re: [PATCH v6 4/4] workqueue: Unbind kworkers before sending them to exit()
Date: Thu, 01 Dec 2022 10:37:30 +0000	[thread overview]
Message-ID: <xhsmh8rjrl89h.mognet@vschneid.remote.csb> (raw)
In-Reply-To: <CAJhGHyB06u=mtbouGBw2CbLX9+gXPSPqHrHZHvorzF+8cPrG+Q@mail.gmail.com>

On 01/12/22 11:01, Lai Jiangshan wrote:
> On Tue, Nov 29, 2022 at 2:31 AM Valentin Schneider <vschneid@redhat.com> wrote:
>
>> @@ -3627,8 +3668,11 @@ static bool wq_manager_inactive(struct worker_pool *pool)
>>  static void put_unbound_pool(struct worker_pool *pool)
>>  {
>>         DECLARE_COMPLETION_ONSTACK(detach_completion);
>> +       struct list_head cull_list;
>>         struct worker *worker;
>>
>> +       INIT_LIST_HEAD(&cull_list);
>> +
>>         lockdep_assert_held(&wq_pool_mutex);
>>
>>         if (--pool->refcnt)
>> @@ -3651,17 +3695,19 @@ static void put_unbound_pool(struct worker_pool *pool)
>>          * Because of how wq_manager_inactive() works, we will hold the
>>          * spinlock after a successful wait.
>>          */
>> +       mutex_lock(&wq_pool_attach_mutex);
>>         rcuwait_wait_event(&manager_wait, wq_manager_inactive(pool),
>>                            TASK_UNINTERRUPTIBLE);
>>         pool->flags |= POOL_MANAGER_ACTIVE;
>
> Hello, Valentin
>
> I'm afraid it might deadlock here.
>
> If put_unbound_pool() is called while manage_workers() is sleeping
> on allocating memory, put_unbound_pool() will get the wq_pool_attach_mutex
> earlier than the manager which prevents the manager from getting the
> lock to attach the newly created worker and deadlock.
>

Well spotted, I can see it now.

> I think mutex_lock(&wq_pool_attach_mutex) can be moved into
> wq_manager_inactive(), and handle it in the same way as pool->lock.
>

That looks sane enough, I'll try to tweak my tests to get the manager
involved to test this out. Thanks!


  reply	other threads:[~2022-12-01 10:38 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-11-28 18:31 [PATCH v6 0/4] workqueue: destroy_worker() vs isolated CPUs Valentin Schneider
2022-11-28 18:31 ` [PATCH v6 1/4] workqueue: Protects wq_unbound_cpumask with wq_pool_attach_mutex Valentin Schneider
2022-11-28 18:31 ` [PATCH v6 2/4] workqueue: Factorize unbind/rebind_workers() logic Valentin Schneider
2022-11-28 18:31 ` [PATCH v6 3/4] workqueue: Convert the idle_timer to a timer + work_struct Valentin Schneider
2022-11-30 21:06   ` Tejun Heo
2022-12-01 11:01     ` Valentin Schneider
2022-11-28 18:31 ` [PATCH v6 4/4] workqueue: Unbind kworkers before sending them to exit() Valentin Schneider
2022-12-01  3:01   ` Lai Jiangshan
2022-12-01 10:37     ` Valentin Schneider [this message]
2022-11-30 21:06 ` [PATCH v6 0/4] workqueue: destroy_worker() vs isolated CPUs Tejun Heo
2022-12-01  3:05   ` Lai Jiangshan

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=xhsmh8rjrl89h.mognet@vschneid.remote.csb \
    --to=vschneid@redhat.com \
    --cc=frederic@kernel.org \
    --cc=jiangshanlai@gmail.com \
    --cc=juri.lelli@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mtosatti@redhat.com \
    --cc=pauld@redhat.com \
    --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®