Source-Changes-HG archive

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

[src/trunk]: src/sys/uvm/pmap remove KERNHIST_INIT_STATIC(). it stradles the...



details:   https://anonhg.NetBSD.org/src/rev/692e782532a0
branches:  trunk
changeset: 1020586:692e782532a0
user:      mrg <mrg%NetBSD.org@localhost>
date:      Sat Apr 17 01:53:58 2021 +0000

description:
remove KERNHIST_INIT_STATIC().  it stradles the line between usable
early in boot and broken early in boot by requiring a partly static
structure with another structure that must be present by the time
any uses are performed.  theoretically platform code could allocate
a chunk while seting up memory and assign it here, giving a dynamic
sizing for the entry list, but the reality is that all users have
a statically allocated entry list as well.

the existing KERNHIST_LINK_STATIC() is used in conjunction with
KERNHIST_INITIALIZER() instead.

this stops a NULL pointer deref when the _LOG() macro is called
before the storage is linked in, which happens with GCC 10 on OCTEON
with UVMHIST enabled, crashing in very early kernel init.

diffstat:

 sys/arch/aarch64/aarch64/pmap.c |   8 ++++----
 sys/dev/usb/usbhist.h           |   4 +---
 sys/sys/biohist.h               |   4 +---
 sys/sys/kernhist.h              |  15 +--------------
 sys/uvm/pmap/pmap.c             |  16 ++++++++--------
 sys/uvm/uvm_map.c               |  10 +++-------
 sys/uvm/uvm_pdaemon.c           |   7 ++++---
 sys/uvm/uvm_stat.h              |   4 +---
 8 files changed, 23 insertions(+), 45 deletions(-)

diffs (262 lines):

