hc
2023-12-11 6778948f9de86c3cfaf36725a7c87dcff9ba247f
kernel/kernel/locking/rtmutex.c
....@@ -8,11 +8,6 @@
88 * Copyright (C) 2005-2006 Timesys Corp., Thomas Gleixner <tglx@timesys.com>
99 * Copyright (C) 2005 Kihon Technologies Inc., Steven Rostedt
1010 * Copyright (C) 2006 Esben Nielsen
11
- * Adaptive Spinlocks:
12
- * Copyright (C) 2008 Novell, Inc., Gregory Haskins, Sven Dietrich,
13
- * and Peter Morreale,
14
- * Adaptive Spinlocks simplification:
15
- * Copyright (C) 2008 Red Hat, Inc., Steven Rostedt <srostedt@redhat.com>
1611 *
1712 * See Documentation/locking/rt-mutex-design.rst for details.
1813 */
....@@ -25,7 +20,6 @@
2520 #include <linux/sched/debug.h>
2621 #include <linux/timer.h>
2722 #include <trace/hooks/dtask.h>
28
-#include <linux/ww_mutex.h>
2923
3024 #include "rtmutex_common.h"
3125
....@@ -143,12 +137,6 @@
143137 WRITE_ONCE(*p, owner & ~RT_MUTEX_HAS_WAITERS);
144138 }
145139
146
-static int rt_mutex_real_waiter(struct rt_mutex_waiter *waiter)
147
-{
148
- return waiter && waiter != PI_WAKEUP_INPROGRESS &&
149
- waiter != PI_REQUEUE_INPROGRESS;
150
-}
151
-
152140 /*
153141 * We can speed up the acquire/release, if there's no debugging state to be
154142 * set up.
....@@ -240,7 +228,7 @@
240228 * Only use with rt_mutex_waiter_{less,equal}()
241229 */
242230 #define task_to_waiter(p) \
243
- &(struct rt_mutex_waiter){ .prio = (p)->prio, .deadline = (p)->dl.deadline, .task = (p) }
231
+ &(struct rt_mutex_waiter){ .prio = (p)->prio, .deadline = (p)->dl.deadline }
244232
245233 static inline int
246234 rt_mutex_waiter_less(struct rt_mutex_waiter *left,
....@@ -278,27 +266,6 @@
278266 return left->deadline == right->deadline;
279267
280268 return 1;
281
-}
282
-
283
-#define STEAL_NORMAL 0
284
-#define STEAL_LATERAL 1
285
-
286
-static inline int
287
-rt_mutex_steal(struct rt_mutex *lock, struct rt_mutex_waiter *waiter, int mode)
288
-{
289
- struct rt_mutex_waiter *top_waiter = rt_mutex_top_waiter(lock);
290
-
291
- if (waiter == top_waiter || rt_mutex_waiter_less(waiter, top_waiter))
292
- return 1;
293
-
294
- /*
295
- * Note that RT tasks are excluded from lateral-steals
296
- * to prevent the introduction of an unbounded latency.
297
- */
298
- if (mode == STEAL_NORMAL || rt_task(waiter->task))
299
- return 0;
300
-
301
- return rt_mutex_waiter_equal(waiter, top_waiter);
302269 }
303270
304271 static void
....@@ -405,14 +372,6 @@
405372 return debug_rt_mutex_detect_deadlock(waiter, chwalk);
406373 }
407374
408
-static void rt_mutex_wake_waiter(struct rt_mutex_waiter *waiter)
409
-{
410
- if (waiter->savestate)
411
- wake_up_lock_sleeper(waiter->task);
412
- else
413
- wake_up_process(waiter->task);
414
-}
415
-
416375 /*
417376 * Max number of times we'll walk the boosting chain:
418377 */
....@@ -420,8 +379,7 @@
420379
421380 static inline struct rt_mutex *task_blocked_on_lock(struct task_struct *p)
422381 {
423
- return rt_mutex_real_waiter(p->pi_blocked_on) ?
424
- p->pi_blocked_on->lock : NULL;
382
+ return p->pi_blocked_on ? p->pi_blocked_on->lock : NULL;
425383 }
426384
427385 /*
....@@ -557,7 +515,7 @@
557515 * reached or the state of the chain has changed while we
558516 * dropped the locks.
559517 */
560
- if (!rt_mutex_real_waiter(waiter))
518
+ if (!waiter)
561519 goto out_unlock_pi;
562520
563521 /*
....@@ -640,6 +598,7 @@
640598 * walk, we detected a deadlock.
641599 */
642600 if (lock == orig_lock || rt_mutex_owner(lock) == top_task) {
601
+ debug_rt_mutex_deadlock(chwalk, orig_waiter, lock);
643602 raw_spin_unlock(&lock->wait_lock);
644603 ret = -EDEADLK;
645604 goto out_unlock_pi;
....@@ -736,16 +695,13 @@
736695 * follow here. This is the end of the chain we are walking.
737696 */
738697 if (!rt_mutex_owner(lock)) {
739
- struct rt_mutex_waiter *lock_top_waiter;
740
-
741698 /*
742699 * If the requeue [7] above changed the top waiter,
743700 * then we need to wake the new top waiter up to try
744701 * to get the lock.
745702 */
746
- lock_top_waiter = rt_mutex_top_waiter(lock);
747
- if (prerequeue_top_waiter != lock_top_waiter)
748
- rt_mutex_wake_waiter(lock_top_waiter);
703
+ if (prerequeue_top_waiter != rt_mutex_top_waiter(lock))
704
+ wake_up_process(rt_mutex_top_waiter(lock)->task);
749705 raw_spin_unlock_irq(&lock->wait_lock);
750706 return 0;
751707 }
....@@ -846,11 +802,9 @@
846802 * @task: The task which wants to acquire the lock
847803 * @waiter: The waiter that is queued to the lock's wait tree if the
848804 * callsite called task_blocked_on_lock(), otherwise NULL
849
- * @mode: Lock steal mode (STEAL_NORMAL, STEAL_LATERAL)
850805 */
851
-static int __try_to_take_rt_mutex(struct rt_mutex *lock,
852
- struct task_struct *task,
853
- struct rt_mutex_waiter *waiter, int mode)
806
+static int try_to_take_rt_mutex(struct rt_mutex *lock, struct task_struct *task,
807
+ struct rt_mutex_waiter *waiter)
854808 {
855809 lockdep_assert_held(&lock->wait_lock);
856810
....@@ -886,11 +840,12 @@
886840 */
887841 if (waiter) {
888842 /*
889
- * If waiter is not the highest priority waiter of @lock,
890
- * or its peer when lateral steal is allowed, give up.
843
+ * If waiter is not the highest priority waiter of
844
+ * @lock, give up.
891845 */
892
- if (!rt_mutex_steal(lock, waiter, mode))
846
+ if (waiter != rt_mutex_top_waiter(lock))
893847 return 0;
848
+
894849 /*
895850 * We can acquire the lock. Remove the waiter from the
896851 * lock waiters tree.
....@@ -908,12 +863,14 @@
908863 */
909864 if (rt_mutex_has_waiters(lock)) {
910865 /*
911
- * If @task->prio is greater than the top waiter
912
- * priority (kernel view), or equal to it when a
913
- * lateral steal is forbidden, @task lost.
866
+ * If @task->prio is greater than or equal to
867
+ * the top waiter priority (kernel view),
868
+ * @task lost.
914869 */
915
- if (!rt_mutex_steal(lock, task_to_waiter(task), mode))
870
+ if (!rt_mutex_waiter_less(task_to_waiter(task),
871
+ rt_mutex_top_waiter(lock)))
916872 return 0;
873
+
917874 /*
918875 * The current top waiter stays enqueued. We
919876 * don't have to change anything in the lock
....@@ -960,329 +917,6 @@
960917 return 1;
961918 }
962919
963
-#ifdef CONFIG_PREEMPT_RT
964
-/*
965
- * preemptible spin_lock functions:
966
- */
967
-static inline void rt_spin_lock_fastlock(struct rt_mutex *lock,
968
- void (*slowfn)(struct rt_mutex *lock))
969
-{
970
- might_sleep_no_state_check();
971
-
972
- if (likely(rt_mutex_cmpxchg_acquire(lock, NULL, current)))
973
- return;
974
- else
975
- slowfn(lock);
976
-}
977
-
978
-static inline void rt_spin_lock_fastunlock(struct rt_mutex *lock,
979
- void (*slowfn)(struct rt_mutex *lock))
980
-{
981
- if (likely(rt_mutex_cmpxchg_release(lock, current, NULL)))
982
- return;
983
- else
984
- slowfn(lock);
985
-}
986
-#ifdef CONFIG_SMP
987
-/*
988
- * Note that owner is a speculative pointer and dereferencing relies
989
- * on rcu_read_lock() and the check against the lock owner.
990
- */
991
-static int adaptive_wait(struct rt_mutex *lock,
992
- struct task_struct *owner)
993
-{
994
- int res = 0;
995
-
996
- rcu_read_lock();
997
- for (;;) {
998
- if (owner != rt_mutex_owner(lock))
999
- break;
1000
- /*
1001
- * Ensure that owner->on_cpu is dereferenced _after_
1002
- * checking the above to be valid.
1003
- */
1004
- barrier();
1005
- if (!owner->on_cpu) {
1006
- res = 1;
1007
- break;
1008
- }
1009
- cpu_relax();
1010
- }
1011
- rcu_read_unlock();
1012
- return res;
1013
-}
1014
-#else
1015
-static int adaptive_wait(struct rt_mutex *lock,
1016
- struct task_struct *orig_owner)
1017
-{
1018
- return 1;
1019
-}
1020
-#endif
1021
-
1022
-static int task_blocks_on_rt_mutex(struct rt_mutex *lock,
1023
- struct rt_mutex_waiter *waiter,
1024
- struct task_struct *task,
1025
- enum rtmutex_chainwalk chwalk);
1026
-/*
1027
- * Slow path lock function spin_lock style: this variant is very
1028
- * careful not to miss any non-lock wakeups.
1029
- *
1030
- * We store the current state under p->pi_lock in p->saved_state and
1031
- * the try_to_wake_up() code handles this accordingly.
1032
- */
1033
-void __sched rt_spin_lock_slowlock_locked(struct rt_mutex *lock,
1034
- struct rt_mutex_waiter *waiter,
1035
- unsigned long flags)
1036
-{
1037
- struct task_struct *lock_owner, *self = current;
1038
- struct rt_mutex_waiter *top_waiter;
1039
- int ret;
1040
-
1041
- if (__try_to_take_rt_mutex(lock, self, NULL, STEAL_LATERAL))
1042
- return;
1043
-
1044
- BUG_ON(rt_mutex_owner(lock) == self);
1045
-
1046
- /*
1047
- * We save whatever state the task is in and we'll restore it
1048
- * after acquiring the lock taking real wakeups into account
1049
- * as well. We are serialized via pi_lock against wakeups. See
1050
- * try_to_wake_up().
1051
- */
1052
- raw_spin_lock(&self->pi_lock);
1053
- self->saved_state = self->state;
1054
- __set_current_state_no_track(TASK_UNINTERRUPTIBLE);
1055
- raw_spin_unlock(&self->pi_lock);
1056
-
1057
- ret = task_blocks_on_rt_mutex(lock, waiter, self, RT_MUTEX_MIN_CHAINWALK);
1058
- BUG_ON(ret);
1059
-
1060
- for (;;) {
1061
- /* Try to acquire the lock again. */
1062
- if (__try_to_take_rt_mutex(lock, self, waiter, STEAL_LATERAL))
1063
- break;
1064
-
1065
- top_waiter = rt_mutex_top_waiter(lock);
1066
- lock_owner = rt_mutex_owner(lock);
1067
-
1068
- raw_spin_unlock_irqrestore(&lock->wait_lock, flags);
1069
-
1070
- if (top_waiter != waiter || adaptive_wait(lock, lock_owner))
1071
- preempt_schedule_lock();
1072
-
1073
- raw_spin_lock_irqsave(&lock->wait_lock, flags);
1074
-
1075
- raw_spin_lock(&self->pi_lock);
1076
- __set_current_state_no_track(TASK_UNINTERRUPTIBLE);
1077
- raw_spin_unlock(&self->pi_lock);
1078
- }
1079
-
1080
- /*
1081
- * Restore the task state to current->saved_state. We set it
1082
- * to the original state above and the try_to_wake_up() code
1083
- * has possibly updated it when a real (non-rtmutex) wakeup
1084
- * happened while we were blocked. Clear saved_state so
1085
- * try_to_wakeup() does not get confused.
1086
- */
1087
- raw_spin_lock(&self->pi_lock);
1088
- __set_current_state_no_track(self->saved_state);
1089
- self->saved_state = TASK_RUNNING;
1090
- raw_spin_unlock(&self->pi_lock);
1091
-
1092
- /*
1093
- * try_to_take_rt_mutex() sets the waiter bit
1094
- * unconditionally. We might have to fix that up:
1095
- */
1096
- fixup_rt_mutex_waiters(lock);
1097
-
1098
- BUG_ON(rt_mutex_has_waiters(lock) && waiter == rt_mutex_top_waiter(lock));
1099
- BUG_ON(!RB_EMPTY_NODE(&waiter->tree_entry));
1100
-}
1101
-
1102
-static void noinline __sched rt_spin_lock_slowlock(struct rt_mutex *lock)
1103
-{
1104
- struct rt_mutex_waiter waiter;
1105
- unsigned long flags;
1106
-
1107
- rt_mutex_init_waiter(&waiter, true);
1108
-
1109
- raw_spin_lock_irqsave(&lock->wait_lock, flags);
1110
- rt_spin_lock_slowlock_locked(lock, &waiter, flags);
1111
- raw_spin_unlock_irqrestore(&lock->wait_lock, flags);
1112
- debug_rt_mutex_free_waiter(&waiter);
1113
-}
1114
-
1115
-static bool __sched __rt_mutex_unlock_common(struct rt_mutex *lock,
1116
- struct wake_q_head *wake_q,
1117
- struct wake_q_head *wq_sleeper);
1118
-/*
1119
- * Slow path to release a rt_mutex spin_lock style
1120
- */
1121
-void __sched rt_spin_lock_slowunlock(struct rt_mutex *lock)
1122
-{
1123
- unsigned long flags;
1124
- DEFINE_WAKE_Q(wake_q);
1125
- DEFINE_WAKE_Q(wake_sleeper_q);
1126
- bool postunlock;
1127
-
1128
- raw_spin_lock_irqsave(&lock->wait_lock, flags);
1129
- postunlock = __rt_mutex_unlock_common(lock, &wake_q, &wake_sleeper_q);
1130
- raw_spin_unlock_irqrestore(&lock->wait_lock, flags);
1131
-
1132
- if (postunlock)
1133
- rt_mutex_postunlock(&wake_q, &wake_sleeper_q);
1134
-}
1135
-
1136
-void __lockfunc rt_spin_lock(spinlock_t *lock)
1137
-{
1138
- spin_acquire(&lock->dep_map, 0, 0, _RET_IP_);
1139
- rt_spin_lock_fastlock(&lock->lock, rt_spin_lock_slowlock);
1140
- rcu_read_lock();
1141
- migrate_disable();
1142
-}
1143
-EXPORT_SYMBOL(rt_spin_lock);
1144
-
1145
-void __lockfunc __rt_spin_lock(struct rt_mutex *lock)
1146
-{
1147
- rt_spin_lock_fastlock(lock, rt_spin_lock_slowlock);
1148
-}
1149
-
1150
-#ifdef CONFIG_DEBUG_LOCK_ALLOC
1151
-void __lockfunc rt_spin_lock_nested(spinlock_t *lock, int subclass)
1152
-{
1153
- spin_acquire(&lock->dep_map, subclass, 0, _RET_IP_);
1154
- rt_spin_lock_fastlock(&lock->lock, rt_spin_lock_slowlock);
1155
- rcu_read_lock();
1156
- migrate_disable();
1157
-}
1158
-EXPORT_SYMBOL(rt_spin_lock_nested);
1159
-
1160
-void __lockfunc rt_spin_lock_nest_lock(spinlock_t *lock,
1161
- struct lockdep_map *nest_lock)
1162
-{
1163
- spin_acquire_nest(&lock->dep_map, 0, 0, nest_lock, _RET_IP_);
1164
- rt_spin_lock_fastlock(&lock->lock, rt_spin_lock_slowlock);
1165
- rcu_read_lock();
1166
- migrate_disable();
1167
-}
1168
-EXPORT_SYMBOL(rt_spin_lock_nest_lock);
1169
-#endif
1170
-
1171
-void __lockfunc rt_spin_unlock(spinlock_t *lock)
1172
-{
1173
- /* NOTE: we always pass in '1' for nested, for simplicity */
1174
- spin_release(&lock->dep_map, _RET_IP_);
1175
- migrate_enable();
1176
- rcu_read_unlock();
1177
- rt_spin_lock_fastunlock(&lock->lock, rt_spin_lock_slowunlock);
1178
-}
1179
-EXPORT_SYMBOL(rt_spin_unlock);
1180
-
1181
-void __lockfunc __rt_spin_unlock(struct rt_mutex *lock)
1182
-{
1183
- rt_spin_lock_fastunlock(lock, rt_spin_lock_slowunlock);
1184
-}
1185
-EXPORT_SYMBOL(__rt_spin_unlock);
1186
-
1187
-/*
1188
- * Wait for the lock to get unlocked: instead of polling for an unlock
1189
- * (like raw spinlocks do), we lock and unlock, to force the kernel to
1190
- * schedule if there's contention:
1191
- */
1192
-void __lockfunc rt_spin_lock_unlock(spinlock_t *lock)
1193
-{
1194
- spin_lock(lock);
1195
- spin_unlock(lock);
1196
-}
1197
-EXPORT_SYMBOL(rt_spin_lock_unlock);
1198
-
1199
-int __lockfunc rt_spin_trylock(spinlock_t *lock)
1200
-{
1201
- int ret;
1202
-
1203
- ret = __rt_mutex_trylock(&lock->lock);
1204
- if (ret) {
1205
- spin_acquire(&lock->dep_map, 0, 1, _RET_IP_);
1206
- rcu_read_lock();
1207
- migrate_disable();
1208
- }
1209
- return ret;
1210
-}
1211
-EXPORT_SYMBOL(rt_spin_trylock);
1212
-
1213
-int __lockfunc rt_spin_trylock_bh(spinlock_t *lock)
1214
-{
1215
- int ret;
1216
-
1217
- local_bh_disable();
1218
- ret = __rt_mutex_trylock(&lock->lock);
1219
- if (ret) {
1220
- spin_acquire(&lock->dep_map, 0, 1, _RET_IP_);
1221
- rcu_read_lock();
1222
- migrate_disable();
1223
- } else {
1224
- local_bh_enable();
1225
- }
1226
- return ret;
1227
-}
1228
-EXPORT_SYMBOL(rt_spin_trylock_bh);
1229
-
1230
-void
1231
-__rt_spin_lock_init(spinlock_t *lock, const char *name, struct lock_class_key *key)
1232
-{
1233
-#ifdef CONFIG_DEBUG_LOCK_ALLOC
1234
- /*
1235
- * Make sure we are not reinitializing a held lock:
1236
- */
1237
- debug_check_no_locks_freed((void *)lock, sizeof(*lock));
1238
- lockdep_init_map(&lock->dep_map, name, key, 0);
1239
-#endif
1240
-}
1241
-EXPORT_SYMBOL(__rt_spin_lock_init);
1242
-
1243
-#endif /* PREEMPT_RT */
1244
-
1245
-#ifdef CONFIG_PREEMPT_RT
1246
- static inline int __sched
1247
-__mutex_lock_check_stamp(struct rt_mutex *lock, struct ww_acquire_ctx *ctx)
1248
-{
1249
- struct ww_mutex *ww = container_of(lock, struct ww_mutex, base.lock);
1250
- struct ww_acquire_ctx *hold_ctx = READ_ONCE(ww->ctx);
1251
-
1252
- if (!hold_ctx)
1253
- return 0;
1254
-
1255
- if (unlikely(ctx == hold_ctx))
1256
- return -EALREADY;
1257
-
1258
- if (ctx->stamp - hold_ctx->stamp <= LONG_MAX &&
1259
- (ctx->stamp != hold_ctx->stamp || ctx > hold_ctx)) {
1260
-#ifdef CONFIG_DEBUG_MUTEXES
1261
- DEBUG_LOCKS_WARN_ON(ctx->contending_lock);
1262
- ctx->contending_lock = ww;
1263
-#endif
1264
- return -EDEADLK;
1265
- }
1266
-
1267
- return 0;
1268
-}
1269
-#else
1270
- static inline int __sched
1271
-__mutex_lock_check_stamp(struct rt_mutex *lock, struct ww_acquire_ctx *ctx)
1272
-{
1273
- BUG();
1274
- return 0;
1275
-}
1276
-
1277
-#endif
1278
-
1279
-static inline int
1280
-try_to_take_rt_mutex(struct rt_mutex *lock, struct task_struct *task,
1281
- struct rt_mutex_waiter *waiter)
1282
-{
1283
- return __try_to_take_rt_mutex(lock, task, waiter, STEAL_NORMAL);
1284
-}
1285
-
1286920 /*
1287921 * Task blocks on lock.
1288922 *
....@@ -1315,22 +949,6 @@
1315949 return -EDEADLK;
1316950
1317951 raw_spin_lock(&task->pi_lock);
1318
- /*
1319
- * In the case of futex requeue PI, this will be a proxy
1320
- * lock. The task will wake unaware that it is enqueueed on
1321
- * this lock. Avoid blocking on two locks and corrupting
1322
- * pi_blocked_on via the PI_WAKEUP_INPROGRESS
1323
- * flag. futex_wait_requeue_pi() sets this when it wakes up
1324
- * before requeue (due to a signal or timeout). Do not enqueue
1325
- * the task if PI_WAKEUP_INPROGRESS is set.
1326
- */
1327
- if (task != current && task->pi_blocked_on == PI_WAKEUP_INPROGRESS) {
1328
- raw_spin_unlock(&task->pi_lock);
1329
- return -EAGAIN;
1330
- }
1331
-
1332
- BUG_ON(rt_mutex_real_waiter(task->pi_blocked_on));
1333
-
1334952 waiter->task = task;
1335953 waiter->lock = lock;
1336954 waiter->prio = task->prio;
....@@ -1354,7 +972,7 @@
1354972 rt_mutex_enqueue_pi(owner, waiter);
1355973
1356974 rt_mutex_adjust_prio(owner);
1357
- if (rt_mutex_real_waiter(owner->pi_blocked_on))
975
+ if (owner->pi_blocked_on)
1358976 chain_walk = 1;
1359977 } else if (rt_mutex_cond_detect_deadlock(waiter, chwalk)) {
1360978 chain_walk = 1;
....@@ -1396,7 +1014,6 @@
13961014 * Called with lock->wait_lock held and interrupts disabled.
13971015 */
13981016 static void mark_wakeup_next_waiter(struct wake_q_head *wake_q,
1399
- struct wake_q_head *wake_sleeper_q,
14001017 struct rt_mutex *lock)
14011018 {
14021019 struct rt_mutex_waiter *waiter;
....@@ -1436,10 +1053,7 @@
14361053 * Pairs with preempt_enable() in rt_mutex_postunlock();
14371054 */
14381055 preempt_disable();
1439
- if (waiter->savestate)
1440
- wake_q_add_sleeper(wake_sleeper_q, waiter->task);
1441
- else
1442
- wake_q_add(wake_q, waiter->task);
1056
+ wake_q_add(wake_q, waiter->task);
14431057 raw_spin_unlock(&current->pi_lock);
14441058 }
14451059
....@@ -1454,7 +1068,7 @@
14541068 {
14551069 bool is_top_waiter = (waiter == rt_mutex_top_waiter(lock));
14561070 struct task_struct *owner = rt_mutex_owner(lock);
1457
- struct rt_mutex *next_lock = NULL;
1071
+ struct rt_mutex *next_lock;
14581072
14591073 lockdep_assert_held(&lock->wait_lock);
14601074
....@@ -1480,8 +1094,7 @@
14801094 rt_mutex_adjust_prio(owner);
14811095
14821096 /* Store the lock on which owner is blocked or NULL */
1483
- if (rt_mutex_real_waiter(owner->pi_blocked_on))
1484
- next_lock = task_blocked_on_lock(owner);
1097
+ next_lock = task_blocked_on_lock(owner);
14851098
14861099 raw_spin_unlock(&owner->pi_lock);
14871100
....@@ -1517,28 +1130,26 @@
15171130 raw_spin_lock_irqsave(&task->pi_lock, flags);
15181131
15191132 waiter = task->pi_blocked_on;
1520
- if (!rt_mutex_real_waiter(waiter) ||
1521
- rt_mutex_waiter_equal(waiter, task_to_waiter(task))) {
1133
+ if (!waiter || rt_mutex_waiter_equal(waiter, task_to_waiter(task))) {
15221134 raw_spin_unlock_irqrestore(&task->pi_lock, flags);
15231135 return;
15241136 }
15251137 next_lock = waiter->lock;
1138
+ raw_spin_unlock_irqrestore(&task->pi_lock, flags);
15261139
15271140 /* gets dropped in rt_mutex_adjust_prio_chain()! */
15281141 get_task_struct(task);
15291142
1530
- raw_spin_unlock_irqrestore(&task->pi_lock, flags);
15311143 rt_mutex_adjust_prio_chain(task, RT_MUTEX_MIN_CHAINWALK, NULL,
15321144 next_lock, NULL, task);
15331145 }
15341146
1535
-void rt_mutex_init_waiter(struct rt_mutex_waiter *waiter, bool savestate)
1147
+void rt_mutex_init_waiter(struct rt_mutex_waiter *waiter)
15361148 {
15371149 debug_rt_mutex_init_waiter(waiter);
15381150 RB_CLEAR_NODE(&waiter->pi_tree_entry);
15391151 RB_CLEAR_NODE(&waiter->tree_entry);
15401152 waiter->task = NULL;
1541
- waiter->savestate = savestate;
15421153 }
15431154
15441155 /**
....@@ -1554,8 +1165,7 @@
15541165 static int __sched
15551166 __rt_mutex_slowlock(struct rt_mutex *lock, int state,
15561167 struct hrtimer_sleeper *timeout,
1557
- struct rt_mutex_waiter *waiter,
1558
- struct ww_acquire_ctx *ww_ctx)
1168
+ struct rt_mutex_waiter *waiter)
15591169 {
15601170 int ret = 0;
15611171
....@@ -1565,22 +1175,23 @@
15651175 if (try_to_take_rt_mutex(lock, current, waiter))
15661176 break;
15671177
1568
- if (timeout && !timeout->task) {
1569
- ret = -ETIMEDOUT;
1570
- break;
1571
- }
1572
- if (signal_pending_state(state, current)) {
1573
- ret = -EINTR;
1574
- break;
1575
- }
1576
-
1577
- if (ww_ctx && ww_ctx->acquired > 0) {
1578
- ret = __mutex_lock_check_stamp(lock, ww_ctx);
1178
+ /*
1179
+ * TASK_INTERRUPTIBLE checks for signals and
1180
+ * timeout. Ignored otherwise.
1181
+ */
1182
+ if (likely(state == TASK_INTERRUPTIBLE)) {
1183
+ /* Signal pending? */
1184
+ if (signal_pending(current))
1185
+ ret = -EINTR;
1186
+ if (timeout && !timeout->task)
1187
+ ret = -ETIMEDOUT;
15791188 if (ret)
15801189 break;
15811190 }
15821191
15831192 raw_spin_unlock_irq(&lock->wait_lock);
1193
+
1194
+ debug_rt_mutex_print_deadlock(waiter);
15841195
15851196 schedule();
15861197
....@@ -1603,147 +1214,14 @@
16031214 if (res != -EDEADLOCK || detect_deadlock)
16041215 return;
16051216
1217
+ /*
1218
+ * Yell lowdly and stop the task right here.
1219
+ */
1220
+ rt_mutex_print_deadlock(w);
16061221 while (1) {
16071222 set_current_state(TASK_INTERRUPTIBLE);
16081223 schedule();
16091224 }
1610
-}
1611
-
1612
-static __always_inline void ww_mutex_lock_acquired(struct ww_mutex *ww,
1613
- struct ww_acquire_ctx *ww_ctx)
1614
-{
1615
-#ifdef CONFIG_DEBUG_MUTEXES
1616
- /*
1617
- * If this WARN_ON triggers, you used ww_mutex_lock to acquire,
1618
- * but released with a normal mutex_unlock in this call.
1619
- *
1620
- * This should never happen, always use ww_mutex_unlock.
1621
- */
1622
- DEBUG_LOCKS_WARN_ON(ww->ctx);
1623
-
1624
- /*
1625
- * Not quite done after calling ww_acquire_done() ?
1626
- */
1627
- DEBUG_LOCKS_WARN_ON(ww_ctx->done_acquire);
1628
-
1629
- if (ww_ctx->contending_lock) {
1630
- /*
1631
- * After -EDEADLK you tried to
1632
- * acquire a different ww_mutex? Bad!
1633
- */
1634
- DEBUG_LOCKS_WARN_ON(ww_ctx->contending_lock != ww);
1635
-
1636
- /*
1637
- * You called ww_mutex_lock after receiving -EDEADLK,
1638
- * but 'forgot' to unlock everything else first?
1639
- */
1640
- DEBUG_LOCKS_WARN_ON(ww_ctx->acquired > 0);
1641
- ww_ctx->contending_lock = NULL;
1642
- }
1643
-
1644
- /*
1645
- * Naughty, using a different class will lead to undefined behavior!
1646
- */
1647
- DEBUG_LOCKS_WARN_ON(ww_ctx->ww_class != ww->ww_class);
1648
-#endif
1649
- ww_ctx->acquired++;
1650
-}
1651
-
1652
-#ifdef CONFIG_PREEMPT_RT
1653
-static void ww_mutex_account_lock(struct rt_mutex *lock,
1654
- struct ww_acquire_ctx *ww_ctx)
1655
-{
1656
- struct ww_mutex *ww = container_of(lock, struct ww_mutex, base.lock);
1657
- struct rt_mutex_waiter *waiter, *n;
1658
-
1659
- /*
1660
- * This branch gets optimized out for the common case,
1661
- * and is only important for ww_mutex_lock.
1662
- */
1663
- ww_mutex_lock_acquired(ww, ww_ctx);
1664
- ww->ctx = ww_ctx;
1665
-
1666
- /*
1667
- * Give any possible sleeping processes the chance to wake up,
1668
- * so they can recheck if they have to back off.
1669
- */
1670
- rbtree_postorder_for_each_entry_safe(waiter, n, &lock->waiters.rb_root,
1671
- tree_entry) {
1672
- /* XXX debug rt mutex waiter wakeup */
1673
-
1674
- BUG_ON(waiter->lock != lock);
1675
- rt_mutex_wake_waiter(waiter);
1676
- }
1677
-}
1678
-
1679
-#else
1680
-
1681
-static void ww_mutex_account_lock(struct rt_mutex *lock,
1682
- struct ww_acquire_ctx *ww_ctx)
1683
-{
1684
- BUG();
1685
-}
1686
-#endif
1687
-
1688
-int __sched rt_mutex_slowlock_locked(struct rt_mutex *lock, int state,
1689
- struct hrtimer_sleeper *timeout,
1690
- enum rtmutex_chainwalk chwalk,
1691
- struct ww_acquire_ctx *ww_ctx,
1692
- struct rt_mutex_waiter *waiter)
1693
-{
1694
- int ret;
1695
-
1696
-#ifdef CONFIG_PREEMPT_RT
1697
- if (ww_ctx) {
1698
- struct ww_mutex *ww;
1699
-
1700
- ww = container_of(lock, struct ww_mutex, base.lock);
1701
- if (unlikely(ww_ctx == READ_ONCE(ww->ctx)))
1702
- return -EALREADY;
1703
- }
1704
-#endif
1705
-
1706
- /* Try to acquire the lock again: */
1707
- if (try_to_take_rt_mutex(lock, current, NULL)) {
1708
- if (ww_ctx)
1709
- ww_mutex_account_lock(lock, ww_ctx);
1710
- return 0;
1711
- }
1712
-
1713
- set_current_state(state);
1714
-
1715
- /* Setup the timer, when timeout != NULL */
1716
- if (unlikely(timeout))
1717
- hrtimer_start_expires(&timeout->timer, HRTIMER_MODE_ABS);
1718
-
1719
- ret = task_blocks_on_rt_mutex(lock, waiter, current, chwalk);
1720
-
1721
- if (likely(!ret)) {
1722
- /* sleep on the mutex */
1723
- ret = __rt_mutex_slowlock(lock, state, timeout, waiter,
1724
- ww_ctx);
1725
- } else if (ww_ctx) {
1726
- /* ww_mutex received EDEADLK, let it become EALREADY */
1727
- ret = __mutex_lock_check_stamp(lock, ww_ctx);
1728
- BUG_ON(!ret);
1729
- }
1730
-
1731
- if (unlikely(ret)) {
1732
- __set_current_state(TASK_RUNNING);
1733
- remove_waiter(lock, waiter);
1734
- /* ww_mutex wants to report EDEADLK/EALREADY, let it */
1735
- if (!ww_ctx)
1736
- rt_mutex_handle_deadlock(ret, chwalk, waiter);
1737
- } else if (ww_ctx) {
1738
- ww_mutex_account_lock(lock, ww_ctx);
1739
- }
1740
-
1741
- /*
1742
- * try_to_take_rt_mutex() sets the waiter bit
1743
- * unconditionally. We might have to fix that up.
1744
- */
1745
- fixup_rt_mutex_waiters(lock);
1746
- return ret;
17471225 }
17481226
17491227 /*
....@@ -1752,14 +1230,13 @@
17521230 static int __sched
17531231 rt_mutex_slowlock(struct rt_mutex *lock, int state,
17541232 struct hrtimer_sleeper *timeout,
1755
- enum rtmutex_chainwalk chwalk,
1756
- struct ww_acquire_ctx *ww_ctx)
1233
+ enum rtmutex_chainwalk chwalk)
17571234 {
17581235 struct rt_mutex_waiter waiter;
17591236 unsigned long flags;
17601237 int ret = 0;
17611238
1762
- rt_mutex_init_waiter(&waiter, false);
1239
+ rt_mutex_init_waiter(&waiter);
17631240
17641241 /*
17651242 * Technically we could use raw_spin_[un]lock_irq() here, but this can
....@@ -1771,8 +1248,35 @@
17711248 */
17721249 raw_spin_lock_irqsave(&lock->wait_lock, flags);
17731250
1774
- ret = rt_mutex_slowlock_locked(lock, state, timeout, chwalk, ww_ctx,
1775
- &waiter);
1251
+ /* Try to acquire the lock again: */
1252
+ if (try_to_take_rt_mutex(lock, current, NULL)) {
1253
+ raw_spin_unlock_irqrestore(&lock->wait_lock, flags);
1254
+ return 0;
1255
+ }
1256
+
1257
+ set_current_state(state);
1258
+
1259
+ /* Setup the timer, when timeout != NULL */
1260
+ if (unlikely(timeout))
1261
+ hrtimer_start_expires(&timeout->timer, HRTIMER_MODE_ABS);
1262
+
1263
+ ret = task_blocks_on_rt_mutex(lock, &waiter, current, chwalk);
1264
+
1265
+ if (likely(!ret))
1266
+ /* sleep on the mutex */
1267
+ ret = __rt_mutex_slowlock(lock, state, timeout, &waiter);
1268
+
1269
+ if (unlikely(ret)) {
1270
+ __set_current_state(TASK_RUNNING);
1271
+ remove_waiter(lock, &waiter);
1272
+ rt_mutex_handle_deadlock(ret, chwalk, &waiter);
1273
+ }
1274
+
1275
+ /*
1276
+ * try_to_take_rt_mutex() sets the waiter bit
1277
+ * unconditionally. We might have to fix that up.
1278
+ */
1279
+ fixup_rt_mutex_waiters(lock);
17761280
17771281 raw_spin_unlock_irqrestore(&lock->wait_lock, flags);
17781282
....@@ -1833,8 +1337,7 @@
18331337 * Return whether the current task needs to call rt_mutex_postunlock().
18341338 */
18351339 static bool __sched rt_mutex_slowunlock(struct rt_mutex *lock,
1836
- struct wake_q_head *wake_q,
1837
- struct wake_q_head *wake_sleeper_q)
1340
+ struct wake_q_head *wake_q)
18381341 {
18391342 unsigned long flags;
18401343
....@@ -1888,7 +1391,7 @@
18881391 *
18891392 * Queue the next waiter for wakeup once we release the wait_lock.
18901393 */
1891
- mark_wakeup_next_waiter(wake_q, wake_sleeper_q, lock);
1394
+ mark_wakeup_next_waiter(wake_q, lock);
18921395 raw_spin_unlock_irqrestore(&lock->wait_lock, flags);
18931396
18941397 return true; /* call rt_mutex_postunlock() */
....@@ -1902,16 +1405,29 @@
19021405 */
19031406 static inline int
19041407 rt_mutex_fastlock(struct rt_mutex *lock, int state,
1905
- struct ww_acquire_ctx *ww_ctx,
19061408 int (*slowfn)(struct rt_mutex *lock, int state,
19071409 struct hrtimer_sleeper *timeout,
1908
- enum rtmutex_chainwalk chwalk,
1909
- struct ww_acquire_ctx *ww_ctx))
1410
+ enum rtmutex_chainwalk chwalk))
19101411 {
19111412 if (likely(rt_mutex_cmpxchg_acquire(lock, NULL, current)))
19121413 return 0;
19131414
1914
- return slowfn(lock, state, NULL, RT_MUTEX_MIN_CHAINWALK, ww_ctx);
1415
+ return slowfn(lock, state, NULL, RT_MUTEX_MIN_CHAINWALK);
1416
+}
1417
+
1418
+static inline int
1419
+rt_mutex_timed_fastlock(struct rt_mutex *lock, int state,
1420
+ struct hrtimer_sleeper *timeout,
1421
+ enum rtmutex_chainwalk chwalk,
1422
+ int (*slowfn)(struct rt_mutex *lock, int state,
1423
+ struct hrtimer_sleeper *timeout,
1424
+ enum rtmutex_chainwalk chwalk))
1425
+{
1426
+ if (chwalk == RT_MUTEX_MIN_CHAINWALK &&
1427
+ likely(rt_mutex_cmpxchg_acquire(lock, NULL, current)))
1428
+ return 0;
1429
+
1430
+ return slowfn(lock, state, timeout, chwalk);
19151431 }
19161432
19171433 static inline int
....@@ -1927,11 +1443,9 @@
19271443 /*
19281444 * Performs the wakeup of the top-waiter and re-enables preemption.
19291445 */
1930
-void rt_mutex_postunlock(struct wake_q_head *wake_q,
1931
- struct wake_q_head *wake_sleeper_q)
1446
+void rt_mutex_postunlock(struct wake_q_head *wake_q)
19321447 {
19331448 wake_up_q(wake_q);
1934
- wake_up_q_sleeper(wake_sleeper_q);
19351449
19361450 /* Pairs with preempt_disable() in rt_mutex_slowunlock() */
19371451 preempt_enable();
....@@ -1940,48 +1454,24 @@
19401454 static inline void
19411455 rt_mutex_fastunlock(struct rt_mutex *lock,
19421456 bool (*slowfn)(struct rt_mutex *lock,
1943
- struct wake_q_head *wqh,
1944
- struct wake_q_head *wq_sleeper))
1457
+ struct wake_q_head *wqh))
19451458 {
19461459 DEFINE_WAKE_Q(wake_q);
1947
- DEFINE_WAKE_Q(wake_sleeper_q);
19481460
19491461 if (likely(rt_mutex_cmpxchg_release(lock, current, NULL)))
19501462 return;
19511463
1952
- if (slowfn(lock, &wake_q, &wake_sleeper_q))
1953
- rt_mutex_postunlock(&wake_q, &wake_sleeper_q);
1954
-}
1955
-
1956
-int __sched __rt_mutex_lock_state(struct rt_mutex *lock, int state)
1957
-{
1958
- might_sleep();
1959
- return rt_mutex_fastlock(lock, state, NULL, rt_mutex_slowlock);
1960
-}
1961
-
1962
-/**
1963
- * rt_mutex_lock_state - lock a rt_mutex with a given state
1964
- *
1965
- * @lock: The rt_mutex to be locked
1966
- * @state: The state to set when blocking on the rt_mutex
1967
- */
1968
-static inline int __sched rt_mutex_lock_state(struct rt_mutex *lock,
1969
- unsigned int subclass, int state)
1970
-{
1971
- int ret;
1972
-
1973
- mutex_acquire(&lock->dep_map, subclass, 0, _RET_IP_);
1974
- ret = __rt_mutex_lock_state(lock, state);
1975
- if (ret)
1976
- mutex_release(&lock->dep_map, _RET_IP_);
1977
- trace_android_vh_record_rtmutex_lock_starttime(current, jiffies);
1978
-
1979
- return ret;
1464
+ if (slowfn(lock, &wake_q))
1465
+ rt_mutex_postunlock(&wake_q);
19801466 }
19811467
19821468 static inline void __rt_mutex_lock(struct rt_mutex *lock, unsigned int subclass)
19831469 {
1984
- rt_mutex_lock_state(lock, subclass, TASK_UNINTERRUPTIBLE);
1470
+ might_sleep();
1471
+
1472
+ mutex_acquire(&lock->dep_map, subclass, 0, _RET_IP_);
1473
+ rt_mutex_fastlock(lock, TASK_UNINTERRUPTIBLE, rt_mutex_slowlock);
1474
+ trace_android_vh_record_rtmutex_lock_starttime(current, jiffies);
19851475 }
19861476
19871477 #ifdef CONFIG_DEBUG_LOCK_ALLOC
....@@ -2022,7 +1512,18 @@
20221512 */
20231513 int __sched rt_mutex_lock_interruptible(struct rt_mutex *lock)
20241514 {
2025
- return rt_mutex_lock_state(lock, 0, TASK_INTERRUPTIBLE);
1515
+ int ret;
1516
+
1517
+ might_sleep();
1518
+
1519
+ mutex_acquire(&lock->dep_map, 0, 0, _RET_IP_);
1520
+ ret = rt_mutex_fastlock(lock, TASK_INTERRUPTIBLE, rt_mutex_slowlock);
1521
+ if (ret)
1522
+ mutex_release(&lock->dep_map, _RET_IP_);
1523
+ else
1524
+ trace_android_vh_record_rtmutex_lock_starttime(current, jiffies);
1525
+
1526
+ return ret;
20261527 }
20271528 EXPORT_SYMBOL_GPL(rt_mutex_lock_interruptible);
20281529
....@@ -2039,17 +1540,38 @@
20391540 return __rt_mutex_slowtrylock(lock);
20401541 }
20411542
2042
-int __sched __rt_mutex_trylock(struct rt_mutex *lock)
1543
+/**
1544
+ * rt_mutex_timed_lock - lock a rt_mutex interruptible
1545
+ * the timeout structure is provided
1546
+ * by the caller
1547
+ *
1548
+ * @lock: the rt_mutex to be locked
1549
+ * @timeout: timeout structure or NULL (no timeout)
1550
+ *
1551
+ * Returns:
1552
+ * 0 on success
1553
+ * -EINTR when interrupted by a signal
1554
+ * -ETIMEDOUT when the timeout expired
1555
+ */
1556
+int
1557
+rt_mutex_timed_lock(struct rt_mutex *lock, struct hrtimer_sleeper *timeout)
20431558 {
2044
-#ifdef CONFIG_PREEMPT_RT
2045
- if (WARN_ON_ONCE(in_irq() || in_nmi()))
2046
-#else
2047
- if (WARN_ON_ONCE(in_irq() || in_nmi() || in_serving_softirq()))
2048
-#endif
2049
- return 0;
1559
+ int ret;
20501560
2051
- return rt_mutex_fasttrylock(lock, rt_mutex_slowtrylock);
1561
+ might_sleep();
1562
+
1563
+ mutex_acquire(&lock->dep_map, 0, 0, _RET_IP_);
1564
+ ret = rt_mutex_timed_fastlock(lock, TASK_INTERRUPTIBLE, timeout,
1565
+ RT_MUTEX_MIN_CHAINWALK,
1566
+ rt_mutex_slowlock);
1567
+ if (ret)
1568
+ mutex_release(&lock->dep_map, _RET_IP_);
1569
+ else
1570
+ trace_android_vh_record_rtmutex_lock_starttime(current, jiffies);
1571
+
1572
+ return ret;
20521573 }
1574
+EXPORT_SYMBOL_GPL(rt_mutex_timed_lock);
20531575
20541576 /**
20551577 * rt_mutex_trylock - try to lock a rt_mutex
....@@ -2066,7 +1588,10 @@
20661588 {
20671589 int ret;
20681590
2069
- ret = __rt_mutex_trylock(lock);
1591
+ if (WARN_ON_ONCE(in_irq() || in_nmi() || in_serving_softirq()))
1592
+ return 0;
1593
+
1594
+ ret = rt_mutex_fasttrylock(lock, rt_mutex_slowtrylock);
20701595 if (ret)
20711596 mutex_acquire(&lock->dep_map, 0, 1, _RET_IP_);
20721597 else
....@@ -2074,11 +1599,7 @@
20741599
20751600 return ret;
20761601 }
2077
-
2078
-void __sched __rt_mutex_unlock(struct rt_mutex *lock)
2079
-{
2080
- rt_mutex_fastunlock(lock, rt_mutex_slowunlock);
2081
-}
1602
+EXPORT_SYMBOL_GPL(rt_mutex_trylock);
20821603
20831604 /**
20841605 * rt_mutex_unlock - unlock a rt_mutex
....@@ -2088,14 +1609,17 @@
20881609 void __sched rt_mutex_unlock(struct rt_mutex *lock)
20891610 {
20901611 mutex_release(&lock->dep_map, _RET_IP_);
2091
- __rt_mutex_unlock(lock);
1612
+ rt_mutex_fastunlock(lock, rt_mutex_slowunlock);
20921613 trace_android_vh_record_rtmutex_lock_starttime(current, 0);
20931614 }
20941615 EXPORT_SYMBOL_GPL(rt_mutex_unlock);
20951616
2096
-static bool __sched __rt_mutex_unlock_common(struct rt_mutex *lock,
2097
- struct wake_q_head *wake_q,
2098
- struct wake_q_head *wq_sleeper)
1617
+/**
1618
+ * Futex variant, that since futex variants do not use the fast-path, can be
1619
+ * simple and will not need to retry.
1620
+ */
1621
+bool __sched __rt_mutex_futex_unlock(struct rt_mutex *lock,
1622
+ struct wake_q_head *wake_q)
20991623 {
21001624 lockdep_assert_held(&lock->wait_lock);
21011625
....@@ -2112,35 +1636,23 @@
21121636 * avoid inversion prior to the wakeup. preempt_disable()
21131637 * therein pairs with rt_mutex_postunlock().
21141638 */
2115
- mark_wakeup_next_waiter(wake_q, wq_sleeper, lock);
1639
+ mark_wakeup_next_waiter(wake_q, lock);
21161640
21171641 return true; /* call postunlock() */
2118
-}
2119
-
2120
-/**
2121
- * Futex variant, that since futex variants do not use the fast-path, can be
2122
- * simple and will not need to retry.
2123
- */
2124
-bool __sched __rt_mutex_futex_unlock(struct rt_mutex *lock,
2125
- struct wake_q_head *wake_q,
2126
- struct wake_q_head *wq_sleeper)
2127
-{
2128
- return __rt_mutex_unlock_common(lock, wake_q, wq_sleeper);
21291642 }
21301643
21311644 void __sched rt_mutex_futex_unlock(struct rt_mutex *lock)
21321645 {
21331646 DEFINE_WAKE_Q(wake_q);
2134
- DEFINE_WAKE_Q(wake_sleeper_q);
21351647 unsigned long flags;
21361648 bool postunlock;
21371649
21381650 raw_spin_lock_irqsave(&lock->wait_lock, flags);
2139
- postunlock = __rt_mutex_futex_unlock(lock, &wake_q, &wake_sleeper_q);
1651
+ postunlock = __rt_mutex_futex_unlock(lock, &wake_q);
21401652 raw_spin_unlock_irqrestore(&lock->wait_lock, flags);
21411653
21421654 if (postunlock)
2143
- rt_mutex_postunlock(&wake_q, &wake_sleeper_q);
1655
+ rt_mutex_postunlock(&wake_q);
21441656 }
21451657
21461658 /**
....@@ -2154,6 +1666,9 @@
21541666 void rt_mutex_destroy(struct rt_mutex *lock)
21551667 {
21561668 WARN_ON(rt_mutex_is_locked(lock));
1669
+#ifdef CONFIG_DEBUG_RT_MUTEXES
1670
+ lock->magic = NULL;
1671
+#endif
21571672 }
21581673 EXPORT_SYMBOL_GPL(rt_mutex_destroy);
21591674
....@@ -2176,7 +1691,7 @@
21761691 if (name && key)
21771692 debug_rt_mutex_init(lock, name, key);
21781693 }
2179
-EXPORT_SYMBOL(__rt_mutex_init);
1694
+EXPORT_SYMBOL_GPL(__rt_mutex_init);
21801695
21811696 /**
21821697 * rt_mutex_init_proxy_locked - initialize and lock a rt_mutex on behalf of a
....@@ -2196,14 +1711,6 @@
21961711 struct task_struct *proxy_owner)
21971712 {
21981713 __rt_mutex_init(lock, NULL, NULL);
2199
-#ifdef CONFIG_DEBUG_SPINLOCK
2200
- /*
2201
- * get another key class for the wait_lock. LOCK_PI and UNLOCK_PI is
2202
- * holding the ->wait_lock of the proxy_lock while unlocking a sleeping
2203
- * lock.
2204
- */
2205
- raw_spin_lock_init(&lock->wait_lock);
2206
-#endif
22071714 debug_rt_mutex_proxy_lock(lock, proxy_owner);
22081715 rt_mutex_set_owner(lock, proxy_owner);
22091716 }
....@@ -2224,26 +1731,6 @@
22241731 {
22251732 debug_rt_mutex_proxy_unlock(lock);
22261733 rt_mutex_set_owner(lock, NULL);
2227
-}
2228
-
2229
-static void fixup_rt_mutex_blocked(struct rt_mutex *lock)
2230
-{
2231
- struct task_struct *tsk = current;
2232
- /*
2233
- * RT has a problem here when the wait got interrupted by a timeout
2234
- * or a signal. task->pi_blocked_on is still set. The task must
2235
- * acquire the hash bucket lock when returning from this function.
2236
- *
2237
- * If the hash bucket lock is contended then the
2238
- * BUG_ON(rt_mutex_real_waiter(task->pi_blocked_on)) in
2239
- * task_blocks_on_rt_mutex() will trigger. This can be avoided by
2240
- * clearing task->pi_blocked_on which removes the task from the
2241
- * boosting chain of the rtmutex. That's correct because the task
2242
- * is not longer blocked on it.
2243
- */
2244
- raw_spin_lock(&tsk->pi_lock);
2245
- tsk->pi_blocked_on = NULL;
2246
- raw_spin_unlock(&tsk->pi_lock);
22471734 }
22481735
22491736 /**
....@@ -2276,34 +1763,6 @@
22761763 if (try_to_take_rt_mutex(lock, task, NULL))
22771764 return 1;
22781765
2279
-#ifdef CONFIG_PREEMPT_RT
2280
- /*
2281
- * In PREEMPT_RT there's an added race.
2282
- * If the task, that we are about to requeue, times out,
2283
- * it can set the PI_WAKEUP_INPROGRESS. This tells the requeue
2284
- * to skip this task. But right after the task sets
2285
- * its pi_blocked_on to PI_WAKEUP_INPROGRESS it can then
2286
- * block on the spin_lock(&hb->lock), which in RT is an rtmutex.
2287
- * This will replace the PI_WAKEUP_INPROGRESS with the actual
2288
- * lock that it blocks on. We *must not* place this task
2289
- * on this proxy lock in that case.
2290
- *
2291
- * To prevent this race, we first take the task's pi_lock
2292
- * and check if it has updated its pi_blocked_on. If it has,
2293
- * we assume that it woke up and we return -EAGAIN.
2294
- * Otherwise, we set the task's pi_blocked_on to
2295
- * PI_REQUEUE_INPROGRESS, so that if the task is waking up
2296
- * it will know that we are in the process of requeuing it.
2297
- */
2298
- raw_spin_lock(&task->pi_lock);
2299
- if (task->pi_blocked_on) {
2300
- raw_spin_unlock(&task->pi_lock);
2301
- return -EAGAIN;
2302
- }
2303
- task->pi_blocked_on = PI_REQUEUE_INPROGRESS;
2304
- raw_spin_unlock(&task->pi_lock);
2305
-#endif
2306
-
23071766 /* We enforce deadlock detection for futexes */
23081767 ret = task_blocks_on_rt_mutex(lock, waiter, task,
23091768 RT_MUTEX_FULL_CHAINWALK);
....@@ -2318,8 +1777,7 @@
23181777 ret = 0;
23191778 }
23201779
2321
- if (ret)
2322
- fixup_rt_mutex_blocked(lock);
1780
+ debug_rt_mutex_print_deadlock(waiter);
23231781
23241782 return ret;
23251783 }
....@@ -2404,15 +1862,12 @@
24041862 raw_spin_lock_irq(&lock->wait_lock);
24051863 /* sleep on the mutex */
24061864 set_current_state(TASK_INTERRUPTIBLE);
2407
- ret = __rt_mutex_slowlock(lock, TASK_INTERRUPTIBLE, to, waiter, NULL);
1865
+ ret = __rt_mutex_slowlock(lock, TASK_INTERRUPTIBLE, to, waiter);
24081866 /*
24091867 * try_to_take_rt_mutex() sets the waiter bit unconditionally. We might
24101868 * have to fix that up.
24111869 */
24121870 fixup_rt_mutex_waiters(lock);
2413
- if (ret)
2414
- fixup_rt_mutex_blocked(lock);
2415
-
24161871 raw_spin_unlock_irq(&lock->wait_lock);
24171872
24181873 return ret;
....@@ -2474,97 +1929,3 @@
24741929
24751930 return cleanup;
24761931 }
2477
-
2478
-static inline int
2479
-ww_mutex_deadlock_injection(struct ww_mutex *lock, struct ww_acquire_ctx *ctx)
2480
-{
2481
-#ifdef CONFIG_DEBUG_WW_MUTEX_SLOWPATH
2482
- unsigned int tmp;
2483
-
2484
- if (ctx->deadlock_inject_countdown-- == 0) {
2485
- tmp = ctx->deadlock_inject_interval;
2486
- if (tmp > UINT_MAX/4)
2487
- tmp = UINT_MAX;
2488
- else
2489
- tmp = tmp*2 + tmp + tmp/2;
2490
-
2491
- ctx->deadlock_inject_interval = tmp;
2492
- ctx->deadlock_inject_countdown = tmp;
2493
- ctx->contending_lock = lock;
2494
-
2495
- ww_mutex_unlock(lock);
2496
-
2497
- return -EDEADLK;
2498
- }
2499
-#endif
2500
-
2501
- return 0;
2502
-}
2503
-
2504
-#ifdef CONFIG_PREEMPT_RT
2505
-int __sched
2506
-ww_mutex_lock_interruptible(struct ww_mutex *lock, struct ww_acquire_ctx *ctx)
2507
-{
2508
- int ret;
2509
-
2510
- might_sleep();
2511
-
2512
- mutex_acquire_nest(&lock->base.dep_map, 0, 0,
2513
- ctx ? &ctx->dep_map : NULL, _RET_IP_);
2514
- ret = rt_mutex_slowlock(&lock->base.lock, TASK_INTERRUPTIBLE, NULL, 0,
2515
- ctx);
2516
- if (ret)
2517
- mutex_release(&lock->base.dep_map, _RET_IP_);
2518
- else if (!ret && ctx && ctx->acquired > 1)
2519
- return ww_mutex_deadlock_injection(lock, ctx);
2520
-
2521
- return ret;
2522
-}
2523
-EXPORT_SYMBOL(ww_mutex_lock_interruptible);
2524
-
2525
-int __sched
2526
-ww_mutex_lock(struct ww_mutex *lock, struct ww_acquire_ctx *ctx)
2527
-{
2528
- int ret;
2529
-
2530
- might_sleep();
2531
-
2532
- mutex_acquire_nest(&lock->base.dep_map, 0, 0,
2533
- ctx ? &ctx->dep_map : NULL, _RET_IP_);
2534
- ret = rt_mutex_slowlock(&lock->base.lock, TASK_UNINTERRUPTIBLE, NULL, 0,
2535
- ctx);
2536
- if (ret)
2537
- mutex_release(&lock->base.dep_map, _RET_IP_);
2538
- else if (!ret && ctx && ctx->acquired > 1)
2539
- return ww_mutex_deadlock_injection(lock, ctx);
2540
-
2541
- return ret;
2542
-}
2543
-EXPORT_SYMBOL(ww_mutex_lock);
2544
-
2545
-void __sched ww_mutex_unlock(struct ww_mutex *lock)
2546
-{
2547
- /*
2548
- * The unlocking fastpath is the 0->1 transition from 'locked'
2549
- * into 'unlocked' state:
2550
- */
2551
- if (lock->ctx) {
2552
-#ifdef CONFIG_DEBUG_MUTEXES
2553
- DEBUG_LOCKS_WARN_ON(!lock->ctx->acquired);
2554
-#endif
2555
- if (lock->ctx->acquired > 0)
2556
- lock->ctx->acquired--;
2557
- lock->ctx = NULL;
2558
- }
2559
-
2560
- mutex_release(&lock->base.dep_map, _RET_IP_);
2561
- __rt_mutex_unlock(&lock->base.lock);
2562
-}
2563
-EXPORT_SYMBOL(ww_mutex_unlock);
2564
-
2565
-int __rt_mutex_owner_current(struct rt_mutex *lock)
2566
-{
2567
- return rt_mutex_owner(lock) == current;
2568
-}
2569
-EXPORT_SYMBOL(__rt_mutex_owner_current);
2570
-#endif