Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1245417
| From | "George Spelvin" <linux@horizon.com> |
|---|---|
| Newsgroups | linux.kernel |
| Subject | Re: Updated scalable urandom patchkit |
| Date | 2015-10-13 10:00 +0200 |
| Message-ID | <qj2F4-98-1@gated-at.bofh.it> (permalink) |
| References | <qiZnQ-3UZ-5@gated-at.bofh.it> |
| Organization | linux.* mail to news gateway |
> 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.
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Back to linux.kernel | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Re: Updated scalable urandom patchkit "George Spelvin" <linux@horizon.com> - 2015-10-10 21:00 +0200
Re: Updated scalable urandom patchkit Theodore Ts'o <tytso@mit.edu> - 2015-10-11 04:40 +0200
Re: Updated scalable urandom patchkit Theodore Ts'o <tytso@mit.edu> - 2015-10-11 05:00 +0200
Re: Updated scalable urandom patchkit "George Spelvin" <linux@horizon.com> - 2015-10-11 06:40 +0200
Re: Updated scalable urandom patchkit Theodore Ts'o <tytso@mit.edu> - 2015-10-12 00:30 +0200
Re: Updated scalable urandom patchkit "George Spelvin" <linux@horizon.com> - 2015-10-12 02:20 +0200
Re: Updated scalable urandom patchkit Theodore Ts'o <tytso@mit.edu> - 2015-10-12 06:10 +0200
Re: Updated scalable urandom patchkit "George Spelvin" <linux@horizon.com> - 2015-10-12 09:50 +0200
Re: Updated scalable urandom patchkit Theodore Ts'o <tytso@mit.edu> - 2015-10-12 16:00 +0200
Re: Updated scalable urandom patchkit "George Spelvin" <linux@horizon.com> - 2015-10-12 22:40 +0200
Re: Updated scalable urandom patchkit "George Spelvin" <linux@horizon.com> - 2015-10-12 22:40 +0200
Re: Updated scalable urandom patchkit Theodore Ts'o <tytso@mit.edu> - 2015-10-13 04:50 +0200
Re: Updated scalable urandom patchkit Raymond Jennings <shentino@gmail.com> - 2015-10-13 06:30 +0200
Re: Updated scalable urandom patchkit "George Spelvin" <linux@horizon.com> - 2015-10-13 10:00 +0200
Re: Updated scalable urandom patchkit "George Spelvin" <linux@horizon.com> - 2015-10-13 08:30 +0200
Re: Updated scalable urandom patchkit Andi Kleen <andi@firstfloor.org> - 2015-10-13 18:30 +0200
Re: Updated scalable urandom patchkit "George Spelvin" <linux@horizon.com> - 2015-10-13 23:20 +0200
Re: Updated scalable urandom patchkit Andi Kleen <andi@firstfloor.org> - 2015-10-14 04:20 +0200
[RFC PATCH 0/4] Alternate sclable urandom patchset "George Spelvin" <linux@horizon.com> - 2015-10-16 07:30 +0200
[RFC PATCH 2/4] random: Remove two unused arguments from extract_entropy() "George Spelvin" <linux@horizon.com> - 2015-10-16 07:40 +0200
[RFC PATCH 4/4] random: Make non-blocking mixback non-blocking "George Spelvin" <linux@horizon.com> - 2015-10-16 07:40 +0200
[RFC PATCH 3/4] random: Only do mixback once per read "George Spelvin" <linux@horizon.com> - 2015-10-16 07:40 +0200
Re: [RFC PATCH 3/4] random: Only do mixback once per read kbuild test robot <lkp@intel.com> - 2015-10-16 08:20 +0200
Re: [RFC PATCH 3/4] random: Only do mixback once per read "George Spelvin" <linux@horizon.com> - 2015-10-16 10:20 +0200
csiph-web