Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

batman-adv: always assume 2-byte packet alignment

NIC drivers generally try to ensure that the "network header" is aligned
to a 4-byte boundary. This is not always possible: When Ethernet frames are
encapsulated in other packets with 4-byte aligned headers, the inner
Ethernet header will have 4-byte alignment, and in consequence, the inner
network header is aligned to 2, but not to 4 bytes.

Most parts of batman-adv only care about 2-byte alignment; in particular,
no unaligned accesses occur in performance-critical paths that handle
actual payload data. This is not true for OGM handling: the seqno and crc
fields are accessed as 32-bit values. To avoid these unaligned accesses,
this patch reduces the expected packet alignment to 2 bytes for all of
batadv's packet types.

As no unaligned accesses existed on the performance-critical paths anyways,
this chance does have any (positive or negative) effect on performance, but
it still makes sense to avoid these accesses to prevent log noise when
examining other unaligned accesses in the kernel while batman-adv is
active.

Signed-off-by: Matthias Schiffer <mschiffer@universe-factory.net>
Signed-off-by: Sven Eckelmann <sven@narfation.org>
Signed-off-by: Simon Wunderlich <sw@simonwunderlich.de>

authored by

Matthias Schiffer and committed by
Simon Wunderlich
a163dc22 d7625f9f

+2 -11
+2 -11
include/uapi/linux/batadv_packet.h
··· 196 196 __be16 group; /* group id */ 197 197 }; 198 198 199 - #pragma pack() 200 - 201 199 /** 202 200 * struct batadv_ogm_packet - ogm (routing protocol) packet 203 201 * @packet_type: batman-adv packet type, part of the general header ··· 220 222 __u8 reserved; 221 223 __u8 tq; 222 224 __be16 tvlv_len; 223 - /* __packed is not needed as the struct size is divisible by 4, 224 - * and the largest data type in this struct has a size of 4. 225 - */ 226 225 }; 227 226 228 227 #define BATADV_OGM_HLEN sizeof(struct batadv_ogm_packet) ··· 244 249 __u8 orig[ETH_ALEN]; 245 250 __be16 tvlv_len; 246 251 __be32 throughput; 247 - /* __packed is not needed as the struct size is divisible by 4, 248 - * and the largest data type in this struct has a size of 4. 249 - */ 250 252 }; 251 253 252 254 #define BATADV_OGM2_HLEN sizeof(struct batadv_ogm2_packet) ··· 397 405 * misalignment of the payload after the ethernet header. It may also lead to 398 406 * leakage of information when the padding it not initialized before sending. 399 407 */ 400 - #pragma pack(2) 401 408 402 409 /** 403 410 * struct batadv_unicast_packet - unicast packet for network payload ··· 524 533 __be16 coded_len; 525 534 }; 526 535 527 - #pragma pack() 528 - 529 536 /** 530 537 * struct batadv_unicast_tvlv_packet - generic unicast packet with tvlv payload 531 538 * @packet_type: batman-adv packet type, part of the general header ··· 629 640 __u8 flags; 630 641 __u8 reserved[3]; 631 642 }; 643 + 644 + #pragma pack() 632 645 633 646 #endif /* _UAPI_LINUX_BATADV_PACKET_H_ */