All of lore.kernel.org
 help / color / mirror / Atom feed
From: Larry Finger <Larry.Finger@lwfinger.net>
To: Jason Andrews <jasona@cadence.com>
Cc: "linux-wireless@vger.kernel.org" <linux-wireless@vger.kernel.org>
Subject: Re: guidance on struct alignment for rtl8192cu driver
Date: Sat, 14 Sep 2013 09:08:34 -0500	[thread overview]
Message-ID: <52346DE2.9090904@lwfinger.net> (raw)
In-Reply-To: <985A2B0C3F73B74792F35D4098E1CA7CB143670E93@MAILSJ3.global.cadence.com>

On 09/14/2013 12:36 AM, Jason Andrews wrote:
> I'm using an ASUS USB N13 on an ARM platform with the rtl8192cu driver.
> Linux kernel is 3.10 so I probably don't have the latest and greatest driver.
>
> When I booted I got an ARM alignment trap caused by the driver.
>
> I determined the cause was the 1st argument to spin_lock_irqsave() has an unaligned address.
>
> By trial-and-error I found that if I edit wifi.h and insert 2 dummy bytes into the rtl_priv struct just above priv (last variable) the locks work and the driver works fine.
>
> What is the recommended way to make sure the last variable in the rtl_priv struct (u8 priv[0]) is aligned on a 4 byte boundary so the driver works on ARM machines?

There are a lot of improvements for this driver in 3.11. The backports release 
has that code. In addition, I am currently working at improving the power 
management for 3.13.

The presence of unaligned variables that cause alignment traps on ARM does not 
surprise me as I test only on x86 and ppc architectures. I now own a Raspberry 
Pi and I will soon be testing with it as well.

What does surprise me is that the first argument in all the calls to 
spin_lock_irqsave() are contained within the rtl_locks struct and everything 
there should be aligned. Perhaps some ARM expert will know why aligning the last 
item in the rtl_priv struct fixes the problem.

As far as I know, the proper way to do a 4-byte alignment is as in the following 
patch:

Index: wireless-testing-save/drivers/net/wireless/rtlwifi/wifi.h
===================================================================
--- wireless-testing-save.orig/drivers/net/wireless/rtlwifi/wifi.h
+++ wireless-testing-save/drivers/net/wireless/rtlwifi/wifi.h
@@ -2057,7 +2057,7 @@ struct rtl_priv {
  	  that it points to the data allocated
  	  beyond  this structure like:
  	  rtl_pci_priv or rtl_usb_priv */
-	u8 priv[0];
+	u8 __aligned(4) priv[0];
  };

  #define rtl_priv(hw)           (((struct rtl_priv *)(hw)->priv))

Larry


  reply	other threads:[~2013-09-14 14:08 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-09-14  5:36 guidance on struct alignment for rtl8192cu driver Jason Andrews
2013-09-14 14:08 ` Larry Finger [this message]
2013-09-16 14:35   ` Seth Forshee
2013-09-16 15:33     ` Larry Finger
2013-09-16 19:29       ` Emmanuel Grumbach
2013-09-16 19:40         ` Larry Finger
2013-09-18  4:59           ` Jason Andrews

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=52346DE2.9090904@lwfinger.net \
    --to=larry.finger@lwfinger.net \
    --cc=jasona@cadence.com \
    --cc=linux-wireless@vger.kernel.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.