From: Julien Grall Date: Wed, 4 Jun 2014 21:13:20 +0000 (+0100) Subject: xen/netfront: Add 2 bytes padding in the rx mbuf X-Git-Url: http://xenbits.xensource.com/gitweb?a=commitdiff_plain;h=cd1cb74cc5ed66b9e8d9c479ff59347907feec61;p=people%2Fjulieng%2Ffreebsd.git xen/netfront: Add 2 bytes padding in the rx mbuf The ethernet header size is not word aligned. Therefore the IP packet and so on won't be align. On some architecture (such as ARM) unaligned access may be slower and/or defined. Therefore we might reveice an alignement fault. To void this case, we need to pull-up the data of ETHER_ALIGN bytes. I'm not sure how this patch will impact x86, we need to do some benchmarking without and with it. I'mi also not sure m_copyup is the right function to any. Can any expert to the network stack can tell me if there is a better solution? --- diff --git a/sys/dev/xen/netfront/netfront.c b/sys/dev/xen/netfront/netfront.c index 835c6ae09462..9f6ee017da77 100644 --- a/sys/dev/xen/netfront/netfront.c +++ b/sys/dev/xen/netfront/netfront.c @@ -88,6 +88,8 @@ __FBSDID("$FreeBSD$"); #include "xenbus_if.h" +#define ETHER_ALIGN 2 + /* Features supported by all backends. TSO and LRO can be negotiated */ #define XN_CSUM_FEATURES (CSUM_TCP | CSUM_UDP) @@ -1357,6 +1359,21 @@ next_skip_queue: ref_cons = *cons + frags; frags++; } + + if (!err) { + /* The ethernet header size is not word aligned. Therefore, + * the IP packet and so on won't be align. On some architecture + * (such as ARM) unaligned access may be slower and/or denied. + * Therefore we might receive an alignment fault. + * To avoid this case, we need to pull-up the data of + * ETHER_ALIGN bytes. + */ + m0 = m_copyup(m0, min(m0->m_pkthdr.len, max_protohdr), + ETHER_ALIGN); + if (!m0) + err = ENOMEM; + } + *list = m0; *cons += frags; *pages_flipped_p = pages_flipped;