@@ -19,10 +19,10 @@ bool kcsan_enabled;
1919
2020/* Per-CPU kcsan_ctx for interrupts */
2121static DEFINE_PER_CPU (struct kcsan_ctx , kcsan_cpu_ctx ) = {
22- .disable_count = 0 ,
23- .atomic_next = 0 ,
24- .atomic_nest_count = 0 ,
25- .in_flat_atomic = false,
22+ .disable_count = 0 ,
23+ .atomic_next = 0 ,
24+ .atomic_nest_count = 0 ,
25+ .in_flat_atomic = false,
2626};
2727
2828/*
@@ -50,11 +50,11 @@ static DEFINE_PER_CPU(struct kcsan_ctx, kcsan_cpu_ctx) = {
5050 * slot=9: [10, 11, 9]
5151 * slot=63: [64, 65, 63]
5252 */
53- #define NUM_SLOTS (1 + 2 * KCSAN_CHECK_ADJACENT)
53+ #define NUM_SLOTS (1 + 2* KCSAN_CHECK_ADJACENT)
5454#define SLOT_IDX (slot , i ) (slot + ((i + KCSAN_CHECK_ADJACENT) % NUM_SLOTS))
5555
5656/*
57- * SLOT_IDX_FAST is used in fast-path. Not first checking the address's primary
57+ * SLOT_IDX_FAST is used in the fast-path. Not first checking the address's primary
5858 * slot (middle) is fine if we assume that data races occur rarely. The set of
5959 * indices {SLOT_IDX(slot, i) | i in [0, NUM_SLOTS)} is equivalent to
6060 * {SLOT_IDX_FAST(slot, i) | i in [0, NUM_SLOTS)}.
@@ -68,17 +68,18 @@ static DEFINE_PER_CPU(struct kcsan_ctx, kcsan_cpu_ctx) = {
6868 * zero-initialized state matches INVALID_WATCHPOINT.
6969 *
7070 * Add NUM_SLOTS-1 entries to account for overflow; this helps avoid having to
71- * use more complicated SLOT_IDX_FAST calculation with modulo in fast-path.
71+ * use more complicated SLOT_IDX_FAST calculation with modulo in the fast-path.
7272 */
73- static atomic_long_t watchpoints [CONFIG_KCSAN_NUM_WATCHPOINTS + NUM_SLOTS - 1 ];
73+ static atomic_long_t watchpoints [CONFIG_KCSAN_NUM_WATCHPOINTS + NUM_SLOTS - 1 ];
7474
7575/*
7676 * Instructions to skip watching counter, used in should_watch(). We use a
7777 * per-CPU counter to avoid excessive contention.
7878 */
7979static DEFINE_PER_CPU (long , kcsan_skip ) ;
8080
81- static inline atomic_long_t * find_watchpoint (unsigned long addr , size_t size ,
81+ static inline atomic_long_t * find_watchpoint (unsigned long addr ,
82+ size_t size ,
8283 bool expect_write ,
8384 long * encoded_watchpoint )
8485{
@@ -110,8 +111,8 @@ static inline atomic_long_t *find_watchpoint(unsigned long addr, size_t size,
110111 return NULL ;
111112}
112113
113- static inline atomic_long_t * insert_watchpoint ( unsigned long addr , size_t size ,
114- bool is_write )
114+ static inline atomic_long_t *
115+ insert_watchpoint ( unsigned long addr , size_t size , bool is_write )
115116{
116117 const int slot = watchpoint_slot (addr );
117118 const long encoded_watchpoint = encode_watchpoint (addr , size , is_write );
@@ -120,21 +121,16 @@ static inline atomic_long_t *insert_watchpoint(unsigned long addr, size_t size,
120121
121122 /* Check slot index logic, ensuring we stay within array bounds. */
122123 BUILD_BUG_ON (SLOT_IDX (0 , 0 ) != KCSAN_CHECK_ADJACENT );
123- BUILD_BUG_ON (SLOT_IDX (0 , KCSAN_CHECK_ADJACENT + 1 ) != 0 );
124- BUILD_BUG_ON (SLOT_IDX (CONFIG_KCSAN_NUM_WATCHPOINTS - 1 ,
125- KCSAN_CHECK_ADJACENT ) !=
126- ARRAY_SIZE (watchpoints ) - 1 );
127- BUILD_BUG_ON (SLOT_IDX (CONFIG_KCSAN_NUM_WATCHPOINTS - 1 ,
128- KCSAN_CHECK_ADJACENT + 1 ) !=
129- ARRAY_SIZE (watchpoints ) - NUM_SLOTS );
124+ BUILD_BUG_ON (SLOT_IDX (0 , KCSAN_CHECK_ADJACENT + 1 ) != 0 );
125+ BUILD_BUG_ON (SLOT_IDX (CONFIG_KCSAN_NUM_WATCHPOINTS - 1 , KCSAN_CHECK_ADJACENT ) != ARRAY_SIZE (watchpoints )- 1 );
126+ BUILD_BUG_ON (SLOT_IDX (CONFIG_KCSAN_NUM_WATCHPOINTS - 1 , KCSAN_CHECK_ADJACENT + 1 ) != ARRAY_SIZE (watchpoints ) - NUM_SLOTS );
130127
131128 for (i = 0 ; i < NUM_SLOTS ; ++ i ) {
132129 long expect_val = INVALID_WATCHPOINT ;
133130
134131 /* Try to acquire this slot. */
135132 watchpoint = & watchpoints [SLOT_IDX (slot , i )];
136- if (atomic_long_try_cmpxchg_relaxed (watchpoint , & expect_val ,
137- encoded_watchpoint ))
133+ if (atomic_long_try_cmpxchg_relaxed (watchpoint , & expect_val , encoded_watchpoint ))
138134 return watchpoint ;
139135 }
140136
@@ -150,26 +146,24 @@ static inline atomic_long_t *insert_watchpoint(unsigned long addr, size_t size,
150146 * 2. the thread that set up the watchpoint already removed it;
151147 * 3. the watchpoint was removed and then re-used.
152148 */
153- static inline bool try_consume_watchpoint ( atomic_long_t * watchpoint ,
154- long encoded_watchpoint )
149+ static inline bool
150+ try_consume_watchpoint ( atomic_long_t * watchpoint , long encoded_watchpoint )
155151{
156- return atomic_long_try_cmpxchg_relaxed (watchpoint , & encoded_watchpoint ,
157- CONSUMED_WATCHPOINT );
152+ return atomic_long_try_cmpxchg_relaxed (watchpoint , & encoded_watchpoint , CONSUMED_WATCHPOINT );
158153}
159154
160155/*
161156 * Return true if watchpoint was not touched, false if consumed.
162157 */
163158static inline bool remove_watchpoint (atomic_long_t * watchpoint )
164159{
165- return atomic_long_xchg_relaxed (watchpoint , INVALID_WATCHPOINT ) !=
166- CONSUMED_WATCHPOINT ;
160+ return atomic_long_xchg_relaxed (watchpoint , INVALID_WATCHPOINT ) != CONSUMED_WATCHPOINT ;
167161}
168162
169163static inline struct kcsan_ctx * get_ctx (void )
170164{
171165 /*
172- * In interrupt , use raw_cpu_ptr to avoid unnecessary checks, that would
166+ * In interrupts , use raw_cpu_ptr to avoid unnecessary checks, that would
173167 * also result in calls that generate warnings in uaccess regions.
174168 */
175169 return in_task () ? & current -> kcsan_ctx : raw_cpu_ptr (& kcsan_cpu_ctx );
@@ -260,7 +254,8 @@ static inline unsigned int get_delay(void)
260254 */
261255
262256static noinline void kcsan_found_watchpoint (const volatile void * ptr ,
263- size_t size , bool is_write ,
257+ size_t size ,
258+ bool is_write ,
264259 atomic_long_t * watchpoint ,
265260 long encoded_watchpoint )
266261{
@@ -296,8 +291,8 @@ static noinline void kcsan_found_watchpoint(const volatile void *ptr,
296291 user_access_restore (flags );
297292}
298293
299- static noinline void kcsan_setup_watchpoint ( const volatile void * ptr ,
300- size_t size , bool is_write )
294+ static noinline void
295+ kcsan_setup_watchpoint ( const volatile void * ptr , size_t size , bool is_write )
301296{
302297 atomic_long_t * watchpoint ;
303298 union {
@@ -346,8 +341,8 @@ static noinline void kcsan_setup_watchpoint(const volatile void *ptr,
346341 watchpoint = insert_watchpoint ((unsigned long )ptr , size , is_write );
347342 if (watchpoint == NULL ) {
348343 /*
349- * Out of capacity: the size of ` watchpoints` , and the frequency
350- * with which ` should_watch()` returns true should be tweaked so
344+ * Out of capacity: the size of ' watchpoints' , and the frequency
345+ * with which should_watch() returns true should be tweaked so
351346 * that this case happens very rarely.
352347 */
353348 kcsan_counter_inc (KCSAN_COUNTER_NO_CAPACITY );
0 commit comments