mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Dominik Brodowski <linux@dominikbrodowski.net>
To: "Jason A. Donenfeld" <Jason@zx2c4.com>
Cc: linux-kernel@vger.kernel.org
Subject: Re: [PATCH 2/4] random: cleanup fractional entropy shift constants
Date: Mon, 17 Jan 2022 18:31:16 +0100	[thread overview]
Message-ID: <YeWn5PH1dVay2sg+@owl.dominikbrodowski.net> (raw)
In-Reply-To: <20220116163547.154991-2-Jason@zx2c4.com>

Am Sun, Jan 16, 2022 at 05:35:45PM +0100 schrieb Jason A. Donenfeld:
> The entropy estimator is calculated in terms of 1/8 bits, which means
> there are various constants where things are shifted by 3. Move these
> into our pool info enum with the other relevant constants. While we're
> at it, move an English assertion about sizes into a proper BUILD_BUG_ON
> so that the compiler can ensure this invariant.
> 
> Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
> ---
>  drivers/char/random.c | 28 +++++++++++++---------------
>  1 file changed, 13 insertions(+), 15 deletions(-)
> 
> diff --git a/drivers/char/random.c b/drivers/char/random.c
> index de1c14787ae8..7343bff086c5 100644
> --- a/drivers/char/random.c
> +++ b/drivers/char/random.c
> @@ -358,16 +358,6 @@
>  
>  /* #define ADD_INTERRUPT_BENCH */
>  
> -/*
> - * To allow fractional bits to be tracked, the entropy_count field is
> - * denominated in units of 1/8th bits.
> - *
> - * 2*(POOL_ENTROPY_SHIFT + poolbitshift) must <= 31, or the multiply in
> - * credit_entropy_bits() needs to be 64 bits wide.
> - */
> -#define POOL_ENTROPY_SHIFT 3
> -#define POOL_ENTROPY_BITS() (input_pool.entropy_count >> POOL_ENTROPY_SHIFT)
> -
>  /*
>   * If the entropy count falls under this number of bits, then we
>   * should wake up processes which are selecting or polling on write
> @@ -425,8 +415,13 @@ enum poolinfo {
>  	POOL_WORDMASK = POOL_WORDS - 1,
>  	POOL_BYTES = POOL_WORDS * sizeof(u32),
>  	POOL_BITS = POOL_BYTES * 8,
> -	POOL_BITSHIFT = ilog2(POOL_WORDS) + 5,
> -	POOL_FRACBITS = POOL_WORDS << (POOL_ENTROPY_SHIFT + 5),
> +	POOL_BITSHIFT = ilog2(POOL_BITS),
> +
> +	/* To allow fractional bits to be tracked, the entropy_count field is
> +	 * denominated in units of 1/8th bits. */
> +	POOL_ENTROPY_SHIFT = 3,
> +#define POOL_ENTROPY_BITS() (input_pool.entropy_count >> POOL_ENTROPY_SHIFT)
> +	POOL_FRACBITS = POOL_BITS << POOL_ENTROPY_SHIFT,


the #define here confuses me a bit, as it is optically breaking the POOL
enum. But that relates to coding style preferences only, so

	Reviewed-by: Dominik Brodowski <linux@dominikbrodowski.net>

  reply	other threads:[~2022-01-17 17:35 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-01-13 15:44 [PATCH 0/7] first in overall series of rng code house cleaning Jason A. Donenfeld
2022-01-13 15:44 ` [PATCH 1/7] random: cleanup poolinfo abstraction Jason A. Donenfeld
2022-01-16 13:24   ` Dominik Brodowski
2022-01-13 15:44 ` [PATCH 2/7] random: cleanup integer types Jason A. Donenfeld
2022-01-16 13:24   ` Dominik Brodowski
2022-01-13 15:44 ` [PATCH 3/7] random: remove incomplete last_data logic Jason A. Donenfeld
2022-01-16 13:24   ` Dominik Brodowski
2022-01-13 15:44 ` [PATCH 4/7] random: remove unused reserved argument Jason A. Donenfeld
2022-01-16 13:24   ` Dominik Brodowski
2022-01-16 16:22     ` Jason A. Donenfeld
2022-01-17 17:28       ` Dominik Brodowski
2022-01-17 17:52         ` [PATCH] random: simplify arithmetic function flow in account() Jason A. Donenfeld
2022-01-17 17:55           ` Jason A. Donenfeld
2022-01-13 15:44 ` [PATCH 5/7] random: rather than entropy_store abstraction, use global Jason A. Donenfeld
2022-01-16 13:24   ` Dominik Brodowski
2022-01-13 15:44 ` [PATCH 6/7] random: remove unused OUTPUT_POOL constants Jason A. Donenfeld
2022-01-16 13:25   ` Dominik Brodowski
2022-01-13 15:44 ` [PATCH 7/7] random: de-duplicate INPUT_POOL constants Jason A. Donenfeld
2022-01-16 13:25   ` Dominik Brodowski
2022-01-14 15:33 ` [PATCH] random: cleanup fractional entropy shift constants Jason A. Donenfeld
2022-01-14 15:39   ` David Laight
2022-01-14 15:46     ` Jason A. Donenfeld
2022-01-16 16:35 ` [PATCH 1/4] random: prepend remaining pool constants with POOL_ Jason A. Donenfeld
2022-01-16 16:35   ` [PATCH 2/4] random: cleanup fractional entropy shift constants Jason A. Donenfeld
2022-01-17 17:31     ` Dominik Brodowski [this message]
2022-01-16 16:35   ` [PATCH 3/4] random: access input_pool_data directly rather than through pointer Jason A. Donenfeld
2022-01-17 17:32     ` Dominik Brodowski
2022-01-16 16:35   ` [PATCH 4/4] random: selectively clang-format where it makes sense Jason A. Donenfeld
2022-01-17 17:34     ` Dominik Brodowski
2022-01-17 17:29   ` [PATCH 1/4] random: prepend remaining pool constants with POOL_ Dominik Brodowski

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=YeWn5PH1dVay2sg+@owl.dominikbrodowski.net \
    --to=linux@dominikbrodowski.net \
    --cc=Jason@zx2c4.com \
    --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 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®