public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Dominik Brodowski <linux@dominikbrodowski.net>
To: "Jason A. Donenfeld" <Jason@zx2c4.com>
Cc: linux-kernel@vger.kernel.org, linux-crypto@vger.kernel.org,
	bigeasy@linutronix.de, Sultan Alsawaf <sultan@kerneltoast.com>,
	Thomas Gleixner <tglx@linutronix.de>,
	Peter Zijlstra <peterz@infradead.org>,
	Theodore Ts'o <tytso@mit.edu>
Subject: Re: [PATCH] random: do crng pre-init loading in worker rather than irq
Date: Thu, 24 Feb 2022 16:11:16 +0100	[thread overview]
Message-ID: <YhegFNGbcgpILo2r@owl.dominikbrodowski.net> (raw)
In-Reply-To: <CAHmME9oesPzz4ofe-wo_ZViM=uahL6WQo8-5ov7xjJN8ui1rsg@mail.gmail.com>

Am Thu, Feb 24, 2022 at 10:49:12AM +0100 schrieb Jason A. Donenfeld:
> On 2/24/22, Dominik Brodowski <linux@dominikbrodowski.net> wrote:
> > Am Wed, Feb 23, 2022 at 07:55:11PM +0100 schrieb Jason A. Donenfeld:
> >> Taking spinlocks from IRQ context is problematic for PREEMPT_RT. That
> >> is, in part, why we take trylocks instead. But apparently this still
> >> trips up various lock dependency analyzers. That seems like a bug in the
> >> analyzers that should be fixed, rather than having to change things
> >> here.
> >>
> >> But maybe there's another reason to change things up: by deferring the
> >> crng pre-init loading to the worker, we can use the cryptographic hash
> >> function rather than xor, which is perhaps a meaningful difference when
> >> considering this data has only been through the relatively weak
> >> fast_mix() function.
> >>
> >> The biggest downside of this approach is that the pre-init loading is
> >> now deferred until later, which means things that need random numbers
> >> after interrupts are enabled, but before workqueues are running -- or
> >> before this particular worker manages to run -- are going to get into
> >> trouble. Hopefully in the real world, this window is rather small,
> >> especially since this code won't run until 64 interrupts had occurred.
> >>
> >> Cc: Dominik Brodowski <linux@dominikbrodowski.net>
> >> Cc: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
> >> Cc: Sultan Alsawaf <sultan@kerneltoast.com>
> >> Cc: Thomas Gleixner <tglx@linutronix.de>
> >> Cc: Peter Zijlstra <peterz@infradead.org>
> >> Cc: Theodore Ts'o <tytso@mit.edu>
> >> Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
> >> ---
> >>  drivers/char/random.c | 62 ++++++++++++-------------------------------
> >>  1 file changed, 17 insertions(+), 45 deletions(-)
> >>
> >> diff --git a/drivers/char/random.c b/drivers/char/random.c
> >> index 536237a0f073..9fb06fc298d3 100644
> >> --- a/drivers/char/random.c
> >> +++ b/drivers/char/random.c
> >> @@ -1298,7 +1278,12 @@ static void mix_interrupt_randomness(struct
> >> work_struct *work)
> >>  	local_irq_enable();
> >>
> >>  	mix_pool_bytes(pool, sizeof(pool));
> >> -	credit_entropy_bits(1);
> >> +
> >> +	if (unlikely(crng_init == 0))
> >> +		crng_pre_init_inject(pool, sizeof(pool), true);
> >> +	else
> >> +		credit_entropy_bits(1);
> >> +
> >>  	memzero_explicit(pool, sizeof(pool));
> >>  }
> >
> > Might it make sense to call crng_pre_init_inject() before mix_pool_bytes?
> 
> What exactly is the difference you see mattering in the order? I keep
> chasing my tail trying to think about it.

We had that order beforehand -- and even if it probably doesn't matter, this
means crng_pre_init_inject() gets called a tiny bit earlier. That means
there's a chance to progres to crng_init=1 a tiny bit earlier as well.

Thanks,
	Dominik

  reply	other threads:[~2022-02-24 15:11 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-02-23 18:55 [PATCH] random: do crng pre-init loading in worker rather than irq Jason A. Donenfeld
2022-02-24  7:47 ` Dominik Brodowski
2022-02-24  9:49   ` Jason A. Donenfeld
2022-02-24 15:11     ` Dominik Brodowski [this message]
2022-02-24 15:15       ` Jason A. Donenfeld
2022-02-24 15:29         ` [PATCH v2] " Jason A. Donenfeld
2022-02-28 14:02           ` Sebastian Andrzej Siewior
2022-02-28 14:17             ` Jason A. Donenfeld
2022-02-28 14:29               ` Sebastian Andrzej Siewior
2022-02-28 15:10                 ` Jason A. Donenfeld
2022-02-28 15:34                   ` Sebastian Andrzej Siewior
2022-02-24 11:31 ` [PATCH] " 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=YhegFNGbcgpILo2r@owl.dominikbrodowski.net \
    --to=linux@dominikbrodowski.net \
    --cc=Jason@zx2c4.com \
    --cc=bigeasy@linutronix.de \
    --cc=linux-crypto@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=peterz@infradead.org \
    --cc=sultan@kerneltoast.com \
    --cc=tglx@linutronix.de \
    --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