Frederic Weisbecker | e7358b3 | 2013-07-12 02:15:49 +0200 | [diff] [blame] | 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; |
Frederic Weisbecker | aed5ed4 | 2015-05-06 18:04:23 +0200 | [diff] [blame] | 15 | int recursion; |
Frederic Weisbecker | e7358b3 | 2013-07-12 02:15:49 +0200 | [diff] [blame] | 16 | enum ctx_state { |
Andy Lutomirski | f928164 | 2015-07-03 12:44:21 -0700 | [diff] [blame] | 17 | CONTEXT_DISABLED = -1, /* returned by ct_state() if unknown */ |
Frederic Weisbecker | c467ea7 | 2015-03-04 18:06:33 +0100 | [diff] [blame] | 18 | CONTEXT_KERNEL = 0, |
| 19 | CONTEXT_USER, |
Rik van Riel | 126a6a5 | 2015-02-10 15:27:54 -0500 | [diff] [blame] | 20 | CONTEXT_GUEST, |
Frederic Weisbecker | e7358b3 | 2013-07-12 02:15:49 +0200 | [diff] [blame] | 21 | } state; |
| 22 | }; |
| 23 | |
| 24 | #ifdef CONFIG_CONTEXT_TRACKING |
| 25 | extern struct static_key context_tracking_enabled; |
| 26 | DECLARE_PER_CPU(struct context_tracking, context_tracking); |
| 27 | |
Frederic Weisbecker | 58135f5 | 2013-11-06 14:45:57 +0100 | [diff] [blame] | 28 | static inline bool context_tracking_is_enabled(void) |
| 29 | { |
| 30 | return static_key_false(&context_tracking_enabled); |
| 31 | } |
Frederic Weisbecker | d0df09e | 2013-11-06 15:11:57 +0100 | [diff] [blame] | 32 | |
| 33 | static inline bool context_tracking_cpu_is_enabled(void) |
| 34 | { |
| 35 | return __this_cpu_read(context_tracking.active); |
| 36 | } |
| 37 | |
Frederic Weisbecker | e7358b3 | 2013-07-12 02:15:49 +0200 | [diff] [blame] | 38 | static inline bool context_tracking_in_user(void) |
| 39 | { |
Frederic Weisbecker | c467ea7 | 2015-03-04 18:06:33 +0100 | [diff] [blame] | 40 | return __this_cpu_read(context_tracking.state) == CONTEXT_USER; |
Frederic Weisbecker | e7358b3 | 2013-07-12 02:15:49 +0200 | [diff] [blame] | 41 | } |
Frederic Weisbecker | e7358b3 | 2013-07-12 02:15:49 +0200 | [diff] [blame] | 42 | #else |
| 43 | static inline bool context_tracking_in_user(void) { return false; } |
| 44 | static inline bool context_tracking_active(void) { return false; } |
Rik van Riel | a3a9c7d | 2015-02-10 15:27:51 -0500 | [diff] [blame] | 45 | static inline bool context_tracking_is_enabled(void) { return false; } |
| 46 | static inline bool context_tracking_cpu_is_enabled(void) { return false; } |
Frederic Weisbecker | e7358b3 | 2013-07-12 02:15:49 +0200 | [diff] [blame] | 47 | #endif /* CONFIG_CONTEXT_TRACKING */ |
| 48 | |
| 49 | #endif |