KVM
Classes | Macros | Typedefs | Functions
spinlock.h File Reference
#include <asm/alternative.h>
#include <asm/lse.h>
#include <asm/rwonce.h>
Include dependency graph for spinlock.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

union  hyp_spinlock
 

Macros

#define __HYP_SPIN_LOCK_INITIALIZER    { .__val = 0 }
 
#define __HYP_SPIN_LOCK_UNLOCKED    ((hyp_spinlock_t) __HYP_SPIN_LOCK_INITIALIZER)
 
#define DEFINE_HYP_SPINLOCK(x)   hyp_spinlock_t x = __HYP_SPIN_LOCK_UNLOCKED
 
#define hyp_spin_lock_init(l)
 

Typedefs

typedef union hyp_spinlock hyp_spinlock_t
 

Functions

static void hyp_spin_lock (hyp_spinlock_t *lock)
 
static void hyp_spin_unlock (hyp_spinlock_t *lock)
 
static bool hyp_spin_is_locked (hyp_spinlock_t *lock)
 
static void hyp_assert_lock_held (hyp_spinlock_t *lock)
 

Macro Definition Documentation

◆ __HYP_SPIN_LOCK_INITIALIZER

#define __HYP_SPIN_LOCK_INITIALIZER    { .__val = 0 }

Definition at line 31 of file spinlock.h.

◆ __HYP_SPIN_LOCK_UNLOCKED

#define __HYP_SPIN_LOCK_UNLOCKED    ((hyp_spinlock_t) __HYP_SPIN_LOCK_INITIALIZER)

Definition at line 34 of file spinlock.h.

◆ DEFINE_HYP_SPINLOCK

#define DEFINE_HYP_SPINLOCK (   x)    hyp_spinlock_t x = __HYP_SPIN_LOCK_UNLOCKED

Definition at line 37 of file spinlock.h.

◆ hyp_spin_lock_init

#define hyp_spin_lock_init (   l)
Value:
do { \
} while (0)
#define __HYP_SPIN_LOCK_UNLOCKED
Definition: spinlock.h:34

Definition at line 39 of file spinlock.h.

Typedef Documentation

◆ hyp_spinlock_t

Function Documentation

◆ hyp_assert_lock_held()

static void hyp_assert_lock_held ( hyp_spinlock_t lock)
inlinestatic

Definition at line 122 of file spinlock.h.

122 { }
Here is the caller graph for this function:

◆ hyp_spin_is_locked()

static bool hyp_spin_is_locked ( hyp_spinlock_t lock)
inlinestatic

Definition at line 101 of file spinlock.h.

102 {
103  hyp_spinlock_t lockval = READ_ONCE(*lock);
104 
105  return lockval.owner != lockval.next;
106 }

◆ hyp_spin_lock()

static void hyp_spin_lock ( hyp_spinlock_t lock)
inlinestatic

Definition at line 44 of file spinlock.h.

45 {
46  u32 tmp;
47  hyp_spinlock_t lockval, newval;
48 
49  asm volatile(
50  /* Atomically increment the next ticket. */
51  ARM64_LSE_ATOMIC_INSN(
52  /* LL/SC */
53 " prfm pstl1strm, %3\n"
54 "1: ldaxr %w0, %3\n"
55 " add %w1, %w0, #(1 << 16)\n"
56 " stxr %w2, %w1, %3\n"
57 " cbnz %w2, 1b\n",
58  /* LSE atomics */
59 " mov %w2, #(1 << 16)\n"
60 " ldadda %w2, %w0, %3\n"
61  __nops(3))
62 
63  /* Did we get the lock? */
64 " eor %w1, %w0, %w0, ror #16\n"
65 " cbz %w1, 3f\n"
66  /*
67  * No: spin on the owner. Send a local event to avoid missing an
68  * unlock before the exclusive load.
69  */
70 " sevl\n"
71 "2: wfe\n"
72 " ldaxrh %w2, %4\n"
73 " eor %w1, %w2, %w0, lsr #16\n"
74 " cbnz %w1, 2b\n"
75  /* We got the lock. Critical section starts here. */
76 "3:"
77  : "=&r" (lockval), "=&r" (newval), "=&r" (tmp), "+Q" (*lock)
78  : "Q" (lock->owner)
79  : "memory");
80 }
Here is the caller graph for this function:

◆ hyp_spin_unlock()

static void hyp_spin_unlock ( hyp_spinlock_t lock)
inlinestatic

Definition at line 82 of file spinlock.h.

83 {
84  u64 tmp;
85 
86  asm volatile(
87  ARM64_LSE_ATOMIC_INSN(
88  /* LL/SC */
89  " ldrh %w1, %0\n"
90  " add %w1, %w1, #1\n"
91  " stlrh %w1, %0",
92  /* LSE atomics */
93  " mov %w1, #1\n"
94  " staddlh %w1, %0\n"
95  __nops(1))
96  : "=Q" (lock->owner), "=&r" (tmp)
97  :
98  : "memory");
99 }
Here is the caller graph for this function: