svn commit: r257455 - head/sys/net

Luigi Rizzo rizzo at iet.unipi.it
Thu Oct 31 22:39:21 UTC 2013


On Thu, Oct 31, 2013 at 03:14:57PM -0700, John-Mark Gurney wrote:
> Luigi Rizzo wrote this message on Thu, Oct 31, 2013 at 22:13 +0100:
> > On Thu, Oct 31, 2013 at 01:49:16PM -0700, John-Mark Gurney wrote:
> > > Luigi Rizzo wrote this message on Thu, Oct 31, 2013 at 21:05 +0100:
> > > > On Thu, Oct 31, 2013 at 01:27:25PM -0600, Ian Lepore wrote:
> > > > ...
> > > > > Is there any chance all this reworking might get us to a position where
> > > > > the protocol header in an mbuf doesn't have to be 32-bit aligned
> > > > > anymore?  We pay a pretty heavy price for that requirement in the
> > > > > drivers of the least capable hardware we support, the systems that have
> > > > > the least horsepower to spare to make an extra copy of each packet to
> > > > > realign it.
> > > > 
> > > > So are you suggesting to use some 'copy_unaligned_32()' function/macro to
> > > > access 32-bit protocol fields in the network stack ?
> > > > (16-bit entries should not be an issue)
> > > 
> > > my idea has been to make a change to the various ip/tcp/udp layers
> > > that is dependant upon __NO_STRICT_ALIGNMENT and if we do require
> > > strict alignment to copy the header to a stack buffer to align the
> > > data...
> > 
> > I'd rather use accessors functions/macros to read/write
> > the unaligned headers so we can hide the #ifdefs in only
> > one place.
> 
> I am/was trying to prevent massive code curn...
> 
> > The copy to a stack buffer is probably useful even for readability
> 
> Oh, I also realized I left out another part of it...
> 
> void
> ip_input(struct mbuf *m)
> {
> #ifndef __NO_STRICT_ALIGNMENT
> 	struct ip tmpip;
> #endif
> 	struct ip *ip = NULL;
> 
> #ifndef __NO_STRICT_ALIGNMENT
> 	bcopy(mtod(m, struct ip *), &tmpip, sizeof tmpip);
> 	ip = &tmpip;
> #else
> 	ip = mtod(m, struct ip *);
> #endif

this is exactly what we shold NOT do.
Apart from the source bloat from conditional blocks,
easily someone will try to use ip to point to options
(which are not copied), etc etc.

Just copy the header unconditionally, or probably just the
source and destination IP which under normal assumptions
(14 byte mac header) are the only ones where alignment breaks.
Then of course options will have similar problems.

This is why I think we should use accessors if we want
to solve this problem.

cheers
luigi


More information about the svn-src-head mailing list