Date: Wed, 15 Jun 2005 15:57:20 -0700 From: Marcel Moolenaar <marcel@xcllnt.net> To: Daniel Hartmeier <daniel@benzedrine.cx> Cc: freebsd-net@freebsd.org, Marcel Moolenaar <marcel@freebsd.org>, freebsd-pf@freebsd.org Subject: Re: ia64/81284: Unaligned Reference with pf on 5.4/IA64 Message-ID: <eb080d6cc5a3775b440d5f19c9e50b97@xcllnt.net> In-Reply-To: <20050615223450.GY8526@insomnia.benzedrine.cx> References: <200506132123.j5DLNove069255@freefall.freebsd.org> <20050615204232.GX8526@insomnia.benzedrine.cx> <df7cf0532ee7aa367a11ff455ffecae1@xcllnt.net> <20050615223450.GY8526@insomnia.benzedrine.cx>
next in thread | previous in thread | raw e-mail | index | archive | help
On Jun 15, 2005, at 3:34 PM, Daniel Hartmeier wrote: > On Wed, Jun 15, 2005 at 02:23:24PM -0700, Marcel Moolenaar wrote: > >> That entirely depends. If a struct ip pointer is constructed without >> any form of casting, then one can assume that alignment is guaranteed. >> The compiler guarantees to do so, except of course in this case: >> the structure is defined as a packed structure. We, as the developers, >> have told the compiler to *NOT* guarantee alignment of fields. We're >> on our own and we miserably fail being on our own. > > 'packed', as I understand it, prohibits the compiler from inserting any > padding anywhere in the struct. That is, it guarantees that the total > size of a struct object equals the sum of the sizes of its members. > > As a consequence, individual members can't be aligned properly if that > would require padding in front of them. The compiler can (and must?) > still align the first member, i.e. the beginning of the struct object, > though, no? No, it can't guarantee alignment of the first field and consequently will not bother trying. The best way to picture this is with an array. Alignment guarantees has to come from the implementation, the compiler will not guarantee alignment. > So, are you really sure we should do differently in pf, instead of > looking for a bridge problem, where bridge constructs an mbuf with the > IP header not properly aligned? I've not been sure to begin with. I forwarded this PR because I have no clue as to where the root problem is. If you say that pf(4) is not at fault and it's the bridge code then fine, fix the bridge code. All I see is an unaligned memory access and plenty of yellow flags in the source code. > I.e. if the IP header is properly aligned within the mbuf (on 32-bit > boundaries, I presume), wouldn't ip_src/dst have to be properly aligned > as well, even though __packed is used, because the layout of struct ip > is chosen like that? Yes. -- Marcel Moolenaar USPA: A-39004 marcel@xcllnt.net
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?eb080d6cc5a3775b440d5f19c9e50b97>