linux-stable/kernel/futex
Peter Zijlstra fbeb558b0d futex/pi: Fix recursive rt_mutex waiter state
Some new assertions pointed out that the existing code has nested rt_mutex wait
state in the futex code.

Specifically, the futex_lock_pi() cancel case uses spin_lock() while there
still is a rt_waiter enqueued for this task, resulting in a state where there
are two waiters for the same task (and task_struct::pi_blocked_on gets
scrambled).

The reason to take hb->lock at this point is to avoid the wake_futex_pi()
EAGAIN case.

This happens when futex_top_waiter() and rt_mutex_top_waiter() state becomes
inconsistent. The current rules are such that this inconsistency will not be
observed.

Notably the case that needs to be avoided is where futex_lock_pi() and
futex_unlock_pi() interleave such that unlock will fail to observe a new
waiter.

*However* the case at hand is where a waiter is leaving, in this case the race
means a waiter that is going away is not observed -- which is harmless,
provided this race is explicitly handled.

This is a somewhat dangerous proposition because the converse race is not
observing a new waiter, which must absolutely not happen. But since the race is
valid this cannot be asserted.

Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Reviewed-by: Thomas Gleixner <tglx@linutronix.de>
Reviewed-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
Tested-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
Link: https://lkml.kernel.org/r/20230915151943.GD6743@noisy.programming.kicks-ass.net
2023-09-20 09:31:14 +02:00
..
core.c Linux 6.6-rc2 2023-09-18 22:17:15 +02:00
futex.h futex: add missing rtmutex.h include 2022-04-07 15:09:12 +02:00
Makefile futex: Split out wait/wake 2021-10-07 13:51:11 +02:00
pi.c futex/pi: Fix recursive rt_mutex waiter state 2023-09-20 09:31:14 +02:00
requeue.c futex/pi: Fix recursive rt_mutex waiter state 2023-09-20 09:31:14 +02:00
syscalls.c futex: Fix futex_waitv() hrtimer debug object leak on kcalloc error 2022-12-27 12:52:02 +01:00
waitwake.c freezer,sched: Rewrite core freezer logic 2022-09-07 21:53:50 +02:00