svn commit: r351191 - head/sys/dev/random

Conrad Meyer cem at FreeBSD.org
Sun Aug 18 16:04:03 UTC 2019


Author: cem
Date: Sun Aug 18 16:04:01 2019
New Revision: 351191
URL: https://svnweb.freebsd.org/changeset/base/351191

Log:
  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.
  
  Reviewed by:	delphij, markjm
  Approved by:	secteam(delphij)
  Differential Revision:	https://reviews.freebsd.org/D21308

Modified:
  head/sys/dev/random/darn.c
  head/sys/dev/random/ivy.c
  head/sys/dev/random/nehemiah.c
  head/sys/dev/random/random_harvestq.c
  head/sys/dev/random/randomdev.c

Modified: head/sys/dev/random/darn.c
==============================================================================
--- head/sys/dev/random/darn.c	Sun Aug 18 15:58:44 2019	(r351190)
+++ head/sys/dev/random/darn.c	Sun Aug 18 16:04:01 2019	(r351191)
@@ -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);

Modified: head/sys/dev/random/ivy.c
==============================================================================
--- head/sys/dev/random/ivy.c	Sun Aug 18 15:58:44 2019	(r351190)
+++ head/sys/dev/random/ivy.c	Sun Aug 18 16:04:01 2019	(r351191)
@@ -164,6 +164,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);

Modified: head/sys/dev/random/nehemiah.c
==============================================================================
--- head/sys/dev/random/nehemiah.c	Sun Aug 18 15:58:44 2019	(r351190)
+++ head/sys/dev/random/nehemiah.c	Sun Aug 18 16:04:01 2019	(r351191)
@@ -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);

Modified: head/sys/dev/random/random_harvestq.c
==============================================================================
--- head/sys/dev/random/random_harvestq.c	Sun Aug 18 15:58:44 2019	(r351190)
+++ head/sys/dev/random/random_harvestq.c	Sun Aug 18 16:04:01 2019	(r351191)
@@ -447,7 +447,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
@@ -555,5 +555,61 @@ random_harvest_deregister_source(enum random_entropy_s
 
 	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);

Modified: head/sys/dev/random/randomdev.c
==============================================================================
--- head/sys/dev/random/randomdev.c	Sun Aug 18 15:58:44 2019	(r351190)
+++ head/sys/dev/random/randomdev.c	Sun Aug 18 16:04:01 2019	(r351191)
@@ -410,62 +410,6 @@ randomdev_ioctl(struct cdev *dev __unused, u_long cmd,
 	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)


More information about the svn-src-all mailing list