From owner-freebsd-emulation@freebsd.org Thu Jun 14 10:13:36 2018 Return-Path: Delivered-To: freebsd-emulation@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id A81A510192BF for ; Thu, 14 Jun 2018 10:13:36 +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 199DC8210D for ; Thu, 14 Jun 2018 10:13:35 +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 ESMTP id w5EADPuh048532; Thu, 14 Jun 2018 13:13:28 +0300 (EEST) (envelope-from kostikbel@gmail.com) DKIM-Filter: OpenDKIM Filter v2.10.3 kib.kiev.ua w5EADPuh048532 Received: (from kostik@localhost) by tom.home (8.15.2/8.15.2/Submit) id w5EADP8m048531; Thu, 14 Jun 2018 13:13:25 +0300 (EEST) (envelope-from kostikbel@gmail.com) X-Authentication-Warning: tom.home: kostik set sender to kostikbel@gmail.com using -f Date: Thu, 14 Jun 2018 13:13:24 +0300 From: Konstantin Belousov To: Yanko Yankulov Cc: freebsd-emulation@freebsd.org Subject: Re: two proposed linuxulator fixes + ptrace Message-ID: <20180614101324.GW2493@kib.kiev.ua> References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.10.0 (2018-05-17) 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-emulation@freebsd.org X-Mailman-Version: 2.1.26 Precedence: list List-Id: Development of Emulators of other operating systems List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 14 Jun 2018 10:13:36 -0000 On Thu, Jun 14, 2018 at 11:31:20AM +0300, Yanko Yankulov wrote: > Hi all, > > I stumbled on two problems trying to run a proprietary java/native Linux > app on FreeBSD. I managed to get it working with two small changes to the > Linux compatibility code. Also in order to pinpoint the issues I got the > ptrace system working for Linux apps, enabling truss & gdb. > > This is all on recent CURRENT. > > The patches work for me, but I am absolutely sure there is better way to do > this, especially for the ptrace part. > > The first issue was 100% CPU usage on start with no progress. Turned out > that the app was expecting TracerPid field in its /proc/pid/status, so just > adding "sbuf_printf(sb, "TracerPid:\t%d\n", 0);" in > linprocfs_doprocstatus solved it. > > The second was random segfaults in the Java code. Traced it to mangled r10 > in the sigreturn path. Just preserving the r10 when returning from > sigreturn resolves it. > > --- a/sys/amd64/linux/linux_sysvec.c > +++ b/sys/amd64/linux/linux_sysvec.c > @@ -228,8 +228,9 @@ linux_set_syscall_retval(struct thread *td, int error) > * the syscall. So, do not clobber %rdx and %r10. > */ > td->td_retval[1] = frame->tf_rdx; > - frame->tf_r10 = frame->tf_rcx; > - > + if( td->td_sa.code != LINUX_SYS_linux_rt_sigreturn ) > + frame->tf_r10 = frame->tf_rcx; > + > cpu_set_syscall_retval(td, error); > > /* Restore all registers. */ > > > So this two fixes solved my issues and was able to run/use the problematic > application. > > The ptrace code is lot more messy, and I am really not happy with it, but I > didn't have the time to figure out a cleaner solution. Attaching it > though, as it at least might help someone to devise a better fix. Good work. For the ptrace patch, I suggest you to put it on https://reviews.freebsd.org and set at least me (kib), jhb and dchagin as reviewers. I will handle it. For the patch 1, TracePid, can you explain what is the meaning of the pid reported ? For the patch 3, %r10 preservation for linux_rt_sigreturn, shouldn't the same handling applied to non-rt signal return ? And in fact, shouldn't it be done based on the return code instead of the syscall number ? Look at the amd64/amd64/vm_machdep.c:cpu_set_syscall_retval(), where I think EJUSTRETURN case is used by linux sigreturns.