linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
From: dave.martin@linaro.org (Dave Martin)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH] ARM: Do not allow unaligned accesses when CONFIG_ALIGNMENT_TRAP
Date: Tue, 24 May 2011 18:13:31 +0100	[thread overview]
Message-ID: <20110524171331.GA2941@arm.com> (raw)
In-Reply-To: <BANLkTi=xLE9gP5YOdr9dR0DfsY1Ymzxu+w@mail.gmail.com>

On Tue, May 24, 2011 at 04:26:35PM +0100, Catalin Marinas wrote:
> 2011/5/24 M?ns Rullg?rd <mans@mansr.com>:
> > Catalin Marinas <catalin.marinas@arm.com> writes:
> >
> >> On Mon, 2011-05-23 at 14:21 +0100, Russell King - ARM Linux wrote:
> >>> On Mon, May 23, 2011 at 12:16:48PM +0100, Catalin Marinas wrote:
> >>> > Newer versions of gcc generate unaligned accesses by default, causing
> >>> > kernel panics when CONFIG_ALIGNMENT_TRAP is enabled. This patch adds the
> >>> > -mno-unaligned-access option to gcc.
> >>>
> >>> This description doesn't make sense. ?If we have alignment traps enabled,
> >>> then we _expect_ to fix up unaligned loads and stores.
> >>>
> >>> Therefore there should be no panic if CONFIG_ALIGNMENT_TRAP is enabled.
> >>>
> >>> So what's the _actual_ problem that this is trying to address? ?What's
> >>> the panic/oops look like? ?And that information should be in the commit
> >>> description _anyway_.
> >>
> >> Does the patch below look better?
> >>
> >> We cannot move alignment_init() earlier as we don't know how early the
> >> compiler would generate unaligned accesses. An alternative is some
> >> #ifdef's in head.S. Please let me know which variant you prefer.
> >
> > ifdefs may be ugly, but I don't see a better solution here. ?Crippling
> > the entire build to make a couple of lines slightly more aesthetically
> > pleasing doesn't seem right to me.
> 
> BTW, are we sure that the code generated with unaligned accesses is
> better? AFAIK, while processors support unaligned accesses, they may
> not always be optimal.

The code gcc generates to synthesise an unaligned access using aligned
accesses is pretty simplistic:

$ cat <<EOF | gcc -O2 -c unaligned.c && objdump -d unaligned.o
unsigned long readw(void *p)
{
	struct { unsigned long l; } __attribute__ (( __packed__ )) *s = p;

	return s->l;
}
EOF

00000000 <readw>:
   0:   7841            ldrb    r1, [r0, #1]
   2:   7803            ldrb    r3, [r0, #0]
   4:   7882            ldrb    r2, [r0, #2]
   6:   78c0            ldrb    r0, [r0, #3]
   8:   ea43 2301       orr.w   r3, r3, r1, lsl #8
   c:   ea43 4302       orr.w   r3, r3, r2, lsl #16
  10:   ea43 6000       orr.w   r0, r3, r0, lsl #24
  14:   4770            bx      lr
  16:   bf00            nop


For code which natively needs to read unaligned fields from data structures,
I sincerely doubt that the CPU will not beat the above code for efficiency...

So if there's code doing unaligned access to data structures for a good
reason, building with unaligned access support turned on in the compiler
seems a good idea, if that code might performance-critical for anything.


Most code should not be doing unaligned accesses even at the source level
though unless there's a good reason, since on average unaligned accesses
will not be quite as efficient as aligned accesses even if performed
natively by the CPU rather than being synthesised by the compiler.

Where are the observed faults coming from?  Maybe it's the faulting code
that's the problem here, not the compiler...

Cheers
---Dave

  parent reply	other threads:[~2011-05-24 17:13 UTC|newest]

Thread overview: 41+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-05-23 11:16 [PATCH] ARM: Do not allow unaligned accesses when CONFIG_ALIGNMENT_TRAP Catalin Marinas
2011-05-23 12:30 ` Måns Rullgård
2011-05-23 13:25   ` Russell King - ARM Linux
2011-05-23 13:21 ` Russell King - ARM Linux
2011-05-23 13:51   ` Catalin Marinas
2011-05-23 14:37     ` Måns Rullgård
2011-05-23 14:41       ` Catalin Marinas
2011-05-23 14:52       ` Russell King - ARM Linux
2011-05-24  9:39   ` Catalin Marinas
2011-05-24 14:17     ` Måns Rullgård
2011-05-24 15:26       ` Catalin Marinas
2011-05-24 16:23         ` Måns Rullgård
2011-05-24 17:26           ` Nicolas Pitre
2011-05-24 17:13         ` Dave Martin [this message]
2011-05-25 11:14           ` Catalin Marinas
2011-05-25 12:43             ` Dave Martin
2011-05-25 13:32               ` Måns Rullgård
2011-05-25 14:05                 ` Dave Martin
2011-05-25 14:48                   ` Måns Rullgård
2011-05-25 14:50                 ` Catalin Marinas
2011-05-25 14:53                   ` Måns Rullgård
2011-05-26 17:10                   ` Will Deacon
2011-05-26 18:14                     ` Måns Rullgård
2011-05-26 19:58                     ` Andi Kleen
2011-05-26 21:03                     ` Nicolas Pitre
2011-05-26 21:10                       ` Andi Kleen
2011-05-26 21:26                         ` Måns Rullgård
2011-05-27 10:05                         ` Will Deacon
2011-05-27 16:53                           ` Andi Kleen
2011-05-26 21:51                       ` Russell King - ARM Linux
2011-05-26 22:29                         ` Andi Kleen
2011-05-27  8:38                         ` Catalin Marinas
2011-05-27  8:54                           ` Russell King - ARM Linux
2011-05-27  9:51                             ` Catalin Marinas
2011-05-27  9:56                               ` Catalin Marinas
2011-05-27 12:46                               ` Måns Rullgård
2011-05-28 15:34                                 ` [PATCH] Disable -fconserve-stack on ARM Andi Kleen
2011-05-31 16:30                                   ` Catalin Marinas
2011-05-31 18:01                                     ` Andi Kleen
2011-06-02 13:08                                       ` Catalin Marinas
     [not found] <mailman.254.1306496353.1533.linux-arm-kernel@lists.infradead.org>
2011-05-27 12:14 ` [PATCH] ARM: Do not allow unaligned accesses when CONFIG_ALIGNMENT_TRAP Frank Hofmann

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=20110524171331.GA2941@arm.com \
    --to=dave.martin@linaro.org \
    --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).