From: Valentin Schneider <vschneid@redhat.com>
To: linux-kernel@vger.kernel.org
Cc: Tejun Heo <tj@kernel.org>, Lai Jiangshan <jiangshanlai@gmail.com>,
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: [RFC PATCH v3 1/3] workqueue: Hold wq_pool_mutex while affining tasks to wq_unbound_cpumask
Date: Tue, 2 Aug 2022 09:41:44 +0100 [thread overview]
Message-ID: <20220802084146.3922640-2-vschneid@redhat.com> (raw)
In-Reply-To: <20220802084146.3922640-1-vschneid@redhat.com>
When unbind_workers() reads wq_unbound_cpumask to set the affinity of
freshly-unbound kworkers, it only holds wq_pool_attach_mutex. This isn't
sufficient as wq_unbound_cpumask is only protected by wq_pool_mutex.
This is made more obvious as of recent commit
46a4d679ef88 ("workqueue: Avoid a false warning in unbind_workers()")
e.g.
unbind_workers() workqueue_set_unbound_cpumask()
kthread_set_per_cpu(p, -1);
if (cpumask_intersects(wq_unbound_cpumask, cpu_active_mask))
cpumask_copy(wq_unbound_cpumask, cpumask);
WARN_ON_ONCE(set_cpus_allowed_ptr(worker->task, wq_unbound_cpumask) < 0);
Make workqueue_offline_cpu() invoke unbind_workers() with wq_pool_mutex
held.
Fixes: 10a5a651e3af ("workqueue: Restrict kworker in the offline CPU pool running on housekeeping CPUs")
Signed-off-by: Valentin Schneider <vschneid@redhat.com>
---
kernel/workqueue.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/kernel/workqueue.c b/kernel/workqueue.c
index aa8a82bc6738..97cc41430a76 100644
--- a/kernel/workqueue.c
+++ b/kernel/workqueue.c
@@ -5143,14 +5143,15 @@ int workqueue_offline_cpu(unsigned int cpu)
if (WARN_ON(cpu != smp_processor_id()))
return -1;
+ mutex_lock(&wq_pool_mutex);
+
unbind_workers(cpu);
/* update NUMA affinity of unbound workqueues */
- mutex_lock(&wq_pool_mutex);
list_for_each_entry(wq, &workqueues, list)
wq_update_unbound_numa(wq, cpu, false);
- mutex_unlock(&wq_pool_mutex);
+ mutex_unlock(&wq_pool_mutex);
return 0;
}
--
2.31.1
next prev parent reply other threads:[~2022-08-02 8:42 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-08-02 8:41 [RFC PATCH v3 0/3] workqueue: destroy_worker() vs isolated CPUs Valentin Schneider
2022-08-02 8:41 ` Valentin Schneider [this message]
2022-08-03 3:40 ` [RFC PATCH v3 1/3] workqueue: Hold wq_pool_mutex while affining tasks to wq_unbound_cpumask Lai Jiangshan
2022-08-04 11:40 ` Valentin Schneider
2022-08-05 2:43 ` Lai Jiangshan
2022-08-15 23:50 ` Tejun Heo
2022-08-18 14:33 ` [PATCH] workqueue: Protects wq_unbound_cpumask with wq_pool_attach_mutex Lai Jiangshan
2022-08-27 0:33 ` Tejun Heo
2022-08-30 9:32 ` Lai Jiangshan
2022-09-04 20:23 ` Tejun Heo
2022-08-30 14:16 ` [RFC PATCH v3 1/3] workqueue: Hold wq_pool_mutex while affining tasks to wq_unbound_cpumask Lai Jiangshan
2022-08-02 8:41 ` [RFC PATCH v3 2/3] workqueue: Unbind workers before sending them to exit() Valentin Schneider
2022-08-05 3:16 ` Lai Jiangshan
2022-08-05 16:47 ` Valentin Schneider
2022-08-02 8:41 ` [RFC PATCH v3 3/3] DEBUG-DO-NOT-MERGE: workqueue: kworker spawner Valentin Schneider
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=20220802084146.3922640-2-vschneid@redhat.com \
--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