2010-08-12 06:14:14

by Luca Barbieri

[permalink] [raw]
Subject: [tip:x86/urgent] x86, asm: Refactor atomic64_386_32.S to support old binutils and be cleaner

Commit-ID: 30246557a06bb20618bed906a06d1e1e0faa8bb4
Gitweb: http://git.kernel.org/tip/30246557a06bb20618bed906a06d1e1e0faa8bb4
Author: Luca Barbieri <[email protected]>
AuthorDate: Fri, 6 Aug 2010 04:04:38 +0200
Committer: H. Peter Anvin <[email protected]>
CommitDate: Wed, 11 Aug 2010 21:03:28 -0700

x86, asm: Refactor atomic64_386_32.S to support old binutils and be cleaner

The old code didn't work on binutils 2.12 because setting a symbol to
a register apparently requires a fairly recent version.

This commit refactors the code to use the C preprocessor instead, and
in the process makes the whole code a bit easier to understand.

The object code produced is unchanged as expected.

This fixes kernel bugzilla 16506.

Reported-by: Dieter Stussy <[email protected]>
Signed-off-by: Luca Barbieri <[email protected]>
Signed-off-by: H. Peter Anvin <[email protected]>
Cc: <[email protected]> 2.6.35
LKML-Reference: <tip-*@git.kernel.org>
---
arch/x86/lib/atomic64_386_32.S | 236 ++++++++++++++++++++++------------------
1 files changed, 128 insertions(+), 108 deletions(-)

diff --git a/arch/x86/lib/atomic64_386_32.S b/arch/x86/lib/atomic64_386_32.S
index 4a5979a..78ee8e0 100644
--- a/arch/x86/lib/atomic64_386_32.S
+++ b/arch/x86/lib/atomic64_386_32.S
@@ -25,150 +25,170 @@
CFI_ADJUST_CFA_OFFSET -4
.endm

