Module Name: src
Committed By: riastradh
Date: Thu Oct 28 10:45:49 UTC 2021
Modified Files:
src/sys/arch/amd64/amd64: machdep.c
src/sys/arch/i386/i386: machdep.c
src/sys/arch/x86/include: machdep.h
src/sys/arch/x86/x86: x86_machdep.c
Log Message:
x86: Process bootloader rndseed much sooner.
To generate a diff of this commit:
cvs rdiff -u -r1.358 -r1.359 src/sys/arch/amd64/amd64/machdep.c
cvs rdiff -u -r1.831 -r1.832 src/sys/arch/i386/i386/machdep.c
cvs rdiff -u -r1.11 -r1.12 src/sys/arch/x86/include/machdep.h
cvs rdiff -u -r1.149 -r1.150 src/sys/arch/x86/x86/x86_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.358 src/sys/arch/amd64/amd64/machdep.c:1.359
--- src/sys/arch/amd64/amd64/machdep.c:1.358 Sun Jan 24 14:17:10 2021
+++ src/sys/arch/amd64/amd64/machdep.c Thu Oct 28 10:45:48 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: machdep.c,v 1.358 2021/01/24 14:17:10 simonb Exp $ */
+/* $NetBSD: machdep.c,v 1.359 2021/10/28 10:45:48 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.358 2021/01/24 14:17:10 simonb Exp $");
+__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.359 2021/10/28 10:45:48 riastradh Exp $");
#include "opt_modular.h"
#include "opt_user_ldt.h"
@@ -1719,6 +1719,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
Index: src/sys/arch/i386/i386/machdep.c
diff -u src/sys/arch/i386/i386/machdep.c:1.831 src/sys/arch/i386/i386/machdep.c:1.832
--- src/sys/arch/i386/i386/machdep.c:1.831 Tue Jul 14 00:45:52 2020
+++ src/sys/arch/i386/i386/machdep.c Thu Oct 28 10:45:48 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: machdep.c,v 1.831 2020/07/14 00:45:52 yamaguchi Exp $ */
+/* $NetBSD: machdep.c,v 1.832 2021/10/28 10:45:48 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.831 2020/07/14 00:45:52 yamaguchi Exp $");
+__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.832 2021/10/28 10:45:48 riastradh Exp $");
#include "opt_beep.h"
#include "opt_compat_freebsd.h"
@@ -1162,6 +1162,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
Index: src/sys/arch/x86/include/machdep.h
diff -u src/sys/arch/x86/include/machdep.h:1.11 src/sys/arch/x86/include/machdep.h:1.12
--- src/sys/arch/x86/include/machdep.h:1.11 Sun Nov 15 13:59:42 2020
+++ src/sys/arch/x86/include/machdep.h Thu Oct 28 10:45:48 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: machdep.h,v 1.11 2020/11/15 13:59:42 bouyer Exp $ */
+/* $NetBSD: machdep.h,v 1.12 2021/10/28 10:45:48 riastradh Exp $ */
/*
* Copyright (c) 2000, 2007 The NetBSD Foundation, Inc.
* All rights reserved.
@@ -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_ */
Index: src/sys/arch/x86/x86/x86_machdep.c
diff -u src/sys/arch/x86/x86/x86_machdep.c:1.149 src/sys/arch/x86/x86/x86_machdep.c:1.150
--- src/sys/arch/x86/x86/x86_machdep.c:1.149 Thu Oct 7 12:52:27 2021
+++ src/sys/arch/x86/x86/x86_machdep.c Thu Oct 28 10:45:49 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: x86_machdep.c,v 1.149 2021/10/07 12:52:27 msaitoh Exp $ */
+/* $NetBSD: x86_machdep.c,v 1.150 2021/10/28 10:45:49 riastradh Exp $ */
/*-
* Copyright (c) 2002, 2006, 2007 YAMAMOTO Takashi,
@@ -31,7 +31,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: x86_machdep.c,v 1.149 2021/10/07 12:52:27 msaitoh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: x86_machdep.c,v 1.150 2021/10/28 10:45:49 riastradh Exp $");
#include "opt_modular.h"
#include "opt_physmem.h"
@@ -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",
@@ -293,6 +284,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)
{