diff -r add7b4280495 -r 692e782532a0 sys/arch/aarch64/aarch64/pmap.c
--- a/sys/arch/aarch64/aarch64/pmap.c   Sat Apr 17 01:19:48 2021 +0000
+++ b/sys/arch/aarch64/aarch64/pmap.c   Sat Apr 17 01:53:58 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: pmap.c,v 1.103 2021/03/09 16:40:59 ryo Exp $   */
+/*     $NetBSD: pmap.c,v 1.104 2021/04/17 01:53:58 mrg Exp $   */
 
 /*
  * Copyright (c) 2017 Ryo Shimizu <ryo%nerv.org@localhost>
@@ -27,7 +27,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.103 2021/03/09 16:40:59 ryo Exp $");
+__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.104 2021/04/17 01:53:58 mrg Exp $");
 
 #include "opt_arm_debug.h"
 #include "opt_ddb.h"
@@ -68,7 +68,6 @@
 #define VPRINTF(...)   __nothing
 #endif
 
-UVMHIST_DEFINE(pmaphist);
 #ifdef UVMHIST
 
 #ifndef UVMHIST_PMAPHIST_SIZE
@@ -76,13 +75,14 @@
 #endif
 
 struct kern_history_ent pmaphistbuf[UVMHIST_PMAPHIST_SIZE];
+UVMHIST_DEFINE(pmaphist) = UVMHIST_INITIALIZER(pmaphist, pmaphistbuf);;
 
 static void
 pmap_hist_init(void)
 {
        static bool inited = false;
        if (inited == false) {
-               UVMHIST_INIT_STATIC(pmaphist, pmaphistbuf);
+               UVMHIST_LINK_STATIC(pmaphist);
                inited = true;
        }
 }
diff -r add7b4280495 -r 692e782532a0 sys/dev/usb/usbhist.h
--- a/sys/dev/usb/usbhist.h     Sat Apr 17 01:19:48 2021 +0000
+++ b/sys/dev/usb/usbhist.h     Sat Apr 17 01:53:58 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: usbhist.h,v 1.6 2019/08/22 00:24:07 mrg Exp $  */
+/*     $NetBSD: usbhist.h,v 1.7 2021/04/17 01:53:58 mrg Exp $  */
 
 /*
  * Copyright (c) 2012 Matthew R. Green
@@ -51,7 +51,6 @@
 #define USBHIST_DECL(NAME)             KERNHIST_DECL(NAME)
 #define USBHIST_DEFINE(NAME)           KERNHIST_DEFINE(NAME)
 #define USBHIST_INIT(NAME,N)           KERNHIST_INIT(NAME,N)
-#define USBHIST_INIT_STATIC(NAME,BUF)  KERNHIST_INIT_STATIC(NAME,BUF)
 #define USBHIST_LINK_STATIC(NAME)      KERNHIST_LINK_STATIC(NAME)
 #define USBHIST_LOGN(NAME,N,FMT,A,B,C,D)       do {            \
        if ((NAME) >= (N)) {                                    \
@@ -88,7 +87,6 @@
 #define USBHIST_DECL(NAME)
 #define USBHIST_DEFINE(NAME)
 #define USBHIST_INIT(NAME,N)
-#define USBHIST_INIT_STATIC(NAME,BUF)
 #define USBHIST_LINK_STATIC(NAME)
 #define USBHIST_LOGN(N,NAME,FMT,A,B,C,D)       do { } while(0)
 #define USBHIST_LOGM(N,NAME,FMT,A,B,C,D)       do { } while(0)
diff -r add7b4280495 -r 692e782532a0 sys/sys/biohist.h
--- a/sys/sys/biohist.h Sat Apr 17 01:19:48 2021 +0000
+++ b/sys/sys/biohist.h Sat Apr 17 01:53:58 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: biohist.h,v 1.2 2016/12/27 04:12:34 pgoyette Exp $ */
+/*     $NetBSD: biohist.h,v 1.3 2021/04/17 01:53:58 mrg Exp $ */
 
 /*-
  * Copyright (c) 2016 The NetBSD Foundation, Inc.
@@ -50,7 +50,6 @@
 #define BIOHIST_DECL(NAME)             KERNHIST_DECL(NAME)
 #define BIOHIST_DEFINE(NAME)           KERNHIST_DEFINE(NAME)
 #define BIOHIST_INIT(NAME,N)           KERNHIST_INIT(NAME,N)
-#define BIOHIST_INIT_STATIC(NAME,BUF)  KERNHIST_INIT_STATIC(NAME,BUF)
 #define BIOHIST_INITIALIZER(NAME,BUF)  KERNHIST_INITIALIZER(NAME,BUF)
 #define BIOHIST_LINK_STATIC(NAME)      KERNHIST_LINK_STATIC(NAME)
 #define BIOHIST_LOG(NAME,FMT,A,B,C,D)  KERNHIST_LOG(NAME,FMT,A,B,C,D)
@@ -68,7 +67,6 @@
 #define BIOHIST_DECL(NAME)
 #define BIOHIST_DEFINE(NAME)
 #define BIOHIST_INIT(NAME,N)
-#define BIOHIST_INIT_STATIC(NAME,BUF)
 #define BIOHIST_INITIALIZER(NAME,BUF)
 #define BIOHIST_LINK_STATIC(NAME)
 #define BIOHIST_LOG(NAME,FMT,A,B,C,D)
diff -r add7b4280495 -r 692e782532a0 sys/sys/kernhist.h
--- a/sys/sys/kernhist.h        Sat Apr 17 01:19:48 2021 +0000
+++ b/sys/sys/kernhist.h        Sat Apr 17 01:53:58 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: kernhist.h,v 1.25 2018/08/14 11:39:10 christos Exp $   */
+/*     $NetBSD: kernhist.h,v 1.26 2021/04/17 01:53:58 mrg Exp $        */
 
 /*
  * Copyright (c) 1997 Charles D. Cranor and Washington University.
@@ -132,7 +132,6 @@
 #define KERNHIST_DECL(NAME)
 #define KERNHIST_DEFINE(NAME)
 #define KERNHIST_INIT(NAME,N)
-#define KERNHIST_INIT_STATIC(NAME,BUF)
 #define KERNHIST_LOG(NAME,FMT,A,B,C,D)
 #define KERNHIST_CALLARGS(NAME,FMT,A,B,C,D)
 #define KERNHIST_CALLED(NAME)
@@ -177,18 +176,6 @@
        /* BUF will inititalized to zeroes by being in .bss */ \
 }
 
