From: arnd@arndb.de (Arnd Bergmann)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH] ARM: unaligned.h: Use an arch-specific version
Date: Fri, 22 Sep 2017 23:49:56 +0200 [thread overview]
Message-ID: <CAK8P3a3MDSDCZq_+Meub6ty8-ZasSOJ09Qjc3h4OArFcB24ScA@mail.gmail.com> (raw)
In-Reply-To: <CAKv+Gu-KAou7y-xTc7aaKU6WFstchKitSPJsKD_dXJ=_BbWb8w@mail.gmail.com>
On Fri, Sep 22, 2017 at 11:36 PM, Ard Biesheuvel
<ard.biesheuvel@linaro.org> wrote:
> On 20 September 2017 at 13:35, Arnd Bergmann <arnd@arndb.de> wrote:
>> The architectures that do use include/asm-generic/unaligned.h and
>> also set HAVE_EFFICIENT_UNALIGNED_ACCESS in some configurations
>> are arm, arm64, metag, s390 and arc.
>>
>> This is a rather short list, and three of them (arm64, metag and arc) only
>> support very recent compilers, so we can probably just ask the respective
>> arch maintainers to ack the patch that changes the asm-generic file
>> for everyone.
>>
>
> If we can limit the fallout like that, I agree that we should simply
> make the struct flavor the default. It elegantly informs the compiler
> about the size of the access and the potential misalignment, so it
> should allow compilers for any architecture to select the most
> appropriate instruction.
>
> But doesn't that mean that any code that currently relies on
> HAVE_EFFICIENT_UNALIGNED_ACCESS should be using get_unaligned instead?
> I haven't reviewed the actual use cases (other than the ones I added
> myself to the crypto subsystem), but it seems to me that it is
> generally unsafe to do any unaligned accesses directly on ARM, given
> that the compiler may merge adjacent LDRs into LDMs or LDRDs (and
> likewise for stores)
It's not clear that all that code should be using get_unaligned(),
but I agree that any code relying on
HAVE_EFFICIENT_UNALIGNED_ACCESS is potentially inefficient
on ARM when it causes a trap.
I think it would be a useful goal to avoid running into the ARM alignment
trap handler entirely for kernel code, but that sounds like a lot of work.
If we want to do that, we'd need at least these steps:
- review each reference to HAVE_EFFICIENT_UNALIGNED_ACCESS
and modify it so that gcc will never use the trapping instructions
- add a WARN_ON_ONCE() in the trap handler
- fix any drivers we run into that should be using get_unaligned() but
blindly rely on the trap handler instead.
Arnd
next prev parent reply other threads:[~2017-09-22 21:49 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-09-20 15:18 [PATCH] ARM: unaligned.h: Use an arch-specific version 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 [this message]
2017-09-20 17:16 ` Robin Murphy
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=CAK8P3a3MDSDCZq_+Meub6ty8-ZasSOJ09Qjc3h4OArFcB24ScA@mail.gmail.com \
--to=arnd@arndb.de \
--cc=linux-arm-kernel@lists.infradead.org \
/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;
as well as URLs for NNTP newsgroup(s).