From owner-svn-src-all@FreeBSD.ORG Mon Nov 22 09:31:39 2010 Return-Path: Delivered-To: svn-src-all@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id BA4EA106567A; Mon, 22 Nov 2010 09:31:39 +0000 (UTC) (envelope-from kostikbel@gmail.com) Received: from mail.zoral.com.ua (mx0.zoral.com.ua [91.193.166.200]) by mx1.freebsd.org (Postfix) with ESMTP id 1C9888FC0A; Mon, 22 Nov 2010 09:31:38 +0000 (UTC) Received: from deviant.kiev.zoral.com.ua (root@deviant.kiev.zoral.com.ua [10.1.1.148]) by mail.zoral.com.ua (8.14.2/8.14.2) with ESMTP id oAM9VZZ4065995 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Mon, 22 Nov 2010 11:31:35 +0200 (EET) (envelope-from kostikbel@gmail.com) Received: from deviant.kiev.zoral.com.ua (kostik@localhost [127.0.0.1]) by deviant.kiev.zoral.com.ua (8.14.4/8.14.4) with ESMTP id oAM9VYAX090054; Mon, 22 Nov 2010 11:31:34 +0200 (EET) (envelope-from kostikbel@gmail.com) Received: (from kostik@localhost) by deviant.kiev.zoral.com.ua (8.14.4/8.14.4/Submit) id oAM9VYrk090053; Mon, 22 Nov 2010 11:31:34 +0200 (EET) (envelope-from kostikbel@gmail.com) X-Authentication-Warning: deviant.kiev.zoral.com.ua: kostik set sender to kostikbel@gmail.com using -f Date: Mon, 22 Nov 2010 11:31:34 +0200 From: Kostik Belousov To: Alexander Leidinger Message-ID: <20101122093134.GU2392@deviant.kiev.zoral.com.ua> References: <201011220907.oAM970To084256@svn.freebsd.org> Mime-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="3FdFc4BA+2Jhnmd7" Content-Disposition: inline In-Reply-To: <201011220907.oAM970To084256@svn.freebsd.org> User-Agent: Mutt/1.4.2.3i X-Virus-Scanned: clamav-milter 0.95.2 at skuns.kiev.zoral.com.ua X-Virus-Status: Clean X-Spam-Status: No, score=-2.2 required=5.0 tests=ALL_TRUSTED,AWL,BAYES_40, DNS_FROM_OPENWHOIS autolearn=no version=3.2.5 X-Spam-Checker-Version: SpamAssassin 3.2.5 (2008-06-10) on skuns.kiev.zoral.com.ua Cc: svn-src-head@freebsd.org, svn-src-all@freebsd.org, src-committers@freebsd.org Subject: Re: svn commit: r215664 - in head/sys: compat/linux kern X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 22 Nov 2010 09:31:39 -0000 --3FdFc4BA+2Jhnmd7 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Mon, Nov 22, 2010 at 09:07:00AM +0000, Alexander Leidinger wrote: > Author: netchild > Date: Mon Nov 22 09:06:59 2010 > New Revision: 215664 > URL: http://svn.freebsd.org/changeset/base/215664 >=20 > Log: > By using the 32-bit Linux version of Sun's Java Development Kit 1.6 > on FreeBSD (amd64), invocations of "javac" (or "java") eventually > end with the output of "Killed" and exit code 137. > =20 > This is caused by: > 1. After calling exec() in multithreaded linux program threads are not > destroyed and continue running. They get killed after program being > executed finishes. > =20 > 2. linux_exit_group doesn't return correct exit code when called not > from group leader. Which happens regularly using sun jvm. > =20 > The submitters fix this in a similar way to how NetBSD handles this. > =20 > I took the PRs away from dchagin, who seems to be out of touch of > this since a while (no response from him). > =20 > The patches committed here are from [2], with some little modifications > from me to the style. > =20 > PR: 141439 [1], 144194 [2] > Submitted by: Stefan Schmidt , gk > Reviewed by: rdivacky (in april 2010) > MFC after: 5 days >=20 > Modified: > head/sys/compat/linux/linux_emul.c > head/sys/compat/linux/linux_emul.h > head/sys/compat/linux/linux_misc.c > head/sys/kern/kern_exit.c >=20 > Modified: head/sys/compat/linux/linux_emul.c > =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D > --- head/sys/compat/linux/linux_emul.c Mon Nov 22 09:04:29 2010 (r215663) > +++ head/sys/compat/linux/linux_emul.c Mon Nov 22 09:06:59 2010 (r215664) > @@ -155,7 +155,7 @@ void > linux_proc_exit(void *arg __unused, struct proc *p) > { > struct linux_emuldata *em; > - int error; > + int error, shared_flags, shared_xstat; > struct thread *td =3D FIRST_THREAD_IN_PROC(p); > int *child_clear_tid; > struct proc *q, *nq; > @@ -187,6 +187,8 @@ linux_proc_exit(void *arg __unused, stru > } > =20 > EMUL_SHARED_WLOCK(&emul_shared_lock); > + shared_flags =3D em->shared->flags; > + shared_xstat =3D em->shared->xstat; > LIST_REMOVE(em, threads); > =20 > em->shared->refs--; > @@ -196,6 +198,12 @@ linux_proc_exit(void *arg __unused, stru > } else=09 > EMUL_SHARED_WUNLOCK(&emul_shared_lock); > =20 > + if ((shared_flags & EMUL_SHARED_HASXSTAT) !=3D 0) { > + PROC_LOCK(p); > + p->p_xstat =3D shared_xstat; > + PROC_UNLOCK(p); > + } Why is process lock taken there ? The assignment to u_short inside the properly aligned structure is atomic on all supported architectures, and the thread that should see side-effect of assignment is the same thread that does assignment. > + > if (child_clear_tid !=3D NULL) { > struct linux_sys_futex_args cup; > int null =3D 0; > @@ -257,6 +265,9 @@ linux_proc_exec(void *arg __unused, stru > if (__predict_false(imgp->sysent =3D=3D &elf_linux_sysvec > && p->p_sysent !=3D &elf_linux_sysvec)) > linux_proc_init(FIRST_THREAD_IN_PROC(p), p->p_pid, 0); > + if (__predict_false(p->p_sysent =3D=3D &elf_linux_sysvec)) > + /* Kill threads regardless of imgp->sysent value */ > + linux_kill_threads(FIRST_THREAD_IN_PROC(p), SIGKILL); This is better expressed by if ((p->p_sysent->sv_flags & SV_ABI_MASK) =3D=3D SV_ABI_LINUX) Regardless of this mostly cosmetic issue, this is racy. Other linux thread in the same process might do an execve(3). More, if execve(3) call fails, then you return into the process that lacks all threads except the one that called execve(3). > if (__predict_false(imgp->sysent !=3D &elf_linux_sysvec > && p->p_sysent =3D=3D &elf_linux_sysvec)) { > struct linux_emuldata *em; > @@ -334,3 +345,29 @@ linux_set_tid_address(struct thread *td, > EMUL_UNLOCK(&emul_lock); > return 0; > } > + > +void > +linux_kill_threads(struct thread *td, int sig) > +{ > + struct linux_emuldata *em, *td_em, *tmp_em; > + struct proc *sp; > + > + td_em =3D em_find(td->td_proc, EMUL_DONTLOCK); > + > + KASSERT(td_em !=3D NULL, ("linux_kill_threads: emuldata not found.\n")); > + > + EMUL_SHARED_RLOCK(&emul_shared_lock); > + LIST_FOREACH_SAFE(em, &td_em->shared->threads, threads, tmp_em) { > + if (em->pid =3D=3D td_em->pid) > + continue; > + > + sp =3D pfind(em->pid); > + if ((sp->p_flag & P_WEXIT) =3D=3D 0) > + psignal(sp, sig); > + PROC_UNLOCK(sp); > +#ifdef DEBUG > + printf(LMSG("linux_kill_threads: kill PID %d\n"), em->pid); > +#endif > + } > + EMUL_SHARED_RUNLOCK(&emul_shared_lock); > +} >=20 > Modified: head/sys/compat/linux/linux_emul.h > =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D > --- head/sys/compat/linux/linux_emul.h Mon Nov 22 09:04:29 2010 (r215663) > +++ head/sys/compat/linux/linux_emul.h Mon Nov 22 09:06:59 2010 (r215664) > @@ -31,8 +31,12 @@ > #ifndef _LINUX_EMUL_H_ > #define _LINUX_EMUL_H_ > =20 > +#define EMUL_SHARED_HASXSTAT 0x01 > + > struct linux_emuldata_shared { > int refs; > + int flags; > + int xstat; > pid_t group_pid; > =20 > LIST_HEAD(, linux_emuldata) threads; /* head of list of linux threads */ > @@ -76,6 +80,7 @@ int linux_proc_init(struct thread *, pid > void linux_proc_exit(void *, struct proc *); > void linux_schedtail(void *, struct proc *); > void linux_proc_exec(void *, struct proc *, struct image_params *); > +void linux_kill_threads(struct thread *, int); > =20 > extern struct sx emul_shared_lock; > extern struct mtx emul_lock; >=20 > Modified: head/sys/compat/linux/linux_misc.c > =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D > --- head/sys/compat/linux/linux_misc.c Mon Nov 22 09:04:29 2010 (r215663) > +++ head/sys/compat/linux/linux_misc.c Mon Nov 22 09:06:59 2010 (r215664) > @@ -1695,34 +1695,23 @@ linux_setdomainname(struct thread *td, s > int > linux_exit_group(struct thread *td, struct linux_exit_group_args *args) > { > - struct linux_emuldata *em, *td_em, *tmp_em; > - struct proc *sp; > + struct linux_emuldata *em; > =20 > #ifdef DEBUG > if (ldebug(exit_group)) > printf(ARGS(exit_group, "%i"), args->error_code); > #endif > =20 > - if (linux_use26(td)) { > - td_em =3D em_find(td->td_proc, EMUL_DONTLOCK); > - > - KASSERT(td_em !=3D NULL, ("exit_group: emuldata not found.\n")); > - > - EMUL_SHARED_RLOCK(&emul_shared_lock); > - LIST_FOREACH_SAFE(em, &td_em->shared->threads, threads, tmp_em) { > - if (em->pid =3D=3D td_em->pid) > - continue; > - > - sp =3D pfind(em->pid); > - psignal(sp, SIGKILL); > - PROC_UNLOCK(sp); > -#ifdef DEBUG > - printf(LMSG("linux_sys_exit_group: kill PID %d\n"), em->pid); > -#endif > - } > - > - EMUL_SHARED_RUNLOCK(&emul_shared_lock); > + em =3D em_find(td->td_proc, EMUL_DONTLOCK); > + if (em->shared->refs > 1) { > + EMUL_SHARED_WLOCK(&emul_shared_lock); > + em->shared->flags |=3D EMUL_SHARED_HASXSTAT; > + em->shared->xstat =3D W_EXITCODE(args->error_code, 0); > + EMUL_SHARED_WUNLOCK(&emul_shared_lock); > + if (linux_use26(td)) > + linux_kill_threads(td, SIGKILL); > } > + > /* > * XXX: we should send a signal to the parent if > * SIGNAL_EXIT_GROUP is set. We ignore that (temporarily?) >=20 > Modified: head/sys/kern/kern_exit.c > =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D > --- head/sys/kern/kern_exit.c Mon Nov 22 09:04:29 2010 (r215663) > +++ head/sys/kern/kern_exit.c Mon Nov 22 09:06:59 2010 (r215664) > @@ -200,6 +200,7 @@ exit1(struct thread *td, int rv) > while (p->p_lock > 0) > msleep(&p->p_lock, &p->p_mtx, PWAIT, "exithold", 0); > =20 > + p->p_xstat =3D rv; /* Let event handler change exit status */ > PROC_UNLOCK(p); > /* Drain the limit callout while we don't have the proc locked */ > callout_drain(&p->p_limco); > @@ -242,6 +243,7 @@ exit1(struct thread *td, int rv) > * P_PPWAIT is set; we will wakeup the parent below. > */ > PROC_LOCK(p); > + rv =3D p->p_xstat; /* Event handler could change exit status */ > stopprofclock(p); > p->p_flag &=3D ~(P_TRACED | P_PPWAIT); > =20 > @@ -424,7 +426,6 @@ exit1(struct thread *td, int rv) > =20 > /* Save exit status. */ > PROC_LOCK(p); > - p->p_xstat =3D rv; > p->p_xthread =3D td; > =20 > /* Tell the prison that we are gone. */ --3FdFc4BA+2Jhnmd7 Content-Type: application/pgp-signature Content-Disposition: inline -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.11 (FreeBSD) iEYEARECAAYFAkzqOHYACgkQC3+MBN1Mb4iE9wCfTDLu/MY6N4KTyfM3ipLdSo7i EFcAn3mRk4aupfZEFyzFLPc475oAgZgr =7jWP -----END PGP SIGNATURE----- --3FdFc4BA+2Jhnmd7--