All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v4 0/2] workqueue: Add warnings and check WQ flags usage
@ 2026-05-29 13:06 Marco Crivellari
  2026-05-29 13:06 ` [PATCH v4 1/2] workqueue: Add warnings and fallback if system_{unbound}_wq is used Marco Crivellari
                   ` (2 more replies)
  0 siblings, 3 replies; 10+ messages in thread
From: Marco Crivellari @ 2026-05-29 13:06 UTC (permalink / raw)
  To: linux-kernel
  Cc: Tejun Heo, Lai Jiangshan, Frederic Weisbecker,
	Sebastian Andrzej Siewior, Marco Crivellari, Michal Hocko,
	Breno Leitao

Hi,

Currently system_wq and system_unbound_wq can still be used and no message
is printed. To avoid further use of them, add a warning. The detection of
deprecated workqueue is done using a new internal flag, called __WQ_DEPRECATED.

Similar scenario for WQ_PERCPU and WQ_UNBOUND. Currently there are still
users that use alloc_workqueue(,0,). To avoid such situations, a couple
of checks have been added:

  - if neither of the flag is present, set WQ_PERCPU
  - if both are present, remove WQ_PERCPU

Along with these, WARN_ONCE() is used.

Thanks!


Marco Crivellari (2):
  workqueue: Add warnings and fallback if system_{unbound}_wq is used
  workqueue: Add warnings and ensure one among WQ_PERCPU or WQ_UNBOUND
    is present

 include/linux/workqueue.h |  1 +
 kernel/workqueue.c        | 31 ++++++++++++++++++++++++++++---
 2 files changed, 29 insertions(+), 3 deletions(-)

---
Changes in v4:
- P2: instead of pr_warn_once() use WARN_ONCE()

Link to v3: https://lore.kernel.org/all/20260528160159.471265-1-marco.crivellari@suse.com/

Changes in v3:
- system_wq / system_unbond_wq not routed to the newer. The warnings have been simpliified
  keeping only one of them inside __queue_work() printing the work function.

- the deprecated status is detected using a new internal flag, called __WQ_DEPRECATED.

Link to v2: https://lore.kernel.org/all/20260526150041.365392-1-marco.crivellari@suse.com/

Changes in v2:
- rebased on v7.1-rc5

- fixed typo in the text

- cleared WQ_PERCPU when wq_pwer_efficient flag is set, to avoid triggering a warning

- if statement to route old workqueue to newer also added in queue_rcu_work()

Link to v1: https://lore.kernel.org/all/20260514092354.125149-1-marco.crivellari@suse.com/

-- 
2.54.0


^ permalink raw reply	[flat|nested] 10+ messages in thread

* [PATCH v4 1/2] workqueue: Add warnings and fallback if system_{unbound}_wq is used
  2026-05-29 13:06 [PATCH v4 0/2] workqueue: Add warnings and check WQ flags usage Marco Crivellari
