From: Adhemerval Zanella <adhemerval.zanella@linaro.org>
To: Noah Goldstein <goldstein.w.n@gmail.com>
Cc: "Cristian Rodríguez" <crrodriguez@opensuse.org>,
"Jason A. Donenfeld" <Jason@zx2c4.com>,
"GNU C Library" <libc-alpha@sourceware.org>,
"Florian Weimer" <fweimer@redhat.com>
Subject: Re: [PATCH v1 1/2] random-bits: Factor out entropy generating function
Date: Mon, 4 Apr 2022 16:57:44 -0300 [thread overview]
Message-ID: <7fdb5ea5-9929-7d55-6b36-960268a4c440@linaro.org> (raw)
In-Reply-To: <CAFUsyfJP3LPD4YnrcCEGxD63YmDQNXO59kFX4xf7aHUt-A5N+w@mail.gmail.com>
On 04/04/2022 16:48, Noah Goldstein wrote:
> On Mon, Apr 4, 2022 at 2:20 PM Adhemerval Zanella
> <adhemerval.zanella@linaro.org> wrote:
>>
>>
>>
>> On 04/04/2022 15:52, Noah Goldstein wrote:
>>> On Mon, Apr 4, 2022 at 1:38 PM Adhemerval Zanella
>>> <adhemerval.zanella@linaro.org> wrote:
>>>>
>>>>
>>>>
>>>> On 04/04/2022 15:23, Noah Goldstein wrote:
>>>>> On Mon, Apr 4, 2022 at 12:42 PM Adhemerval Zanella
>>>>> <adhemerval.zanella@linaro.org> wrote:
>>>>>>
>>>>>>
>>>>>>
>>>>>> On 01/04/2022 15:01, Cristian Rodríguez wrote:
>>>>>>> On Thu, Mar 31, 2022 at 8:05 PM Noah Goldstein <goldstein.w.n@gmail.com> wrote:
>>>>>>>
>>>>>>>> AFAIK our goal is entropy more so than security. For example
>>>>>>>> if this is used to generate jiffies to stagger threads its not a security
>>>>>>>> issue in any sense, it's just not ideal for performance.
>>>>>>>
>>>>>>> In any case this should be more than fast enough for the other use
>>>>>>> cases of random_bits() .. maybe one new random_bits_fast() function
>>>>>>> foe edge cases where even this is too slow?
>>>>>>
>>>>>> I think we are bike-shedding in the same issue OpenBSD guys stumbled
>>>>>> and which they have solved 10 years ago [1]. Essentially, we need to
>>>>>> come up with a internal PRNG interface that can be used internally and
>>>>>> externally, instead of reinventing cleaver ways to use the timer as
>>>>>> entropy source.
>>>>>>
>>>>>> The issue is not really the cypher used, ideally it could be replace if
>>>>>> we find out that it does not fit. The main issue is to glue together
>>>>>> all the requirements to have a concise internal interface, taking in
>>>>>> consideration the glibc constrains to work with multiple kernel version
>>>>>> and environments (where we can't assume we have access to a source or
>>>>>> reliable entropy like getrandom syscall).
>>>>>>
>>>>>> My plan to rehearse Florian arc4random proposal to have some simpler
>>>>>> to where we might improve upon (a simpler fork detection for kernels
>>>>>> without MADV_WIPEONFORK that just issue a atfork handle, maybe using
>>>>>> ChaCha20 as virtually all other systems do, no per-thread state).
>>>>>
>>>>> Why no per-thread / per-cpu? It seems otherwise there will need to be
>>>>> some explicit synchronization on the stream.
>>>>
>>>> Mainly because it simplifies a lot the *initial* implementation. I would
>>>> prefer to incremental add per-thread optimization than dump a large patch
>>>> so we can review in integrate the code more easier.
>>>>
>>>>>
>>>>>
>>>>> Regarding this patch, do we want to skip it and just wait on arc4random
>>>>> interface in kernel/glibc or should I go forward with it and some arch
>>>>> specific entropy functions in the mean-time?
>>>>
>>>> I don't have a strong opinion on this patch, it does improve x86_64
>>>> latency on random_bits although currently internal usage are far from
>>>> latency sensitive. It is really a microoptimization without much real
>>>> work gain for current code.
>>>
>>> That's fair. The motivation is so random_bits can be used for lightweight
>>> jitter i.e in cases like:
>>>
>>> [v2] nptl: Add backoff mechanism to spinlock loop
>>>
>>> The x86 backend with `rdtsc` is just because it's a simple improvement,
>>> other arch will hopefully be able to get off syscall if they don't have vdso
>>> gettime.
>>> But agree the improvement gains a minimal so if people don't feel its worth
>>> the added complexity we can wait on a strong arch-random interface.
>>
>> I think for mutex optimization it would be better to just add a arch-specific
>> jitter code and use the backoff optimization iff the arch-specific code is
>> used. And maybe not tied to random_bits(), since I am not sure if an interface
>> like arc4random would be good to use in such scenario (since a possible state
>> reschedule might call getentropy with my add unexpected latency).
>
> So you propose drop this patch in favor of some new internal interface like
> get_fast_jitter() and a define such as 'HAS_FAST_JITTER'?
Yeah, this would be better than try to improve random_bits. Also, recently
we are trying to avoid internal HAS/HAVE defines, it is better to add a
generic interface that does either nothing or return a default value
(so default get_fast_jitter() would return 1 or 0, so the mutex code will
se it just do the current spinning without backoff).
next prev parent reply other threads:[~2022-04-04 19:57 UTC|newest]
Thread overview: 48+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-03-28 22:09 Noah Goldstein
2022-03-28 22:09 ` [PATCH v1 2/2] x86: Use rdtsc for generating entropy for random_bits Noah Goldstein
2022-03-29 19:51 ` [PATCH v1 1/2] random-bits: Factor out entropy generating function Adhemerval Zanella
2022-03-29 19:56 ` Noah Goldstein
2022-03-29 20:04 ` Noah Goldstein
2022-03-29 20:14 ` H.J. Lu
2022-03-29 20:44 ` Adhemerval Zanella
2022-03-29 20:52 ` Noah Goldstein
2022-03-29 20:37 ` Adhemerval Zanella
2022-03-29 20:44 ` Noah Goldstein
2022-03-30 15:37 ` Adhemerval Zanella
2022-03-30 16:30 ` Noah Goldstein
2022-03-30 19:38 ` Cristian Rodríguez
2022-03-31 4:45 ` Jason A. Donenfeld
2022-03-31 10:08 ` Cristian Rodríguez
2022-03-31 11:17 ` Adhemerval Zanella
2022-03-31 11:25 ` Cristian Rodríguez
2022-03-31 11:48 ` Adhemerval Zanella
2022-03-31 12:14 ` Cristian Rodríguez
2022-03-31 13:12 ` Yann Droneaud
2022-03-31 15:31 ` Jason A. Donenfeld
2022-03-31 18:16 ` Noah Goldstein
2022-03-31 21:57 ` Cristian Rodríguez
2022-03-31 22:33 ` Noah Goldstein
2022-03-31 22:51 ` Jason A. Donenfeld
2022-03-31 23:05 ` Noah Goldstein
2022-03-31 23:25 ` Jason A. Donenfeld
2022-04-01 18:01 ` Cristian Rodríguez
2022-04-04 17:42 ` Adhemerval Zanella
2022-04-04 18:23 ` Noah Goldstein
2022-04-04 18:38 ` Adhemerval Zanella
2022-04-04 18:52 ` Noah Goldstein
2022-04-04 19:20 ` Adhemerval Zanella
2022-04-04 19:48 ` Noah Goldstein
2022-04-04 19:57 ` Adhemerval Zanella [this message]
2022-04-04 14:51 ` Florian Weimer
2022-04-04 14:54 ` Jason A. Donenfeld
2022-04-04 15:00 ` Florian Weimer
2022-04-04 16:51 ` Noah Goldstein
2022-04-04 17:22 ` Adhemerval Zanella
2022-04-04 18:32 ` Jason A. Donenfeld
2022-04-04 19:16 ` Noah Goldstein
2022-04-05 0:10 ` Cristian Rodríguez
2022-04-05 0:18 ` Jason A. Donenfeld
2022-04-05 13:45 ` Cristian Rodríguez
2022-04-05 9:22 ` Florian Weimer
2022-04-04 18:28 ` Jason A. Donenfeld
2022-04-05 9:20 ` 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=7fdb5ea5-9929-7d55-6b36-960268a4c440@linaro.org \
--to=adhemerval.zanella@linaro.org \
--cc=Jason@zx2c4.com \
--cc=crrodriguez@opensuse.org \
--cc=fweimer@redhat.com \
--cc=goldstein.w.n@gmail.com \
--cc=libc-alpha@sourceware.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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).