Commit 51859c5a authored by Linus Torvalds's avatar Linus Torvalds
Browse files

Merge tag 'locking-urgent-2024-08-25' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip

Pull locking fix from Thomas Gleixner:
 "A single fix for rt_mutex.

  The deadlock detection code drops into an infinite scheduling loop
  while still holding rt_mutex::wait_lock, which rightfully triggers a
  'scheduling in atomic' warning.

  Unlock it before that"

* tag 'locking-urgent-2024-08-25' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip:
  rtmutex: Drop rt_mutex::wait_lock before scheduling
parents 9a754292 d33d2603
Loading
Loading
Loading
Loading
+5 −4
Original line number Diff line number Diff line
@@ -1644,6 +1644,7 @@ static int __sched rt_mutex_slowlock_block(struct rt_mutex_base *lock,
}

static void __sched rt_mutex_handle_deadlock(int res, int detect_deadlock,
					     struct rt_mutex_base *lock,
					     struct rt_mutex_waiter *w)
{
	/*
@@ -1656,10 +1657,10 @@ static void __sched rt_mutex_handle_deadlock(int res, int detect_deadlock,
	if (build_ww_mutex() && w->ww_ctx)
		return;

	/*
	 * Yell loudly and stop the task right here.
	 */
	raw_spin_unlock_irq(&lock->wait_lock);

	WARN(1, "rtmutex deadlock detected\n");

	while (1) {
		set_current_state(TASK_INTERRUPTIBLE);
		rt_mutex_schedule();
@@ -1713,7 +1714,7 @@ static int __sched __rt_mutex_slowlock(struct rt_mutex_base *lock,
	} else {
		__set_current_state(TASK_RUNNING);
		remove_waiter(lock, waiter);
		rt_mutex_handle_deadlock(ret, chwalk, waiter);
		rt_mutex_handle_deadlock(ret, chwalk, lock, waiter);
	}

	/*