From f5f850067e153e389ec678b5463f9aaa3eacc727 Mon Sep 17 00:00:00 2001 From: Taylor R Campbell Date: Wed, 20 Oct 2021 13:08:17 +0000 Subject: [PATCH] x86: Process bootloader rndseed much sooner. --- sys/arch/amd64/amd64/machdep.c | 1 + sys/arch/i386/i386/machdep.c | 1 + sys/arch/x86/include/machdep.h | 2 ++ sys/arch/x86/x86/x86_machdep.c | 42 ++++++++++++++++++++++++++-------- 4 files changed, 36 insertions(+), 10 deletions(-) diff --git a/sys/arch/amd64/amd64/machdep.c b/sys/arch/amd64/amd64/machdep.c index a1ba09316f52..27c86d243351 100644 --- a/sys/arch/amd64/amd64/machdep.c +++ b/sys/arch/amd64/amd64/machdep.c @@ -1726,6 +1726,7 @@ init_x86_64(paddr_t first_avail) #endif cpu_init_msrs(&cpu_info_primary, true); cpu_rng_init(); + x86_rndseed(); #ifndef XENPV cpu_speculation_init(&cpu_info_primary); #endif diff --git a/sys/arch/i386/i386/machdep.c b/sys/arch/i386/i386/machdep.c index a4058ee83da5..107becb5a217 100644 --- a/sys/arch/i386/i386/machdep.c +++ b/sys/arch/i386/i386/machdep.c @@ -1169,6 +1169,7 @@ 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 diff --git a/sys/arch/x86/include/machdep.h b/sys/arch/x86/include/machdep.h index a87a7ecfec70..1c24f8594ef9 100644 --- a/sys/arch/x86/include/machdep.h +++ b/sys/arch/x86/include/machdep.h @@ -65,4 +65,6 @@ void init_x86_msgbuf(void); void x86_startup(void); void x86_sysctl_machdep_setup(struct sysctllog **); +void x86_rndseed(void); + #endif /* _X86_MACHDEP_H_ */ diff --git a/sys/arch/x86/x86/x86_machdep.c b/sys/arch/x86/x86/x86_machdep.c index fe382bd079ae..39aa80cdce95 100644 --- a/sys/arch/x86/x86/x86_machdep.c +++ b/sys/arch/x86/x86/x86_machdep.c @@ -259,16 +259,7 @@ module_init_md(void) #endif break; case BI_MODULE_RND: - aprint_debug("Random seed data path=%s len=%d pa=%x\n", - bi->path, bi->len, bi->base); - KASSERT(trunc_page(bi->base) == bi->base); - rnd_seed( -#ifdef KASLR - (void *)PMAP_DIRECT_MAP((uintptr_t)bi->base), -#else - (void *)((uintptr_t)bi->base + KERNBASE), -#endif - bi->len); + /* handled in x86_rndseed */ break; case BI_MODULE_FS: aprint_debug("File-system image path=%s len=%d pa=%x\n", @@ -292,6 +283,37 @@ module_init_md(void) } #endif /* MODULAR */ +void +x86_rndseed(void) +{ + struct btinfo_modulelist *biml; + struct bi_modulelist_entry *bi, *bimax; + + biml = lookup_bootinfo(BTINFO_MODULELIST); + if (biml == NULL) { + aprint_debug("No module info at boot\n"); + return; + } + + bi = (struct bi_modulelist_entry *)((uint8_t *)biml + sizeof(*biml)); + bimax = bi + biml->num; + for (; bi < bimax; bi++) { + switch (bi->type) { + case BI_MODULE_RND: + aprint_debug("Random seed data path=%s len=%d pa=%x\n", + bi->path, bi->len, bi->base); + KASSERT(trunc_page(bi->base) == bi->base); + rnd_seed( +#ifdef KASLR + (void *)PMAP_DIRECT_MAP((uintptr_t)bi->base), +#else + (void *)((uintptr_t)bi->base + KERNBASE), +#endif + bi->len); + } + } +} + void cpu_need_resched(struct cpu_info *ci, struct lwp *l, int flags) {