Date: Tue, 15 Feb 2022 02:09:28 GMT From: "David E. O'Brien" <obrien@FreeBSD.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org Subject: git: e6e5f6a7dd80 - stable/12 - random(4): Reorder configuration of random source modules Message-ID: <202202150209.21F29SiX046660@gitrepo.freebsd.org>
next in thread | raw e-mail | index | archive | help
The branch stable/12 has been updated by obrien: URL: https://cgit.FreeBSD.org/src/commit/?id=e6e5f6a7dd807e1e703e2a3eee3983701bea283f commit e6e5f6a7dd807e1e703e2a3eee3983701bea283f Author: Conrad Meyer <cem@FreeBSD.org> AuthorDate: 2019-08-18 16:04:01 +0000 Commit: David E. O'Brien <obrien@FreeBSD.org> CommitDate: 2022-02-15 02:09:08 +0000 random(4): Reorder configuration of random source modules Move fast entropy source registration to the earlier SI_SUB_RANDOM:SI_ORDER_FOURTH and move random_harvestq_prime after that. Relocate the registration routines out of the much later randomdev module and into random_harvestq. This is necessary for the fast random sources to actually register before we perform random_harvestq_prime() early in the kernel boot. No functional change. (cherry picked from commit 7384206a943be8d6b83e52bf5bfa5fca07e949f5) --- sys/dev/random/darn.c | 10 +++++-- sys/dev/random/ivy.c | 10 +++++-- sys/dev/random/nehemiah.c | 10 +++++-- sys/dev/random/random_harvestq.c | 58 +++++++++++++++++++++++++++++++++++++++- sys/dev/random/randomdev.c | 56 -------------------------------------- 5 files changed, 81 insertions(+), 63 deletions(-) diff --git a/sys/dev/random/darn.c b/sys/dev/random/darn.c index e42a4287a532..a9b0a84c7edd 100644 --- a/sys/dev/random/darn.c +++ b/sys/dev/random/darn.c @@ -137,6 +137,12 @@ darn_modevent(module_t mod, int type, void *unused) return (error); } -DEV_MODULE(darn, darn_modevent, NULL); +static moduledata_t darn_mod = { + "darn", + darn_modevent, + 0 +}; + +DECLARE_MODULE(darn, darn_mod, SI_SUB_RANDOM, SI_ORDER_FOURTH); MODULE_VERSION(darn, 1); -MODULE_DEPEND(darn, random_device, 1, 1, 1); +MODULE_DEPEND(darn, random_harvestq, 1, 1, 1); diff --git a/sys/dev/random/ivy.c b/sys/dev/random/ivy.c index 7ab2b0356094..7431f56f0f69 100644 --- a/sys/dev/random/ivy.c +++ b/sys/dev/random/ivy.c @@ -127,6 +127,12 @@ rdrand_modevent(module_t mod, int type, void *unused) return (error); } -DEV_MODULE(rdrand, rdrand_modevent, NULL); +static moduledata_t rdrand_mod = { + "rdrand", + rdrand_modevent, + 0 +}; + +DECLARE_MODULE(rdrand, rdrand_mod, SI_SUB_RANDOM, SI_ORDER_FOURTH); MODULE_VERSION(rdrand, 1); -MODULE_DEPEND(rdrand, random_device, 1, 1, 1); +MODULE_DEPEND(rdrand, random_harvestq, 1, 1, 1); diff --git a/sys/dev/random/nehemiah.c b/sys/dev/random/nehemiah.c index 6666eca2930e..3ad18005c935 100644 --- a/sys/dev/random/nehemiah.c +++ b/sys/dev/random/nehemiah.c @@ -146,6 +146,12 @@ nehemiah_modevent(module_t mod, int type, void *unused) return (error); } -DEV_MODULE(nehemiah, nehemiah_modevent, NULL); +static moduledata_t nehemiah_mod = { + "nehemiah", + nehemiah_modevent, + 0 +}; + +DECLARE_MODULE(nehemiah, nehemiah_mod, SI_SUB_RANDOM, SI_ORDER_FOURTH); MODULE_VERSION(nehemiah, 1); -MODULE_DEPEND(nehemiah, random_device, 1, 1, 1); +MODULE_DEPEND(nehemiah, random_harvestq, 1, 1, 1); diff --git a/sys/dev/random/random_harvestq.c b/sys/dev/random/random_harvestq.c index d681204832a5..598e2cfdc1f9 100644 --- a/sys/dev/random/random_harvestq.c +++ b/sys/dev/random/random_harvestq.c @@ -424,7 +424,7 @@ random_harvestq_prime(void *unused __unused) printf("random: no preloaded entropy cache\n"); } } -SYSINIT(random_device_prime, SI_SUB_RANDOM, SI_ORDER_FOURTH, random_harvestq_prime, NULL); +SYSINIT(random_device_prime, SI_SUB_RANDOM, SI_ORDER_MIDDLE, random_harvestq_prime, NULL); /* ARGSUSED */ static void @@ -533,4 +533,60 @@ random_harvest_deregister_source(enum random_entropy_source source) hc_source_mask &= ~(1 << source); } +void +random_source_register(struct random_source *rsource) +{ + struct random_sources *rrs; + + KASSERT(rsource != NULL, ("invalid input to %s", __func__)); + + rrs = malloc(sizeof(*rrs), M_ENTROPY, M_WAITOK); + rrs->rrs_source = rsource; + + random_harvest_register_source(rsource->rs_source); + + printf("random: registering fast source %s\n", rsource->rs_ident); + LIST_INSERT_HEAD(&source_list, rrs, rrs_entries); +} + +void +random_source_deregister(struct random_source *rsource) +{ + struct random_sources *rrs = NULL; + + KASSERT(rsource != NULL, ("invalid input to %s", __func__)); + + random_harvest_deregister_source(rsource->rs_source); + + LIST_FOREACH(rrs, &source_list, rrs_entries) + if (rrs->rrs_source == rsource) { + LIST_REMOVE(rrs, rrs_entries); + break; + } + if (rrs != NULL) + free(rrs, M_ENTROPY); +} + +static int +random_source_handler(SYSCTL_HANDLER_ARGS) +{ + struct random_sources *rrs; + struct sbuf sbuf; + int error, count; + + sbuf_new_for_sysctl(&sbuf, NULL, 64, req); + count = 0; + LIST_FOREACH(rrs, &source_list, rrs_entries) { + sbuf_cat(&sbuf, (count++ ? ",'" : "'")); + sbuf_cat(&sbuf, rrs->rrs_source->rs_ident); + sbuf_cat(&sbuf, "'"); + } + error = sbuf_finish(&sbuf); + sbuf_delete(&sbuf); + return (error); +} +SYSCTL_PROC(_kern_random, OID_AUTO, random_sources, CTLTYPE_STRING | CTLFLAG_RD | CTLFLAG_MPSAFE, + NULL, 0, random_source_handler, "A", + "List of active fast entropy sources."); + MODULE_VERSION(random_harvestq, 1); diff --git a/sys/dev/random/randomdev.c b/sys/dev/random/randomdev.c index 8af39deeb34b..f1ed80cc02f1 100644 --- a/sys/dev/random/randomdev.c +++ b/sys/dev/random/randomdev.c @@ -410,62 +410,6 @@ randomdev_ioctl(struct cdev *dev __unused, u_long cmd, caddr_t addr __unused, return (error); } -void -random_source_register(struct random_source *rsource) -{ - struct random_sources *rrs; - - KASSERT(rsource != NULL, ("invalid input to %s", __func__)); - - rrs = malloc(sizeof(*rrs), M_ENTROPY, M_WAITOK); - rrs->rrs_source = rsource; - - random_harvest_register_source(rsource->rs_source); - - printf("random: registering fast source %s\n", rsource->rs_ident); - LIST_INSERT_HEAD(&source_list, rrs, rrs_entries); -} - -void -random_source_deregister(struct random_source *rsource) -{ - struct random_sources *rrs = NULL; - - KASSERT(rsource != NULL, ("invalid input to %s", __func__)); - - random_harvest_deregister_source(rsource->rs_source); - - LIST_FOREACH(rrs, &source_list, rrs_entries) - if (rrs->rrs_source == rsource) { - LIST_REMOVE(rrs, rrs_entries); - break; - } - if (rrs != NULL) - free(rrs, M_ENTROPY); -} - -static int -random_source_handler(SYSCTL_HANDLER_ARGS) -{ - struct random_sources *rrs; - struct sbuf sbuf; - int error, count; - - sbuf_new_for_sysctl(&sbuf, NULL, 64, req); - count = 0; - LIST_FOREACH(rrs, &source_list, rrs_entries) { - sbuf_cat(&sbuf, (count++ ? ",'" : "'")); - sbuf_cat(&sbuf, rrs->rrs_source->rs_ident); - sbuf_cat(&sbuf, "'"); - } - error = sbuf_finish(&sbuf); - sbuf_delete(&sbuf); - return (error); -} -SYSCTL_PROC(_kern_random, OID_AUTO, random_sources, CTLTYPE_STRING | CTLFLAG_RD | CTLFLAG_MPSAFE, - NULL, 0, random_source_handler, "A", - "List of active fast entropy sources."); - /* ARGSUSED */ static int randomdev_modevent(module_t mod __unused, int type, void *data __unused)
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202202150209.21F29SiX046660>