linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 20/23] ARM: signal: sigreturn_codes should be endian neutral to work in BE8
  2013-10-08 22:34 New big-endian patch series against 3.12-rc4 Ben Dooks
@ 2013-10-08 22:34 ` Ben Dooks
  2013-11-05 21:18   ` Uwe Kleine-König
  0 siblings, 1 reply; 6+ messages in thread
From: Ben Dooks @ 2013-10-08 22:34 UTC (permalink / raw)
  To: linux-arm-kernel

From: Victor Kamensky <victor.kamensky@linaro.org>

In case of BE8 kernel data is in BE order whereas code stays in LE
order. Move sigreturn_codes to separate .S file and use proper
assembler mnemonics for these code snippets. In this case compiler
will take care of proper instructions byteswaps for BE8 case.
Change assumes that sufficiently Thumb-capable tools are used to
build kernel.

Problem was discovered during ltp testing of BE system: all rt_sig*
tests failed. Tested against the same tests in both BE and LE modes.

Signed-off-by: Victor Kamensky <victor.kamensky@linaro.org>
Reviewed-by: Dave Martin <Dave.Martin@arm.com>
Signed-off-by: Ben Dooks <ben.dooks@codethink.co.uk>
---
 arch/arm/kernel/Makefile          |  3 +-
 arch/arm/kernel/signal.c          | 24 +-----------
 arch/arm/kernel/sigreturn_codes.S | 80 +++++++++++++++++++++++++++++++++++++++
 3 files changed, 83 insertions(+), 24 deletions(-)
 create mode 100644 arch/arm/kernel/sigreturn_codes.S

diff --git a/arch/arm/kernel/Makefile b/arch/arm/kernel/Makefile
index 5140df5f..39c9834 100644
--- a/arch/arm/kernel/Makefile
+++ b/arch/arm/kernel/Makefile
@@ -17,7 +17,8 @@ CFLAGS_REMOVE_return_address.o = -pg
 
 obj-y		:= elf.o entry-common.o irq.o opcodes.o \
 		   process.o ptrace.o return_address.o \
-		   setup.o signal.o stacktrace.o sys_arm.o time.o traps.o
+		   setup.o signal.o sigreturn_codes.o \
+		   stacktrace.o sys_arm.o time.o traps.o
 
 obj-$(CONFIG_ATAGS)		+= atags_parse.o
 obj-$(CONFIG_ATAGS_PROC)	+= atags_proc.o
diff --git a/arch/arm/kernel/signal.c b/arch/arm/kernel/signal.c
index ab33042..64845fc 100644
--- a/arch/arm/kernel/signal.c
+++ b/arch/arm/kernel/signal.c
@@ -21,29 +21,7 @@
 #include <asm/unistd.h>
 #include <asm/vfp.h>
 
-/*
- * For ARM syscalls, we encode the syscall number into the instruction.
- */
-#define SWI_SYS_SIGRETURN	(0xef000000|(__NR_sigreturn)|(__NR_OABI_SYSCALL_BASE))
-#define SWI_SYS_RT_SIGRETURN	(0xef000000|(__NR_rt_sigreturn)|(__NR_OABI_SYSCALL_BASE))
-
-/*
- * With EABI, the syscall number has to be loaded into r7.
- */
-#define MOV_R7_NR_SIGRETURN	(0xe3a07000 | (__NR_sigreturn - __NR_SYSCALL_BASE))
-#define MOV_R7_NR_RT_SIGRETURN	(0xe3a07000 | (__NR_rt_sigreturn - __NR_SYSCALL_BASE))
-
-/*
- * For Thumb syscalls, we pass the syscall number via r7.  We therefore
- * need two 16-bit instructions.
- */
-#define SWI_THUMB_SIGRETURN	(0xdf00 << 16 | 0x2700 | (__NR_sigreturn - __NR_SYSCALL_BASE))
-#define SWI_THUMB_RT_SIGRETURN	(0xdf00 << 16 | 0x2700 | (__NR_rt_sigreturn - __NR_SYSCALL_BASE))
-
-static const unsigned long sigreturn_codes[7] = {
-	MOV_R7_NR_SIGRETURN,    SWI_SYS_SIGRETURN,    SWI_THUMB_SIGRETURN,
-	MOV_R7_NR_RT_SIGRETURN, SWI_SYS_RT_SIGRETURN, SWI_THUMB_RT_SIGRETURN,
-};
+extern const unsigned long sigreturn_codes[7];
 
 static unsigned long signal_return_offset;
 
