Re: [syzbot] [perf?] KCSAN: data-race in _free_event / perf_pending_task (2)

From: Marco Elver
Date: Mon Oct 14 2024 - 08:42:57 EST


On Mon, 14 Oct 2024 at 12:30, Dmitry Vyukov <dvyukov@xxxxxxxxxx> wrote:
[...]
> But that task is later using 'current' to do something with regard to
> this event:
>
> /*
> * If the task is queued to the current task's queue, we
> * obviously can't wait for it to complete. Simply cancel it.
> */
> if (task_work_cancel(current, head)) {
>
> Is this current wrong here? So it may both not cancel it for the real
> owner, and cancel something else for itself (?).

That's fine - task_work_cancel() looks for the event in the passed
task_struct, and does nothing if not found. If the task_work is owned
by another task, task_work_cancel() will never find a match, and this
is a no-op. The later rcuwait_wait_event() will wait for the task_work
to complete in the other task.