Module Name: src
Committed By: riastradh
Date: Thu Oct 28 10:46:05 UTC 2021
Modified Files:
src/sys/arch/amd64/amd64: machdep.c
src/sys/arch/i386/i386: machdep.c
Log Message:
x86: Move RNG initialization to after consinit.
This ensures we have the opportunity to get feedback about early
entropy.
To generate a diff of this commit:
cvs rdiff -u -r1.359 -r1.360 src/sys/arch/amd64/amd64/machdep.c
cvs rdiff -u -r1.832 -r1.833 src/sys/arch/i386/i386/machdep.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/sys/arch/amd64/amd64/machdep.c
diff -u src/sys/arch/amd64/amd64/machdep.c:1.359 src/sys/arch/amd64/amd64/machdep.c:1.360
--- src/sys/arch/amd64/amd64/machdep.c:1.359 Thu Oct 28 10:45:48 2021
+++ src/sys/arch/amd64/amd64/machdep.c Thu Oct 28 10:46:05 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: machdep.c,v 1.359 2021/10/28 10:45:48 riastradh Exp $ */
+/* $NetBSD: machdep.c,v 1.360 2021/10/28 10:46:05 riastradh Exp $ */
/*
* Copyright (c) 1996, 1997, 1998, 2000, 2006, 2007, 2008, 2011
@@ -110,7 +110,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.359 2021/10/28 10:45:48 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.360 2021/10/28 10:46:05 riastradh Exp $");
#include "opt_modular.h"
#include "opt_user_ldt.h"
@@ -1718,8 +1718,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
@@ -1743,6 +1741,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.
*/
uvm_md_init();
Index: src/sys/arch/i386/i386/machdep.c
diff -u src/sys/arch/i386/i386/machdep.c:1.832 src/sys/arch/i386/i386/machdep.c:1.833
--- src/sys/arch/i386/i386/machdep.c:1.832 Thu Oct 28 10:45:48 2021
+++ src/sys/arch/i386/i386/machdep.c Thu Oct 28 10:46:05 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: machdep.c,v 1.832 2021/10/28 10:45:48 riastradh Exp $ */
+/* $NetBSD: machdep.c,v 1.833 2021/10/28 10:46:05 riastradh Exp $ */
/*
* Copyright (c) 1996, 1997, 1998, 2000, 2004, 2006, 2008, 2009, 2017
@@ -67,7 +67,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.832 2021/10/28 10:45:48 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.833 2021/10/28 10:46:05 riastradh Exp $");
#include "opt_beep.h"
#include "opt_compat_freebsd.h"
@@ -1161,8 +1161,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
@@ -1243,6 +1241,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