Skip to content

Commit 4f9d138

Browse files
committed
x86/spinlock: Replace ACCESS_ONCE with READ_ONCE
ACCESS_ONCE does not work reliably on non-scalar types. For example gcc 4.6 and 4.7 might remove the volatile tag for such accesses during the SRA (scalar replacement of aggregates) step (https://gcc.gnu.org/bugzilla/show_bug.cgi?id=58145) Change the spinlock code to replace ACCESS_ONCE with READ_ONCE. Signed-off-by: Christian Borntraeger <borntraeger@de.ibm.com> Acked-by: Paul E. McKenney <paulmck@linux.vnet.ibm.com>
1 parent e37c698 commit 4f9d138

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

arch/x86/include/asm/spinlock.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ static __always_inline void arch_spin_lock(arch_spinlock_t *lock)
9292
unsigned count = SPIN_THRESHOLD;
9393

9494
do {
95-
if (ACCESS_ONCE(lock->tickets.head) == inc.tail)
95+
if (READ_ONCE(lock->tickets.head) == inc.tail)
9696
goto out;
9797
cpu_relax();
9898
} while (--count);
@@ -105,7 +105,7 @@ static __always_inline int arch_spin_trylock(arch_spinlock_t *lock)
105105
{
106106
arch_spinlock_t old, new;
107107

108-
old.tickets = ACCESS_ONCE(lock->tickets);
108+
old.tickets = READ_ONCE(lock->tickets);
109109
if (old.tickets.head != (old.tickets.tail & ~TICKET_SLOWPATH_FLAG))
110110
return 0;
111111

@@ -162,14 +162,14 @@ static __always_inline void arch_spin_unlock(arch_spinlock_t *lock)
162162

163163
static inline int arch_spin_is_locked(arch_spinlock_t *lock)
164164
{
165-
struct __raw_tickets tmp = ACCESS_ONCE(lock->tickets);
165+
struct __raw_tickets tmp = READ_ONCE(lock->tickets);
166166

167167
return tmp.tail != tmp.head;
168168
}
169169

170170
static inline int arch_spin_is_contended(arch_spinlock_t *lock)
171171
{
172-
struct __raw_tickets tmp = ACCESS_ONCE(lock->tickets);
172+
struct __raw_tickets tmp = READ_ONCE(lock->tickets);
173173

174174
return (__ticket_t)(tmp.tail - tmp.head) > TICKET_LOCK_INC;
175175
}

0 commit comments

Comments
 (0)