blob: 3e70bed8a978e7ef3541d80ef860185c8a0f12de [file] [log] [blame]
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01001/* SPDX-License-Identifier: GPL-2.0 */
Waiman Longd73a3392015-04-24 14:56:31 -04002#ifndef _ASM_X86_QSPINLOCK_H
3#define _ASM_X86_QSPINLOCK_H
4
Juergen Gross90434422017-09-06 19:36:24 +02005#include <linux/jump_label.h>
Peter Zijlstra (Intel)2aa79af2015-04-24 14:56:36 -04006#include <asm/cpufeature.h>
Waiman Longd73a3392015-04-24 14:56:31 -04007#include <asm-generic/qspinlock_types.h>
Peter Zijlstra (Intel)f233f7f2015-04-24 14:56:38 -04008#include <asm/paravirt.h>
Waiman Longd73a3392015-04-24 14:56:31 -04009
Will Deaconb247be32018-04-26 11:34:18 +010010#define _Q_PENDING_LOOPS (1 << 9)
11
Will Deacon626e5fb2018-04-26 11:34:24 +010012#ifdef CONFIG_PARAVIRT_SPINLOCKS
13extern void native_queued_spin_lock_slowpath(struct qspinlock *lock, u32 val);
14extern void __pv_init_lock_hash(void);
15extern void __pv_queued_spin_lock_slowpath(struct qspinlock *lock, u32 val);
16extern void __raw_callee_save___pv_queued_spin_unlock(struct qspinlock *lock);
17
Waiman Longd73a3392015-04-24 14:56:31 -040018#define queued_spin_unlock queued_spin_unlock
19/**
20 * queued_spin_unlock - release a queued spinlock
21 * @lock : Pointer to queued spinlock structure
22 *
23 * A smp_store_release() on the least-significant byte.
24 */
Peter Zijlstra (Intel)f233f7f2015-04-24 14:56:38 -040025static inline void native_queued_spin_unlock(struct qspinlock *lock)
Waiman Longd73a3392015-04-24 14:56:31 -040026{
Will Deacon625e88b2018-04-26 11:34:16 +010027 smp_store_release(&lock->locked, 0);
Waiman Longd73a3392015-04-24 14:56:31 -040028}
29
Peter Zijlstra (Intel)f233f7f2015-04-24 14:56:38 -040030static inline void queued_spin_lock_slowpath(struct qspinlock *lock, u32 val)
31{
32 pv_queued_spin_lock_slowpath(lock, val);
33}
34
35static inline void queued_spin_unlock(struct qspinlock *lock)
36{
37 pv_queued_spin_unlock(lock);
38}
Peter Zijlstra3cded412016-11-15 16:47:06 +010039
40#define vcpu_is_preempted vcpu_is_preempted
Waiman Long6c629852017-02-20 13:36:03 -050041static inline bool vcpu_is_preempted(long cpu)
Peter Zijlstra3cded412016-11-15 16:47:06 +010042{
43 return pv_vcpu_is_preempted(cpu);
44}
Peter Zijlstra (Intel)f233f7f2015-04-24 14:56:38 -040045#endif
46
Peter Zijlstraa6b27782015-09-05 16:55:05 +020047#ifdef CONFIG_PARAVIRT
Juergen Gross90434422017-09-06 19:36:24 +020048DECLARE_STATIC_KEY_TRUE(virt_spin_lock_key);
49
50void native_pv_lock_init(void) __init;
51
Peter Zijlstra43b3f022015-09-04 17:25:23 +020052#define virt_spin_lock virt_spin_lock
Peter Zijlstra43b3f022015-09-04 17:25:23 +020053static inline bool virt_spin_lock(struct qspinlock *lock)
Peter Zijlstra (Intel)2aa79af2015-04-24 14:56:36 -040054{
Juergen Gross90434422017-09-06 19:36:24 +020055 if (!static_branch_likely(&virt_spin_lock_key))
Peter Zijlstra (Intel)2aa79af2015-04-24 14:56:36 -040056 return false;
57
Peter Zijlstra43b3f022015-09-04 17:25:23 +020058 /*
59 * On hypervisors without PARAVIRT_SPINLOCKS support we fall
60 * back to a Test-and-Set spinlock, because fair locks have
61 * horrible lock 'holder' preemption issues.
62 */
63
64 do {
65 while (atomic_read(&lock->val) != 0)
66 cpu_relax();
67 } while (atomic_cmpxchg(&lock->val, 0, _Q_LOCKED_VAL) != 0);
Peter Zijlstra (Intel)2aa79af2015-04-24 14:56:36 -040068
69 return true;
70}
Juergen Gross90434422017-09-06 19:36:24 +020071#else
72static inline void native_pv_lock_init(void)
73{
74}
Peter Zijlstraa6b27782015-09-05 16:55:05 +020075#endif /* CONFIG_PARAVIRT */
Peter Zijlstra (Intel)2aa79af2015-04-24 14:56:36 -040076
Waiman Longd73a3392015-04-24 14:56:31 -040077#include <asm-generic/qspinlock.h>
78
79#endif /* _ASM_X86_QSPINLOCK_H */