-.macro BEGIN func reg
-$v = \reg
-
-ENTRY(atomic64_\func\()_386)
- CFI_STARTPROC
- LOCK $v
-
-.macro RETURN
- UNLOCK $v
+#define BEGIN(op) \
+.macro END; \
+ CFI_ENDPROC; \
+ENDPROC(atomic64_##op##_386); \
+.purgem END; \
+.endm; \
+ENTRY(atomic64_##op##_386); \
+ CFI_STARTPROC; \
+ LOCK v;
+
+#define RET \
+ UNLOCK v; \
ret
-.endm
-
-.macro END_
- CFI_ENDPROC
-ENDPROC(atomic64_\func\()_386)
-.purgem RETURN
-.purgem END_
-.purgem END
-.endm
-
-.macro END
-RETURN
-END_
-.endm
-.endm
-
-BEGIN read %ecx
- movl ($v), %eax
- movl 4($v), %edx
-END
-
-BEGIN set %esi
- movl %ebx, ($v)
- movl %ecx, 4($v)
-END
-
-BEGIN xchg %esi
- movl ($v), %eax
- movl 4($v), %edx
- movl %ebx, ($v)
- movl %ecx, 4($v)
-END
-
-BEGIN add %ecx
- addl %eax, ($v)
- adcl %edx, 4($v)
-END

-BEGIN add_return %ecx
- addl ($v), %eax
- adcl 4($v), %edx
- movl %eax, ($v)
- movl %edx, 4($v)
-END
-
-BEGIN sub %ecx
- subl %eax, ($v)
- sbbl %edx, 4($v)
-END
-
-BEGIN sub_return %ecx
+#define RET_END \
+ RET; \
+ END
+
+#define v %ecx
+BEGIN(read)
+ movl (v), %eax
+ movl 4(v), %edx
+RET_END
+#undef v
+
+#define v %esi
+BEGIN(set)
+ movl %ebx, (v)
+ movl %ecx, 4(v)
+RET_END
+#undef v
+
+#define v %esi
+BEGIN(xchg)
+ movl (v), %eax
+ movl 4(v), %edx
+ movl %ebx, (v)
+ movl %ecx, 4(v)
+RET_END
+#undef v
+
+#define v %ecx
+BEGIN(add)
+ addl %eax, (v)
+ adcl %edx, 4(v)
+RET_END
+#undef v
+
+#define v %ecx
+BEGIN(add_return)
+ addl (v), %eax
+ adcl 4(v), %edx
+ movl %eax, (v)
+ movl %edx, 4(v)
+RET_END
+#undef v
+
+#define v %ecx
+BEGIN(sub)
+ subl %eax, (v)
+ sbbl %edx, 4(v)
+RET_END
+#undef v
+
+#define v %ecx
+BEGIN(sub_return)
negl %edx
negl %eax
sbbl $0, %edx
- addl ($v), %eax
- adcl 4($v), %edx
- movl %eax, ($v)
- movl %edx, 4($v)
-END
-
-BEGIN inc %esi
- addl $1, ($v)
- adcl $0, 4($v)
-END
-
-BEGIN inc_return %esi
- movl ($v), %eax
- movl 4($v), %edx
+ addl (v), %eax
+ adcl 4(v), %edx
+ movl %eax, (v)
+ movl %edx, 4(v)
+RET_END
+#undef v
+
+#define v %esi
+BEGIN(inc)
+ addl $1, (v)
+ adcl $0, 4(v)
+RET_END
+#undef v
+
+#define v %esi
+BEGIN(inc_return)
+ movl (v), %eax
+ movl 4(v), %edx
addl $1, %eax
adcl $0, %edx
- movl %eax, ($v)
- movl %edx, 4($v)
-END
-
-BEGIN dec %esi
- subl $1, ($v)
- sbbl $0, 4($v)
-END
-
-BEGIN dec_return %esi
- movl ($v), %eax
- movl 4($v), %edx
+ movl %eax, (v)
+ movl %edx, 4(v)
+RET_END
+#undef v
+
+#define v %esi
+BEGIN(dec)
+ subl $1, (v)
+ sbbl $0, 4(v)
+RET_END
+#undef v
+
+#define v %esi
+BEGIN(dec_return)
+ movl (v), %eax
+ movl 4(v), %edx
subl $1, %eax
sbbl $0, %edx
- movl %eax, ($v)
- movl %edx, 4($v)
-END
+ movl %eax, (v)
+ movl %edx, 4(v)
+RET_END
+#undef v

-BEGIN add_unless %ecx
+#define v %ecx
+BEGIN(add_unless)
addl %eax, %esi
adcl %edx, %edi
- addl ($v), %eax
- adcl 4($v), %edx
+ addl (v), %eax
+ adcl 4(v), %edx
cmpl %eax, %esi
je 3f
1:
- movl %eax, ($v)
- movl %edx, 4($v)
+ movl %eax, (v)
+ movl %edx, 4(v)
movl $1, %eax
2:
-RETURN
+ RET
3:
cmpl %edx, %edi
jne 1b
xorl %eax, %eax
jmp 2b
-END_
+END
+#undef v

-BEGIN inc_not_zero %esi
- movl ($v), %eax
- movl 4($v), %edx
+#define v %esi
+BEGIN(inc_not_zero)
+ movl (v), %eax
+ movl 4(v), %edx
testl %eax, %eax
je 3f
1:
addl $1, %eax
adcl $0, %edx
- movl %eax, ($v)
- movl %edx, 4($v)
+ movl %eax, (v)
+ movl %edx, 4(v)
movl $1, %eax
2:
-RETURN
+ RET
3:
testl %edx, %edx
jne 1b
jmp 2b
-END_
+END
+#undef v

-BEGIN dec_if_positive %esi
- movl ($v), %eax
- movl 4($v), %edx
+#define v %esi
+BEGIN(dec_if_positive)
+ movl (v), %eax
+ movl 4(v), %edx
subl $1, %eax
sbbl $0, %edx
js 1f
- movl %eax, ($v)
- movl %edx, 4($v)
+ movl %eax, (v)
+ movl %edx, 4(v)
1:
-END
+RET_END
+#undef v


2010-08-12 12:15:25

by Luca Barbieri

[permalink] [raw]
Subject: Re: [tip:x86/urgent] x86, asm: Refactor atomic64_386_32.S to support old binutils and be cleaner

Any reason you applied the older version I attached to the bug,
instead of the second one?

NiTr0 reported an additional issue with this version you committed,
which is solved by the second patch I attached.

2010-08-12 14:07:34

by H. Peter Anvin

[permalink] [raw]
Subject: Re: [tip:x86/urgent] x86, asm: Refactor atomic64_386_32.S to support old binutils and be cleaner

On 08/12/2010 05:15 AM, Luca Barbieri wrote:
> Any reason you applied the older version I attached to the bug,
> instead of the second one?
>
> NiTr0 reported an additional issue with this version you committed,
> which is solved by the second patch I attached.

I already had the first version queued up (I forgot to push it to the
public repository, however). I'll just put in the incremental changes.

-hpa

--
H. Peter Anvin, Intel Open Source Technology Center
I work for Intel. I don't speak on their behalf.

2010-08-12 15:18:26

by Luca Barbieri

[permalink] [raw]
Subject: Re: [tip:x86/urgent] x86, asm: Refactor atomic64_386_32.S to support old binutils and be cleaner

> I already had the first version queued up (I forgot to push it to the
> public repository, however). ?I'll just put in the incremental changes.

OK, thanks.

2010-08-12 15:34:06

by Luca Barbieri

[permalink] [raw]
Subject: [tip:x86/urgent] x86, asm: Use a lower case name for the end macro in atomic64_386_32.S

Commit-ID: 417484d47e115774745ef025bce712a102b6f86f
Gitweb: http://git.kernel.org/tip/417484d47e115774745ef025bce712a102b6f86f
Author: Luca Barbieri <[email protected]>
AuthorDate: Thu, 12 Aug 2010 07:00:35 -0700
Committer: H. Peter Anvin <[email protected]>
CommitDate: Thu, 12 Aug 2010 07:04:16 -0700

x86, asm: Use a lower case name for the end macro in atomic64_386_32.S

Use a lowercase name for the end macro, which somehow fixes a binutils 2.16
problem.

Signed-off-by: Luca Barbieri <[email protected]>
LKML-Reference: <[email protected]>
Signed-off-by: H. Peter Anvin <[email protected]>
---
arch/x86/lib/atomic64_386_32.S | 38 ++++++++++++++++++++------------------
1 files changed, 20 insertions(+), 18 deletions(-)

diff --git a/arch/x86/lib/atomic64_386_32.S b/arch/x86/lib/atomic64_386_32.S
index 78ee8e0..2cda60a 100644
--- a/arch/x86/lib/atomic64_386_32.S
+++ b/arch/x86/lib/atomic64_386_32.S
@@ -26,35 +26,37 @@
.endm

#define BEGIN(op) \
-.macro END; \
+.macro endp; \
CFI_ENDPROC; \
ENDPROC(atomic64_##op##_386); \
-.purgem END; \
+.purgem endp; \
.endm; \
ENTRY(atomic64_##op##_386); \
CFI_STARTPROC; \
LOCK v;

+#define ENDP endp
+
#define RET \
UNLOCK v; \
ret

-#define RET_END \
+#define RET_ENDP \
RET; \
- END
+ ENDP

#define v %ecx
BEGIN(read)
movl (v), %eax
movl 4(v), %edx
-RET_END
+RET_ENDP
#undef v

#define v %esi
BEGIN(set)
movl %ebx, (v)
movl %ecx, 4(v)
-RET_END
+RET_ENDP
#undef v

#define v %esi
@@ -63,14 +65,14 @@ BEGIN(xchg)
movl 4(v), %edx
movl %ebx, (v)
movl %ecx, 4(v)
-RET_END
+RET_ENDP
#undef v

#define v %ecx
BEGIN(add)
addl %eax, (v)
adcl %edx, 4(v)
-RET_END
+RET_ENDP
#undef v

#define v %ecx
@@ -79,14 +81,14 @@ BEGIN(add_return)
adcl 4(v), %edx
movl %eax, (v)
movl %edx, 4(v)
-RET_END
+RET_ENDP
#undef v

#define v %ecx
BEGIN(sub)
subl %eax, (v)
sbbl %edx, 4(v)
-RET_END
+RET_ENDP
#undef v

#define v %ecx
@@ -98,14 +100,14 @@ BEGIN(sub_return)
adcl 4(v), %edx
movl %eax, (v)
movl %edx, 4(v)
-RET_END
+RET_ENDP
#undef v

#define v %esi
BEGIN(inc)
addl $1, (v)
adcl $0, 4(v)
-RET_END
+RET_ENDP
#undef v

#define v %esi
@@ -116,14 +118,14 @@ BEGIN(inc_return)
adcl $0, %edx
movl %eax, (v)
movl %edx, 4(v)
-RET_END
+RET_ENDP
#undef v

#define v %esi
BEGIN(dec)
subl $1, (v)
sbbl $0, 4(v)
-RET_END
+RET_ENDP
#undef v

#define v %esi
@@ -134,7 +136,7 @@ BEGIN(dec_return)
sbbl $0, %edx
movl %eax, (v)
movl %edx, 4(v)
-RET_END
+RET_ENDP
#undef v

#define v %ecx
@@ -156,7 +158,7 @@ BEGIN(add_unless)
jne 1b
xorl %eax, %eax
jmp 2b
-END
+ENDP
#undef v

#define v %esi
@@ -177,7 +179,7 @@ BEGIN(inc_not_zero)
testl %edx, %edx
jne 1b
jmp 2b
-END
+ENDP
#undef v

#define v %esi
@@ -190,5 +192,5 @@ BEGIN(dec_if_positive)
movl %eax, (v)
movl %edx, 4(v)
1:
-RET_END
+RET_ENDP
#undef v

2010-08-19 19:06:52

by D. Stussy

[permalink] [raw]
Subject: Re: [tip:x86/urgent] x86, asm: Refactor atomic64_386_32.S to support old binutils and be cleaner

Has this patch been posted to the 2.6.35 kernel also, or just to 2.6.36? I don't think it's been posted to 2.6.35 where the problem it corrects was introduced.

"Greg KH" <[email protected]> has made a last call (tomorrow - Aug 20) for chnges for 2.6.35.3 and doesn't seem to have this. It's not in the prior two updates either.....

--- On Wed, 8/11/10, tip-bot for Luca Barbieri <[email protected]> wrote:
> Commit-ID:? 30246557a06bb20618bed906a06d1e1e0faa8bb4
> Gitweb:? ???http://git.kernel.org/tip/30246557a06bb20618bed906a06d1e1e0faa8bb4
> Author:? ???Luca Barbieri <[email protected]>
> AuthorDate: Fri, 6 Aug 2010 04:04:38 +0200
> Committer:? H. Peter Anvin <[email protected]>
> CommitDate: Wed, 11 Aug 2010 21:03:28 -0700
>
> x86, asm: Refactor atomic64_386_32.S to support old
> binutils and be cleaner
>
> The old code didn't work on binutils 2.12 because setting a symbol to
> a register apparently requires a fairly recent version.
>
> ...
>
> This fixes kernel bugzilla 16506.
...

2010-08-19 21:23:34

by H. Peter Anvin

[permalink] [raw]
Subject: Re: [tip:x86/urgent] x86, asm: Refactor atomic64_386_32.S to support old binutils and be cleaner

On 08/19/2010 12:06 PM, D. Stussy wrote:
> Has this patch been posted to the 2.6.35 kernel also, or just to 2.6.36? I don't think it's been posted to 2.6.35 where the problem it corrects was introduced.
>
> "Greg KH" <[email protected]> has made a last call (tomorrow - Aug 20) for chnges for 2.6.35.3 and doesn't seem to have this. It's not in the prior two updates either.....

It was Cc: <[email protected]>; it's up to Greg to include it or not.

[Greg: 30246557a06bb20618bed906a06d1e1e0faa8bb4]

-hpa

2010-08-20 08:21:19

by Ingo Molnar

[permalink] [raw]
Subject: Re: [tip:x86/urgent] x86, asm: Refactor atomic64_386_32.S to support old binutils and be cleaner


* H. Peter Anvin <[email protected]> wrote:

> On 08/19/2010 12:06 PM, D. Stussy wrote:
> > Has this patch been posted to the 2.6.35 kernel also, or just to 2.6.36? I don't think it's been posted to 2.6.35 where the problem it corrects was introduced.
> >
> > "Greg KH" <[email protected]> has made a last call (tomorrow - Aug 20) for chnges for 2.6.35.3 and doesn't seem to have this. It's not in the prior two updates either.....
>
> It was Cc: <[email protected]>; it's up to Greg to include it or not.

I think Greg generally includes all upstream commits marked with a -stable tag
- except if it wont apply cleanly, in which case he mails for a backport.

It of course has to fit in the regular stable release cycle, so the patches
dont propagate instantaneously.

Thanks,

Ingo