Commit | Line | Data |
---|---|---|
e7358b3b FW |
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; | |
aed5ed47 | 15 | int recursion; |
e7358b3b | 16 | enum ctx_state { |
c467ea76 FW |
17 | CONTEXT_KERNEL = 0, |
18 | CONTEXT_USER, | |
126a6a54 | 19 | CONTEXT_GUEST, |
e7358b3b FW |
20 | } state; |
21 | }; | |
22 | ||
23 | #ifdef CONFIG_CONTEXT_TRACKING | |
24 | extern struct static_key context_tracking_enabled; | |
25 | DECLARE_PER_CPU(struct context_tracking, context_tracking); | |
26 | ||
58135f57 FW |
27 | static inline bool context_tracking_is_enabled(void) |
28 | { | |
29 | return static_key_false(&context_tracking_enabled); | |
30 | } | |
d0df09eb FW |
31 | |
32 | static inline bool context_tracking_cpu_is_enabled(void) | |
e7358b3b | 33 | { |
d0df09eb | 34 | return __this_cpu_read(context_tracking.active); |
e7358b3b FW |
35 | } |
36 | ||
d0df09eb | 37 | static inline bool context_tracking_in_user(void) |
e7358b3b | 38 | { |
c467ea76 | 39 | return __this_cpu_read(context_tracking.state) == CONTEXT_USER; |
e7358b3b FW |
40 | } |
41 | #else | |
42 | static inline bool context_tracking_in_user(void) { return false; } | |
43 | static inline bool context_tracking_active(void) { return false; } | |
a3a9c7df RR |
44 | static inline bool context_tracking_is_enabled(void) { return false; } |
45 | static inline bool context_tracking_cpu_is_enabled(void) { return false; } | |
e7358b3b FW |
46 | #endif /* CONFIG_CONTEXT_TRACKING */ |
47 | ||
48 | #endif |