Development discussion of WireGuard
 help / color / mirror / Atom feed
From: Hannes Frederic Sowa <hannes@stressinduktion.org>
To: "Jason A. Donenfeld" <Jason@zx2c4.com>,
	Netdev <netdev@vger.kernel.org>,
	linux-mips@linux-mips.org
Cc: LKML <linux-kernel@vger.kernel.org>,
	WireGuard mailing list <wireguard@lists.zx2c4.com>
Subject: Re: Misalignment, MIPS, and ip_hdr(skb)->version
Date: Thu, 8 Dec 2016 01:30:34 +0100	[thread overview]
Message-ID: <095cac5b-b757-6f4a-e699-8eedf9ed7221@stressinduktion.org> (raw)
In-Reply-To: <CAHmME9o_eCNXpVztOZKW55kpRtE+1KSEQTQOjUBVn68Y2+or2g@mail.gmail.com>

Hi Jason,

On 07.12.2016 19:35, Jason A. Donenfeld wrote:
> 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?

Your custom protocol should be designed in a way you get an aligned ip
header. Most protocols of the IETF follow this mantra and it is always
possible to e.g. pad options so you end up on aligned boundaries for the
next header.

GRE-TEB for example needs skb_copy_bits to extract the header so it can
access them in an aligned way.

> 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 don't see an issue with that at all. Why do you think it could be a
problem?

Bye,
Hannes

  parent reply	other threads:[~2016-12-08  0:25 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-12-07 18:35 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 [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=095cac5b-b757-6f4a-e699-8eedf9ed7221@stressinduktion.org \
    --to=hannes@stressinduktion.org \
    --cc=Jason@zx2c4.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mips@linux-mips.org \
    --cc=netdev@vger.kernel.org \
    --cc=wireguard@lists.zx2c4.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).