mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Thomas Richard <thomas.richard@bootlin.com>
To: Herbert Xu <herbert@gondor.apana.org.au>
Cc: Olivia Mackall <olivia@selenic.com>,
	Thomas Petazzoni <thomas.petazzoni@bootlin.com>,
	linux-crypto@vger.kernel.org, linux-kernel@vger.kernel.org,
	gregory.clement@bootlin.com, richard.genoud@bootlin.com,
	u-kumar1@ti.com, a-kumar2@ti.com
Subject: Re: [PATCH v4] hwrng: core - Stop/start hwrng_fillfn() kthread before/after suspend-resume
Date: Mon, 27 Jul 2026 11:30:41 +0200	[thread overview]
Message-ID: <d0d77fe9-d806-4ecf-9e40-7ddab8dcac45@bootlin.com> (raw)
In-Reply-To: <amaef-KUBBjOcyMH@gondor.apana.org.au>

On 7/27/26 1:55 AM, Herbert Xu wrote:
> On Mon, Jul 13, 2026 at 01:25:37PM +0200, Thomas Richard (TI) wrote:
>>
>> This is the fourth iteration, as requested by Herbert I replaced BUG_ON()
>> by lockdep_assert_held().
>> ---
>> Changes in v4:
>> - use lockdep_assert_held() instead of BUG_ON()
>> - Link to v3: https://lore.kernel.org/r/20260703-hw-random-fix-hwrng-fillfn-crash-suspend-resume-v3-1-b7165cb9cf38@bootlin.com
> 
> https://sashiko.dev/#/patchset/20260713-hw-random-fix-hwrng-fillfn-crash-suspend-resume-v4-1-b5fb4c520b05%40bootlin.com
> 
> Sashiko is asking about whether user-space can restart the hwrng
> thread via sysfs after you stop it in the notifier.  I know nothing
> about suspension so I can't say whether that's possible.  But if
> it is possible then you'd need to close the race window with a flag
> of some kind.

Oh yes, indeed Sashiko is right. PM notifiers are run before user space
processes freezing.

What do you think if I lock the rng_mutex at the very beginning of
suspend and release it at the end of resume?

static int hwrng_pm_notifier(struct notifier_block *nb,
			     unsigned long action,
			     void *data)
{
	switch (action) {
	case PM_SUSPEND_PREPARE:
	case PM_HIBERNATION_PREPARE:
	case PM_RESTORE_PREPARE:
		mutex_lock(&rng_mutex);
		hwrng_stop_hwrng_fillfn();
		break;

	case PM_POST_SUSPEND:
	case PM_POST_HIBERNATION:
	case PM_POST_RESTORE:
		if (rcu_access_pointer(current_rng))
			hwrng_start_hwrng_fillfn();
		mutex_unlock(&rng_mutex);
		break;
	}

	return NOTIFY_DONE;
}

IIUC once rng_mutex is locked nobody can start the hwrng_thread.

And even if suspend sequence fails somewhere, POST PM notifier will be
run, so mutex will be released in any cases.

Best Regards,
Thomas

  reply	other threads:[~2026-07-27  9:30 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-13 11:25 Thomas Richard (TI)
2026-07-26 23:55 ` Herbert Xu
2026-07-27  9:30   ` Thomas Richard [this message]
2026-07-28  7:35     ` Herbert Xu

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=d0d77fe9-d806-4ecf-9e40-7ddab8dcac45@bootlin.com \
    --to=thomas.richard@bootlin.com \
    --cc=a-kumar2@ti.com \
    --cc=gregory.clement@bootlin.com \
    --cc=herbert@gondor.apana.org.au \
    --cc=linux-crypto@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=olivia@selenic.com \
    --cc=richard.genoud@bootlin.com \
    --cc=thomas.petazzoni@bootlin.com \
    --cc=u-kumar1@ti.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®