kcsan.h 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /*
  3. * The Kernel Concurrency Sanitizer (KCSAN) infrastructure. Public interface and
  4. * data structures to set up runtime. See kcsan-checks.h for explicit checks and
  5. * modifiers. For more info please see Documentation/dev-tools/kcsan.rst.
  6. *
  7. * Copyright (C) 2019, Google LLC.
  8. */
  9. #ifndef _LINUX_KCSAN_H
  10. #define _LINUX_KCSAN_H
  11. #include <linux/kcsan-checks.h>
  12. #include <linux/types.h>
  13. #ifdef CONFIG_KCSAN
  14. /*
  15. * Context for each thread of execution: for tasks, this is stored in
  16. * task_struct, and interrupts access internal per-CPU storage.
  17. */
  18. struct kcsan_ctx {
  19. int disable_count; /* disable counter */
  20. int disable_scoped; /* disable scoped access counter */
  21. int atomic_next; /* number of following atomic ops */
  22. /*
  23. * We distinguish between: (a) nestable atomic regions that may contain
  24. * other nestable regions; and (b) flat atomic regions that do not keep
  25. * track of nesting. Both (a) and (b) are entirely independent of each
  26. * other, and a flat region may be started in a nestable region or
  27. * vice-versa.
  28. *
  29. * This is required because, for example, in the annotations for
  30. * seqlocks, we declare seqlock writer critical sections as (a) nestable
  31. * atomic regions, but reader critical sections as (b) flat atomic
  32. * regions, but have encountered cases where seqlock reader critical
  33. * sections are contained within writer critical sections (the opposite
  34. * may be possible, too).
  35. *
  36. * To support these cases, we independently track the depth of nesting
  37. * for (a), and whether the leaf level is flat for (b).
  38. */
  39. int atomic_nest_count;
  40. bool in_flat_atomic;
  41. /*
  42. * Access mask for all accesses if non-zero.
  43. */
  44. unsigned long access_mask;
  45. /* List of scoped accesses; likely to be empty. */
  46. struct list_head scoped_accesses;
  47. #ifdef CONFIG_KCSAN_WEAK_MEMORY
  48. /*
  49. * Scoped access for modeling access reordering to detect missing memory
  50. * barriers; only keep 1 to keep fast-path complexity manageable.
  51. */
  52. struct kcsan_scoped_access reorder_access;
  53. #endif
  54. };
  55. /**
  56. * kcsan_init - initialize KCSAN runtime
  57. */
  58. void kcsan_init(void);
  59. #else /* CONFIG_KCSAN */
  60. static inline void kcsan_init(void) { }
  61. #endif /* CONFIG_KCSAN */
  62. #endif /* _LINUX_KCSAN_H */