Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/arch x86: Process bootloader rndseed much sooner.



details:   https://anonhg.NetBSD.org/src/rev/c60cfc5789d0
branches:  trunk
changeset: 1024546:c60cfc5789d0
user:      riastradh <riastradh%NetBSD.org@localhost>
date:      Thu Oct 28 10:45:48 2021 +0000

description:
x86: Process bootloader rndseed much sooner.

diffstat:

 sys/arch/amd64/amd64/machdep.c |   5 ++-
 sys/arch/i386/i386/machdep.c   |   5 ++-
 sys/arch/x86/include/machdep.h |   4 ++-
 sys/arch/x86/x86/x86_machdep.c |  46 +++++++++++++++++++++++++++++++----------
 4 files changed, 43 insertions(+), 17 deletions(-)

diffs (142 lines):

diff -r de66ee0816a5 -r c60cfc5789d0 sys/arch/amd64/amd64/machdep.c
--- a/sys/arch/amd64/amd64/machdep.c    Thu Oct 28 09:51:39 2021 +0000
+++ b/sys/arch/amd64/amd64/machdep.c    Thu Oct 28 10:45:48 2021 +0000
@@ -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 @@
 #endif
        cpu_init_msrs(&cpu_info_primary, true);
        cpu_rng_init();
+       x86_rndseed();
 #ifndef XENPV
        cpu_speculation_init(&cpu_info_primary);
 #endif
diff -r de66ee0816a5 -r c60cfc5789d0 sys/arch/i386/i386/machdep.c
--- a/sys/arch/i386/i386/machdep.c      Thu Oct 28 09:51:39 2021 +0000
+++ b/sys/arch/i386/i386/machdep.c      Thu Oct 28 10:45:48 2021 +0000
@@ -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 @@
        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 -r de66ee0816a5 -r c60cfc5789d0 sys/arch/x86/include/machdep.h
--- a/sys/arch/x86/include/machdep.h    Thu Oct 28 09:51:39 2021 +0000
+++ b/sys/arch/x86/include/machdep.h    Thu Oct 28 10:45:48 2021 +0000
@@ -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   x86_startup(void);
 void   x86_sysctl_machdep_setup(struct sysctllog **);
 
+void   x86_rndseed(void);
+
 #endif /* _X86_MACHDEP_H_ */
diff -r de66ee0816a5 -r c60cfc5789d0 sys/arch/x86/x86/x86_machdep.c
--- a/sys/arch/x86/x86/x86_machdep.c    Thu Oct 28 09:51:39 2021 +0000
+++ b/sys/arch/x86/x86/x86_machdep.c    Thu Oct 28 10:45:48 2021 +0000
@@ -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 @@
 #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 @@
 #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)
 {
 



Home | Main Index | Thread Index | Old Index