* [PATCH] kthread: Don't cancel a work that is being cancelled
@ 2020-07-02 1:13 qiang.zhang
0 siblings, 0 replies; 3+ messages in thread
From: qiang.zhang @ 2020-07-02 1:13 UTC (permalink / raw)
To: ben.dooks, bfields, cl, peterz; +Cc: linux-kernel
From: Zhang Qiang <qiang.zhang@windriver.com>
When canceling a work, if it is found that the work is in
the cancelling state, we should directly exit the cancelled
operation.
Signed-off-by: Zhang Qiang <qiang.zhang@windriver.com>
---
kernel/kthread.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/kernel/kthread.c b/kernel/kthread.c
index bfbfa481be3a..1166f2043e67 100644
--- a/kernel/kthread.c
+++ b/kernel/kthread.c
@@ -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)
--
2.24.1
^ permalink raw reply [flat|nested] 3+ messages in thread
* [PATCH] kthread: Don't cancel a work that is being cancelled
@ 2020-07-02 4:43 qiang.zhang
2020-07-03 7:28 ` Petr Mladek
0 siblings, 1 reply; 3+ messages in thread
From: qiang.zhang @ 2020-07-02 4:43 UTC (permalink / raw)
To: ben.dooks, bfields, cl, peterz, pmladek, tj; +Cc: linux-kernel
From: Zhang Qiang <qiang.zhang@windriver.com>
When canceling a work, if it is found that the work is in
the cancelling state, we should directly exit the cancelled
operation.
Signed-off-by: Zhang Qiang <qiang.zhang@windriver.com>
---
kernel/kthread.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/kernel/kthread.c b/kernel/kthread.c
index bfbfa481be3a..1166f2043e67 100644
--- a/kernel/kthread.c
+++ b/kernel/kthread.c
@@ -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)
--
2.24.1
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] kthread: Don't cancel a work that is being cancelled
2020-07-02 4:43 qiang.zhang
@ 2020-07-03 7:28 ` Petr Mladek
0 siblings, 0 replies; 3+ messages in thread
From: Petr Mladek @ 2020-07-03 7:28 UTC (permalink / raw)
To: qiang.zhang; +Cc: ben.dooks, bfields, cl, peterz, tj, linux-kernel
On Thu 2020-07-02 12:43:24, qiang.zhang@windriver.com wrote:
> From: Zhang Qiang <qiang.zhang@windriver.com>
>
> 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
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2020-07-03 7:28 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-07-02 1:13 [PATCH] kthread: Don't cancel a work that is being cancelled qiang.zhang
2020-07-02 4:43 qiang.zhang
2020-07-03 7:28 ` Petr Mladek
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®