kthread: Don't cancel a work that is being cancelled
PATCH 1/1 kthread: Don't cancel a work that is being cancelled
From: Zhang Qiang <[email protected]>
When canceling a work, if it is found that the work is in the cancelling state, we should directly exit the cancelled operation.
--- kernel/kthread.c | 3 +++ 1 file changed, 3 insertions(+)
kernel/kthread.c +3 -0
@@ -1103,6 +1103,9 @@ static bool __kthread_cancel_work_sync(struct kthread_work *work, bool is_dwork)/* Work must not be used with >1 worker, see kthread_queue_work(). */ WARN_ON_ONCE (work->worker != worker); +if (work->canceling) + goto out_fast; + ret =__kthread_cancel_work (work, is_dwork, &flags);if (worker->current_work != work)
Signature · 1 line
2.24.1
Quoted 5 lines · On Thu 2020-07-02 12:43:24, [email protected] wrote:
From: Zhang Qiang <[email protected]>
When canceling a work, if it is found that the work is in the cancelling state, we should directly exit the cancelled operation.
No, the function guarantees that the work is not longer running when it returns. This is why it has the suffix "_sync" in the name.
We would need to add kthread_cancel_work() without the "_sync" wrappers that would not wait for the work in progress. But it might be dangerous. The API users usually want to make sure that the work in not longer running to avoid races.
What is the use case for the non-sync behavior, please?
Best Regards,
Petr
Thank you for your advice, if add kthread_cancel_work() without the "_sync"
it is be dangerous, But I think it is unnecessary to cancel work which is be canceling.
________________________________________
发件人: [email protected] <[email protected]> 代表 Petr Mladek <[email protected]> 发送时间: 2020年7月3日 15:28
收件人: Zhang, Qiang
抄送: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected] 主题: Re: [PATCH] kthread: Don't cancel a work that is being cancelled
Quoted 5 lines · On Thu 2020-07-02 12:43:24, [email protected] wrote:
From: Zhang Qiang <[email protected]>
When canceling a work, if it is found that the work is in the cancelling state, we should directly exit the cancelled operation.
No, the function guarantees that the work is not longer running when it returns. This is why it has the suffix "_sync" in the name.
We would need to add kthread_cancel_work() without the "_sync" wrappers that would not wait for the work in progress. But it might be dangerous. The API users usually want to make sure that the work in not longer running to avoid races.
What is the use case for the non-sync behavior, please?
Best Regards,
Petr