From: Josip Rodin <joy@entuzijast.net>
To: Mikael Pettersson <mikpe@it.uu.se>
Cc: sparclinux@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH,SPARC] make sparc32 arch_write_unlock() match the sparc64 version
Date: Mon, 15 Aug 2011 15:31:17 +0200 [thread overview]
Message-ID: <20110815133116.GA20563@entuzijast.net> (raw)
In-Reply-To: <20040.65109.439941.444670@pilspetsen.it.uu.se>
On Mon, Aug 15, 2011 at 01:09:09PM +0200, Mikael Pettersson wrote:
> The sparc32 version of arch_write_unlock() is just a plain assignment.
> Unfortunately this allows the compiler to schedule side-effects in a
> protected region to occur after the HW-level unlock, which is broken.
> E.g., the following trivial test case gets miscompiled:
>
> #include <linux/spinlock.h>
> rwlock_t lock;
> int counter;
> void foo(void) { write_lock(&lock); ++counter; write_unlock(&lock); }
>
> Fixed by adding a compiler memory barrier to arch_write_unlock(). The
> sparc64 version combines the barrier and assignment into a single asm(),
> so that's what I did here as well.
>
> Compiled-tested with a sparc32 SMP kernel.
>
> Signed-off-by: Mikael Pettersson <mikpe@it.uu.se>
> ---
> --- linux-3.1-rc2/arch/sparc/include/asm/spinlock_32.h.~1~ 2011-07-22 12:01:08.000000000 +0200
> +++ linux-3.1-rc2/arch/sparc/include/asm/spinlock_32.h 2011-08-15 11:43:49.000000000 +0200
> @@ -131,6 +131,15 @@ static inline void arch_write_lock(arch_
> *(volatile __u32 *)&lp->lock = ~0U;
> }
>
> +static void inline arch_write_unlock(arch_rwlock_t *lock)
> +{
> + __asm__ __volatile__(
> +" st %%g0, [%0]"
> + : /* no outputs */
> + : "r" (lock)
> + : "memory");
> +}
> +
> static inline int arch_write_trylock(arch_rwlock_t *rw)
> {
> unsigned int val;
> @@ -175,7 +184,7 @@ static inline int __arch_read_trylock(ar
> res; \
> })
>
> -#define arch_write_unlock(rw) do { (rw)->lock = 0; } while(0)
> +#define arch_write_unlock(rw) arch_write_unlock(rw)
>
> #define arch_spin_lock_flags(lock, flags) arch_spin_lock(lock)
> #define arch_read_lock_flags(rw, flags) arch_read_lock(rw)
Why keep the tautological define? Just wondering.
--
2. That which causes joy or happiness.
next prev parent reply other threads:[~2011-08-15 14:07 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-08-15 11:09 Mikael Pettersson
2011-08-15 13:31 ` Josip Rodin [this message]
2011-08-15 14:32 ` Mikael Pettersson
2011-08-15 15:24 ` Sam Ravnborg
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=20110815133116.GA20563@entuzijast.net \
--to=joy@entuzijast.net \
--cc=linux-kernel@vger.kernel.org \
--cc=mikpe@it.uu.se \
--cc=sparclinux@vger.kernel.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
all inboxes | Powered by JetHome®