Module Name: src Committed By: rin Date: Tue Jun 1 00:30:22 UTC 2021
Modified Files: src/sys/arch/arm/vfp: vfp_init.c Log Message: PR port-arm/55790 Fix KASSERT failure with floating-point exception in userland. Consider the case in which curlwp owns enabled FPU in vfp_handler(). If FPE is raised, we must skip pcu_load(9) rather than just falling through. Otherwise, KASSERT fires in vfp_state_load(), since curlwp already owns enabled FPU. No regression for ATF is introduced. To generate a diff of this commit: cvs rdiff -u -r1.73 -r1.74 src/sys/arch/arm/vfp/vfp_init.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/arm/vfp/vfp_init.c diff -u src/sys/arch/arm/vfp/vfp_init.c:1.73 src/sys/arch/arm/vfp/vfp_init.c:1.74 --- src/sys/arch/arm/vfp/vfp_init.c:1.73 Tue Jun 1 00:13:19 2021 +++ src/sys/arch/arm/vfp/vfp_init.c Tue Jun 1 00:30:22 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: vfp_init.c,v 1.73 2021/06/01 00:13:19 rin Exp $ */ +/* $NetBSD: vfp_init.c,v 1.74 2021/06/01 00:30:22 rin Exp $ */ /* * Copyright (c) 2008 ARM Ltd @@ -32,7 +32,7 @@ #include "opt_cputypes.h" #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: vfp_init.c,v 1.73 2021/06/01 00:13:19 rin Exp $"); +__KERNEL_RCSID(0, "$NetBSD: vfp_init.c,v 1.74 2021/06/01 00:30:22 rin Exp $"); #include <sys/param.h> #include <sys/types.h> @@ -423,6 +423,7 @@ static int vfp_handler(u_int address, u_int insn, trapframe_t *frame, int fault_code) { struct cpu_info * const ci = curcpu(); + uint32_t fpexc; /* This shouldn't ever happen. */ if (fault_code != FAULT_USER && @@ -436,12 +437,19 @@ vfp_handler(u_int address, u_int insn, t /* * If we already own the FPU and it's enabled (and no exception), raise - * SIGILL. If there is an exception, drop through to raise a SIGFPE. + * SIGILL. If there is an exception, raise SIGFPE. */ - if (curlwp->l_pcu_cpu[PCU_FPU] == ci - && (armreg_fpexc_read() & (VFP_FPEXC_EX|VFP_FPEXC_EN)) == VFP_FPEXC_EN) { + if (curlwp->l_pcu_cpu[PCU_FPU] == ci) { KASSERT(ci->ci_pcu_curlwp[PCU_FPU] == curlwp); - return 1; + + fpexc = armreg_fpexc_read(); + if (fpexc & VFP_FPEXC_EN) { + if ((fpexc & VFP_FPEXC_EX) == 0) { + return 1; /* SIGILL */ + } else { + goto fpe; /* SIGFPE; skip pcu_load(9) */ + } + } } /* @@ -449,11 +457,12 @@ vfp_handler(u_int address, u_int insn, t */ pcu_load(&arm_vfp_ops); - uint32_t fpexc = armreg_fpexc_read(); + fpexc = armreg_fpexc_read(); if (fpexc & VFP_FPEXC_EX) { ksiginfo_t ksi; KASSERT(fpexc & VFP_FPEXC_EN); +fpe: curcpu()->ci_vfp_evs[2].ev_count++; /*