Skip to contentSkip to conversation

ARM: futex: fix clobbering oldval

PATCH In review mhban 3 participants 8 messages Sep 22, 2011 – Dec 6, 2011 Arm (32-bit)

lore
Share & tools
lore

mhban

author
#0 lore raw

PATCH 1/1 ARM: futex: fix clobbering oldval

This patch fixes clobbering oldval bug. oldval should be preserved for next compare operation.

Change-Id I2a63bc1bdb8de330eb9e1ac02d7da1f77e6e8c3c
---
 arch/arm/include/asm/futex.h |    6 +++---
 1 files changed, 3 insertions(+), 3 deletions(-)
arch/arm/include/asm/futex.h +3 -3
index d2d733c..b0f2e8e 100644
@@ -30,14 +30,14 @@
 	__asm__ __volatile__(					\
 	"1:	ldrex	%1, [%2]\n"				\
 	"	" insn "\n"					\
-	"2:	strex	%1, %0, [%2]\n"				\
-	"	teq	%1, #0\n"				\
+	"2:	strex	r5, %0, [%2]\n"				\
+	"	teq	r5, #0\n"				\
 	"	bne	1b\n"					\
 	"	mov	%0, #0\n"				\
 	__futex_atomic_ex_table("%4")				\
 	: "=&r" (ret), "=&r" (oldval)				\
 	: "r" (uaddr), "r" (oparg), "Ir" (-EFAULT)		\
-	: "cc", "memory")
+	: "r5", "cc", "memory")
 
 static inline int
 futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
Signature · 1 line
1.7.0.4
#1 lore raw

Hi,

Quoted 5 lines · mhban

This patch fixes clobbering oldval bug. oldval should be preserved for next compare operation.

Change-Id I2a63bc1bdb8de330eb9e1ac02d7da1f77e6e8c3c

It would have been nice to have been CC'd on this...

I ran LTP tests on this, so I'm surprised that this was broken (the tests passed). Well spotted anyway!

Quoted 13 lines
---
 arch/arm/include/asm/futex.h |    6 +++---
 1 files changed, 3 insertions(+), 3 deletions(-)
arch/arm/include/asm/futex.h +0 -1
index d2d733c..b0f2e8e 100644
@@ -30,14 +30,14 @@
 	__asm__ __volatile__(					\
 	"1:	ldrex	%1, [%2]\n"				\
 	"	" insn "\n"					\
-	"2:	strex	%1, %0, [%2]\n"				\

arch/arm/include/asm/futex.h line 40

Quoted 10 lines
arch/arm/include/asm/futex.h +3 -2
-	"	teq	%1, #0\n"				\
+	"2:	strex	r5, %0, [%2]\n"				\
+	"	teq	r5, #0\n"				\
 	"	bne	1b\n"					\
 	"	mov	%0, #0\n"				\
 	__futex_atomic_ex_table("%4")				\
 	: "=&r" (ret), "=&r" (oldval)				\
 	: "r" (uaddr), "r" (oparg), "Ir" (-EFAULT)		\
-	: "cc", "memory")
+	: "r5", "cc", "memory")

You shouldn't reference r5 directly here, but due to the way the futex code is laid out, you can't add an extra output operand without converting the code to use named arguments.

I'll post a patch to do that.

Will

author
#2 lore raw
Quoted 10 lines · Will Deacon

Hi,

Quoted 5 lines · mhban

This patch fixes clobbering oldval bug. oldval should be preserved for next compare operation.

Change-Id I2a63bc1bdb8de330eb9e1ac02d7da1f77e6e8c3c

It would have been nice to have been CC'd on this...

Will not miss next time. Thanks.

Quoted 32 lines

I ran LTP tests on this, so I'm surprised that this was broken (the tests passed). Well spotted anyway!

Quoted 13 lines
---
 arch/arm/include/asm/futex.h |    6 +++---
 1 files changed, 3 insertions(+), 3 deletions(-)
arch/arm/include/asm/futex.h +0 -1
index d2d733c..b0f2e8e 100644
@@ -30,14 +30,14 @@
 	__asm__ __volatile__(					\
 	"1:	ldrex	%1, [%2]\n"				\
 	"	" insn "\n"					\
-	"2:	strex	%1, %0, [%2]\n"				\

arch/arm/include/asm/futex.h line 40

Quoted 10 lines
arch/arm/include/asm/futex.h +3 -2
-	"	teq	%1, #0\n"				\
+	"2:	strex	r5, %0, [%2]\n"				\
+	"	teq	r5, #0\n"				\
 	"	bne	1b\n"					\
 	"	mov	%0, #0\n"				\
 	__futex_atomic_ex_table("%4")				\
 	: "=&r" (ret), "=&r" (oldval)				\
 	: "r" (uaddr), "r" (oparg), "Ir" (-EFAULT)		\
-	: "cc", "memory")
+	: "r5", "cc", "memory")

