From: Herbert Xu <herbert@gondor.apana.org.au>
To: Lianjie Wang <karin0.zst@gmail.com>
Cc: Olivia Mackall <olivia@selenic.com>,
David Laight <david.laight.linux@gmail.com>,
Jonathan McDowell <noodles@meta.com>,
linux-crypto@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] hwrng: core - fix racing condition when stopping hwrng_fill
Date: Fri, 23 Jan 2026 11:32:21 +0800 [thread overview]
Message-ID: <aXLrxVR0tmPuzIyM@gondor.apana.org.au> (raw)
In-Reply-To: <aXLiYQuXehWtvRrx@gondor.apana.org.au>
On Fri, Jan 23, 2026 at 10:52:17AM +0800, Herbert Xu wrote:
> On Sun, Dec 21, 2025 at 09:24:48PM +0900, Lianjie Wang wrote:
> >
> > Besides, if the hwrng_unregister() call happens immediately after a
> > hwrng_register() before, the stopped thread may have never been running,
>
> How can this happen? Surely that would mean that the kthread_* API is
> broken?
OK, kthread_stop can stop the thread without ever calling threadfn.
However, rather than having unregisters/registers firing off in
parallel, let's just make sure that register cannot start until
the unregister is actually done.
The thing that's stopping us from waiting on kthread while holding
the mutex is the get_current_rng() call in the kthread.
We could get around this by converting the lock for get_current_rng
to RCU instead. That should allow hwrng_unregister to safely wait
on the kthread without dead-lock.
Cheers,
--
Email: Herbert Xu <herbert@gondor.apana.org.au>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt
prev parent reply other threads:[~2026-01-23 3:32 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-12-21 12:24 Lianjie Wang
2026-01-23 2:52 ` Herbert Xu
2026-01-23 3:32 ` Herbert Xu [this message]
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=aXLrxVR0tmPuzIyM@gondor.apana.org.au \
--to=herbert@gondor.apana.org.au \
--cc=david.laight.linux@gmail.com \
--cc=karin0.zst@gmail.com \
--cc=linux-crypto@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=noodles@meta.com \
--cc=olivia@selenic.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®