Turns out the __aligned(8) solution has some unforeseen side effects:
<deraadt> /usr/src/sys/dev/ic/re.c:1602: warning: ignoring alignment for stack
allocated 'mh'
While that warning is probably false in the sense that we don't
actually need the 8-byte alignment that we're asking for, the compiler
rightly complains that we shouldn't do this. I think that this leaves
us adding explicit padding as the only viable option.
This diff uses #ifndef __LP64__. Alternative would be to use u_long
and take hit of an extra 8-bytes on 64-bit architectures. That's what
Theo prefers to force the folks that care to redesign this properly...
This diff also adds a CTASSERT such that we catch any issues with the
size of struct mbuf in the future.
Index: sys/mbuf.h
===================================================================
RCS file: /cvs/src/sys/sys/mbuf.h,v
retrieving revision 1.227
diff -u -p -r1.227 mbuf.h
--- sys/mbuf.h 10 May 2017 21:41:27 -0000 1.227
+++ sys/mbuf.h 16 May 2017 14:51:15 -0000
@@ -86,7 +86,10 @@ struct m_hdr {
u_int mh_len; /* amount of data in this mbuf */
short mh_type; /* type of data in this mbuf */
u_short mh_flags; /* flags; see below */
-} __aligned(8);
+#ifndef __LP64__
+ u_int mh_pad; /* pad to 8-byte boundary */
+#endif
+};
/* pf stuff */
struct pf_state_key;
Index: kern/uipc_mbuf.c
===================================================================
RCS file: /cvs/src/sys/kern/uipc_mbuf.c,v
retrieving revision 1.246
diff -u -p -r1.246 uipc_mbuf.c
--- kern/uipc_mbuf.c 8 May 2017 15:47:49 -0000 1.246
+++ kern/uipc_mbuf.c 16 May 2017 14:51:15 -0000
@@ -100,6 +100,8 @@
#include <net/pfvar.h>
#endif /* NPF > 0 */
+CTASSERT(sizeof(struct mbuf) == MSIZE);
+
/* mbuf stats */
COUNTERS_BOOT_MEMORY(mbstat_boot, MBSTAT_COUNT);
struct cpumem *mbstat = COUNTERS_BOOT_INITIALIZER(mbstat_boot);