Module Name: src Committed By: riastradh Date: Fri Mar 3 14:32:38 UTC 2023
Modified Files: src/sys/arch/x86/x86: fpu.c Log Message: Revert "x86/fpu.c: Sprinkle KNF." kthread_fpu_enter/exit changes broke some hardware, unclear why, to investigate before fixing and reapplying these changes. To generate a diff of this commit: cvs rdiff -u -r1.83 -r1.84 src/sys/arch/x86/x86/fpu.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/x86/x86/fpu.c diff -u src/sys/arch/x86/x86/fpu.c:1.83 src/sys/arch/x86/x86/fpu.c:1.84 --- src/sys/arch/x86/x86/fpu.c:1.83 Sat Feb 25 18:28:57 2023 +++ src/sys/arch/x86/x86/fpu.c Fri Mar 3 14:32:38 2023 @@ -1,4 +1,4 @@ -/* $NetBSD: fpu.c,v 1.83 2023/02/25 18:28:57 riastradh Exp $ */ +/* $NetBSD: fpu.c,v 1.84 2023/03/03 14:32:38 riastradh Exp $ */ /* * Copyright (c) 2008, 2019 The NetBSD Foundation, Inc. All @@ -96,38 +96,35 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: fpu.c,v 1.83 2023/02/25 18:28:57 riastradh Exp $"); +__KERNEL_RCSID(0, "$NetBSD: fpu.c,v 1.84 2023/03/03 14:32:38 riastradh Exp $"); #include "opt_multiprocessor.h" #include <sys/param.h> -#include <sys/types.h> - +#include <sys/systm.h> #include <sys/conf.h> #include <sys/cpu.h> #include <sys/file.h> +#include <sys/proc.h> #include <sys/kernel.h> #include <sys/kthread.h> -#include <sys/proc.h> #include <sys/sysctl.h> -#include <sys/systm.h> #include <sys/xcall.h> #include <machine/cpu.h> -#include <machine/cpufunc.h> -#include <machine/cputypes.h> #include <machine/cpuvar.h> +#include <machine/cputypes.h> #include <machine/intr.h> +#include <machine/cpufunc.h> #include <machine/pcb.h> -#include <machine/specialreg.h> #include <machine/trap.h> - +#include <machine/specialreg.h> #include <x86/cpu.h> #include <x86/fpu.h> #ifdef XENPV -#define clts() HYPERVISOR_fpu_taskswitch(0) -#define stts() HYPERVISOR_fpu_taskswitch(1) +#define clts() HYPERVISOR_fpu_taskswitch(0) +#define stts() HYPERVISOR_fpu_taskswitch(1) #endif void fpu_handle_deferred(void); @@ -182,8 +179,7 @@ fpu_save_lwp(struct lwp *l) s = splvm(); if (l->l_md.md_flags & MDL_FPU_IN_CPU) { KASSERT(lwp_can_haz_fpu(l)); - fpu_area_save(area, x86_xsave_features, - !(l->l_proc->p_flag & PK_32)); + fpu_area_save(area, x86_xsave_features, !(l->l_proc->p_flag & PK_32)); l->l_md.md_flags &= ~MDL_FPU_IN_CPU; } splx(s); @@ -196,14 +192,12 @@ fpu_save_lwp(struct lwp *l) void fpu_save(void) { - fpu_save_lwp(curlwp); } void fpuinit(struct cpu_info *ci) { - /* * This might not be strictly necessary since it will be initialized * for each process. However it does no harm. @@ -284,7 +278,6 @@ fpu_errata_amd(void) void fpu_area_save(void *area, uint64_t xsave_features, bool is_64bit) { - switch (x86_fpu_save) { case FPU_SAVE_FSAVE: fnsave(area); @@ -306,7 +299,6 @@ fpu_area_save(void *area, uint64_t xsave void fpu_area_restore(const void *area, uint64_t xsave_features, bool is_64bit) { - clts(); switch (x86_fpu_save) { @@ -331,7 +323,6 @@ void fpu_handle_deferred(void) { struct pcb *pcb = lwp_getpcb(curlwp); - fpu_area_restore(&pcb->pcb_savefpu, x86_xsave_features, !(curlwp->l_proc->p_flag & PK_32)); } @@ -388,7 +379,7 @@ fpu_lwp_abandon(struct lwp *l) splx(s); } -/* ------------------------------------------------------------------------- */ +/* -------------------------------------------------------------------------- */ static const union savefpu safe_fpu __aligned(64) = { .sv_xmm = { @@ -437,8 +428,8 @@ fpu_kern_enter(void) ci->ci_kfpu_spl = s; /* - * If we are in a softint and have a pinned lwp, the fpu state - * is that of the pinned lwp, so save it there. + * If we are in a softint and have a pinned lwp, the fpu state is that + * of the pinned lwp, so save it there. */ while ((l->l_pflag & LP_INTR) && (l->l_switchto != NULL)) l = l->l_switchto; @@ -522,7 +513,7 @@ kthread_fpu_exit_md(void) stts(); } -/* ------------------------------------------------------------------------- */ +/* -------------------------------------------------------------------------- */ /* * The following table is used to ensure that the FPE_... value @@ -676,7 +667,6 @@ fpudna(struct trapframe *frame) static inline void fpu_xstate_reload(union savefpu *fpu_save, uint64_t xstate) { - /* * Force a reload of the given xstate during the next XRSTOR. */ @@ -875,7 +865,6 @@ process_read_xstate(struct lwp *l, struc int process_verify_xstate(const struct xstate *xstate) { - /* xstate_bv must be a subset of RFBM */ if (xstate->xs_xstate_bv & ~xstate->xs_rfbm) return EINVAL; @@ -905,10 +894,8 @@ process_write_xstate(struct lwp *l, cons /* Convert data into legacy FSAVE format. */ if (x86_fpu_save == FPU_SAVE_FSAVE) { - if (xstate->xs_xstate_bv & XCR0_X87) { - process_xmm_to_s87(&xstate->xs_fxsave, - &fpu_save->sv_87); - } + if (xstate->xs_xstate_bv & XCR0_X87) + process_xmm_to_s87(&xstate->xs_fxsave, &fpu_save->sv_87); return 0; } @@ -941,16 +928,15 @@ process_write_xstate(struct lwp *l, cons /* * Invalid bits in mxcsr or mxcsr_mask will cause faults. */ - fpu_save->sv_xmm.fx_mxcsr_mask = - xstate->xs_fxsave.fx_mxcsr_mask & x86_fpu_mxcsr_mask; + fpu_save->sv_xmm.fx_mxcsr_mask = xstate->xs_fxsave.fx_mxcsr_mask + & x86_fpu_mxcsr_mask; fpu_save->sv_xmm.fx_mxcsr = xstate->xs_fxsave.fx_mxcsr & fpu_save->sv_xmm.fx_mxcsr_mask; } if (xstate->xs_xstate_bv & XCR0_SSE) { memcpy(&fpu_save->sv_xsave_hdr.xsh_fxsave[160], - xstate->xs_fxsave.fx_xmm, - sizeof(xstate->xs_fxsave.fx_xmm)); + xstate->xs_fxsave.fx_xmm, sizeof(xstate->xs_fxsave.fx_xmm)); } #define COPY_COMPONENT(xcr0_val, xsave_val, field) \