diff --git a/arch/arm/kernel/sigreturn_codes.S b/arch/arm/kernel/sigreturn_codes.S
new file mode 100644
index 0000000..3c5d0f2
--- /dev/null
+++ b/arch/arm/kernel/sigreturn_codes.S
@@ -0,0 +1,80 @@
+/*
+ * sigreturn_codes.S - code sinpets for sigreturn syscalls
+ *
+ * Created by:	Victor Kamensky, 2013-08-13
+ * Copyright:	(C) 2013  Linaro Limited
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ */
+
+#include <asm/unistd.h>
+
+/*
+ * For ARM syscalls, we encode the syscall number into the instruction.
+ * With EABI, the syscall number has to be loaded into r7. As result
+ * ARM syscall sequence snippet will have move and svc in .arm encoding
+ *
+ * For Thumb syscalls, we pass the syscall number via r7.  We therefore
+ * need two 16-bit instructions in .thumb encoding
+ *
+ * Please note sigreturn_codes code are not executed in place. Instead
+ * they just copied by kernel into appropriate places. Code inside of
+ * arch/arm/kernel/signal.c is very sensitive to layout of these code
+ * snippets.
+ */
+
+#if __LINUX_ARM_ARCH__ <= 4
+	/*
+	 * Note we manually set minimally required arch that supports
+	 * required thumb opcodes for early arch versions. It is OK
+	 * for this file to be used in combination with other
+	 * lower arch variants, since these code snippets are only
+	 * used as input data.
+	 */
+	.arch armv4t
+#endif
+
+	.section .rodata
+	.global sigreturn_codes
+	.type	sigreturn_codes, #object
+
+	.arm
+
+sigreturn_codes:
+
+	/* ARM sigreturn syscall code snippet */
+	mov	r7, #(__NR_sigreturn - __NR_SYSCALL_BASE)
+	swi	#(__NR_sigreturn)|(__NR_OABI_SYSCALL_BASE)
+
+	/* Thumb sigreturn syscall code snippet */
+	.thumb
+	movs	r7, #(__NR_sigreturn - __NR_SYSCALL_BASE)
+	swi	#0
+
+	/* ARM sigreturn_rt syscall code snippet */
+	.arm
+	mov	r7, #(__NR_rt_sigreturn - __NR_SYSCALL_BASE)
+	swi	#(__NR_rt_sigreturn)|(__NR_OABI_SYSCALL_BASE)
+
+	/* Thumb sigreturn_rt syscall code snippet */
+	.thumb
+	movs	r7, #(__NR_rt_sigreturn - __NR_SYSCALL_BASE)
+	swi	#0
+
+	/*
+	 * Note on addtional space: setup_return in signal.c
+	 * algorithm uses two words copy regardless whether
+	 * it is thumb case or not, so we need additional
+	 * word after real last entry.
+	 */
+	.arm
+	.space	4
+
+	.size	sigreturn_codes, . - sigreturn_codes
-- 
1.8.4.rc3

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

