| @@ -1,14 +1,14 @@ | | | @@ -1,14 +1,14 @@ |
1 | /* $NetBSD: kern_rndq.c,v 1.62 2015/04/14 14:16:34 riastradh Exp $ */ | | 1 | /* $NetBSD: kern_rndq.c,v 1.63 2015/04/14 14:18:57 riastradh Exp $ */ |
2 | | | 2 | |
3 | /*- | | 3 | /*- |
4 | * Copyright (c) 1997-2013 The NetBSD Foundation, Inc. | | 4 | * Copyright (c) 1997-2013 The NetBSD Foundation, Inc. |
5 | * All rights reserved. | | 5 | * All rights reserved. |
6 | * | | 6 | * |
7 | * This code is derived from software contributed to The NetBSD Foundation | | 7 | * This code is derived from software contributed to The NetBSD Foundation |
8 | * by Michael Graff <explorer@flame.org> and Thor Lancelot Simon. | | 8 | * by Michael Graff <explorer@flame.org> and Thor Lancelot Simon. |
9 | * This code uses ideas and algorithms from the Linux driver written by | | 9 | * This code uses ideas and algorithms from the Linux driver written by |
10 | * Ted Ts'o. | | 10 | * Ted Ts'o. |
11 | * | | 11 | * |
12 | * Redistribution and use in source and binary forms, with or without | | 12 | * Redistribution and use in source and binary forms, with or without |
13 | * modification, are permitted provided that the following conditions | | 13 | * modification, are permitted provided that the following conditions |
14 | * are met: | | 14 | * are met: |
| @@ -22,27 +22,27 @@ | | | @@ -22,27 +22,27 @@ |
22 | * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED | | 22 | * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED |
23 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | | 23 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
24 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS | | 24 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS |
25 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | | 25 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
26 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | | 26 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
27 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | | 27 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
28 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | | 28 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
29 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | | 29 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
30 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | | 30 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
31 | * POSSIBILITY OF SUCH DAMAGE. | | 31 | * POSSIBILITY OF SUCH DAMAGE. |
32 | */ | | 32 | */ |
33 | | | 33 | |
34 | #include <sys/cdefs.h> | | 34 | #include <sys/cdefs.h> |
35 | __KERNEL_RCSID(0, "$NetBSD: kern_rndq.c,v 1.62 2015/04/14 14:16:34 riastradh Exp $"); | | 35 | __KERNEL_RCSID(0, "$NetBSD: kern_rndq.c,v 1.63 2015/04/14 14:18:57 riastradh Exp $"); |
36 | | | 36 | |
37 | #include <sys/param.h> | | 37 | #include <sys/param.h> |
38 | #include <sys/atomic.h> | | 38 | #include <sys/atomic.h> |
39 | #include <sys/ioctl.h> | | 39 | #include <sys/ioctl.h> |
40 | #include <sys/fcntl.h> | | 40 | #include <sys/fcntl.h> |
41 | #include <sys/select.h> | | 41 | #include <sys/select.h> |
42 | #include <sys/poll.h> | | 42 | #include <sys/poll.h> |
43 | #include <sys/kmem.h> | | 43 | #include <sys/kmem.h> |
44 | #include <sys/mutex.h> | | 44 | #include <sys/mutex.h> |
45 | #include <sys/proc.h> | | 45 | #include <sys/proc.h> |
46 | #include <sys/kernel.h> | | 46 | #include <sys/kernel.h> |
47 | #include <sys/conf.h> | | 47 | #include <sys/conf.h> |
48 | #include <sys/systm.h> | | 48 | #include <sys/systm.h> |
| @@ -984,36 +984,35 @@ rnd_hwrng_test(rnd_sample_t *sample) | | | @@ -984,36 +984,35 @@ rnd_hwrng_test(rnd_sample_t *sample) |
984 | * Process the events in the ring buffer. Called by rnd_timeout or | | 984 | * Process the events in the ring buffer. Called by rnd_timeout or |
985 | * by the add routines directly if the callout has never fired (that | | 985 | * by the add routines directly if the callout has never fired (that |
986 | * is, if we are "cold" -- just booted). | | 986 | * is, if we are "cold" -- just booted). |
987 | * | | 987 | * |
988 | */ | | 988 | */ |
989 | static void | | 989 | static void |
990 | rnd_process_events(void) | | 990 | rnd_process_events(void) |
991 | { | | 991 | { |
992 | rnd_sample_t *sample = NULL; | | 992 | rnd_sample_t *sample = NULL; |
993 | krndsource_t *source; | | 993 | krndsource_t *source; |
994 | static krndsource_t *last_source; | | 994 | static krndsource_t *last_source; |
995 | uint32_t entropy; | | 995 | uint32_t entropy; |
996 | size_t pool_entropy; | | 996 | size_t pool_entropy; |
997 | int found = 0, wake = 0; | | 997 | int wake = 0; |
998 | struct rnd_sampleq dq_samples = SIMPLEQ_HEAD_INITIALIZER(dq_samples); | | 998 | struct rnd_sampleq dq_samples = SIMPLEQ_HEAD_INITIALIZER(dq_samples); |
999 | struct rnd_sampleq df_samples = SIMPLEQ_HEAD_INITIALIZER(df_samples); | | 999 | struct rnd_sampleq df_samples = SIMPLEQ_HEAD_INITIALIZER(df_samples); |
1000 | | | 1000 | |
1001 | /* | | 1001 | /* |
1002 | * Drain to the on-stack queue and drop the lock. | | 1002 | * Drain to the on-stack queue and drop the lock. |
1003 | */ | | 1003 | */ |
1004 | mutex_spin_enter(&rnd_samples.lock); | | 1004 | mutex_spin_enter(&rnd_samples.lock); |
1005 | while ((sample = SIMPLEQ_FIRST(&rnd_samples.q))) { | | 1005 | while ((sample = SIMPLEQ_FIRST(&rnd_samples.q))) { |
1006 | found++; | | | |
1007 | SIMPLEQ_REMOVE_HEAD(&rnd_samples.q, next); | | 1006 | SIMPLEQ_REMOVE_HEAD(&rnd_samples.q, next); |
1008 | /* | | 1007 | /* |
1009 | * We repeat this check here, since it is possible | | 1008 | * We repeat this check here, since it is possible |
1010 | * the source was disabled before we were called, but | | 1009 | * the source was disabled before we were called, but |
1011 | * after the entry was queued. | | 1010 | * after the entry was queued. |
1012 | */ | | 1011 | */ |
1013 | if (__predict_false(!(sample->source->flags & | | 1012 | if (__predict_false(!(sample->source->flags & |
1014 | (RND_FLAG_COLLECT_TIME| | | 1013 | (RND_FLAG_COLLECT_TIME| |
1015 | RND_FLAG_COLLECT_VALUE)))) { | | 1014 | RND_FLAG_COLLECT_VALUE)))) { |
1016 | SIMPLEQ_INSERT_TAIL(&df_samples, sample, next); | | 1015 | SIMPLEQ_INSERT_TAIL(&df_samples, sample, next); |
1017 | } else { | | 1016 | } else { |
1018 | SIMPLEQ_INSERT_TAIL(&dq_samples, sample, next); | | 1017 | SIMPLEQ_INSERT_TAIL(&dq_samples, sample, next); |
1019 | } | | 1018 | } |