6.18-stable review patch. If anyone has any objections, please let me know. ------------------ From: Breno Leitao [ Upstream commit 3180ee71b676845603274c66f6bb5528939cf470 ] Add is_percpu_pool() and test the pool directly for per cpu. Convert the other open-coded pool->cpu checks -- in put_unbound_pool(), pool_allowed_cpus() and the workqueue watchdog -- to the same helper. No functional change. Signed-off-by: Breno Leitao Signed-off-by: Tejun Heo Use a single-evaluation macro for the pool predicate. Keep the existing watchdog timestamp and reporting behavior, converting only its pool-type test; the newer stall-duration accounting is absent. Stable-dep-of: cf9c8aaea0d4 ("workqueue: Fix unbound pool lifetime for pending pwqs") Signed-off-by: Sasha Levin Signed-off-by: Greg Kroah-Hartman --- kernel/workqueue.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) --- a/kernel/workqueue.c +++ b/kernel/workqueue.c @@ -1562,6 +1562,9 @@ work_func_t wq_worker_last_func(struct t return worker->last_func; } +/* True if @pool is a static per-cpu pool rather than an unbound one. */ +#define is_percpu_pool(pool) ((pool)->cpu >= 0) + /** * wq_node_nr_active - Determine wq_node_nr_active to use * @wq: workqueue of interest @@ -2689,7 +2692,7 @@ static struct worker *alloc_worker(int n static cpumask_t *pool_allowed_cpus(struct worker_pool *pool) { - if (pool->cpu < 0 && pool->attrs->affn_strict) + if (!is_percpu_pool(pool) && pool->attrs->affn_strict) return pool->attrs->__pod_cpumask; else return pool->attrs->cpumask; @@ -5030,7 +5033,7 @@ static void put_unbound_pool(struct work return; /* sanity checks */ - if (WARN_ON(!(pool->cpu < 0)) || + if (WARN_ON(is_percpu_pool(pool)) || WARN_ON(!list_empty(&pool->worklist))) return; @@ -5182,7 +5185,7 @@ static void pwq_release_workfn(struct kt mutex_unlock(&wq->mutex); } - if (wq->flags & WQ_UNBOUND) { + if (!is_percpu_pool(pool)) { mutex_lock(&wq_pool_mutex); put_unbound_pool(pool); mutex_unlock(&wq_pool_mutex); @@ -7720,7 +7723,7 @@ static void wq_watchdog_timer_fn(struct /* did we stall? */ if (time_after(now, ts + thresh)) { lockup_detected = true; - if (pool->cpu >= 0 && !(pool->flags & POOL_BH)) { + if (is_percpu_pool(pool) && !(pool->flags & POOL_BH)) { pool->cpu_stall = true; cpu_pool_stall = true; }