* [PATCH 20/23] ARM: signal: sigreturn_codes should be endian neutral to work in BE8
  2013-10-08 22:34 ` [PATCH 20/23] ARM: signal: sigreturn_codes should be endian neutral to work in BE8 Ben Dooks
@ 2013-11-05 21:18   ` Uwe Kleine-König
  2013-11-06  3:48     ` Victor Kamensky
  0 siblings, 1 reply; 6+ messages in thread
From: Uwe Kleine-König @ 2013-11-05 21:18 UTC (permalink / raw)
  To: linux-arm-kernel

Hello,

On Wed, Oct 09, 2013 at 12:34:36AM +0200, Ben Dooks wrote:
> From: Victor Kamensky <victor.kamensky@linaro.org>
> 
> In case of BE8 kernel data is in BE order whereas code stays in LE
> order. Move sigreturn_codes to separate .S file and use proper
> assembler mnemonics for these code snippets. In this case compiler
> will take care of proper instructions byteswaps for BE8 case.
> Change assumes that sufficiently Thumb-capable tools are used to
> build kernel.
> 
> Problem was discovered during ltp testing of BE system: all rt_sig*
> tests failed. Tested against the same tests in both BE and LE modes.
> 
> Signed-off-by: Victor Kamensky <victor.kamensky@linaro.org>
> Reviewed-by: Dave Martin <Dave.Martin@arm.com>
> Signed-off-by: Ben Dooks <ben.dooks@codethink.co.uk>
> ---
>  arch/arm/kernel/Makefile          |  3 +-
>  arch/arm/kernel/signal.c          | 24 +-----------
>  arch/arm/kernel/sigreturn_codes.S | 80 +++++++++++++++++++++++++++++++++++++++
>  3 files changed, 83 insertions(+), 24 deletions(-)
>  create mode 100644 arch/arm/kernel/sigreturn_codes.S
> 
> diff --git a/arch/arm/kernel/Makefile b/arch/arm/kernel/Makefile
> index 5140df5f..39c9834 100644
> --- a/arch/arm/kernel/Makefile
> +++ b/arch/arm/kernel/Makefile
> @@ -17,7 +17,8 @@ CFLAGS_REMOVE_return_address.o = -pg
>  
>  obj-y		:= elf.o entry-common.o irq.o opcodes.o \
>  		   process.o ptrace.o return_address.o \
> -		   setup.o signal.o stacktrace.o sys_arm.o time.o traps.o
> +		   setup.o signal.o sigreturn_codes.o \
> +		   stacktrace.o sys_arm.o time.o traps.o
>  
>  obj-$(CONFIG_ATAGS)		+= atags_parse.o
>  obj-$(CONFIG_ATAGS_PROC)	+= atags_proc.o
> diff --git a/arch/arm/kernel/signal.c b/arch/arm/kernel/signal.c
> index ab33042..64845fc 100644
> --- a/arch/arm/kernel/signal.c
> +++ b/arch/arm/kernel/signal.c
> @@ -21,29 +21,7 @@
>  #include <asm/unistd.h>
>  #include <asm/vfp.h>
>  
> -/*
> - * For ARM syscalls, we encode the syscall number into the instruction.
> - */
> -#define SWI_SYS_SIGRETURN	(0xef000000|(__NR_sigreturn)|(__NR_OABI_SYSCALL_BASE))
> -#define SWI_SYS_RT_SIGRETURN	(0xef000000|(__NR_rt_sigreturn)|(__NR_OABI_SYSCALL_BASE))
> -
> -/*
> - * With EABI, the syscall number has to be loaded into r7.
> - */
> -#define MOV_R7_NR_SIGRETURN	(0xe3a07000 | (__NR_sigreturn - __NR_SYSCALL_BASE))
> -#define MOV_R7_NR_RT_SIGRETURN	(0xe3a07000 | (__NR_rt_sigreturn - __NR_SYSCALL_BASE))
> -
> -/*
> - * For Thumb syscalls, we pass the syscall number via r7.  We therefore
> - * need two 16-bit instructions.
> - */
> -#define SWI_THUMB_SIGRETURN	(0xdf00 << 16 | 0x2700 | (__NR_sigreturn - __NR_SYSCALL_BASE))
> -#define SWI_THUMB_RT_SIGRETURN	(0xdf00 << 16 | 0x2700 | (__NR_rt_sigreturn - __NR_SYSCALL_BASE))
> -
> -static const unsigned long sigreturn_codes[7] = {
> -	MOV_R7_NR_SIGRETURN,    SWI_SYS_SIGRETURN,    SWI_THUMB_SIGRETURN,
> -	MOV_R7_NR_RT_SIGRETURN, SWI_SYS_RT_SIGRETURN, SWI_THUMB_RT_SIGRETURN,
> -};
> +extern const unsigned long sigreturn_codes[7];
>  
>  static unsigned long signal_return_offset;
>  
> diff --git a/arch/arm/kernel/sigreturn_codes.S b/arch/arm/kernel/sigreturn_codes.S
> new file mode 100644
> index 0000000..3c5d0f2
> --- /dev/null
> +++ b/arch/arm/kernel/sigreturn_codes.S
> @@ -0,0 +1,80 @@
> +/*
> + * sigreturn_codes.S - code sinpets for sigreturn syscalls
> + *
> + * Created by:	Victor Kamensky, 2013-08-13
> + * Copyright:	(C) 2013  Linaro Limited
> + *
> + * This program is free software; you can redistribute it and/or modify
> + * it under the terms of the GNU General Public License version 2 as
> + * published by the Free Software Foundation.
> + *
> + * This program is distributed in the hope that it will be useful,
> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
> + * GNU General Public License for more details.
> + */
> +
> +#include <asm/unistd.h>
> +
> +/*
> + * For ARM syscalls, we encode the syscall number into the instruction.
> + * With EABI, the syscall number has to be loaded into r7. As result
> + * ARM syscall sequence snippet will have move and svc in .arm encoding
> + *
> + * For Thumb syscalls, we pass the syscall number via r7.  We therefore
> + * need two 16-bit instructions in .thumb encoding
> + *
> + * Please note sigreturn_codes code are not executed in place. Instead
> + * they just copied by kernel into appropriate places. Code inside of
> + * arch/arm/kernel/signal.c is very sensitive to layout of these code
> + * snippets.
> + */
> +
> +#if __LINUX_ARM_ARCH__ <= 4
> +	/*
> +	 * Note we manually set minimally required arch that supports
> +	 * required thumb opcodes for early arch versions. It is OK
> +	 * for this file to be used in combination with other
> +	 * lower arch variants, since these code snippets are only
> +	 * used as input data.
> +	 */
> +	.arch armv4t
> +#endif
> +
> +	.section .rodata
> +	.global sigreturn_codes
> +	.type	sigreturn_codes, #object
> +
> +	.arm
This breaks a ARMv7-M build, see
http://arm-soc.lixom.net/buildlogs/misc/next-20131105-1-g2b29c44/buildall.arm.efm32_defconfig.log.failed

Best regards
Uwe

-- 
Pengutronix e.K.                           | Uwe Kleine-K?nig            |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |

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

* [PATCH 20/23] ARM: signal: sigreturn_codes should be endian neutral to work in BE8
  2013-11-05 21:18   ` Uwe Kleine-König
