Subject: Re: The ifconfig(8) unaligned access bug
To: None <port-alpha@NetBSD.ORG, thorpej@nas.nasa.gov>
From: Ross Harvey <ross@teraflop.com>
List: port-alpha
Date: 04/30/1997 19:06:49
> So, my two questions are:
>
> (1) Why on earth didn't "struct netrange" get rounded to 8
> bytes, and
>
> (2) Why on earth doesn't it align "addreq" properly?
I can answer (2) but not (1). Addreq _is_ aligned properly. Its alignment
requirement will depend on the maximum alignment of any field in it.
Well, they are all chars or u_char fields.
There is a bug, but it is in the struct sockaddr definition itself!
With 20-20 hindsight we could travel back in time and make sure all
the typecasting that the sockaddr gets hammered with goes in the direction
of strict alignment to loose alignment.
That is, define the field as int64_t[2], say, and then cast it to
the various protocol types, or the generic u_char/char fields, rather
than...as is presently done...start as chars and then cast into
other less generic structures. This is the wrong (unsafe) direction.
I suppose you could easily justify aligning all blocks >= 8 bytes to
an increasing progression of 8, 16, 32. (Stop at 32.) You can justify this
as a work-around for wrong-way typecasting, or, with noble purpose,
as an anti-cache-fragmentation measure. Things need a lot more alignment
than the basic load-determined requirement if you want to not waste
critical parts of the cache blocks. There is such an enormous ratio
between main memory and cache speed these days: anything that increases
cache hit rate has a huge payoff.
------------------------------
Ross Harvey Avalon Computer Systems, Inc.
ross@teraflop.com