Files
Greg Kroah-Hartman 598cf27219 Linux 6.19.3
Link: https://lore.kernel.org/r/20260217200002.683975158@linuxfoundation.org
Tested-by: Florian Fainelli <florian.fainelli@broadcom.com>
Tested-by: Takeshi Ogasawara <takeshi.ogasawara@futuring-girl.com>
Tested-by: Peter Schneider <pschneider1968@googlemail.com>
Tested-by: Jon Hunter <jonathanh@nvidia.com>
Tested-by: Salvatore Bonaccorso <carnil@debian.org>
Tested-by: Brett A C Sheffield <bacs@librecast.net>
Tested-by: Mark Brown <broonie@kernel.org>
Tested-by: Luna Jernberg <droidbittin@gmail.com>
Tested-by: Ronald Warsow <rwarsow@gmx.de>
Tested-by: Justin M. Forbes <jforbes@fedoraproject.org>
Tested-by: Ron Economos <re@w6rz.net>
Tested-by: Miguel Ojeda <ojeda@kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2026-02-19 16:33:27 +01:00

49 lines
1.4 KiB
C

/* SPDX-License-Identifier: GPL-2.0-or-later */
/*
* Resilient Queued Spin Lock defines
*
* (C) Copyright 2024-2025 Meta Platforms, Inc. and affiliates.
*
* Authors: Kumar Kartikeya Dwivedi <memxor@gmail.com>
*/
#ifndef __LINUX_RQSPINLOCK_H
#define __LINUX_RQSPINLOCK_H
#include "../locking/qspinlock.h"
/*
* try_cmpxchg_tail - Return result of cmpxchg of tail word with a new value
* @lock: Pointer to queued spinlock structure
* @tail: The tail to compare against
* @new_tail: The new queue tail code word
* Return: Bool to indicate whether the cmpxchg operation succeeded
*
* This is used by the head of the wait queue to clean up the queue.
* Provides relaxed ordering, since observers only rely on initialized
* state of the node which was made visible through the xchg_tail operation,
* i.e. through the smp_wmb preceding xchg_tail.
*
* We avoid using 16-bit cmpxchg, which is not available on all architectures.
*/
static __always_inline bool try_cmpxchg_tail(struct qspinlock *lock, u32 tail, u32 new_tail)
{
u32 old, new;
old = atomic_read(&lock->val);
do {
/*
* Is the tail part we compare to already stale? Fail.
*/
if ((old & _Q_TAIL_MASK) != tail)
return false;
/*
* Encode latest locked/pending state for new tail.
*/
new = (old & _Q_LOCKED_PENDING_MASK) | new_tail;
} while (!atomic_try_cmpxchg_relaxed(&lock->val, &old, new));
return true;
}
#endif /* __LINUX_RQSPINLOCK_H */