mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Robin Murphy <robin.murphy@arm.com>
To: Romain Izard <romain.izard.pro@gmail.com>,
	Russell King <linux@armlinux.org.uk>,
	Al Viro <viro@zeniv.linux.org.uk>,
	Ard Biesheuvel <ard.biesheuvel@linaro.org>,
	Arnd Bergmann <arnd@arndb.de>
Cc: linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org
Subject: Re: [PATCH] ARM: unaligned.h: Use an arch-specific version
Date: Wed, 20 Sep 2017 18:16:45 +0100	[thread overview]
Message-ID: <8a7a3680-c021-402b-c0f5-f10363051543@arm.com> (raw)
In-Reply-To: <20170920151802.7609-1-romain.izard.pro@gmail.com>

Hi Romain,

On 20/09/17 16:18, Romain Izard wrote:
> For the 32-bit ARM architecture, unaligned access support is variable.
> On a chip without a MMU, an unaligned access returns a rotated data word
> and must be avoided.

Nit: that sentence is not really true - there are CPUs without MMUs that
still support alignment checking (e.g. ARM1156), and more importantly
the rotation thing is only true for LDR/LDRH - LDM always just ignores
the bottom two bits of the address, and LDRD doesn't make any guarantee
at all of what you might get back (and stores are even worse). I think
it suffices to say that in the absence of alignment checking, the
results of unaligned accesses are inconsistent and impossible to rely upon.

Robin.

> When a MMU is available, it can be trapped. On ARMv6 or ARMv7, it can also
> be handled by the hardware, depending on the type of access instruction.
> Unaligned access of 32 bits or less are corrected, while larger access
> provoke a trap.
> 
> Unfortunately, the compiler is able to merge two 32-bit access that
> would generate a LDR instruction, that works on unaligned access, into a
> single LDM access that will not work. This is not a common situation,
> but it has been observed in the LZ4 decompression code.
> 
> To prevent this type of optimization, it is necessary to change the
> explicit accessors for unaligned addresses from those defined in the
> access_ok.h header, to those defined in the packed_struct.h header.
> 
> Add an arch-specific header to ARM, to retain other optimizations that
> rely on HAVE_EFFICIENT_UNALIGNED_ACCESS, while making sure that access
> that explicitly rely on the unaligned accessors are correctly handled by
> the compiler.
> 
> Signed-off-by: Romain Izard <romain.izard.pro@gmail.com>
> ---
> 
> This is a follow-up to this discussion:
> HAVE_EFFICIENT_UNALIGNED_ACCESS on ARM32
> https://lkml.org/lkml/2017/9/4/359
> 
>  arch/arm/include/asm/Kbuild      |  1 -
>  arch/arm/include/asm/unaligned.h | 22 ++++++++++++++++++++++
>  2 files changed, 22 insertions(+), 1 deletion(-)
>  create mode 100644 arch/arm/include/asm/unaligned.h
> 
> diff --git a/arch/arm/include/asm/Kbuild b/arch/arm/include/asm/Kbuild
> index 721ab5ecfb9b..0f2c8a2a8131 100644
> --- a/arch/arm/include/asm/Kbuild
> +++ b/arch/arm/include/asm/Kbuild
> @@ -20,7 +20,6 @@ generic-y += simd.h
>  generic-y += sizes.h
>  generic-y += timex.h
>  generic-y += trace_clock.h
> -generic-y += unaligned.h
>  
>  generated-y += mach-types.h
>  generated-y += unistd-nr.h
> diff --git a/arch/arm/include/asm/unaligned.h b/arch/arm/include/asm/unaligned.h
> new file mode 100644
> index 000000000000..394227f24b77
> --- /dev/null
> +++ b/arch/arm/include/asm/unaligned.h
> @@ -0,0 +1,22 @@
> +#ifndef __ASM_ARM_UNALIGNED_H
> +#define __ASM_ARM_UNALIGNED_H
> +
> +#include <asm/byteorder.h>
> +
> +#if defined(__LITTLE_ENDIAN)
> +#include <linux/unaligned/le_struct.h>
> +#include <linux/unaligned/be_byteshift.h>
> +#include <linux/unaligned/generic.h>
> +#define get_unaligned	__get_unaligned_le
> +#define put_unaligned	__put_unaligned_le
> +#elif defined(__BIG_ENDIAN)
> +#include <linux/unaligned/be_struct.h>
> :q
> +#include <linux/unaligned/le_byteshift.h>
> +#include <linux/unaligned/generic.h>
> +#define get_unaligned	__get_unaligned_be
> +#define put_unaligned	__put_unaligned_be
> +#else
> +#error need to define endianness
> +#endif
> +
> +#endif /* __ASM_ARM_UNALIGNED_H */
> 

      parent reply	other threads:[~2017-09-20 17:16 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-09-20 15:18 Romain Izard
2017-09-20 15:26 ` Ard Biesheuvel
2017-09-20 15:41   ` Russell King - ARM Linux
2017-09-20 16:28     ` Ard Biesheuvel
2017-09-20 20:35   ` Arnd Bergmann
2017-09-22 21:36     ` Ard Biesheuvel
2017-09-22 21:49       ` Arnd Bergmann
2017-09-20 17:16 ` Robin Murphy [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=8a7a3680-c021-402b-c0f5-f10363051543@arm.com \
    --to=robin.murphy@arm.com \
    --cc=ard.biesheuvel@linaro.org \
    --cc=arnd@arndb.de \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux@armlinux.org.uk \
    --cc=romain.izard.pro@gmail.com \
    --cc=viro@zeniv.linux.org.uk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®