@ 2026-05-29 13:06 ` Marco Crivellari
  2026-05-29 13:06 ` [PATCH v4 2/2] workqueue: Add warnings and ensure one among WQ_PERCPU or WQ_UNBOUND is present Marco Crivellari
  2026-05-29 18:07 ` [PATCH v4 0/2] workqueue: Add warnings and check WQ flags usage Tejun Heo
  2 siblings, 0 replies; 10+ messages in thread
From: Marco Crivellari @ 2026-05-29 13:06 UTC (permalink / raw)
  To: linux-kernel
  Cc: Tejun Heo, Lai Jiangshan, Frederic Weisbecker,
	Sebastian Andrzej Siewior, Marco Crivellari, Michal Hocko,
	Breno Leitao

Currently many users transitioned already to the new introduced workqueue
(system_percpu_wq, system_dfl_wq), but there are new users who still use the
older system_wq and system_unbound_wq.

This change try to push this transition forward, by warning whether the old
workqueues are used.

Link: https://lore.kernel.org/all/20250221112003.1dSuoGyc@linutronix.de/
Suggested-by: Tejun Heo <tj@kernel.org>
Signed-off-by: Marco Crivellari <marco.crivellari@suse.com>
---
 include/linux/workqueue.h |  1 +
 kernel/workqueue.c        | 12 ++++++++++--
 2 files changed, 11 insertions(+), 2 deletions(-)

diff --git a/include/linux/workqueue.h b/include/linux/workqueue.h
index 6177624539b3..a283766a192a 100644
--- a/include/linux/workqueue.h
+++ b/include/linux/workqueue.h
@@ -409,6 +409,7 @@ enum wq_flags {
 	__WQ_DRAINING		= 1 << 16, /* internal: workqueue is draining */
 	__WQ_ORDERED		= 1 << 17, /* internal: workqueue is ordered */
 	__WQ_LEGACY		= 1 << 18, /* internal: create*_workqueue() */
+	__WQ_DEPRECATED		= 1 << 19, /* internal: workqueue is deprecated */
 
 	/* BH wq only allows the following flags */
 	__WQ_BH_ALLOWS		= WQ_BH | WQ_HIGHPRI | WQ_PERCPU,
diff --git a/kernel/workqueue.c b/kernel/workqueue.c
index 33b721a9af02..0b55f8009eed 100644
--- a/kernel/workqueue.c
+++ b/kernel/workqueue.c
@@ -2280,6 +2280,14 @@ static void __queue_work(int cpu, struct workqueue_struct *wq,
 	unsigned int work_flags;
 	unsigned int req_cpu = cpu;
 
+	/*
+	 * NOTE: Check whether the used workqueue is deprecated and warn
+	 */
+	if (unlikely(wq->flags & __WQ_DEPRECATED))
+		pr_warn_once("workqueue: work func %ps enqueued on deprecated workqueue. "
+			"Use system_{percpu|dfl}_wq instead.\n",
+			work->func);
+
 	/*
 	 * While a work item is PENDING && off queue, a task trying to
 	 * steal the PENDING will busy-loop waiting for it to either get
@@ -8037,12 +8045,12 @@ void __init workqueue_init_early(void)
 		ordered_wq_attrs[i] = attrs;
 	}
 
-	system_wq = alloc_workqueue("events", WQ_PERCPU, 0);
+	system_wq = alloc_workqueue("events", WQ_PERCPU | __WQ_DEPRECATED, 0);
 	system_percpu_wq = alloc_workqueue("events", WQ_PERCPU, 0);
 	system_highpri_wq = alloc_workqueue("events_highpri",
 					    WQ_HIGHPRI | WQ_PERCPU, 0);
 	system_long_wq = alloc_workqueue("events_long", WQ_PERCPU, 0);
-	system_unbound_wq = alloc_workqueue("events_unbound", WQ_UNBOUND, WQ_MAX_ACTIVE);
+	system_unbound_wq = alloc_workqueue("events_unbound", WQ_UNBOUND | __WQ_DEPRECATED, WQ_MAX_ACTIVE);
 	system_dfl_wq = alloc_workqueue("events_unbound", WQ_UNBOUND, WQ_MAX_ACTIVE);
 	system_freezable_wq = alloc_workqueue("events_freezable",
 					      WQ_FREEZABLE | WQ_PERCPU, 0);
-- 
2.54.0


^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH v4 2/2] workqueue: Add warnings and ensure one among WQ_PERCPU or WQ_UNBOUND is present
  2026-05-29 13:06 [PATCH v4 0/2] workqueue: Add warnings and check WQ flags usage Marco Crivellari
  2026-05-29 13:06 ` [PATCH v4 1/2] workqueue: Add warnings and fallback if system_{unbound}_wq is used Marco Crivellari
@ 2026-05-29 13:06 ` Marco Crivellari
  2026-05-29 18:07 ` [PATCH v4 0/2] workqueue: Add warnings and check WQ flags usage Tejun Heo
  2 siblings, 0 replies; 10+ messages in thread
