LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
From: "Theodore Y. Ts'o" <tytso@mit.edu>
To: "Jason A. Donenfeld" <Jason@zx2c4.com>
Cc: Tony Luck <tony.luck@gmail.com>,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
Linux Kernel Mailing List <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH] random: always use batched entropy for get_random_u{32,64}
Date: Fri, 21 Feb 2020 19:41:33 -0500 [thread overview]
Message-ID: <20200222004133.GC873427@mit.edu> (raw)
In-Reply-To: <CAHmME9q1rnD5z2bENYhqnM5-XCD+E68nm2RrGRWXt8ntpvfezg@mail.gmail.com>
On Fri, Feb 21, 2020 at 09:08:19PM +0100, Jason A. Donenfeld wrote:
> On Thu, Feb 20, 2020 at 11:29 PM Tony Luck <tony.luck@gmail.com> wrote:
> >
> > Also ... what's the deal with a spin_lock on a per-cpu structure?
> >
> > batch = raw_cpu_ptr(&batched_entropy_u64);
> > spin_lock_irqsave(&batch->batch_lock, flags);
> > if (batch->position % ARRAY_SIZE(batch->entropy_u64) == 0) {
> > extract_crng((u8 *)batch->entropy_u64);
> > batch->position = 0;
> > }
> > ret = batch->entropy_u64[batch->position++];
> > spin_unlock_irqrestore(&batch->batch_lock, flags);
> >
> > Could we just disable interrupts and pre-emption around the entropy extraction?
>
> Probably, yes... We can address this in a separate patch.
No, we can't; take a look at invalidate_batched_entropy(), where we
need invalidate all of per-cpu batched entropy from a single CPU after
we have initialized the the CRNG.
Since most of the time after CRNG initialization, the spinlock for
each CPU will be on that CPU's cacheline, the time to take and release
the spinlock is not going to be material.
- Ted
next prev parent reply other threads:[~2020-02-22 0:41 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-02-16 16:18 Jason A. Donenfeld
2020-02-16 18:23 ` Greg Kroah-Hartman
2020-02-20 22:20 ` Tony Luck
2020-02-20 22:29 ` Tony Luck
2020-02-21 20:08 ` Jason A. Donenfeld
2020-02-22 0:41 ` Theodore Y. Ts'o [this message]
2020-02-22 9:59 ` Jason A. Donenfeld
2020-02-24 20:41 ` Luck, Tony
2020-02-21 20:07 ` Jason A. Donenfeld
2020-02-21 20:10 ` [PATCH v2] " Jason A. Donenfeld
2020-02-28 4:09 ` Theodore Y. Ts'o
2020-04-01 13:08 ` Nicolai Stange
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=20200222004133.GC873427@mit.edu \
--to=tytso@mit.edu \
--cc=Jason@zx2c4.com \
--cc=gregkh@linuxfoundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=tony.luck@gmail.com \
--subject='Re: [PATCH] random: always use batched entropy for get_random_u{32,64}' \
/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
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).