Re: [PATCH v2] hwrng: core - Do not read data during PM sleep transition
From: Thomas Richard
Date: Fri Jul 03 2026 - 04:29:15 EST
On 6/11/26 7:16 AM, Herbert Xu wrote:
> On Mon, Jun 01, 2026 at 03:19:13PM +0200, Thomas Richard (TI) wrote:
>>
>> @@ -538,8 +539,9 @@ static int hwrng_fillfn(void *unused)
>> }
>>
>> mutex_lock(&reading_mutex);
>> - rc = rng_get_data(rng, rng_fillbuf,
>> - rng_buffer_size(), 1);
>> + if (!pm_sleep_transition_in_progress())
>> + rc = rng_get_data(rng, rng_fillbuf,
>> + rng_buffer_size(), 1);
>
> Sashiko asks how this can be safe given that there is no locking
> at all. That's exactly what I was going to ask :)
Yes indeed, you are right. I dug again the topic (including the freeze
solution I implemented in a first time), and I may have found the right
solution. The only way is to stop the hwrng_fillfn() kthread before
suspend and restart it after resume. Fortunately there is a mechanism to
do this: pm_notifier. I'll send a patch soon.
Best Regards,
Thomas