···33# and is generally not a function of system call inputs.44KCOV_INSTRUMENT := n5566+CONTEXT_ANALYSIS_mutex.o := y77+68obj-y += mutex.o semaphore.o rwsem.o percpu-rwsem.o79810# Avoid recursion lockdep -> sanitizer -> ... -> lockdep & improve performance.
+28-5
kernel/locking/mutex.c
···4646static void __mutex_init_generic(struct mutex *lock)4747{4848 atomic_long_set(&lock->owner, 0);4949- raw_spin_lock_init(&lock->wait_lock);5050- lock->first_waiter = NULL;4949+ scoped_guard (raw_spinlock_init, &lock->wait_lock) {5050+ lock->first_waiter = NULL;5151+ }5152#ifdef CONFIG_MUTEX_SPIN_ON_OWNER5253 osq_lock_init(&lock->osq);5354#endif···151150 * follow with a __mutex_trylock() before failing.152151 */153152static __always_inline bool __mutex_trylock_fast(struct mutex *lock)153153+ __cond_acquires(true, lock)154154{155155 unsigned long curr = (unsigned long)current;156156 unsigned long zero = 0UL;···165163}166164167165static __always_inline bool __mutex_unlock_fast(struct mutex *lock)166166+ __cond_releases(true, lock)168167{169168 unsigned long curr = (unsigned long)current;170169···204201static void205202__mutex_add_waiter(struct mutex *lock, struct mutex_waiter *waiter,206203 struct mutex_waiter *first)204204+ __must_hold(&lock->wait_lock)207205{208206 hung_task_set_blocker(lock, BLOCKER_TYPE_MUTEX);209207 debug_mutex_add_waiter(lock, waiter, current);···223219224220static void225221__mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter)222222+ __must_hold(&lock->wait_lock)226223{227224 if (list_empty(&waiter->list)) {228225 __mutex_clear_flag(lock, MUTEX_FLAGS);···273268 * We also put the fastpath first in the kernel image, to make sure the274269 * branch is predicted by the CPU as default-untaken.275270 */276276-static void __sched __mutex_lock_slowpath(struct mutex *lock);271271+static void __sched __mutex_lock_slowpath(struct mutex *lock)272272+ __acquires(lock);277273278274/**279275 * mutex_lock - acquire the mutex···355349 * Similarly, stop spinning if we are no longer the356350 * first waiter.357351 */358358- if (waiter && lock->first_waiter != waiter)352352+ if (waiter && data_race(lock->first_waiter != waiter))359353 return false;360354361355 return true;···540534}541535#endif542536543543-static noinline void __sched __mutex_unlock_slowpath(struct mutex *lock, unsigned long ip);537537+static noinline void __sched __mutex_unlock_slowpath(struct mutex *lock, unsigned long ip)538538+ __releases(lock);544539545540/**546541 * mutex_unlock - release the mutex···581574 * of a unlocked mutex is not allowed.582575 */583576void __sched ww_mutex_unlock(struct ww_mutex *lock)577577+ __no_context_analysis584578{585579 __ww_mutex_unlock(lock);586580 mutex_unlock(&lock->base);···595587__mutex_lock_common(struct mutex *lock, unsigned int state, unsigned int subclass,596588 struct lockdep_map *nest_lock, unsigned long ip,597589 struct ww_acquire_ctx *ww_ctx, const bool use_ww_ctx)590590+ __cond_acquires(0, lock)598591{599592 DEFINE_WAKE_Q(wake_q);600593 struct mutex_waiter waiter;···789780static int __sched790781__mutex_lock(struct mutex *lock, unsigned int state, unsigned int subclass,791782 struct lockdep_map *nest_lock, unsigned long ip)783783+ __cond_acquires(0, lock)792784{793785 return __mutex_lock_common(lock, state, subclass, nest_lock, ip, NULL, false);794786}···797787static int __sched798788__ww_mutex_lock(struct mutex *lock, unsigned int state, unsigned int subclass,799789 unsigned long ip, struct ww_acquire_ctx *ww_ctx)790790+ __cond_acquires(0, lock)800791{801792 return __mutex_lock_common(lock, state, subclass, NULL, ip, ww_ctx, true);802793}···845834mutex_lock_nested(struct mutex *lock, unsigned int subclass)846835{847836 __mutex_lock(lock, TASK_UNINTERRUPTIBLE, subclass, NULL, _RET_IP_);837837+ __acquire(lock);848838}849839850840EXPORT_SYMBOL_GPL(mutex_lock_nested);···854842_mutex_lock_nest_lock(struct mutex *lock, struct lockdep_map *nest)855843{856844 __mutex_lock(lock, TASK_UNINTERRUPTIBLE, 0, nest, _RET_IP_);845845+ __acquire(lock);857846}858847EXPORT_SYMBOL_GPL(_mutex_lock_nest_lock);859848···883870 token = io_schedule_prepare();884871 __mutex_lock_common(lock, TASK_UNINTERRUPTIBLE,885872 subclass, NULL, _RET_IP_, NULL, 0);873873+ __acquire(lock);886874 io_schedule_finish(token);887875}888876EXPORT_SYMBOL_GPL(mutex_lock_io_nested);889877890878static inline int891879ww_mutex_deadlock_injection(struct ww_mutex *lock, struct ww_acquire_ctx *ctx)880880+ __cond_releases(nonzero, lock)892881{893882#ifdef CONFIG_DEBUG_WW_MUTEX_SLOWPATH894883 unsigned tmp;···952937 * Release the lock, slowpath:953938 */954939static noinline void __sched __mutex_unlock_slowpath(struct mutex *lock, unsigned long ip)940940+ __releases(lock)955941{956942 struct task_struct *next = NULL;957943 struct mutex_waiter *waiter;···961945 unsigned long flags;962946963947 mutex_release(&lock->dep_map, ip);948948+ __release(lock);964949965950 /*966951 * Release the lock before (potentially) taking the spinlock such that···1083106610841067static noinline void __sched10851068__mutex_lock_slowpath(struct mutex *lock)10691069+ __acquires(lock)10861070{10871071 __mutex_lock(lock, TASK_UNINTERRUPTIBLE, 0, NULL, _RET_IP_);10721072+ __acquire(lock);10881073}1089107410901075static noinline int __sched10911076__mutex_lock_killable_slowpath(struct mutex *lock)10771077+ __cond_acquires(0, lock)10921078{10931079 return __mutex_lock(lock, TASK_KILLABLE, 0, NULL, _RET_IP_);10941080}1095108110961082static noinline int __sched10971083__mutex_lock_interruptible_slowpath(struct mutex *lock)10841084+ __cond_acquires(0, lock)10981085{10991086 return __mutex_lock(lock, TASK_INTERRUPTIBLE, 0, NULL, _RET_IP_);11001087}1101108811021089static noinline int __sched11031090__ww_mutex_lock_slowpath(struct ww_mutex *lock, struct ww_acquire_ctx *ctx)10911091+ __cond_acquires(0, lock)11041092{11051093 return __ww_mutex_lock(&lock->base, TASK_UNINTERRUPTIBLE, 0,11061094 _RET_IP_, ctx);···11141092static noinline int __sched11151093__ww_mutex_lock_interruptible_slowpath(struct ww_mutex *lock,11161094 struct ww_acquire_ctx *ctx)10951095+ __cond_acquires(0, lock)11171096{11181097 return __ww_mutex_lock(&lock->base, TASK_INTERRUPTIBLE, 0,11191098 _RET_IP_, ctx);
+1
kernel/locking/mutex.h
···77 * Copyright (C) 2004, 2005, 2006 Red Hat, Inc., Ingo Molnar <mingo@redhat.com>88 */99#ifndef CONFIG_PREEMPT_RT1010+#include <linux/mutex.h>1011/*1112 * This is the control structure for tasks blocked on mutex, which resides1213 * on the blocked task's kernel stack: