All of lore.kernel.org
 help / color / mirror / Atom feed
From: Siarhei Siamashka <siarhei.siamashka@gmail.com>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH] net: Mark the ip_udp_hdr struct as packed
Date: Fri, 21 Jul 2017 21:46:40 +0300	[thread overview]
Message-ID: <20170721214640.701c5113@i7> (raw)
In-Reply-To: <e1c76b48-0557-1c62-9570-49c3e05884b0@myspectrum.nl>

On Wed, 19 Jul 2017 20:26:54 +0200
Jeroen Hofstee <jeroen@myspectrum.nl> wrote:

> Hi,
> 
> 
> On 07/18/2017 08:10 PM, Joe Hershberger wrote:
> > Hi Maxime,
> >
> > On Wed, Jul 12, 2017 at 9:34 AM, Maxime Ripard
> > <maxime.ripard@free-electrons.com> wrote:  
> >> The -mno-unaligned-access flag used on ARM to prevent GCC from generating
> >> unaligned accesses (obviously) will only do so on packed structures.
> >>
> >> It seems like gcc 7.1 is a bit stricter than previous gcc versions on this,
> >> and using it lead to data abort for unaligned accesses when generating
> >> network traffic.
> >>
> >> Fix this by adding the packed attribute to the ip_udp_hdr structure in
> >> order to let GCC do its job.
> >>
> >> Signed-off-by: Maxime Ripard <maxime.ripard@free-electrons.com>
> >> ---
> >>   include/net.h | 2 +-
> >>   1 file changed, 1 insertion(+), 1 deletion(-)
> >>
> >> diff --git a/include/net.h b/include/net.h
> >> index 997db9210a8f..7b815afffafa 100644
> >> --- a/include/net.h
> >> +++ b/include/net.h
> >> @@ -390,7 +390,7 @@ struct ip_udp_hdr {
> >>          u16             udp_dst;        /* UDP destination port         */
> >>          u16             udp_len;        /* Length of UDP packet         */
> >>          u16             udp_xsum;       /* Checksum                     */
> >> -};
> >> +} __attribute__ ((packed));  
> > Do you have an example of why this is unaligned? It seems that the
> > structure itself is naturally packed (each element is aligned to its
> > access size). It seems the only time this would hit a dabort is if the
> > head of the buffer is not 32-bit aligned. Maybe we should address the
> > place where that is the case instead of forcing byte-wise accesses in
> > general for this structure?  
> 
> |Perhaps __attribute__((aligned(2))) can prevent byte wise accesses? 
> Regards, Jeroen |

https://gcc.gnu.org/onlinedocs/gcc/Common-Type-Attributes.html

It says that "The aligned attribute can only increase alignment".

-- 
Best regards,
Siarhei Siamashka

  reply	other threads:[~2017-07-21 18:46 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-07-12 14:34 [U-Boot] [PATCH] net: Mark the ip_udp_hdr struct as packed Maxime Ripard
2017-07-18 18:10 ` Joe Hershberger
2017-07-19  7:01   ` Maxime Ripard
2017-07-19 18:13     ` Joe Hershberger
2017-07-19 18:26   ` Jeroen Hofstee
2017-07-21 18:46     ` Siarhei Siamashka [this message]
2017-07-22 13:32       ` Jeroen Hofstee
2017-07-19 18:14 ` Joe Hershberger
  -- strict thread matches above, loose matches on Subject: below --
2017-07-12 14:34 Maxime Ripard
2017-07-12 14:37 ` Dr. Philipp Tomsich
2017-07-17  9:29   ` Maxime Ripard
2017-07-18  2:35     ` Tom Rini
2017-07-21 19:15 ` Siarhei Siamashka
2017-07-21 19:37   ` Siarhei Siamashka

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=20170721214640.701c5113@i7 \
    --to=siarhei.siamashka@gmail.com \
    --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 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.