Re: [PATCH 1/2] [RFC] hwrng: fix khwrng lifecycle

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Thu, Oct 24, 2024 at 06:30:15PM +0200, Marek Vasut wrote:
>
> @@ -582,15 +585,12 @@ void hwrng_unregister(struct hwrng *rng)
>  	}
>  
>  	new_rng = get_current_rng_nolock();
> -	if (list_empty(&rng_list)) {
> -		mutex_unlock(&rng_mutex);
> -		if (hwrng_fill)
> -			kthread_stop(hwrng_fill);
> -	} else
> -		mutex_unlock(&rng_mutex);
> +	mutex_unlock(&rng_mutex);
>  
>  	if (new_rng)
>  		put_rng(new_rng);
> +	else
> +		kthread_park(hwrng_fill);

The kthread_park should be moved back into the locked region
of rng_mute).  The kthread_stop was moved out because it could
dead-lock waiting on the kthread that's also taking the same
lock.  This is no longer an issue with kthread_park since it
simply sets a flag.

Having it outside of the locked region is potentially dangerous
since a pair of hwrng_unregister and hwrng_register could be
re-ordered resulting in the kthread being parked forever.

Thanks,
-- 
Email: Herbert Xu <herbert@xxxxxxxxxxxxxxxxxxx>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt




[Index of Archives]     [Kernel]     [Gnu Classpath]     [Gnu Crypto]     [DM Crypt]     [Netfilter]     [Bugtraq]
  Powered by Linux