From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796387241; b=FZRVLFUH8Q731rjFNOsJKtBTO31Bd6wsUi9ho7Mgj2cblW/5rtMbv7MTXENO+N2t8f3+ 0mFBIvWxemSeWvwJCVV2ZGlD7o7pe9Jw4g34LiNRUMBZ5WrPWK2/mzm2SIIwvQAWvwE/e 5jIFJoUxrj7y+jZ7Ar3MMWQYkBzoNVPr41kpaLaDlunK/fPirQd4usombcXEH+b9rnw/P ETVTTGRNraoYllPdih937HWMEPBg8iVXGEVA8jNStQiCUwWIT3wAgAVxq2Mn67LV7uyx/ +McsfpG7gJmLz/0k5HqPzREiXKs+Qv1o8Clqpk9O2x72belRM+vNI7HpgkYUhXzXcOQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796387241; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:User-Agent:X-stable:X-Patchwork-Hint: MIME-Version:Content-Transfer-Encoding; bh=pdmJ5WDyiy74Tu5LZjZ8A30WOjUe5RWVOFOHHyvNs3k=; b=TPbwsvHT3cN9Cb43n/mKfLuzbOKFcy+oe7EXwM62qFOTHGAIL8dLCZx/wEne7QI7wSub C+BwsbZpRregHkXmWBoAjGYRxYfr52SkhzUhnwOq2zRc2IG4AAsiBnrbBgjfRUyGVSxN3 n6JxMxGZyi9Oc8rIz12l1xPqAaJuRZbcXUC+cNLh8G0Yi7abEJZ+KZclb63gvB/EowBPo ZT7ScX/DvyW2j2kVa295kSqjbm0e8RPJJkmmP+m9Ehv42tUjaAOiIrAS5fLS/53e6Bu3B XNhdGwS9HSIMUml8Ztkr5lwIfobl5+UPBsEnhZoiPhOS8kHOu6rUZ7+MTWRb1W0pVVg== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=uluLfB22; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 399BA606A322; Fri, 4 Dec 2026 12:27:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=uluLfB22 Received: by smtp.kernel.org (Postfix) with ESMTPSA id AD0381F000C2; Fri, 4 Dec 2026 12:27:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796387241; bh=pdmJ5WDyiy74Tu5LZjZ8A30WOjUe5RWVOFOHHyvNs3k=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=uluLfB22D58gXaGVTlFEUvAuPIEE3dRA31g6Vyw69XmO8TEsDbD/imTgKx0zz+SUb 4ifwW5Ib9vW3C+mE6J7QqokXFM1x5ZGKJGyfJWkWAXurOXQr+p89Xt4stsB0MZ3dhY qmhlbUDRo7L+/b4eJZ9ybHTrRLFGMkY5aKd7R2zo= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, David Laight , "Peter Zijlstra (Intel)" , Ingo Molnar , Linus Torvalds , Waiman Long , linux-kernel@vger.kernel.org, Sasha Levin Subject: [PATCH 6.1 0145/1059] locking/osq: Switch osq_wait_next()/atomic_cmpxchg() ordering Date: Fri, 4 Dec 2026 18:54:36 +0900 Message-ID: <20261204100647.973149444@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100643.980430235@linuxfoundation.org> References: <20261204100643.980430235@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore X-Mailing-List: patches@lists.linux.dev List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.1-stable review patch. If anyone has any objections, please let me know. ------------------ From: Peter Zijlstra [ Upstream commit 1b9e01fcc47aff00d2fd64693c5dcd620eff5865 ] The atomic_cmpxchg() in osq_wait_next() removes the current CPU's node from the tail of the queue and puts @old_cpu back. This is very much like an 'unlock', which is RELEASE, rather than ACQUIRE. Additionally, on success (the only case where the ordering is effective), this returns NULL which means both callsites will do nothing more, there are no subsequent operations to order against. Furthermore, the osq_lock() caller will then return false, indicating failure to acquire -- the mutex must go block. Again, not making a case for ACQUIRE. Neither atomics nor locks provide ordering on failure. Since ACQUIRE makes no sense, while RELEASE makes it more symmetric with osq_unlock(), switch the ordering. This then makes osq_unlock() consistently RELEASE. Fixes: c55a6ffa6285 ("locking/osq: Relax atomic semantics") Suggested-by: David Laight Signed-off-by: Peter Zijlstra (Intel) Signed-off-by: Ingo Molnar Cc: Linus Torvalds Cc: Waiman Long Cc: linux-kernel@vger.kernel.org Signed-off-by: Sasha Levin --- kernel/locking/osq_lock.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kernel/locking/osq_lock.c b/kernel/locking/osq_lock.c index ebb1493915ce9..b3748ed287ebb 100644 --- a/kernel/locking/osq_lock.c +++ b/kernel/locking/osq_lock.c @@ -53,7 +53,7 @@ osq_wait_next(struct optimistic_spin_queue *lock, for (;;) { if (atomic_read(&lock->tail) == curr && - atomic_cmpxchg_acquire(&lock->tail, curr, old_cpu) == curr) { + atomic_cmpxchg_release(&lock->tail, curr, old_cpu) == curr) { /* * We were the last queued, we moved @lock back. @prev * will now observe @lock and will complete its -- 2.53.0