Back out the recent rnd stop-gap/stop-gap/stop-gap measures.

This reverts

sys/dev/rnd_private.h -> r1.1
sys/kern/init_main.c -> r1.450
sys/kern/kern_rndq.c -> r1.14
sys/kern/kern_rndsink.c -> r1.2

Parts of these changes will be added back, and the rndsource
callbacks will be fixed to avoid the lock recursion bug that
motivated the stop-gaps in the first place.

ok tls
This commit is contained in:
riastradh 2013-08-27 19:30:10 +00:00
parent cc1cb97e40
commit b1574872b8
4 changed files with 27 additions and 34 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: rnd_private.h,v 1.3 2013/08/26 23:41:24 tls Exp $ */ /* $NetBSD: rnd_private.h,v 1.4 2013/08/27 19:30:10 riastradh Exp $ */
/*- /*-
* Copyright (c) 1997 The NetBSD Foundation, Inc. * Copyright (c) 1997 The NetBSD Foundation, Inc.
@ -55,7 +55,4 @@
(short read ok) */ (short read ok) */
uint32_t rnd_extract_data(void *, uint32_t, uint32_t); uint32_t rnd_extract_data(void *, uint32_t, uint32_t);
int rnd_process_events(void); /* XXX should be static */
void rnd_wakeup_readers(void); /* XXX should be static */
#endif #endif

View File

@ -1,4 +1,4 @@
/* $NetBSD: init_main.c,v 1.451 2013/08/25 21:12:56 tls Exp $ */ /* $NetBSD: init_main.c,v 1.452 2013/08/27 19:30:10 riastradh Exp $ */
/*- /*-
* Copyright (c) 2008, 2009 The NetBSD Foundation, Inc. * Copyright (c) 2008, 2009 The NetBSD Foundation, Inc.
@ -97,7 +97,7 @@
*/ */
#include <sys/cdefs.h> #include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: init_main.c,v 1.451 2013/08/25 21:12:56 tls Exp $"); __KERNEL_RCSID(0, "$NetBSD: init_main.c,v 1.452 2013/08/27 19:30:10 riastradh Exp $");
#include "opt_ddb.h" #include "opt_ddb.h"
#include "opt_ipsec.h" #include "opt_ipsec.h"
@ -519,9 +519,6 @@ main(void)
/* Now timer is working. Enable preemption. */ /* Now timer is working. Enable preemption. */
kpreempt_enable(); kpreempt_enable();
/* Enable deferred processing of RNG samples */
rnd_init_softint();
#ifdef SYSVSHM #ifdef SYSVSHM
/* Initialize System V style shared memory. */ /* Initialize System V style shared memory. */
shminit(); shminit();
@ -568,6 +565,8 @@ main(void)
if_attachdomain(); if_attachdomain();
splx(s); splx(s);
rnd_init_softint();
#ifdef GPROF #ifdef GPROF
/* Initialize kernel profiling. */ /* Initialize kernel profiling. */
kmstartup(); kmstartup();

View File

