mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH] arm: Disable unaligned access if MMU is switched off
@ 2015-09-24  3:17 Andrey Smirnov
  2015-09-24  9:20 ` Lucas Stach
  0 siblings, 1 reply; 4+ messages in thread
From: Andrey Smirnov @ 2015-09-24  3:17 UTC (permalink / raw)
  To: barebox; +Cc: Andrey Smirnov

Form reading ARM architecture related documentation if appears that
while unaligned memory access is supported by the processor in general
it is not supported if MMU is disabled.

The problem in question can be easilty reproduced by building the code
without this patch, MMU disabled and trying to run 'memtest'
command. Which would in turn call mem_test() which would eventually
call show_progress(). That last function, if build without
-mno-unaligned-access would result in unaligned memory access which
would result in Barebox hanging.

This patch is a very conservative attempt to make sure that any code
that can potentially be executed with MMU disabled is built with
unaligned memory accesses disabled.

Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com>
---
 arch/arm/Makefile      | 14 ++++++++++++++
 scripts/Makefile.build |  2 +-
 2 files changed, 15 insertions(+), 1 deletion(-)

diff --git a/arch/arm/Makefile b/arch/arm/Makefile
index 721aa9b..9af4f3b 100644
--- a/arch/arm/Makefile
+++ b/arch/arm/Makefile
@@ -13,6 +13,20 @@ AS		+= -EL
 LD		+= -EL
 endif
 
+#
+# Unaligned access is not supported when MMU is disabled, so if MMU is
+# enabled early on, only PBL, part of which will be executed with MMU
+# diabled, would have to be build with -mno-unaligned-accesses,
+# otherwise set this flag globally
+#
+ifeq ($(CONFIG_MMU_EARLY),y)
+ifneq ($(CONFIG_PBL_IMAGE),y)
+PBL_CFLAGS += -mno-unaligned-access
+endif
+else
+CFLAGS += -mno-unaligned-access
+endif
+
 # This selects which instruction set is used.
 # Note that GCC does not numerically define an architecture version
 # macro, but instead defines a whole series of macros which makes
diff --git a/scripts/Makefile.build b/scripts/Makefile.build
index 56ee072..1624a7a 100644
--- a/scripts/Makefile.build
+++ b/scripts/Makefile.build
@@ -188,7 +188,7 @@ quiet_cmd_pbl_cc_o_c = PBLCC   $@
 
 ifndef CONFIG_MODVERSIONS
 cmd_cc_o_c = $(CC) $(c_flags) -c -o $@ $<
-cmd_pbl_cc_o_c = $(CC) -D__PBL__ $(c_flags) $(PBL_CPPFLAGS) -c -o $@ $<
+cmd_pbl_cc_o_c = $(CC) -D__PBL__ $(c_flags) $(PBL_CFLAGS) $(PBL_CPPFLAGS) -c -o $@ $<
 
 else
 # When module versioning is enabled the following steps are executed:
-- 
2.1.4


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

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

* Re: [PATCH] arm: Disable unaligned access if MMU is switched off
  2015-09-24  3:17 [PATCH] arm: Disable unaligned access if MMU is switched off Andrey Smirnov
@ 2015-09-24  9:20 ` Lucas Stach
  2015-09-29  7:32   ` Sascha Hauer
  0 siblings, 1 reply; 4+ messages in thread
From: Lucas Stach @ 2015-09-24  9:20 UTC (permalink / raw)
  To: Andrey Smirnov; +Cc: barebox

Am Mittwoch, den 23.09.2015, 20:17 -0700 schrieb Andrey Smirnov:
> Form reading ARM architecture related documentation if appears that
> while unaligned memory access is supported by the processor in general
> it is not supported if MMU is disabled.
> 
> The problem in question can be easilty reproduced by building the code
> without this patch, MMU disabled and trying to run 'memtest'
> command. Which would in turn call mem_test() which would eventually
> call show_progress(). That last function, if build without
> -mno-unaligned-access would result in unaligned memory access which
> would result in Barebox hanging.
> 
The reasoning given here seems sound. Unaligned accesses do only work on
cached memory on ARMv7.

> This patch is a very conservative attempt to make sure that any code
> that can potentially be executed with MMU disabled is built with
> unaligned memory accesses disabled.

The patch looks good as is, but I'm not sure we want to make this
distinction in behavior between the different config options. Given that
we should only have a very small amount of unaligned accesses anyway I
think it might make sense to enable the compiler workaround always. But
that would be for Sascha to decide.

> Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com>
> ---
>  arch/arm/Makefile      | 14 ++++++++++++++
>  scripts/Makefile.build |  2 +-
>  2 files changed, 15 insertions(+), 1 deletion(-)
> 
> diff --git a/arch/arm/Makefile b/arch/arm/Makefile
> index 721aa9b..9af4f3b 100644
> --- a/arch/arm/Makefile
> +++ b/arch/arm/Makefile
> @@ -13,6 +13,20 @@ AS		+= -EL
>  LD		+= -EL
>  endif
>  
> +#
> +# Unaligned access is not supported when MMU is disabled, so if MMU is
> +# enabled early on, only PBL, part of which will be executed with MMU
> +# diabled, would have to be build with -mno-unaligned-accesses,
> +# otherwise set this flag globally
> +#
> +ifeq ($(CONFIG_MMU_EARLY),y)
> +ifneq ($(CONFIG_PBL_IMAGE),y)
> +PBL_CFLAGS += -mno-unaligned-access
> +endif
> +else
> +CFLAGS += -mno-unaligned-access
> +endif
> +
>  # This selects which instruction set is used.
>  # Note that GCC does not numerically define an architecture version
>  # macro, but instead defines a whole series of macros which makes
> diff --git a/scripts/Makefile.build b/scripts/Makefile.build
> index 56ee072..1624a7a 100644
> --- a/scripts/Makefile.build
> +++ b/scripts/Makefile.build
> @@ -188,7 +188,7 @@ quiet_cmd_pbl_cc_o_c = PBLCC   $@
>  
>  ifndef CONFIG_MODVERSIONS
>  cmd_cc_o_c = $(CC) $(c_flags) -c -o $@ $<
> -cmd_pbl_cc_o_c = $(CC) -D__PBL__ $(c_flags) $(PBL_CPPFLAGS) -c -o $@ $<
> +cmd_pbl_cc_o_c = $(CC) -D__PBL__ $(c_flags) $(PBL_CFLAGS) $(PBL_CPPFLAGS) -c -o $@ $<
>  
>  else
>  # When module versioning is enabled the following steps are executed:

-- 
Pengutronix e.K.             | Lucas Stach                 |
Industrial Linux Solutions   | http://www.pengutronix.de/  |


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

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

* Re: [PATCH] arm: Disable unaligned access if MMU is switched off
  2015-09-24  9:20 ` Lucas Stach
