Re: [RFC PATCH 1/6] task_work: Provide means to check if a work is queued

From: Oleg Nesterov
Date: Tue Jun 25 2024 - 10:18:57 EST


On 06/25, Frederic Weisbecker wrote:
>
> --- a/kernel/task_work.c
> +++ b/kernel/task_work.c
> @@ -177,6 +177,7 @@ void task_work_run(void)
>
> do {
> next = work->next;
> + work->next = TASK_WORK_DEQUEUED;

OK, but then the additional change below makes sense too?

Oleg.
---

--- x/kernel/task_work.c
+++ x/kernel/task_work.c
@@ -106,8 +106,10 @@ task_work_cancel_match(struct task_struc
if (!match(work, data)) {
pprev = &work->next;
work = READ_ONCE(*pprev);
- } else if (try_cmpxchg(pprev, &work, work->next))
+ } else if (try_cmpxchg(pprev, &work, work->next)) {
+ work->next = TASK_WORK_DEQUEUED;
break;
+ }
}
raw_spin_unlock_irqrestore(&task->pi_lock, flags);