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 __cond_lock() function-like helper

As discussed in [1], removing __cond_lock() will improve the readability
of trylock code. Now that Sparse context tracking support has been
removed, we can also remove __cond_lock().

Change existing APIs to either drop __cond_lock() completely, or make
use of the __cond_acquires() function attribute instead.

In particular, spinlock and rwlock implementations required switching
over to inline helpers rather than statement-expressions for their
trylock_* variants.

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

authored by

Marco Elver and committed by
Peter Zijlstra
e4588c25 5b63d0ae

+163 -195
-2
Documentation/dev-tools/context-analysis.rst
··· 112 112 __releases_shared 113 113 __acquire 114 114 __release 115 - __cond_lock 116 115 __acquire_shared 117 116 __release_shared 118 - __cond_lock_shared 119 117 __acquire_ret 120 118 __acquire_shared_ret 121 119 context_unsafe
+3 -3
Documentation/mm/process_addrs.rst
··· 583 583 :c:func:`!pte_offset_map` can be used depending on stability requirements. 584 584 These map the page table into kernel memory if required, take the RCU lock, and 585 585 depending on variant, may also look up or acquire the PTE lock. 586 - See the comment on :c:func:`!__pte_offset_map_lock`. 586 + See the comment on :c:func:`!pte_offset_map_lock`. 587 587 588 588 Atomicity 589 589 ^^^^^^^^^ ··· 667 667 .. note:: There are some variants on this, such as 668 668 :c:func:`!pte_offset_map_rw_nolock` when we know we hold the PTE stable but 669 669 for brevity we do not explore this. See the comment for 670 - :c:func:`!__pte_offset_map_lock` for more details. 670 + :c:func:`!pte_offset_map_lock` for more details. 671 671 672 672 When modifying data in ranges we typically only wish to allocate higher page 673 673 tables as necessary, using these locks to avoid races or overwriting anything, ··· 686 686 as we have separate PMD and PTE locks and a THP collapse for instance might have 687 687 eliminated the PMD entry as well as the PTE from under us. 688 688 689 - This is why :c:func:`!__pte_offset_map_lock` locklessly retrieves the PMD entry 689 + This is why :c:func:`!pte_offset_map_lock` locklessly retrieves the PMD entry 690 690 for the PTE, carefully checking it is as expected, before acquiring the 691 691 PTE-specific lock, and then *again* checking that the PMD entry is as expected. 692 692
+2 -2
drivers/net/wireless/intel/iwlwifi/iwl-trans.c
··· 548 548 return iwl_trans_pcie_read_config32(trans, ofs, val); 549 549 } 550 550 551 - bool _iwl_trans_grab_nic_access(struct iwl_trans *trans) 551 + bool iwl_trans_grab_nic_access(struct iwl_trans *trans) 552 552 { 553 553 return iwl_trans_pcie_grab_nic_access(trans); 554 554 } 555 - IWL_EXPORT_SYMBOL(_iwl_trans_grab_nic_access); 555 + IWL_EXPORT_SYMBOL(iwl_trans_grab_nic_access); 556 556 557 557 void __releases(nic_access) 558 558 iwl_trans_release_nic_access(struct iwl_trans *trans)
+1 -5
drivers/net/wireless/intel/iwlwifi/iwl-trans.h
··· 1063 1063 void iwl_trans_set_bits_mask(struct iwl_trans *trans, u32 reg, 1064 1064 u32 mask, u32 value); 1065 1065 1066 - bool _iwl_trans_grab_nic_access(struct iwl_trans *trans); 1067 - 1068 - #define iwl_trans_grab_nic_access(trans) \ 1069 - __cond_lock(nic_access, \ 1070 - likely(_iwl_trans_grab_nic_access(trans))) 1066 + bool iwl_trans_grab_nic_access(struct iwl_trans *trans); 1071 1067 1072 1068 void __releases(nic_access) 1073 1069 iwl_trans_release_nic_access(struct iwl_trans *trans);
+1 -4
drivers/net/wireless/intel/iwlwifi/pcie/gen1_2/internal.h
··· 553 553 void iwl_trans_pcie_free_pnvm_dram_regions(struct iwl_dram_regions *dram_regions, 554 554 struct device *dev); 555 555 556 - bool __iwl_trans_pcie_grab_nic_access(struct iwl_trans *trans, bool silent); 557 - #define _iwl_trans_pcie_grab_nic_access(trans, silent) \ 558 - __cond_lock(nic_access_nobh, \ 559 - likely(__iwl_trans_pcie_grab_nic_access(trans, silent))) 556 + bool _iwl_trans_pcie_grab_nic_access(struct iwl_trans *trans, bool silent); 560 557 561 558 void iwl_trans_pcie_check_product_reset_status(struct pci_dev *pdev); 562 559 void iwl_trans_pcie_check_product_reset_mode(struct pci_dev *pdev);
+2 -2
drivers/net/wireless/intel/iwlwifi/pcie/gen1_2/trans.c
··· 2327 2327 * This version doesn't disable BHs but rather assumes they're 2328 2328 * already disabled. 2329 2329 */ 2330 - bool __iwl_trans_pcie_grab_nic_access(struct iwl_trans *trans, bool silent) 2330 + bool _iwl_trans_pcie_grab_nic_access(struct iwl_trans *trans, bool silent) 2331 2331 { 2332 2332 int ret; 2333 2333 struct iwl_trans_pcie *trans_pcie = IWL_TRANS_GET_PCIE_TRANS(trans); ··· 2415 2415 bool ret; 2416 2416 2417 2417 local_bh_disable(); 2418 - ret = __iwl_trans_pcie_grab_nic_access(trans, false); 2418 + ret = _iwl_trans_pcie_grab_nic_access(trans, false); 2419 2419 if (ret) { 2420 2420 /* keep BHs disabled until iwl_trans_pcie_release_nic_access */ 2421 2421 return ret;
-31
include/linux/compiler-context-analysis.h
··· 342 342 #define __release(x) __release_ctx_lock(x) 343 343 344 344 /** 345 - * __cond_lock() - function that conditionally acquires a context lock 346 - * exclusively 347 - * @x: context lock instance pinter 348 - * @c: boolean expression 349 - * 350 - * Return: result of @c 351 - * 352 - * No-op function that conditionally acquires context lock instance @x 353 - * exclusively, if the boolean expression @c is true. The result of @c is the 354 - * return value; for example: 355 - * 356 - * .. code-block:: c 357 - * 358 - * #define spin_trylock(l) __cond_lock(&lock, _spin_trylock(&lock)) 359 - */ 360 - #define __cond_lock(x, c) __try_acquire_ctx_lock(x, c) 361 - 362 - /** 363 345 * __must_hold_shared() - function attribute, caller must hold shared context lock 364 346 * 365 347 * Function attribute declaring that the caller must hold the given context ··· 398 416 * access. 399 417 */ 400 418 #define __release_shared(x) __release_shared_ctx_lock(x) 401 - 402 - /** 403 - * __cond_lock_shared() - function that conditionally acquires a context lock shared 404 - * @x: context lock instance pinter 405 - * @c: boolean expression 406 - * 407 - * Return: result of @c 408 - * 409 - * No-op function that conditionally acquires context lock instance @x with 410 - * shared access, if the boolean expression @c is true. The result of @c is the 411 - * return value. 412 - */ 413 - #define __cond_lock_shared(x, c) __try_acquire_shared_ctx_lock(x, c) 414 419 415 420 /** 416 421 * __acquire_ret() - helper to acquire context lock of return value
+1 -3
include/linux/lockref.h
··· 49 49 void lockref_get(struct lockref *lockref); 50 50 int lockref_put_return(struct lockref *lockref); 51 51 bool lockref_get_not_zero(struct lockref *lockref); 52 - bool lockref_put_or_lock(struct lockref *lockref); 53 - #define lockref_put_or_lock(_lockref) \ 54 - (!__cond_lock((_lockref)->lock, !lockref_put_or_lock(_lockref))) 52 + bool lockref_put_or_lock(struct lockref *lockref) __cond_acquires(false, &lockref->lock); 55 53 56 54 void lockref_mark_dead(struct lockref *lockref); 57 55 bool lockref_get_not_dead(struct lockref *lockref);
+5 -28
include/linux/mm.h
··· 2975 2975 } 2976 2976 #endif /* CONFIG_ARCH_SUPPORTS_PUD_PFNMAP */ 2977 2977 2978 - extern pte_t *__get_locked_pte(struct mm_struct *mm, unsigned long addr, 2979 - spinlock_t **ptl); 2980 - static inline pte_t *get_locked_pte(struct mm_struct *mm, unsigned long addr, 2981 - spinlock_t **ptl) 2982 - { 2983 - pte_t *ptep; 2984 - __cond_lock(*ptl, ptep = __get_locked_pte(mm, addr, ptl)); 2985 - return ptep; 2986 - } 2978 + extern pte_t *get_locked_pte(struct mm_struct *mm, unsigned long addr, 2979 + spinlock_t **ptl); 2987 2980 2988 2981 #ifdef __PAGETABLE_P4D_FOLDED 2989 2982 static inline int __p4d_alloc(struct mm_struct *mm, pgd_t *pgd, ··· 3330 3337 return true; 3331 3338 } 3332 3339 3333 - pte_t *___pte_offset_map(pmd_t *pmd, unsigned long addr, pmd_t *pmdvalp); 3334 - static inline pte_t *__pte_offset_map(pmd_t *pmd, unsigned long addr, 3335 - pmd_t *pmdvalp) 3336 - { 3337 - pte_t *pte; 3340 + pte_t *__pte_offset_map(pmd_t *pmd, unsigned long addr, pmd_t *pmdvalp); 3338 3341 3339 - __cond_lock(RCU, pte = ___pte_offset_map(pmd, addr, pmdvalp)); 3340 - return pte; 3341 - } 3342 3342 static inline pte_t *pte_offset_map(pmd_t *pmd, unsigned long addr) 3343 3343 { 3344 3344 return __pte_offset_map(pmd, addr, NULL); 3345 3345 } 3346 3346 3347 - pte_t *__pte_offset_map_lock(struct mm_struct *mm, pmd_t *pmd, 3348 - unsigned long addr, spinlock_t **ptlp); 3349 - static inline pte_t *pte_offset_map_lock(struct mm_struct *mm, pmd_t *pmd, 3350 - unsigned long addr, spinlock_t **ptlp) 3351 - { 3352 - pte_t *pte; 3353 - 3354 - __cond_lock(RCU, __cond_lock(*ptlp, 3355 - pte = __pte_offset_map_lock(mm, pmd, addr, ptlp))); 3356 - return pte; 3357 - } 3347 + pte_t *pte_offset_map_lock(struct mm_struct *mm, pmd_t *pmd, 3348 + unsigned long addr, spinlock_t **ptlp); 3358 3349 3359 3350 pte_t *pte_offset_map_ro_nolock(struct mm_struct *mm, pmd_t *pmd, 3360 3351 unsigned long addr, spinlock_t **ptlp);
+3 -8
include/linux/rwlock.h
··· 50 50 * regardless of whether CONFIG_SMP or CONFIG_PREEMPT are set. The various 51 51 * methods are defined as nops in the case they are not required. 52 52 */ 53 - #define read_trylock(lock) __cond_lock_shared(lock, _raw_read_trylock(lock)) 54 - #define write_trylock(lock) __cond_lock(lock, _raw_write_trylock(lock)) 53 + #define read_trylock(lock) _raw_read_trylock(lock) 54 + #define write_trylock(lock) _raw_write_trylock(lock) 55 55 56 56 #define write_lock(lock) _raw_write_lock(lock) 57 57 #define read_lock(lock) _raw_read_lock(lock) ··· 113 113 } while (0) 114 114 #define write_unlock_bh(lock) _raw_write_unlock_bh(lock) 115 115 116 - #define write_trylock_irqsave(lock, flags) \ 117 - __cond_lock(lock, ({ \ 118 - local_irq_save(flags); \ 119 - _raw_write_trylock(lock) ? \ 120 - 1 : ({ local_irq_restore(flags); 0; }); \ 121 - })) 116 + #define write_trylock_irqsave(lock, flags) _raw_write_trylock_irqsave(lock, &(flags)) 122 117 123 118 #ifdef arch_rwlock_is_contended 124 119 #define rwlock_is_contended(lock) \
+12 -2
include/linux/rwlock_api_smp.h
··· 26 26 __acquires(lock); 27 27 unsigned long __lockfunc _raw_write_lock_irqsave(rwlock_t *lock) 28 28 __acquires(lock); 29 - int __lockfunc _raw_read_trylock(rwlock_t *lock); 30 - int __lockfunc _raw_write_trylock(rwlock_t *lock); 29 + int __lockfunc _raw_read_trylock(rwlock_t *lock) __cond_acquires_shared(true, lock); 30 + int __lockfunc _raw_write_trylock(rwlock_t *lock) __cond_acquires(true, lock); 31 31 void __lockfunc _raw_read_unlock(rwlock_t *lock) __releases_shared(lock); 32 32 void __lockfunc _raw_write_unlock(rwlock_t *lock) __releases(lock); 33 33 void __lockfunc _raw_read_unlock_bh(rwlock_t *lock) __releases_shared(lock); ··· 40 40 void __lockfunc 41 41 _raw_write_unlock_irqrestore(rwlock_t *lock, unsigned long flags) 42 42 __releases(lock); 43 + 44 + static inline bool _raw_write_trylock_irqsave(rwlock_t *lock, unsigned long *flags) 45 + __cond_acquires(true, lock) 46 + { 47 + local_irq_save(*flags); 48 + if (_raw_write_trylock(lock)) 49 + return true; 50 + local_irq_restore(*flags); 51 + return false; 52 + } 43 53 44 54 #ifdef CONFIG_INLINE_READ_LOCK 45 55 #define _raw_read_lock(lock) __raw_read_lock(lock)
+11 -10
include/linux/rwlock_rt.h
··· 26 26 } while (0) 27 27 28 28 extern void rt_read_lock(rwlock_t *rwlock) __acquires_shared(rwlock); 29 - extern int rt_read_trylock(rwlock_t *rwlock); 29 + extern int rt_read_trylock(rwlock_t *rwlock) __cond_acquires_shared(true, rwlock); 30 30 extern void rt_read_unlock(rwlock_t *rwlock) __releases_shared(rwlock); 31 31 extern void rt_write_lock(rwlock_t *rwlock) __acquires(rwlock); 32 32 extern void rt_write_lock_nested(rwlock_t *rwlock, int subclass) __acquires(rwlock); 33 - extern int rt_write_trylock(rwlock_t *rwlock); 33 + extern int rt_write_trylock(rwlock_t *rwlock) __cond_acquires(true, rwlock); 34 34 extern void rt_write_unlock(rwlock_t *rwlock) __releases(rwlock); 35 35 36 36 static __always_inline void read_lock(rwlock_t *rwlock) ··· 59 59 flags = 0; \ 60 60 } while (0) 61 61 62 - #define read_trylock(lock) __cond_lock_shared(lock, rt_read_trylock(lock)) 62 + #define read_trylock(lock) rt_read_trylock(lock) 63 63 64 64 static __always_inline void read_unlock(rwlock_t *rwlock) 65 65 __releases_shared(rwlock) ··· 123 123 flags = 0; \ 124 124 } while (0) 125 125 126 - #define write_trylock(lock) __cond_lock(lock, rt_write_trylock(lock)) 126 + #define write_trylock(lock) rt_write_trylock(lock) 127 127 128 - #define write_trylock_irqsave(lock, flags) \ 129 - __cond_lock(lock, ({ \ 130 - typecheck(unsigned long, flags); \ 131 - flags = 0; \ 132 - rt_write_trylock(lock); \ 133 - })) 128 + static __always_inline bool _write_trylock_irqsave(rwlock_t *rwlock, unsigned long *flags) 129 + __cond_acquires(true, rwlock) 130 + { 131 + *flags = 0; 132 + return rt_write_trylock(rwlock); 133 + } 134 + #define write_trylock_irqsave(lock, flags) _write_trylock_irqsave(lock, &(flags)) 134 135 135 136 static __always_inline void write_unlock(rwlock_t *rwlock) 136 137 __releases(rwlock)
+2 -12
include/linux/sched/signal.h
··· 737 737 #define delay_group_leader(p) \ 738 738 (thread_group_leader(p) && !thread_group_empty(p)) 739 739 740 - extern struct sighand_struct *__lock_task_sighand(struct task_struct *task, 741 - unsigned long *flags); 742 - 743 - static inline struct sighand_struct *lock_task_sighand(struct task_struct *task, 744 - unsigned long *flags) 745 - { 746 - struct sighand_struct *ret; 747 - 748 - ret = __lock_task_sighand(task, flags); 749 - (void)__cond_lock(&task->sighand->siglock, ret); 750 - return ret; 751 - } 740 + extern struct sighand_struct *lock_task_sighand(struct task_struct *task, 741 + unsigned long *flags); 752 742 753 743 static inline void unlock_task_sighand(struct task_struct *task, 754 744 unsigned long *flags)
+16 -29
include/linux/spinlock.h
··· 213 213 * various methods are defined as nops in the case they are not 214 214 * required. 215 215 */ 216 - #define raw_spin_trylock(lock) __cond_lock(lock, _raw_spin_trylock(lock)) 216 + #define raw_spin_trylock(lock) _raw_spin_trylock(lock) 217 217 218 218 #define raw_spin_lock(lock) _raw_spin_lock(lock) 219 219 ··· 284 284 } while (0) 285 285 #define raw_spin_unlock_bh(lock) _raw_spin_unlock_bh(lock) 286 286 287 - #define raw_spin_trylock_bh(lock) \ 288 - __cond_lock(lock, _raw_spin_trylock_bh(lock)) 287 + #define raw_spin_trylock_bh(lock) _raw_spin_trylock_bh(lock) 289 288 290 - #define raw_spin_trylock_irq(lock) \ 291 - __cond_lock(lock, ({ \ 292 - local_irq_disable(); \ 293 - _raw_spin_trylock(lock) ? \ 294 - 1 : ({ local_irq_enable(); 0; }); \ 295 - })) 289 + #define raw_spin_trylock_irq(lock) _raw_spin_trylock_irq(lock) 296 290 297 - #define raw_spin_trylock_irqsave(lock, flags) \ 298 - __cond_lock(lock, ({ \ 299 - local_irq_save(flags); \ 300 - _raw_spin_trylock(lock) ? \ 301 - 1 : ({ local_irq_restore(flags); 0; }); \ 302 - })) 291 + #define raw_spin_trylock_irqsave(lock, flags) _raw_spin_trylock_irqsave(lock, &(flags)) 303 292 304 293 #ifndef CONFIG_PREEMPT_RT 305 294 /* Include rwlock functions for !RT */ ··· 422 433 return raw_spin_trylock_irq(&lock->rlock); 423 434 } 424 435 425 - #define spin_trylock_irqsave(lock, flags) \ 426 - __cond_lock(lock, raw_spin_trylock_irqsave(spinlock_check(lock), flags)) 436 + static __always_inline bool _spin_trylock_irqsave(spinlock_t *lock, unsigned long *flags) 437 + __cond_acquires(true, lock) __no_context_analysis 438 + { 439 + return raw_spin_trylock_irqsave(spinlock_check(lock), *flags); 440 + } 441 + #define spin_trylock_irqsave(lock, flags) _spin_trylock_irqsave(lock, &(flags)) 427 442 428 443 /** 429 444 * spin_is_locked() - Check whether a spinlock is locked. ··· 505 512 * Decrements @atomic by 1. If the result is 0, returns true and locks 506 513 * @lock. Returns false for all other cases. 507 514 */ 508 - extern int _atomic_dec_and_lock(atomic_t *atomic, spinlock_t *lock); 509 - #define atomic_dec_and_lock(atomic, lock) \ 510 - __cond_lock(lock, _atomic_dec_and_lock(atomic, lock)) 515 + extern int atomic_dec_and_lock(atomic_t *atomic, spinlock_t *lock) __cond_acquires(true, lock); 511 516 512 517 extern int _atomic_dec_and_lock_irqsave(atomic_t *atomic, spinlock_t *lock, 513 - unsigned long *flags); 514 - #define atomic_dec_and_lock_irqsave(atomic, lock, flags) \ 515 - __cond_lock(lock, _atomic_dec_and_lock_irqsave(atomic, lock, &(flags))) 518 + unsigned long *flags) __cond_acquires(true, lock); 519 + #define atomic_dec_and_lock_irqsave(atomic, lock, flags) _atomic_dec_and_lock_irqsave(atomic, lock, &(flags)) 516 520 517 - extern int _atomic_dec_and_raw_lock(atomic_t *atomic, raw_spinlock_t *lock); 518 - #define atomic_dec_and_raw_lock(atomic, lock) \ 519 - __cond_lock(lock, _atomic_dec_and_raw_lock(atomic, lock)) 521 + extern int atomic_dec_and_raw_lock(atomic_t *atomic, raw_spinlock_t *lock) __cond_acquires(true, lock); 520 522 521 523 extern int _atomic_dec_and_raw_lock_irqsave(atomic_t *atomic, raw_spinlock_t *lock, 522 - unsigned long *flags); 523 - #define atomic_dec_and_raw_lock_irqsave(atomic, lock, flags) \ 524 - __cond_lock(lock, _atomic_dec_and_raw_lock_irqsave(atomic, lock, &(flags))) 524 + unsigned long *flags) __cond_acquires(true, lock); 525 + #define atomic_dec_and_raw_lock_irqsave(atomic, lock, flags) _atomic_dec_and_raw_lock_irqsave(atomic, lock, &(flags)) 525 526 526 527 int __alloc_bucket_spinlocks(spinlock_t **locks, unsigned int *lock_mask, 527 528 size_t max_size, unsigned int cpu_mult,
+20
include/linux/spinlock_api_smp.h
··· 95 95 return 0; 96 96 } 97 97 98 + static __always_inline bool _raw_spin_trylock_irq(raw_spinlock_t *lock) 99 + __cond_acquires(true, lock) 100 + { 101 + local_irq_disable(); 102 + if (_raw_spin_trylock(lock)) 103 + return true; 104 + local_irq_enable(); 105 + return false; 106 + } 107 + 108 + static __always_inline bool _raw_spin_trylock_irqsave(raw_spinlock_t *lock, unsigned long *flags) 109 + __cond_acquires(true, lock) 110 + { 111 + local_irq_save(*flags); 112 + if (_raw_spin_trylock(lock)) 113 + return true; 114 + local_irq_restore(*flags); 115 + return false; 116 + } 117 + 98 118 /* 99 119 * If lockdep is enabled then we use the non-preemption spin-ops 100 120 * even on CONFIG_PREEMPTION, because lockdep assumes that interrupts are
+52 -9
include/linux/spinlock_api_up.h
··· 24 24 * flags straight, to suppress compiler warnings of unused lock 25 25 * variables, and to add the proper checker annotations: 26 26 */ 27 - #define ___LOCK_void(lock) \ 28 - do { (void)(lock); } while (0) 29 - 30 27 #define ___LOCK_(lock) \ 31 - do { __acquire(lock); ___LOCK_void(lock); } while (0) 28 + do { __acquire(lock); (void)(lock); } while (0) 32 29 33 30 #define ___LOCK_shared(lock) \ 34 - do { __acquire_shared(lock); ___LOCK_void(lock); } while (0) 31 + do { __acquire_shared(lock); (void)(lock); } while (0) 35 32 36 33 #define __LOCK(lock, ...) \ 37 34 do { preempt_disable(); ___LOCK_##__VA_ARGS__(lock); } while (0) ··· 75 78 #define _raw_spin_lock_irqsave(lock, flags) __LOCK_IRQSAVE(lock, flags) 76 79 #define _raw_read_lock_irqsave(lock, flags) __LOCK_IRQSAVE(lock, flags, shared) 77 80 #define _raw_write_lock_irqsave(lock, flags) __LOCK_IRQSAVE(lock, flags) 78 - #define _raw_spin_trylock(lock) ({ __LOCK(lock, void); 1; }) 79 - #define _raw_read_trylock(lock) ({ __LOCK(lock, void); 1; }) 80 - #define _raw_write_trylock(lock) ({ __LOCK(lock, void); 1; }) 81 - #define _raw_spin_trylock_bh(lock) ({ __LOCK_BH(lock, void); 1; }) 81 + 82 + static __always_inline int _raw_spin_trylock(raw_spinlock_t *lock) 83 + __cond_acquires(true, lock) 84 + { 85 + __LOCK(lock); 86 + return 1; 87 + } 88 + 89 + static __always_inline int _raw_spin_trylock_bh(raw_spinlock_t *lock) 90 + __cond_acquires(true, lock) 91 + { 92 + __LOCK_BH(lock); 93 + return 1; 94 + } 95 + 96 + static __always_inline int _raw_spin_trylock_irq(raw_spinlock_t *lock) 97 + __cond_acquires(true, lock) 98 + { 99 + __LOCK_IRQ(lock); 100 + return 1; 101 + } 102 + 103 + static __always_inline int _raw_spin_trylock_irqsave(raw_spinlock_t *lock, unsigned long *flags) 104 + __cond_acquires(true, lock) 105 + { 106 + __LOCK_IRQSAVE(lock, *(flags)); 107 + return 1; 108 + } 109 + 110 + static __always_inline int _raw_read_trylock(rwlock_t *lock) 111 + __cond_acquires_shared(true, lock) 112 + { 113 + __LOCK(lock, shared); 114 + return 1; 115 + } 116 + 117 + static __always_inline int _raw_write_trylock(rwlock_t *lock) 118 + __cond_acquires(true, lock) 119 + { 120 + __LOCK(lock); 121 + return 1; 122 + } 123 + 124 + static __always_inline int _raw_write_trylock_irqsave(rwlock_t *lock, unsigned long *flags) 125 + __cond_acquires(true, lock) 126 + { 127 + __LOCK_IRQSAVE(lock, *(flags)); 128 + return 1; 129 + } 130 + 82 131 #define _raw_spin_unlock(lock) __UNLOCK(lock) 83 132 #define _raw_read_unlock(lock) __UNLOCK(lock, shared) 84 133 #define _raw_write_unlock(lock) __UNLOCK(lock)
+12 -14
include/linux/spinlock_rt.h
··· 37 37 extern void rt_spin_lock_nest_lock(spinlock_t *lock, struct lockdep_map *nest_lock) __acquires(lock); 38 38 extern void rt_spin_unlock(spinlock_t *lock) __releases(lock); 39 39 extern void rt_spin_lock_unlock(spinlock_t *lock); 40 - extern int rt_spin_trylock_bh(spinlock_t *lock); 41 - extern int rt_spin_trylock(spinlock_t *lock); 40 + extern int rt_spin_trylock_bh(spinlock_t *lock) __cond_acquires(true, lock); 41 + extern int rt_spin_trylock(spinlock_t *lock) __cond_acquires(true, lock); 42 42 43 43 static __always_inline void spin_lock(spinlock_t *lock) 44 44 __acquires(lock) ··· 130 130 rt_spin_unlock(lock); 131 131 } 132 132 133 - #define spin_trylock(lock) \ 134 - __cond_lock(lock, rt_spin_trylock(lock)) 133 + #define spin_trylock(lock) rt_spin_trylock(lock) 135 134 136 - #define spin_trylock_bh(lock) \ 137 - __cond_lock(lock, rt_spin_trylock_bh(lock)) 135 + #define spin_trylock_bh(lock) rt_spin_trylock_bh(lock) 138 136 139 - #define spin_trylock_irq(lock) \ 140 - __cond_lock(lock, rt_spin_trylock(lock)) 137 + #define spin_trylock_irq(lock) rt_spin_trylock(lock) 141 138 142 - #define spin_trylock_irqsave(lock, flags) \ 143 - __cond_lock(lock, ({ \ 144 - typecheck(unsigned long, flags); \ 145 - flags = 0; \ 146 - rt_spin_trylock(lock); \ 147 - })) 139 + static __always_inline bool _spin_trylock_irqsave(spinlock_t *lock, unsigned long *flags) 140 + __cond_acquires(true, lock) 141 + { 142 + *flags = 0; 143 + return rt_spin_trylock(lock); 144 + } 145 + #define spin_trylock_irqsave(lock, flags) _spin_trylock_irqsave(lock, &(flags)) 148 146 149 147 #define spin_is_contended(lock) (((void)(lock), 0)) 150 148
+2 -2
kernel/signal.c
··· 1355 1355 return count; 1356 1356 } 1357 1357 1358 - struct sighand_struct *__lock_task_sighand(struct task_struct *tsk, 1359 - unsigned long *flags) 1358 + struct sighand_struct *lock_task_sighand(struct task_struct *tsk, 1359 + unsigned long *flags) 1360 1360 { 1361 1361 struct sighand_struct *sighand; 1362 1362
+3 -10
kernel/time/posix-timers.c
··· 66 66 #error "SIGEV_THREAD_ID must not share bit with other SIGEV values!" 67 67 #endif 68 68 69 - static struct k_itimer *__lock_timer(timer_t timer_id); 70 - 71 - #define lock_timer(tid) \ 72 - ({ struct k_itimer *__timr; \ 73 - __cond_lock(&__timr->it_lock, __timr = __lock_timer(tid)); \ 74 - __timr; \ 75 - }) 76 - 69 + static struct k_itimer *lock_timer(timer_t timer_id); 77 70 static inline void unlock_timer(struct k_itimer *timr) 78 71 { 79 72 if (likely((timr))) ··· 78 85 79 86 #define scoped_timer (scope) 80 87 81 - DEFINE_CLASS(lock_timer, struct k_itimer *, unlock_timer(_T), __lock_timer(id), timer_t id); 88 + DEFINE_CLASS(lock_timer, struct k_itimer *, unlock_timer(_T), lock_timer(id), timer_t id); 82 89 DEFINE_CLASS_IS_COND_GUARD(lock_timer); 83 90 84 91 static struct timer_hash_bucket *hash_bucket(struct signal_struct *sig, unsigned int nr) ··· 593 600 } 594 601 #endif 595 602 596 - static struct k_itimer *__lock_timer(timer_t timer_id) 603 + static struct k_itimer *lock_timer(timer_t timer_id) 597 604 { 598 605 struct k_itimer *timr; 599 606
+4 -4
lib/dec_and_lock.c
··· 18 18 * because the spin-lock and the decrement must be 19 19 * "atomic". 20 20 */ 21 - int _atomic_dec_and_lock(atomic_t *atomic, spinlock_t *lock) 21 + int atomic_dec_and_lock(atomic_t *atomic, spinlock_t *lock) 22 22 { 23 23 /* Subtract 1 from counter unless that drops it to 0 (ie. it was 1) */ 24 24 if (atomic_add_unless(atomic, -1, 1)) ··· 32 32 return 0; 33 33 } 34 34 35 - EXPORT_SYMBOL(_atomic_dec_and_lock); 35 + EXPORT_SYMBOL(atomic_dec_and_lock); 36 36 37 37 int _atomic_dec_and_lock_irqsave(atomic_t *atomic, spinlock_t *lock, 38 38 unsigned long *flags) ··· 50 50 } 51 51 EXPORT_SYMBOL(_atomic_dec_and_lock_irqsave); 52 52 53 - int _atomic_dec_and_raw_lock(atomic_t *atomic, raw_spinlock_t *lock) 53 + int atomic_dec_and_raw_lock(atomic_t *atomic, raw_spinlock_t *lock) 54 54 { 55 55 /* Subtract 1 from counter unless that drops it to 0 (ie. it was 1) */ 56 56 if (atomic_add_unless(atomic, -1, 1)) ··· 63 63 raw_spin_unlock(lock); 64 64 return 0; 65 65 } 66 - EXPORT_SYMBOL(_atomic_dec_and_raw_lock); 66 + EXPORT_SYMBOL(atomic_dec_and_raw_lock); 67 67 68 68 int _atomic_dec_and_raw_lock_irqsave(atomic_t *atomic, raw_spinlock_t *lock, 69 69 unsigned long *flags)
-1
lib/lockref.c
··· 105 105 * @lockref: pointer to lockref structure 106 106 * Return: 1 if count updated successfully or 0 if count <= 1 and lock taken 107 107 */ 108 - #undef lockref_put_or_lock 109 108 bool lockref_put_or_lock(struct lockref *lockref) 110 109 { 111 110 CMPXCHG_LOOP(
+2 -2
mm/memory.c
··· 2210 2210 return pmd; 2211 2211 } 2212 2212 2213 - pte_t *__get_locked_pte(struct mm_struct *mm, unsigned long addr, 2214 - spinlock_t **ptl) 2213 + pte_t *get_locked_pte(struct mm_struct *mm, unsigned long addr, 2214 + spinlock_t **ptl) 2215 2215 { 2216 2216 pmd_t *pmd = walk_to_pmd(mm, addr); 2217 2217
+9 -10
mm/pgtable-generic.c
··· 280 280 static void pmdp_get_lockless_end(unsigned long irqflags) { } 281 281 #endif 282 282 283 - pte_t *___pte_offset_map(pmd_t *pmd, unsigned long addr, pmd_t *pmdvalp) 283 + pte_t *__pte_offset_map(pmd_t *pmd, unsigned long addr, pmd_t *pmdvalp) 284 284 { 285 285 unsigned long irqflags; 286 286 pmd_t pmdval; ··· 332 332 } 333 333 334 334 /* 335 - * pte_offset_map_lock(mm, pmd, addr, ptlp), and its internal implementation 336 - * __pte_offset_map_lock() below, is usually called with the pmd pointer for 337 - * addr, reached by walking down the mm's pgd, p4d, pud for addr: either while 338 - * holding mmap_lock or vma lock for read or for write; or in truncate or rmap 339 - * context, while holding file's i_mmap_lock or anon_vma lock for read (or for 340 - * write). In a few cases, it may be used with pmd pointing to a pmd_t already 341 - * copied to or constructed on the stack. 335 + * pte_offset_map_lock(mm, pmd, addr, ptlp) is usually called with the pmd 336 + * pointer for addr, reached by walking down the mm's pgd, p4d, pud for addr: 337 + * either while holding mmap_lock or vma lock for read or for write; or in 338 + * truncate or rmap context, while holding file's i_mmap_lock or anon_vma lock 339 + * for read (or for write). In a few cases, it may be used with pmd pointing to 340 + * a pmd_t already copied to or constructed on the stack. 342 341 * 343 342 * When successful, it returns the pte pointer for addr, with its page table 344 343 * kmapped if necessary (when CONFIG_HIGHPTE), and locked against concurrent ··· 388 389 * table, and may not use RCU at all: "outsiders" like khugepaged should avoid 389 390 * pte_offset_map() and co once the vma is detached from mm or mm_users is zero. 390 391 */ 391 - pte_t *__pte_offset_map_lock(struct mm_struct *mm, pmd_t *pmd, 392 - unsigned long addr, spinlock_t **ptlp) 392 + pte_t *pte_offset_map_lock(struct mm_struct *mm, pmd_t *pmd, 393 + unsigned long addr, spinlock_t **ptlp) 393 394 { 394 395 spinlock_t *ptl; 395 396 pmd_t pmdval;
-2
tools/include/linux/compiler_types.h
··· 20 20 # define __releases(x) __attribute__((context(x,1,0))) 21 21 # define __acquire(x) __context__(x,1) 22 22 # define __release(x) __context__(x,-1) 23 - # define __cond_lock(x,c) ((c) ? ({ __acquire(x); 1; }) : 0) 24 23 #else /* __CHECKER__ */ 25 24 /* context/locking */ 26 25 # define __must_hold(x) ··· 27 28 # define __releases(x) 28 29 # define __acquire(x) (void)0 29 30 # define __release(x) (void)0 30 - # define __cond_lock(x,c) (c) 31 31 #endif /* __CHECKER__ */ 32 32 33 33 /* Compiler specific macros. */