@ 2013-11-06  3:48     ` Victor Kamensky
  2013-11-06  8:46       ` Uwe Kleine-König
  0 siblings, 1 reply; 6+ messages in thread
From: Victor Kamensky @ 2013-11-06  3:48 UTC (permalink / raw)
  To: linux-arm-kernel

Hi Uwe, and All,

On 5 November 2013 13:18, Uwe Kleine-K?nig
<u.kleine-koenig@pengutronix.de> wrote:

<snip>

>> +
>> +#if __LINUX_ARM_ARCH__ <= 4
>> +     /*
>> +      * Note we manually set minimally required arch that supports
>> +      * required thumb opcodes for early arch versions. It is OK
>> +      * for this file to be used in combination with other
>> +      * lower arch variants, since these code snippets are only
>> +      * used as input data.
>> +      */
>> +     .arch armv4t
>> +#endif
>> +
>> +     .section .rodata
>> +     .global sigreturn_codes
>> +     .type   sigreturn_codes, #object
>> +
>> +     .arm
> This breaks a ARMv7-M build, see
> http://arm-soc.lixom.net/buildlogs/misc/next-20131105-1-g2b29c44/buildall.arm.efm32_defconfig.log.failed

Could you please point to git tree and branch from which efm32_defconfig
was built - I could not find such in my tree.
I would like to be able to reproduce this failure.

