![]() |
|
|||
0001 /* SPDX-License-Identifier: GPL-2.0 */ 0002 /* 0003 * The Kernel Concurrency Sanitizer (KCSAN) infrastructure. For more info please 0004 * see Documentation/dev-tools/kcsan.rst. 0005 * 0006 * Copyright (C) 2019, Google LLC. 0007 */ 0008 0009 #ifndef _KERNEL_KCSAN_KCSAN_H 0010 #define _KERNEL_KCSAN_KCSAN_H 0011 0012 #include <linux/atomic.h> 0013 #include <linux/kcsan.h> 0014 #include <linux/sched.h> 0015 0016 /* The number of adjacent watchpoints to check. */ 0017 #define KCSAN_CHECK_ADJACENT 1 0018 #define NUM_SLOTS (1 + 2*KCSAN_CHECK_ADJACENT) 0019 0020 extern unsigned int kcsan_udelay_task; 0021 extern unsigned int kcsan_udelay_interrupt; 0022 0023 /* 0024 * Globally enable and disable KCSAN. 0025 */ 0026 extern bool kcsan_enabled; 0027 0028 /* 0029 * Save/restore IRQ flags state trace dirtied by KCSAN. 0030 */ 0031 void kcsan_save_irqtrace(struct task_struct *task); 0032 void kcsan_restore_irqtrace(struct task_struct *task); 0033 0034 /* 0035 * Statistics counters displayed via debugfs; should only be modified in 0036 * slow-paths. 0037 */ 0038 enum kcsan_counter_id { 0039 /* 0040 * Number of watchpoints currently in use. 0041 */ 0042 KCSAN_COUNTER_USED_WATCHPOINTS, 0043 0044 /* 0045 * Total number of watchpoints set up. 0046 */ 0047 KCSAN_COUNTER_SETUP_WATCHPOINTS, 0048 0049 /* 0050 * Total number of data races. 0051 */ 0052 KCSAN_COUNTER_DATA_RACES, 0053 0054 /* 0055 * Total number of ASSERT failures due to races. If the observed race is 0056 * due to two conflicting ASSERT type accesses, then both will be 0057 * counted. 0058 */ 0059 KCSAN_COUNTER_ASSERT_FAILURES, 0060 0061 /* 0062 * Number of times no watchpoints were available. 0063 */ 0064 KCSAN_COUNTER_NO_CAPACITY, 0065 0066 /* 0067 * A thread checking a watchpoint raced with another checking thread; 0068 * only one will be reported. 0069 */ 0070 KCSAN_COUNTER_REPORT_RACES, 0071 0072 /* 0073 * Observed data value change, but writer thread unknown. 0074 */ 0075 KCSAN_COUNTER_RACES_UNKNOWN_ORIGIN, 0076 0077 /* 0078 * The access cannot be encoded to a valid watchpoint. 0079 */ 0080 KCSAN_COUNTER_UNENCODABLE_ACCESSES, 0081 0082 /* 0083 * Watchpoint encoding caused a watchpoint to fire on mismatching 0084 * accesses. 0085 */ 0086 KCSAN_COUNTER_ENCODING_FALSE_POSITIVES, 0087 0088 KCSAN_COUNTER_COUNT, /* number of counters */ 0089 }; 0090 extern atomic_long_t kcsan_counters[KCSAN_COUNTER_COUNT]; 0091 0092 /* 0093 * Returns true if data races in the function symbol that maps to func_addr 0094 * (offsets are ignored) should *not* be reported. 0095 */ 0096 extern bool kcsan_skip_report_debugfs(unsigned long func_addr); 0097 0098 /* 0099 * Value-change states. 0100 */ 0101 enum kcsan_value_change { 0102 /* 0103 * Did not observe a value-change, however, it is valid to report the 0104 * race, depending on preferences. 0105 */ 0106 KCSAN_VALUE_CHANGE_MAYBE, 0107 0108 /* 0109 * Did not observe a value-change, and it is invalid to report the race. 0110 */ 0111 KCSAN_VALUE_CHANGE_FALSE, 0112 0113 /* 0114 * The value was observed to change, and the race should be reported. 0115 */ 0116 KCSAN_VALUE_CHANGE_TRUE, 0117 }; 0118 0119 /* 0120 * The calling thread hit and consumed a watchpoint: set the access information 0121 * to be consumed by the reporting thread. No report is printed yet. 0122 */ 0123 void kcsan_report_set_info(const volatile void *ptr, size_t size, int access_type, 0124 unsigned long ip, int watchpoint_idx); 0125 0126 /* 0127 * The calling thread observed that the watchpoint it set up was hit and 0128 * consumed: print the full report based on information set by the racing 0129 * thread. 0130 */ 0131 void kcsan_report_known_origin(const volatile void *ptr, size_t size, int access_type, 0132 unsigned long ip, enum kcsan_value_change value_change, 0133 int watchpoint_idx, u64 old, u64 new, u64 mask); 0134 0135 /* 0136 * No other thread was observed to race with the access, but the data value 0137 * before and after the stall differs. Reports a race of "unknown origin". 0138 */ 0139 void kcsan_report_unknown_origin(const volatile void *ptr, size_t size, int access_type, 0140 unsigned long ip, u64 old, u64 new, u64 mask); 0141 0142 #endif /* _KERNEL_KCSAN_KCSAN_H */
[ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
This page was automatically generated by the 2.1.0 LXR engine. The LXR team |
![]() ![]() |