public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
From: Albert ARIBAUD <albert.u.boot@aribaud.net>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH] arm: armv7: add compile option -mno-unaligned-access if available
Date: Wed, 18 Jul 2012 23:37:49 +0200	[thread overview]
Message-ID: <20120718233749.2e595dfb@lilith> (raw)
In-Reply-To: <20120705095719.5d6ca845@aari01-12>

on Thu, 5 Jul 2012 09:57:19 +0200,
Albert ARIBAUD <albert.u.boot@aribaud.net> wrote :

> Hi M?ns,
> 
> On Mon, 02 Jul 2012 17:14:40 +0100, M?ns Rullg?rd <mans@mansr.com>
> wrote:
> 
> > > IMHO, our recent discussion showed that both ways are wrong.
> > > "-mno-unaligned-access" works around misaligned data on the software
> > > level, while allowing unaligned access does on the hardware level.
> > >
> > > What we really want is no unaligned access in U-Boot at all. Just
> > > because "-mno-unaligned-access" is the default on ARMv5, we should
> > > not consider it a gold standard.
> > 
> > It's slightly more complicated than that.  Data can be misaligned for
> > a variety of reasons:
> > 
> > 1. Errors in software.
> > 2. Specified by a file format or communication protocol.
> > 3. Deliberately misaligned by the compiler.
> > 
> > Misaligned data of type 1 should of course be fixed properly, not
> > worked around in any way.
> 
> Agreed.
> 
> > Type 2 happens all the time, and has to be dealt with one way or
> > another.  If the hardware supports unaligned accesses, this is usually
> > faster than reading a byte at a time.
> 
> Sorry but I don't accept a systemic change as a good solution to a
> specific issue. The best fix is "don't accept using a protocol or file
> format which was not designed to avoid native misaligned accesses", and
> the second best fix is "if you really must deal with a protocol or file
> format which causes native alignment issues, then the fix should only
> affect the protocol or file format's issue, not with your system which
> is not the root cause".
> 
> But to be honest, I haven't seen such badly a designed protocol or file
> format; their designers tend to make sure that (assuming the start of a
> protocol or file 'content' (frame, record, etc) is aligned, then all
> fields in it are aligned as well. Can someone point me to an example of
> a protocol or file format which does present such a misalignment risk ?
> 
> > When targeting ARMv6 and later, recent gcc versions have started
> > issuing deliberate unaligned accesses where previously byte by byte
> > accesses would have been done.
> 
> Wrongly formulated: "mis-aligning deliberately" seems to imply that
> GCC did away with the possibility of properly aligning, which they of
> course did not. What they did is switch its default behavior regarding
> native misaligned accesses from forbidding to allowing them. The change
> here is of policy, a change which we may or may not want to follow. 
> 
> > This happens with "packed" structs
> > and sometimes to write multiple smaller values at once, typically when
> > zero-initialising things.  These unaligned accesses are *good*.  They
> > make code smaller and faster.
> 
> Again, "good" is a policy, or subjective, statement, not an absolute.
> Just as "good" is correctly aligning data in the first place (to begin
> with, in protocols and file formats) and keeping the compiler's native
> misaligned access policy set to "do not allow".
> 
> > The real problem here is that u-boot is setting the strict alignment
> > checking flag, invalidating the assumption of the compiler that the
> > system allows unaligned accesses.  For ARMv5 and earlier, setting this
> > flag is usually advisable since it makes finding accidental unaligned
> > accesses much easier.
> 
> Just as it is for ARMv6 and up. Again, just because the compiler folks
> changed their default policy does not mean we should change ours,
> which is not based on the same goals. 
> 
> > This was debated in the context of the kernel a while ago, ultimately
> > leading to strict alignment being disabled for ARMv6 and up [1].
> > 
> > [1]
> > http://git.kernel.org/?p=linux/kernel/git/torvalds/linux.git;a=commitdiff;h=8428e84d42179c2a00f5f6450866e70d802d1d05
> 
> I'd rather have a link to the rationale than to the commit, but anyway,
> the kernel folks' decision is theirs and does not necessarily apply to
> us. I have mailed Catalin Marinas off-list to get details on the
> rationale and context of the kernel patch; I will report conclusions
> here.
> 
> Meanwhile, our policy regarding misalignment accesses is to only allow
> them when externally required (by something other than a bad design).
> Someone please show me such an external requirement for U-Boot, and I
> will reconsider -- and then, other arch custodians may have a problem
> with that too.
> 
> Regarding the origin of this patch, i.e. a mis-alignment of USB fields,
> and unless U-Boot USB folks say otherwise, this issue should be fixed
> by aligning said fields properly.

We are nearing the release, and we obviously won't have misalignments
fixed and tested in time for it.

So I suspect that if I want the ARM U-Boot release to work I'll have to
allow this patch in my master branch to be pulled in for 12.07, so that
the compiler keeps behaving as it did before gcc changed the default.

... but only for the upcoming release, i.e. I will revert the patch in
my 'next' branch, which will apply right after 12.07 is out. Therefore,
before next release, misalignments will have to be fixed at the root.

Amicalement,
-- 
Albert.

  reply	other threads:[~2012-07-18 21:37 UTC|newest]

Thread overview: 32+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-06-05 17:47 [U-Boot] [PATCH] arm: enable unaligned access on ARMv7 Lucas Stach
2012-06-05 18:42 ` Stephen Warren
2012-06-05 19:06   ` Lucas Stach
2012-06-22  9:15     ` Albert ARIBAUD
2012-06-22  9:36       ` Lucas Stach
2012-06-22 11:16         ` Albert ARIBAUD
2012-06-22 11:47           ` Lucas Stach
2012-06-22 22:11             ` Aneesh V
2012-06-22 22:13               ` Aneesh V
2012-06-23  9:01                 ` Albert ARIBAUD
2012-06-23 17:43                   ` V, Aneesh
2012-06-25 20:34                     ` Albert ARIBAUD
2012-06-25 21:49                       ` Aneesh V
2012-06-25 22:02                         ` Wolfgang Denk
2012-06-23 19:50                   ` Måns Rullgård
2012-06-24  6:30                   ` Lucas Stach
     [not found]                     ` <20120625221741.3a32790e@lilith>
2012-06-25 21:34                       ` Lucas Stach
2012-06-26 20:56       ` Rob Herring
2012-06-27 10:14         ` Tetsuyuki Kobayashi
2012-07-02  9:42           ` [U-Boot] [PATCH] arm: armv7: add compile option -mno-unaligned-access if available Tetsuyuki Kobayashi
2012-07-02  9:53             ` Måns Rullgård
2012-07-02 15:16               ` Lucas Stach
2012-07-02 16:14                 ` Måns Rullgård
2012-07-03  7:10                   ` Tetsuyuki Kobayashi
2012-07-05  7:57                   ` Albert ARIBAUD
2012-07-18 21:37                     ` Albert ARIBAUD [this message]
2012-07-19  4:31                     ` Mike Frysinger
2012-07-19  4:29                   ` Mike Frysinger
2012-07-19  6:28                     ` Albert ARIBAUD
2012-07-19 14:27                       ` Mike Frysinger
2012-07-20  7:12                         ` Albert ARIBAUD
2012-07-12 15:12             ` Gary Thomas

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=20120718233749.2e595dfb@lilith \
    --to=albert.u.boot@aribaud.net \
    --cc=u-boot@lists.denx.de \
    /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