Commit Graph

89 Commits

Author SHA1 Message Date
riastradh
77ebf39786 Ask on-demand entropy sources to produce enough data to fill buffer.
Remainder of fix for PR kern/51135: if there is an entropy source
that can produce arbitrarily much data, as in rump, then nothing
should ever block indefinitely waiting for data.
2016-05-21 15:27:15 +00:00
riastradh
e6b3ef04bb Mark skewsrcp as __diagused to unbreak non-DIAGNOSTIC builds. 2016-02-29 01:57:30 +00:00
riastradh
c4e203b42e Omit needless `if (RND_ENABLED(...))' in rnd_skew_get. 2016-02-28 20:37:16 +00:00
riastradh
e166aa2176 Omit needless `if (RND_ENABLED(...))' in rnd_cpu_get. 2016-02-28 20:36:08 +00:00
riastradh
ca8d0e731f Use __arraycount(x), not howmany(sizeof(x), sizeof(*x)). 2016-02-28 20:24:23 +00:00
riastradh
83300bbb9e Skip disabled sources in rnd_getmore. 2016-02-28 20:20:17 +00:00
mlelstv
2daae857dd Don't use CPU_RNG for rump kernels. So far there is no rump infrastructure
for this.
2016-02-27 14:30:33 +00:00
tls
1b1730d0f9 Add cpu_rng, a framework for simple on-CPU random number generators. 2016-02-27 00:09:44 +00:00
riastradh
446ef7b7a7 Don't schedule a softint if we have nothing to do.
Some systems seem to have gotten stuck in a softint processing loop
doing nothing and then trying to do it again.  Might fix gson's
frozen qemu/anita sparc autobuilds -- tested on macallan's real sparc
hardware and confirmed to fix at least some freeze at boot.
2016-02-17 19:44:40 +00:00
riastradh
7e7551b30d Move entropy_count into the scope where it is used.
Omit now-unused definition.

XXX This code probably shouldn't be under DIAGNOSTIC...  It is
significantly more than just an assertion.
2016-02-17 01:23:32 +00:00
riastradh
25f6b3cbaa Use real atomics, not atomics faked with membars, for rnd_printing. 2016-02-17 01:09:49 +00:00
riastradh
4242e92df8 Omit needless call to rnd_getmore in rnd_extract_data.
The only remaining caller -- rnd_extract -- already does it.
2016-02-17 01:01:42 +00:00
riastradh
3d1bee43d3 Omit call to rnd_getmore from rnd_process_events.
There are three cases to consider here:

1. You have on-demand synchronous rndsources, e.g. RDRAND (and you're
willing to use it).  In that case, you'll just use those whenever you
need to extract entropy.  There's no benefit to requesting more from
them when we're entering data into the pool.

2. You have on-demand asynchronous rndsources.  These should continue
trying to feed data to the entropy pool as long as it needs more, so
there's no benefit to requesting more from them when we're entering
data into the pool.

3. You don't have any on-demand rndsources.  Then rnd_getmore does
nothing, so there's no benefit to calling it.

ok tls
2016-02-17 00:57:36 +00:00
riastradh
3945f2f07a Add rnd_add_data_sync for synchronous on-demand rndsource callbacks.
Avoids lock recursion in rndsinks:

rndsink user holds lock
calls rndsink_request
calls rnd_getmore
calls an rndsource callback
calls rnd_add_data
calls rnd_process_events
calls rndsinks_distribute
calls rndsink callback
acquires rndsink user lock.

This can happen only before the rnd_process_events softint is
established, but that's enough to cause a problem and is the main
reason why all our HWRNG drivers are so byzantine (soon to be
fixed!).