@ 2015-09-29  7:32   ` Sascha Hauer
  2015-09-29 17:53     ` Andrey Smirnov
  0 siblings, 1 reply; 4+ messages in thread
From: Sascha Hauer @ 2015-09-29  7:32 UTC (permalink / raw)
  To: Lucas Stach; +Cc: Andrey Smirnov, barebox

On Thu, Sep 24, 2015 at 11:20:43AM +0200, Lucas Stach wrote:
> Am Mittwoch, den 23.09.2015, 20:17 -0700 schrieb Andrey Smirnov:
> > Form reading ARM architecture related documentation if appears that
> > while unaligned memory access is supported by the processor in general
> > it is not supported if MMU is disabled.
> > 
> > The problem in question can be easilty reproduced by building the code
> > without this patch, MMU disabled and trying to run 'memtest'
> > command. Which would in turn call mem_test() which would eventually
> > call show_progress(). That last function, if build without
> > -mno-unaligned-access would result in unaligned memory access which
> > would result in Barebox hanging.
> > 
> The reasoning given here seems sound. Unaligned accesses do only work on
> cached memory on ARMv7.
> 
> > This patch is a very conservative attempt to make sure that any code
> > that can potentially be executed with MMU disabled is built with
> > unaligned memory accesses disabled.
> 
> The patch looks good as is, but I'm not sure we want to make this
> distinction in behavior between the different config options. Given that
> we should only have a very small amount of unaligned accesses anyway I
> think it might make sense to enable the compiler workaround always. But
> that would be for Sascha to decide.

Even with MMU enabled in the config we still run some initial portions
of the code with MMU disabled, so it seems safer to enable this option
unconditionally.
On the other hand disabling unaligned accesses makes the image around
1.5% bigger (tested with imx_v7_defconfig), so the compiler really makes
use of this option.
Ok, better safe than sorry, so I vote for always passing
-mno-unaligned-accesses.

Sascha

-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

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

* Re: [PATCH] arm: Disable unaligned access if MMU is switched off
  2015-09-29  7:32   ` Sascha Hauer
@ 2015-09-29 17:53     ` Andrey Smirnov
  0 siblings, 0 replies; 4+ messages in thread
From: Andrey Smirnov @ 2015-09-29 17:53 UTC (permalink / raw)
  To: Sascha Hauer; +Cc: barebox

>
> Even with MMU enabled in the config we still run some initial portions
> of the code with MMU disabled, so it seems safer to enable this option
> unconditionally.
> On the other hand disabling unaligned accesses makes the image around
> 1.5% bigger (tested with imx_v7_defconfig), so the compiler really makes
> use of this option.
> Ok, better safe than sorry, so I vote for always passing
> -mno-unaligned-accesses.

OK, sounds good, I'll update the patch and send the second version shortly.

>
> Sascha
>
> --
> Pengutronix e.K.                           |                             |
> Industrial Linux Solutions                 | http://www.pengutronix.de/  |
> Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
> Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

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

end of thread, other threads:[~2015-09-29 17:53 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-09-24  3:17 [PATCH] arm: Disable unaligned access if MMU is switched off Andrey Smirnov
2015-09-24  9:20 ` Lucas Stach
2015-09-29  7:32   ` Sascha Hauer
2015-09-29 17:53     ` Andrey Smirnov

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