From owner-svn-src-head@freebsd.org Fri Oct 16 11:23:31 2020 Return-Path: Delivered-To: svn-src-head@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 7D98C431540; Fri, 16 Oct 2020 11:23:31 +0000 (UTC) (envelope-from trasz@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4CCP0g2r2nz4p8P; Fri, 16 Oct 2020 11:23:31 +0000 (UTC) (envelope-from trasz@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 44E5AF3FF; Fri, 16 Oct 2020 11:23:31 +0000 (UTC) (envelope-from trasz@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id 09GBNVkW073740; Fri, 16 Oct 2020 11:23:31 GMT (envelope-from trasz@FreeBSD.org) Received: (from trasz@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id 09GBNUhp073737; Fri, 16 Oct 2020 11:23:30 GMT (envelope-from trasz@FreeBSD.org) Message-Id: <202010161123.09GBNUhp073737@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: trasz set sender to trasz@FreeBSD.org using -f From: Edward Tomasz Napierala Date: Fri, 16 Oct 2020 11:23:30 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r366756 - head/sys/compat/linux X-SVN-Group: head X-SVN-Commit-Author: trasz X-SVN-Commit-Paths: head/sys/compat/linux X-SVN-Commit-Revision: 366756 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.33 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 16 Oct 2020 11:23:31 -0000 Author: trasz Date: Fri Oct 16 11:23:30 2020 New Revision: 366756 URL: https://svnweb.freebsd.org/changeset/base/366756 Log: Set default stack size for Linux apps to 8MB. This matches Linux' defaults, makes core files smaller, and fixes applications which use pthread_join(3) in a wrong way, namely Steam. This is based on a patch submitted by Jason Yang, which I've reworked to set the limit instead of only changing the value reported (which is enough to fix the bug for Linux pthreads, but could be confusing). PR: 248225 Submitted by: Jason_YH_Yang at wistron.com (earlier version) Analyzed by: Alex S Reviewed by: emaste MFC after: 2 weeks Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D26778 Modified: head/sys/compat/linux/linux_emul.c head/sys/compat/linux/linux_mib.c head/sys/compat/linux/linux_mib.h Modified: head/sys/compat/linux/linux_emul.c ============================================================================== --- head/sys/compat/linux/linux_emul.c Fri Oct 16 11:22:29 2020 (r366755) +++ head/sys/compat/linux/linux_emul.c Fri Oct 16 11:23:30 2020 (r366756) @@ -115,6 +115,29 @@ linux_set_default_openfiles(struct thread *td, struct KASSERT(error == 0, ("kern_proc_setrlimit failed")); } +/* + * The default stack size limit in Linux is 8MB. + */ +static void +linux_set_default_stacksize(struct thread *td, struct proc *p) +{ + struct rlimit rlim; + int error; + + if (linux_default_stacksize < 0) + return; + + PROC_LOCK(p); + lim_rlimit_proc(p, RLIMIT_STACK, &rlim); + PROC_UNLOCK(p); + if (rlim.rlim_cur != rlim.rlim_max || + rlim.rlim_cur <= linux_default_stacksize) + return; + rlim.rlim_cur = linux_default_stacksize; + error = kern_proc_setrlimit(td, p, RLIMIT_STACK, &rlim); + KASSERT(error == 0, ("kern_proc_setrlimit failed")); +} + void linux_proc_init(struct thread *td, struct thread *newtd, int flags) { @@ -145,6 +168,7 @@ linux_proc_init(struct thread *td, struct thread *newt newtd->td_emuldata = em; linux_set_default_openfiles(td, p); + linux_set_default_stacksize(td, p); } else { p = td->td_proc; Modified: head/sys/compat/linux/linux_mib.c ============================================================================== --- head/sys/compat/linux/linux_mib.c Fri Oct 16 11:22:29 2020 (r366755) +++ head/sys/compat/linux/linux_mib.c Fri Oct 16 11:23:30 2020 (r366756) @@ -72,6 +72,11 @@ SYSCTL_INT(_compat_linux, OID_AUTO, default_openfiles, &linux_default_openfiles, 0, "Default soft openfiles resource limit, or -1 for unlimited"); +int linux_default_stacksize = 8 * 1024 * 1024; +SYSCTL_INT(_compat_linux, OID_AUTO, default_stacksize, CTLFLAG_RWTUN, + &linux_default_stacksize, 0, + "Default soft stack size resource limit, or -1 for unlimited"); + int linux_ignore_ip_recverr = 1; SYSCTL_INT(_compat_linux, OID_AUTO, ignore_ip_recverr, CTLFLAG_RWTUN, &linux_ignore_ip_recverr, 0, "Ignore enabling IP_RECVERR"); Modified: head/sys/compat/linux/linux_mib.h ============================================================================== --- head/sys/compat/linux/linux_mib.h Fri Oct 16 11:22:29 2020 (r366755) +++ head/sys/compat/linux/linux_mib.h Fri Oct 16 11:23:30 2020 (r366756) @@ -64,6 +64,7 @@ int linux_kernver(struct thread *td); extern int linux_debug; extern int linux_default_openfiles; +extern int linux_default_stacksize; extern int linux_ignore_ip_recverr; extern int linux_preserve_vstatus; extern bool linux_map_sched_prio;