All of lore.kernel.org
 help / color / mirror / Atom feed
From: Dominik Brodowski <linux@dominikbrodowski.net>
To: "Jason A. Donenfeld" <Jason@zx2c4.com>
Cc: Linux Crypto Mailing List <linux-crypto@vger.kernel.org>,
	LKML <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH] random: mix hwgenerator randomness before sleeping
Date: Wed, 4 May 2022 07:36:53 +0200	[thread overview]
Message-ID: <YnIQ9RJpP/3j5aWF@owl.dominikbrodowski.net> (raw)
In-Reply-To: <CAHmME9o1zhtq=bMetwEx7YEzoW79z36BQ=vTWEv4M_ocChm5eA@mail.gmail.com>

Hi Jason,

Am Wed, May 04, 2022 at 02:45:46AM +0200 schrieb Jason A. Donenfeld:
> On Tue, May 3, 2022 at 9:56 PM Dominik Brodowski
> <linux@dominikbrodowski.net> wrote:
> >
> > Am Tue, May 03, 2022 at 09:51:41PM +0200 schrieb Jason A. Donenfeld:
> > > The add_hwgenerator_randomness() function is called in a loop from a
> > > kthread by the hwgenerator core. It's supposed to sleep when there's
> > > nothing to do, and wake up periodically for more entropy. Right now it
> > > receives entropy, sleeps, and then mixes it in. This commit reverses the
> > > order, so that it always mixes in entropy sooner and sleeps after. This
> > > way the entropy is more fresh.
> >
> > ... however, the hwgenerator may take quite some time to accumulate entropy
> > after wakeup. So now we might have a delay between a wakeup ("we need more
> > entropy!") and that entropy becoming available. Beforehand, the thread only
> > went to sleep when there is no current need for "fresh" entropy.
> 
> Huh, interesting consideration. I didn't think about that. You wrote,
> "hwgenerator may take quite some time to accumulate entropy" -- any
> idea how long in the worst case? A second? A minute?

For TPM or virtio-rng, this shouldn't take long. But, for example, the
Kconfig entry for HW_RANDOM_TIMERIOMEM states that

	  This driver provides kernel-side support for a generic Random
	  Number Generator used by reading a 'dumb' iomem address that
	  is to be read no faster than, for example, once a second;
	  the default FPGA bitstream on the TS-7800 has such functionality.

Then, optee-rng.c contains a value "data_rate" in random bytes per second,
and may sleep for a considerable time:

	msleep((1000 * (max - read)) / pvt_data->data_rate);

Thanks,
	Dominik

  reply	other threads:[~2022-05-04  6:34 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-05-03 19:51 [PATCH] random: mix hwgenerator randomness before sleeping Jason A. Donenfeld
2022-05-03 19:56 ` Dominik Brodowski
2022-05-04  0:45   ` Jason A. Donenfeld
2022-05-04  5:36     ` Dominik Brodowski [this message]
2022-05-04 11:13       ` Jason A. Donenfeld

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=YnIQ9RJpP/3j5aWF@owl.dominikbrodowski.net \
    --to=linux@dominikbrodowski.net \
    --cc=Jason@zx2c4.com \
    --cc=linux-crypto@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.