All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH stable 5.18 5.17 5.15 5.10 0/3] rng stable patches from 5.19-rc2
@ 2022-06-13  8:07 Jason A. Donenfeld
  2022-06-13  8:07 ` [PATCH stable 5.18 5.17 5.15 5.10 1/3] random: avoid checking crng_ready() twice in random_init() Jason A. Donenfeld
                   ` (3 more replies)
  0 siblings, 4 replies; 6+ messages in thread
From: Jason A. Donenfeld @ 2022-06-13  8:07 UTC (permalink / raw)
  To: stable, gregkh

Hi Greg,

These three patches from 5.19-rc2 failed to automatically apply. The
following series should work okay.

Note that these are already part of the 4.9, 4.14, 4.19, 5.4 backport I
did for later this week.

Jason

Jason A. Donenfeld (3):
  random: avoid checking crng_ready() twice in random_init()
  random: mark bootloader randomness code as __init
  random: account for arch randomness in bits

 drivers/char/random.c  | 15 +++++++--------
 include/linux/random.h |  2 +-
 2 files changed, 8 insertions(+), 9 deletions(-)

-- 
2.35.1


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH stable 5.18 5.17 5.15 5.10 1/3] random: avoid checking crng_ready() twice in random_init()
  2022-06-13  8:07 [PATCH stable 5.18 5.17 5.15 5.10 0/3] rng stable patches from 5.19-rc2 Jason A. Donenfeld
@ 2022-06-13  8:07 ` Jason A. Donenfeld
  2022-06-13  8:07 ` [PATCH stable 5.18 5.17 5.15 5.10 2/3] random: mark bootloader randomness code as __init Jason A. Donenfeld
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 6+ messages in thread
From: Jason A. Donenfeld @ 2022-06-13  8:07 UTC (permalink / raw)
  To: stable, gregkh

commit 9b29b6b20376ab64e1b043df6301d8a92378e631 upstream.

The current flow expands to:

    if (crng_ready())
       ...
    else if (...)
        if (!crng_ready())
            ...

The second crng_ready() call is redundant, but can't so easily be
optimized out by the compiler.

This commit simplifies that to:

    if (crng_ready()
        ...
    else if (...)
        ...

Fixes: 560181c27b58 ("random: move initialization functions out of hot pages")
Cc: stable@vger.kernel.org
Cc: Dominik Brodowski <linux@dominikbrodowski.net>
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
---
 drivers/char/random.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/char/random.c b/drivers/char/random.c
index 420d78eee6c5..9972259809db 100644
--- a/drivers/char/random.c
+++ b/drivers/char/random.c
@@ -834,7 +834,7 @@ int __init random_init(const char *command_line)
 	if (crng_ready())
 		crng_reseed();
 	else if (trust_cpu)
-		credit_init_bits(arch_bytes * 8);
+		_credit_init_bits(arch_bytes * 8);
 
 	return 0;
 }
-- 
2.35.1


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH stable 5.18 5.17 5.15 5.10 2/3] random: mark bootloader randomness code as __init
  2022-06-13  8:07 [PATCH stable 5.18 5.17 5.15 5.10 0/3] rng stable patches from 5.19-rc2 Jason A. Donenfeld
  2022-06-13  8:07 ` [PATCH stable 5.18 5.17 5.15 5.10 1/3] random: avoid checking crng_ready() twice in random_init() Jason A. Donenfeld
@ 2022-06-13  8:07 ` Jason A. Donenfeld
  2022-06-13  8:07 ` [PATCH stable 5.18 5.17 5.15 5.10 3/3] random: account for arch randomness in bits Jason A. Donenfeld
  2022-06-13  9:02 ` [PATCH stable 5.18 5.17 5.15 5.10 0/3] rng stable patches from 5.19-rc2 Greg KH
  3 siblings, 0 replies; 6+ messages in thread
From: Jason A. Donenfeld @ 2022-06-13  8:07 UTC (permalink / raw)
  To: stable, gregkh

commit 39e0f991a62ed5efabd20711a7b6e7da92603170 upstream.

add_bootloader_randomness() and the variables it touches are only used
during __init and not after, so mark these as __init. At the same time,
unexport this, since it's only called by other __init code that's
built-in.