@ -1,4 +1,4 @@
/* $NetBSD: kern_rndq.c,v 1.17 2013/08/27 14:01:35 riastradh Exp $ */ /* $NetBSD: kern_rndq.c,v 1.18 2013/08/27 19:30:10 riastradh Exp $ */
/*- /*-
* Copyright (c) 1997-2013 The NetBSD Foundation, Inc. * Copyright (c) 1997-2013 The NetBSD Foundation, Inc.
@ -32,7 +32,7 @@
*/ */
#include <sys/cdefs.h> #include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: kern_rndq.c,v 1.17 2013/08/27 14:01:35 riastradh Exp $"); __KERNEL_RCSID(0, "$NetBSD: kern_rndq.c,v 1.18 2013/08/27 19:30:10 riastradh Exp $");
#include <sys/param.h> #include <sys/param.h>
#include <sys/ioctl.h> #include <sys/ioctl.h>
@ -141,10 +141,12 @@ static krndsource_t rnd_source_no_collect = {
void *rnd_process, *rnd_wakeup; void *rnd_process, *rnd_wakeup;
struct callout skew_callout; struct callout skew_callout;
void rnd_wakeup_readers(void);
static inline u_int32_t rnd_estimate_entropy(krndsource_t *, u_int32_t); static inline u_int32_t rnd_estimate_entropy(krndsource_t *, u_int32_t);
static inline u_int32_t rnd_counter(void); static inline u_int32_t rnd_counter(void);
static void rnd_intr(void *); static void rnd_intr(void *);
static void rnd_wake(void *); static void rnd_wake(void *);
static void rnd_process_events(void);
u_int32_t rnd_extract_data_locked(void *, u_int32_t, u_int32_t); /* XXX */ u_int32_t rnd_extract_data_locked(void *, u_int32_t, u_int32_t); /* XXX */
static void rnd_add_data_ts(krndsource_t *, const void *const, static void rnd_add_data_ts(krndsource_t *, const void *const,
uint32_t, uint32_t, uint32_t); uint32_t, uint32_t, uint32_t);
@ -165,10 +167,7 @@ rndsave_t *boot_rsp;
void void
rnd_init_softint(void) { rnd_init_softint(void) {
rnd_process = softint_establish(SOFTINT_SERIAL|SOFTINT_MPSAFE, rnd_process = softint_establish(SOFTINT_SERIAL|SOFTINT_MPSAFE,
rnd_intr, NULL); rnd_intr, NULL);
rnd_wakeup = softint_establish(SOFTINT_CLOCK|SOFTINT_MPSAFE,
rnd_wake, NULL);
rnd_intr(NULL);
} }
/* /*
@ -211,6 +210,7 @@ rnd_schedule_process(void)
rnd_schedule_softint(rnd_process); rnd_schedule_softint(rnd_process);
return; return;
} }
rnd_process_events();
} }
static inline void static inline void
@ -220,6 +220,11 @@ rnd_schedule_wakeup(void)
rnd_schedule_softint(rnd_wakeup); rnd_schedule_softint(rnd_wakeup);
return; return;
} }
if (!cold) {
rnd_wakeup = softint_establish(SOFTINT_CLOCK|SOFTINT_MPSAFE,
rnd_wake, NULL);
}
rnd_wakeup_readers();
} }
/* /*
@ -815,10 +820,8 @@ rnd_hwrng_test(rnd_sample_t *sample)
* by the add routines directly if the callout has never fired (that * by the add routines directly if the callout has never fired (that
* is, if we are "cold" -- just booted). * is, if we are "cold" -- just booted).
* *
* Returns >0 if we got enough entropy to distribute some (wake sleepers)
* 0 elsewise.
*/ */
int static void
rnd_process_events(void) rnd_process_events(void)
{ {
rnd_sample_t *sample = NULL; rnd_sample_t *sample = NULL;
@ -932,15 +935,19 @@ rnd_process_events(void)
rnd_sample_free(sample); rnd_sample_free(sample);
} }
return wake;
/*
* Wake up any potential readers waiting.
*/
if (wake) {
rnd_schedule_wakeup();
}
} }
static void static void
rnd_intr(void *arg) rnd_intr(void *arg)
{ {
if (rnd_process_events()) { rnd_process_events();
rnd_schedule_wakeup();
}
} }
static void static void
@ -1028,19 +1035,11 @@ rnd_extract_data_locked(void *p, u_int32_t len, u_int32_t flags)
u_int32_t u_int32_t
rnd_extract_data(void *p, u_int32_t len, u_int32_t flags) rnd_extract_data(void *p, u_int32_t len, u_int32_t flags)
{ {
int wake;
uint32_t retval; uint32_t retval;
wake = rnd_process_events(); /* XXX extra take/release rndpool_mtx */
mutex_spin_enter(&rndpool_mtx); mutex_spin_enter(&rndpool_mtx);
retval = rnd_extract_data_locked(p, len, flags); retval = rnd_extract_data_locked(p, len, flags);
mutex_spin_exit(&rndpool_mtx); mutex_spin_exit(&rndpool_mtx);
if (wake) {
rnd_schedule_wakeup();
}
return retval; return retval;
} }

View File

@ -1,4 +1,4 @@
/* $NetBSD: kern_rndsink.c,v 1.4 2013/08/26 23:41:24 tls Exp $ */ /* $NetBSD: kern_rndsink.c,v 1.5 2013/08/27 19:30:10 riastradh Exp $ */
/*- /*-
* Copyright (c) 2013 The NetBSD Foundation, Inc. * Copyright (c) 2013 The NetBSD Foundation, Inc.
@ -30,7 +30,7 @@
*/ */
#include <sys/cdefs.h> #include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: kern_rndsink.c,v 1.4 2013/08/26 23:41:24 tls Exp $"); __KERNEL_RCSID(0, "$NetBSD: kern_rndsink.c,v 1.5 2013/08/27 19:30:10 riastradh Exp $");
#include <sys/param.h> #include <sys/param.h>
#include <sys/types.h> #include <sys/types.h>
@ -131,8 +131,6 @@ rndpool_maybe_extract(void *buffer, size_t bytes)
const uint32_t bits_needed = ((bytes + RND_ENTROPY_THRESHOLD) * NBBY); const uint32_t bits_needed = ((bytes + RND_ENTROPY_THRESHOLD) * NBBY);
(void)rnd_process_events(); /* XXX extra take/release rndpool_mtx */
mutex_spin_enter(&rndpool_mtx); mutex_spin_enter(&rndpool_mtx);
if (bits_needed <= rndpool_get_entropy_count(&rnd_pool)) { if (bits_needed <= rndpool_get_entropy_count(&rnd_pool)) {
const uint32_t extracted __unused = const uint32_t extracted __unused =