public inbox for libc-hacker@sourceware.org
 help / color / mirror / Atom feed
From: "David S. Miller" <davem@davemloft.net>
To: libc-hacker@sources.redhat.com
Subject: Fw: [PATCH]: Fix sparc atomic operations
Date: Sat, 25 Mar 2006 20:46:00 -0000	[thread overview]
Message-ID: <20060325.124621.38239765.davem@davemloft.net> (raw)

[-- Attachment #1: Type: Text/Plain, Size: 7 bytes --]


Ping?

[-- Attachment #2: Type: Message/Rfc822, Size: 5558 bytes --]

From: "David S. Miller" <davem@davemloft.net>
To: libc-hacker@sources.redhat.com
Cc: jakub@redhat.com
Subject: [PATCH]: Fix sparc atomic operations
Date: Fri, 24 Mar 2006 02:06:30 -0800 (PST)
Message-ID: <20060324.020630.43672826.davem@davemloft.net>


The sparc atomics were missing "memory" clobbers in their
asm statements.  This caused miscompilation of the various
pthread atomic primitives.

In one case, pthread_mutex_lock() was miscompiled such that
the ->owner field of the mutex was sampled before we acquired
the lock, thus triggering the "owner == 0" assertion if things
were just right.

Surprisingly nothing in the nptl tests caught this, instead I
discovered it when trying to build MONO, which seemed to be
able to trigger this case quite readily. :-)

Please apply, thanks.

2006-03-24  David S. Miller  <davem@sunset.davemloft.net>

	* sysdeps/sparc/sparc32/bits/atomic.h
	(__v9_compare_and_exchange_val_32_acq): Add "memory" clobber.
	* sysdeps/sparc/sparc32/sparcv9/bits/atomic.h
	(__arch_compare_and_exchange_val_32_acq, atomic_exchange_acq):
	Likewise.
	* sysdeps/sparc/sparc64/bits/atomic.h
	(__arch_compare_and_exchange_val_32_acq,
	__arch_compare_and_exchange_val_64_acq, atomic_exchange_acq):
	Likewise.
	
--- ./sysdeps/sparc/sparc32/bits/atomic.h.~1~	2006-01-03 16:05:07.000000000 -0800
+++ ./sysdeps/sparc/sparc32/bits/atomic.h	2006-03-24 00:00:06.000000000 -0800
@@ -122,7 +122,7 @@ volatile unsigned char __sparc32_atomic_
   __asm __volatile (".word 0xcde05005"					      \
 		    : "+r" (__acev_tmp), "=m" (*__acev_mem)		      \
 		    : "r" (__acev_oldval), "m" (*__acev_mem),		      \
-		      "r" (__acev_mem));				      \
+		      "r" (__acev_mem) : "memory");			      \
   __acev_tmp; })
 #endif
 
--- ./sysdeps/sparc/sparc32/sparcv9/bits/atomic.h.~1~	2006-01-03 16:05:07.000000000 -0800
+++ ./sysdeps/sparc/sparc32/sparcv9/bits/atomic.h	2006-03-24 00:00:32.000000000 -0800
@@ -59,7 +59,7 @@ typedef uintmax_t uatomic_max_t;
   __asm __volatile ("cas [%4], %2, %0"					      \
 		    : "=r" (__acev_tmp), "=m" (*__acev_mem)		      \
 		    : "r" (oldval), "m" (*__acev_mem), "r" (__acev_mem),      \
-		      "0" (newval));					      \
+		      "0" (newval) : "memory");				      \
   __acev_tmp; })
 
 /* This can be implemented if needed.  */
@@ -74,7 +74,7 @@ typedef uintmax_t uatomic_max_t;
      if (sizeof (*(mem)) == 4)						      \
        __asm ("swap %0, %1"						      \
 	      : "=m" (*__memp), "=r" (__oldval)				      \
-	      : "m" (*__memp), "1" (__value));				      \
+	      : "m" (*__memp), "1" (__value) : "memory");		      \
      else								      \
        abort ();							      \
      __oldval; })
--- ./sysdeps/sparc/sparc64/bits/atomic.h.~1~	2006-01-03 16:05:07.000000000 -0800
+++ ./sysdeps/sparc/sparc64/bits/atomic.h	2006-03-24 00:01:04.000000000 -0800
@@ -59,7 +59,7 @@ typedef uintmax_t uatomic_max_t;
   __asm __volatile ("cas [%4], %2, %0"					      \
 		    : "=r" (__acev_tmp), "=m" (*__acev_mem)		      \
 		    : "r" (oldval), "m" (*__acev_mem), "r" (__acev_mem),      \
-		      "0" (newval));					      \
+		      "0" (newval) : "memory");				      \
   __acev_tmp; })
 
 #define __arch_compare_and_exchange_val_64_acq(mem, newval, oldval) \
@@ -69,7 +69,7 @@ typedef uintmax_t uatomic_max_t;
   __asm __volatile ("casx [%4], %2, %0"					      \
 		    : "=r" (__acev_tmp), "=m" (*__acev_mem)		      \
 		    : "r" ((long) (oldval)), "m" (*__acev_mem),		      \
-		      "r" (__acev_mem), "0" ((long) (newval)));		      \
+		      "r" (__acev_mem), "0" ((long) (newval)) : "memory");    \
   __acev_tmp; })
 
 #define atomic_exchange_acq(mem, newvalue) \
@@ -80,7 +80,7 @@ typedef uintmax_t uatomic_max_t;
      if (sizeof (*(mem)) == 4)						      \
        __asm ("swap %0, %1"						      \
 	      : "=m" (*__memp), "=r" (__oldval)				      \
-	      : "m" (*__memp), "1" (__value));				      \
+	      : "m" (*__memp), "1" (__value) : "memory");		      \
      else								      \
        {								      \
 	 __val = *__memp;						      \

             reply	other threads:[~2006-03-25 20:46 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-03-25 20:46 David S. Miller [this message]
2006-03-25 21:03 ` Ulrich Drepper

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=20060325.124621.38239765.davem@davemloft.net \
    --to=davem@davemloft.net \
    --cc=libc-hacker@sources.redhat.com \
    /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 read-only IMAP folder(s) and NNTP newsgroup(s).