This issue looks similar to

http://lists.infradead.org/pipermail/linux-arm-kernel/2013-September/197636.html
http://lists.infradead.org/pipermail/linux-arm-kernel/2013-September/197637.html

which is fixed as in left quoted patch above. but this time
is not thumb opcodes are problem, but rather arm opcodes.
However it seems to be more harder.

I have tried to enable arm opcodes with '.arch armv7a' directive. But
unlike above case of v4t and v7a. .o file with armv7a and armv7m are
not compatible and cannot be linked together even though
sigreturn_codes snipet used as data.

I see only way fix that is to come back to manually constructed
opcodes and use macros from <asm/opcodes.h> to deal with
endianity issues. Effectively it will back out my v3 version of patch
and apply v1 version as I posted here:

http://lists.infradead.org/pipermail/linux-arm-kernel/2013-August/191543.html

Adding bunch of ifdef into sigreturns_codes.S could be another
option, but IMHO it seems to be move in wrong direction. I would
rather see constructed opcodes.

Any other ideas?

Thanks,
Victor

> Best regards
> Uwe
>
> --
> Pengutronix e.K.                           | Uwe Kleine-K?nig            |
> Industrial Linux Solutions                 | http://www.pengutronix.de/  |

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

* [PATCH 20/23] ARM: signal: sigreturn_codes should be endian neutral to work in BE8
  2013-11-06  3:48     ` Victor Kamensky
@ 2013-11-06  8:46       ` Uwe Kleine-König
  0 siblings, 0 replies; 6+ messages in thread
From: Uwe Kleine-König @ 2013-11-06  8:46 UTC (permalink / raw)
  To: linux-arm-kernel

Hello Victor,

On Tue, Nov 05, 2013 at 07:48:42PM -0800, Victor Kamensky wrote:
> Hi Uwe, and All,
> 
> On 5 November 2013 13:18, Uwe Kleine-K?nig
> <u.kleine-koenig@pengutronix.de> wrote:
> 
> <snip>
> 
> >> +
> >> +#if __LINUX_ARM_ARCH__ <= 4
> >> +     /*
> >> +      * Note we manually set minimally required arch that supports
> >> +      * required thumb opcodes for early arch versions. It is OK
> >> +      * for this file to be used in combination with other
> >> +      * lower arch variants, since these code snippets are only
> >> +      * used as input data.
> >> +      */
> >> +     .arch armv4t
> >> +#endif
> >> +
> >> +     .section .rodata
> >> +     .global sigreturn_codes
> >> +     .type   sigreturn_codes, #object
> >> +
> >> +     .arm
> > This breaks a ARMv7-M build, see
> > http://arm-soc.lixom.net/buildlogs/misc/next-20131105-1-g2b29c44/buildall.arm.efm32_defconfig.log.failed
> 
> Could you please point to git tree and branch from which efm32_defconfig
> was built - I could not find such in my tree.
next-20131105 contains both, your patch and the efm32 support.
(i.e. git://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git
next/master)

The problem is, that armv7-M doesn't support ARM, only Thumb-2.
If you go the ifdef route, CONFIG_CPU_THUMBONLY is what you want to use.

Best regards
Uwe

-- 
Pengutronix e.K.                           | Uwe Kleine-K?nig            |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |

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

* [PATCH 20/23] ARM: signal: sigreturn_codes should be endian neutral to work in BE8
       [not found] <20131111141258.GA3166@localhost.localdomain>
