From owner-freebsd-net@FreeBSD.ORG Thu Jan 9 23:39:00 2014 Return-Path: Delivered-To: freebsd-net@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 0D91A12B; Thu, 9 Jan 2014 23:39:00 +0000 (UTC) Received: from h2.funkthat.com (gate2.funkthat.com [208.87.223.18]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id D807E1AEE; Thu, 9 Jan 2014 23:38:59 +0000 (UTC) Received: from h2.funkthat.com (localhost [127.0.0.1]) by h2.funkthat.com (8.14.3/8.14.3) with ESMTP id s09Ncwm9059056 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Thu, 9 Jan 2014 15:38:59 -0800 (PST) (envelope-from jmg@h2.funkthat.com) Received: (from jmg@localhost) by h2.funkthat.com (8.14.3/8.14.3/Submit) id s09Ncwe2059055; Thu, 9 Jan 2014 15:38:58 -0800 (PST) (envelope-from jmg) Date: Thu, 9 Jan 2014 15:38:58 -0800 From: John-Mark Gurney To: Guy Yur Subject: Re: 10.0-RC1, armv6: "pfctl -s state" crashes on BeagleBone Black due to unaligned access Message-ID: <20140109233858.GL46596@funkthat.com> Mail-Followup-To: Guy Yur , Gleb Smirnoff , freebsd-net@freebsd.org, freebsd-arm@freebsd.org References: <20140109104223.GS71033@FreeBSD.org> <20140109222610.GJ46596@funkthat.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.4.2.3i X-Operating-System: FreeBSD 7.2-RELEASE i386 X-PGP-Fingerprint: 54BA 873B 6515 3F10 9E88 9322 9CB1 8F74 6D3F A396 X-Files: The truth is out there X-URL: http://resnet.uoregon.edu/~gurney_j/ X-Resume: http://resnet.uoregon.edu/~gurney_j/resume.html X-to-the-FBI-CIA-and-NSA: HI! HOW YA DOIN? can i haz chizburger? X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.2.2 (h2.funkthat.com [127.0.0.1]); Thu, 09 Jan 2014 15:38:59 -0800 (PST) Cc: freebsd-net@freebsd.org, freebsd-arm@freebsd.org X-BeenThere: freebsd-net@freebsd.org X-Mailman-Version: 2.1.17 Precedence: list List-Id: Networking and TCP/IP with FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 09 Jan 2014 23:39:00 -0000 Guy Yur wrote this message on Fri, Jan 10, 2014 at 01:04 +0200: > On Fri, Jan 10, 2014 at 12:26 AM, John-Mark Gurney wrote: > > Guy Yur wrote this message on Fri, Jan 10, 2014 at 00:17 +0200: > >> On Thu, Jan 9, 2014 at 12:42 PM, Gleb Smirnoff wrote: > >> > Guy, > >> > > >> > On Sat, Jan 04, 2014 at 03:06:02PM +0200, Guy Yur wrote: > >> > G> I am running 10.0-RC1 arm.armv6 on the BeagleBone Black. > >> > G> The "pfctl -s state" command is crashing when trying to print the > >> > G> second entry. > >> > > > Ok, that makes sense... so, either we mark struct pf_addr as __packed, > > or we do some nasty stuff, like the following in print_host: > > struct { > > struct pf_addr a > > } *uaddr __packed; > > > > uaddr = addr; > > aw.v.a.addr = uaddr->a; > > > > it's not pretty, but I believe it would work... > > For performance reasons, I don't think pf_addr should be marked as __packed. > > I attached the changes I am now using in print_state() since there is > no need to copy > the full pfsync_state, only pf_addr. > I converted sk and nk from pointers to structs on the stack and using > struct copy. > pf_addr is 16 bytes. Did you look at using the above trick? Since we are iterating over a list, that'll be a lot of copies, plus, I'm not sure that your fix will be guaranteed to work for ever.. since there isn't a requirement that the copy happens w/ bcopy/memcpy or some other copy routine that assumes things might not be aligned... Specificly these: - sk = &s->key[PF_SK_STACK]; - nk = &s->key[PF_SK_WIRE]; + sk = s->key[PF_SK_STACK]; + nk = s->key[PF_SK_WIRE]; since s->key is already assumed to be aligned, a future compiler could be smart enough to say, I'm not going to use the stack.. That would/could happen if print_host's addr arg grew a const which it could... Also, I just realized that some of the lines modify sk (setting port), but you don't write those modifications back to s->key[PF_SK_STACK]... -- John-Mark Gurney Voice: +1 415 225 5579 "All that I will do, has been done, All that I have, has not."