]> xenbits.xensource.com Git - people/julieng/freebsd.git/commitdiff
xen/netfront: Add 2 bytes padding in the rx mbuf
authorJulien Grall <julien.grall@citrix.com>
Mon, 5 Oct 2015 17:35:54 +0000 (18:35 +0100)
committerJulien Grall <julien.grall@citrix.com>
Mon, 2 Nov 2015 11:46:55 +0000 (11:46 +0000)
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 not supported. Therefore we might reveice an alignement
fault. To avoid 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.

Furthermore, I don't know if m_copyup is the rigth function to use here. Can
any expert to the network stack can tell me if there is a better solution?

sys/dev/xen/netfront/netfront.c

index 7588956210e6e4ba8285687c15560926101af518..57f826f1d0cce0cb8803f741b1fc3bc46d03d6da 100644 (file)
@@ -86,6 +86,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)
 
@@ -1247,6 +1249,22 @@ next_skip_queue:
                ref_cons = *cons + frags;
                frags++;
        }
+
+       if (err == 0) {
+               /*
+                * 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 not
+                * supported. 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 == 0)
+                       err = ENOMEM;
+       }
+
        *list = m0;
        *cons += frags;