linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* Misalignment, MIPS, and ip_hdr(skb)->version
@ 2016-12-07 18:35 Jason A. Donenfeld
  2016-12-07 18:47 ` Dave Taht
  2016-12-08  0:30 ` Hannes Frederic Sowa
  0 siblings, 2 replies; 27+ messages in thread
From: Jason A. Donenfeld @ 2016-12-07 18:35 UTC (permalink / raw)
  To: Netdev, linux-mips; +Cc: LKML, WireGuard mailing list

Hey MIPS Networking People,

I receive encrypted packets with a 13 byte header. I decrypt the
ciphertext in place, and then discard the header. I then pass the
plaintext to the rest of the networking stack. The plaintext is an IP
packet. Due to the 13 byte header that was discarded, the plaintext
possibly begins at an unaligned location (depending on whether
dev->needed_headroom was respected).

Does this matter? Is this bad? Will there be a necessary performance hit?

In order to find out, I instrumented the MIPS unaligned access
exception handler to see where I was actually in trouble.
Surprisingly, the only part of the stack that seemed to be upset was
on calls to ip_hdr(skb)->version.

Two things disturb me about this. First, this seems too good to be
true. Does it seem reasonable to you that this is actually the only
place that would be problematic? Or was my testing methodology wrong
to arrive at such an optimistic conclusion?

Secondly, why should a call to ip_hdr(skb)->version cause an unaligned
access anyway? This struct member is simply the second half of a
single byte in a bit field. I'd expect for the compiler to generate a
single byte load, followed by a bitshift or a mask. Instead, the
compiler appears to generate a double byte load, hence the exception.
What's up with this? Stupid compiler that should be fixed? Some odd
optimization? What to do?

I'm considering just adding an extra byte of padding (see discussion
in [1]), but before I make any decision like that (and hopefully it
won't be necessary), I'd like to completely and entirely understand
the full effects and consequences of calling netif_rx(skb) when
skb->data is unaligned. Any insight you have to offer would be most
welcome.

Thanks,
Jason

[1] https://lists.zx2c4.com/pipermail/wireguard/2016-December/000709.html

^ permalink raw reply	[flat|nested] 27+ messages in thread

end of thread, other threads:[~2016-12-12 16:31 UTC | newest]

Thread overview: 27+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-12-07 18:35 Misalignment, MIPS, and ip_hdr(skb)->version Jason A. Donenfeld
2016-12-07 18:47 ` Dave Taht
2016-12-07 18:51   ` David Miller
2016-12-07 18:54     ` Jason A. Donenfeld
2016-12-07 19:52       ` David Miller
2016-12-08  0:29         ` Jason A. Donenfeld
2016-12-08  0:37           ` David Miller
2016-12-08 22:20             ` Jason A. Donenfeld
2016-12-08 23:14               ` David Miller
2016-12-11  8:07               ` Willy Tarreau
2016-12-11 10:47                 ` Måns Rullgård
2016-12-10 12:25       ` Felix Fietkau
2016-12-10 13:25         ` Måns Rullgård
2016-12-10 20:09           ` Felix Fietkau
2016-12-10 20:32             ` Måns Rullgård
2016-12-10 20:36               ` Felix Fietkau
2016-12-12 16:19           ` David Laight
2016-12-12 16:31             ` Måns Rullgård
2016-12-08  0:30 ` Hannes Frederic Sowa
2016-12-08  4:34   ` Daniel Kahn Gillmor
2016-12-09 11:26     ` Jiri Benc
2016-12-10 22:18     ` Dan Lüdtke
2016-12-11  7:15       ` Greg KH
2016-12-11 14:50         ` Jason A. Donenfeld
2016-12-11 15:30           ` Andrew Lunn
2016-12-11 15:37             ` Jason A. Donenfeld
2016-12-11 16:44           ` Willy Tarreau

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).