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=1796384582; b=pbFl3w8r9NnoZZMBo9tFuJIMPRbmSpL7x7cCv1w9DDWV/evBFB3iUp7V7RFLyaYGog4D onlEm1f9TInnwcsJn9zOm02vlSxPY3cOvMhw2AJd+3fb7VhWKKD7sNJiuZtEDFonBxRBn yr4wMTLt8sxTiS4sR2qHz2WS+eTz/OX9hVUF5wV4B2HhwYKVKAMDX4ZMYCG67A2Wh4tny pTw33B2dH5rBRg5xs7YZCD4PJTfOIvcu2xyb6kYm4HiurJtKrmYURIclZ5NmpZ5A5WBHw SBmxPFcWDdOkU83G57jUrD72Lws7GVJY1sWVKUm5tbWqRw9zfJz80synjCSSCprdmiA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796384582; 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=fK5R8voVl7JKM8jfBu9GEx8XtIvykYRVgqw8OPrbx5E=; b=LoQsEud98jl6Od6538iOm1t5I/PkuDyD3mzg6rkRgnNPK2iVIhh21NUqwvDbo2C4sQGQ 4Mxqi+IViQ/w/K4mP06Z7bFdbvZ4mVtNZnivBkzEWdQ3zgD9k3vL9u4YYA3Fae24I5s6u /Pj4fvi604UV2lTk8lkBeZrXXGK5lt0XXV3FzKWghBWKFlL7rnFdmbyrn1sJbEHIUA0/D /zfrtr9m0jKsKKFCSPBkYPIM9Q4ggXy5Nld4zn9jSlHB3kO6NMND8IEwmj3Tp4BRM9On7 6jIbEWXGDj3fOffFGPYdT2F0Yy+D1VsFyPAWoP/K33r1oLosfbOWqaEHYez+Q9igAcQ== 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="G8Px/WCI"; 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 CC95B606A32C; Fri, 4 Dec 2026 11:43:02 +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=G8Px/WCI Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4BBB01F00931; Fri, 4 Dec 2026 11:43:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796384582; bh=fK5R8voVl7JKM8jfBu9GEx8XtIvykYRVgqw8OPrbx5E=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=G8Px/WCIY4JrTlehkQQXp0dyUtr3xCwAZDcNyXxaFHmvBi4UatYDJgQRucan0mNTP RgFLC9BEqbSCBtns9pH7YcmGfo5+DOopgX6rEB346XQRYjd0kOAXQCqThEvHxHLLSs qwq3+x6sbbTxJf//aHZG7C3PvAAhCB3tS95GzR3Q= 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.6 0194/1167] locking/osq: Fix unlink queue corruption Date: Fri, 4 Dec 2026 18:53:41 +0900 Message-ID: <20261204100707.114718428@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100702.047403948@linuxfoundation.org> References: <20261204100702.047403948@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore X-Mailing-List: stable@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.6-stable review patch. If anyone has any objections, please let me know. ------------------ From: Peter Zijlstra [ Upstream commit 408b129aac48b574c0c9d11137a89eefba825d5d ] Very similar to commit 50972fe78f24 ("locking/osq_lock: Fix osq_lock queue corruption"), make sure to order the prev->next store against the next->prev store. Fixes: 50972fe78f24 ("locking/osq_lock: Fix osq_lock queue corruption") 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 | 60 +++++++++++++++++++++++++++++---------- 1 file changed, 45 insertions(+), 15 deletions(-) diff --git a/kernel/locking/osq_lock.c b/kernel/locking/osq_lock.c index b3748ed287ebb..29597052f442c 100644 --- a/kernel/locking/osq_lock.c +++ b/kernel/locking/osq_lock.c @@ -84,6 +84,49 @@ osq_wait_next(struct optimistic_spin_queue *lock, return next; } +/* + * Set prev->next; this is the counterpart of osq_wait_next() in that + * by setting ->next the wait is terminated and progress is resumed. + */ +static inline void osq_link_next(struct optimistic_spin_node *prev, + struct optimistic_spin_node *next) +{ + /* + * Suppose: + * + * tail + * | + * V + * CPU1 -> CPU2 -> CPU3: + * n: 2 n: 3 n: nil + * p: nil p: 1 p: 2 + * + * And this is CPU2 doing the self-unqueue concurrent against CPU1s + * unlock()/unqueue(). Since 'prev->next == NULL' and CPU1 will be + * stuck in osq_wait_next() until the below store of 'prev->next'. + * + * CPU2 CPU1 + * + * next->prev = prev; osq_wait_next() + * WMB MB + * prev->next = next; next->prev = prev + * + * Without the WMB it would be possible to have conflicting stores + * like: + * + * CPU2 CPU1 + * + * prev->next = next // CPU1.n = 3 + * next = osq_wait_next() // = 3 + * next->prev = prev // CPU3.p = nil + * next->prev = prev // CPU3.p = 1 + * + * Which would result in list corruption. + */ + smp_wmb(); + WRITE_ONCE(prev->next, next); +} + bool osq_lock(struct optimistic_spin_queue *lock) { struct optimistic_spin_node *node = this_cpu_ptr(&osq_node); @@ -107,20 +150,7 @@ bool osq_lock(struct optimistic_spin_queue *lock) prev = decode_cpu(old); node->prev = prev; - - /* - * osq_lock() unqueue - * - * node->prev = prev osq_wait_next() - * WMB MB - * prev->next = node next->prev = prev // unqueue-C - * - * Here 'node->prev' and 'next->prev' are the same variable and we need - * to ensure these stores happen in-order to avoid corrupting the list. - */ - smp_wmb(); - - WRITE_ONCE(prev->next, node); + osq_link_next(prev, node); /* * Normally @prev is untouchable after the above store; because at that @@ -196,7 +226,7 @@ bool osq_lock(struct optimistic_spin_queue *lock) */ WRITE_ONCE(next->prev, prev); - WRITE_ONCE(prev->next, next); + osq_link_next(prev, next); return false; } -- 2.53.0