[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <AE90C24D6B3A694183C094C60CF0A2F6026B70F6@saturn3.aculab.com>
Date: Wed, 19 Dec 2012 09:17:41 -0000
From: "David Laight" <David.Laight@...LAB.COM>
To: "Thomas Graf" <tgraf@...g.ch>
Cc: <nicolas.dichtel@...nd.com>, <bhutchings@...arflare.com>,
<netdev@...r.kernel.org>, <davem@...emloft.net>
Subject: RE: [PATCH v2] netlink: align attributes on 64-bits
> > Consider the structure:
> > struct bar {
> > __u32 foo1;
> > __u64 foo2;
> > }
> > On i386 it will have size 12 and foo2 will be at offset 4.
> > On sparc32 (and most 64bit) it will have size 16 with foo2
> > at offset 8 (and 4 bytes of pad after foo1).
>
> This is a known problem and I can't think of anything
> that can be done about it except for memcpy()ing the
> data before accessing it.
You can't use memcpy() to copy a pointer to a misaligned
structure into an aligned buffer. The compiler assumes
the pointer is aligned and will use instructions that
depend on the alignment.
> If you have ideas, I'm more that willing to listen :)
> ... Netlink has and will be host bound. It also
> uses host byte order for that reason.
I think:
1) Alignment is only needed on systems that have 'strict alignment'
requirements (maybe disable for testing?)
2) Alignment is only needed for parameters whose size is a
multiple of the alignment (a structure containing a
field that needs 8 byte alignment will always be a multiple
of 8 bytes long).
3) You need to add NA_HDR_LEN to the write pointer before
determining the size of the pad.
So a structure of three uint32_t will never need aligning.
David
--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Powered by blists - more mailing lists