Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 03 Sep 2014 10:05:24 -0500
From:      Bryan Drewery <bdrewery@FreeBSD.org>
To:        Konstantin Belousov <kib@FreeBSD.org>, src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   Re: svn commit: r271000 - head/sys/kern
Message-ID:  <54072E34.3080403@FreeBSD.org>
In-Reply-To: <201409030818.s838I8uY084843@svn.freebsd.org>
References:  <201409030818.s838I8uY084843@svn.freebsd.org>

next in thread | previous in thread | raw e-mail | index | archive | help
This is an OpenPGP/MIME signed message (RFC 4880 and 3156)
--mv7p62cdxbHga8v6jLn38kEFvItCLoG9o
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: quoted-printable

On 9/3/2014 3:18 AM, Konstantin Belousov wrote:
> Author: kib
> Date: Wed Sep  3 08:18:07 2014
> New Revision: 271000
> URL: http://svnweb.freebsd.org/changeset/base/271000
>=20
> Log:
>   Right now, thread_single(SINGLE_EXIT) returns after the p_numthreads
>   reaches 1. The p_numthreads counter is decremented in thread_exit() b=
y
>   a call to thread_unlink(). This means that the exiting threads may
>   still execute on other CPUs when thread_single(SINGLE_EXIT) returns.
>   As result, vmspace could be destroyed while paging structures are
>   still used on other CPUs by exiting threads.
>  =20
>   Delay the return from thread_single(SINGLE_EXIT) until all threads ar=
e
>   really destroyed by thread_stash() after the last switch out. The
>   p_exitthreads counter already provides the required mechanism, move
>   the wait from the thread_wait() (which is called from wait(2) code)
>   into thread_single().
>  =20
>   Reported by:	many (as "panic: pmap active <addr>")
>   Reviewed by:	alc, jhb
>   Tested by:	pho
>   Sponsored by:	The FreeBSD Foundation
>   MFC after:	1 week
>=20
> Modified:
>   head/sys/kern/kern_thread.c
>=20
> Modified: head/sys/kern/kern_thread.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_thread.c	Wed Sep  3 08:14:07 2014	(r270999)
> +++ head/sys/kern/kern_thread.c	Wed Sep  3 08:18:07 2014	(r271000)
> @@ -432,6 +432,7 @@ thread_exit(void)
>  	 */
>  	if (p->p_flag & P_HADTHREADS) {
>  		if (p->p_numthreads > 1) {
> +			atomic_add_int(&td->td_proc->p_exitthreads, 1);
>  			thread_unlink(td);
>  			td2 =3D FIRST_THREAD_IN_PROC(p);
>  			sched_exit_thread(td2, td);
> @@ -452,7 +453,6 @@ thread_exit(void)
>  				}
>  			}
> =20
> -			atomic_add_int(&td->td_proc->p_exitthreads, 1);
>  			PCPU_SET(deadthread, td);
>  		} else {
>  			/*
> @@ -507,14 +507,12 @@ thread_wait(struct proc *p)
>  	struct thread *td;
> =20
>  	mtx_assert(&Giant, MA_NOTOWNED);
> -	KASSERT((p->p_numthreads =3D=3D 1), ("Multiple threads in wait1()"));=

> +	KASSERT((p->p_numthreads =3D=3D 1), ("multiple threads in thread_wait=
()"));
> +	KASSERT((p->p_exitthreads =3D=3D 0), ("p_exitthreads leaking"));
>  	td =3D FIRST_THREAD_IN_PROC(p);
>  	/* Lock the last thread so we spin until it exits cpu_throw(). */
>  	thread_lock(td);
>  	thread_unlock(td);
> -	/* Wait for any remaining threads to exit cpu_throw(). */
> -	while (p->p_exitthreads)
> -		sched_relinquish(curthread);
>  	lock_profile_thread_exit(td);
>  	cpuset_rel(td->td_cpuset);
>  	td->td_cpuset =3D NULL;
> @@ -722,6 +720,17 @@ stopme:
>  		p->p_singlethread =3D NULL;
>  		p->p_flag &=3D ~(P_STOPPED_SINGLE | P_SINGLE_EXIT);
>  		thread_unthread(td);
> +
> +		/*
> +		 * Wait for any remaining threads to exit cpu_throw().
> +		 */
> +		while (p->p_exitthreads !=3D 0) {
> +			PROC_SUNLOCK(p);
> +			PROC_UNLOCK(p);
> +			sched_relinquish(td);
> +			PROC_LOCK(p);
> +			PROC_SLOCK(p);
> +		}
>  	}
>  	PROC_SUNLOCK(p);
>  	return (0);
>=20

Thanks!

--=20
Regards,
Bryan Drewery


--mv7p62cdxbHga8v6jLn38kEFvItCLoG9o
Content-Type: application/pgp-signature; name="signature.asc"
Content-Description: OpenPGP digital signature
Content-Disposition: attachment; filename="signature.asc"

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (MingW32)

iQEcBAEBAgAGBQJUBy40AAoJEDXXcbtuRpfPgNIIAMcrjKmUsAr+qHsxaYGODJT+
wKHwdGwcNM3XuVXe8g8zG3/gyzYIvrWNuQyUKc0ZOewIhEgxUvHJz3WPB/IMV7zH
cxH7R+W2sM/L+QUIbSEcpqe6YdogX8mzgzzmOxwKmN22HkE4RcaG5Dc7V3xmXs6v
fnw1Ilbez0YCDXL1CpLSyc06cu11zTW5F/Fce798HdCyI0YQn1rxFbamfR5wdLLD
gOeHFUgltZ7eMb6t7HEI101jrsh1qrsYpokPStA5pIdKhYK/rXKT+5LfTdrFl+Fz
Ao5TX8NcmvgPwqrwBsLvV5ZMRPNOcgwkC3WurfhG3/uzm8F1Q655liXlU/Y6js0=
=Eg8Q
-----END PGP SIGNATURE-----

--mv7p62cdxbHga8v6jLn38kEFvItCLoG9o--



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?54072E34.3080403>