diff options
Diffstat (limited to 'include/linux/context_tracking_state.h')
-rw-r--r-- | include/linux/context_tracking_state.h | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/include/linux/context_tracking_state.h b/include/linux/context_tracking_state.h new file mode 100644 index 000000000000..0f1979d0674f --- /dev/null +++ b/include/linux/context_tracking_state.h | |||
@@ -0,0 +1,39 @@ | |||
1 | #ifndef _LINUX_CONTEXT_TRACKING_STATE_H | ||
2 | #define _LINUX_CONTEXT_TRACKING_STATE_H | ||
3 | |||
4 | #include <linux/percpu.h> | ||
5 | #include <linux/static_key.h> | ||
6 | |||
7 | struct context_tracking { | ||
8 | /* | ||
9 | * When active is false, probes are unset in order | ||
10 | * to minimize overhead: TIF flags are cleared | ||
11 | * and calls to user_enter/exit are ignored. This | ||
12 | * may be further optimized using static keys. | ||
13 | */ | ||
14 | bool active; | ||
15 | enum ctx_state { | ||
16 | IN_KERNEL = 0, | ||
17 | IN_USER, | ||
18 | } state; | ||
19 | }; | ||
20 | |||
21 | #ifdef CONFIG_CONTEXT_TRACKING | ||
22 | extern struct static_key context_tracking_enabled; | ||
23 | DECLARE_PER_CPU(struct context_tracking, context_tracking); | ||
24 | |||
25 | static inline bool context_tracking_in_user(void) | ||
26 | { | ||
27 | return __this_cpu_read(context_tracking.state) == IN_USER; | ||
28 | } | ||
29 | |||
30 | static inline bool context_tracking_active(void) | ||
31 | { | ||
32 | return __this_cpu_read(context_tracking.active); | ||
33 | } | ||
34 | #else | ||
35 | static inline bool context_tracking_in_user(void) { return false; } | ||
36 | static inline bool context_tracking_active(void) { return false; } | ||
37 | #endif /* CONFIG_CONTEXT_TRACKING */ | ||
38 | |||
39 | #endif | ||