task_work_add: generic process-context callbacks
authorOleg Nesterov <[email protected]>
Fri, 11 May 2012 00:59:07 +0000 (10:59 +1000)
committerAl Viro <[email protected]>
Thu, 24 May 2012 02:09:21 +0000 (22:09 -0400)
commite73f8959af0439d114847eab5a8a5ce48f1217c4
tree47f056093590a5e5552e3a75f163e1f798063bda
parent62366c88b29c5a32e1531142092f98eaf49b1103
task_work_add: generic process-context callbacks

Provide a simple mechanism that allows running code in the (nonatomic)
context of the arbitrary task.

The caller does task_work_add(task, task_work) and this task executes
task_work->func() either from do_notify_resume() or from do_exit().  The
callback can rely on PF_EXITING to detect the latter case.

"struct task_work" can be embedded in another struct, still it has "void
*data" to handle the most common/simple case.

This allows us to kill the ->replacement_session_keyring hack, and
potentially this can have more users.

Performance-wise, this adds 2 "unlikely(!hlist_empty())" checks into
tracehook_notify_resume() and do_exit().  But at the same time we can
remove the "replacement_session_keyring != NULL" checks from
arch/*/signal.c and exit_creds().

Note: task_work_add/task_work_run abuses ->pi_lock.  This is only because
this lock is already used by lookup_pi_state() to synchronize with
do_exit() setting PF_EXITING.  Fortunately the scope of this lock in
task_work.c is really tiny, and the code is unlikely anyway.

Signed-off-by: Oleg Nesterov <[email protected]>
Acked-by: David Howells <[email protected]>
Cc: Thomas Gleixner <[email protected]>
Cc: Richard Kuo <[email protected]>
Cc: Linus Torvalds <[email protected]>
Cc: Alexander Gordeev <[email protected]>
Cc: Chris Zankel <[email protected]>
Cc: David Smith <[email protected]>
Cc: "Frank Ch. Eigler" <[email protected]>
Cc: Geert Uytterhoeven <[email protected]>
Cc: Larry Woodman <[email protected]>
Cc: Peter Zijlstra <[email protected]>
Cc: Tejun Heo <[email protected]>
Cc: Ingo Molnar <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Al Viro <[email protected]>
include/linux/sched.h
include/linux/task_work.h [new file with mode: 0644]
include/linux/tracehook.h
kernel/Makefile
kernel/exit.c
kernel/fork.c
kernel/task_work.c [new file with mode: 0644]