From owner-freebsd-amd64@FreeBSD.ORG Thu May 29 01:38:25 2014 Return-Path: Delivered-To: freebsd-amd64@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 31F404C6 for ; Thu, 29 May 2014 01:38:25 +0000 (UTC) Received: from kib.kiev.ua (kib.kiev.ua [IPv6:2001:470:d5e7:1::1]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id C71BF2AB7 for ; Thu, 29 May 2014 01:38:24 +0000 (UTC) Received: from tom.home (kostik@localhost [127.0.0.1]) by kib.kiev.ua (8.14.9/8.14.9) with ESMTP id s4T1cJTm043462; Thu, 29 May 2014 04:38:19 +0300 (EEST) (envelope-from kostikbel@gmail.com) DKIM-Filter: OpenDKIM Filter v2.8.3 kib.kiev.ua s4T1cJTm043462 Received: (from kostik@localhost) by tom.home (8.14.9/8.14.8/Submit) id s4T1cIGY043460; Thu, 29 May 2014 04:38:18 +0300 (EEST) (envelope-from kostikbel@gmail.com) X-Authentication-Warning: tom.home: kostik set sender to kostikbel@gmail.com using -f Date: Thu, 29 May 2014 04:38:18 +0300 From: Konstantin Belousov To: Peter Jeremy Subject: Re: i386 Go programs crash on amd64 Message-ID: <20140529013817.GF3991@kib.kiev.ua> 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> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="Pgaa2uWPnPrfixyx" Content-Disposition: inline In-Reply-To: <20140528225542.GA46230@server.rulingia.com> User-Agent: Mutt/1.5.23 (2014-03-12) X-Spam-Status: No, score=-2.0 required=5.0 tests=ALL_TRUSTED,BAYES_00, DKIM_ADSP_CUSTOM_MED,FREEMAIL_FROM,NML_ADSP_CUSTOM_MED autolearn=no autolearn_force=no version=3.4.0 X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on tom.home 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 01:38:25 -0000 --Pgaa2uWPnPrfixyx Content-Type: text/plain; charset=us-ascii Content-Disposition: inline On Thu, May 29, 2014 at 08:55:42AM +1000, Peter Jeremy wrote: > As I wrote in my initial mail, I am not certain whether this is a problem > with Go or FreeBSD. And having done some poking at corefiles with gdb > (you need gdb7.6 from ports to grok the Go debug information), I have > found that all my programs are dying at: > mov %gs:0xfffffff8,%ecx > but it seems to be timing related as to when the offending instruction > is executed. I will do some further investigation into how segment > wraparound is handled. Hm, I think I know what is going on. Try this, please. At least, your test binary worked for me. diff --git a/sys/amd64/amd64/exception.S b/sys/amd64/amd64/exception.S index d4e58b1..d51078d 100644 --- a/sys/amd64/amd64/exception.S +++ b/sys/amd64/amd64/exception.S @@ -721,21 +721,38 @@ ld_fsbase: pushfq cli movl $MSR_GSBASE,%ecx + /* Save current kernel %gs base into %r12d:%r13d */ rdmsr + movl %eax,%r12d + movl %edx,%r13d .globl ld_gs ld_gs: movw %si,%gs + /* Save user %gs base into %r14d:%r15d */ + rdmsr + movl %eax,%r14d + movl %edx,%r15d + /* Restore kernel %gs base */ + movl %r12d,%eax + movl %r13d,%edx wrmsr popfq + /* + * Restore user %gs base, either from PCB if used for TLS, or + * from the previously saved msr read. + */ + movl $MSR_KGSBASE,%ecx cmpw $KUG32SEL,%si jne 1f - movl $MSR_KGSBASE,%ecx movl PCB_GSBASE(%r8),%eax movl PCB_GSBASE+4(%r8),%edx + jmp ld_gsbase +1: + movl %r14d,%eax + movl %r15d,%edx .globl ld_gsbase ld_gsbase: - wrmsr -1: + wrmsr /* May trap if non-canonical, but only for TLS. */ .globl ld_es ld_es: movw TF_ES(%rsp),%es --Pgaa2uWPnPrfixyx Content-Type: application/pgp-signature -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.22 (FreeBSD) iQIcBAEBAgAGBQJTho+JAAoJEJDCuSvBvK1B0DYP/0+tfp2ARb1YMsrwdwKEAUZ9 zwEXu0K7qsEnXXQGZlTpBFXpEexZSPQsVDOKsMNYSRWOHS4v38v6OlX3ha0UlTPV jtwbGS5agxUy69p19e/NcUP893wzeVzQB5LW/5R11ERb3hlTj9xOGJNO99h3pE7E xJ0Hc+BZ8HhRKr4yHMb3ETEy4sVyR+4xeYs7pu0BgQpQK0VtKd9UKDDtZzvGVulH jydPjv3SPlw7HKeKdDTJMwcOpMCSRm4u0iRWklDL4snqtKB4Yg+BFeHJGKVctu/W Pth8ESJKqiOa+1L1sKb7oQN5UVh4jmSSkVtEyPniVRLkNgr+XP2tA+/oGbg0ZnI7 EOfz1oD35vveW8cUNTZTmX/GB3mS8PS4yRQzcH34SNS1V1jk8O1db1DMnVjjDbNi mFfpBC79OxtO8fygyOv6+qNignSDFPnKzmadWzyVZVg2Y9EcS/DKf5JC8b7tB1yf MpYI4OeaPnx8lRxjokhoFoMzFwl6ManKWNLwZHm2x4YCha/2/POfN+TK5xPluJy/ P4fA/oc3KZgb7s3ykfytviktgZtiQLb1kzumDcGaYBYyVBPjqePn0zhoS9bBcd1l ku3szAcE+GbdhYMeMViszW6wOgDsl1np2ZEvYd/6BshHFm4zrP3oyr65aYdTwOs4 EdtHdpOWvVTzyVuGhpg6 =XF5w -----END PGP SIGNATURE----- --Pgaa2uWPnPrfixyx--