All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Jason A. Donenfeld" <Jason@zx2c4.com>
To: linux-crypto@vger.kernel.org, linux-kernel@vger.kernel.org
Cc: "Jason A. Donenfeld" <Jason@zx2c4.com>,
	Dominik Brodowski <linux@dominikbrodowski.net>
Subject: [PATCH] random: mix hwgenerator randomness before sleeping
Date: Tue,  3 May 2022 21:51:41 +0200	[thread overview]
Message-ID: <20220503195141.683217-1-Jason@zx2c4.com> (raw)

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.

Cc: Dominik Brodowski <linux@dominikbrodowski.net>
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
---
 drivers/char/random.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/drivers/char/random.c b/drivers/char/random.c
index 845f610b6611..d4eae4b167b4 100644
--- a/drivers/char/random.c
+++ b/drivers/char/random.c
@@ -1154,6 +1154,9 @@ void rand_initialize_disk(struct gendisk *disk)
 void add_hwgenerator_randomness(const void *buffer, size_t count,
 				size_t entropy)
 {
+	mix_pool_bytes(buffer, count);
+	credit_entropy_bits(entropy);
+
 	/*
 	 * Throttle writing if we're above the trickle threshold.
 	 * We'll be woken up again once below POOL_MIN_BITS, when
@@ -1164,8 +1167,6 @@ void add_hwgenerator_randomness(const void *buffer, size_t count,
 			!system_wq || kthread_should_stop() ||
 			input_pool.entropy_count < POOL_MIN_BITS,
 			CRNG_RESEED_INTERVAL);
-	mix_pool_bytes(buffer, count);
-	credit_entropy_bits(entropy);
 }
 EXPORT_SYMBOL_GPL(add_hwgenerator_randomness);
 
-- 
2.35.1


             reply	other threads:[~2022-05-03 19:51 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-05-03 19:51 Jason A. Donenfeld [this message]
2022-05-03 19:56 ` [PATCH] random: mix hwgenerator randomness before sleeping Dominik Brodowski
2022-05-04  0:45   ` Jason A. Donenfeld
2022-05-04  5:36     ` Dominik Brodowski
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=20220503195141.683217-1-Jason@zx2c4.com \
    --to=jason@zx2c4.com \
    --cc=linux-crypto@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux@dominikbrodowski.net \
    /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.