Skip to contentSkip to conversation

net/vxlan: Avoid unaligned access in vxlan_build_skb()

PATCH In review Sowmini Varadhan 5 participants 7 messages Sep 20, 2016 – Sep 21, 2016

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 net/vxlan: Avoid unaligned access in vxlan_build_skb()

The vxlan header may not be aligned to 4 bytes in vxlan_build_skb (e.g., for MLD packets). This patch avoids unaligned access traps from vxlan_build_skb (in platforms like sparc) by making struct vxlanhdr __packed.

---
 include/net/vxlan.h |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
include/net/vxlan.h +1 -1
index 0255613..1ec56f4 100644
@@ -18,7 +18,7 @@
 struct vxlanhdr {
 	__be32 vx_flags;
 	__be32 vx_vni;
-};
+} __packed;
 
 /* VXLAN header flags. */
 #define VXLAN_HF_VNI	cpu_to_be32(BIT(27))
Signature · 1 line
1.7.1
Acked-by on v2 1/1
#2 lore raw
In reply to Sowmini Varadhan
Quoted 6 lines · Sowmini Varadhan

The vxlan header may not be aligned to 4 bytes in vxlan_build_skb (e.g., for MLD packets). This patch avoids unaligned access traps from vxlan_build_skb (in platforms like sparc) by making struct vxlanhdr __packed.

Performance wise this should only affect code generation for archs where it matters anyway.

Thanks,
Hannes

#3 lore raw
Quoted 10 lines · Hannes Frederic Sowa
Quoted 6 lines · Sowmini Varadhan

The vxlan header may not be aligned to 4 bytes in vxlan_build_skb (e.g., for MLD packets). This patch avoids unaligned access traps from vxlan_build_skb (in platforms like sparc) by making struct vxlanhdr __packed.

Performance wise this should only affect code generation for archs where it matters anyway.

I think it's the opposite. Even on x86 compiler will use byte loads.

#4 lore raw
Quoted 7 lines · Alexei Starovoitov
Quoted 6 lines · Hannes Frederic Sowa
Quoted 5 lines · Sowmini Varadhan

The vxlan header may not be aligned to 4 bytes in vxlan_build_skb (e.g., for MLD packets). This patch avoids unaligned access traps from vxlan_build_skb (in platforms like sparc) by making struct vxlanhdr __packed.

Quoted 6 lines
Quoted 4 lines
Quoted 1 line

Performance wise this should only affect code generation for archs where it matters anyway.

I think it's the opposite. Even on x86 compiler will use byte loads.

I checked that on x86-64 actually. Also clearly visible here:

https://godbolt.org/g/xsW2P1

Bye,
Hannes

#6 lore raw
Quoted 8 lines · Eric Dumazet
Quoted 2 lines · Alexei Starovoitov

I think it's the opposite. Even on x86 compiler will use byte loads.

Unless you tweaked gcc, it should still use word loads on x86.

checked that on x86-64 actually. Also clearly visible here:

ahh. ok. good to know. thanks guys!