1 // SPDX-License-Identifier: GPL-2.0-only
5 #include <linux/spinlock.h>
6 #include <linux/export.h>
8 #define RT_MUTEX_BUILD_MUTEX
13 __ww_rt_mutex_lock(struct ww_mutex *lock, struct ww_acquire_ctx *ww_ctx,
14 unsigned int state, unsigned long ip)
16 struct lockdep_map __maybe_unused *nest_lock = NULL;
17 struct rt_mutex *rtm = &lock->base;
23 if (unlikely(ww_ctx == READ_ONCE(lock->ctx)))
27 * Reset the wounded flag after a kill. No other process can
28 * race and wound us here, since they can't have a valid owner
29 * pointer if we don't have any locks held.
31 if (ww_ctx->acquired == 0)
34 #ifdef CONFIG_DEBUG_LOCK_ALLOC
35 nest_lock = &ww_ctx->dep_map;
38 mutex_acquire_nest(&rtm->dep_map, 0, 0, nest_lock, ip);
40 if (likely(rt_mutex_cmpxchg_acquire(&rtm->rtmutex, NULL, current))) {
42 ww_mutex_set_context_fastpath(lock, ww_ctx);
46 ret = rt_mutex_slowlock(&rtm->rtmutex, ww_ctx, state);
49 mutex_release(&rtm->dep_map, ip);
54 ww_mutex_lock(struct ww_mutex *lock, struct ww_acquire_ctx *ctx)
56 return __ww_rt_mutex_lock(lock, ctx, TASK_UNINTERRUPTIBLE, _RET_IP_);
58 EXPORT_SYMBOL(ww_mutex_lock);
61 ww_mutex_lock_interruptible(struct ww_mutex *lock, struct ww_acquire_ctx *ctx)
63 return __ww_rt_mutex_lock(lock, ctx, TASK_INTERRUPTIBLE, _RET_IP_);
65 EXPORT_SYMBOL(ww_mutex_lock_interruptible);
67 void __sched ww_mutex_unlock(struct ww_mutex *lock)
69 struct rt_mutex *rtm = &lock->base;
71 __ww_mutex_unlock(lock);
73 mutex_release(&rtm->dep_map, _RET_IP_);
74 __rt_mutex_unlock(&rtm->rtmutex);
76 EXPORT_SYMBOL(ww_mutex_unlock);