mirror of
https://github.com/AuxXxilium/linux_dsm_epyc7002.git
synced 2024-12-18 22:56:45 +07:00
e73f8959af
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 <oleg@redhat.com> Acked-by: David Howells <dhowells@redhat.com> Cc: Thomas Gleixner <tglx@linutronix.de> Cc: Richard Kuo <rkuo@codeaurora.org> Cc: Linus Torvalds <torvalds@linux-foundation.org> Cc: Alexander Gordeev <agordeev@redhat.com> Cc: Chris Zankel <chris@zankel.net> Cc: David Smith <dsmith@redhat.com> Cc: "Frank Ch. Eigler" <fche@redhat.com> Cc: Geert Uytterhoeven <geert@linux-m68k.org> Cc: Larry Woodman <lwoodman@redhat.com> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Tejun Heo <tj@kernel.org> Cc: Ingo Molnar <mingo@elte.hu> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
34 lines
748 B
C
34 lines
748 B
C
#ifndef _LINUX_TASK_WORK_H
|
|
#define _LINUX_TASK_WORK_H
|
|
|
|
#include <linux/list.h>
|
|
#include <linux/sched.h>
|
|
|
|
struct task_work;
|
|
typedef void (*task_work_func_t)(struct task_work *);
|
|
|
|
struct task_work {
|
|
struct hlist_node hlist;
|
|
task_work_func_t func;
|
|
void *data;
|
|
};
|
|
|
|
static inline void
|
|
init_task_work(struct task_work *twork, task_work_func_t func, void *data)
|
|
{
|
|
twork->func = func;
|
|
twork->data = data;
|
|
}
|
|
|
|
int task_work_add(struct task_struct *task, struct task_work *twork, bool);
|
|
struct task_work *task_work_cancel(struct task_struct *, task_work_func_t);
|
|
void task_work_run(void);
|
|
|
|
static inline void exit_task_work(struct task_struct *task)
|
|
{
|
|
if (unlikely(!hlist_empty(&task->task_works)))
|
|
task_work_run();
|
|
}
|
|
|
|
#endif /* _LINUX_TASK_WORK_H */
|