Skip to content

Commit c051b21

Browse files
committed
rtmutex: Confine deadlock logic to futex
The deadlock logic is only required for futexes. Remove the extra arguments for the public functions and also for the futex specific ones which get always called with deadlock detection enabled. Signed-off-by: Thomas Gleixner <tglx@linutronix.de> Reviewed-by: Steven Rostedt <rostedt@goodmis.org>
1 parent 1ca7b86 commit c051b21

4 files changed

Lines changed: 40 additions & 42 deletions

File tree

‎include/linux/rtmutex.h‎

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -90,11 +90,9 @@ extern void __rt_mutex_init(struct rt_mutex *lock, const char *name);
9090
extern void rt_mutex_destroy(struct rt_mutex *lock);
9191

9292
extern void rt_mutex_lock(struct rt_mutex *lock);
93-
extern int rt_mutex_lock_interruptible(struct rt_mutex *lock,
94-
int detect_deadlock);
93+
extern int rt_mutex_lock_interruptible(struct rt_mutex *lock);
9594
extern int rt_mutex_timed_lock(struct rt_mutex *lock,
96-
struct hrtimer_sleeper *timeout,
97-
int detect_deadlock);
95+
struct hrtimer_sleeper *timeout);
9896

9997
extern int rt_mutex_trylock(struct rt_mutex *lock);
10098

