Source-Changes-HG archive

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

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



details:   https://anonhg.NetBSD.org/src-all/rev/1cce10dff9cf
branches:  trunk
changeset: 932579:1cce10dff9cf
user:      Taylor R Campbell <riastradh%NetBSD.org@localhost>
date:      Mon May 11 19:28:52 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  |  4 ++--
 sys/kern/subr_cprng.c |  7 +++++--
 2 files changed, 7 insertions(+), 4 deletions(-)

diffs (47 lines):

diff -r f96050b5dc22 -r 1cce10dff9cf sys/kern/init_main.c
--- a/sys/kern/init_main.c      Mon May 11 18:01:19 2020 +0000
+++ b/sys/kern/init_main.c      Mon May 11 19:28:52 2020 +0000
@@ -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 f96050b5dc22 -r 1cce10dff9cf sys/kern/subr_cprng.c
--- a/sys/kern/subr_cprng.c     Mon May 11 18:01:19 2020 +0000
+++ b/sys/kern/subr_cprng.c     Mon May 11 19:28:52 2020 +0000
@@ -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