at commit 2e42cade

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