diff --git a/sys/dev/random/random_harvestq.c b/sys/dev/random/random_harvestq.c --- a/sys/dev/random/random_harvestq.c +++ b/sys/dev/random/random_harvestq.c @@ -278,8 +278,15 @@ epoch_enter_preempt(rs_epoch, &et); CK_LIST_FOREACH(rrs, &source_list, rrs_entries) { for (i = 0; i < npools; i++) { + if (rrs->rrs_source->rs_read == NULL) { + /* Source pushes entropy asynchronously. */ + continue; + } n = rrs->rrs_source->rs_read(entropy, sizeof(entropy)); - KASSERT((n <= sizeof(entropy)), ("%s: rs_read returned too much data (%u > %zu)", __func__, n, sizeof(entropy))); + KASSERT((n <= sizeof(entropy)), + ("%s: rs_read returned too much data (%u > %zu)", + __func__, n, sizeof(entropy))); + /* * Sometimes the HW entropy source doesn't have anything * ready for us. This isn't necessarily untrustworthy. @@ -870,20 +877,6 @@ random_harvestq_fast_process_event(&event); } -void -random_harvest_register_source(enum random_entropy_source source) -{ - - hc_source_mask |= (1 << source); -} - -void -random_harvest_deregister_source(enum random_entropy_source source) -{ - - hc_source_mask &= ~(1 << source); -} - void random_source_register(const struct random_source *rsource) { @@ -894,10 +887,9 @@ 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); + hc_source_mask |= (1 << rsource->rs_source); RANDOM_HARVEST_LOCK(); CK_LIST_INSERT_HEAD(&source_list, rrs, rrs_entries); RANDOM_HARVEST_UNLOCK(); @@ -910,8 +902,7 @@ KASSERT(rsource != NULL, ("invalid input to %s", __func__)); - random_harvest_deregister_source(rsource->rs_source); - + hc_source_mask &= ~(1 << rsource->rs_source); RANDOM_HARVEST_LOCK(); CK_LIST_FOREACH(rrs, &source_list, rrs_entries) if (rrs->rrs_source == rsource) { diff --git a/sys/dev/random/randomdev.h b/sys/dev/random/randomdev.h --- a/sys/dev/random/randomdev.h +++ b/sys/dev/random/randomdev.h @@ -52,7 +52,9 @@ } #endif /* SYSCTL_DECL */ +#ifdef MALLOC_DECLARE MALLOC_DECLARE(M_ENTROPY); +#endif extern bool random_bypass_before_seeding; extern bool read_random_bypassed_before_seeding; diff --git a/sys/dev/tpm/tpm20.c b/sys/dev/tpm/tpm20.c --- a/sys/dev/tpm/tpm20.c +++ b/sys/dev/tpm/tpm20.c @@ -25,8 +25,8 @@ * POSSIBILITY OF SUCH DAMAGE. */ -#include #include +#include #include "tpm20.h" @@ -184,6 +184,13 @@ return (ENOTTY); } +#ifdef TPM_HARVEST +static const struct random_source random_tpm = { + .rs_ident = "TPM", + .rs_source = RANDOM_PURE_TPM, +}; +#endif + int tpm20_init(struct tpm_sc *sc) { @@ -206,7 +213,7 @@ tpm20_release(sc); #ifdef TPM_HARVEST - random_harvest_register_source(RANDOM_PURE_TPM); + random_source_register(&random_tpm); TIMEOUT_TASK_INIT(taskqueue_thread, &sc->harvest_task, 0, tpm20_harvest, sc); taskqueue_enqueue_timeout(taskqueue_thread, &sc->harvest_task, 0); @@ -223,7 +230,7 @@ #ifdef TPM_HARVEST if (device_is_attached(sc->dev)) taskqueue_drain_timeout(taskqueue_thread, &sc->harvest_task); - random_harvest_deregister_source(RANDOM_PURE_TPM); + random_source_deregister(&random_tpm); #endif if (sc->buf != NULL) diff --git a/sys/dev/vmgenc/vmgenc_acpi.c b/sys/dev/vmgenc/vmgenc_acpi.c --- a/sys/dev/vmgenc/vmgenc_acpi.c +++ b/sys/dev/vmgenc/vmgenc_acpi.c @@ -56,6 +56,7 @@ #include #include +#include #include #include @@ -210,6 +211,11 @@ } +static const struct random_source random_vmgenid = { + .rs_ident = "VM Generation ID", + .rs_source = RANDOM_PURE_VMGENID, +}; + static int vmgenc_attach(device_t dev) { @@ -234,7 +240,7 @@ memcpy(sc->vmg_cache_guid, __DEVOLATILE(void *, sc->vmg_pguid), sizeof(sc->vmg_cache_guid)); - random_harvest_register_source(RANDOM_PURE_VMGENID); + random_source_register(&random_vmgenid); vmgenc_harvest_all(sc->vmg_cache_guid, sizeof(sc->vmg_cache_guid)); AcpiInstallNotifyHandler(h, ACPI_DEVICE_NOTIFY, vmgenc_notify, dev); diff --git a/sys/sys/random.h b/sys/sys/random.h --- a/sys/sys/random.h +++ b/sys/sys/random.h @@ -142,9 +142,6 @@ random_harvest_direct_(entropy, size, origin); } -void random_harvest_register_source(enum random_entropy_source); -void random_harvest_deregister_source(enum random_entropy_source); - #if defined(RANDOM_ENABLE_UMA) #define random_harvest_fast_uma(a, b, c) random_harvest_fast(a, b, c) #else /* !defined(RANDOM_ENABLE_UMA) */