linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
* [Question] race between spin_lock and spin_unlock
@ 2013-06-24 15:13 Ming Lei
  2013-06-24 15:43 ` Will Deacon
  0 siblings, 1 reply; 9+ messages in thread
From: Ming Lei @ 2013-06-24 15:13 UTC (permalink / raw)
  To: linux-arm-kernel

Hi,

When reading the code of arch_spin_lock(), I think there might be
a race between arch_spin_lock() and arch_spin_unlock():

- arch_spin_unlock() happened just between StoreExcl(lock->next)
and comparing lockval.tickets.next with lockval.tickets.owner inside
arch_spin_lock()

- arch_spin_lock() can't notice the change on lock->owner, so call
wfe(), then just waiting for being waken up, but there isn't corresponding
unlock to send wake event any more.

Maybe the below change may make the race to happen difficultly,
but it still can't avoid it completely.

diff --git a/arch/arm/include/asm/spinlock.h b/arch/arm/include/asm/spinlock.h
index 6220e9f..e1b239c 100644
--- a/arch/arm/include/asm/spinlock.h
+++ b/arch/arm/include/asm/spinlock.h
@@ -87,10 +87,8 @@ static inline void arch_spin_lock(arch_spinlock_t *lock)
 	: "r" (&lock->slock), "I" (1 << TICKET_SHIFT)
 	: "cc");

-	while (lockval.tickets.next != lockval.tickets.owner) {
+	while (lockval.tickets.next != ACCESS_ONCE(lock->tickets.owner))
 		wfe();
-		lockval.tickets.owner = ACCESS_ONCE(lock->tickets.owner);
-	}

 	smp_mb();
 }

Any comments on the problem?

Thanks,
-- 
Ming Lei

^ permalink raw reply related	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2013-06-25 11:19 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-06-24 15:13 [Question] race between spin_lock and spin_unlock Ming Lei
2013-06-24 15:43 ` Will Deacon
2013-06-24 16:04   ` Ming Lei
2013-06-24 16:37     ` Will Deacon
2013-06-25  4:31       ` Ming Lei
2013-06-25  8:48         ` Will Deacon
2013-06-25 10:54           ` Ming Lei
2013-06-25 10:59             ` Will Deacon
2013-06-25 11:19               ` Ming Lei

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).