1 /* SPDX-License-Identifier: GPL-2.0-only */
3 #ifndef LINUX_RESUME_USER_MODE_H
4 #define LINUX_RESUME_USER_MODE_H
6 #include <linux/sched.h>
7 #include <linux/task_work.h>
8 #include <linux/memcontrol.h>
9 #include <linux/rseq.h>
10 #include <linux/blk-cgroup.h>
13 * set_notify_resume - cause resume_user_mode_work() to be called
14 * @task: task that will call resume_user_mode_work()
16 * Calling this arranges that @task will call resume_user_mode_work()
17 * before returning to user mode. If it's already running in user mode,
18 * it will enter the kernel and call resume_user_mode_work() soon.
19 * If it's blocked, it will not be woken.
21 static inline void set_notify_resume(struct task_struct *task)
23 if (!test_and_set_tsk_thread_flag(task, TIF_NOTIFY_RESUME))
29 * resume_user_mode_work - Perform work before returning to user mode
30 * @regs: user-mode registers of @current task
32 * This is called when %TIF_NOTIFY_RESUME has been set. Now we are
33 * about to return to user mode, and the user state in @regs can be
34 * inspected or adjusted. The caller in arch code has cleared
35 * %TIF_NOTIFY_RESUME before the call. If the flag gets set again
36 * asynchronously, this will be called again before we return to
39 * Called without locks.
41 static inline void resume_user_mode_work(struct pt_regs *regs)
43 clear_thread_flag(TIF_NOTIFY_RESUME);
45 * This barrier pairs with task_work_add()->set_notify_resume() after
46 * hlist_add_head(task->task_works);
48 smp_mb__after_atomic();
49 if (unlikely(task_work_pending(current)))
52 #ifdef CONFIG_KEYS_REQUEST_CACHE
53 if (unlikely(current->cached_requested_key)) {
54 key_put(current->cached_requested_key);
55 current->cached_requested_key = NULL;
59 mem_cgroup_handle_over_high(GFP_KERNEL);
60 blkcg_maybe_throttle_current();
62 rseq_handle_notify_resume(NULL, regs);
65 #endif /* LINUX_RESUME_USER_MODE_H */