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>
Thu, 27 Feb 2020 21:21:22 +0000 (14:21 -0700)
commit3b668ecf75f94f40c1faf9688ba3f32fb5e9f5d0
tree8bb9651b2faa25ef3ebf2c8320112abcbe7d7c24
parent52b31bc9aabca8c3ba023ff60cf701c0567b1267
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