Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

compiler-context-analysis: Remove Sparse support

Remove Sparse support as discussed at [1].

The kernel codebase is still scattered with numerous places that try to
appease Sparse's context tracking ("annotation for sparse", "fake out
sparse", "work around sparse", etc.). Eventually, as more subsystems
enable Clang's context analysis, these places will show up and need
adjustment or removal of the workarounds altogether.

Signed-off-by: Marco Elver <elver@google.com>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Link: https://lore.kernel.org/all/20250207083335.GW7145@noisy.programming.kicks-ass.net/ [1]
Link: https://lore.kernel.org/all/Z6XTKTo_LMj9KmbY@elver.google.com/ [2]
Link: https://patch.msgid.link/20251219154418.3592607-24-elver@google.com

authored by

Marco Elver and committed by
Peter Zijlstra
5b63d0ae 4f109bae

+27 -90
-19
Documentation/dev-tools/sparse.rst
··· 53 53 vs cpu-endian vs whatever), and there the constant "0" really _is_ 54 54 special. 55 55 56 - Using sparse for lock checking 57 - ------------------------------ 58 - 59 - The following macros are undefined for gcc and defined during a sparse 60 - run to use the "context" tracking feature of sparse, applied to 61 - locking. These annotations tell sparse when a lock is held, with 62 - regard to the annotated function's entry and exit. 63 - 64 - __must_hold - The specified lock is held on function entry and exit. 65 - 66 - __acquires - The specified lock is held on function exit, but not entry. 67 - 68 - __releases - The specified lock is held on function entry, but not exit. 69 - 70 - If the function enters and exits without the lock held, acquiring and 71 - releasing the lock inside the function in a balanced way, no 72 - annotation is needed. The three annotations above are for cases where 73 - sparse would otherwise report a context imbalance. 74 - 75 56 Getting sparse 76 57 -------------- 77 58
+26 -57
include/linux/compiler-context-analysis.h
··· 262 262 extern const struct __ctx_lock_##ctx *name 263 263 264 264 /* 265 - * Common keywords for static context analysis. Both Clang's "capability 266 - * analysis" and Sparse's "context tracking" are currently supported. 265 + * Common keywords for static context analysis. 267 266 */ 268 - #ifdef __CHECKER__ 269 - 270 - /* Sparse context/lock checking support. */ 271 - # define __must_hold(x) __attribute__((context(x,1,1))) 272 - # define __must_not_hold(x) 273 - # define __acquires(x) __attribute__((context(x,0,1))) 274 - # define __cond_acquires(ret, x) __attribute__((context(x,0,-1))) 275 - # define __releases(x) __attribute__((context(x,1,0))) 276 - # define __acquire(x) __context__(x,1) 277 - # define __release(x) __context__(x,-1) 278 - # define __cond_lock(x, c) ((c) ? ({ __acquire(x); 1; }) : 0) 279 - /* For Sparse, there's no distinction between exclusive and shared locks. */ 280 - # define __must_hold_shared __must_hold 281 - # define __acquires_shared __acquires 282 - # define __cond_acquires_shared __cond_acquires 283 - # define __releases_shared __releases 284 - # define __acquire_shared __acquire 285 - # define __release_shared __release 286 - # define __cond_lock_shared __cond_acquire 287 - 288 - #else /* !__CHECKER__ */ 289 267 290 268 /** 291 269 * __must_hold() - function attribute, caller must hold exclusive context lock 292 - * @x: context lock instance pointer 293 270 * 294 271 * Function attribute declaring that the caller must hold the given context 295 - * lock instance @x exclusively. 272 + * lock instance(s) exclusively. 296 273 */ 297 - # define __must_hold(x) __requires_ctx_lock(x) 274 + #define __must_hold(...) __requires_ctx_lock(__VA_ARGS__) 298 275 299 276 /** 300 277 * __must_not_hold() - function attribute, caller must not hold context lock 301 - * @x: context lock instance pointer 302 278 * 303 279 * Function attribute declaring that the caller must not hold the given context 304 - * lock instance @x. 280 + * lock instance(s). 305 281 */ 306 - # define __must_not_hold(x) __excludes_ctx_lock(x) 282 + #define __must_not_hold(...) __excludes_ctx_lock(__VA_ARGS__) 307 283 308 284 /** 309 285 * __acquires() - function attribute, function acquires context lock exclusively 310 - * @x: context lock instance pointer 311 286 * 312 287 * Function attribute declaring that the function acquires the given context 313 - * lock instance @x exclusively, but does not release it. 288 + * lock instance(s) exclusively, but does not release them. 314 289 */ 315 - # define __acquires(x) __acquires_ctx_lock(x) 290 + #define __acquires(...) __acquires_ctx_lock(__VA_ARGS__) 316 291 317 292 /* 318 293 * Clang's analysis does not care precisely about the value, only that it is ··· 314 339 * 315 340 * @ret may be one of: true, false, nonzero, 0, nonnull, NULL. 316 341 */ 317 - # define __cond_acquires(ret, x) __cond_acquires_impl_##ret(x) 342 + #define __cond_acquires(ret, x) __cond_acquires_impl_##ret(x) 318 343 319 344 /** 320 345 * __releases() - function attribute, function releases a context lock exclusively 321 - * @x: context lock instance pointer 322 346 * 323 347 * Function attribute declaring that the function releases the given context 324 - * lock instance @x exclusively. The associated context must be active on 348 + * lock instance(s) exclusively. The associated context(s) must be active on 325 349 * entry. 326 350 */ 327 - # define __releases(x) __releases_ctx_lock(x) 351 + #define __releases(...) __releases_ctx_lock(__VA_ARGS__) 328 352 329 353 /** 330 354 * __acquire() - function to acquire context lock exclusively ··· 331 357 * 332 358 * No-op function that acquires the given context lock instance @x exclusively. 333 359 */ 334 - # define __acquire(x) __acquire_ctx_lock(x) 360 + #define __acquire(x) __acquire_ctx_lock(x) 335 361 336 362 /** 337 363 * __release() - function to release context lock exclusively ··· 339 365 * 340 366 * No-op function that releases the given context lock instance @x. 341 367 */ 342 - # define __release(x) __release_ctx_lock(x) 368 + #define __release(x) __release_ctx_lock(x) 343 369 344 370 /** 345 371 * __cond_lock() - function that conditionally acquires a context lock ··· 357 383 * 358 384 * #define spin_trylock(l) __cond_lock(&lock, _spin_trylock(&lock)) 359 385 */ 360 - # define __cond_lock(x, c) __try_acquire_ctx_lock(x, c) 386 + #define __cond_lock(x, c) __try_acquire_ctx_lock(x, c) 361 387 362 388 /** 363 389 * __must_hold_shared() - function attribute, caller must hold shared context lock 364 - * @x: context lock instance pointer 365 390 * 366 391 * Function attribute declaring that the caller must hold the given context 367 - * lock instance @x with shared access. 392 + * lock instance(s) with shared access. 368 393 */ 369 - # define __must_hold_shared(x) __requires_shared_ctx_lock(x) 394 + #define __must_hold_shared(...) __requires_shared_ctx_lock(__VA_ARGS__) 370 395 371 396 /** 372 397 * __acquires_shared() - function attribute, function acquires context lock shared 373 - * @x: context lock instance pointer 374 398 * 375 399 * Function attribute declaring that the function acquires the given 376 - * context lock instance @x with shared access, but does not release it. 400 + * context lock instance(s) with shared access, but does not release them. 377 401 */ 378 - # define __acquires_shared(x) __acquires_shared_ctx_lock(x) 402 + #define __acquires_shared(...) __acquires_shared_ctx_lock(__VA_ARGS__) 379 403 380 404 /** 381 405 * __cond_acquires_shared() - function attribute, function conditionally ··· 382 410 * @x: context lock instance pointer 383 411 * 384 412 * Function attribute declaring that the function conditionally acquires the 385 - * given context lock instance @x with shared access, but does not release it. The 386 - * function return value @ret denotes when the context lock is acquired. 413 + * given context lock instance @x with shared access, but does not release it. 414 + * The function return value @ret denotes when the context lock is acquired. 387 415 * 388 416 * @ret may be one of: true, false, nonzero, 0, nonnull, NULL. 389 417 */ 390 - # define __cond_acquires_shared(ret, x) __cond_acquires_impl_##ret(x, _shared) 418 + #define __cond_acquires_shared(ret, x) __cond_acquires_impl_##ret(x, _shared) 391 419 392 420 /** 393 421 * __releases_shared() - function attribute, function releases a 394 422 * context lock shared 395 - * @x: context lock instance pointer 396 423 * 397 424 * Function attribute declaring that the function releases the given context 398 - * lock instance @x with shared access. The associated context must be active 399 - * on entry. 425 + * lock instance(s) with shared access. The associated context(s) must be 426 + * active on entry. 400 427 */ 401 - # define __releases_shared(x) __releases_shared_ctx_lock(x) 428 + #define __releases_shared(...) __releases_shared_ctx_lock(__VA_ARGS__) 402 429 403 430 /** 404 431 * __acquire_shared() - function to acquire context lock shared ··· 406 435 * No-op function that acquires the given context lock instance @x with shared 407 436 * access. 408 437 */ 409 - # define __acquire_shared(x) __acquire_shared_ctx_lock(x) 438 + #define __acquire_shared(x) __acquire_shared_ctx_lock(x) 410 439 411 440 /** 412 441 * __release_shared() - function to release context lock shared ··· 415 444 * No-op function that releases the given context lock instance @x with shared 416 445 * access. 417 446 */ 418 - # define __release_shared(x) __release_shared_ctx_lock(x) 447 + #define __release_shared(x) __release_shared_ctx_lock(x) 419 448 420 449 /** 421 450 * __cond_lock_shared() - function that conditionally acquires a context lock shared ··· 428 457 * shared access, if the boolean expression @c is true. The result of @c is the 429 458 * return value. 430 459 */ 431 - # define __cond_lock_shared(x, c) __try_acquire_shared_ctx_lock(x, c) 432 - 433 - #endif /* __CHECKER__ */ 460 + #define __cond_lock_shared(x, c) __try_acquire_shared_ctx_lock(x, c) 434 461 435 462 /** 436 463 * __acquire_ret() - helper to acquire context lock of return value
+1 -14
include/linux/rcupdate.h
··· 1219 1219 extern int rcu_expedited; 1220 1220 extern int rcu_normal; 1221 1221 1222 - DEFINE_LOCK_GUARD_0(rcu, 1223 - do { 1224 - rcu_read_lock(); 1225 - /* 1226 - * sparse doesn't call the cleanup function, 1227 - * so just release immediately and don't track 1228 - * the context. We don't need to anyway, since 1229 - * the whole point of the guard is to not need 1230 - * the explicit unlock. 1231 - */ 1232 - __release(RCU); 1233 - } while (0), 1234 - rcu_read_unlock()) 1235 - 1222 + DEFINE_LOCK_GUARD_0(rcu, rcu_read_lock(), rcu_read_unlock()) 1236 1223 DECLARE_LOCK_GUARD_0_ATTRS(rcu, __acquires_shared(RCU), __releases_shared(RCU)) 1237 1224 1238 1225 #endif /* __LINUX_RCUPDATE_H */