Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys Attempt to resolve locking issues at kernel startup on p...



details:   https://anonhg.NetBSD.org/src/rev/1957eb7d278f
branches:  trunk
changeset: 789603:1957eb7d278f
user:      tls <tls%NetBSD.org@localhost>
date:      Sun Aug 25 21:12:56 2013 +0000

description:
Attempt to resolve locking issues at kernel startup on platforms with
hardware RNGs using the polling mode of operation:

1) Initialize the rng subsystem soft interrupts as early in kernel startup
   as seems safe (we have no MI guarantee that softints are working at all
   until configure2() returns, AFAICT).

   This should have the rnd subsystem able to process events via softint
   before the network subsystem (a notorious early user of entropy) starts.

2) Remove the shortcut calls to rnd_process_events() from
   rnd_schedule_process(), with the result that until the softint is installed
   rnd_process_events() is a NOP.

3) Directly call rnd_process_events() in rnd_extract_data(),
   rnd_maybe_extract(), and rnd_init_softint().  This should suck up any
   samples actually collected as early as possible.

diffstat:

 sys/dev/rnd_private.h   |   4 +++-
 sys/kern/init_main.c    |   9 +++++----
 sys/kern/kern_rndq.c    |  20 +++++++++-----------
 sys/kern/kern_rndsink.c |   6 ++++--
 4 files changed, 21 insertions(+), 18 deletions(-)

diffs (156 lines):

diff -r 3d2eeca7ba04 -r 1957eb7d278f sys/dev/rnd_private.h
--- a/sys/dev/rnd_private.h     Sun Aug 25 17:08:41 2013 +0000
+++ b/sys/dev/rnd_private.h     Sun Aug 25 21:12:56 2013 +0000
@@ -1,4 +1,4 @@
-/*      $NetBSD: rnd_private.h,v 1.1 2011/11/29 03:50:31 tls Exp $     */
+/*      $NetBSD: rnd_private.h,v 1.2 2013/08/25 21:12:56 tls Exp $     */
 
 /*-
  * Copyright (c) 1997 The NetBSD Foundation, Inc.
@@ -55,4 +55,6 @@
                                      (short read ok) */
 
 uint32_t        rnd_extract_data(void *, uint32_t, uint32_t);
+void           rnd_process_events(void);       /* XXX should be static */
+
 #endif
diff -r 3d2eeca7ba04 -r 1957eb7d278f sys/kern/init_main.c
--- a/sys/kern/init_main.c      Sun Aug 25 17:08:41 2013 +0000
+++ b/sys/kern/init_main.c      Sun Aug 25 21:12:56 2013 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: init_main.c,v 1.450 2013/06/20 23:21:41 christos Exp $ */
+/*     $NetBSD: init_main.c,v 1.451 2013/08/25 21:12:56 tls Exp $      */
 
 /*-
  * Copyright (c) 2008, 2009 The NetBSD Foundation, Inc.
@@ -97,7 +97,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: init_main.c,v 1.450 2013/06/20 23:21:41 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: init_main.c,v 1.451 2013/08/25 21:12:56 tls Exp $");
 
 #include "opt_ddb.h"
 #include "opt_ipsec.h"
@@ -519,6 +519,9 @@
        /* Now timer is working.  Enable preemption. */
        kpreempt_enable();
 
+       /* Enable deferred processing of RNG samples */
+       rnd_init_softint();
+
 #ifdef SYSVSHM
        /* Initialize System V style shared memory. */
        shminit();
@@ -565,8 +568,6 @@
        if_attachdomain();
        splx(s);
 
-       rnd_init_softint();
-
 #ifdef GPROF
        /* Initialize kernel profiling. */
        kmstartup();
diff -r 3d2eeca7ba04 -r 1957eb7d278f sys/kern/kern_rndq.c
--- a/sys/kern/kern_rndq.c      Sun Aug 25 17:08:41 2013 +0000
+++ b/sys/kern/kern_rndq.c      Sun Aug 25 21:12:56 2013 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: kern_rndq.c,v 1.14 2013/06/23 02:35:24 riastradh Exp $ */
+/*     $NetBSD: kern_rndq.c,v 1.15 2013/08/25 21:12:56 tls Exp $       */
 
 /*-
  * Copyright (c) 1997-2013 The NetBSD Foundation, Inc.
@@ -32,7 +32,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: kern_rndq.c,v 1.14 2013/06/23 02:35:24 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_rndq.c,v 1.15 2013/08/25 21:12:56 tls Exp $");
 
 #include <sys/param.h>
 #include <sys/ioctl.h>
@@ -146,7 +146,6 @@
 static inline u_int32_t rnd_counter(void);
 static        void     rnd_intr(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 */
 static       void      rnd_add_data_ts(krndsource_t *, const void *const,
                                        uint32_t, uint32_t, uint32_t);
@@ -167,7 +166,10 @@
 void
 rnd_init_softint(void) {
        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_process_events();
 }
 
 /*
@@ -210,7 +212,6 @@
                rnd_schedule_softint(rnd_process);
                return;
        } 
-       rnd_process_events();
 }
 
 static inline void
@@ -220,11 +221,6 @@
                rnd_schedule_softint(rnd_wakeup);
                return;
        }
-       if (!cold) {
-               rnd_wakeup = softint_establish(SOFTINT_CLOCK|SOFTINT_MPSAFE,
-                                              rnd_wake, NULL);
-       }
-       rnd_wakeup_readers();
 }
 
 /*
@@ -821,7 +817,7 @@
  * is, if we are "cold" -- just booted).
  *
  */
-static void
+void
 rnd_process_events(void)
 {
        rnd_sample_t *sample = NULL;
@@ -1037,6 +1033,8 @@
 {
        uint32_t retval;
 
+       rnd_process_events();   /* XXX extra take/release rndpool_mtx */
+
        mutex_spin_enter(&rndpool_mtx);
        retval = rnd_extract_data_locked(p, len, flags);
        mutex_spin_exit(&rndpool_mtx);
diff -r 3d2eeca7ba04 -r 1957eb7d278f sys/kern/kern_rndsink.c
--- a/sys/kern/kern_rndsink.c   Sun Aug 25 17:08:41 2013 +0000
+++ b/sys/kern/kern_rndsink.c   Sun Aug 25 21:12:56 2013 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: kern_rndsink.c,v 1.2 2013/06/24 04:21:20 riastradh Exp $       */
+/*     $NetBSD: kern_rndsink.c,v 1.3 2013/08/25 21:12:56 tls Exp $     */
 
 /*-
  * Copyright (c) 2013 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: kern_rndsink.c,v 1.2 2013/06/24 04:21:20 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_rndsink.c,v 1.3 2013/08/25 21:12:56 tls Exp $");
 
 #include <sys/param.h>
 #include <sys/types.h>
@@ -131,6 +131,8 @@
 
        const uint32_t bits_needed = ((bytes + RND_ENTROPY_THRESHOLD) * NBBY);
 
+       rnd_process_events();   /* XXX extra take/release rndpool_mtx */
+
        mutex_spin_enter(&rndpool_mtx);
        if (bits_needed <= rndpool_get_entropy_count(&rnd_pool)) {
                const uint32_t extracted __unused =



Home | Main Index | Thread Index | Old Index