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.
This commit is contained in:
mrg 2021-04-17 01:53:58 +00:00
parent 856324edf9
commit f405a45af6
8 changed files with 23 additions and 45 deletions

View File

@ -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>
@ -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.103 2021/03/09 16:40:59 ryo Exp $");
#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;
}
}

View File

@ -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)

View File

@ -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)

View File

@ -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_history);
#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

View File

@ -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 and PA limits */
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);

View File

@ -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_entry *entry, int flags)
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);

View File

@ -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.c,v 1.131 2020/11/04 01:30:19 chs Exp $"
#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
/*

View File

@ -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)