-#define KERNHIST_INIT_STATIC(NAME,BUF) \
-do { \
-       (NAME).name = __STRING(NAME); \
-       (NAME).namelen = strlen(__STRING(NAME)); \
-       (NAME).n = sizeof(BUF) / sizeof(struct kern_history_ent); \
-       (NAME).f = 0; \
-       (NAME).e = (struct kern_history_ent *) (BUF); \
-       (NAME).s = 0; \
-       memset((NAME).e, 0, sizeof(struct kern_history_ent) * (NAME).n); \
-       KERNHIST_LINK_STATIC(NAME); \
-} while (/*CONSTCOND*/ 0)
-
 #ifndef KERNHIST_DELAY
 #define KERNHIST_DELAY 100000
 #endif
diff -r add7b4280495 -r 692e782532a0 sys/uvm/pmap/pmap.c
--- a/sys/uvm/pmap/pmap.c       Sat Apr 17 01:19:48 2021 +0000
+++ b/sys/uvm/pmap/pmap.c       Sat Apr 17 01:53:58 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: pmap.c,v 1.61 2021/03/19 07:51:33 skrll Exp $  */
+/*     $NetBSD: pmap.c,v 1.62 2021/04/17 01:53:58 mrg Exp $    */
 
 /*-
  * Copyright (c) 1998, 2001 The NetBSD Foundation, Inc.
@@ -67,7 +67,7 @@
 
 #include <sys/cdefs.h>
 
-__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.61 2021/03/19 07:51:33 skrll Exp $");
+__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.62 2021/04/17 01:53:58 mrg Exp $");
 
 /*
  *     Manages physical address maps.
@@ -225,9 +225,9 @@
 static struct kern_history_ent pmapexechistbuf[10000];
 static struct kern_history_ent pmaphistbuf[10000];
 static struct kern_history_ent pmapsegtabhistbuf[1000];
-UVMHIST_DEFINE(pmapexechist);
-UVMHIST_DEFINE(pmaphist);
-UVMHIST_DEFINE(pmapsegtabhist);
+UVMHIST_DEFINE(pmapexechist) = UVMHIST_INITIALIZER(pmapexechist, pmapexechistbuf);
+UVMHIST_DEFINE(pmaphist) = UVMHIST_INITIALIZER(pmaphist, pmaphistbuf);
+UVMHIST_DEFINE(pmapsegtabhist) = UVMHIST_INITIALIZER(pmapsegtabhist, pmapsegtabhistbuf);
 #endif
 
 /*
@@ -604,9 +604,9 @@
 void
 pmap_init(void)
 {
-       UVMHIST_INIT_STATIC(pmapexechist, pmapexechistbuf);
-       UVMHIST_INIT_STATIC(pmaphist, pmaphistbuf);
-       UVMHIST_INIT_STATIC(pmapsegtabhist, pmapsegtabhistbuf);
+       UVMHIST_LINK_STATIC(pmapexechist);
+       UVMHIST_LINK_STATIC(pmaphist);
+       UVMHIST_LINK_STATIC(pmapsegtabhist);
 
        UVMHIST_FUNC(__func__);
        UVMHIST_CALLED(pmaphist);
diff -r add7b4280495 -r 692e782532a0 sys/uvm/uvm_map.c
--- a/sys/uvm/uvm_map.c Sat Apr 17 01:19:48 2021 +0000
+++ b/sys/uvm/uvm_map.c Sat Apr 17 01:53:58 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: uvm_map.c,v 1.386 2021/03/13 15:29:55 skrll Exp $      */
+/*     $NetBSD: uvm_map.c,v 1.387 2021/04/17 01:53:58 mrg Exp $        */
 
 /*
  * Copyright (c) 1997 Charles D. Cranor and Washington University.
@@ -66,7 +66,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: uvm_map.c,v 1.386 2021/03/13 15:29:55 skrll Exp $");
+__KERNEL_RCSID(0, "$NetBSD: uvm_map.c,v 1.387 2021/04/17 01:53:58 mrg Exp $");
 
 #include "opt_ddb.h"
 #include "opt_pax.h"
@@ -904,17 +904,13 @@
 void
 uvm_map_init(void)
 {
-#if defined(UVMHIST)
-       static struct kern_history_ent pdhistbuf[UVMHIST_PDHIST_SIZE];
-#endif
-
        /*
         * first, init logging system.
         */
 
        UVMHIST_FUNC(__func__);
        UVMHIST_LINK_STATIC(maphist);