Cc: stable@vger.kernel.org
Fixes: 428826f5358c ("fdt: add support for rng-seed")
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
---
 drivers/char/random.c  | 7 +++----
 include/linux/random.h | 2 +-
 2 files changed, 4 insertions(+), 5 deletions(-)

diff --git a/drivers/char/random.c b/drivers/char/random.c
index 9972259809db..d09e78e6f24b 100644
--- a/drivers/char/random.c
+++ b/drivers/char/random.c
@@ -785,8 +785,8 @@ static void __cold _credit_init_bits(size_t bits)
  *
  **********************************************************************/
 
-static bool trust_cpu __ro_after_init = IS_ENABLED(CONFIG_RANDOM_TRUST_CPU);
-static bool trust_bootloader __ro_after_init = IS_ENABLED(CONFIG_RANDOM_TRUST_BOOTLOADER);
+static bool trust_cpu __initdata = IS_ENABLED(CONFIG_RANDOM_TRUST_CPU);
+static bool trust_bootloader __initdata = IS_ENABLED(CONFIG_RANDOM_TRUST_BOOTLOADER);
 static int __init parse_trust_cpu(char *arg)
 {
 	return kstrtobool(arg, &trust_cpu);
@@ -882,13 +882,12 @@ EXPORT_SYMBOL_GPL(add_hwgenerator_randomness);
  * Handle random seed passed by bootloader, and credit it if
  * CONFIG_RANDOM_TRUST_BOOTLOADER is set.
  */
-void __cold add_bootloader_randomness(const void *buf, size_t len)
+void __init add_bootloader_randomness(const void *buf, size_t len)
 {
 	mix_pool_bytes(buf, len);
 	if (trust_bootloader)
 		credit_init_bits(len * 8);
 }
-EXPORT_SYMBOL_GPL(add_bootloader_randomness);
 
 struct fast_pool {
 	struct work_struct mix;
diff --git a/include/linux/random.h b/include/linux/random.h
index 917470c4490a..3feafab498ad 100644
--- a/include/linux/random.h
+++ b/include/linux/random.h
@@ -13,7 +13,7 @@
 struct notifier_block;
 
 void add_device_randomness(const void *buf, size_t len);
-void add_bootloader_randomness(const void *buf, size_t len);
+void __init add_bootloader_randomness(const void *buf, size_t len);
 void add_input_randomness(unsigned int type, unsigned int code,
 			  unsigned int value) __latent_entropy;
 void add_interrupt_randomness(int irq) __latent_entropy;
-- 
2.35.1


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH stable 5.18 5.17 5.15 5.10 3/3] random: account for arch randomness in bits
  2022-06-13  8:07 [PATCH stable 5.18 5.17 5.15 5.10 0/3] rng stable patches from 5.19-rc2 Jason A. Donenfeld
  2022-06-13  8:07 ` [PATCH stable 5.18 5.17 5.15 5.10 1/3] random: avoid checking crng_ready() twice in random_init() Jason A. Donenfeld
  2022-06-13  8:07 ` [PATCH stable 5.18 5.17 5.15 5.10 2/3] random: mark bootloader randomness code as __init Jason A. Donenfeld
@ 2022-06-13  8:07 ` Jason A. Donenfeld
  2022-06-13  9:02 ` [PATCH stable 5.18 5.17 5.15 5.10 0/3] rng stable patches from 5.19-rc2 Greg KH
  3 siblings, 0 replies; 6+ messages in thread
From: Jason A. Donenfeld @ 2022-06-13  8:07 UTC (permalink / raw)
  To: stable, gregkh

commit 77fc95f8c0dc9e1f8e620ec14d2fb65028fb7adc upstream.

Rather than accounting in bytes and multiplying (shifting), we can just
account in bits and avoid the shift. The main motivation for this is
there are other patches in flux that expand this code a bit, and
avoiding the duplication of "* 8" everywhere makes things a bit clearer.

Cc: stable@vger.kernel.org
Fixes: 12e45a2a6308 ("random: credit architectural init the exact amount")
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
---
 drivers/char/random.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/char/random.c b/drivers/char/random.c
index d09e78e6f24b..82f9ee440406 100644
--- a/drivers/char/random.c
+++ b/drivers/char/random.c
@@ -809,7 +809,7 @@ early_param("random.trust_bootloader", parse_trust_bootloader);
 int __init random_init(const char *command_line)
 {
 	ktime_t now = ktime_get_real();
-	unsigned int i, arch_bytes;
+	unsigned int i, arch_bits;
 	unsigned long entropy;
 
 #if defined(LATENT_ENTROPY_PLUGIN)
@@ -817,12 +817,12 @@ int __init random_init(const char *command_line)
 	_mix_pool_bytes(compiletime_seed, sizeof(compiletime_seed));
 #endif
 
-	for (i = 0, arch_bytes = BLAKE2S_BLOCK_SIZE;
+	for (i = 0, arch_bits = BLAKE2S_BLOCK_SIZE * 8;
 	     i < BLAKE2S_BLOCK_SIZE; i += sizeof(entropy)) {
 		if (!arch_get_random_seed_long_early(&entropy) &&
 		    !arch_get_random_long_early(&entropy)) {
 			entropy = random_get_entropy();
-			arch_bytes -= sizeof(entropy);
+			arch_bits -= sizeof(entropy) * 8;
 		}
 		_mix_pool_bytes(&entropy, sizeof(entropy));
 	}
@@ -834,7 +834,7 @@ int __init random_init(const char *command_line)
 	if (crng_ready())
 		crng_reseed();
 	else if (trust_cpu)
-		_credit_init_bits(arch_bytes * 8);
+		_credit_init_bits(arch_bits);
 
 	return 0;
 }
-- 
2.35.1


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH stable 5.18 5.17 5.15 5.10 0/3] rng stable patches from 5.19-rc2
  2022-06-13  8:07 [PATCH stable 5.18 5.17 5.15 5.10 0/3] rng stable patches from 5.19-rc2 Jason A. Donenfeld
                   ` (2 preceding siblings ...)
  2022-06-13  8:07 ` [PATCH stable 5.18 5.17 5.15 5.10 3/3] random: account for arch randomness in bits Jason A. Donenfeld
@ 2022-06-13  9:02 ` Greg KH
  3 siblings, 0 replies; 6+ messages in thread
From: Greg KH @ 2022-06-13  9:02 UTC (permalink / raw)
  To: Jason A. Donenfeld; +Cc: stable

On Mon, Jun 13, 2022 at 10:07:46AM +0200, Jason A. Donenfeld wrote:
> Hi Greg,
> 
> These three patches from 5.19-rc2 failed to automatically apply. The
> following series should work okay.

All now queued up, thanks.

> Note that these are already part of the 4.9, 4.14, 4.19, 5.4 backport I
> did for later this week.

Great, thanks for adding them there too.

greg k-h

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH stable 5.18 5.17 5.15 5.10 0/3] rng stable patches from 5.19-rc2
@ 2022-06-13  8:05 Jason A. Donenfeld
  0 siblings, 0 replies; 6+ messages in thread
From: Jason A. Donenfeld @ 2022-06-13  8:05 UTC (permalink / raw)
  To: stable, gregkh

Hi Greg,

These three patches from 5.19-rc2 failed to automatically apply. The
following series should work okay.

Note that these are already part of the 4.9, 4.14, 4.19, 5.4 backport I
did for later this week.

Jason

Jason A. Donenfeld (3):
  random: avoid checking crng_ready() twice in random_init()
  random: mark bootloader randomness code as __init
  random: account for arch randomness in bits

 drivers/char/random.c  | 15 +++++++--------
 include/linux/random.h |  2 +-
 2 files changed, 8 insertions(+), 9 deletions(-)

-- 
2.35.1


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2022-06-13  9:02 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-06-13  8:07 [PATCH stable 5.18 5.17 5.15 5.10 0/3] rng stable patches from 5.19-rc2 Jason A. Donenfeld
2022-06-13  8:07 ` [PATCH stable 5.18 5.17 5.15 5.10 1/3] random: avoid checking crng_ready() twice in random_init() Jason A. Donenfeld
2022-06-13  8:07 ` [PATCH stable 5.18 5.17 5.15 5.10 2/3] random: mark bootloader randomness code as __init Jason A. Donenfeld
2022-06-13  8:07 ` [PATCH stable 5.18 5.17 5.15 5.10 3/3] random: account for arch randomness in bits Jason A. Donenfeld
2022-06-13  9:02 ` [PATCH stable 5.18 5.17 5.15 5.10 0/3] rng stable patches from 5.19-rc2 Greg KH
  -- strict thread matches above, loose matches on Subject: below --
2022-06-13  8:05 Jason A. Donenfeld

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.