From: tom.leiming@gmail.com (Ming Lei)
To: linux-arm-kernel@lists.infradead.org
Subject: [Question] race between spin_lock and spin_unlock
Date: Mon, 24 Jun 2013 23:13:38 +0800 [thread overview]
Message-ID: <CACVXFVMBL5E5SGwDatn_ay0sPOhqPKTwouCbzjwrhPuRKHNDcg@mail.gmail.com> (raw)
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
next reply other threads:[~2013-06-24 15:13 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-06-24 15:13 Ming Lei [this message]
2013-06-24 15:43 ` [Question] race between spin_lock and spin_unlock 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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=CACVXFVMBL5E5SGwDatn_ay0sPOhqPKTwouCbzjwrhPuRKHNDcg@mail.gmail.com \
--to=tom.leiming@gmail.com \
--cc=linux-arm-kernel@lists.infradead.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).