From nobody Tue Jun 16 20:39:47 2026 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 30E7839B972; Wed, 29 Apr 2026 06:57:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777445852; cv=none; b=m6rP+486ZxKm5X0aFMES+RgiP5yh5SibaKyuj8BT3X27mn9x2iLidV55T4DYD+gZBgi6U9A0cVXjgL4+AKNbZKq7A7RzoGmlsM/hkE5h+k2ZSZqjKBjmE0onu+BBvjtWn2HMIf+a7FBs58iQR94+VTcCpPHu0+6q8EjaNJ5WoWU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777445852; c=relaxed/simple; bh=jxRZFO8ijPCIOdlYLtcteX9PbPFu27CMZ3Yx2N71Mg4=; h=Date:From:To:Subject:Cc:In-Reply-To:References:MIME-Version: Message-ID:Content-Type; b=qEXjeiZkjOPhHNMWKR+YoXIjCzfWdzvB+IQtzJHLBSnKOCUCp1jhYMhgf1fBPCx5Q8RzqY1oXFNe95ecTBLE7OtvRZlevjSRRZIsdpBFP41fV2EmwSmcc65LzrNqk7/S6Sd+80BjylxkKQHc4IkZI0PRxr9rehSZDjVKIgft2wA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=Ux/o0IGK; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=rYI26WJR; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="Ux/o0IGK"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="rYI26WJR" Date: Wed, 29 Apr 2026 06:57:26 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1777445847; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Uwa3ZVW3jG7bVzJ4zu52FtC4T/uHLv5COI8edHywVXc=; b=Ux/o0IGKhqVe/Bb+Ee4aqq+xIs984+Chww6WPcRkgHeRC2sqZ9cwxYEyY6AAYpFFhY+485 n/LfgAKj61MAZyFBHmpkIFYJiG1m+FEQW+ajI/DhifsBmNod/ezoJCbGtX2UHP9jW4+7Sx E4aEYW6ieiDEONsLJzf4HWqZFZFezap0+uUZhIqmVCuEZfCVVw5WKLJs5HYEjCoxjSUV2J PVpAc+/B18HLS9y6av3f142FifDWhvQSNy4Iui4CkPoKyLcCg2w9nOj8Fd/2fQd00e16vV tT/bAfBqMzw8+9HceOlNXdtbXoo+YFfhUwp1H7U/Svkb99mtF9Fadf2Y6CuFUA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1777445847; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Uwa3ZVW3jG7bVzJ4zu52FtC4T/uHLv5COI8edHywVXc=; b=rYI26WJR0iMEYT8PgTcnvBtqKmiS5j0OvdbLwMRPUEBVECIvfw5gvhlEzJuNCHShUwB/kp NpDNPXvOU3SARLAw== From: "tip-bot2 for Sebastian Andrzej Siewior" Sender: tip-bot2@linutronix.de Reply-to: linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip: locking/urgent] futex: Prevent lockup in requeue-PI during signal/ timeout wakeup Cc: Moritz Klammler , Sebastian Andrzej Siewior , Thomas Gleixner , x86@kernel.org, linux-kernel@vger.kernel.org In-Reply-To: <20260428103425.dywXyPd3@linutronix.de> References: <20260428103425.dywXyPd3@linutronix.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-ID: <177744584623.3521451.7117256247508138021.tip-bot2@tip-bot2> Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails Precedence: bulk Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable The following commit has been merged into the locking/urgent branch of tip: Commit-ID: bc7304f3ae20972d11db6e0b1b541c63feda5f05 Gitweb: https://git.kernel.org/tip/bc7304f3ae20972d11db6e0b1b541c63f= eda5f05 Author: Sebastian Andrzej Siewior AuthorDate: Tue, 28 Apr 2026 12:34:25 +02:00 Committer: Thomas Gleixner CommitterDate: Wed, 29 Apr 2026 08:56:40 +02:00 futex: Prevent lockup in requeue-PI during signal/ timeout wakeup During wait-requeue-pi (task A) and requeue-PI (task B) the following race can happen: Task A Task B futex_wait_requeue_pi() futex_setup_timer() futex_do_wait() futex_requeue() CLASS(hb, hb1)(&key1); CLASS(hb, hb2)(&key2); *timeout* futex_requeue_pi_wakeup_sync() requeue_state =3D Q_REQUEUE_PI_IGNORE *blocks on hb->lock* futex_proxy_trylock_atomic() futex_requeue_pi_prepare() Q_REQUEUE_PI_IGNORE =3D> -EAGAIN double_unlock_hb(hb1, hb2) *retry* Task B acquires both hb locks and attempts to acquire the PI-lock of the top most waiter (task B). Task A is leaving early due to a signal/ timeout and started removing itself from the queue. It updates its requeue_state but can not remove it from the list because this requires the hb lock which is owned by task B. Usually task A is able to swoop the lock after task B unlocked it. However if task B is of higher priority then task A may not be able to wake up in time and acquire the lock before task B gets it again. Especially on a UP system where A is never scheduled. As a result task A blocks on the lock and task B busy loops, trying to make progress but live locks the system instead. Tragic. This can be fixed by removing the top most waiter from the list in this case. This allows task B to grab the next top waiter (if any) in the next iteration and make progress. Remove the top most waiter if futex_requeue_pi_prepare() fails. Let the waiter conditionally remove itself from the list in handle_early_requeue_pi_wakeup(). Fixes: 07d91ef510fb1 ("futex: Prevent requeue_pi() lock nesting issue on RT= ") Reported-by: Moritz Klammler Signed-off-by: Sebastian Andrzej Siewior Signed-off-by: Thomas Gleixner Link: https://patch.msgid.link/20260428103425.dywXyPd3@linutronix.de Closes: https://lore.kernel.org/all/VE1PR06MB6894BE61C173D802365BE19DFF4CA@= VE1PR06MB6894.eurprd06.prod.outlook.com --- kernel/futex/requeue.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/kernel/futex/requeue.c b/kernel/futex/requeue.c index d818b4d..b597cb3 100644 --- a/kernel/futex/requeue.c +++ b/kernel/futex/requeue.c @@ -319,8 +319,11 @@ futex_proxy_trylock_atomic(u32 __user *pifutex, struct= futex_hash_bucket *hb1, return -EINVAL; =20 /* Ensure that this does not race against an early wakeup */ - if (!futex_requeue_pi_prepare(top_waiter, NULL)) + if (!futex_requeue_pi_prepare(top_waiter, NULL)) { + plist_del(&top_waiter->list, &hb1->chain); + futex_hb_waiters_dec(hb1); return -EAGAIN; + } =20 /* * Try to take the lock for top_waiter and set the FUTEX_WAITERS bit @@ -722,10 +725,12 @@ int handle_early_requeue_pi_wakeup(struct futex_hash_= bucket *hb, =20 /* * We were woken prior to requeue by a timeout or a signal. - * Unqueue the futex_q and determine which it was. + * Conditionally unqueue the futex_q and determine which it was. */ - plist_del(&q->list, &hb->chain); - futex_hb_waiters_dec(hb); + if (!plist_node_empty(&q->list)) { + plist_del(&q->list, &hb->chain); + futex_hb_waiters_dec(hb); + } =20 /* Handle spurious wakeups gracefully */ ret =3D -EWOULDBLOCK;