Module Name: src
Committed By: mrg
Date: Sat Apr 17 01:53:58 UTC 2021
Modified Files:
src/sys/arch/aarch64/aarch64: pmap.c
src/sys/dev/usb: usbhist.h
src/sys/sys: biohist.h kernhist.h
src/sys/uvm: uvm_map.c uvm_pdaemon.c uvm_stat.h
src/sys/uvm/pmap: pmap.c
Log Message:
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.
To generate a diff of this commit:
cvs rdiff -u -r1.103 -r1.104 src/sys/arch/aarch64/aarch64/pmap.c
cvs rdiff -u -r1.6 -r1.7 src/sys/dev/usb/usbhist.h
cvs rdiff -u -r1.2 -r1.3 src/sys/sys/biohist.h
cvs rdiff -u -r1.25 -r1.26 src/sys/sys/kernhist.h
cvs rdiff -u -r1.386 -r1.387 src/sys/uvm/uvm_map.c
cvs rdiff -u -r1.131 -r1.132 src/sys/uvm/uvm_pdaemon.c
cvs rdiff -u -r1.54 -r1.55 src/sys/uvm/uvm_stat.h
cvs rdiff -u -r1.61 -r1.62 src/sys/uvm/pmap/pmap.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/aarch64/aarch64/pmap.c
diff -u src/sys/arch/aarch64/aarch64/pmap.c:1.103 src/sys/arch/aarch64/aarch64/pmap.c:1.104
--- src/sys/arch/aarch64/aarch64/pmap.c:1.103 Tue Mar 9 16:40:59 2021
+++ src/sys/arch/aarch64/aarch64/pmap.c Sat Apr 17 01:53:58 2021
@@ -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 <[email protected]>
@@ -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 @@ __KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.1
#define VPRINTF(...) __nothing
#endif
-UVMHIST_DEFINE(pmaphist);
#ifdef UVMHIST
#ifndef UVMHIST_PMAPHIST_SIZE
@@ -76,13 +75,14 @@ UVMHIST_DEFINE(pmaphist);
#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;
}
}
Index: src/sys/dev/usb/usbhist.h
diff -u src/sys/dev/usb/usbhist.h:1.6 src/sys/dev/usb/usbhist.h:1.7
--- src/sys/dev/usb/usbhist.h:1.6 Thu Aug 22 00:24:07 2019
+++ src/sys/dev/usb/usbhist.h Sat Apr 17 01:53:58 2021
@@ -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 @@ extern int usbdebug;
#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 @@ USBHIST_DECL(usbhist);
#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)
Index: src/sys/sys/biohist.h
diff -u src/sys/sys/biohist.h:1.2 src/sys/sys/biohist.h:1.3
--- src/sys/sys/biohist.h:1.2 Tue Dec 27 04:12:34 2016
+++ src/sys/sys/biohist.h Sat Apr 17 01:53:58 2021
@@ -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)
Index: src/sys/sys/kernhist.h
diff -u src/sys/sys/kernhist.h:1.25 src/sys/sys/kernhist.h:1.26
--- src/sys/sys/kernhist.h:1.25 Tue Aug 14 11:39:10 2018
+++ src/sys/sys/kernhist.h Sat Apr 17 01:53:58 2021
@@ -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 @@ LIST_HEAD(kern_history_head, kern_histor
#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 @@ do { \
/* 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
Index: src/sys/uvm/uvm_map.c
diff -u src/sys/uvm/uvm_map.c:1.386 src/sys/uvm/uvm_map.c:1.387
--- src/sys/uvm/uvm_map.c:1.386 Sat Mar 13 15:29:55 2021
+++ src/sys/uvm/uvm_map.c Sat Apr 17 01:53:58 2021
@@ -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 @@ uvm_map_unreference_amap(struct vm_map_e
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);
Index: src/sys/uvm/uvm_pdaemon.c
diff -u src/sys/uvm/uvm_pdaemon.c:1.131 src/sys/uvm/uvm_pdaemon.c:1.132
--- src/sys/uvm/uvm_pdaemon.c:1.131 Wed Nov 4 01:30:19 2020
+++ src/sys/uvm/uvm_pdaemon.c Sat Apr 17 01:53:58 2021
@@ -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 @@ __KERNEL_RCSID(0, "$NetBSD: uvm_pdaemon.
#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
/*
Index: src/sys/uvm/uvm_stat.h
diff -u src/sys/uvm/uvm_stat.h:1.54 src/sys/uvm/uvm_stat.h:1.55
--- src/sys/uvm/uvm_stat.h:1.54 Mon Apr 13 07:11:08 2020
+++ src/sys/uvm/uvm_stat.h Sat Apr 17 01:53:58 2021
@@ -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)
Index: src/sys/uvm/pmap/pmap.c
diff -u src/sys/uvm/pmap/pmap.c:1.61 src/sys/uvm/pmap/pmap.c:1.62
--- src/sys/uvm/pmap/pmap.c:1.61 Fri Mar 19 07:51:33 2021
+++ src/sys/uvm/pmap/pmap.c Sat Apr 17 01:53:58 2021
@@ -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 @@ struct pmap_limits pmap_limits = { /* VA
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 @@ pmap_bootstrap_common(void)
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);