Module Name: src Committed By: maxv Date: Tue Oct 31 12:02:20 UTC 2017
Modified Files: src/sys/arch/amd64/include: pcb.h src/sys/arch/i386/include: pcb.h src/sys/arch/x86/include: cpu_extended_state.h src/sys/arch/x86/x86: fpu.c Log Message: Don't embed our own values in the reserved fields of the XSAVE area, it really is a bad idea. Move them into the PCB. To generate a diff of this commit: cvs rdiff -u -r1.26 -r1.27 src/sys/arch/amd64/include/pcb.h cvs rdiff -u -r1.56 -r1.57 src/sys/arch/i386/include/pcb.h cvs rdiff -u -r1.12 -r1.13 src/sys/arch/x86/include/cpu_extended_state.h cvs rdiff -u -r1.16 -r1.17 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/amd64/include/pcb.h diff -u src/sys/arch/amd64/include/pcb.h:1.26 src/sys/arch/amd64/include/pcb.h:1.27 --- src/sys/arch/amd64/include/pcb.h:1.26 Thu Feb 23 03:34:22 2017 +++ src/sys/arch/amd64/include/pcb.h Tue Oct 31 12:02:20 2017 @@ -1,6 +1,6 @@ -/* $NetBSD: pcb.h,v 1.26 2017/02/23 03:34:22 kamil Exp $ */ +/* $NetBSD: pcb.h,v 1.27 2017/10/31 12:02:20 maxv Exp $ */ -/*- +/* * Copyright (c) 1998 The NetBSD Foundation, Inc. * All rights reserved. * @@ -29,7 +29,7 @@ * POSSIBILITY OF SUCH DAMAGE. */ -/*- +/* * Copyright (c) 1990 The Regents of the University of California. * All rights reserved. * @@ -91,9 +91,10 @@ struct pcb { uint64_t pcb_fs; uint64_t pcb_gs; struct dbreg *pcb_dbregs; + uint16_t pcb_fpu_dflt_cw; int pcb_iopl; - uint32_t pcb_unused[9]; /* unused */ + uint32_t pcb_unused[8]; /* unused */ struct cpu_info *pcb_fpcpu; /* cpu holding our fp state. */ union savefpu pcb_savefpu __aligned(64); /* floating point state */ Index: src/sys/arch/i386/include/pcb.h diff -u src/sys/arch/i386/include/pcb.h:1.56 src/sys/arch/i386/include/pcb.h:1.57 --- src/sys/arch/i386/include/pcb.h:1.56 Sat Aug 12 12:48:47 2017 +++ src/sys/arch/i386/include/pcb.h Tue Oct 31 12:02:20 2017 @@ -1,6 +1,6 @@ -/* $NetBSD: pcb.h,v 1.56 2017/08/12 12:48:47 maxv Exp $ */ +/* $NetBSD: pcb.h,v 1.57 2017/10/31 12:02:20 maxv Exp $ */ -/*- +/* * Copyright (c) 1998, 2009 The NetBSD Foundation, Inc. * All rights reserved. * @@ -29,7 +29,7 @@ * POSSIBILITY OF SUCH DAMAGE. */ -/*- +/* * Copyright (c) 1990 The Regents of the University of California. * All rights reserved. * @@ -91,8 +91,9 @@ struct pcb { void *pcb_onfault; /* copyin/out fault recovery */ char *pcb_iomap; /* I/O permission bitmap */ struct dbreg *pcb_dbregs; /* CPU Debug Registers */ + uint16_t pcb_fpu_dflt_cw; - int not_used[17]; + int not_used[16]; /* floating point state */ struct cpu_info *pcb_fpcpu; /* cpu holding our fp state. */ Index: src/sys/arch/x86/include/cpu_extended_state.h diff -u src/sys/arch/x86/include/cpu_extended_state.h:1.12 src/sys/arch/x86/include/cpu_extended_state.h:1.13 --- src/sys/arch/x86/include/cpu_extended_state.h:1.12 Tue Oct 31 10:39:13 2017 +++ src/sys/arch/x86/include/cpu_extended_state.h Tue Oct 31 12:02:20 2017 @@ -1,4 +1,4 @@ -/* $NetBSD: cpu_extended_state.h,v 1.12 2017/10/31 10:39:13 maxv Exp $ */ +/* $NetBSD: cpu_extended_state.h,v 1.13 2017/10/31 12:02:20 maxv Exp $ */ #ifndef _X86_CPU_EXTENDED_STATE_H_ #define _X86_CPU_EXTENDED_STATE_H_ @@ -120,15 +120,6 @@ struct fxsave { __CTASSERT_NOLINT(sizeof(struct fxsave) == 512); /* - * The end of the fsave buffer can be used by the operating system - */ -struct fxsave_os { - uint8_t fxo_fxsave[512 - 48]; - /* 48 bytes available, NB copied to/from userspace */ - uint16_t fxo_dflt_cw; /* Control word for signal handlers */ -}; - -/* * For XSAVE, a 64byte header follows the fxsave data. */ struct xsave_header { @@ -158,7 +149,6 @@ union savefpu { struct save87 sv_87; struct fxsave sv_xmm; #ifdef _KERNEL - struct fxsave_os sv_os; struct xsave_header sv_xsave_hdr; #endif }; Index: src/sys/arch/x86/x86/fpu.c diff -u src/sys/arch/x86/x86/fpu.c:1.16 src/sys/arch/x86/x86/fpu.c:1.17 --- src/sys/arch/x86/x86/fpu.c:1.16 Tue Oct 31 11:37:05 2017 +++ src/sys/arch/x86/x86/fpu.c Tue Oct 31 12:02:20 2017 @@ -1,4 +1,4 @@ -/* $NetBSD: fpu.c,v 1.16 2017/10/31 11:37:05 maxv Exp $ */ +/* $NetBSD: fpu.c,v 1.17 2017/10/31 12:02:20 maxv Exp $ */ /* * Copyright (c) 2008 The NetBSD Foundation, Inc. All @@ -96,7 +96,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: fpu.c,v 1.16 2017/10/31 11:37:05 maxv Exp $"); +__KERNEL_RCSID(0, "$NetBSD: fpu.c,v 1.17 2017/10/31 12:02:20 maxv Exp $"); #include "opt_multiprocessor.h" @@ -493,21 +493,24 @@ void fpu_set_default_cw(struct lwp *l, unsigned int x87_cw) { union savefpu *fpu_save = process_fpframe(l); + struct pcb *pcb = lwp_getpcb(l); if (i386_use_fxsave) fpu_save->sv_xmm.fx_cw = x87_cw; else fpu_save->sv_87.s87_cw = x87_cw; - fpu_save->sv_os.fxo_dflt_cw = x87_cw; + pcb->pcb_fpu_dflt_cw = x87_cw; } void fpu_save_area_clear(struct lwp *l, unsigned int x87_cw) { union savefpu *fpu_save; + struct pcb *pcb; fpusave_lwp(l, false); fpu_save = process_fpframe(l); + pcb = lwp_getpcb(l); if (i386_use_fxsave) { memset(&fpu_save->sv_xmm, 0, x86_fpu_save_size); @@ -519,13 +522,14 @@ fpu_save_area_clear(struct lwp *l, unsig fpu_save->sv_87.s87_tw = 0xffff; fpu_save->sv_87.s87_cw = x87_cw; } - fpu_save->sv_os.fxo_dflt_cw = x87_cw; + pcb->pcb_fpu_dflt_cw = x87_cw; } void fpu_save_area_reset(struct lwp *l) { union savefpu *fpu_save = process_fpframe(l); + struct pcb *pcb = lwp_getpcb(l); /* * For signal handlers the register values don't matter. Just reset @@ -535,10 +539,10 @@ fpu_save_area_reset(struct lwp *l) fpu_save->sv_xmm.fx_mxcsr = __INITIAL_MXCSR__; fpu_save->sv_xmm.fx_mxcsr_mask = __INITIAL_MXCSR_MASK__; fpu_save->sv_xmm.fx_tw = 0; - fpu_save->sv_xmm.fx_cw = fpu_save->sv_os.fxo_dflt_cw; + fpu_save->sv_xmm.fx_cw = pcb->pcb_fpu_dflt_cw; } else { fpu_save->sv_87.s87_tw = 0xffff; - fpu_save->sv_87.s87_cw = fpu_save->sv_os.fxo_dflt_cw; + fpu_save->sv_87.s87_cw = pcb->pcb_fpu_dflt_cw; } }