You shouldn't reference r5 directly here, but due to the way the futex code is laid out, you can't add an extra output operand without converting the code to use named arguments.

Quoted 3 lines

I'll post a patch to do that.

Will

I'm not familiar with gcc inline, thanks for pointing it out.

BTW, my last name is Ban not Ben.

Minho

#3 lore raw
Quoted 5 lines · mhban
Quoted 2 lines · Will Deacon

It would have been nice to have been CC'd on this...

Will not miss next time. Thanks.

Thanks. You can use scripts/get_maintainer.pl to get a list of people to email.

Quoted 10 lines
Quoted 8 lines

You shouldn't reference r5 directly here, but due to the way the futex code is laid out, you can't add an extra output operand without converting the code to use named arguments.

I'll post a patch to do that.

Will

I'm not familiar with gcc inline, thanks for pointing it out.

There's a good guide for ARM here:

http://www.ethernut.de/en/documents/arm-inline-asm.html

Quoted 1 line

BTW, my last name is Ban not Ben.

Oops, I'll update my reported-by to spell that correctly.

Cheers,

Will

#4 lore raw
In reply to Will Deacon
Quoted 6 lines · Will Deacon

Hi,

Quoted 3 lines · mhban

This patch fixes clobbering oldval bug. oldval should be preserved for next compare operation.

Quoted 7 lines
Quoted 2 lines
Change-Id I2a63bc1bdb8de330eb9e1ac02d7da1f77e6e8c3c

It would have been nice to have been CC'd on this...

I ran LTP tests on this, so I'm surprised that this was broken (the tests passed). Well spotted anyway!

This appears to be the cause of our "stuck builder" problem in Fedora building certain large packages, such as OpenJDK. Some of our guys are still monitoring the situation in case there's a secondary issue.

Was there ever any additional followup on this topic?

Jon.

#5 lore raw

Hi Jon,

Quoted 12 lines · Jon Masters
Quoted 11 lines · Will Deacon

Hi,

Quoted 5 lines · mhban

This patch fixes clobbering oldval bug. oldval should be preserved for next compare operation.

Change-Id I2a63bc1bdb8de330eb9e1ac02d7da1f77e6e8c3c

It would have been nice to have been CC'd on this...

Quoted 8 lines
Quoted 2 lines

I ran LTP tests on this, so I'm surprised that this was broken (the tests passed). Well spotted anyway!

This appears to be the cause of our "stuck builder" problem in Fedora building certain large packages, such as OpenJDK. Some of our guys are still monitoring the situation in case there's a secondary issue.

Was there ever any additional followup on this topic?

Yup, check commit df77abca ("ARM: 7099/1: futex: preserve oldval in SMP __futex_atomic_op"). It should be in stable for all affected kernels too.

Cheers,

Will

#6 lore raw
Quoted 18 lines · Will Deacon

Hi Jon,

Quoted 15 lines · Jon Masters
Quoted 13 lines · Will Deacon

Hi,

Quoted 5 lines · mhban

This patch fixes clobbering oldval bug. oldval should be preserved for next compare operation.

Change-Id I2a63bc1bdb8de330eb9e1ac02d7da1f77e6e8c3c

It would have been nice to have been CC'd on this...

I ran LTP tests on this, so I'm surprised that this was broken (the tests passed). Well spotted anyway!

Quoted 8 lines
Quoted 5 lines

This appears to be the cause of our "stuck builder" problem in Fedora building certain large packages, such as OpenJDK. Some of our guys are still monitoring the situation in case there's a secondary issue.

Was there ever any additional followup on this topic?

Yup, check commit df77abca ("ARM: 7099/1: futex: preserve oldval in SMP __futex_atomic_op"). It should be in stable for all affected kernels too.

Yea, Mark flagged that patch and it was included into the kernels on our boards here. So far, it seems to be making some improvement, though we still have stuck boards and weird signal issues sometimes. We are trying to collect more data when this occurs (I gave the engineer concerned some instructions around collecting data that will be of use). So I just wondered if you saw any more futex issues, or if this is believe fixed.

Jon.

#7 lore raw
Quoted 8 lines · Jon Masters
Quoted 6 lines · Will Deacon
Quoted 2 lines · Jon Masters

Was there ever any additional followup on this topic?

Yup, check commit df77abca ("ARM: 7099/1: futex: preserve oldval in SMP __futex_atomic_op"). It should be in stable for all affected kernels too.

Quoted 6 lines

Yea, Mark flagged that patch and it was included into the kernels on our boards here. So far, it seems to be making some improvement, though we still have stuck boards and weird signal issues sometimes. We are trying to collect more data when this occurs (I gave the engineer concerned some instructions around collecting data that will be of use). So I just wondered if you saw any more futex issues, or if this is believe fixed.

I think this is fixed, but that doesn't mean there aren't bugs lurking elsewhere that I'm simply not seeing. If you do get any diagnostics or concrete debug information, please CC me on any posts to the list.

Cheers,

Will