From: Breno Leitao <leitao@debian.org>
To: Tejun Heo <tj@kernel.org>, Lai Jiangshan <jiangshanlai@gmail.com>
Cc: linux-kernel@vger.kernel.org, marco.crivellari@suse.com,
Breno Leitao <leitao@debian.org>,
kernel-team@meta.com, kernel test robot <lkp@intel.com>
Subject: [PATCH 2/3] workqueue: use RCU accessors when populating wq->cpu_pwq
Date: Wed, 12 Aug 2026 09:03:19 -0700 [thread overview]
Message-ID: <20260812-wq_fix-v1-2-f7effcfa8d37@debian.org> (raw)
In-Reply-To: <20260812-wq_fix-v1-0-f7effcfa8d37@debian.org>
wq->cpu_pwq holds RCU-protected pwq pointers, but the percpu allocation
path fills it in with plain loads and stores, which sparse flags:
kernel/workqueue.c:5682:57: sparse: incorrect type in initializer (different address spaces) @@ expected struct pool_workqueue **pwq_p @@ got struct pool_workqueue [noderef] __rcu ** @@
Allocate the array as __rcu pointers and publish each pwq with
rcu_assign_pointer() once it is initialized and linked, the order
install_unbound_pwq() uses.
The warnings are not new: commit 79f23600bc7b ("workqueue: factor out
get_percpu_pool()") only turned the flagged assignment into an
initializer.
Reported-by: kernel test robot <lkp@intel.com>
Closes: https://lore.kernel.org/oe-kbuild-all/202608120931.tvTzq1gD-lkp@intel.com/
Signed-off-by: Breno Leitao <leitao@debian.org>
---
kernel/workqueue.c | 19 ++++++++++++-------
1 file changed, 12 insertions(+), 7 deletions(-)
diff --git a/kernel/workqueue.c b/kernel/workqueue.c
index 1748ef5541a26..83aced28523b5 100644
--- a/kernel/workqueue.c
+++ b/kernel/workqueue.c
@@ -5681,21 +5681,23 @@ static void unbound_wq_update_pwq(struct workqueue_struct *wq, int cpu)
static int alloc_and_link_percpu_pwqs(struct workqueue_struct *wq)
{
+ struct pool_workqueue *pwq;
int cpu;
for_each_possible_cpu(cpu) {
- struct pool_workqueue **pwq_p = per_cpu_ptr(wq->cpu_pwq, cpu);
struct worker_pool *pool = get_percpu_pool(wq, cpu);
- *pwq_p = kmem_cache_alloc_node(pwq_cache, GFP_KERNEL, pool->node);
- if (!*pwq_p)
+ pwq = kmem_cache_alloc_node(pwq_cache, GFP_KERNEL, pool->node);
+ if (!pwq)
return -ENOMEM;
- init_pwq(*pwq_p, wq, pool);
+ init_pwq(pwq, wq, pool);
mutex_lock(&wq->mutex);
- link_pwq(*pwq_p);
+ link_pwq(pwq);
mutex_unlock(&wq->mutex);
+
+ rcu_assign_pointer(*per_cpu_ptr(wq->cpu_pwq, cpu), pwq);
}
return 0;
@@ -5708,7 +5710,7 @@ static int alloc_and_link_pwqs(struct workqueue_struct *wq)
lockdep_assert_held(&wq_pool_mutex);
- wq->cpu_pwq = alloc_percpu(struct pool_workqueue *);
+ wq->cpu_pwq = alloc_percpu(struct pool_workqueue __rcu *);
if (!wq->cpu_pwq)
goto enomem;
@@ -5734,8 +5736,11 @@ static int alloc_and_link_pwqs(struct workqueue_struct *wq)
enomem:
if (wq->cpu_pwq) {
for_each_possible_cpu(cpu) {
- struct pool_workqueue *pwq = *per_cpu_ptr(wq->cpu_pwq, cpu);
+ struct pool_workqueue __rcu **slot;
+ struct pool_workqueue *pwq;
+ slot = per_cpu_ptr(wq->cpu_pwq, cpu);
+ pwq = rcu_access_pointer(*slot);
if (pwq) {
/*
* Unlink pwq from wq->pwqs since link_pwq()
--
2.53.0-Meta
next prev parent reply other threads:[~2026-08-12 16:06 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-12 16:03 [PATCH 0/3] workqueue: sparse and wq_node_nr_active() fixes Breno Leitao
2026-08-12 16:03 ` [PATCH 1/3] workqueue: use rcu_dereference_sched() in workqueue_congested() Breno Leitao
2026-08-12 16:03 ` Breno Leitao [this message]
2026-08-12 16:03 ` [PATCH 3/3] workqueue: BUG_ON() instead of returning NULL in wq_node_nr_active() Breno Leitao
2026-08-12 17:18 ` [PATCH 0/3] workqueue: sparse and wq_node_nr_active() fixes 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=20260812-wq_fix-v1-2-f7effcfa8d37@debian.org \
--to=leitao@debian.org \
--cc=jiangshanlai@gmail.com \
--cc=kernel-team@meta.com \
--cc=linux-kernel@vger.kernel.org \
--cc=lkp@intel.com \
--cc=marco.crivellari@suse.com \
--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®