Zqiang
c8f6219be2
workqueue: Fix WARN_ON_ONCE() triggers in worker_enter_idle()
Currently, pool->nr_running can be modified from timer tick, that means the
timer tick can run nested inside a not-irq-protected section that's in the
process of modifying nr_running. Consider the following scenario:
CPU0
kworker/0:2 (events)
worker_clr_flags(worker, WORKER_PREP | WORKER_REBOUND);
->pool->nr_running++; (1)
process_one_work()
->worker->current_func(work);
->schedule()
->wq_worker_sleeping()
->worker->sleeping = 1;
->pool->nr_running--; (0)
....
->wq_worker_running()
....
CPU0 by interrupt:
wq_worker_tick()
->worker_set_flags(worker, WORKER_CPU_INTENSIVE);
->pool->nr_running--; (-1)
->worker->flags |= WORKER_CPU_INTENSIVE;
....
->if (!(worker->flags & WORKER_NOT_RUNNING))
->pool->nr_running++; (will not execute)
->worker->sleeping = 0;
....
->worker_clr_flags(worker, WORKER_CPU_INTENSIVE);
->pool->nr_running++; (0)
....
worker_set_flags(worker, WORKER_PREP);
->pool->nr_running--; (-1)
....
worker_enter_idle()
->WARN_ON_ONCE(pool->nr_workers == pool->nr_idle && pool->nr_running);
if the nr_workers is equal to nr_idle, due to the nr_running is not zero,
will trigger WARN_ON_ONCE().
[ 2.460602] WARNING: CPU: 0 PID: 63 at kernel/workqueue.c:1999 worker_enter_idle+0xb2/0xc0
[ 2.462163] Modules linked in:
[ 2.463401] CPU: 0 PID: 63 Comm: kworker/0:2 Not tainted 6.4.0-rc2-next-20230519 #1
[ 2.463771] Hardware name: QEMU Standard PC (Q35 + ICH9, 2009), BIOS 1.14.0-2 04/01/2014
[ 2.465127] Workqueue: 0x0 (events)
[ 2.465678] RIP: 0010:worker_enter_idle+0xb2/0xc0
...
[ 2.472614] Call Trace:
[ 2.473152] <TASK>
[ 2.474182] worker_thread+0x71/0x430
[ 2.474992] ? _raw_spin_unlock_irqrestore+0x28/0x50
[ 2.475263] kthread+0x103/0x120
[ 2.475493] ? __pfx_worker_thread+0x10/0x10
[ 2.476355] ? __pfx_kthread+0x10/0x10
[ 2.476635] ret_from_fork+0x2c/0x50
[ 2.477051] </TASK>
This commit therefore add the check of worker->sleeping in wq_worker_tick(),
if the worker->sleeping is not zero, directly return.
tj: Updated comment and description.
Reported-by: Naresh Kamboju <naresh.kamboju@linaro.org>
Reported-by: Linux Kernel Functional Testing <lkft@linaro.org>
Tested-by: Anders Roxell <anders.roxell@linaro.org>
Closes: https://qa-reports.linaro.org/lkft/linux-next-master/build/next-20230519/testrun/17078554/suite/boot/test/clang-nightly-lkftconfig/log
Signed-off-by: Zqiang <qiang.zhang1211@gmail.com>
Signed-off-by: Tejun Heo <tj@kernel.org>
2023-05-24 11:57:26 -10:00
..
2023-04-29 10:05:22 -07:00
2023-04-29 10:05:22 -07:00
2023-04-27 12:07:50 -07:00
2022-12-02 11:25:00 +01:00
2023-04-29 10:29:57 -07:00
2023-04-16 14:23:07 +02:00
2023-04-28 14:41:53 -07:00
2023-01-01 11:15:05 -08:00
2022-12-21 14:31:52 -08:00
2023-04-15 10:17:16 +02:00
2023-04-27 19:42:02 -07:00
2023-04-28 14:53:30 -07:00
2023-05-05 12:56:55 -07:00
2023-05-02 20:33:36 -07:00
2023-05-03 12:01:05 -07:00
2023-04-27 19:42:02 -07:00
2023-04-24 12:16:14 -07:00
2023-05-17 17:02:08 -10:00
2023-04-29 10:24:30 -07:00
2023-05-05 13:11:02 -07:00
2022-11-30 16:13:18 -08:00
2022-08-22 18:50:06 -04:00
2022-04-25 14:37:28 +02:00
2022-09-01 17:39:30 -04:00
2022-08-29 19:47:03 -04:00
2022-09-07 11:30:15 -04:00
2023-03-01 10:01:22 -08:00
2022-09-26 19:46:09 -07:00
2023-03-01 10:01:22 -08:00
2022-09-26 10:13:13 -07:00
2023-03-14 19:32:38 -07:00
2023-01-13 11:48:18 +01:00
2023-01-13 11:48:15 +01:00
2023-04-27 19:42:02 -07:00
2023-04-05 19:42:46 -07:00
2022-11-01 10:04:52 -07:00
2023-04-18 16:39:34 -07:00
2023-04-28 15:57:53 -07:00
2022-07-05 13:32:59 -07:00
2023-02-08 13:36:22 +01:00
2023-04-30 13:00:38 -07:00
2022-09-07 21:53:50 +02:00
2023-01-22 23:43:34 +09:00
2022-07-15 18:21:49 +00:00
2023-04-08 13:45:37 -07:00
2023-03-24 11:01:29 +01:00
2022-12-01 15:53:05 -08:00
2022-11-12 18:47:36 -08:00
2023-03-19 13:27:19 -07:00
2022-11-15 00:42:02 -08:00
2023-03-19 13:27:19 -07:00
2023-02-09 16:51:39 -08:00
2023-02-23 17:55:40 -08:00
2023-04-08 13:45:38 -07:00
2022-09-11 21:55:06 -07:00
2023-02-02 22:50:05 -08:00
2023-03-24 20:10:59 -07:00
2023-02-21 08:49:16 +09:00
2023-03-24 17:09:14 +01:00
2023-04-27 19:42:02 -07:00
2022-09-11 21:55:12 -07:00
2023-04-27 16:36:55 -07:00
2023-04-08 13:45:38 -07:00
2023-04-20 22:55:35 -04:00
2023-03-14 17:06:44 +08:00
2023-04-14 17:31:26 +02:00
2023-03-09 12:55:15 -08:00
2023-05-02 19:23:29 -07:00
2023-05-02 19:23:29 -07:00
2023-04-03 11:16:56 +02:00
2022-09-11 21:55:12 -07:00
2023-04-16 14:23:07 +02:00
2022-10-04 15:59:36 +02:00
2023-05-02 17:23:27 -07:00
2023-02-17 14:58:01 -08:00
2022-12-27 12:52:12 +01:00
2022-11-09 18:06:35 +00:00
2023-04-13 11:49:20 -07:00
2023-04-16 09:00:18 +02:00
2023-03-24 11:01:30 +01:00
2022-09-11 21:55:10 -07:00
2023-04-15 10:17:16 +02:00
2023-04-20 11:36:35 +02:00
2022-10-17 16:41:16 +02:00
2022-05-24 11:11:13 -07:00
2022-08-20 15:17:45 -07:00
2023-05-02 17:21:49 -07:00
2022-09-08 16:56:45 -07:00
2023-04-13 11:49:35 -07:00
2022-09-11 21:55:10 -07:00
2022-08-29 12:47:15 +01:00
2023-01-05 12:10:35 -08:00
2023-02-18 14:34:36 -05:00
2022-04-29 14:38:03 -07:00
2022-05-18 18:24:57 -05:00
2023-03-03 16:18:19 -08:00
2023-02-02 22:50:04 -08:00
2022-11-30 20:16:49 -04:00
2022-05-19 23:25:47 -04:00
2023-04-13 11:49:35 -07:00
2023-03-23 12:45:36 +01:00
2023-04-27 16:36:55 -07:00
2022-06-23 18:41:40 +02:00
2022-08-06 16:38:17 -07:00
2023-05-17 17:02:08 -10:00
2023-05-24 11:57:26 -10:00