Source-Changes-HG archive

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

[src/trunk]: src/sys/kern Move cprng_init before configure.



details:   https://anonhg.NetBSD.org/src/rev/7cddf9d3105e
branches:  trunk
changeset: 971986:7cddf9d3105e
user:      riastradh <riastradh%NetBSD.org@localhost>
date:      Mon May 11 21:38:54 2020 +0000

description:
Move cprng_init before configure.

This makes it available to device drivers, e.g. to generate MAC
addresses at random, without initialization order hacks.

Requires a minor initialization hack for cpu_name(primary cpu) early
on, since that doesn't get set until mi_cpu_attach which may not run
until the middle of configure.  But this hack is less bad than other
initialization order hacks.

diffstat:

 sys/kern/init_main.c  |   8 ++++----
 sys/kern/subr_cprng.c |  11 +++++++----
 2 files changed, 11 insertions(+), 8 deletions(-)

diffs (77 lines):

diff -r 723e084479ae -r 7cddf9d3105e sys/kern/init_main.c
--- a/sys/kern/init_main.c      Mon May 11 21:37:31 2020 +0000
+++ b/sys/kern/init_main.c      Mon May 11 21:38:54 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: init_main.c,v 1.524 2020/04/30 03:28:18 riastradh Exp $        */
+/*     $NetBSD: init_main.c,v 1.525 2020/05/11 21:38:54 riastradh Exp $        */
 
 /*-
  * Copyright (c) 2008, 2009, 2019 The NetBSD Foundation, Inc.
@@ -97,7 +97,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: init_main.c,v 1.524 2020/04/30 03:28:18 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: init_main.c,v 1.525 2020/05/11 21:38:54 riastradh Exp $");
 
 #include "opt_ddb.h"
 #include "opt_inet.h"
@@ -395,6 +395,8 @@
         */
        rnd_init();             /* initialize entropy pool */
 
+       cprng_init();           /* initialize cryptographic PRNG */
+
        /* Initialize process and pgrp structures. */
        procinit();
        lwpinit();
@@ -529,8 +531,6 @@
        /* Configure the system hardware.  This will enable interrupts. */
        configure();
 
-       cprng_init();           /* initialize cryptographic PRNG */
-
        /* Once all CPUs are detected, initialize the per-CPU cprng_fast.  */
        cprng_fast_init();
 
diff -r 723e084479ae -r 7cddf9d3105e sys/kern/subr_cprng.c
--- a/sys/kern/subr_cprng.c     Mon May 11 21:37:31 2020 +0000
+++ b/sys/kern/subr_cprng.c     Mon May 11 21:38:54 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: subr_cprng.c,v 1.38 2020/05/11 17:27:48 riastradh Exp $        */
+/*     $NetBSD: subr_cprng.c,v 1.39 2020/05/11 21:38:54 riastradh Exp $        */
 
 /*-
  * Copyright (c) 2019 The NetBSD Foundation, Inc.
@@ -52,7 +52,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: subr_cprng.c,v 1.38 2020/05/11 17:27:48 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: subr_cprng.c,v 1.39 2020/05/11 21:38:54 riastradh Exp $");
 
 #include <sys/types.h>
 #include <sys/cprng.h>
@@ -217,6 +217,7 @@
 {
        struct cprng_cpu *cc = ptr;
        const char *name = cookie;
+       const char *cpuname;
        uint8_t zero[NIST_HASH_DRBG_SEEDLEN_BYTES] = {0};
        char namebuf[64];       /* XXX size? */
 
@@ -246,10 +247,12 @@
                panic("nist_hash_drbg_instantiate");
 
        /* Attach the event counters.  */
+       /* XXX ci_cpuname may not be initialized early enough.  */
+       cpuname = ci->ci_cpuname[0] == '\0' ? "cpu0" : ci->ci_cpuname;
        evcnt_attach_dynamic(&cc->cc_evcnt->intr, EVCNT_TYPE_MISC, NULL,
-           ci->ci_cpuname, "cprng_strong intr");
+           cpuname, "cprng_strong intr");
        evcnt_attach_dynamic(&cc->cc_evcnt->reseed, EVCNT_TYPE_MISC, NULL,
-           ci->ci_cpuname, "cprng_strong reseed");
+           cpuname, "cprng_strong reseed");
 
        /* Set the epoch uninitialized so we reseed on first use.  */
        cc->cc_epoch = 0;



Home | Main Index | Thread Index | Old Index