task_work_run: don't take ->pi_lock unconditionally
authorOleg Nesterov <oleg@redhat.com>
Tue, 18 Feb 2020 15:50:18 +0000 (16:50 +0100)
committerJens Axboe <axboe@kernel.dk>
Mon, 2 Mar 2020 21:06:33 +0000 (14:06 -0700)
commit6fb614920b38bbf3c1c7fcd944c6d9b5d746103d
tree07e72f16b7e06d68a6cdfc915dcf4289e188f2bf
parent3684f24653534c71c7dc9f44d7281a838f4e4979
task_work_run: don't take ->pi_lock unconditionally

As Peter pointed out, task_work() can avoid ->pi_lock and cmpxchg()
if task->task_works == NULL && !PF_EXITING.

And in fact the only reason why task_work_run() needs ->pi_lock is
the possible race with task_work_cancel(), we can optimize this code
and make the locking more clear.

Signed-off-by: Oleg Nesterov <oleg@redhat.com>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
kernel/task_work.c