From owner-freebsd-amd64@FreeBSD.ORG Thu May 29 21:19:07 2014 Return-Path: Delivered-To: freebsd-amd64@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 33B093CE for ; Thu, 29 May 2014 21:19:07 +0000 (UTC) Received: from mail-qg0-x234.google.com (mail-qg0-x234.google.com [IPv6:2607:f8b0:400d:c04::234]) (using TLSv1 with cipher ECDHE-RSA-RC4-SHA (128/128 bits)) (Client CN "smtp.gmail.com", Issuer "Google Internet Authority G2" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id E726528AD for ; Thu, 29 May 2014 21:19:06 +0000 (UTC) Received: by mail-qg0-f52.google.com with SMTP id a108so2825415qge.39 for ; Thu, 29 May 2014 14:19:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=Dv8b3bvR2LmagfSsMXp1hlCDdSxcFI+rt/cTLwn8Yhk=; b=W+JYJMzTf1T8W9/nP6QRpK4NEcOgx6Hw1qe0AhM6QoC9K8a/sSDCP7J7V+P83r8OGd ZmxpTt98Lhv3B41YNWavu/P8l5is91yULgFKR8/Q/2EIeHObRcsCm691UguZ7Ck8a2Wi QrlxJ8bo31reOL8EQPOL23qPA06uykEshb/D8eN+JH/t/UJH/nJYvLQCl992/QwAGfQd B2DistiCDuVA8FwpKiCVwSHbjmQPg8E2shzE7OIIze6Di4MuCXC9MotPNFO7WaVzrfk2 4W1hBYd1jOTyzChvCAApWlVIfrWnsfZhU8SI9yvv3C9/Ablp/WH09J/OZ3J2QrWrPPRr cZVg== MIME-Version: 1.0 X-Received: by 10.224.60.71 with SMTP id o7mr14527144qah.38.1401398346093; Thu, 29 May 2014 14:19:06 -0700 (PDT) Received: by 10.140.48.37 with HTTP; Thu, 29 May 2014 14:19:06 -0700 (PDT) In-Reply-To: <20140529104458.GA61598@server.rulingia.com> References: <20140523225300.GA14433@server.rulingia.com> <537FD853.3000505@wemm.org> <537FD9A2.2010607@wemm.org> <20140523233444.GH74331@kib.kiev.ua> <20140524033944.GA96083@server.rulingia.com> <20140524074101.GI74331@kib.kiev.ua> <20140526113622.GB96083@server.rulingia.com> <20140526134457.GR74331@kib.kiev.ua> <20140528225542.GA46230@server.rulingia.com> <20140529013817.GF3991@kib.kiev.ua> <20140529104458.GA61598@server.rulingia.com> Date: Thu, 29 May 2014 14:19:06 -0700 Message-ID: Subject: Re: i386 Go programs crash on amd64 From: Neel Natu To: Peter Jeremy Content-Type: text/plain; charset=UTF-8 Cc: freebsd-amd64@freebsd.org X-BeenThere: freebsd-amd64@freebsd.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Porting FreeBSD to the AMD64 platform List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 29 May 2014 21:19:07 -0000 Hi, On Thu, May 29, 2014 at 3:44 AM, Peter Jeremy wrote: > On 2014-May-29 04:38:18 +0300, Konstantin Belousov wrote: >>Hm, I think I know what is going on. Try this, please. >>At least, your test binary worked for me. > > Thank you. That seems to fix the problem even on non-trivial code. > Occasionally, I run into a problem where sys arch(I386_SET_LDT) fails with a ENOSPC. The golang runtime isn't checking the error return correctly and proceeds to load the bogus selector value into %gs. ./write pid 2571 comm write: signal 10 err e4 code 3 type 9 addr 0x8062446 rsp 0xffffdae8 rip 0x8062446 <8e e8 83 c4 20 c3 00 00> Bus error (core dumped) Here is the output of kdump: $ kdump capability mode sandbox enabled 1934 ktrace RET ktrace 0 1934 ktrace CALL execve(0x7fffffffed2f,0x7fffffffeae0,0x7fffffffeaf0) 1934 ktrace NAMI "./write" 1934 write RET execve 0 1934 write CALL sysarch(0x1,0xffffdb38) 1934 write RET sysarch -1 errno 28 No space left on device 1934 write PSIG SIGBUS SIG_DFL code=BUS_OBJERR 1934 write NAMI "write.core" In any case this is a problem because we aren't zeroing the LDT after allocation. Here is a patch that fixes it: Index: sys/amd64/amd64/sys_machdep.c =================================================================== --- sys/amd64/amd64/sys_machdep.c (revision 266856) +++ sys/amd64/amd64/sys_machdep.c (working copy) @@ -462,7 +462,7 @@ new_ldt = malloc(sizeof(struct proc_ldt), M_SUBPROC, M_WAITOK); new_ldt->ldt_base = (caddr_t)kmem_malloc(kernel_arena, max_ldt_segment * sizeof(struct user_segment_descriptor), - M_WAITOK); + M_WAITOK | M_ZERO); if (new_ldt->ldt_base == NULL) { FREE(new_ldt, M_SUBPROC); mtx_lock(&dt_lock); Ok to commit? best Neel > -- > Peter Jeremy