Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753631AbcLHAa4 (ORCPT ); Wed, 7 Dec 2016 19:30:56 -0500 Received: from out4-smtp.messagingengine.com ([66.111.4.28]:54123 "EHLO out4-smtp.messagingengine.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752905AbcLHAay (ORCPT ); Wed, 7 Dec 2016 19:30:54 -0500 X-ME-Sender: X-Sasl-enc: EBQ1uLfe/+HBwD78gekAQLWr8x3n1mVlMmgP/nckBxyS 1481157036 Subject: Re: Misalignment, MIPS, and ip_hdr(skb)->version To: "Jason A. Donenfeld" , Netdev , linux-mips@linux-mips.org References: Cc: LKML , WireGuard mailing list From: Hannes Frederic Sowa Message-ID: <095cac5b-b757-6f4a-e699-8eedf9ed7221@stressinduktion.org> Date: Thu, 8 Dec 2016 01:30:34 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.4.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1888 Lines: 43 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