Linux MIPS Architecture development
 help / color / mirror / Atom feed
* Bug in atomic_sub_if_positive
@ 2008-06-26  6:07 Morten Larsen
  2008-06-26 12:11 ` Ralf Baechle
  0 siblings, 1 reply; 9+ messages in thread
From: Morten Larsen @ 2008-06-26  6:07 UTC (permalink / raw)
  To: linux-mips


As far as I can tell the branch optimization fixes in 2.6.21 introduced
a bug in atomic_sub_if_positive that causes it to return even when the
sc instruction fails. The result is that e.g. down_trylock becomes
unreliable as the semaphore counter is not always decremented.

Below is a patch that fixed the problem on my system.

Morten S. Larsen


--- a/include/asm-mips/atomic.h 2008-06-25 22:38:43.159739000 -0700
+++ b/include/asm-mips/atomic.h 2008-06-25 22:39:07.552065000 -0700
@@ -292,10 +292,10 @@ static __inline__ int atomic_sub_if_posi
                "       beqz    %0, 2f
\n"
                "        subu   %0, %1, %3
\n"
                "       .set    reorder
\n"
-               "1:
\n"
                "       .subsection 2
\n"
                "2:     b       1b
\n"
                "       .previous
\n"
+               "1:
\n"
                "       .set    mips0
\n"
                : "=&r" (result), "=&r" (temp), "=m" (v->counter)
                : "Ir" (i), "m" (v->counter)
@@ -682,10 +682,10 @@ static __inline__ long atomic64_sub_if_p
                "       beqz    %0, 2f
\n"
                "        dsubu  %0, %1, %3
\n"
                "       .set    reorder
\n"
-               "1:
\n"
                "       .subsection 2
\n"
                "2:     b       1b
\n"
                "       .previous
\n"
+               "1:
\n"
                "       .set    mips0
\n"
                : "=&r" (result), "=&r" (temp), "=m" (v->counter)
                : "Ir" (i), "m" (v->counter)

^ permalink raw reply	[flat|nested] 9+ messages in thread
* RE: Bug in atomic_sub_if_positive
@ 2008-07-02  0:12 Morten Larsen
  2008-07-02  9:59 ` Thiemo Seufer
  0 siblings, 1 reply; 9+ messages in thread
From: Morten Larsen @ 2008-07-02  0:12 UTC (permalink / raw)
  To: linux-mips


> As far as I can tell the branch optimization fixes in 2.6.21 introduced
> a bug in atomic_sub_if_positive that causes it to return even when the
> sc instruction fails. The result is that e.g. down_trylock becomes
> unreliable as the semaphore counter is not always decremented.

Previous patch was garbled by Outlook - this one should be clean:

--- a/include/asm-mips/atomic.h	2008-06-25 22:38:43.159739000 -0700
+++ b/include/asm-mips/atomic.h	2008-06-25 22:39:07.552065000 -0700
@@ -292,10 +292,10 @@ static __inline__ int atomic_sub_if_posi
 		"	beqz	%0, 2f					\n"
 		"	 subu	%0, %1, %3				\n"
 		"	.set	reorder					\n"
-		"1:							\n"
 		"	.subsection 2					\n"
 		"2:	b	1b					\n"
 		"	.previous					\n"
+		"1:							\n"
 		"	.set	mips0					\n"
 		: "=&r" (result), "=&r" (temp), "=m" (v->counter)
 		: "Ir" (i), "m" (v->counter)
@@ -682,10 +682,10 @@ static __inline__ long atomic64_sub_if_p
 		"	beqz	%0, 2f					\n"
 		"	 dsubu	%0, %1, %3				\n"
 		"	.set	reorder					\n"
-		"1:							\n"
 		"	.subsection 2					\n"
 		"2:	b	1b					\n"
 		"	.previous					\n"
+		"1:							\n"
 		"	.set	mips0					\n"
 		: "=&r" (result), "=&r" (temp), "=m" (v->counter)
 		: "Ir" (i), "m" (v->counter)

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

end of thread, other threads:[~2008-07-04 11:56 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-06-26  6:07 Bug in atomic_sub_if_positive Morten Larsen
2008-06-26 12:11 ` Ralf Baechle
2008-06-27  6:00   ` Morten Larsen
  -- strict thread matches above, loose matches on Subject: below --
2008-07-02  0:12 Morten Larsen
2008-07-02  9:59 ` Thiemo Seufer
2008-07-02 10:31   ` Atsushi Nemoto
2008-07-02 10:51     ` Thiemo Seufer
2008-07-03 15:04       ` Atsushi Nemoto
2008-07-04 11:54         ` Ralf Baechle

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox