svn commit: r367714 - head/sys/kern

Hans Petter Selasky hps at selasky.org
Tue Dec 1 10:10:19 UTC 2020


On 11/16/20 4:12 AM, Mateusz Guzik wrote:
> Author: mjg
> Date: Mon Nov 16 03:12:21 2020
> New Revision: 367714
> URL: https://svnweb.freebsd.org/changeset/base/367714
> 
> Log:
>    select: call seltdfini on process and thread exit
>    
>    Since thread_zone is marked NOFREE the thread_fini callback is never
>    executed, meaning memory allocated by seltdinit is never released.
>    
>    Adding the call to thread_dtor is not sufficient as exiting processes
>    cache the main thread.
> 
> Modified:
>    head/sys/kern/kern_exit.c
>    head/sys/kern/kern_thread.c
> 
> Modified: head/sys/kern/kern_exit.c
> ==============================================================================
> --- head/sys/kern/kern_exit.c	Mon Nov 16 03:09:18 2020	(r367713)
> +++ head/sys/kern/kern_exit.c	Mon Nov 16 03:12:21 2020	(r367714)
> @@ -355,6 +355,7 @@ exit1(struct thread *td, int rval, int signo)
>   	PROC_UNLOCK(p);
>   
>   	umtx_thread_exit(td);
> +	seltdfini(td);
>   
>   	/*
>   	 * Reset any sigio structures pointing to us as a result of
> 
> Modified: head/sys/kern/kern_thread.c
> ==============================================================================
> --- head/sys/kern/kern_thread.c	Mon Nov 16 03:09:18 2020	(r367713)
> +++ head/sys/kern/kern_thread.c	Mon Nov 16 03:12:21 2020	(r367714)
> @@ -329,6 +329,7 @@ thread_ctor(void *mem, int size, void *arg, int flags)
>   	audit_thread_alloc(td);
>   #endif
>   	umtx_thread_alloc(td);
> +	MPASS(td->td_sel == NULL);
>   	return (0);
>   }
>   
> @@ -369,6 +370,7 @@ thread_dtor(void *mem, int size, void *arg)
>   	osd_thread_exit(td);
>   	td_softdep_cleanup(td);
>   	MPASS(td->td_su == NULL);
> +	seltdfini(td);
>   }
>   
>   /*
> @@ -405,7 +407,7 @@ thread_fini(void *mem, int size)
>   	turnstile_free(td->td_turnstile);
>   	sleepq_free(td->td_sleepqueue);
>   	umtx_thread_fini(td);
> -	seltdfini(td);
> +	MPASS(td->td_sel == NULL);
>   }
>   
>   /*

Hi,

The following panic() has been observed after this change:

panic: Assertion mtx_unowned(m) failed at /usr/src/sys/kern/kern_mutex:1181
cpuid = 6
....
panic()
_mtx_destroy()
seltdfini()
exit1()
postsig()
ast()
doreti_ast()

--HPS



More information about the svn-src-head mailing list