From nobody Thu Dec 18 20:19:34 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 ACB571A00FE 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=GEh49J+tKhRmoDWAzZvgeuXYuPwyScOKchHgongifSt7224yT1NqaGwoOByPpf1Ij/G8xGopNj9Eqe0Jl2sPgSrjgIML/iU77W37iuyADF9T38xcma25r4DEoYu/bxfUTvfKmNQcef1Cl//bSohUfsoTd2nlYB4gPGdkXlUuRUY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734520592; c=relaxed/simple; bh=fgip/RU+lTB3R0w6MLaWB/u++7/aYFKZsABMMEtRnlI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=FtgMtMQRnRyyzt+O84Wcc/WEVVCEK3FiJOmTFy5YeCdhCfeFHLfbDcZOCvKvFOJ5tXrFTJNiV5kl9Z1Do5MSXJdbuIZ1opDo0W+O+VWbFKhZAnIF1b8Sbeu4uYP7WLKpkHwGuF6Pm4JbDRA7OS8jJ1pSpYIZh4sXSF0a//ViTxE= 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=ck6gAqne; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=eirE1mtR; 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="ck6gAqne"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="eirE1mtR" From: Sebastian Andrzej Siewior DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1734520587; 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=/bxp6kVzpikx/DHSvPukV1Xoc2vF5cq0WM8tkOhgCLc=; b=ck6gAqnei+cui7vNnBjVsGhmV+FtS4ahJBaBRVH6bpewWS9rWe0d6hl7ZlP41O8logXipB dzQ7da1aZ/y18YAZR2ys30Q1r8qvFpV0hTrKc7URjY4+ftXs39sb50h0w11R6jPUunns1/ VP4wL9DCeQeX6xjS0nIW7NeeoC6XGXDDKMUfYyskDTu6BuBlyZm6BkWEQ6vp3SLHOOgiVn DLIGIBb13x5DM76+bITCoKwrrpS5LevpSfYZlf6+5aH86DGoCJiU+kvNzUDRkesLJ7XQvF A6SiTp5E4suHS/tifgDGSVTOzZGYlA9/EPRCq+BtifFdecqgLtpPjsg9h8xeQw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1734520587; 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=/bxp6kVzpikx/DHSvPukV1Xoc2vF5cq0WM8tkOhgCLc=; b=eirE1mtRKMA2ztguFUjhEh87Gr0/Bu9dd4wDA7UtNcYjL9drVRBYpQlOeTW162QnFOe1H3 nSdwGf8R3Tra9nBQ== 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 06/15] futex: Decrease the waiter count before the unlock operation. Date: Wed, 18 Dec 2024 12:09:44 +0100 Message-ID: <20241218111618.268028-7-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" To support runtime resizing of the process private hash, it's required to not use the obtained hash bucket once the reference count has been dropped. The reference will be dropped after the unlock of the hash bucket. The amount of waiters is decremented after the unlock operation. There is no requirement that this needs to happen after the unlock. The increment happens before acquiring the lock to signal early that there will be a waiter. The waiter can avoid blocking on the lock if it is known that there will be no waiter. There is no difference in terms of ordering if the decrement happens before or after the unlock. Decrease the waiter count before the unlock operation. Signed-off-by: Sebastian Andrzej Siewior --- kernel/futex/core.c | 2 +- kernel/futex/requeue.c | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/kernel/futex/core.c b/kernel/futex/core.c index 907b76590df16..254d0dfac71a9 100644 --- a/kernel/futex/core.c +++ b/kernel/futex/core.c @@ -558,8 +558,8 @@ struct futex_hash_bucket *futex_q_lock(struct futex_q *= q) void futex_q_unlock(struct futex_hash_bucket *hb) __releases(&hb->lock) { - spin_unlock(&hb->lock); futex_hb_waiters_dec(hb); + spin_unlock(&hb->lock); } =20 void __futex_queue(struct futex_q *q, struct futex_hash_bucket *hb) diff --git a/kernel/futex/requeue.c b/kernel/futex/requeue.c index b47bb764b3520..fb69dcdf74da8 100644 --- a/kernel/futex/requeue.c +++ b/kernel/futex/requeue.c @@ -456,8 +456,8 @@ int futex_requeue(u32 __user *uaddr1, unsigned int flag= s1, ret =3D futex_get_value_locked(&curval, uaddr1); =20 if (unlikely(ret)) { - double_unlock_hb(hb1, hb2); futex_hb_waiters_dec(hb2); + double_unlock_hb(hb1, hb2); =20 ret =3D get_user(curval, uaddr1); if (ret) @@ -542,8 +542,8 @@ int futex_requeue(u32 __user *uaddr1, unsigned int flag= s1, * waiter::requeue_state is correct. */ case -EFAULT: - double_unlock_hb(hb1, hb2); futex_hb_waiters_dec(hb2); + double_unlock_hb(hb1, hb2); ret =3D fault_in_user_writeable(uaddr2); if (!ret) goto retry; @@ -556,8 +556,8 @@ int futex_requeue(u32 __user *uaddr1, unsigned int flag= s1, * exit to complete. * - EAGAIN: The user space value changed. */ - double_unlock_hb(hb1, hb2); futex_hb_waiters_dec(hb2); + double_unlock_hb(hb1, hb2); /* * Handle the case where the owner is in the middle of * exiting. Wait for the exit to complete otherwise @@ -674,9 +674,9 @@ int futex_requeue(u32 __user *uaddr1, unsigned int flag= s1, put_pi_state(pi_state); =20 out_unlock: + futex_hb_waiters_dec(hb2); double_unlock_hb(hb1, hb2); wake_up_q(&wake_q); - futex_hb_waiters_dec(hb2); return ret ? ret : task_count; } =20 --=20 2.45.2