Subject: kern/13385: Network stack assumes aligned payload from devices
To: None <gnats-bugs@gnats.netbsd.org>
From: None <thorpej@zembu.com>
List: netbsd-bugs
Date: 07/05/2001 08:16:07
>Number:         13385
>Category:       kern
>Synopsis:       Network stack assumes aligned payload from devices
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    kern-bug-people
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Thu Jul 05 08:14:00 PDT 2001
>Closed-Date:
>Last-Modified:
>Originator:     Jason R. Thorpe
>Release:        All versions of NetBSD
>Organization:
Zembu Labs, Inc.
>Environment:
	
System: NetBSD dr-evil 1.5W NetBSD 1.5W (DR-EVIL) #200: Fri Jun 15 15:05:53 PDT 2001 thorpej@dr-evil:/u1/netbsd/src/sys/arch/i386/compile/DR-EVIL i386
Architecture: i386
Machine: i386
>Description:
	The network stack assumes that the packets provided by
	network device drivers are suitably aligned, or that the
	CPU being used can perform unaligned access efficiently.

	In the case of Ethernet, the header is 14 bytes.  If a
	device can only DMA to a 32-bit boundary (and I know of
	devices which are even more strict, requiring *cacheline*
	boundaries for DMA), this means that the payload after
	the Ethernet header is misaligned.

	On systems that cannot perform unaligned access, such as
	the MIPS, Alpha, and SPARC, a fault occurs.  On other systems,
	such as the ARM, `incorrect' data will result from the
	unaligned access.  On systems such as the x86, the unaligned
	access is *very* slow.

	To avoid this, device drivers with their own DMA alignment
	constraints generally must copy the packet into a new buffer,
	who's offset is adjusted to compensate for the payload
	alignment requirements.

	Unfortunately, this leads to high CPU usage even at 100Mb/s,
	and at 1000Mb/s, it basically destroys performance.

>How-To-Repeat:
	Code inspection.

>Fix:
	The correct fix would be to implement a sort of "extractor"
	macro that would allow packet payload data to be accessed
	in-place if the data is properly aligned, or copied to a
	stack area if not aligned, and a way to copyback, if necessary.

	The fix is not included here.  This problem report is meant
	mostly to formally document the problem.
>Release-Note:
>Audit-Trail:
>Unformatted: