diff options
Diffstat (limited to 'include/linux')
-rw-r--r-- | include/linux/sched.h | 2 | ||||
-rw-r--r-- | include/linux/task_work.h | 33 | ||||
-rw-r--r-- | include/linux/tracehook.h | 11 |
3 files changed, 46 insertions, 0 deletions
diff --git a/include/linux/sched.h b/include/linux/sched.h index 5ea8baea938..7930131abc1 100644 --- a/include/linux/sched.h +++ b/include/linux/sched.h | |||
@@ -1400,6 +1400,8 @@ struct task_struct { | |||
1400 | int (*notifier)(void *priv); | 1400 | int (*notifier)(void *priv); |
1401 | void *notifier_data; | 1401 | void *notifier_data; |
1402 | sigset_t *notifier_mask; | 1402 | sigset_t *notifier_mask; |
1403 | struct hlist_head task_works; | ||
1404 | |||
1403 | struct audit_context *audit_context; | 1405 | struct audit_context *audit_context; |
1404 | #ifdef CONFIG_AUDITSYSCALL | 1406 | #ifdef CONFIG_AUDITSYSCALL |
1405 | uid_t loginuid; | 1407 | uid_t loginuid; |
diff --git a/include/linux/task_work.h b/include/linux/task_work.h new file mode 100644 index 00000000000..294d5d5e90b --- /dev/null +++ b/include/linux/task_work.h | |||
@@ -0,0 +1,33 @@ | |||
1 | #ifndef _LINUX_TASK_WORK_H | ||
2 | #define _LINUX_TASK_WORK_H | ||
3 | |||
4 | #include <linux/list.h> | ||
5 | #include <linux/sched.h> | ||
6 | |||
7 | struct task_work; | ||
8 | typedef void (*task_work_func_t)(struct task_work *); | ||
9 | |||
10 | struct task_work { | ||
11 | struct hlist_node hlist; | ||
12 | task_work_func_t func; | ||
13 | void *data; | ||
14 | }; | ||
15 | |||
16 | static inline void | ||
17 | init_task_work(struct task_work *twork, task_work_func_t func, void *data) | ||
18 | { | ||
19 | twork->func = func; | ||
20 | twork->data = data; | ||
21 | } | ||
22 | |||
23 | int task_work_add(struct task_struct *task, struct task_work *twork, bool); | ||
24 | struct task_work *task_work_cancel(struct task_struct *, task_work_func_t); | ||
25 | void task_work_run(void); | ||
26 | |||
27 | static inline void exit_task_work(struct task_struct *task) | ||
28 | { | ||
29 | if (unlikely(!hlist_empty(&task->task_works))) | ||
30 | task_work_run(); | ||
31 | } | ||
32 | |||
33 | #endif /* _LINUX_TASK_WORK_H */ | ||
diff --git a/include/linux/tracehook.h b/include/linux/tracehook.h index b9ca903bb55..b2dd0917ca0 100644 --- a/include/linux/tracehook.h +++ b/include/linux/tracehook.h | |||
@@ -49,6 +49,7 @@ | |||
49 | #include <linux/sched.h> | 49 | #include <linux/sched.h> |
50 | #include <linux/ptrace.h> | 50 | #include <linux/ptrace.h> |
51 | #include <linux/security.h> | 51 | #include <linux/security.h> |
52 | #include <linux/task_work.h> | ||
52 | struct linux_binprm; | 53 | struct linux_binprm; |
53 | 54 | ||
54 | /* | 55 | /* |
@@ -164,8 +165,10 @@ static inline void tracehook_signal_handler(int sig, siginfo_t *info, | |||
164 | */ | 165 | */ |
165 | static inline void set_notify_resume(struct task_struct *task) | 166 | static inline void set_notify_resume(struct task_struct *task) |
166 | { | 167 | { |
168 | #ifdef TIF_NOTIFY_RESUME | ||
167 | if (!test_and_set_tsk_thread_flag(task, TIF_NOTIFY_RESUME)) | 169 | if (!test_and_set_tsk_thread_flag(task, TIF_NOTIFY_RESUME)) |
168 | kick_process(task); | 170 | kick_process(task); |
171 | #endif | ||
169 | } | 172 | } |
170 | 173 | ||
171 | /** | 174 | /** |
@@ -185,6 +188,14 @@ static inline void tracehook_notify_resume(struct pt_regs *regs) | |||
185 | { | 188 | { |
186 | if (current->replacement_session_keyring) | 189 | if (current->replacement_session_keyring) |
187 | key_replace_session_keyring(); | 190 | key_replace_session_keyring(); |
191 | /* | ||
192 | * The caller just cleared TIF_NOTIFY_RESUME. This barrier | ||
193 | * pairs with task_work_add()->set_notify_resume() after | ||
194 | * hlist_add_head(task->task_works); | ||
195 | */ | ||
196 | smp_mb__after_clear_bit(); | ||
197 | if (unlikely(!hlist_empty(¤t->task_works))) | ||
198 | task_work_run(); | ||
188 | } | 199 | } |
189 | 200 | ||
190 | #endif /* <linux/tracehook.h> */ | 201 | #endif /* <linux/tracehook.h> */ |