From owner-svn-src-head@FreeBSD.ORG Tue Feb 24 20:16:11 2015 Return-Path: Delivered-To: svn-src-head@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id EC87D4BC; Tue, 24 Feb 2015 20:16:10 +0000 (UTC) Received: from mail-ig0-x233.google.com (mail-ig0-x233.google.com [IPv6:2607:f8b0:4001:c05::233]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client CN "smtp.gmail.com", Issuer "Google Internet Authority G2" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id B159199; Tue, 24 Feb 2015 20:16:10 +0000 (UTC) Received: by mail-ig0-f179.google.com with SMTP id l13so200825iga.0; Tue, 24 Feb 2015 12:16:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:sender:in-reply-to:references:date:message-id:subject :from:to:cc:content-type; bh=qUQjRpGscbSPyKsN510dyzbqEG/i/+glbkkePsBZBKk=; b=W77IXf+0xI5ZsdJhLPTGa4XBXMg5GJE4H6P030L8M4ayYxKfr4IH2VakPPk9/BESh9 ngGilN9EbRo830cCEzL7oPnpzON6QdGV4Ic07HgyoaOXfV/JBfhN35UuRNOmyUhbmD68 wzhb37jZtE5NGOdOo+XBi17KnIx5pRaKUCvKkxlk1D/PTpPj5AQ64VT+WncqCOrWvSiS Cnu10Fb0hYpyJfKwqc8I/DdvCJ8Pfg3le6HpdEwuUTJDmmTRee4sMjUluN0ia9TVlb1J A5EGBobghOsbbjTaavyBVsID5g+VCLZQy7KF+ScevL+AGSfetBeLiBPLTZLZt47Kt2Yy 3ZfA== MIME-Version: 1.0 X-Received: by 10.107.136.230 with SMTP id s99mr12088ioi.8.1424808970140; Tue, 24 Feb 2015 12:16:10 -0800 (PST) Sender: adrian.chadd@gmail.com Received: by 10.36.17.66 with HTTP; Tue, 24 Feb 2015 12:16:10 -0800 (PST) In-Reply-To: <201502241257.t1OCv40V097418@svn.freebsd.org> References: <201502241257.t1OCv40V097418@svn.freebsd.org> Date: Tue, 24 Feb 2015 12:16:10 -0800 X-Google-Sender-Auth: xMUyzCyTeQWEOAIApU7KikVUIJo Message-ID: Subject: Re: svn commit: r279236 - head/sys/netinet From: Adrian Chadd To: Zbigniew Bodek Content-Type: text/plain; charset=UTF-8 Cc: "svn-src-head@freebsd.org" , "svn-src-all@freebsd.org" , "src-committers@freebsd.org" X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 24 Feb 2015 20:16:11 -0000 Hi, Erm, did you test this stuff on MIPS too? We should be smarter about accessing fields in the IP header, rather than trying to play alignment games like this. -adrian On 24 February 2015 at 04:57, Zbigniew Bodek wrote: > Author: zbb > Date: Tue Feb 24 12:57:03 2015 > New Revision: 279236 > URL: https://svnweb.freebsd.org/changeset/base/279236 > > Log: > Change struct attribute to avoid aligned operations mismatch > > Previous __alignment(4) allowed compiler to assume that operations are > performed on aligned region. On ARM processor, this led to alignment fault > as shown below: > trapframe: 0xda9e5b10 > FSR=00000001, FAR=a67b680e, spsr=60000113 > r0 =00000000, r1 =00000068, r2 =0000007c, r3 =00000000 > r4 =a67b6826, r5 =a67b680e, r6 =00000014, r7 =00000068 > r8 =00000068, r9 =da9e5bd0, r10=00000011, r11=da9e5c10 > r12=da9e5be0, ssp=da9e5b60, slr=a054f164, pc =a054f2cc > <...> > udp_input+0x264: ldmia r5, {r0-r3, r6} > udp_input+0x268: stmia r12, {r0-r3, r6} > > This was due to instructions which do not support unaligned access, > whereas for __alignment(2) compiler replaced ldmia/stmia with some > logically equivalent memcpy operations. > In fact, the assumption that 'struct ip' is always 4-byte aligned > is definitely false, as we have no impact on data alignment of packet > stream received. > > Another possible solution would be to explicitely perform memcpy() > on objects of 'struct ip' type, which, however, would suffer from > performance drop, and be merely a problem hiding. > > Please, note that this has nothing to do with > ARM32_DISABLE_ALIGNMENT_FAULTS option, but is related strictly to > compiler behaviour. > > Submitted by: Wojciech Macek > Reviewed by: glebius, ian > Obtained from: Semihalf > > Modified: > head/sys/netinet/ip.h > > Modified: head/sys/netinet/ip.h > ============================================================================== > --- head/sys/netinet/ip.h Tue Feb 24 12:31:08 2015 (r279235) > +++ head/sys/netinet/ip.h Tue Feb 24 12:57:03 2015 (r279236) > @@ -67,7 +67,7 @@ struct ip { > u_char ip_p; /* protocol */ > u_short ip_sum; /* checksum */ > struct in_addr ip_src,ip_dst; /* source and dest address */ > -} __packed __aligned(4); > +} __packed __aligned(2); > > #define IP_MAXPACKET 65535 /* maximum packet size */ > >