From: arnd@arndb.de (Arnd Bergmann)
To: linux-arm-kernel@lists.infradead.org
Subject: DWord alignment on ARMv7
Date: Fri, 04 Mar 2016 14:30:23 +0100 [thread overview]
Message-ID: <72900410.JPa1IHPXo5@wuerfel> (raw)
In-Reply-To: <CAKv+Gu_HttHOutHAw-k_uwmTUGjUsTWCotVHroqRK0NQDOGkNg@mail.gmail.com>
On Friday 04 March 2016 12:44:23 Ard Biesheuvel wrote:
> On 4 March 2016 at 12:38, Arnd Bergmann <arnd@arndb.de> wrote:
> > On Friday 04 March 2016 12:14:24 Ard Biesheuvel wrote:
> >> On 4 March 2016 at 12:02, Russell King - ARM Linux
> > Here is a patch I've come up with independently. I have verified
> > that it removes all ldrd/strd from the btrfs unaligned data
> > handling.
> >
> > The open question about it is whether we'd rather play safe and
> > let the compiler handle unaligned accesses itself, removing the
> > theoretical risk of the compiler optimizing
> >
> > void *p;
> > u64 v = get_unaligned((u32)p) + (get_unaligned((u32)(p + 4)) << 32);
> >
> > into an ldrd. I think the linux/unaligned/access_ok.h implementation
> > would allow that.
> >
>
> I would assume that the compiler engineers are aware of the alignment
> requirement of ldrd/strd, and don't promote adjacent accesses like
> that if the pointer may not be 64-bit aligned.
Ah, I thought it only required 32-bit alignment like ldm/stm, but it
seems that it won't do that. However, an implementation like
unsigned long long get_unaligned_u64(void *p)
{
unsigned long long upper, lower;
lower = *(unsigned long*)p;
upper = *(unsigned long*)(p+4);
return lower | (upper << 32);
}
does get compiled into
00000000 <f>:
0: e8900003 ldm r0, {r0, r1}
4: e12fff1e bx lr
which is still wrong, so I assume there is some danger of that remaining
with both of our patches, as the compiler might decide to merge
a series of unaligned 32-bit loads into an ldm, as long as our implementation
incorrectly tells the compiler that the data is 32-bit aligned.
> > + * This is the most generic implementation of unaligned accesses
> > + * and should work almost anywhere.
> > + */
> > +#include <asm/byteorder.h>
> > +#include <linux/kernel.h>
> > +#include <asm/byteorder.h>
>
> Any particular reason to include this twice?
No, just a mistake when merging the access_ok.h into this file.
Arnd
next prev parent reply other threads:[~2016-03-04 13:30 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-03-03 22:27 DWord alignment on ARMv7 Marc Kleine-Budde
2016-03-03 23:54 ` Will Deacon
2016-03-04 8:01 ` btrfs_get_token_64() alignment problem on ARM (was: Re: DWord alignment on ARMv7) Marc Kleine-Budde
2016-03-04 9:16 ` David Sterba
2016-03-04 10:48 ` DWord alignment on ARMv7 Ard Biesheuvel
2016-03-04 11:02 ` Russell King - ARM Linux
2016-03-04 11:14 ` Ard Biesheuvel
2016-03-04 11:19 ` Marc Kleine-Budde
2016-03-04 11:26 ` Ard Biesheuvel
2016-03-04 11:38 ` Arnd Bergmann
2016-03-04 11:44 ` Ard Biesheuvel
2016-03-04 13:30 ` Arnd Bergmann [this message]
2016-03-04 13:33 ` Ard Biesheuvel
2016-03-04 13:46 ` Russell King - ARM Linux
2016-03-04 14:41 ` Arnd Bergmann
2016-03-04 14:56 ` Russell King - ARM Linux
2016-03-04 15:49 ` Arnd Bergmann
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=72900410.JPa1IHPXo5@wuerfel \
--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