From c2cdb48e8ff26d25a8878cccc5f1c9f26dd433e8 Mon Sep 17 00:00:00 2001 From: Taylor R Campbell Date: Wed, 27 Oct 2021 22:41:35 +0000 Subject: [PATCH] x86: Move RNG initialization to after consinit. This ensures we have the opportunity to get feedback about early entropy. --- sys/arch/amd64/amd64/machdep.c | 11 +++++++++-- sys/arch/i386/i386/machdep.c | 11 +++++++++-- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/sys/arch/amd64/amd64/machdep.c b/sys/arch/amd64/amd64/machdep.c index 27c86d243351..be270419c26c 100644 --- a/sys/arch/amd64/amd64/machdep.c +++ b/sys/arch/amd64/amd64/machdep.c @@ -1725,8 +1725,6 @@ init_x86_64(paddr_t first_avail) svs_init(); #endif cpu_init_msrs(&cpu_info_primary, true); - cpu_rng_init(); - x86_rndseed(); #ifndef XENPV cpu_speculation_init(&cpu_info_primary); #endif @@ -1749,6 +1747,15 @@ init_x86_64(paddr_t first_avail) consinit(); /* XXX SHOULD NOT BE DONE HERE */ + /* + * Initialize RNG to get entropy ASAP either from CPU + * RDRAND/RDSEED or from seed on disk. Must happen after + * cpu_init_msrs. Prefer to happen after consinit so we have + * the opportunity to print useful feedback. + */ + cpu_rng_init(); + x86_rndseed(); + /* * Initialize PAGE_SIZE-dependent variables. */ diff --git a/sys/arch/i386/i386/machdep.c b/sys/arch/i386/i386/machdep.c index 107becb5a217..4d2e270b99af 100644 --- a/sys/arch/i386/i386/machdep.c +++ b/sys/arch/i386/i386/machdep.c @@ -1168,8 +1168,6 @@ init386(paddr_t first_avail) cpu_probe(&cpu_info_primary); cpu_init_msrs(&cpu_info_primary, true); - cpu_rng_init(); - x86_rndseed(); #ifndef XENPV cpu_speculation_init(&cpu_info_primary); #endif @@ -1250,6 +1248,15 @@ init386(paddr_t first_avail) consinit(); /* XXX SHOULD NOT BE DONE HERE */ + /* + * Initialize RNG to get entropy ASAP either from CPU + * RDRAND/RDSEED or from seed on disk. Must happen after + * cpu_init_msrs. Prefer to happen after consinit so we have + * the opportunity to print useful feedback. + */ + cpu_rng_init(); + x86_rndseed(); + #ifdef DEBUG_MEMLOAD printf("mem_cluster_count: %d\n", mem_cluster_cnt); #endif