All of lore.kernel.org
 help / color / mirror / Atom feed
From: arnd@arndb.de (Arnd Bergmann)
To: linux-arm-kernel@lists.infradead.org
Subject: ARM unaligned MMIO access with attribute((packed))
Date: Wed, 27 Apr 2011 18:37:53 +0200	[thread overview]
Message-ID: <201104271837.53983.arnd@arndb.de> (raw)
In-Reply-To: <Pine.LNX.4.44L0.1104271224030.2239-100000@iolanthe.rowland.org>

On Wednesday 27 April 2011 18:25:40 Alan Stern wrote:
> On Wed, 27 Apr 2011, Rabin Vincent wrote:
> 
> > On Wed, Apr 27, 2011 at 00:21, Alan Stern <stern@rowland.harvard.edu> wrote:
> > > On Tue, 26 Apr 2011, Rabin Vincent wrote:
> > >> In my case it's this writel() in ehci-hub.c that gets chopped into
> > >> strbs:
> > >>
> > >> ? ? ? /* force reset to complete */
> > >> ? ? ? ehci_writel(ehci, temp & ~(PORT_RWC_BITS | PORT_RESET),
> > >> ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? status_reg);
> > >
> > > Why would that get messed up? ?The status_reg variable doesn't have any
> > > __atribute__((packed)) associated with it.
> > 
> > The initialization of status_reg is:
> > 
> >       u32 __iomem *status_reg
> >               = &ehci->regs->port_status[(wIndex & 0xff) - 1];
> > 
> > where ehci->regs is a pointer to the packed struct ehci_regs.  So, this
> > is the same problem of casting pointers to stricter alignment.
> 
> Right.  I can understand the compiler complaining about the cast to 
> stricter alignment during the initialization.  But I don't understand 
> why that would affect the code generated for the writel function.

The compiler does not complain, it just silently assumes that it needs
to do byte accesses. There is no way to tell the compiler to ignore
what it knows about the alignment, other than using inline assembly
for the actual pointer dereference. Most architectures today do that,
but on ARM it comes down to "*(u32 *)status_reg = temp".

	Arnd

WARNING: multiple messages have this Message-ID (diff)
From: Arnd Bergmann <arnd@arndb.de>
To: Alan Stern <stern@rowland.harvard.edu>
Cc: Rabin Vincent <rabin@rab.in>,
	linux-arm-kernel@lists.infradead.org, linux-usb@vger.kernel.org,
	Ulrich Weigand <Ulrich.Weigand@de.ibm.com>,
	linux-kernel@vger.kernel.org, gcc@gcc.gnu.org,
	Peter Maydell <peter.maydell@linaro.org>
Subject: Re: ARM unaligned MMIO access with attribute((packed))
Date: Wed, 27 Apr 2011 18:37:53 +0200	[thread overview]
Message-ID: <201104271837.53983.arnd@arndb.de> (raw)
In-Reply-To: <Pine.LNX.4.44L0.1104271224030.2239-100000@iolanthe.rowland.org>

On Wednesday 27 April 2011 18:25:40 Alan Stern wrote:
> On Wed, 27 Apr 2011, Rabin Vincent wrote:
> 
> > On Wed, Apr 27, 2011 at 00:21, Alan Stern <stern@rowland.harvard.edu> wrote:
> > > On Tue, 26 Apr 2011, Rabin Vincent wrote:
> > >> In my case it's this writel() in ehci-hub.c that gets chopped into
> > >> strbs:
> > >>
> > >> � � � /* force reset to complete */
> > >> � � � ehci_writel(ehci, temp & ~(PORT_RWC_BITS | PORT_RESET),
> > >> � � � � � � � � � � � � � � � status_reg);
> > >
> > > Why would that get messed up? �The status_reg variable doesn't have any
> > > __atribute__((packed)) associated with it.
> > 
> > The initialization of status_reg is:
> > 
> >       u32 __iomem *status_reg
> >               = &ehci->regs->port_status[(wIndex & 0xff) - 1];
> > 
> > where ehci->regs is a pointer to the packed struct ehci_regs.  So, this
> > is the same problem of casting pointers to stricter alignment.
> 
> Right.  I can understand the compiler complaining about the cast to 
> stricter alignment during the initialization.  But I don't understand 
> why that would affect the code generated for the writel function.

The compiler does not complain, it just silently assumes that it needs
to do byte accesses. There is no way to tell the compiler to ignore
what it knows about the alignment, other than using inline assembly
for the actual pointer dereference. Most architectures today do that,
but on ARM it comes down to "*(u32 *)status_reg = temp".

	Arnd

  reply	other threads:[~2011-04-27 16:37 UTC|newest]

Thread overview: 41+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-02-02 16:00 ARM unaligned MMIO access with attribute((packed)) Arnd Bergmann
2011-02-02 16:00 ` Arnd Bergmann
2011-02-02 16:37 ` Russell King - ARM Linux
2011-02-02 16:37   ` Russell King - ARM Linux
2011-02-02 17:39   ` Arnd Bergmann
2011-02-02 17:39     ` Arnd Bergmann
2011-02-02 19:14     ` Ian Lance Taylor
2011-02-02 19:14       ` Ian Lance Taylor
2011-02-02 21:38   ` David Miller
2011-02-02 21:38     ` David Miller
2011-02-02 21:45     ` Russell King - ARM Linux
2011-02-02 21:45       ` Russell King - ARM Linux
2011-02-02 21:59       ` David Miller
2011-02-02 21:59         ` David Miller
2011-02-02 23:08     ` Måns Rullgård
2011-02-02 23:23       ` David Miller
2011-02-02 23:23         ` David Miller
2011-02-03  9:26       ` Arnd Bergmann
2011-02-03  9:26         ` Arnd Bergmann
2011-02-03 15:03   ` Arnd Bergmann
2011-02-03 15:03     ` Arnd Bergmann
2011-02-02 16:51 ` Richard Guenther
2011-02-02 16:51   ` Richard Guenther
2011-02-02 17:09   ` Russell King - ARM Linux
2011-02-02 17:09     ` Russell King - ARM Linux
2011-02-02 17:39   ` Joseph S. Myers
2011-02-02 17:39     ` Joseph S. Myers
2011-04-26 15:00 ` Rabin Vincent
2011-04-26 15:00   ` Rabin Vincent
2011-04-26 18:51   ` Alan Stern
2011-04-26 18:51     ` Alan Stern
2011-04-27 14:06     ` Rabin Vincent
2011-04-27 14:06       ` Rabin Vincent
2011-04-27 16:25       ` Alan Stern
2011-04-27 16:25         ` Alan Stern
2011-04-27 16:37         ` Arnd Bergmann [this message]
2011-04-27 16:37           ` Arnd Bergmann
2011-04-28 13:35           ` Alan Stern
2011-04-28 13:35             ` Alan Stern
2011-04-28 14:16             ` Arnd Bergmann
2011-04-28 14:16               ` 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=201104271837.53983.arnd@arndb.de \
    --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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.