Subject: Re: struct netbsd32_statvfs and packed attribute
To: NetBSD Kernel <tech-kern@NetBSD.org>
From: David Young <dyoung@pobox.com>
List: tech-kern
Date: 09/08/2007 16:53:30
On Sat, Sep 08, 2007 at 02:22:30PM +0100, David Laight wrote:
> On Fri, Sep 07, 2007 at 04:36:21PM -0700, Markus Mayer wrote:
> > Hi,
> > 
> > I just noticed an issue with netbsd32_statvfs and the getvfsstat() 
> > syscall. This is for a MIPS platform with 64 bit kernel and (some) 32 
> > bit userland applications. However, I am assuming it'll affect other 
> > platforms, as well.
> ...
> > I traced the problem to the attribute "packed" that is specified for 
> > struct netbsd32_statvfs. netbsd32_statvfs is 2228 bytes in the kernel. 
> > However, struct statvfs, which is not packed, is 2232 bytes in 32 bit 
> > userland.
> 
> IIRC the 'problem' is that struct statvfs has a 64bit integer that
> isn't (by default) aligned on an 8 byte boundary.
> On i386 (I'm not sure about sparc) 64bit types only have 4 byte alignment,
> so an amd64 kernel (where they have 8 byte alignment) incorrectly
> maps the statvfs structure.
> Adding 'base' types netbsd32_int64 and netbsd32_uint64 (which have 4byte
> alignemnt when needed) may be necessary.  Packing the whole structure
> gives a massive performance penalty on cpus that can't do misaligned
> access.

You can avoid the performance penalty by using __attribute__((__packed__,
__aligned__(n))), for 'n' the alignment in bytes that the architecture
needs.  See struct rtw_rxdesc in dev/ic/rtwreg.h.

Dave

-- 
David Young             OJC Technologies
dyoung@ojctech.com      Urbana, IL * (217) 278-3933 ext 24