context_tracking_state.h 993 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. #ifndef _LINUX_CONTEXT_TRACKING_STATE_H
  2. #define _LINUX_CONTEXT_TRACKING_STATE_H
  3. #include <linux/percpu.h>
  4. #include <linux/static_key.h>
  5. struct context_tracking {
  6. /*
  7. * When active is false, probes are unset in order
  8. * to minimize overhead: TIF flags are cleared
  9. * and calls to user_enter/exit are ignored. This
  10. * may be further optimized using static keys.
  11. */
  12. bool active;
  13. enum ctx_state {
  14. IN_KERNEL = 0,
  15. IN_USER,
  16. } state;
  17. };
  18. #ifdef CONFIG_CONTEXT_TRACKING
  19. extern struct static_key context_tracking_enabled;
  20. DECLARE_PER_CPU(struct context_tracking, context_tracking);
  21. static inline bool context_tracking_in_user(void)
  22. {
  23. return __this_cpu_read(context_tracking.state) == IN_USER;
  24. }
  25. static inline bool context_tracking_active(void)
  26. {
  27. return __this_cpu_read(context_tracking.active);
  28. }
  29. #else
  30. static inline bool context_tracking_in_user(void) { return false; }
  31. static inline bool context_tracking_active(void) { return false; }
  32. #endif /* CONFIG_CONTEXT_TRACKING */
  33. #endif