@ 2013-11-11 17:00 ` Uwe Kleine-König
  2013-11-12  6:41 ` Victor Kamensky
  1 sibling, 0 replies; 6+ messages in thread
From: Uwe Kleine-König @ 2013-11-11 17:00 UTC (permalink / raw)
  To: linux-arm-kernel

Hello,

On Mon, Nov 11, 2013 at 02:13:02PM +0000, Dave Martin wrote:
> On Tue, Nov 05, 2013 at 10:18:07PM +0100, Uwe Kleine-K?nig wrote:
> > > +	.section .rodata
> > > +	.global sigreturn_codes
> > > +	.type	sigreturn_codes, #object
> > > +
> > > +	.arm
> > This breaks a ARMv7-M build, see
> > http://arm-soc.lixom.net/buildlogs/misc/next-20131105-1-g2b29c44/buildall.arm.efm32_defconfig.log.failed
> 
> Hmmm, looks like we missed this scenario.
Did you see Victor already addressing this failure with a patch?

Best regards
Uwe

-- 
Pengutronix e.K.                           | Uwe Kleine-K?nig            |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |

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

* [PATCH 20/23] ARM: signal: sigreturn_codes should be endian neutral to work in BE8
       [not found] <20131111141258.GA3166@localhost.localdomain>
  2013-11-11 17:00 ` [PATCH 20/23] ARM: signal: sigreturn_codes should be endian neutral to work in BE8 Uwe Kleine-König
@ 2013-11-12  6:41 ` Victor Kamensky
  1 sibling, 0 replies; 6+ messages in thread
From: Victor Kamensky @ 2013-11-12  6:41 UTC (permalink / raw)
  To: linux-arm-kernel

