[RFC PATCH 2/2] workqueue: Add warnings and ensure one among WQ_PERCPU or WQ_UNBOUND is present
From: Marco Crivellari
Date: Thu May 14 2026 - 05:24:10 EST
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@xxxxxxxxxxxxx/
Suggested-by: Tejun Heo <tj@xxxxxxxxxx>
Signed-off-by: Marco Crivellari <marco.crivellari@xxxxxxxx>
---
kernel/workqueue.c | 18 ++++++++++++++++++
1 file changed, 18 insertions(+)
diff --git a/kernel/workqueue.c b/kernel/workqueue.c
index 80d9c91ae606..80e6efb4aa52 100644
--- a/kernel/workqueue.c
+++ b/kernel/workqueue.c
@@ -5882,6 +5882,24 @@ 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. "
+ "Seting 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