rtmutex_api.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * rtmutex API
  4. */
  5. #include <linux/spinlock.h>
  6. #include <linux/export.h>
  7. #define RT_MUTEX_BUILD_MUTEX
  8. #include "rtmutex.c"
  9. /*
  10. * Max number of times we'll walk the boosting chain:
  11. */
  12. int max_lock_depth = 1024;
  13. /*
  14. * Debug aware fast / slowpath lock,trylock,unlock
  15. *
  16. * The atomic acquire/release ops are compiled away, when either the
  17. * architecture does not support cmpxchg or when debugging is enabled.
  18. */
  19. static __always_inline int __rt_mutex_lock_common(struct rt_mutex *lock,
  20. unsigned int state,
  21. struct lockdep_map *nest_lock,
  22. unsigned int subclass)
  23. {
  24. int ret;
  25. might_sleep();
  26. mutex_acquire_nest(&lock->dep_map, subclass, 0, nest_lock, _RET_IP_);
  27. ret = __rt_mutex_lock(&lock->rtmutex, state);
  28. if (ret)
  29. mutex_release(&lock->dep_map, _RET_IP_);
  30. return ret;
  31. }
  32. void rt_mutex_base_init(struct rt_mutex_base *rtb)
  33. {
  34. __rt_mutex_base_init(rtb);
  35. }
  36. EXPORT_SYMBOL(rt_mutex_base_init);
  37. #ifdef CONFIG_DEBUG_LOCK_ALLOC
  38. /**
  39. * rt_mutex_lock_nested - lock a rt_mutex
  40. *
  41. * @lock: the rt_mutex to be locked
  42. * @subclass: the lockdep subclass
  43. */
  44. void __sched rt_mutex_lock_nested(struct rt_mutex *lock, unsigned int subclass)
  45. {
  46. __rt_mutex_lock_common(lock, TASK_UNINTERRUPTIBLE, NULL, subclass);
  47. }
  48. EXPORT_SYMBOL_GPL(rt_mutex_lock_nested);
  49. void __sched _rt_mutex_lock_nest_lock(struct rt_mutex *lock, struct lockdep_map *nest_lock)
  50. {
  51. __rt_mutex_lock_common(lock, TASK_UNINTERRUPTIBLE, nest_lock, 0);
  52. }
  53. EXPORT_SYMBOL_GPL(_rt_mutex_lock_nest_lock);
  54. #else /* !CONFIG_DEBUG_LOCK_ALLOC */
  55. /**
  56. * rt_mutex_lock - lock a rt_mutex
  57. *
  58. * @lock: the rt_mutex to be locked
  59. */
  60. void __sched rt_mutex_lock(struct rt_mutex *lock)
  61. {
  62. __rt_mutex_lock_common(lock, TASK_UNINTERRUPTIBLE, NULL, 0);
  63. }
  64. EXPORT_SYMBOL_GPL(rt_mutex_lock);
  65. #endif
  66. /**
  67. * rt_mutex_lock_interruptible - lock a rt_mutex interruptible
  68. *
  69. * @lock: the rt_mutex to be locked
  70. *
  71. * Returns:
  72. * 0 on success
  73. * -EINTR when interrupted by a signal
  74. */
  75. int __sched rt_mutex_lock_interruptible(struct rt_mutex *lock)
  76. {
  77. return __rt_mutex_lock_common(lock, TASK_INTERRUPTIBLE, NULL, 0);
  78. }
  79. EXPORT_SYMBOL_GPL(rt_mutex_lock_interruptible);
  80. /**
  81. * rt_mutex_lock_killable - lock a rt_mutex killable
  82. *
  83. * @lock: the rt_mutex to be locked
  84. *
  85. * Returns:
  86. * 0 on success
  87. * -EINTR when interrupted by a signal
  88. */
  89. int __sched rt_mutex_lock_killable(struct rt_mutex *lock)
  90. {
  91. return __rt_mutex_lock_common(lock, TASK_KILLABLE, NULL, 0);
  92. }
  93. EXPORT_SYMBOL_GPL(rt_mutex_lock_killable);
  94. /**
  95. * rt_mutex_trylock - try to lock a rt_mutex
  96. *
  97. * @lock: the rt_mutex to be locked
  98. *
  99. * This function can only be called in thread context. It's safe to call it
  100. * from atomic regions, but not from hard or soft interrupt context.
  101. *
  102. * Returns:
  103. * 1 on success
  104. * 0 on contention
  105. */
  106. int __sched rt_mutex_trylock(struct rt_mutex *lock)
  107. {
  108. int ret;
  109. if (IS_ENABLED(CONFIG_DEBUG_RT_MUTEXES) && WARN_ON_ONCE(!in_task()))
  110. return 0;
  111. ret = __rt_mutex_trylock(&lock->rtmutex);
  112. if (ret)
  113. mutex_acquire(&lock->dep_map, 0, 1, _RET_IP_);
  114. return ret;
  115. }
  116. EXPORT_SYMBOL_GPL(rt_mutex_trylock);
  117. /**
  118. * rt_mutex_unlock - unlock a rt_mutex
  119. *
  120. * @lock: the rt_mutex to be unlocked
  121. */
  122. void __sched rt_mutex_unlock(struct rt_mutex *lock)
  123. {
  124. mutex_release(&lock->dep_map, _RET_IP_);
  125. __rt_mutex_unlock(&lock->rtmutex);
  126. }
  127. EXPORT_SYMBOL_GPL(rt_mutex_unlock);
  128. /*
  129. * Futex variants, must not use fastpath.
  130. */
  131. int __sched rt_mutex_futex_trylock(struct rt_mutex_base *lock)
  132. {
  133. return rt_mutex_slowtrylock(lock);
  134. }
  135. int __sched __rt_mutex_futex_trylock(struct rt_mutex_base *lock)
  136. {
  137. return __rt_mutex_slowtrylock(lock);
  138. }
  139. /**
  140. * __rt_mutex_futex_unlock - Futex variant, that since futex variants
  141. * do not use the fast-path, can be simple and will not need to retry.
  142. *
  143. * @lock: The rt_mutex to be unlocked
  144. * @wqh: The wake queue head from which to get the next lock waiter
  145. */
  146. bool __sched __rt_mutex_futex_unlock(struct rt_mutex_base *lock,
  147. struct rt_wake_q_head *wqh)
  148. {
  149. lockdep_assert_held(&lock->wait_lock);
  150. debug_rt_mutex_unlock(lock);
  151. if (!rt_mutex_has_waiters(lock)) {
  152. lock->owner = NULL;
  153. return false; /* done */
  154. }
  155. /*
  156. * We've already deboosted, mark_wakeup_next_waiter() will
  157. * retain preempt_disabled when we drop the wait_lock, to
  158. * avoid inversion prior to the wakeup. preempt_disable()
  159. * therein pairs with rt_mutex_postunlock().
  160. */
  161. mark_wakeup_next_waiter(wqh, lock);
  162. return true; /* call postunlock() */
  163. }
  164. void __sched rt_mutex_futex_unlock(struct rt_mutex_base *lock)
  165. {
  166. DEFINE_RT_WAKE_Q(wqh);
  167. unsigned long flags;
  168. bool postunlock;
  169. raw_spin_lock_irqsave(&lock->wait_lock, flags);
  170. postunlock = __rt_mutex_futex_unlock(lock, &wqh);
  171. raw_spin_unlock_irqrestore(&lock->wait_lock, flags);
  172. if (postunlock)
  173. rt_mutex_postunlock(&wqh);
  174. }
  175. /**
  176. * __rt_mutex_init - initialize the rt_mutex
  177. *
  178. * @lock: The rt_mutex to be initialized
  179. * @name: The lock name used for debugging
  180. * @key: The lock class key used for debugging
  181. *
  182. * Initialize the rt_mutex to unlocked state.
  183. *
  184. * Initializing of a locked rt_mutex is not allowed
  185. */
  186. void __sched __rt_mutex_init(struct rt_mutex *lock, const char *name,
  187. struct lock_class_key *key)
  188. {
  189. debug_check_no_locks_freed((void *)lock, sizeof(*lock));
  190. __rt_mutex_base_init(&lock->rtmutex);
  191. lockdep_init_map_wait(&lock->dep_map, name, key, 0, LD_WAIT_SLEEP);
  192. }
  193. EXPORT_SYMBOL_GPL(__rt_mutex_init);
  194. /**
  195. * rt_mutex_init_proxy_locked - initialize and lock a rt_mutex on behalf of a
  196. * proxy owner
  197. *
  198. * @lock: the rt_mutex to be locked
  199. * @proxy_owner:the task to set as owner
  200. *
  201. * No locking. Caller has to do serializing itself
  202. *
  203. * Special API call for PI-futex support. This initializes the rtmutex and
  204. * assigns it to @proxy_owner. Concurrent operations on the rtmutex are not
  205. * possible at this point because the pi_state which contains the rtmutex
  206. * is not yet visible to other tasks.
  207. */
  208. void __sched rt_mutex_init_proxy_locked(struct rt_mutex_base *lock,
  209. struct task_struct *proxy_owner)
  210. {
  211. static struct lock_class_key pi_futex_key;
  212. __rt_mutex_base_init(lock);
  213. /*
  214. * On PREEMPT_RT the futex hashbucket spinlock becomes 'sleeping'
  215. * and rtmutex based. That causes a lockdep false positive, because
  216. * some of the futex functions invoke spin_unlock(&hb->lock) with
  217. * the wait_lock of the rtmutex associated to the pi_futex held.
  218. * spin_unlock() in turn takes wait_lock of the rtmutex on which
  219. * the spinlock is based, which makes lockdep notice a lock
  220. * recursion. Give the futex/rtmutex wait_lock a separate key.
  221. */
  222. lockdep_set_class(&lock->wait_lock, &pi_futex_key);
  223. rt_mutex_set_owner(lock, proxy_owner);
  224. }
  225. /**
  226. * rt_mutex_proxy_unlock - release a lock on behalf of owner
  227. *
  228. * @lock: the rt_mutex to be locked
  229. *
  230. * No locking. Caller has to do serializing itself
  231. *
  232. * Special API call for PI-futex support. This just cleans up the rtmutex
  233. * (debugging) state. Concurrent operations on this rt_mutex are not
  234. * possible because it belongs to the pi_state which is about to be freed
  235. * and it is not longer visible to other tasks.
  236. */
  237. void __sched rt_mutex_proxy_unlock(struct rt_mutex_base *lock)
  238. {
  239. debug_rt_mutex_proxy_unlock(lock);
  240. rt_mutex_clear_owner(lock);
  241. }
  242. /**
  243. * __rt_mutex_start_proxy_lock() - Start lock acquisition for another task
  244. * @lock: the rt_mutex to take
  245. * @waiter: the pre-initialized rt_mutex_waiter
  246. * @task: the task to prepare
  247. *
  248. * Starts the rt_mutex acquire; it enqueues the @waiter and does deadlock
  249. * detection. It does not wait, see rt_mutex_wait_proxy_lock() for that.
  250. *
  251. * NOTE: does _NOT_ remove the @waiter on failure; must either call
  252. * rt_mutex_wait_proxy_lock() or rt_mutex_cleanup_proxy_lock() after this.
  253. *
  254. * Returns:
  255. * 0 - task blocked on lock
  256. * 1 - acquired the lock for task, caller should wake it up
  257. * <0 - error
  258. *
  259. * Special API call for PI-futex support.
  260. */
  261. int __sched __rt_mutex_start_proxy_lock(struct rt_mutex_base *lock,
  262. struct rt_mutex_waiter *waiter,
  263. struct task_struct *task)
  264. {
  265. int ret;
  266. lockdep_assert_held(&lock->wait_lock);
  267. if (try_to_take_rt_mutex(lock, task, NULL))
  268. return 1;
  269. /* We enforce deadlock detection for futexes */
  270. ret = task_blocks_on_rt_mutex(lock, waiter, task, NULL,
  271. RT_MUTEX_FULL_CHAINWALK);
  272. if (ret && !rt_mutex_owner(lock)) {
  273. /*
  274. * Reset the return value. We might have
  275. * returned with -EDEADLK and the owner
  276. * released the lock while we were walking the
  277. * pi chain. Let the waiter sort it out.
  278. */
  279. ret = 0;
  280. }
  281. return ret;
  282. }
  283. /**
  284. * rt_mutex_start_proxy_lock() - Start lock acquisition for another task
  285. * @lock: the rt_mutex to take
  286. * @waiter: the pre-initialized rt_mutex_waiter
  287. * @task: the task to prepare
  288. *
  289. * Starts the rt_mutex acquire; it enqueues the @waiter and does deadlock
  290. * detection. It does not wait, see rt_mutex_wait_proxy_lock() for that.
  291. *
  292. * NOTE: unlike __rt_mutex_start_proxy_lock this _DOES_ remove the @waiter
  293. * on failure.
  294. *
  295. * Returns:
  296. * 0 - task blocked on lock
  297. * 1 - acquired the lock for task, caller should wake it up
  298. * <0 - error
  299. *
  300. * Special API call for PI-futex support.
  301. */
  302. int __sched rt_mutex_start_proxy_lock(struct rt_mutex_base *lock,
  303. struct rt_mutex_waiter *waiter,
  304. struct task_struct *task)
  305. {
  306. int ret;
  307. raw_spin_lock_irq(&lock->wait_lock);
  308. ret = __rt_mutex_start_proxy_lock(lock, waiter, task);
  309. if (unlikely(ret))
  310. remove_waiter(lock, waiter);
  311. raw_spin_unlock_irq(&lock->wait_lock);
  312. return ret;
  313. }
  314. /**
  315. * rt_mutex_wait_proxy_lock() - Wait for lock acquisition
  316. * @lock: the rt_mutex we were woken on
  317. * @to: the timeout, null if none. hrtimer should already have
  318. * been started.
  319. * @waiter: the pre-initialized rt_mutex_waiter
  320. *
  321. * Wait for the lock acquisition started on our behalf by
  322. * rt_mutex_start_proxy_lock(). Upon failure, the caller must call
  323. * rt_mutex_cleanup_proxy_lock().
  324. *
  325. * Returns:
  326. * 0 - success
  327. * <0 - error, one of -EINTR, -ETIMEDOUT
  328. *
  329. * Special API call for PI-futex support
  330. */
  331. int __sched rt_mutex_wait_proxy_lock(struct rt_mutex_base *lock,
  332. struct hrtimer_sleeper *to,
  333. struct rt_mutex_waiter *waiter)
  334. {
  335. int ret;
  336. raw_spin_lock_irq(&lock->wait_lock);
  337. /* sleep on the mutex */
  338. set_current_state(TASK_INTERRUPTIBLE);
  339. ret = rt_mutex_slowlock_block(lock, NULL, TASK_INTERRUPTIBLE, to, waiter);
  340. /*
  341. * try_to_take_rt_mutex() sets the waiter bit unconditionally. We might
  342. * have to fix that up.
  343. */
  344. fixup_rt_mutex_waiters(lock, true);
  345. raw_spin_unlock_irq(&lock->wait_lock);
  346. return ret;
  347. }
  348. /**
  349. * rt_mutex_cleanup_proxy_lock() - Cleanup failed lock acquisition
  350. * @lock: the rt_mutex we were woken on
  351. * @waiter: the pre-initialized rt_mutex_waiter
  352. *
  353. * Attempt to clean up after a failed __rt_mutex_start_proxy_lock() or
  354. * rt_mutex_wait_proxy_lock().
  355. *
  356. * Unless we acquired the lock; we're still enqueued on the wait-list and can
  357. * in fact still be granted ownership until we're removed. Therefore we can
  358. * find we are in fact the owner and must disregard the
  359. * rt_mutex_wait_proxy_lock() failure.
  360. *
  361. * Returns:
  362. * true - did the cleanup, we done.
  363. * false - we acquired the lock after rt_mutex_wait_proxy_lock() returned,
  364. * caller should disregards its return value.
  365. *
  366. * Special API call for PI-futex support
  367. */
  368. bool __sched rt_mutex_cleanup_proxy_lock(struct rt_mutex_base *lock,
  369. struct rt_mutex_waiter *waiter)
  370. {
  371. bool cleanup = false;
  372. raw_spin_lock_irq(&lock->wait_lock);
  373. /*
  374. * Do an unconditional try-lock, this deals with the lock stealing
  375. * state where __rt_mutex_futex_unlock() -> mark_wakeup_next_waiter()
  376. * sets a NULL owner.
  377. *
  378. * We're not interested in the return value, because the subsequent
  379. * test on rt_mutex_owner() will infer that. If the trylock succeeded,
  380. * we will own the lock and it will have removed the waiter. If we
  381. * failed the trylock, we're still not owner and we need to remove
  382. * ourselves.
  383. */
  384. try_to_take_rt_mutex(lock, current, waiter);
  385. /*
  386. * Unless we're the owner; we're still enqueued on the wait_list.
  387. * So check if we became owner, if not, take us off the wait_list.
  388. */
  389. if (rt_mutex_owner(lock) != current) {
  390. remove_waiter(lock, waiter);
  391. cleanup = true;
  392. }
  393. /*
  394. * try_to_take_rt_mutex() sets the waiter bit unconditionally. We might
  395. * have to fix that up.
  396. */
  397. fixup_rt_mutex_waiters(lock, false);
  398. raw_spin_unlock_irq(&lock->wait_lock);
  399. return cleanup;
  400. }
  401. /*
  402. * Recheck the pi chain, in case we got a priority setting
  403. *
  404. * Called from sched_setscheduler
  405. */
  406. void __sched rt_mutex_adjust_pi(struct task_struct *task)
  407. {
  408. struct rt_mutex_waiter *waiter;
  409. struct rt_mutex_base *next_lock;
  410. unsigned long flags;
  411. raw_spin_lock_irqsave(&task->pi_lock, flags);
  412. waiter = task->pi_blocked_on;
  413. if (!waiter || rt_waiter_node_equal(&waiter->tree, task_to_waiter_node(task))) {
  414. raw_spin_unlock_irqrestore(&task->pi_lock, flags);
  415. return;
  416. }
  417. next_lock = waiter->lock;
  418. raw_spin_unlock_irqrestore(&task->pi_lock, flags);
  419. /* gets dropped in rt_mutex_adjust_prio_chain()! */
  420. get_task_struct(task);
  421. rt_mutex_adjust_prio_chain(task, RT_MUTEX_MIN_CHAINWALK, NULL,
  422. next_lock, NULL, task);
  423. }
  424. /*
  425. * Performs the wakeup of the top-waiter and re-enables preemption.
  426. */
  427. void __sched rt_mutex_postunlock(struct rt_wake_q_head *wqh)
  428. {
  429. rt_mutex_wake_up_q(wqh);
  430. }
  431. #ifdef CONFIG_DEBUG_RT_MUTEXES
  432. void rt_mutex_debug_task_free(struct task_struct *task)
  433. {
  434. DEBUG_LOCKS_WARN_ON(!RB_EMPTY_ROOT(&task->pi_waiters.rb_root));
  435. DEBUG_LOCKS_WARN_ON(task->pi_blocked_on);
  436. }
  437. #endif
  438. #ifdef CONFIG_PREEMPT_RT
  439. /* Mutexes */
  440. void __mutex_rt_init(struct mutex *mutex, const char *name,
  441. struct lock_class_key *key)
  442. {
  443. debug_check_no_locks_freed((void *)mutex, sizeof(*mutex));
  444. lockdep_init_map_wait(&mutex->dep_map, name, key, 0, LD_WAIT_SLEEP);
  445. }
  446. EXPORT_SYMBOL(__mutex_rt_init);
  447. static __always_inline int __mutex_lock_common(struct mutex *lock,
  448. unsigned int state,
  449. unsigned int subclass,
  450. struct lockdep_map *nest_lock,
  451. unsigned long ip)
  452. {
  453. int ret;
  454. might_sleep();
  455. mutex_acquire_nest(&lock->dep_map, subclass, 0, nest_lock, ip);
  456. ret = __rt_mutex_lock(&lock->rtmutex, state);
  457. if (ret)
  458. mutex_release(&lock->dep_map, ip);
  459. else
  460. lock_acquired(&lock->dep_map, ip);
  461. return ret;
  462. }
  463. #ifdef CONFIG_DEBUG_LOCK_ALLOC
  464. void __sched mutex_lock_nested(struct mutex *lock, unsigned int subclass)
  465. {
  466. __mutex_lock_common(lock, TASK_UNINTERRUPTIBLE, subclass, NULL, _RET_IP_);
  467. }
  468. EXPORT_SYMBOL_GPL(mutex_lock_nested);
  469. void __sched _mutex_lock_nest_lock(struct mutex *lock,
  470. struct lockdep_map *nest_lock)
  471. {
  472. __mutex_lock_common(lock, TASK_UNINTERRUPTIBLE, 0, nest_lock, _RET_IP_);
  473. }
  474. EXPORT_SYMBOL_GPL(_mutex_lock_nest_lock);
  475. int __sched mutex_lock_interruptible_nested(struct mutex *lock,
  476. unsigned int subclass)
  477. {
  478. return __mutex_lock_common(lock, TASK_INTERRUPTIBLE, subclass, NULL, _RET_IP_);
  479. }
  480. EXPORT_SYMBOL_GPL(mutex_lock_interruptible_nested);
  481. int __sched mutex_lock_killable_nested(struct mutex *lock,
  482. unsigned int subclass)
  483. {
  484. return __mutex_lock_common(lock, TASK_KILLABLE, subclass, NULL, _RET_IP_);
  485. }
  486. EXPORT_SYMBOL_GPL(mutex_lock_killable_nested);
  487. void __sched mutex_lock_io_nested(struct mutex *lock, unsigned int subclass)
  488. {
  489. int token;
  490. might_sleep();
  491. token = io_schedule_prepare();
  492. __mutex_lock_common(lock, TASK_UNINTERRUPTIBLE, subclass, NULL, _RET_IP_);
  493. io_schedule_finish(token);
  494. }
  495. EXPORT_SYMBOL_GPL(mutex_lock_io_nested);
  496. #else /* CONFIG_DEBUG_LOCK_ALLOC */
  497. void __sched mutex_lock(struct mutex *lock)
  498. {
  499. __mutex_lock_common(lock, TASK_UNINTERRUPTIBLE, 0, NULL, _RET_IP_);
  500. }
  501. EXPORT_SYMBOL(mutex_lock);
  502. int __sched mutex_lock_interruptible(struct mutex *lock)
  503. {
  504. return __mutex_lock_common(lock, TASK_INTERRUPTIBLE, 0, NULL, _RET_IP_);
  505. }
  506. EXPORT_SYMBOL(mutex_lock_interruptible);
  507. int __sched mutex_lock_killable(struct mutex *lock)
  508. {
  509. return __mutex_lock_common(lock, TASK_KILLABLE, 0, NULL, _RET_IP_);
  510. }
  511. EXPORT_SYMBOL(mutex_lock_killable);
  512. void __sched mutex_lock_io(struct mutex *lock)
  513. {
  514. int token = io_schedule_prepare();
  515. __mutex_lock_common(lock, TASK_UNINTERRUPTIBLE, 0, NULL, _RET_IP_);
  516. io_schedule_finish(token);
  517. }
  518. EXPORT_SYMBOL(mutex_lock_io);
  519. #endif /* !CONFIG_DEBUG_LOCK_ALLOC */
  520. int __sched mutex_trylock(struct mutex *lock)
  521. {
  522. int ret;
  523. if (IS_ENABLED(CONFIG_DEBUG_RT_MUTEXES) && WARN_ON_ONCE(!in_task()))
  524. return 0;
  525. ret = __rt_mutex_trylock(&lock->rtmutex);
  526. if (ret)
  527. mutex_acquire(&lock->dep_map, 0, 1, _RET_IP_);
  528. return ret;
  529. }
  530. EXPORT_SYMBOL(mutex_trylock);
  531. void __sched mutex_unlock(struct mutex *lock)
  532. {
  533. mutex_release(&lock->dep_map, _RET_IP_);
  534. __rt_mutex_unlock(&lock->rtmutex);
  535. }
  536. EXPORT_SYMBOL(mutex_unlock);
  537. #endif /* CONFIG_PREEMPT_RT */