* [PATCH v2] workqueue: warn if delayed_work is queued to an offlined cpu.
@ 2025-01-09 23:27 Imran Khan
2025-01-10 18:33 ` Tejun Heo
0 siblings, 1 reply; 2+ messages in thread
From: Imran Khan @ 2025-01-09 23:27 UTC (permalink / raw)
To: tj, jiangshanlai; +Cc: linux-kernel
delayed_work submitted to an offlined cpu, will not get executed,
after the specified delay if the cpu remains offline. If the cpu
never comes online the work will never get executed.
checking for online cpu in __queue_delayed_work, does not sound
like a good idea because to do this reliably we need hotplug lock
and since work may be submitted from atomic contexts, we would
have to use cpus_read_trylock. But if trylock fails we would queue
the work on any cpu and this may not be optimal because our intended
cpu might still be online.
Putting a WARN_ON_ONCE for an already offlined cpu, will indicate users
of queue_delayed_work_on, if they are (wrongly) trying to queue
delayed_work on offlined cpu. Also indicate the problem of using
offlined cpu with queue_delayed_work_on, in its description.
Signed-off-by: Imran Khan <imran.f.khan@oracle.com>
---
changes since v1:
- use WARN_ON_ONCE in place of WARN_ON.
- modify description of queue_delayed_work_on, to include
why the caller needs to ensure that specified CPU remains
around for non-zero delays.
kernel/workqueue.c | 7 +++++++
1 file changed, 7 insertions(+)
diff --git a/kernel/workqueue.c b/kernel/workqueue.c
index 8e0bb3c608239..3c2c45313c886 100644
--- a/kernel/workqueue.c
+++ b/kernel/workqueue.c
@@ -2508,6 +2508,7 @@ static void __queue_delayed_work(int cpu, struct workqueue_struct *wq,
return;
}
+ WARN_ON_ONCE(cpu != WORK_CPU_UNBOUND && !cpu_online(cpu));
dwork->wq = wq;
dwork->cpu = cpu;
timer->expires = jiffies + delay;
@@ -2533,6 +2534,12 @@ static void __queue_delayed_work(int cpu, struct workqueue_struct *wq,
* @dwork: work to queue
* @delay: number of jiffies to wait before queueing
*
+ * We queue the delayed_work to a specific CPU, for non-zero delays the
+ * caller must ensure it is online and can't go away. Callers that fail
+ * to ensure this, may get @dwork->timer queued to an offlined CPU and
+ * this will prevent queueing of @dwork->work unless the offlined CPU
+ * becomes online again.
+ *
* Return: %false if @work was already on a queue, %true otherwise. If
* @delay is zero and @dwork is idle, it will be scheduled for immediate
* execution.
base-commit: 6ecd20965bdc21b265a0671ccf36d9ad8043f5ab
--
2.34.1
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH v2] workqueue: warn if delayed_work is queued to an offlined cpu.
2025-01-09 23:27 [PATCH v2] workqueue: warn if delayed_work is queued to an offlined cpu Imran Khan
@ 2025-01-10 18:33 ` Tejun Heo
0 siblings, 0 replies; 2+ messages in thread
From: Tejun Heo @ 2025-01-10 18:33 UTC (permalink / raw)
To: Imran Khan; +Cc: jiangshanlai, linux-kernel
On Fri, Jan 10, 2025 at 10:27:11AM +1100, Imran Khan wrote:
> delayed_work submitted to an offlined cpu, will not get executed,
> after the specified delay if the cpu remains offline. If the cpu
> never comes online the work will never get executed.
> checking for online cpu in __queue_delayed_work, does not sound
> like a good idea because to do this reliably we need hotplug lock
> and since work may be submitted from atomic contexts, we would
> have to use cpus_read_trylock. But if trylock fails we would queue
> the work on any cpu and this may not be optimal because our intended
> cpu might still be online.
>
> Putting a WARN_ON_ONCE for an already offlined cpu, will indicate users
> of queue_delayed_work_on, if they are (wrongly) trying to queue
> delayed_work on offlined cpu. Also indicate the problem of using
> offlined cpu with queue_delayed_work_on, in its description.
>
> Signed-off-by: Imran Khan <imran.f.khan@oracle.com>
Applied to wq/for-6.13-fixes.
Thanks.
--
tejun
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2025-01-10 18:34 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-01-09 23:27 [PATCH v2] workqueue: warn if delayed_work is queued to an offlined cpu Imran Khan
2025-01-10 18:33 ` Tejun Heo
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®