x86, arm: Allow fpu_kern_enter/leave while cold.

Normally these are forbidden above IPL_VM, so that FPU usage doesn't
block IPL_SCHED or IPL_HIGH interrupts.  But while cold, e.g. during
builtin module initialization at boot, all interrupts are blocked
anyway so it's a moot point.

Also initialize x86 cpu_info_primary.ci_kfpu_spl to -1 so we don't
trip over an assertion about it while cold -- the assertion is meant
to detect reentrance into fpu_kern_enter/leave, which is prohibited.

Also initialize cpu0's ci_kfpu_spl.
This commit is contained in:
riastradh 2022-04-01 19:57:22 +00:00
parent 12ad5afd80
commit b451bcfc45
4 changed files with 18 additions and 14 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: fpu.c,v 1.11 2020/12/11 18:03:33 skrll Exp $ */
/* $NetBSD: fpu.c,v 1.12 2022/04/01 19:57:22 riastradh Exp $ */
/*-
* Copyright (c) 2014 The NetBSD Foundation, Inc.
@ -31,11 +31,12 @@
#include <sys/cdefs.h>
__KERNEL_RCSID(1, "$NetBSD: fpu.c,v 1.11 2020/12/11 18:03:33 skrll Exp $");
__KERNEL_RCSID(1, "$NetBSD: fpu.c,v 1.12 2022/04/01 19:57:22 riastradh Exp $");
#include <sys/param.h>
#include <sys/types.h>
#include <sys/cpu.h>
#include <sys/kernel.h>
#include <sys/kthread.h>
#include <sys/lwp.h>
#include <sys/evcnt.h>
@ -213,7 +214,7 @@ fpu_kern_enter(void)
*/
s = splvm();
ci = curcpu();
KASSERTMSG(ci->ci_cpl <= IPL_VM, "cpl=%d", ci->ci_cpl);
KASSERTMSG(ci->ci_cpl <= IPL_VM || cold, "cpl=%d", ci->ci_cpl);
KASSERT(ci->ci_kfpu_spl == -1);
ci->ci_kfpu_spl = s;
@ -241,7 +242,7 @@ fpu_kern_leave(void)
ci = curcpu();
KASSERT(ci->ci_cpl == IPL_VM);
KASSERT(ci->ci_cpl == IPL_VM || cold);
KASSERT(ci->ci_kfpu_spl != -1);
/*

View File

@ -1,4 +1,4 @@
/* $NetBSD: vfp_init.c,v 1.76 2021/10/31 16:23:48 skrll Exp $ */
/* $NetBSD: vfp_init.c,v 1.77 2022/04/01 19:57:22 riastradh Exp $ */
/*
* Copyright (c) 2008 ARM Ltd
@ -32,12 +32,13 @@
#include "opt_cputypes.h"
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: vfp_init.c,v 1.76 2021/10/31 16:23:48 skrll Exp $");
__KERNEL_RCSID(0, "$NetBSD: vfp_init.c,v 1.77 2022/04/01 19:57:22 riastradh Exp $");
#include <sys/param.h>
#include <sys/types.h>
#include <sys/systm.h>
#include <sys/device.h>
#include <sys/kernel.h>
#include <sys/kthread.h>
#include <sys/proc.h>
#include <sys/cpu.h>
@ -694,7 +695,7 @@ fpu_kern_enter(void)
*/
s = splvm();
ci = curcpu();
KASSERTMSG(ci->ci_cpl <= IPL_VM, "cpl=%d", ci->ci_cpl);
KASSERTMSG(ci->ci_cpl <= IPL_VM || cold, "cpl=%d", ci->ci_cpl);
KASSERT(ci->ci_kfpu_spl == -1);
ci->ci_kfpu_spl = s;
@ -720,7 +721,7 @@ fpu_kern_leave(void)
return;
}
KASSERT(ci->ci_cpl == IPL_VM);
KASSERT(ci->ci_cpl == IPL_VM || cold);
KASSERT(ci->ci_kfpu_spl != -1);
/*

View File

@ -1,4 +1,4 @@
/* $NetBSD: cpu.c,v 1.202 2021/10/07 12:52:27 msaitoh Exp $ */
/* $NetBSD: cpu.c,v 1.203 2022/04/01 19:57:22 riastradh Exp $ */
/*
* Copyright (c) 2000-2020 NetBSD Foundation, Inc.
@ -62,7 +62,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: cpu.c,v 1.202 2021/10/07 12:52:27 msaitoh Exp $");
__KERNEL_RCSID(0, "$NetBSD: cpu.c,v 1.203 2022/04/01 19:57:22 riastradh Exp $");
#include "opt_ddb.h"
#include "opt_mpbios.h" /* for MPDEBUG */
@ -175,6 +175,7 @@ struct cpu_info cpu_info_primary __aligned(CACHE_LINE_SIZE) = {
.ci_idepth = -1,
.ci_curlwp = &lwp0,
.ci_curldt = -1,
.ci_kfpu_spl = -1,
};
struct cpu_info *cpu_info_list = &cpu_info_primary;

View File

@ -1,4 +1,4 @@
/* $NetBSD: fpu.c,v 1.76 2020/10/24 07:14:30 mgorny Exp $ */
/* $NetBSD: fpu.c,v 1.77 2022/04/01 19:57:22 riastradh Exp $ */
/*
* Copyright (c) 2008, 2019 The NetBSD Foundation, Inc. All
@ -96,7 +96,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: fpu.c,v 1.76 2020/10/24 07:14:30 mgorny Exp $");
__KERNEL_RCSID(0, "$NetBSD: fpu.c,v 1.77 2022/04/01 19:57:22 riastradh Exp $");
#include "opt_multiprocessor.h"
@ -380,7 +380,8 @@ fpu_kern_enter(void)
s = splvm();
ci = curcpu();
KASSERTMSG(ci->ci_ilevel <= IPL_VM, "ilevel=%d", ci->ci_ilevel);
KASSERTMSG(ci->ci_ilevel <= IPL_VM || cold, "ilevel=%d",
ci->ci_ilevel);
KASSERT(ci->ci_kfpu_spl == -1);
ci->ci_kfpu_spl = s;
@ -413,7 +414,7 @@ fpu_kern_leave(void)
struct cpu_info *ci = curcpu();
int s;
KASSERT(ci->ci_ilevel == IPL_VM);
KASSERT(ci->ci_ilevel == IPL_VM || cold);
KASSERT(ci->ci_kfpu_spl != -1);
/*