Re: [PATCH] kthread: add kthread_mod_pending_delayed_work api

From: Petr Mladek
Date: Mon Feb 15 2021 - 08:31:01 EST


On Sun 2021-02-14 00:06:11, Yiwei Zhang wrote:
> The existing kthread_mod_delayed_work api will queue a new work if
> failing to cancel the current work due to no longer being pending.
> However, there's a case that the same work can be enqueued from both
> an async request and a delayed work, and a racing could happen if the
> async request comes right after the timeout delayed work gets
> scheduled,

By other words, you want to modify the delayed work only when
it is still waiting in the queue. You do not want to queue new
work when it has not been already queued. Do I get it correctly?

Could you please provide a patch where the new API is used?

> because the clean up work may not be safe to run twice.

This looks like a bad design of the code. There is likely
another race that might break it. You should ask the following
questions:

Why anyone tries to modify the clean up work when it has been already
queued? There should be only one location/caller that triggers the clean up.

Could anyone queue any work to the workqueue after the clean up
work was queued? The cleanup work should be the last queued one.
The workqueue user must inform all other users that the queue
is being destroyed and nobody is allowed to queue any work
any longer.

Best Regards,
Petr