1/* SPDX-License-Identifier: GPL-2.0-or-later */
2#ifndef _LINUX_LIVEPATCH_SCHED_H_
3#define _LINUX_LIVEPATCH_SCHED_H_
4
5#include <linux/jump_label.h>
6#include <linux/sched.h>
7
8#ifdef CONFIG_LIVEPATCH
9
10void __klp_sched_try_switch(void);
11
12DECLARE_STATIC_KEY_FALSE(klp_sched_try_switch_key);
13
14static __always_inline void klp_sched_try_switch(struct task_struct *curr)
15{
16 if (static_branch_unlikely(&klp_sched_try_switch_key) &&
17 READ_ONCE(curr->__state) & TASK_FREEZABLE)
18 __klp_sched_try_switch();
19}
20
21#else /* !CONFIG_LIVEPATCH */
22static inline void klp_sched_try_switch(struct task_struct *curr) {}
23#endif /* CONFIG_LIVEPATCH */
24
25#endif /* _LINUX_LIVEPATCH_SCHED_H_ */
26