[igt-dev] [PATCH i-g-t v2] lib/igt_core: Reinitialize print mutex in child process

Petri Latvala petri.latvala at intel.com
Wed Sep 30 10:39:37 UTC 2020


On Tue, Sep 29, 2020 at 03:38:33PM +0200, Zbigniew Kempczyński wrote:
> IGT are prone to deadlock in igt_log() in following scenario:
> 
> 1. Parent process creates additional thread which for example
>    is doing endless loop.
> 2. Thread sometimes is logging to console using igt_info().
>    This locks and unlocks print_mutex.
> 3. If in the meantime parent process will spawn child process
>    it can be created having print_mutex locked (thread entered
>    igt_vlog() function and entered critical section). When child
>    will try to log it will deadlock.
> 
> We should reinitialize print_mutex in child process to avoid
> use inherited value.
> 
> Signed-off-by: Zbigniew Kempczyński <zbigniew.kempczynski at intel.com>
> Cc: Petri Latvala <petri.latvala at intel.com>

Reviewed-by: Petri Latvala <petri.latvala at intel.com>


> ---
>  lib/igt_core.c | 5 +++--
>  1 file changed, 3 insertions(+), 2 deletions(-)
> 
> diff --git a/lib/igt_core.c b/lib/igt_core.c
> index cedd8168..b358173f 100644
> --- a/lib/igt_core.c
> +++ b/lib/igt_core.c
> @@ -2271,6 +2271,8 @@ static void children_exit_handler(int sig)
>  		;
>  }
>  
> +static pthread_mutex_t print_mutex = PTHREAD_MUTEX_INITIALIZER;
> +
>  bool __igt_fork(void)
>  {
>  	internal_assert(!test_with_subtests || in_subtest,
> @@ -2300,6 +2302,7 @@ bool __igt_fork(void)
>  		igt_assert(0);
>  	case 0:
>  		test_child = true;
> +		pthread_mutex_init(&print_mutex, NULL);
>  		exit_handler_count = 0;
>  		reset_helper_process_list();
>  		oom_adjust_for_doom();
> @@ -2737,8 +2740,6 @@ void igt_vlog(const char *domain, enum igt_log_level level, const char *format,
>  		"NONE"
>  	};
>  
> -	static pthread_mutex_t print_mutex = PTHREAD_MUTEX_INITIALIZER;
> -
>  	assert(format);
>  
>  #ifdef __GLIBC__
> -- 
> 2.26.0
> 


More information about the igt-dev mailing list