1 /* SPDX-License-Identifier: GPL-2.0 */
4 * The Kernel Concurrency Sanitizer (KCSAN) infrastructure. For more info please
5 * see Documentation/dev-tools/kcsan.rst.
8 #ifndef _KERNEL_KCSAN_KCSAN_H
9 #define _KERNEL_KCSAN_KCSAN_H
11 #include <linux/atomic.h>
12 #include <linux/kcsan.h>
13 #include <linux/sched.h>
15 /* The number of adjacent watchpoints to check. */
16 #define KCSAN_CHECK_ADJACENT 1
17 #define NUM_SLOTS (1 + 2*KCSAN_CHECK_ADJACENT)
19 extern unsigned int kcsan_udelay_task;
20 extern unsigned int kcsan_udelay_interrupt;
23 * Globally enable and disable KCSAN.
25 extern bool kcsan_enabled;
28 * Save/restore IRQ flags state trace dirtied by KCSAN.
30 void kcsan_save_irqtrace(struct task_struct *task);
31 void kcsan_restore_irqtrace(struct task_struct *task);
34 * Statistics counters displayed via debugfs; should only be modified in
37 enum kcsan_counter_id {
39 * Number of watchpoints currently in use.
41 KCSAN_COUNTER_USED_WATCHPOINTS,
44 * Total number of watchpoints set up.
46 KCSAN_COUNTER_SETUP_WATCHPOINTS,
49 * Total number of data races.
51 KCSAN_COUNTER_DATA_RACES,
54 * Total number of ASSERT failures due to races. If the observed race is
55 * due to two conflicting ASSERT type accesses, then both will be
58 KCSAN_COUNTER_ASSERT_FAILURES,
61 * Number of times no watchpoints were available.
63 KCSAN_COUNTER_NO_CAPACITY,
66 * A thread checking a watchpoint raced with another checking thread;
67 * only one will be reported.
69 KCSAN_COUNTER_REPORT_RACES,
72 * Observed data value change, but writer thread unknown.
74 KCSAN_COUNTER_RACES_UNKNOWN_ORIGIN,
77 * The access cannot be encoded to a valid watchpoint.
79 KCSAN_COUNTER_UNENCODABLE_ACCESSES,
82 * Watchpoint encoding caused a watchpoint to fire on mismatching
85 KCSAN_COUNTER_ENCODING_FALSE_POSITIVES,
87 KCSAN_COUNTER_COUNT, /* number of counters */
89 extern atomic_long_t kcsan_counters[KCSAN_COUNTER_COUNT];
92 * Returns true if data races in the function symbol that maps to func_addr
93 * (offsets are ignored) should *not* be reported.
95 extern bool kcsan_skip_report_debugfs(unsigned long func_addr);
98 * Value-change states.
100 enum kcsan_value_change {
102 * Did not observe a value-change, however, it is valid to report the
103 * race, depending on preferences.
105 KCSAN_VALUE_CHANGE_MAYBE,
108 * Did not observe a value-change, and it is invalid to report the race.
110 KCSAN_VALUE_CHANGE_FALSE,
113 * The value was observed to change, and the race should be reported.
115 KCSAN_VALUE_CHANGE_TRUE,
118 enum kcsan_report_type {
120 * The thread that set up the watchpoint and briefly stalled was
121 * signalled that another thread triggered the watchpoint.
123 KCSAN_REPORT_RACE_SIGNAL,
126 * A thread found and consumed a matching watchpoint.
128 KCSAN_REPORT_CONSUMED_WATCHPOINT,
131 * No other thread was observed to race with the access, but the data
132 * value before and after the stall differs.
134 KCSAN_REPORT_RACE_UNKNOWN_ORIGIN,
138 * Print a race report from thread that encountered the race.
140 extern void kcsan_report(const volatile void *ptr, size_t size, int access_type,
141 enum kcsan_value_change value_change,
142 enum kcsan_report_type type, int watchpoint_idx);
144 #endif /* _KERNEL_KCSAN_KCSAN_H */