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=1796384666; b=WkzKkenH8R7ki3zWO3LvDweAE6XeMdRkRymRfGWytSfDp5Fs8lL2S+oWRrvH5bTKHgTy moXsSMnnxr33sIfKxaccaFtfYX2g3uaa9UoTnJxbE/OToZrUrzF6SsgD64gzf3aGmar1o LkTTodpoT7+cDkMpZtP8ZJsTVxSlOq9vKZvD9TlSpJGdmP7jQeEAGQVeKBhEEfdViJ7i0 wDciXH+MA7jYQS9sBBJ3zJdBrPTwo3m9eR+EuNRcS6rXtru/6aD6KI9jgEs0qGwipVdxG PAjYhE/PwHYTSYbFW+Iwg4AA+BmO7cxiHDoFk4J3LA+Zj+DUziM0gWHurLklt1ybpVA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796384666; 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=NZHDglsrdHJCbMfX4D+cUGXcEn/UI80kFm7+AfUCX7g=; b=sh76DDulZQRiCpBwWENXEkdGZD/7e3lG9pH4xB9OK6/lJeehiUhf8kSfhcFL2ev1gPB8 twgbbRCxxDVveOkxVzHD/ILwd6ffVqc1l9pqVn2gzmlDeHsH1WZpEP+lOGEXml3Dak7k5 b71bAt/GO0mmDOtrURt+Kz64YV0j6j/ZCwbqQ8EOasQ16bTCRpaS5tzWE8lTIG7vlDvh0 LkZ7gC4AVRvKwxtiBkPw0jS9ck2+Zo2lN+j13mLWsGrmRweUQsouWiDuGThQGlvh4sTUx bOAuFilMDixwyIrd3pznpQtACvbSScgS7gx8qaelwK42ymo6y+C3yeYE0EKhqt/doew== 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="Ik/JAvIH"; 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 93C37606A322; Fri, 4 Dec 2026 11:44:26 +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=Ik/JAvIH Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0C8911F000C2; Fri, 4 Dec 2026 11:44:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796384666; bh=NZHDglsrdHJCbMfX4D+cUGXcEn/UI80kFm7+AfUCX7g=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=Ik/JAvIHVIzqMaoooQvePQYaiMPsxJp2/4EddIh1JRgpSUkAkdJLS+rsCtYtiCLeN P4NxxJlKon6Wu28mxslBGVEsew0Sv3xi0VUgr3cOrGbune/bzky0MBLDCh47mLKBep M3gL6dgtkMKG5imH3l4siTn9LfRGYjYj9+lJn8Ho= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, David Laight , Linus Torvalds , Sasha Levin Subject: [PATCH 6.6 0192/1167] locking/osq_lock: Clarify osq_wait_next() calling convention Date: Fri, 4 Dec 2026 18:53:39 +0900 Message-ID: <20261204100707.063856346@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: David Laight [ Upstream commit 563adbfc351b2af9f1406b809ba60b9f1673a882 ] osq_wait_next() is passed 'prev' from osq_lock() and NULL from osq_unlock() but only needs the 'cpu' value to write to lock->tail. Just pass prev->cpu or OSQ_UNLOCKED_VAL instead. Should have no effect on the generated code since gcc manages to assume that 'prev != NULL' due to an earlier dereference. Signed-off-by: David Laight [ Changed 'old' to 'old_cpu' by request from Waiman Long - Linus ] Signed-off-by: Linus Torvalds Stable-dep-of: 1b9e01fcc47a ("locking/osq: Switch osq_wait_next()/atomic_cmpxchg() ordering") Signed-off-by: Sasha Levin --- kernel/locking/osq_lock.c | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/kernel/locking/osq_lock.c b/kernel/locking/osq_lock.c index d5610ad52b92b..ebb1493915ce9 100644 --- a/kernel/locking/osq_lock.c +++ b/kernel/locking/osq_lock.c @@ -37,26 +37,23 @@ static inline struct optimistic_spin_node *decode_cpu(int encoded_cpu_val) /* * Get a stable @node->next pointer, either for unlock() or unqueue() purposes. * Can return NULL in case we were the last queued and we updated @lock instead. + * + * If osq_lock() is being cancelled there must be a previous node + * and 'old_cpu' is its CPU #. + * For osq_unlock() there is never a previous node and old_cpu is + * set to OSQ_UNLOCKED_VAL. */ static inline struct optimistic_spin_node * osq_wait_next(struct optimistic_spin_queue *lock, struct optimistic_spin_node *node, - struct optimistic_spin_node *prev) + int old_cpu) { struct optimistic_spin_node *next = NULL; int curr = encode_cpu(smp_processor_id()); - int old; - - /* - * If there is a prev node in queue, then the 'old' value will be - * the prev node's CPU #, else it's set to OSQ_UNLOCKED_VAL since if - * we're currently last in queue, then the queue will then become empty. - */ - old = prev ? prev->cpu : OSQ_UNLOCKED_VAL; for (;;) { if (atomic_read(&lock->tail) == curr && - atomic_cmpxchg_acquire(&lock->tail, curr, old) == curr) { + atomic_cmpxchg_acquire(&lock->tail, curr, old_cpu) == curr) { /* * We were the last queued, we moved @lock back. @prev * will now observe @lock and will complete its @@ -186,7 +183,7 @@ bool osq_lock(struct optimistic_spin_queue *lock) * back to @prev. */ - next = osq_wait_next(lock, node, prev); + next = osq_wait_next(lock, node, prev->cpu); if (!next) return false; @@ -226,7 +223,7 @@ void osq_unlock(struct optimistic_spin_queue *lock) return; } - next = osq_wait_next(lock, node, NULL); + next = osq_wait_next(lock, node, OSQ_UNLOCKED_VAL); if (next) WRITE_ONCE(next->locked, 1); } -- 2.53.0