‎kernel/futex.c‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1718,7 +1718,7 @@ static int futex_requeue(u32 __user *uaddr1, unsigned int flags,
17181718
this->pi_state = pi_state;
17191719
ret = rt_mutex_start_proxy_lock(&pi_state->pi_mutex,
17201720
this->rt_waiter,
1721-
this->task, 1);
1721+
this->task);
17221722
if (ret == 1) {
17231723
/* We got the lock. */
17241724
requeue_pi_wake_futex(this, &key2, hb2);
@@ -2337,9 +2337,9 @@ static int futex_lock_pi(u32 __user *uaddr, unsigned int flags, int detect,
23372337
/*
23382338
* Block on the PI mutex:
23392339
*/
2340-
if (!trylock)
2341-
ret = rt_mutex_timed_lock(&q.pi_state->pi_mutex, to, 1);
2342-
else {
2340+
if (!trylock) {
2341+
ret = rt_mutex_timed_futex_lock(&q.pi_state->pi_mutex, to);
2342+
} else {
23432343
ret = rt_mutex_trylock(&q.pi_state->pi_mutex);
23442344
/* Fixup the trylock return value: */
23452345
ret = ret ? 0 : -EWOULDBLOCK;
@@ -2669,7 +2669,7 @@ static int futex_wait_requeue_pi(u32 __user *uaddr, unsigned int flags,
26692669
*/
26702670
WARN_ON(!q.pi_state);
26712671
pi_mutex = &q.pi_state->pi_mutex;
2672-
ret = rt_mutex_finish_proxy_lock(pi_mutex, to, &rt_waiter, 1);
2672+
ret = rt_mutex_finish_proxy_lock(pi_mutex, to, &rt_waiter);
26732673
debug_rt_mutex_free_waiter(&rt_waiter);
26742674

26752675
spin_lock(q.lock_ptr);

‎kernel/locking/rtmutex.c‎

Lines changed: 30 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1228,16 +1228,15 @@ rt_mutex_slowunlock(struct rt_mutex *lock)
12281228
*/
12291229
static inline int
12301230
rt_mutex_fastlock(struct rt_mutex *lock, int state,
1231-
int detect_deadlock,
12321231
int (*slowfn)(struct rt_mutex *lock, int state,
12331232
struct hrtimer_sleeper *timeout,
12341233
int detect_deadlock))
12351234
{
1236-
if (!detect_deadlock && likely(rt_mutex_cmpxchg(lock, NULL, current))) {
1235+
if (likely(rt_mutex_cmpxchg(lock, NULL, current))) {
12371236
rt_mutex_deadlock_account_lock(lock, current);
12381237
return 0;
12391238
} else
1240-
return slowfn(lock, state, NULL, detect_deadlock);
1239+
return slowfn(lock, state, NULL, 0);
12411240
}
12421241

12431242
static inline int
@@ -1284,54 +1283,59 @@ void __sched rt_mutex_lock(struct rt_mutex *lock)
12841283
{
12851284
might_sleep();
12861285

1287-
rt_mutex_fastlock(lock, TASK_UNINTERRUPTIBLE, 0, rt_mutex_slowlock);
1286+
rt_mutex_fastlock(lock, TASK_UNINTERRUPTIBLE, rt_mutex_slowlock);
12881287
}
12891288
EXPORT_SYMBOL_GPL(rt_mutex_lock);
12901289

12911290
/**
12921291
* rt_mutex_lock_interruptible - lock a rt_mutex interruptible
12931292
*
1294-
* @lock: the rt_mutex to be locked
1295-
* @detect_deadlock: deadlock detection on/off
1293+
* @lock: the rt_mutex to be locked
12961294
*
12971295
* Returns:
1298-
* 0 on success
1299-
* -EINTR when interrupted by a signal
1300-
* -EDEADLK when the lock would deadlock (when deadlock detection is on)
1296+
* 0 on success
1297+
* -EINTR when interrupted by a signal
13011298
*/
1302-
int __sched rt_mutex_lock_interruptible(struct rt_mutex *lock,
1303-
int detect_deadlock)
1299+
int __sched rt_mutex_lock_interruptible(struct rt_mutex *lock)
13041300
{
13051301
might_sleep();
13061302

1307-
return rt_mutex_fastlock(lock, TASK_INTERRUPTIBLE,
1308-
detect_deadlock, rt_mutex_slowlock);
1303+
return rt_mutex_fastlock(lock, TASK_INTERRUPTIBLE, rt_mutex_slowlock);
13091304
}
13101305
EXPORT_SYMBOL_GPL(rt_mutex_lock_interruptible);
13111306

1307+
/*
1308+
* Futex variant with full deadlock detection.
1309+
*/
1310+
int rt_mutex_timed_futex_lock(struct rt_mutex *lock,
1311+
struct hrtimer_sleeper *timeout)
1312+
{
1313+
might_sleep();
1314+
1315+
return rt_mutex_timed_fastlock(lock, TASK_INTERRUPTIBLE, timeout, 1,
1316+
rt_mutex_slowlock);
1317+
}
1318+
13121319
/**
13131320
* rt_mutex_timed_lock - lock a rt_mutex interruptible
13141321
* the timeout structure is provided
13151322
* by the caller
13161323
*
1317-
* @lock: the rt_mutex to be locked
1324+
* @lock: the rt_mutex to be locked
13181325
* @timeout: timeout structure or NULL (no timeout)
1319-
* @detect_deadlock: deadlock detection on/off
13201326
*
13211327
* Returns:
1322-
* 0 on success
1323-
* -EINTR when interrupted by a signal
1328+
* 0 on success
1329+
* -EINTR when interrupted by a signal
13241330
* -ETIMEDOUT when the timeout expired
1325-
* -EDEADLK when the lock would deadlock (when deadlock detection is on)
13261331
*/
13271332
int
1328-
rt_mutex_timed_lock(struct rt_mutex *lock, struct hrtimer_sleeper *timeout,
1329-
int detect_deadlock)
1333+
rt_mutex_timed_lock(struct rt_mutex *lock, struct hrtimer_sleeper *timeout)
13301334
{
13311335
might_sleep();
13321336

1333-
return rt_mutex_timed_fastlock(lock, TASK_INTERRUPTIBLE, timeout,
1334-
detect_deadlock, rt_mutex_slowlock);
1337+
return rt_mutex_timed_fastlock(lock, TASK_INTERRUPTIBLE, timeout, 0,
1338+
rt_mutex_slowlock);
13351339
}
13361340
EXPORT_SYMBOL_GPL(rt_mutex_timed_lock);
13371341

@@ -1437,7 +1441,6 @@ void rt_mutex_proxy_unlock(struct rt_mutex *lock,
14371441
* @lock: the rt_mutex to take
14381442
* @waiter: the pre-initialized rt_mutex_waiter
14391443
* @task: the task to prepare
1440-
* @detect_deadlock: perform deadlock detection (1) or not (0)
14411444
*
14421445
* Returns:
14431446
* 0 - task blocked on lock
@@ -1448,7 +1451,7 @@ void rt_mutex_proxy_unlock(struct rt_mutex *lock,
14481451
*/
14491452
int rt_mutex_start_proxy_lock(struct rt_mutex *lock,
14501453
struct rt_mutex_waiter *waiter,
1451-
struct task_struct *task, int detect_deadlock)
1454+
struct task_struct *task)
14521455
{
14531456
int ret;
14541457

@@ -1506,22 +1509,20 @@ struct task_struct *rt_mutex_next_owner(struct rt_mutex *lock)
15061509
* rt_mutex_finish_proxy_lock() - Complete lock acquisition
15071510
* @lock: the rt_mutex we were woken on
15081511
* @to: the timeout, null if none. hrtimer should already have
1509-
* been started.
1512+
* been started.
15101513
* @waiter: the pre-initialized rt_mutex_waiter
1511-
* @detect_deadlock: perform deadlock detection (1) or not (0)
15121514
*
15131515
* Complete the lock acquisition started our behalf by another thread.
15141516
*
15151517
* Returns:
15161518
* 0 - success
1517-
* <0 - error, one of -EINTR, -ETIMEDOUT, or -EDEADLK
1519+
* <0 - error, one of -EINTR, -ETIMEDOUT
15181520
*
15191521
* Special API call for PI-futex requeue support
15201522
*/
15211523
int rt_mutex_finish_proxy_lock(struct rt_mutex *lock,
15221524
struct hrtimer_sleeper *to,
1523-
struct rt_mutex_waiter *waiter,
1524-
int detect_deadlock)
1525+
struct rt_mutex_waiter *waiter)
15251526
{
15261527
int ret;
15271528

‎kernel/locking/rtmutex_common.h‎

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -111,12 +111,11 @@ extern void rt_mutex_proxy_unlock(struct rt_mutex *lock,
111111
struct task_struct *proxy_owner);
112112
extern int rt_mutex_start_proxy_lock(struct rt_mutex *lock,
113113
struct rt_mutex_waiter *waiter,
114-
struct task_struct *task,
115-
int detect_deadlock);
114+
struct task_struct *task);
116115
extern int rt_mutex_finish_proxy_lock(struct rt_mutex *lock,
117116
struct hrtimer_sleeper *to,
118-
struct rt_mutex_waiter *waiter,
119-
int detect_deadlock);
117+
struct rt_mutex_waiter *waiter);
118+
extern int rt_mutex_timed_futex_lock(struct rt_mutex *l, struct hrtimer_sleeper *to);
120119

121120
#ifdef CONFIG_DEBUG_RT_MUTEXES
122121
# include "rtmutex-debug.h"

0 commit comments

Comments
 (0)