From: "George Spelvin" <linux@horizon.com>
To: ahferroin7@gmail.com, andi@firstfloor.org, jepler@unpythonic.net,
linux-kernel@vger.kernel.org, linux@horizon.com,
linux@rasmusvillemoes.dk, shentino@gmail.com, tytso@mit.edu
Subject: Re: Updated scalable urandom patchkit
Date: 13 Oct 2015 03:50:21 -0400 [thread overview]
Message-ID: <20151013075021.3427.qmail@ns.horizon.com> (raw)
In-Reply-To: <1444708222.900.0@smtp.gmail.com>
> This might be stupid, but could something asynchronous work? Perhaps
> have the entropy generators dump their entropy into a central pool via
> a cycbuf, and have a background kthread manage the per-cpu or
> per-process entropy pools?
No for two reasons:
(Minor): One of the functions of the mixback is to ensure that the next
reader hashes a *different* pool state. If the mixback is
delayed, the next reader might hash the *same* pool state and
return the same numbers. (There are easy workarounds for this.)
(Major): What do you do when the circular buffer is full? If it's not safe
to skip the mixback, then we have to block and get into the same
lock-contention problem.
But... this suggestion of having a separate thread do the mixback gives
me an idea. In fact, I think it's a good idea.
Ted (or anyone else listening), what do you think of the following?
I think it would solve Andi's problem and be a smaller code change than
the abuse mitigation mode. (Which is still a good idea, but is off the
critical path.)
- Associated with a pool is an atomic "mixback needed" flag.
- Also an optional mixback buffer. (Optional because the mixback
could just recompute it.)
- Dropping the lock requires the following operations:
- Test the mixback needed flag. If set,
- Copy out and wipe the buffer,
- smp_wmb()
- Clear the flag
- smp_wmb()
- Do the mixback, and
- Re-check again before dropping the lock.
(This check before dropping the lock is technically an optional
optimization.)
- Drop the lock.
- smp_mb() (Since it's write-to-read, we can't use _rmb or _wmb.)
- Test the mixback pending flag again.
- If it's set, trylock(). If that succeeds, go do the mixback as above.
- If it fails, return.
Each reader uses already-discussed nonce techniques to safely do concurrent
reads from the same pool. Then, at the end:
- (Optional) trylock() and, if it succeeds,
do mixback directly.
- Copy our mixback data to the buffer (race conditions be damned)
- smp_wmb()
- set the mixback needed flag
- smp_mb() (Since it's write-to-read; or use smp_store_mb())
- trylock()
- If that fails. return
- If that succeeds (and the flag is still set) do the mixback
This is based on the fact that if there are multiple concurrent reads,
we only need one mixback (thus, only one buffer/flag), but the "last one
out the door" has to do it.
Also, we don't care if we mis-count and end up doing it twice.
Each reader sets the flag and *then* does a trylock. If the trylock fails,
it's guaranteed that the lock-holder will see the flag and take care of
the mixback for us.
The writers drop the lock and *then* test the flag.
The result is that readers *never* do a blocking acquire of the pool
lock. Which should solve all the contention problems. Andi's stupid
application will still be stupid, but won't fall off a locking cliff.
(We could also use w[5] as the "mixback needed" flag and just
force it to 1 on the off chance it's zero with negligible loss
of entropy and zero security loss.)
The one thing I worry about is livelock keeping one thread in the
mixback code indefinitely, which can be mitigated by dropping the lock
and waiting before re-testing and re-acquiring if we loop too often.
next prev parent reply other threads:[~2015-10-13 7:50 UTC|newest]
Thread overview: 30+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-10-10 18:45 George Spelvin
2015-10-11 2:31 ` Theodore Ts'o
2015-10-11 2:53 ` Theodore Ts'o
2015-10-11 4:35 ` George Spelvin
2015-10-11 22:25 ` Theodore Ts'o
2015-10-12 0:16 ` George Spelvin
2015-10-12 4:05 ` Theodore Ts'o
2015-10-12 7:49 ` George Spelvin
2015-10-12 13:54 ` Theodore Ts'o
2015-10-12 20:30 ` George Spelvin
2015-10-12 20:34 ` George Spelvin
2015-10-13 2:46 ` Theodore Ts'o
2015-10-13 3:50 ` Raymond Jennings
2015-10-13 7:50 ` George Spelvin [this message]
2015-10-13 6:24 ` George Spelvin
2015-10-13 16:20 ` Andi Kleen
2015-10-13 21:10 ` George Spelvin
2015-10-14 2:15 ` Andi Kleen
2015-10-16 5:28 ` [RFC PATCH 0/4] Alternate sclable urandom patchset George Spelvin
2015-10-16 5:29 ` [RFC PATCH 1/4] random: Reduce stack usage in _xfer_secondary_pool George Spelvin
2015-10-16 5:30 ` [RFC PATCH 2/4] random: Remove two unused arguments from extract_entropy() George Spelvin
2015-10-16 5:33 ` [RFC PATCH 3/4] random: Only do mixback once per read George Spelvin
2015-10-16 6:12 ` kbuild test robot
2015-10-16 8:11 ` George Spelvin
2015-10-16 6:23 ` kbuild test robot
2015-10-16 5:34 ` [RFC PATCH 4/4] random: Make non-blocking mixback non-blocking George Spelvin
2015-10-21 8:27 ` Updated scalable urandom patchkit George Spelvin
2015-10-21 11:47 ` Andi Kleen
2015-10-21 18:10 ` George Spelvin
-- strict thread matches above, loose matches on Subject: below --
2015-09-24 17:19 Andi Kleen
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=20151013075021.3427.qmail@ns.horizon.com \
--to=linux@horizon.com \
--cc=ahferroin7@gmail.com \
--cc=andi@firstfloor.org \
--cc=jepler@unpythonic.net \
--cc=linux-kernel@vger.kernel.org \
--cc=linux@rasmusvillemoes.dk \
--cc=shentino@gmail.com \
--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
all inboxes | Powered by JetHome®