ok tls
2016-02-17 00:43:42 +00:00
tls
249ac9a942 memset() -> explicit_memset() for sensitive data. 2016-01-11 14:55:52 +00:00
tls
b8373ab831 Fix callout-skew source so it runs only when needed (remove second callout,
eliminate race).
2016-01-01 16:09:00 +00:00
mlelstv
cc9526659d when querying randomness sources from position 'start' then skip 'start'
entries and not one less.
2015-08-29 10:00:19 +00:00
riastradh
c5389a31f5 KNF (Khange Not Functional) 2015-08-05 16:51:09 +00:00
riastradh
3aafbe4261 Terminate message with newline. 2015-08-05 16:37:27 +00:00
riastradh
b8cae62e30 Mark some variables __read_mostly. 2015-04-21 12:55:57 +00:00
riastradh
b1dc061a01 Xor, not ior, to combine bits of binuptime for rnd_counter. 2015-04-21 12:07:31 +00:00
riastradh
6be68e2895 Release rnd_global.lock while calling an rndsource's callback.
Obviates the need for obnoxious double-lock dances in hardware RNG
drivers.
2015-04-21 03:53:07 +00:00
riastradh
4faebe442f Correction: we do need <sys/atomic.h>, for membar_*.
(Not clear that these membars actually make sense, but that's a
separate issue.)
2015-04-21 03:46:46 +00:00
riastradh
e8cbd445df Nix some more needless includes. 2015-04-21 03:29:27 +00:00
riastradh
a2deb59454 Don't need <sys/atomic.h>. 2015-04-21 03:25:46 +00:00
riastradh
9cfa0037ec Sort includes. 2015-04-21 03:24:07 +00:00
riastradh
ee3e1f931f Omit needless variable. 2015-04-14 14:18:57 +00:00
riastradh
dd73799480 Omit needless rnd_wakeup_readers. 2015-04-14 14:16:34 +00:00
riastradh
8ded945441 Centralize bookkeeping of rnd_initial_entropy.
It is not adjusted everywhere it should be, although the only places
it perhaps formally ought to be are places with questionable entropy
estimates in the first place.
2015-04-14 14:11:51 +00:00
riastradh
15aebae27c Make the softint cookies static. 2015-04-14 13:57:35 +00:00
riastradh
72bd6b4bfa Group initialization of rnd_samples and rnd_global. 2015-04-14 13:26:58 +00:00
riastradh
eaea47613c Gather global pool and sources state into a cacheline-aligned struct. 2015-04-14 13:23:25 +00:00
riastradh
511c5fc9ff Omit unused rndpool_cv. 2015-04-14 13:15:36 +00:00
riastradh
c3178eae02 Make various things now private to kern_rndq.c static. 2015-04-14 13:12:33 +00:00
riastradh
b5cd74a06e Make rnd_getmore acquire rndpool_mtx itself. 2015-04-14 13:08:22 +00:00
riastradh
b86e4b4dba #ifdef RND_VERBOSE printf -> rnd_printf_verbose 2015-04-14 13:05:33 +00:00
riastradh
e75aac8fa3 Move substantive part of rnd_ioctl to kern_rndq.c. 2015-04-14 12:51:30 +00:00
riastradh
2ade1483d8 Omit unused rndsource `anonymous'. 2015-04-14 12:35:44 +00:00
riastradh
a8379f86d8 Remove null pointer dereference in the code that never worked before... 2015-04-14 12:33:53 +00:00
riastradh
81b1249fe7 Eliminate remaining cases of u_int*_t in kern_rndq.c. 2015-04-14 12:28:12 +00:00
riastradh
0ea00109fe Use binuptime, not microtime/nanotime as substitute cycle counter. 2015-04-14 12:25:41 +00:00
riastradh
e745693cd3 Fix comment. 2015-04-14 11:59:40 +00:00
riastradh
5c5f06b858 More rnd.h user cleanup. 2015-04-13 22:43:41 +00:00
riastradh
cff1e35637 Little rnd.h cleanup.
- Make rnd_printing static in kern_rndq.c.
- Merge some #ifdef _KERNEL blocks.
- Fix comments about RND_DEV_(U)RANDOM.
- Move rnd_ready to rnd_private.h.
2015-04-13 15:23:00 +00:00
riastradh
6f03865532 Gather rnd-private declarations into <dev/rnd_private.h>.
Let's try to avoid putting externs in .c files where the compiler
can't check them.
2015-04-13 15:13:50 +00:00
riastradh
2a2eccb11d Move rndpool_(maybe_)extract to rndq, rename to rnd_(try)extract.
Make rnd_extract_data static.
2015-04-13 14:41:06 +00:00
riastradh
951f0df7f9 Fix a bit of indentation. 2015-04-08 14:13:55 +00:00
riastradh
2ed5dc64df Remove unnecessary, and actively wrong and harmful, locking.
Obviously this `enable callback' never actually worked, because it
would deadlock against itself as soon as you try it.
2015-04-08 14:11:21 +00:00
riastradh
127f4dd2aa Don't do broken lazy initialization. Just do it up front. 2015-04-08 14:08:49 +00:00
riastradh
353a30186d Gather (some) rnd_skew state into a cacheline-aligned static struct. 2015-04-08 14:04:47 +00:00