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=1796387215; b=g0tA3+NUTfhdYllrCk7FVglrLgj5nc4Y/1jAfjTSbKmYhFXwuOO8JSp5Sny3zXAANxTJ 2++ZY0CKbCcskWLG+CkbClfTC4qmcLh3VhU1eNaAjCHVGFapt8Xzj77buzrcN5GwrOBFr KdYqcsYyz8rcliiI900XsgPm556ts7dsI5uddCqnUdLxofqx4XJqbHBEo7ieAzciOUuVS P/R6/W2D77m3zPu2p0qubv9CV6mLR6VFscdJBzMkcLDUFeJ80id8HU2Yc/cUFLNlu7as6 85smwzKjwUTwZU5VJO2I+34YwRNJYdehY/xMSWWAe/hJ3Rc+NIFj7HrYvdu6PLu3XTA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796387215; 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=97udWv/DEmzmhUSqddP17Yvywp8j79lb50QpzHBdyOA=; b=wHQzuM6N7GhLjw0ladyQZ0koSY+0eEwp9FfuszIkhIrLKZ4lHTmWEoyW3M+o9qf8S4ZN Shpku15RTPTz1O7lF0Afna41KqnulCDTMmGQSUelllOrJCOwjYyvvs/zA2GG34/XZYecH VVNMRxaO44fBzCUAmBTMK0qDxZ+HYw/uPTeGkARTk7LmU3r0D46ponznGtVo2sp2APoj5 seMbplcM+grJ0u3I4R425a2WnwT9dEuT6b3GOVx7abBi5GhA46gu73PO5lxxXqo7VUHCU ldFF9nQ3+9dAtmytfQ0BJL4c3AvsZxla903IMKD07el/CnCimYRVcF7DAeVP2K7wTCw== 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=rm6OQPQo; 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 709ED606A322; Fri, 4 Dec 2026 12:26:55 +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=rm6OQPQo Received: by smtp.kernel.org (Postfix) with ESMTPSA id DD46C1F00897; Fri, 4 Dec 2026 12:26:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796387215; bh=97udWv/DEmzmhUSqddP17Yvywp8j79lb50QpzHBdyOA=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=rm6OQPQo6XG4dam9PL/1wvlbB/U6OFmaYysSRxsE0Tn8Q6JJIQrlWp5flZIAl3BYb 0Cv/qWcQe0VhV9SZ9AAadAS3JRmn7+7AsC2CbBmw2CKB4iA8uPyStkiNju7QHpba87 bB9BUD8xSlNv106IdwY6qRiLrT8F+SC/DfyOkGa4= 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.1 0144/1059] locking/osq_lock: Clarify osq_wait_next() calling convention Date: Fri, 4 Dec 2026 18:54:35 +0900 Message-ID: <20261204100647.947847904@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: 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