-       UVMHIST_INIT_STATIC(pdhist, pdhistbuf);
+       UVMHIST_LINK_STATIC(pdhist);
        UVMHIST_CALLED(maphist);
        UVMHIST_LOG(maphist,"<starting uvm map system>", 0, 0, 0, 0);
 
diff -r add7b4280495 -r 692e782532a0 sys/uvm/uvm_pdaemon.c
--- a/sys/uvm/uvm_pdaemon.c     Sat Apr 17 01:19:48 2021 +0000
+++ b/sys/uvm/uvm_pdaemon.c     Sat Apr 17 01:53:58 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: uvm_pdaemon.c,v 1.131 2020/11/04 01:30:19 chs Exp $    */
+/*     $NetBSD: uvm_pdaemon.c,v 1.132 2021/04/17 01:53:58 mrg Exp $    */
 
 /*
  * Copyright (c) 1997 Charles D. Cranor and Washington University.
@@ -66,7 +66,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: uvm_pdaemon.c,v 1.131 2020/11/04 01:30:19 chs Exp $");
+__KERNEL_RCSID(0, "$NetBSD: uvm_pdaemon.c,v 1.132 2021/04/17 01:53:58 mrg Exp $");
 
 #include "opt_uvmhist.h"
 #include "opt_readahead.h"
@@ -88,7 +88,8 @@
 #include <uvm/uvm_pgflcache.h>
 
 #ifdef UVMHIST
-UVMHIST_DEFINE(pdhist);
+static struct kern_history_ent pdhistbuf[UVMHIST_PDHIST_SIZE];
+UVMHIST_DEFINE(pdhist) = UVMHIST_INITIALIZER(pdhisthist, pdhistbuf);
 #endif
 
 /*
diff -r add7b4280495 -r 692e782532a0 sys/uvm/uvm_stat.h
--- a/sys/uvm/uvm_stat.h        Sat Apr 17 01:19:48 2021 +0000
+++ b/sys/uvm/uvm_stat.h        Sat Apr 17 01:53:58 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: uvm_stat.h,v 1.54 2020/04/13 07:11:08 skrll Exp $      */
+/*     $NetBSD: uvm_stat.h,v 1.55 2021/04/17 01:53:58 mrg Exp $        */
 
 /*
  * Copyright (c) 2011 Matthew R. Green
@@ -54,7 +54,6 @@
 #define UVMHIST_DECL(NAME)                     KERNHIST_DECL(NAME)
 #define UVMHIST_DEFINE(NAME)                   KERNHIST_DEFINE(NAME)
 #define UVMHIST_INIT(NAME,N)                   KERNHIST_INIT(NAME,N)
-#define UVMHIST_INIT_STATIC(NAME,BUF)          KERNHIST_INIT_STATIC(NAME,BUF)
 #define UVMHIST_INITIALIZER(NAME,BUF)          KERNHIST_INITIALIZER(NAME,BUF)
 #define UVMHIST_LINK_STATIC(NAME)              KERNHIST_LINK_STATIC(NAME)
 #define UVMHIST_LOG(NAME,FMT,A,B,C,D)          KERNHIST_LOG(NAME,FMT,A,B,C,D)
@@ -67,7 +66,6 @@
 #define UVMHIST_DECL(NAME)
 #define UVMHIST_DEFINE(NAME)
 #define UVMHIST_INIT(NAME,N)
-#define UVMHIST_INIT_STATIC(NAME,BUF)
 #define UVMHIST_INITIALIZER(NAME,BUF)
 #define UVMHIST_LINK_STATIC(NAME)
 #define UVMHIST_LOG(NAME,FMT,A,B,C,D)



Home | Main Index | Thread Index | Old Index