1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef _ASM_LOONGARCH_QSPINLOCK_H
3 #define _ASM_LOONGARCH_QSPINLOCK_H
5 #include <linux/jump_label.h>
9 DECLARE_STATIC_KEY_FALSE(virt_spin_lock_key
);
11 #define virt_spin_lock virt_spin_lock
13 static inline bool virt_spin_lock(struct qspinlock
*lock
)
17 if (!static_branch_unlikely(&virt_spin_lock_key
))
21 * On hypervisors without PARAVIRT_SPINLOCKS support we fall
22 * back to a Test-and-Set spinlock, because fair locks have
23 * horrible lock 'holder' preemption issues.
27 val
= atomic_read(&lock
->val
);
29 if (val
|| !atomic_try_cmpxchg(&lock
->val
, &val
, _Q_LOCKED_VAL
)) {
37 #endif /* CONFIG_PARAVIRT */
39 #include <asm-generic/qspinlock.h>
41 #endif // _ASM_LOONGARCH_QSPINLOCK_H