From owner-freebsd-hackers@freebsd.org Mon Mar 27 16:18:45 2017 Return-Path: Delivered-To: freebsd-hackers@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id CB3D9D20CD1 for ; Mon, 27 Mar 2017 16:18:45 +0000 (UTC) (envelope-from kostikbel@gmail.com) Received: from kib.kiev.ua (kib.kiev.ua [IPv6:2001:470:d5e7:1::1]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 6B67D1D8; Mon, 27 Mar 2017 16:18:45 +0000 (UTC) (envelope-from kostikbel@gmail.com) Received: from tom.home (kib@localhost [127.0.0.1]) by kib.kiev.ua (8.15.2/8.15.2) with ESMTPS id v2RGIXbt012419 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Mon, 27 Mar 2017 19:18:34 +0300 (EEST) (envelope-from kostikbel@gmail.com) DKIM-Filter: OpenDKIM Filter v2.10.3 kib.kiev.ua v2RGIXbt012419 Received: (from kostik@localhost) by tom.home (8.15.2/8.15.2/Submit) id v2RGIX4n012418; Mon, 27 Mar 2017 19:18:33 +0300 (EEST) (envelope-from kostikbel@gmail.com) X-Authentication-Warning: tom.home: kostik set sender to kostikbel@gmail.com using -f Date: Mon, 27 Mar 2017 19:18:33 +0300 From: Konstantin Belousov To: Steven Hartland Cc: "K. Macy" , "freebsd-hackers@freebsd.org" Subject: Re: Help needed to identify golang fork / memory corruption issue on FreeBSD Message-ID: <20170327161833.GL43712@kib.kiev.ua> References: <20161206125919.GQ54029@kib.kiev.ua> <8b502580-4d2d-1e1f-9e05-61d46d5ac3b1@multiplay.co.uk> <20161206143532.GR54029@kib.kiev.ua> <18b40a69-4460-faf2-c0ce-7491eca92782@multiplay.co.uk> <20170317082333.GP16105@kib.kiev.ua> <180a601b-5481-bb41-f7fc-67976aabe451@multiplay.co.uk> <20170317124437.GR16105@kib.kiev.ua> <5ba92447-945e-6fea-ad4f-f58ac2a0012e@multiplay.co.uk> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <5ba92447-945e-6fea-ad4f-f58ac2a0012e@multiplay.co.uk> User-Agent: Mutt/1.8.0 (2017-02-23) 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.1 X-Spam-Checker-Version: SpamAssassin 3.4.1 (2015-04-28) on tom.home X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 27 Mar 2017 16:18:45 -0000 On Mon, Mar 27, 2017 at 12:47:11PM +0100, Steven Hartland wrote: > OK now the similar but unrelated issue with signal stacks is solved I've > moved back to the initial issue. > > I've made some progress with a reproduction case as detailed here: > https://github.com/golang/go/issues/15658#issuecomment-288747812 > > In short it seems that having a running child, while the parent runs GC, > is some how responsible for memory corruption in the parent. > > The reason I believe this is if I run the same GC in the parent after > the child exits instead of while its running, I've been unable to > reproduce the issue. > > As the memory segments are COW then the issue might be in VM subsystem. Well, it might be, but it is a strange corruption mode to believe. > > In order to confirm / deny this I was wondering if there was a way to > force a full copy of all segments for the child instead of using the COW > optimisation. No, there is no. By design, copying only occurs on faults, when VM detects that the map entry needs copying. Doing the actual copy at fork time would require writing a lot of new code. Does go have FreeBSD/i386 port ? If yes, is the issue reproducable there ? Another blind experiment to try is to comment out call to vm_object_collapse() in sys/vm/vm_map.c:vm_map_copy_entry() and see if it changes anything. What could be quite interesting is to look at the parent and possibly child address map after the error occured, using procstat -v. At least for parent, this should be relatively easy to set up, just make go runtime spin or pause on panic, instead of exiting, and then use procstat. > > Is this something that would be relatively easy to hack into the kernel, > and if so pointers would be appreciated. BTW, I looked some more at the go code, and I noted that runtimemmap() implementation looks very strange. It ignores %rflags.C bit to identify error, and instead callers of mmap() compare the return value with 4096, assuming Linux-style error reporting. This would certainly break if mmap(2) syscall returns ERESTART one day.