From: Herbert Xu <herbert@gondor.apana.org.au>
To: "Maciej S. Szmigiero" <mail@maciej.szmigiero.name>
Cc: Theodore Ts'o <tytso@mit.edu>, Arnd Bergmann <arnd@arndb.de>,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
Sebastian Andrzej Siewior <bigeasy@linutronix.de>,
Keerthy <j-keerthy@ti.com>, Stephen Boyd <swboyd@chromium.org>,
linux-crypto@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] random: Don't freeze in add_hwgenerator_randomness() if stopping kthread
Date: Fri, 15 Nov 2019 14:08:33 +0800 [thread overview]
Message-ID: <20191115060833.xze5kkq64pxci2la@gondor.apana.org.au> (raw)
In-Reply-To: <20191110135543.3476097-1-mail@maciej.szmigiero.name>
On Sun, Nov 10, 2019 at 02:55:42PM +0100, Maciej S. Szmigiero wrote:
> Since commit 59b569480dc8
> ("random: Use wait_event_freezable() in add_hwgenerator_randomness()")
> there is a race in add_hwgenerator_randomness() between freezing and
> stopping the calling kthread.
>
> This commit changed wait_event_interruptible() call with
> kthread_freezable_should_stop() as a condition into wait_event_freezable()
> with just kthread_should_stop() as a condition to fix a warning that
> kthread_freezable_should_stop() might sleep inside the wait.
>
> wait_event_freezable() ultimately calls __refrigerator() with its
> check_kthr_stop argument set to false, which causes it to keep the kthread
> frozen even if somebody calls kthread_stop() on it.
>
> Calling wait_event_freezable() with kthread_should_stop() as a condition
> is racy because it doesn't take into account the situation where this
> condition becomes true on a kthread marked for freezing only after this
> condition has already been checked.
>
> Calling freezing() should avoid the issue that the commit 59b569480dc8 has
> fixed, as it is only a checking function, it doesn't actually do the
> freezing.
>
> add_hwgenerator_randomness() has two post-boot users: in khwrng the
> kthread will be frozen anyway by call to kthread_freezable_should_stop()
> in its main loop, while its second user (ath9k-hwrng) is not freezable at
> all.
>
> This change allows a VM with virtio-rng loaded to write s2disk image
> successfully.
>
> Fixes: 59b569480dc8 ("random: Use wait_event_freezable() in add_hwgenerator_randomness()")
> Signed-off-by: Maciej S. Szmigiero <mail@maciej.szmigiero.name>
> ---
> drivers/char/random.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
Patch applied. Thanks.
--
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
next prev parent reply other threads:[~2019-11-15 6:09 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-11-10 13:55 [PATCH] random: Don't freeze in add_hwgenerator_randomness() if stopping kthread Maciej S. Szmigiero
2019-11-15 6:08 ` Herbert Xu [this message]
[not found] ` <5dcee409.1c69fb81.f5027.48ad@mx.google.com>
2019-11-16 23:01 ` Maciej S. Szmigiero
2019-11-17 0:56 ` Herbert Xu
2019-11-17 4:09 ` Theodore Y. Ts'o
2020-12-02 14:28 ` Horia Geantă
2020-12-03 0:29 ` 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=20191115060833.xze5kkq64pxci2la@gondor.apana.org.au \
--to=herbert@gondor.apana.org.au \
--cc=arnd@arndb.de \
--cc=bigeasy@linutronix.de \
--cc=gregkh@linuxfoundation.org \
--cc=j-keerthy@ti.com \
--cc=linux-crypto@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mail@maciej.szmigiero.name \
--cc=swboyd@chromium.org \
--cc=tytso@mit.edu \
/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;
as well as URLs for NNTP newsgroup(s).