From nobody Wed Oct 06 07:00:07 2021 X-Original-To: dev-commits-src-branches@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id EFA6712D43EA; Wed, 6 Oct 2021 07:00:07 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4HPQLv65ySz3QVG; Wed, 6 Oct 2021 07:00:07 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id AEC191B9C7; Wed, 6 Oct 2021 07:00:07 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 1967071g014504; Wed, 6 Oct 2021 07:00:07 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 196707Dv014501; Wed, 6 Oct 2021 07:00:07 GMT (envelope-from git) Date: Wed, 6 Oct 2021 07:00:07 GMT Message-Id: <202110060700.196707Dv014501@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Kyle Evans Subject: git: 06248c821580 - stable/13 - kern: random: collect ~16x less from fast-entropy sources List-Id: Commits to the stable branches of the FreeBSD src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-branches List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-branches@freebsd.org X-BeenThere: dev-commits-src-branches@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: kevans X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: 06248c82158019f30a18494e7ce91ac5f9524452 Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch stable/13 has been updated by kevans: URL: https://cgit.FreeBSD.org/src/commit/?id=06248c82158019f30a18494e7ce91ac5f9524452 commit 06248c82158019f30a18494e7ce91ac5f9524452 Author: Kyle Evans AuthorDate: 2021-09-20 05:46:21 +0000 Commit: Kyle Evans CommitDate: 2021-10-06 06:44:07 +0000 kern: random: collect ~16x less from fast-entropy sources Previously, we were collecting at a base rate of: 64 bits x 32 pools x 10 Hz = 2.5 kB/s This change drops it to closer to 64-ish bits per pool per second, to work a little better with entropy providers in virtualized environments without compromising the security goals of Fortuna. (cherry picked from commit 5e79bba562bc303eed669dbd0d391b6c6a9c289b) --- sys/dev/random/random_harvestq.c | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/sys/dev/random/random_harvestq.c b/sys/dev/random/random_harvestq.c index 1c0ba0774687..563ff73a3d38 100644 --- a/sys/dev/random/random_harvestq.c +++ b/sys/dev/random/random_harvestq.c @@ -72,6 +72,13 @@ __FBSDID("$FreeBSD$"); #define _RANDOM_HARVEST_UMA_OFF (1u << RANDOM_UMA) #endif +/* + * Note that random_sources_feed() will also use this to try and split up + * entropy into a subset of pools per iteration with the goal of feeding + * HARVESTSIZE into every pool at least once per second. + */ +#define RANDOM_KTHREAD_HZ 10 + static void random_kthread(void); static void random_sources_feed(void); @@ -199,7 +206,8 @@ random_kthread(void) } } /* XXX: FIX!! This is a *great* place to pass hardware/live entropy to random(9) */ - tsleep_sbt(&harvest_context.hc_kthread_proc, 0, "-", SBT_1S/10, 0, C_PREL(1)); + tsleep_sbt(&harvest_context.hc_kthread_proc, 0, "-", + SBT_1S/RANDOM_KTHREAD_HZ, 0, C_PREL(1)); } random_kthread_control = -1; wakeup(&harvest_context.hc_kthread_proc); @@ -229,11 +237,23 @@ random_sources_feed(void) uint32_t entropy[HARVESTSIZE]; struct epoch_tracker et; struct random_sources *rrs; - u_int i, n; + u_int i, n, npools; bool rse_warm; rse_warm = epoch_inited; + /* + * Evenly-ish distribute pool population across the second based on how + * frequently random_kthread iterates. + * + * For Fortuna, the math currently works out as such: + * + * 64 bits * 4 pools = 256 bits per iteration + * 256 bits * 10 Hz = 2560 bits per second, 320 B/s + * + */ + npools = howmany(p_random_alg_context->ra_poolcount, RANDOM_KTHREAD_HZ); + /* * Step over all of live entropy sources, and feed their output * to the system-wide RNG. @@ -241,7 +261,7 @@ random_sources_feed(void) if (rse_warm) epoch_enter_preempt(rs_epoch, &et); CK_LIST_FOREACH(rrs, &source_list, rrs_entries) { - for (i = 0; i < p_random_alg_context->ra_poolcount; i++) { + for (i = 0; i < npools; i++) { 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))); /*