On 11 November 2013 06:13, Dave Martin <Dave.Martin@arm.com> wrote:
> On Tue, Nov 05, 2013 at 10:18:07PM +0100, Uwe Kleine-K?nig wrote:
>> Hello,
>>
>> On Wed, Oct 09, 2013 at 12:34:36AM +0200, Ben Dooks wrote:
>> > From: Victor Kamensky <victor.kamensky@linaro.org>
>> >
>> > In case of BE8 kernel data is in BE order whereas code stays in LE
>> > order. Move sigreturn_codes to separate .S file and use proper
>> > assembler mnemonics for these code snippets. In this case compiler
>> > will take care of proper instructions byteswaps for BE8 case.
>> > Change assumes that sufficiently Thumb-capable tools are used to
>> > build kernel.
>> >
>> > Problem was discovered during ltp testing of BE system: all rt_sig*
>> > tests failed. Tested against the same tests in both BE and LE modes.
>> >
>> > Signed-off-by: Victor Kamensky <victor.kamensky@linaro.org>
>> > Reviewed-by: Dave Martin <Dave.Martin@arm.com>
>> > Signed-off-by: Ben Dooks <ben.dooks@codethink.co.uk>
>> > ---
>> >  arch/arm/kernel/Makefile          |  3 +-
>> >  arch/arm/kernel/signal.c          | 24 +-----------
>> >  arch/arm/kernel/sigreturn_codes.S | 80 +++++++++++++++++++++++++++++++++++++++
>> >  3 files changed, 83 insertions(+), 24 deletions(-)
>> >  create mode 100644 arch/arm/kernel/sigreturn_codes.S
>> >
>> > diff --git a/arch/arm/kernel/Makefile b/arch/arm/kernel/Makefile
>> > index 5140df5f..39c9834 100644
>> > --- a/arch/arm/kernel/Makefile
>> > +++ b/arch/arm/kernel/Makefile
>> > @@ -17,7 +17,8 @@ CFLAGS_REMOVE_return_address.o = -pg
>> >
>> >  obj-y              := elf.o entry-common.o irq.o opcodes.o \
>> >                process.o ptrace.o return_address.o \
>> > -              setup.o signal.o stacktrace.o sys_arm.o time.o traps.o
>> > +              setup.o signal.o sigreturn_codes.o \
>> > +              stacktrace.o sys_arm.o time.o traps.o
>> >
>> >  obj-$(CONFIG_ATAGS)                += atags_parse.o
>> >  obj-$(CONFIG_ATAGS_PROC)   += atags_proc.o
>> > diff --git a/arch/arm/kernel/signal.c b/arch/arm/kernel/signal.c
>> > index ab33042..64845fc 100644
>> > --- a/arch/arm/kernel/signal.c
>> > +++ b/arch/arm/kernel/signal.c
>> > @@ -21,29 +21,7 @@
>> >  #include <asm/unistd.h>
>> >  #include <asm/vfp.h>
>> >
>> > -/*
>> > - * For ARM syscalls, we encode the syscall number into the instruction.
>> > - */
>> > -#define SWI_SYS_SIGRETURN  (0xef000000|(__NR_sigreturn)|(__NR_OABI_SYSCALL_BASE))
>> > -#define SWI_SYS_RT_SIGRETURN       (0xef000000|(__NR_rt_sigreturn)|(__NR_OABI_SYSCALL_BASE))
>> > -
>> > -/*
>> > - * With EABI, the syscall number has to be loaded into r7.
>> > - */
>> > -#define MOV_R7_NR_SIGRETURN        (0xe3a07000 | (__NR_sigreturn - __NR_SYSCALL_BASE))
>> > -#define MOV_R7_NR_RT_SIGRETURN     (0xe3a07000 | (__NR_rt_sigreturn - __NR_SYSCALL_BASE))
>> > -
>> > -/*
>> > - * For Thumb syscalls, we pass the syscall number via r7.  We therefore
>> > - * need two 16-bit instructions.
>> > - */
>> > -#define SWI_THUMB_SIGRETURN        (0xdf00 << 16 | 0x2700 | (__NR_sigreturn - __NR_SYSCALL_BASE))
>> > -#define SWI_THUMB_RT_SIGRETURN     (0xdf00 << 16 | 0x2700 | (__NR_rt_sigreturn - __NR_SYSCALL_BASE))
>> > -
>> > -static const unsigned long sigreturn_codes[7] = {
>> > -   MOV_R7_NR_SIGRETURN,    SWI_SYS_SIGRETURN,    SWI_THUMB_SIGRETURN,
>> > -   MOV_R7_NR_RT_SIGRETURN, SWI_SYS_RT_SIGRETURN, SWI_THUMB_RT_SIGRETURN,
>> > -};
>> > +extern const unsigned long sigreturn_codes[7];
>> >
>> >  static unsigned long signal_return_offset;
>> >
>> > diff --git a/arch/arm/kernel/sigreturn_codes.S b/arch/arm/kernel/sigreturn_codes.S
>> > new file mode 100644
>> > index 0000000..3c5d0f2
>> > --- /dev/null
>> > +++ b/arch/arm/kernel/sigreturn_codes.S
>> > @@ -0,0 +1,80 @@
>> > +/*
>> > + * sigreturn_codes.S - code sinpets for sigreturn syscalls
>> > + *
>> > + * Created by:     Victor Kamensky, 2013-08-13
>> > + * Copyright:      (C) 2013  Linaro Limited
>> > + *
>> > + * This program is free software; you can redistribute it and/or modify
>> > + * it under the terms of the GNU General Public License version 2 as
>> > + * published by the Free Software Foundation.
>> > + *
>> > + * This program is distributed in the hope that it will be useful,
>> > + * but WITHOUT ANY WARRANTY; without even the implied warranty of
>> > + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
>> > + * GNU General Public License for more details.
>> > + */
>> > +
>> > +#include <asm/unistd.h>
>> > +
>> > +/*
>> > + * For ARM syscalls, we encode the syscall number into the instruction.
>> > + * With EABI, the syscall number has to be loaded into r7. As result
>> > + * ARM syscall sequence snippet will have move and svc in .arm encoding
>> > + *
>> > + * For Thumb syscalls, we pass the syscall number via r7.  We therefore
>> > + * need two 16-bit instructions in .thumb encoding
>> > + *
>> > + * Please note sigreturn_codes code are not executed in place. Instead
>> > + * they just copied by kernel into appropriate places. Code inside of
>> > + * arch/arm/kernel/signal.c is very sensitive to layout of these code
>> > + * snippets.
>> > + */
>> > +
>> > +#if __LINUX_ARM_ARCH__ <= 4
>> > +   /*
>> > +    * Note we manually set minimally required arch that supports
>> > +    * required thumb opcodes for early arch versions. It is OK
>> > +    * for this file to be used in combination with other
>> > +    * lower arch variants, since these code snippets are only
>> > +    * used as input data.
>> > +    */
>> > +   .arch armv4t
>> > +#endif
>> > +
>> > +   .section .rodata
>> > +   .global sigreturn_codes
>> > +   .type   sigreturn_codes, #object
>> > +
>> > +   .arm
>> This breaks a ARMv7-M build, see
>> http://arm-soc.lixom.net/buildlogs/misc/next-20131105-1-g2b29c44/buildall.arm.efm32_defconfig.log.failed
>
> Hmmm, looks like we missed this scenario.
>
> Since the conditional .arch directive is supposed to set some CPU that
> can assemble the relevant instructions, maybe we just need to change the
> condition.
>
> Does the following help?
>
> Cheers
> ---Dave
>
>
> diff --git a/arch/arm/kernel/sigreturn_codes.S b/arch/arm/kernel/sigreturn_codes.S
> index 3c5d0f2..bfec1ff 100644
> --- a/arch/arm/kernel/sigreturn_codes.S
> +++ b/arch/arm/kernel/sigreturn_codes.S
> @@ -30,7 +30,7 @@
>   * snippets.
>   */
>
> -#if __LINUX_ARM_ARCH__ <= 4
> +#if __LINUX_ARM_ARCH__ <= 4 || defined(CONFIG_CPU_THUMBONLY)
>         /*
>          * Note we manually set minimally required arch that supports
>          * required thumb opcodes for early arch versions. It is OK

Interesting ... I thought I've tried above, but turns out I've tried

#ifdef CONFIG_CPU_THUMBONLY
        .arch armv7a
#endif

And it fails as I mentioned in previous email. The error looks
like this:

arm-linux-gnueabihf-ld: error: arch/arm/kernel/sigreturn_codes.o:
Conflicting architecture profiles A/M
arm-linux-gnueabihf-ld: failed to merge target specific data of file
arch/arm/kernel/sigreturn_codes.o

I.e armv7a and armv7m are not compatible. But if I try
literally as above it will do '.arch armv4t' and that one is
compatible with armv7m! It links fine and sigreturn_opcodes
looks correctly.

This looks much cleaner. But I wonder whether such
solution is fragile ... Any concerns/comments here?
I will check binutils source tomorrow. And if it looks
solid I will send V2 of patch based on this suggestion.

Thanks,
Victor

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

end of thread, other threads:[~2013-11-12  6:41 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <20131111141258.GA3166@localhost.localdomain>
2013-11-11 17:00 ` [PATCH 20/23] ARM: signal: sigreturn_codes should be endian neutral to work in BE8 Uwe Kleine-König
2013-11-12  6:41 ` Victor Kamensky
2013-10-08 22:34 New big-endian patch series against 3.12-rc4 Ben Dooks
2013-10-08 22:34 ` [PATCH 20/23] ARM: signal: sigreturn_codes should be endian neutral to work in BE8 Ben Dooks
2013-11-05 21:18   ` Uwe Kleine-König
2013-11-06  3:48     ` Victor Kamensky
2013-11-06  8:46       ` Uwe Kleine-König

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 NNTP newsgroup(s).