From owner-freebsd-arm@FreeBSD.ORG Sat Dec 21 19:16:00 2013 Return-Path: Delivered-To: freebsd-arm@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 938965D3; Sat, 21 Dec 2013 19:16: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 6D1E01C7D; Sat, 21 Dec 2013 19:16:00 +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 rBLJFqA3084907 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Sat, 21 Dec 2013 11:15:53 -0800 (PST) (envelope-from jmg@h2.funkthat.com) Received: (from jmg@localhost) by h2.funkthat.com (8.14.3/8.14.3/Submit) id rBLJFq3x084906; Sat, 21 Dec 2013 11:15:52 -0800 (PST) (envelope-from jmg) Date: Sat, 21 Dec 2013 11:15:52 -0800 From: John-Mark Gurney To: Guy Yur Subject: Re: 10.0-RC1: net/mpd5 crashes in NgMkSockNode due to stack alignment on ARM EABI Message-ID: <20131221191552.GE99167@funkthat.com> Mail-Followup-To: Guy Yur , freebsd-arm@freebsd.org, freebsd-net@FreeBSD.org References: Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="/Uq4LBwYP4y1W6pO" 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]); Sat, 21 Dec 2013 11:15:53 -0800 (PST) Cc: freebsd-net@freebsd.org, freebsd-arm@freebsd.org X-BeenThere: freebsd-arm@freebsd.org X-Mailman-Version: 2.1.17 Precedence: list List-Id: "Porting FreeBSD to ARM processors." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 21 Dec 2013 19:16:00 -0000 --/Uq4LBwYP4y1W6pO Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Guy Yur wrote this message on Sat, Dec 21, 2013 at 19:24 +0200: > I am running 10.0-RC1 on the BeagleBone Black and the net/mpd5 port is > crashing in libnetgraph NgMkSockNode due to stack alignment. > > 10.0-RC1 World and kernel were compiled in a VirtualBox VM running > 9.2-RELEASE-p2 i386. > clang and ARM_EABI used as the default make options. > > Added prints in NgMkSockNode show rbuf is aligned on 2-byte and not > 4-byte which is needed to access ni->id (a uint32_t). > > ni = 0xbfffe87a > rbuf = 0xbfffe842 > sizeof(resp->header) = 56 > > > (gdb) bt > #0 0x201529a0 in NgMkSockNode (name=, csp=0xbfffe95c, > dsp=0xbfffe958) at /usr/src/lib/libnetgraph/sock.c:134 > #1 0x00037b9c in MppcTestCap () at ccp_mppc.c:754 > #2 0x0007c1f4 in main (ac=4, av=0xbfffeb90) at main.c:248 > #3 0x0000d1b0 in __start (argc=4, argv=0xbfffeb90, env=0xbfffeba4, > ps_strings=, obj=, > cleanup=) at /usr/src/lib/csu/arm/crt1.c:115 > #4 0x203e9dc0 in _thr_ast (curthread=0x200fd000) > at /usr/src/lib/libthr/thread/thr_sig.c:265 > > > Putting rbuf in a union with struct ng_mesg sorted the alignment to > 4-byte and mpd5 didn't crash. > I attached the changes I used to test mpd5 doesn't crash with correct alignment. The patch looks correct, but lets make sure that the -net people don't have an issue with it... I've reattached Guy's patch for review. Guy, bug me in a week or so if I haven't committed it, and I will... Thanks for tracking this down. -- John-Mark Gurney Voice: +1 415 225 5579 "All that I will do, has been done, All that I have, has not." --/Uq4LBwYP4y1W6pO Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="sock-NgMkSockNode.patch" Index: lib/libnetgraph/sock.c =================================================================== --- lib/libnetgraph/sock.c (revision 259250) +++ lib/libnetgraph/sock.c (working copy) @@ -111,8 +111,11 @@ /* Save node name */ strlcpy(namebuf, name, sizeof(namebuf)); } else if (dsp != NULL) { - u_char rbuf[sizeof(struct ng_mesg) + sizeof(struct nodeinfo)]; - struct ng_mesg *const resp = (struct ng_mesg *) rbuf; + union { + u_char rbuf[sizeof(struct ng_mesg) + sizeof(struct nodeinfo)]; + struct ng_mesg res; + } res; + struct ng_mesg *const resp = (struct ng_mesg *) res.rbuf; struct nodeinfo *const ni = (struct nodeinfo *) resp->data; /* Find out the node ID */ @@ -123,7 +126,7 @@ NGLOG("send nodeinfo"); goto errout; } - if (NgRecvMsg(cs, resp, sizeof(rbuf), NULL) < 0) { + if (NgRecvMsg(cs, resp, sizeof(res.rbuf), NULL) < 0) { errnosv = errno; if (_gNgDebugLevel >= 1) NGLOG("recv nodeinfo"); --/Uq4LBwYP4y1W6pO--