* [RFC PATCH v2 0/2] workqueue: Add warnings and check WQ flags usage
@ 2026-05-26 15:00 Marco Crivellari
2026-05-26 15:00 ` [RFC PATCH v2 1/2] workqueue: Add warnings and fallback if system_{unbound}_wq is used Marco Crivellari
2026-05-26 15:00 ` [RFC PATCH v2 2/2] workqueue: Add warnings and ensure one among WQ_PERCPU or WQ_UNBOUND is present Marco Crivellari
0 siblings, 2 replies; 9+ messages in thread
From: Marco Crivellari @ 2026-05-26 15:00 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 and route the
workqueue on system_percpu_wq or system_dfl_wq.
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, a warning will be printed.
~~~~
Few things to note, and that's the main reason because it is an RFC:
1. I wanted to use a compile time error, but considering the new users still
relying on the old workqueue or using alloc_workqueue() without one of the
flags, it means break the code. So I decided to avoid.
2. there are no compile-time warnings: should we add something?
3. __alloc_workqueue() prints the WQ_* messages with pr_warn_ratelimited();
I used this because otherwise with the _once version we're going to see
only the 1st.
4. another option would have been make the workqueue unbound by default, but
of course, it's still not possible due to point 1.
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
kernel/workqueue.c | 91 +++++++++++++++++++++++++++++++++++++++++++++-
1 file changed, 90 insertions(+), 1 deletion(-)
---
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] 9+ messages in thread* [RFC PATCH v2 1/2] workqueue: Add warnings and fallback if system_{unbound}_wq is used
2026-05-26 15:00 [RFC PATCH v2 0/2] workqueue: Add warnings and check WQ flags usage Marco Crivellari
@ 2026-05-26 15:00 ` Marco Crivellari
2026-05-27 18:32 ` Tejun Heo
2026-05-26 15:00 ` [RFC PATCH v2 2/2] workqueue: Add warnings and ensure one among WQ_PERCPU or WQ_UNBOUND is present Marco Crivellari
1 sibling, 1 reply; 9+ messages in thread
From: Marco Crivellari @ 2026-05-26 15:00 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
workqueus are used and redirecting them old used workqueue with the appropriate
new one.
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 | 72 ++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 72 insertions(+)
diff --git a/kernel/workqueue.c b/kernel/workqueue.c
index 33b721a9af02..e17617e205b1 100644
--- a/kernel/workqueue.c
+++ b/kernel/workqueue.c
@@ -2437,6 +2437,24 @@ bool queue_work_on(int cpu, struct workqueue_struct *wq,
bool ret = false;
unsigned long irq_flags;
+ /*
+ * NOTE: These checks are here to assure that no users will still
+ * rely on system_wq and system_unbound_wq.
+ * They can be removed along with those workqueue when the
+ * time comes.
+ */
+ if (unlikely(wq == system_wq)) {
+ pr_warn_once("workqueue: system_wq will be removed shortly. "
+ "Use system_percpu_wq instead. Caller: %ps\n",
+ __builtin_return_address(0));
+ wq = system_percpu_wq;
+ } else if (unlikely(wq == system_unbound_wq)) {
+ pr_warn_once("workqueue: system_unbound_wq will be removed shortly. "
+ "Use system_dfl_wq instead. Caller: %ps\n",
+ __builtin_return_address(0));
+ wq = system_dfl_wq;
+ }
+
local_irq_save(irq_flags);
if (!test_and_set_bit(WORK_STRUCT_PENDING_BIT, work_data_bits(work)) &&
@@ -2604,6 +2622,24 @@ bool queue_delayed_work_on(int cpu, struct workqueue_struct *wq,
bool ret = false;
unsigned long irq_flags;
+ /*
+ * NOTE: These checks are here to assure that no users will still
+ * rely on system_wq and system_unbound_wq.
+ * They can be removed along with those workqueue when the
+ * time comes.
+ */
+ if (unlikely(wq == system_wq)) {
+ pr_warn_once("workqueue: system_wq will be removed shortly. "
+ "Use system_percpu_wq instead. Caller: %ps\n",
+ __builtin_return_address(0));
+ wq = system_percpu_wq;
+ } else if (unlikely(wq == system_unbound_wq)) {
+ pr_warn_once("workqueue: system_unbound_wq will be removed shortly. "
+ "Use system_dfl_wq instead. Caller: %ps\n",
+ __builtin_return_address(0));
+ wq = system_dfl_wq;
+ }
+
/* read the comment in __queue_work() */
local_irq_save(irq_flags);
@@ -2642,6 +2678,24 @@ bool mod_delayed_work_on(int cpu, struct workqueue_struct *wq,
unsigned long irq_flags;
bool ret;
+ /*
+ * NOTE: These checks are here to assure that no users will still
+ * rely on system_wq and system_unbound_wq.
+ * They can be removed along with those workqueue when the
+ * time comes.
+ */
+ if (unlikely(wq == system_wq)) {
+ pr_warn_once("workqueue: system_wq will be removed shortly. "
+ "Use system_percpu_wq instead. Caller: %ps\n",
+ __builtin_return_address(0));
+ wq = system_percpu_wq;
+ } else if (unlikely(wq == system_unbound_wq)) {
+ pr_warn_once("workqueue: system_unbound_wq will be removed shortly. "
+ "Use system_dfl_wq instead. Caller: %ps\n",
+ __builtin_return_address(0));
+ wq = system_dfl_wq;
+ }
+
ret = work_grab_pending(&dwork->work, WORK_CANCEL_DELAYED, &irq_flags);
if (!clear_pending_if_disabled(&dwork->work))
@@ -2676,6 +2730,24 @@ bool queue_rcu_work(struct workqueue_struct *wq, struct rcu_work *rwork)
{
struct work_struct *work = &rwork->work;
+ /*
+ * NOTE: These checks are here to assure that no users will still
+ * rely on system_wq and system_unbound_wq.
+ * They can be removed along with those workqueue when the
+ * time comes.
+ */
+ if (unlikely(wq == system_wq)) {
+ pr_warn_once("workqueue: system_wq will be removed shortly. "
+ "Use system_percpu_wq instead. Caller: %ps\n",
+ __builtin_return_address(0));
+ wq = system_percpu_wq;
+ } else if (unlikely(wq == system_unbound_wq)) {
+ pr_warn_once("workqueue: system_unbound_wq will be removed shortly. "
+ "Use system_dfl_wq instead. Caller: %ps\n",
+ __builtin_return_address(0));
+ wq = system_dfl_wq;
+ }
+
/*
* rcu_work can't be canceled or disabled. Warn if the user reached
* inside @rwork and disabled the inner work.
--
2.54.0
^ permalink raw reply [flat|nested] 9+ messages in thread* Re: [RFC PATCH v2 1/2] workqueue: Add warnings and fallback if system_{unbound}_wq is used
2026-05-26 15:00 ` [RFC PATCH v2 1/2] workqueue: Add warnings and fallback if system_{unbound}_wq is used Marco Crivellari
@ 2026-05-27 18:32 ` Tejun Heo
2026-05-28 8:45 ` Marco Crivellari
2026-05-28 14:14 ` Marco Crivellari
0 siblings, 2 replies; 9+ messages in thread
From: Tejun Heo @ 2026-05-27 18:32 UTC (permalink / raw)
To: Marco Crivellari
Cc: linux-kernel, Lai Jiangshan, Frederic Weisbecker,
Sebastian Andrzej Siewior, Michal Hocko, Breno Leitao
Hello,
On Tue, May 26, 2026 at 05:00:40PM +0200, Marco Crivellari wrote:
> 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
> workqueus are used and redirecting them old used workqueue with the appropriate
> new one.
>
> 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 | 72 ++++++++++++++++++++++++++++++++++++++++++++++
> 1 file changed, 72 insertions(+)
>
> diff --git a/kernel/workqueue.c b/kernel/workqueue.c
> index 33b721a9af02..e17617e205b1 100644
> --- a/kernel/workqueue.c
> +++ b/kernel/workqueue.c
> @@ -2437,6 +2437,24 @@ bool queue_work_on(int cpu, struct workqueue_struct *wq,
> bool ret = false;
> unsigned long irq_flags;
>
> + /*
> + * NOTE: These checks are here to assure that no users will still
> + * rely on system_wq and system_unbound_wq.
> + * They can be removed along with those workqueue when the
> + * time comes.
> + */
> + if (unlikely(wq == system_wq)) {
Can you add an internal flag to mark the workqueues and use a helper so that
the warning messages aren't replicated in multiple places? Also, do we need
to have the warning on delayed_queue? Just put it in a single spot where
they'll all converge.
Thanks.
--
tejun
^ permalink raw reply [flat|nested] 9+ messages in thread* Re: [RFC PATCH v2 1/2] workqueue: Add warnings and fallback if system_{unbound}_wq is used
2026-05-27 18:32 ` Tejun Heo
@ 2026-05-28 8:45 ` Marco Crivellari
2026-05-28 14:22 ` Tejun Heo
2026-05-28 14:14 ` Marco Crivellari
1 sibling, 1 reply; 9+ messages in thread
From: Marco Crivellari @ 2026-05-28 8:45 UTC (permalink / raw)
To: Tejun Heo
Cc: linux-kernel, Lai Jiangshan, Frederic Weisbecker,
Sebastian Andrzej Siewior, Michal Hocko, Breno Leitao
Hello,
On Wed, May 27, 2026 at 8:32 PM Tejun Heo <tj@kernel.org> wrote:
> [...]
> > + /*
> > + * NOTE: These checks are here to assure that no users will still
> > + * rely on system_wq and system_unbound_wq.
> > + * They can be removed along with those workqueue when the
> > + * time comes.
> > + */
> > + if (unlikely(wq == system_wq)) {
>
> Can you add an internal flag to mark the workqueues and use a helper so that
> the warning messages aren't replicated in multiple places? Also, do we need
> to have the warning on delayed_queue? Just put it in a single spot where
> they'll all converge.
Yes, that sounds better indeed. So I can place the warnings directly
inside __queue_work(), calling an inline function?
Regarding the internal flags I guess you mean something like
__WQ_DEPRECATED and use this flag instead of the pointer to perform
the check.
Thanks!
--
Marco Crivellari
SUSE Labs
^ permalink raw reply [flat|nested] 9+ messages in thread* Re: [RFC PATCH v2 1/2] workqueue: Add warnings and fallback if system_{unbound}_wq is used
2026-05-28 8:45 ` Marco Crivellari
@ 2026-05-28 14:22 ` Tejun Heo
0 siblings, 0 replies; 9+ messages in thread
From: Tejun Heo @ 2026-05-28 14:22 UTC (permalink / raw)
To: Marco Crivellari
Cc: linux-kernel, Lai Jiangshan, Frederic Weisbecker,
Sebastian Andrzej Siewior, Michal Hocko, Breno Leitao
Hello,
On Thu, May 28, 2026 at 10:45:23AM +0200, Marco Crivellari wrote:
> Hello,
>
> On Wed, May 27, 2026 at 8:32 PM Tejun Heo <tj@kernel.org> wrote:
> > [...]
> > > + /*
> > > + * NOTE: These checks are here to assure that no users will still
> > > + * rely on system_wq and system_unbound_wq.
> > > + * They can be removed along with those workqueue when the
> > > + * time comes.
> > > + */
> > > + if (unlikely(wq == system_wq)) {
> >
> > Can you add an internal flag to mark the workqueues and use a helper so that
> > the warning messages aren't replicated in multiple places? Also, do we need
> > to have the warning on delayed_queue? Just put it in a single spot where
> > they'll all converge.
>
> Yes, that sounds better indeed. So I can place the warnings directly
> inside __queue_work(), calling an inline function?
If it's just a single palce, open-coding it should be fine too.
Thanks.
--
tejun
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [RFC PATCH v2 1/2] workqueue: Add warnings and fallback if system_{unbound}_wq is used
2026-05-27 18:32 ` Tejun Heo
2026-05-28 8:45 ` Marco Crivellari
@ 2026-05-28 14:14 ` Marco Crivellari
2026-05-28 14:23 ` Tejun Heo
1 sibling, 1 reply; 9+ messages in thread
From: Marco Crivellari @ 2026-05-28 14:14 UTC (permalink / raw)
To: Tejun Heo
Cc: linux-kernel, Lai Jiangshan, Frederic Weisbecker,
Sebastian Andrzej Siewior, Michal Hocko, Breno Leitao
On Wed, May 27, 2026 at 8:32 PM Tejun Heo <tj@kernel.org> wrote:
>
> Hello,
>
> On Tue, May 26, 2026 at 05:00:40PM +0200, Marco Crivellari wrote:
> > 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
> > workqueus are used and redirecting them old used workqueue with the appropriate
> > new one.
> >
> > 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 | 72 ++++++++++++++++++++++++++++++++++++++++++++++
> > 1 file changed, 72 insertions(+)
> >
> > diff --git a/kernel/workqueue.c b/kernel/workqueue.c
> > index 33b721a9af02..e17617e205b1 100644
> > --- a/kernel/workqueue.c
> > +++ b/kernel/workqueue.c
> > @@ -2437,6 +2437,24 @@ bool queue_work_on(int cpu, struct workqueue_struct *wq,
> > bool ret = false;
> > unsigned long irq_flags;
> >
> > + /*
> > + * NOTE: These checks are here to assure that no users will still
> > + * rely on system_wq and system_unbound_wq.
> > + * They can be removed along with those workqueue when the
> > + * time comes.
> > + */
> > + if (unlikely(wq == system_wq)) {
>
> Can you add an internal flag to mark the workqueues and use a helper so that
> the warning messages aren't replicated in multiple places? Also, do we need
> to have the warning on delayed_queue? Just put it in a single spot where
> they'll all converge.
Hello Tejun,
That's maybe a silly observation on my side.
If I remove the checks from where I placed them and move them deeper
(__queue_work() for example), I won't know how to print the "caller,"
making it harder for people to understand which code is using the
deprecated workqueue.
Printing the stack with dump_stack() is not doable.
Do you have suggestions?
Thanks!
--
Marco Crivellari
SUSE Labs
^ permalink raw reply [flat|nested] 9+ messages in thread* Re: [RFC PATCH v2 1/2] workqueue: Add warnings and fallback if system_{unbound}_wq is used
2026-05-28 14:14 ` Marco Crivellari
@ 2026-05-28 14:23 ` Tejun Heo
2026-05-28 14:57 ` Marco Crivellari
0 siblings, 1 reply; 9+ messages in thread
From: Tejun Heo @ 2026-05-28 14:23 UTC (permalink / raw)
To: Marco Crivellari
Cc: linux-kernel, Lai Jiangshan, Frederic Weisbecker,
Sebastian Andrzej Siewior, Michal Hocko, Breno Leitao
On Thu, May 28, 2026 at 04:14:03PM +0200, Marco Crivellari wrote:
> That's maybe a silly observation on my side.
>
> If I remove the checks from where I placed them and move them deeper
> (__queue_work() for example), I won't know how to print the "caller,"
> making it harder for people to understand which code is using the
> deprecated workqueue.
>
> Printing the stack with dump_stack() is not doable.
>
> Do you have suggestions?
For workqueues, identifying the work function and workqueue name should be
good enough. It's not like these are difficult to find.
Thanks.
--
tejun
^ permalink raw reply [flat|nested] 9+ messages in thread* Re: [RFC PATCH v2 1/2] workqueue: Add warnings and fallback if system_{unbound}_wq is used
2026-05-28 14:23 ` Tejun Heo
@ 2026-05-28 14:57 ` Marco Crivellari
0 siblings, 0 replies; 9+ messages in thread
From: Marco Crivellari @ 2026-05-28 14:57 UTC (permalink / raw)
To: Tejun Heo
Cc: linux-kernel, Lai Jiangshan, Frederic Weisbecker,
Sebastian Andrzej Siewior, Michal Hocko, Breno Leitao
On Thu, May 28, 2026 at 4:23 PM Tejun Heo <tj@kernel.org> wrote:
>
> On Thu, May 28, 2026 at 04:14:03PM +0200, Marco Crivellari wrote:
> > That's maybe a silly observation on my side.
> >
> > If I remove the checks from where I placed them and move them deeper
> > (__queue_work() for example), I won't know how to print the "caller,"
> > making it harder for people to understand which code is using the
> > deprecated workqueue.
> >
> > Printing the stack with dump_stack() is not doable.
> >
> > Do you have suggestions?
>
> For workqueues, identifying the work function and workqueue name should be
> good enough. It's not like these are difficult to find.
Cool, let's do like this.
Thanks!
--
Marco Crivellari
SUSE Labs
^ permalink raw reply [flat|nested] 9+ messages in thread
* [RFC PATCH v2 2/2] workqueue: Add warnings and ensure one among WQ_PERCPU or WQ_UNBOUND is present
2026-05-26 15:00 [RFC PATCH v2 0/2] workqueue: Add warnings and check WQ flags usage Marco Crivellari
2026-05-26 15:00 ` [RFC PATCH v2 1/2] workqueue: Add warnings and fallback if system_{unbound}_wq is used Marco Crivellari
@ 2026-05-26 15:00 ` Marco Crivellari
1 sibling, 0 replies; 9+ messages in thread
From: Marco Crivellari @ 2026-05-26 15:00 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 WQ_PERCPU and
avoid this flag is used if WQ_UNBOUND is already present.
So act as following:
- if neither of them is present, set WQ_PERCPU
- if both are present, remove WQ_PERCPU
Along with this change, print a warning, 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 e17617e205b1..d28eb5923a1c 100644
--- a/kernel/workqueue.c
+++ b/kernel/workqueue.c
@@ -5890,7 +5890,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)
@@ -5914,6 +5914,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 (!(flags & (WQ_UNBOUND | WQ_PERCPU))) {
+ pr_warn_ratelimited("workqueue: %s is using neither WQ_PERCPU or WQ_UNBOUND. "
+ "Setting WQ_PERCPU.\n", wq->name);
+ flags |= WQ_PERCPU;
+ } else if((flags & WQ_PERCPU) && (flags & WQ_UNBOUND)) {
+ pr_warn_ratelimited("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 [flat|nested] 9+ messages in thread
end of thread, other threads:[~2026-05-28 14:57 UTC | newest]
Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-05-26 15:00 [RFC PATCH v2 0/2] workqueue: Add warnings and check WQ flags usage Marco Crivellari
2026-05-26 15:00 ` [RFC PATCH v2 1/2] workqueue: Add warnings and fallback if system_{unbound}_wq is used Marco Crivellari
2026-05-27 18:32 ` Tejun Heo
2026-05-28 8:45 ` Marco Crivellari
2026-05-28 14:22 ` Tejun Heo
2026-05-28 14:14 ` Marco Crivellari
2026-05-28 14:23 ` Tejun Heo
2026-05-28 14:57 ` Marco Crivellari
2026-05-26 15:00 ` [RFC PATCH v2 2/2] workqueue: Add warnings and ensure one among WQ_PERCPU or WQ_UNBOUND is present Marco Crivellari
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®