git: 220841e5279f - stable/12 - random(4): Fix RANDOM_LOADABLE build

From: David E. O'Brien <>
Date: Tue, 22 Feb 2022 07:28:57 UTC
The branch stable/12 has been updated by obrien:


commit 220841e5279fad74fd696b2076520f38d5592d74
Author:     Conrad Meyer <>
AuthorDate: 2019-06-01 01:22:21 +0000
Commit:     David E. O'Brien <>
CommitDate: 2022-02-22 06:20:48 +0000

    random(4): Fix RANDOM_LOADABLE build
    I introduced an obvious compiler error in r346282, so this change fixes
    Unfortunately, RANDOM_LOADABLE isn't covered by our existing tinderbox, and
    it seems like there were existing latent linking problems.  I believe these
    were introduced on accident in r338324 during reduction of the boolean
    expression(s) adjacent to randomdev.c and hash.c.  It seems the
    RANDOM_LOADABLE build breakage has gone unnoticed for nine months.
    This change correctly annotates randomdev.c and hash.c with !random_loadable
    to match the pre-r338324 logic; and additionally updates the HWRNG drivers
    in MD 'files.*', which depend on random_device symbols, with
    !random_loadable (it is invalid for the kernel to depend on symbols from a
    (The expression for both randomdev.c and hash.c was the same, prior to
    r338324: "optional random random_yarrow | random !random_yarrow
    !random_loadable".  I.e., "random && (yarrow || !loadable)."  When Yarrow
    was removed ("yarrow := False"), the expression was incorrectly reduced to
    "optional random" when it should have retained "random && !loadable".)
    Additionally, I discovered that virtio_random was missing a MODULE_DEPEND on
    random_device, which breaks kld load/link of the driver on RANDOM_LOADABLE
    kernels.  Address that issue as well.
    (cherry picked from commit 5ca5dfe938c1e4c741dc4c7bd83c738714456978)
 sys/conf/files                        | 4 ++--
 sys/conf/files.amd64                  | 4 ++--
 sys/conf/files.i386                   | 4 ++--
 sys/conf/files.powerpc                | 2 +-
 sys/dev/random/random_infra.c         | 5 ++++-
 sys/dev/virtio/random/virtio_random.c | 1 +
 6 files changed, 12 insertions(+), 8 deletions(-)

diff --git a/sys/conf/files b/sys/conf/files
index 0b01ac08623e..5ac40e866e8f 100644
--- a/sys/conf/files
+++ b/sys/conf/files
@@ -2881,9 +2881,9 @@ rt2860.fw			optional rt2860fw | ralfw		\
 	clean		"rt2860.fw"
 dev/random/random_infra.c	optional random
 dev/random/random_harvestq.c	optional random
-dev/random/randomdev.c		optional random
+dev/random/randomdev.c		optional random !random_loadable
 dev/random/fortuna.c		optional random !random_loadable
-dev/random/hash.c		optional random
+dev/random/hash.c		optional random !random_loadable
 dev/rc/rc.c			optional rc
 dev/rccgpio/rccgpio.c		optional rccgpio gpio
 dev/re/if_re.c			optional re
diff --git a/sys/conf/files.amd64 b/sys/conf/files.amd64
index 425abcd8b4c7..d1470131b860 100644
--- a/sys/conf/files.amd64
+++ b/sys/conf/files.amd64
@@ -420,8 +420,8 @@ dev/nvme/nvme_sysctl.c		optional	nvme
 dev/nvme/nvme_test.c		optional	nvme
 dev/nvme/nvme_util.c		optional	nvme
 dev/nvram/nvram.c		optional	nvram isa
-dev/random/ivy.c		optional	rdrand_rng
-dev/random/nehemiah.c		optional	padlock_rng
+dev/random/ivy.c		optional	rdrand_rng !random_loadable
+dev/random/nehemiah.c		optional	padlock_rng !random_loadable
 dev/qat/qat.c			optional	qat
 dev/qat/qat_ae.c		optional	qat
 dev/qat/qat_c2xxx.c		optional	qat
diff --git a/sys/conf/files.i386 b/sys/conf/files.i386
index 4bb09402791a..603a9a4dba88 100644
--- a/sys/conf/files.i386
+++ b/sys/conf/files.i386
@@ -311,8 +311,8 @@ dev/nvme/nvme_util.c		optional nvme
 dev/nvram/nvram.c		optional nvram isa
 dev/ofw/ofwpci.c		optional fdt pci
 dev/pcf/pcf_isa.c		optional pcf
-dev/random/ivy.c		optional rdrand_rng
-dev/random/nehemiah.c		optional padlock_rng
+dev/random/ivy.c		optional rdrand_rng !random_loadable
+dev/random/nehemiah.c		optional padlock_rng !random_loadable
 dev/sbni/if_sbni.c		optional sbni
 dev/sbni/if_sbni_isa.c		optional sbni isa
 dev/sbni/if_sbni_pci.c		optional sbni pci
diff --git a/sys/conf/files.powerpc b/sys/conf/files.powerpc
index 90f683f7a890..f9df5e04d04c 100644
--- a/sys/conf/files.powerpc
+++ b/sys/conf/files.powerpc
@@ -101,7 +101,7 @@ dev/ofw/ofw_standard.c		optional	aim powerpc
 dev/ofw/ofw_subr.c		standard
 dev/powermac_nvram/powermac_nvram.c optional	powermac_nvram powermac
 dev/quicc/quicc_bfe_fdt.c	optional	quicc mpc85xx
-dev/random/darn.c		optional	powerpc64 random
+dev/random/darn.c		optional	powerpc64 random !random_loadable
 dev/scc/scc_bfe_macio.c		optional	scc powermac
 dev/sdhci/fsl_sdhci.c		optional	mpc85xx sdhci
 dev/sec/sec.c			optional	sec mpc85xx
diff --git a/sys/dev/random/random_infra.c b/sys/dev/random/random_infra.c
index 19973ac4b46d..a6090b54c454 100644
--- a/sys/dev/random/random_infra.c
+++ b/sys/dev/random/random_infra.c
@@ -196,9 +196,12 @@ read_random(void *buf, u_int len)
+	bool result;
-	random_reader_context.is_random_seeded();
+	result = random_reader_context.is_random_seeded();
+	return (result);
diff --git a/sys/dev/virtio/random/virtio_random.c b/sys/dev/virtio/random/virtio_random.c
index 15311b9e6fbc..e78bf74f17c2 100644
--- a/sys/dev/virtio/random/virtio_random.c
+++ b/sys/dev/virtio/random/virtio_random.c
@@ -89,6 +89,7 @@ DRIVER_MODULE(virtio_random, virtio_pci, vtrnd_driver, vtrnd_devclass,
     vtrnd_modevent, 0);
 MODULE_VERSION(virtio_random, 1);
 MODULE_DEPEND(virtio_random, virtio, 1, 1, 1);
+MODULE_DEPEND(virtio_random, random_device, 1, 1, 1);
 static int
 vtrnd_modevent(module_t mod, int type, void *unused)