From: "Jason A. Donenfeld" <Jason@zx2c4.com>
To: Florian Weimer <fweimer@redhat.com>
Cc: linux-kernel@vger.kernel.org, linux-crypto@vger.kernel.org,
x86@kernel.org, Nadia Heninger <nadiah@cs.ucsd.edu>,
Thomas Ristenpart <ristenpart@cornell.edu>,
Theodore Ts'o <tytso@mit.edu>,
Vincenzo Frascino <vincenzo.frascino@arm.com>,
Adhemerval Zanella Netto <adhemerval.zanella@linaro.org>,
Linus Torvalds <torvalds@linux-foundation.org>
Subject: Re: [PATCH RFC v2] random: implement getrandom() in vDSO
Date: Mon, 1 Aug 2022 14:49:17 +0200 [thread overview]
Message-ID: <YufLzQkmaERnJMOs@zx2c4.com> (raw)
In-Reply-To: <871qu0qri6.fsf@oldenburg.str.redhat.com>
Hey Florian,
On Mon, Aug 01, 2022 at 10:48:01AM +0200, Florian Weimer wrote:
> * Jason A. Donenfeld:
>
> > API-wise, vDSO getrandom has a pair of functions:
> >
> > ssize_t getrandom(void *state, void *buffer, size_t len, unsigned int flags);
> > void *getrandom_alloc([inout] size_t *num, [out] size_t *size_per_each);
> >
> > In the first function, the return value and the latter 3 arguments are
> > the same as ordinary getrandom(), while the first argument is a pointer
> > to some state allocated with getrandom_alloc(). getrandom_alloc() takes
> > the desired number of states, and returns an array of states, the number
> > actually allocated, and the size in bytes of each one, enabling a libc
> > to use one per thread. We very intentionally do *not* leave state
> > allocation up to the caller. There are too many weird things that can go
> > wrong, and it's important that vDSO does not provide too generic of a
> > mechanism. It's not going to store its state in just any old memory
> > address. It'll do it only in ones it allocates.
>
> I still don't see why this couldn't be per-thread state (if you handle
> fork generations somehow).
That actually *is* the intent of this v2. Specifically, you call
getrandom_alloc and you get an *array* of states, which you can then
pass off to various threads. Since we have to allocate in page sizes, we
can't do this piecemeal, so this is a mechanism for giving out chunks of
them (~28 at a time), which you'd then give to threads as they're
created, making more as needed.
> I also think it makes sense to introduce batching for the system call
> implementation first, and tie that to the vDSO acceleration. I expect a
> large part of the benefit comes from the batching, not the system call
> avoidance.
What I understand you to mean is that *instead of* doing vDSO, we could
just batch in the kernel, and reap most of the performance benefits. If
that turns out to be true, and then we don't even need this vDSO stuff,
I'd be really happy. So I'll give this a try.
One question is where to store that batch. On the surface, per-cpu seems
appealing, like what we do for get_random_u32() and such for kernel
callers. But per-cpu means disabling preemption, which then becomes a
problem when copying into userspace, where the copies can fault. So
maybe something more sensible is, like above, just doing this per-task.
I'll give it a stab and will let you know what it looks like.
Jason
next prev parent reply other threads:[~2022-08-01 12:53 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-07-29 14:55 [PATCH RFC v1] " Jason A. Donenfeld
2022-07-29 20:19 ` Florian Weimer
2022-07-29 22:06 ` Jason A. Donenfeld
2022-07-30 15:48 ` Linus Torvalds
2022-07-30 23:45 ` Jason A. Donenfeld
2022-07-31 0:23 ` Jason A. Donenfeld
2022-07-31 1:31 ` [PATCH RFC v2] " Jason A. Donenfeld
2022-08-01 8:48 ` Florian Weimer
2022-08-01 12:49 ` Jason A. Donenfeld [this message]
2022-08-01 13:29 ` Jason A. Donenfeld
2022-08-01 13:00 ` Jason A. Donenfeld
2022-08-01 20:48 ` Thomas Gleixner
2022-08-01 23:41 ` Jason A. Donenfeld
2022-08-02 0:12 ` Jason A. Donenfeld
2022-08-01 19:30 ` [PATCH RFC v1] " Thomas Gleixner
2022-08-01 23:16 ` Jason A. Donenfeld
2022-08-02 13:46 ` Thomas Gleixner
2022-08-02 13:59 ` Jason A. Donenfeld
2022-08-02 15:14 ` Thomas Gleixner
2022-08-02 15:26 ` Jason A. Donenfeld
2022-08-02 22:27 ` Thomas Gleixner
2022-08-04 15:23 ` Jason A. Donenfeld
2022-08-04 16:08 ` Jeffrey Walton
2022-08-04 23:11 ` Thomas Gleixner
2022-08-17 8:20 ` Peter Zijlstra
2022-08-05 8:36 ` Florian Weimer
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=YufLzQkmaERnJMOs@zx2c4.com \
--to=jason@zx2c4.com \
--cc=adhemerval.zanella@linaro.org \
--cc=fweimer@redhat.com \
--cc=linux-crypto@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=nadiah@cs.ucsd.edu \
--cc=ristenpart@cornell.edu \
--cc=torvalds@linux-foundation.org \
--cc=tytso@mit.edu \
--cc=vincenzo.frascino@arm.com \
--cc=x86@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®