From nobody Thu Dec 18 20:19:29 2025 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 ACBA21A01CC for ; Wed, 18 Dec 2024 11:16: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=1734520592; cv=none; b=QEQ8RoQAWUdLeFsKdMzgt/go2P+Y+sPU0IJiPnqa1CLhoZ54RbrFyy3PyPE3oX0WV0QcTrvD+ZpxoYzIlNFL7pL9Fpe59jcjVU8Slh8vkQ2PUcC+OH8dGQVVdfet4AK3l4GCFF03R7RCB6jbp2u19BXrcuw99IrGNb7mC5snA+g= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734520592; c=relaxed/simple; bh=y9QHnww7dsE9jJJeTyKx3mgtH9RzETbu4RJH6fEo64g=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=LEoKZRvqj07h1uLPI9kHZUqUpxPCYadhSLEEPHB1fG3sQgLjtfMWoetUT/1dRzxMS4KBKYTwwuNXqAe9zx6M9DeZlViUVMOKbGIqXmVvSOFEJCvARSiwQA4uQspeaPYuKaPkLrXTEw88aMxeYMZv8H9OquohkiruGpfX5HXDKY8= 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=L044UsHG; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=Tz2Jz5wG; 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="L044UsHG"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="Tz2Jz5wG" From: Sebastian Andrzej Siewior DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1734520588; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=aXpqOOBJeNGbJ2omXu9WIWMFWCXXo+fLDPz2Rz90DRw=; b=L044UsHGW17Fd16srhWn6G6Av/s6pi5potN9lmucpqUgpUAaxavjAmGDsmBL1jC225Yt7K NVQZbS5mRlOo+yiQ3WIcJwZrP42Xu5HfUhpnKQoqRYbF3MB3/E8HWc6sXP7dSYf/2+Jhzz sRxprfSgyLeRDGKpXuVNTgsqPlmRfKYIUf7Ap006MQ1mhLugQkVe/WyoDJE3llbNxuDigv WZtZZdoF8YMWc2ZXyyNdBWFDjDEueRTWyGMBKEdayFoeWLR1Q1Vq1o6gYdOYklYZX6SgJN NjNeuaxAIoTrVm88/8CjlsyJSW6+RMqGS5WQxvEFRnv9a9gCuAuF0JWLZKqXzg== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1734520588; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=aXpqOOBJeNGbJ2omXu9WIWMFWCXXo+fLDPz2Rz90DRw=; b=Tz2Jz5wGTz9q+rMRIkGz5NKttHocwn6b74/f9B7Rf8gW0MNBFZWzac+G0vRz55bZLuXbYI nfgH+RR8IWyYwKAw== To: linux-kernel@vger.kernel.org Cc: =?UTF-8?q?Andr=C3=A9=20Almeida?= , Darren Hart , Davidlohr Bueso , Ingo Molnar , Juri Lelli , Peter Zijlstra , Thomas Gleixner , Valentin Schneider , Waiman Long , Sebastian Andrzej Siewior Subject: [PATCH v6 08/15] futex: Re-evaluate the hash bucket after dropping the lock Date: Wed, 18 Dec 2024 12:09:46 +0100 Message-ID: <20241218111618.268028-9-bigeasy@linutronix.de> In-Reply-To: <20241218111618.268028-1-bigeasy@linutronix.de> References: <20241218111618.268028-1-bigeasy@linutronix.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" In futex_requeue() and futex_wake_op() the hash bucket lock is dropped in the failure paths for handling page faults and other error scenarios. After that the code jumps back to retry_private which relocks the hash bucket[s] under the assumption that the hash bucket pointer which was retrieved via futex_hash() is still valid. With resizable private hash buckets, that assumption is not longer true as the waiters can be moved to a larger hash in the meantime. Move the retry_private label above the hashing function to handle this correctly. Signed-off-by: Sebastian Andrzej Siewior --- kernel/futex/requeue.c | 2 +- kernel/futex/waitwake.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/kernel/futex/requeue.c b/kernel/futex/requeue.c index 217cec5c8302e..31ec543e7fdb3 100644 --- a/kernel/futex/requeue.c +++ b/kernel/futex/requeue.c @@ -443,10 +443,10 @@ int futex_requeue(u32 __user *uaddr1, unsigned int fl= ags1, if (requeue_pi && futex_match(&key1, &key2)) return -EINVAL; =20 +retry_private: hb1 =3D futex_hash(&key1); hb2 =3D futex_hash(&key2); =20 -retry_private: futex_hb_waiters_inc(hb2); double_lock_hb(hb1, hb2); =20 diff --git a/kernel/futex/waitwake.c b/kernel/futex/waitwake.c index 01d419efbf298..03e2f546967d8 100644 --- a/kernel/futex/waitwake.c +++ b/kernel/futex/waitwake.c @@ -267,10 +267,10 @@ int futex_wake_op(u32 __user *uaddr1, unsigned int fl= ags, u32 __user *uaddr2, if (unlikely(ret !=3D 0)) return ret; =20 +retry_private: hb1 =3D futex_hash(&key1); hb2 =3D futex_hash(&key2); =20 -retry_private: double_lock_hb(hb1, hb2); op_ret =3D futex_atomic_op_inuser(op, uaddr2); if (unlikely(op_ret < 0)) { --=20 2.45.2