From: Marco Crivellari @ 2026-05-29 13:06 UTC (permalink / raw)
  To: linux-kernel
  Cc: Tejun Heo, Lai Jiangshan, Frederic Weisbecker,
	Sebastian Andrzej Siewior, Marco Crivellari, Michal Hocko,
	Breno Leitao

Currently there are no checks in order to enforce the use of one between
WQ_PERCPU or WQ_UNBOUND.

So act as following:
- if neither of them is present, set WQ_PERCPU
- if both are present, remove WQ_PERCPU

Along with this change, WARN_ONCE(), so that the code still uses both or
neither of them, can be changed.

Link: https://lore.kernel.org/all/20250221112003.1dSuoGyc@linutronix.de/
Suggested-by: Tejun Heo <tj@kernel.org>
Signed-off-by: Marco Crivellari <marco.crivellari@suse.com>
---
 kernel/workqueue.c | 19 ++++++++++++++++++-
 1 file changed, 18 insertions(+), 1 deletion(-)

diff --git a/kernel/workqueue.c b/kernel/workqueue.c
index 0b55f8009eed..d4799e93d10f 100644
--- a/kernel/workqueue.c
+++ b/kernel/workqueue.c
@@ -5826,7 +5826,7 @@ static struct workqueue_struct *__alloc_workqueue(const char *fmt,
 
 	/* see the comment above the definition of WQ_POWER_EFFICIENT */
 	if ((flags & WQ_POWER_EFFICIENT) && wq_power_efficient)
-		flags |= WQ_UNBOUND;
+		flags = (flags & ~WQ_PERCPU) | WQ_UNBOUND;
 
 	/* allocate wq and format name */
 	if (flags & WQ_UNBOUND)
@@ -5850,6 +5850,23 @@ static struct workqueue_struct *__alloc_workqueue(const char *fmt,
 		pr_warn_once("workqueue: name exceeds WQ_NAME_LEN. Truncating to: %s\n",
 			     wq->name);
 
+	/*
+	 * One among WQ_PERCPU and WQ_UNBOUND must be set, but not both.
+	 * - If neither is set, default to WQ_PERCPU
+	 * - If both are set, default to WQ_UNBOUND
+	 *
+	 * This code can be removed after workqueue are unbound by default
+	 */
+	if (unlikely(!(flags & (WQ_UNBOUND | WQ_PERCPU)))) {
+		WARN_ONCE(1, "workqueue: %s is using neither WQ_PERCPU or WQ_UNBOUND. "
+			  "Setting WQ_PERCPU.\n", wq->name);
+		flags |= WQ_PERCPU;
+	} else if(unlikely((flags & WQ_PERCPU) && (flags & WQ_UNBOUND))) {
+		WARN_ONCE(1, "workqueue: %s uses both WQ_PERCPU and WQ_UNBOUND. "
+			  "Dropped WQ_PERCPU, keeping WQ_UNBOUND.\n", wq->name);
+		flags &= (~WQ_PERCPU);
+	}
+
 	if (flags & WQ_BH) {
 		/*
 		 * BH workqueues always share a single execution context per CPU
-- 
2.54.0


^ permalink raw reply related	[flat|nested] 10+ messages in thread

* Re: [PATCH v4 0/2] workqueue: Add warnings and check WQ flags usage
  2026-05-29 13:06 [PATCH v4 0/2] workqueue: Add warnings and check WQ flags usage Marco Crivellari
  2026-05-29 13:06 ` [PATCH v4 1/2] workqueue: Add warnings and fallback if system_{unbound}_wq is used Marco Crivellari
  2026-05-29 13:06 ` [PATCH v4 2/2] workqueue: Add warnings and ensure one among WQ_PERCPU or WQ_UNBOUND is present Marco Crivellari
@ 2026-05-29 18:07 ` Tejun Heo
  2026-05-30 10:54   ` Tetsuo Handa
  2026-06-01 15:41   ` Marco Crivellari
  2 siblings, 2 replies; 10+ messages in thread
From: Tejun Heo @ 2026-05-29 18:07 UTC (permalink / raw)
  To: Marco Crivellari
  Cc: linux-kernel, Lai Jiangshan, Frederic Weisbecker,
	Sebastian Andrzej Siewior, Michal Hocko, Breno Leitao

Hello,

On Fri, May 29, 2026 at 03:06:38PM +0200, Marco Crivellari wrote:
> Marco Crivellari (2):
>   workqueue: Add warnings and fallback if system_{unbound}_wq is used
>   workqueue: Add warnings and ensure one among WQ_PERCPU or WQ_UNBOUND
>     is present

Applied 1-2 to wq/for-7.2. I fixed up minor whitespace on 2/2: added the
missing space in "else if (" and dropped the redundant parentheses around
~WQ_PERCPU.

Thanks.

-- 
tejun

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH v4 0/2] workqueue: Add warnings and check WQ flags usage
  2026-05-29 18:07 ` [PATCH v4 0/2] workqueue: Add warnings and check WQ flags usage Tejun Heo
@ 2026-05-30 10:54   ` Tetsuo Handa
  2026-05-31 16:48     ` Tejun Heo
  2026-06-01 15:41   ` Marco Crivellari
  1 sibling, 1 reply; 10+ messages in thread
From: Tetsuo Handa @ 2026-05-30 10:54 UTC (permalink / raw)
  To: Tejun Heo, Marco Crivellari
  Cc: linux-kernel, Lai Jiangshan, Frederic Weisbecker,
	Sebastian Andrzej Siewior, Michal Hocko, Breno Leitao

On 2026/05/30 3:07, Tejun Heo wrote:
> Hello,
> 
> On Fri, May 29, 2026 at 03:06:38PM +0200, Marco Crivellari wrote:
>> Marco Crivellari (2):
>>   workqueue: Add warnings and fallback if system_{unbound}_wq is used
>>   workqueue: Add warnings and ensure one among WQ_PERCPU or WQ_UNBOUND
>>     is present
> 
> Applied 1-2 to wq/for-7.2. I fixed up minor whitespace on 2/2: added the
> missing space in "else if (" and dropped the redundant parentheses around
> ~WQ_PERCPU.

Please don't use WARN_ONCE(), please use printk() but don't emit WARNING: or BUG: in the string.
syzbot is failing to test linux-next kernels due to commit 21c05ca88a54 ("workqueue:
Add warnings and ensure one among WQ_PERCPU or WQ_UNBOUND is present").
We can't tolerate linux-next being untested until all callers are fixed.


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH v4 0/2] workqueue: Add warnings and check WQ flags usage
  2026-05-30 10:54   ` Tetsuo Handa
@ 2026-05-31 16:48     ` Tejun Heo
  2026-05-31 22:12       ` Tetsuo Handa
  0 siblings, 1 reply; 10+ messages in thread
From: Tejun Heo @ 2026-05-31 16:48 UTC (permalink / raw)
  To: Tetsuo Handa, Marco Crivellari
  Cc: linux-kernel, Lai Jiangshan, Frederic Weisbecker,
	Sebastian Andrzej Siewior, Michal Hocko, Breno Leitao

Sorry for the slow reply - I'm off at the moment so my latency is high.

> syzbot is failing to test linux-next kernels due to commit 21c05ca88a54
> ("workqueue: Add warnings and ensure one among WQ_PERCPU or WQ_UNBOUND is
> present").
> We can't tolerate linux-next being untested until all callers are fixed.

Which caller is breaking which tests?

Reverting 21c05ca88a54 is easy, but there's no clean point to do it: the
warning is in the wq tree while the caller fixes are scattered across several
subsystem trees, and there's no reasonable way to synchronize all of that
outside mainline. If it's a specific caller breaking a test, fixing that one
is the better path.

Thanks.

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH v4 0/2] workqueue: Add warnings and check WQ flags usage
  2026-05-31 16:48     ` Tejun Heo
@ 2026-05-31 22:12       ` Tetsuo Handa
  2026-06-01 14:47         ` Tejun Heo
  0 siblings, 1 reply; 10+ messages in thread
From: Tetsuo Handa @ 2026-05-31 22:12 UTC (permalink / raw)
  To: Tejun Heo, Marco Crivellari
  Cc: linux-kernel, Lai Jiangshan, Frederic Weisbecker,
	Sebastian Andrzej Siewior, Michal Hocko, Breno Leitao

On 2026/06/01 1:48, Tejun Heo wrote:
> Sorry for the slow reply - I'm off at the moment so my latency is high.
> 
>> syzbot is failing to test linux-next kernels due to commit 21c05ca88a54
>> ("workqueue: Add warnings and ensure one among WQ_PERCPU or WQ_UNBOUND is
>> present").
>> We can't tolerate linux-next being untested until all callers are fixed.
> 
> Which caller is breaking which tests?

It is https://syzkaller.appspot.com/bug?extid=d078cba4418e65f61984 .

Even 10 days of being unable to test linux-next tree
( https://lkml.kernel.org/r/1a9f53d4-6f48-4df8-a3d8-2b0e442a163a@I-love.SAKURA.ne.jp )
can cause difficulty of identifying a culprit.

> 
> Reverting 21c05ca88a54 is easy, but there's no clean point to do it: the
> warning is in the wq tree while the caller fixes are scattered across several
> subsystem trees, and there's no reasonable way to synchronize all of that
> outside mainline. If it's a specific caller breaking a test, fixing that one
> is the better path.
> 

I've spent more than one year for updating all in-tree users who are
flushing kernel global workqueues. Please see a message from Linus at
https://lkml.kernel.org/r/CAHk-=whWreGjEQ6yasspzBrNnS7EQiL+SknToWt=SzUh4XomyQ@mail.gmail.com .

Please never try to emit WARNING: or BUG: message just for letting developers
update their code. If you can't use panic() instead of WARN*() or BUG*(), you
should not use WARN*() or BUG*(). The patch author who changes the behavior of
in-tree code is responsible for updating all in-tree code.


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH v4 0/2] workqueue: Add warnings and check WQ flags usage
  2026-05-31 22:12       ` Tetsuo Handa
@ 2026-06-01 14:47         ` Tejun Heo
  2026-06-01 17:51           ` Tetsuo Handa
  0 siblings, 1 reply; 10+ messages in thread
From: Tejun Heo @ 2026-06-01 14:47 UTC (permalink / raw)
  To: Tetsuo Handa
  Cc: Marco Crivellari, linux-kernel, Lai Jiangshan,
	Frederic Weisbecker, Sebastian Andrzej Siewior, Michal Hocko,
	Breno Leitao

On Mon, Jun 01, 2026 at 07:12:28AM +0900, Tetsuo Handa wrote:
> I've spent more than one year for updating all in-tree users who are
> flushing kernel global workqueues. Please see a message from Linus at
> https://lkml.kernel.org/r/CAHk-=whWreGjEQ6yasspzBrNnS7EQiL+SknToWt=SzUh4XomyQ@mail.gmail.com .
> 
> Please never try to emit WARNING: or BUG: message just for letting developers
> update their code. If you can't use panic() instead of WARN*() or BUG*(), you
> should not use WARN*() or BUG*(). The patch author who changes the behavior of
> in-tree code is responsible for updating all in-tree code.

I don't think a statement this blanket makes sense. I scanned the existing
linux-next tree and there were a handful that were missed (I didn't find out
whether they are new ones in linux-next or ones that were misseds from
mainline tho). Let's just apply the nvme-tcp patch and move on.

Thanks.

-- 
tejun

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH v4 0/2] workqueue: Add warnings and check WQ flags usage
  2026-05-29 18:07 ` [PATCH v4 0/2] workqueue: Add warnings and check WQ flags usage Tejun Heo
  2026-05-30 10:54   ` Tetsuo Handa
@ 2026-06-01 15:41   ` Marco Crivellari
  1 sibling, 0 replies; 10+ messages in thread
From: Marco Crivellari @ 2026-06-01 15:41 UTC (permalink / raw)
  To: Tejun Heo
  Cc: linux-kernel, Lai Jiangshan, Frederic Weisbecker,
	Sebastian Andrzej Siewior, Michal Hocko, Breno Leitao

On Fri, May 29, 2026 at 8:07 PM Tejun Heo <tj@kernel.org> wrote:
>
> Hello,
>
> On Fri, May 29, 2026 at 03:06:38PM +0200, Marco Crivellari wrote:
> > Marco Crivellari (2):
> >   workqueue: Add warnings and fallback if system_{unbound}_wq is used
> >   workqueue: Add warnings and ensure one among WQ_PERCPU or WQ_UNBOUND
> >     is present
>
> Applied 1-2 to wq/for-7.2. I fixed up minor whitespace on 2/2: added the
> missing space in "else if (" and dropped the redundant parentheses around
> ~WQ_PERCPU.

Hello Tejun,

Many thanks!

-- 

Marco Crivellari

SUSE Labs

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH v4 0/2] workqueue: Add warnings and check WQ flags usage
  2026-06-01 14:47         ` Tejun Heo
@ 2026-06-01 17:51           ` Tetsuo Handa
  0 siblings, 0 replies; 10+ messages in thread
From: Tetsuo Handa @ 2026-06-01 17:51 UTC (permalink / raw)
  To: Tejun Heo, Mark Brown, Linux-Next Mailing List, Linus Torvalds
  Cc: Marco Crivellari, linux-kernel, Lai Jiangshan,
	Frederic Weisbecker, Sebastian Andrzej Siewior, Michal Hocko,
	Breno Leitao

On 2026/06/01 23:47, Tejun Heo wrote:
> On Mon, Jun 01, 2026 at 07:12:28AM +0900, Tetsuo Handa wrote:
>> I've spent more than one year for updating all in-tree users who are
>> flushing kernel global workqueues. Please see a message from Linus at
>> https://lkml.kernel.org/r/CAHk-=whWreGjEQ6yasspzBrNnS7EQiL+SknToWt=SzUh4XomyQ@mail.gmail.com .
>>
>> Please never try to emit WARNING: or BUG: message just for letting developers
>> update their code. If you can't use panic() instead of WARN*() or BUG*(), you
>> should not use WARN*() or BUG*(). The patch author who changes the behavior of
>> in-tree code is responsible for updating all in-tree code.
> 
> I don't think a statement this blanket makes sense. I scanned the existing
> linux-next tree and there were a handful that were missed (I didn't find out
> whether they are new ones in linux-next or ones that were misseds from
> mainline tho). Let's just apply the nvme-tcp patch and move on.

Not all users are quickly accepting patches. Please apply all fixes *before* you start
emitting WARNING: message. You are currently making linux-next tree untestable by syzbot.

> 
> Thanks.
> 

Mark Brown, please skip WQ changes from linux-next until all fixes are applied.

Linus, please be sure to skip WQ changes in the upcoming merge window if some fix
does not get applied in time for the merge window. (Of course, applying all fixes
before we start emitting WARNING: message is desirable for bisectability, even if
all fixes are get applied in time for the merge window...)


^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2026-06-01 17:51 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-05-29 13:06 [PATCH v4 0/2] workqueue: Add warnings and check WQ flags usage Marco Crivellari
2026-05-29 13:06 ` [PATCH v4 1/2] workqueue: Add warnings and fallback if system_{unbound}_wq is used Marco Crivellari
2026-05-29 13:06 ` [PATCH v4 2/2] workqueue: Add warnings and ensure one among WQ_PERCPU or WQ_UNBOUND is present Marco Crivellari
2026-05-29 18:07 ` [PATCH v4 0/2] workqueue: Add warnings and check WQ flags usage Tejun Heo
2026-05-30 10:54   ` Tetsuo Handa
2026-05-31 16:48     ` Tejun Heo
2026-05-31 22:12       ` Tetsuo Handa
2026-06-01 14:47         ` Tejun Heo
2026-06-01 17:51           ` Tetsuo Handa
2026-06-01 15:41   ` Marco Crivellari

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.