Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys Remove all references to MDL_USEDFPU and deferred fpu in...
details: https://anonhg.NetBSD.org/src/rev/f43f4dcf7ee1
branches: trunk
changeset: 326733:f43f4dcf7ee1
user: dsl <dsl%NetBSD.org@localhost>
date: Sat Feb 15 10:11:14 2014 +0000
description:
Remove all references to MDL_USEDFPU and deferred fpu initialisation.
The cost of zeroing the save area on exec is minimal.
This stops the FP registers of a random process being used the first
time an lwp uses the fpu.
sendsig_siginfo() and get_mcontext() now unconditionally copy the FP
registers.
I'll remove the double-copy for signal handlers soon.
get_mcontext() might have been leaking kernel memory to userspace - and
may still do so if i386_use_fxsave is false (short copies).
diffstat:
sys/arch/amd64/amd64/genassym.cf | 3 +-
sys/arch/amd64/amd64/machdep.c | 60 ++++------------
sys/arch/amd64/amd64/netbsd32_machdep.c | 51 ++++---------
sys/arch/amd64/amd64/process_machdep.c | 41 +---------
sys/arch/amd64/include/proc.h | 3 +-
sys/arch/i386/i386/compat_16_machdep.c | 7 +-
sys/arch/i386/i386/genassym.cf | 3 +-
sys/arch/i386/i386/machdep.c | 88 +++++++++---------------
sys/arch/i386/i386/process_machdep.c | 81 ++--------------------
sys/arch/i386/include/proc.h | 3 +-
sys/arch/x86/include/cpu.h | 6 +-
sys/arch/x86/include/cpu_extended_state.h | 7 +-
sys/arch/x86/include/fpu.h | 10 ++-
sys/arch/x86/x86/fpu.c | 82 +++++++++++++++-------
sys/arch/x86/x86/vm_machdep.c | 13 +--
sys/compat/linux/arch/amd64/linux_machdep.c | 25 +-----
sys/compat/linux/arch/i386/linux_machdep.c | 18 +----
sys/compat/linux32/arch/amd64/linux32_machdep.c | 14 +--
18 files changed, 174 insertions(+), 341 deletions(-)
diffs (truncated from 1111 to 300 lines):
diff -r a315fc716355 -r f43f4dcf7ee1 sys/arch/amd64/amd64/genassym.cf
--- a/sys/arch/amd64/amd64/genassym.cf Sat Feb 15 09:43:02 2014 +0000
+++ b/sys/arch/amd64/amd64/genassym.cf Sat Feb 15 10:11:14 2014 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: genassym.cf,v 1.54 2013/12/01 01:05:16 christos Exp $
+# $NetBSD: genassym.cf,v 1.55 2014/02/15 10:11:14 dsl Exp $
#
# Copyright (c) 1998, 2006, 2007, 2008 The NetBSD Foundation, Inc.
@@ -185,7 +185,6 @@
define PCB_RSP0 offsetof(struct pcb, pcb_rsp0)
define PCB_CR0 offsetof(struct pcb, pcb_cr0)
define PCB_ONFAULT offsetof(struct pcb, pcb_onfault)
-define PCB_FPCPU offsetof(struct pcb, pcb_fpcpu)
define PCB_FLAGS offsetof(struct pcb, pcb_flags)
define PCB_COMPAT32 PCB_COMPAT32
define PCB_FS offsetof(struct pcb, pcb_fs)
diff -r a315fc716355 -r f43f4dcf7ee1 sys/arch/amd64/amd64/machdep.c
--- a/sys/arch/amd64/amd64/machdep.c Sat Feb 15 09:43:02 2014 +0000
+++ b/sys/arch/amd64/amd64/machdep.c Sat Feb 15 10:11:14 2014 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: machdep.c,v 1.203 2014/02/11 20:17:16 dsl Exp $ */
+/* $NetBSD: machdep.c,v 1.204 2014/02/15 10:11:14 dsl Exp $ */
/*-
* Copyright (c) 1996, 1997, 1998, 2000, 2006, 2007, 2008, 2011
@@ -111,7 +111,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.203 2014/02/11 20:17:16 dsl Exp $");
+__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.204 2014/02/15 10:11:14 dsl Exp $");
/* #define XENDEBUG_LOW */
@@ -548,8 +548,8 @@
tf->tf_rsp = (uint64_t)f;
tf->tf_ss = GSEL(GUDATA_SEL, SEL_UPL);
- /* Ensure FP state is reset, if FP is used. */
- l->l_md.md_flags &= ~MDL_USEDFPU;
+ /* Ensure FP state is sane */
+ fpu_save_area_reset(l);
}
void
@@ -566,7 +566,7 @@
struct lwp *l = curlwp;
struct proc *p = l->l_proc;
struct sigacts *ps = p->p_sigacts;
- int onstack, tocopy, error;
+ int onstack, error;
int sig = ksi->ksi_signo;
struct sigframe_siginfo *fp, frame;
sig_t catcher = SIGACTION(p, sig).sa_handler;
@@ -587,21 +587,9 @@
sp = (char *)tf->tf_rsp - 128;
sp -= sizeof(struct sigframe_siginfo);
- /*
- * Round down the stackpointer to a multiple of 16 for
- * fxsave and the ABI.
- */
+ /* Round down the stackpointer to a multiple of 16 for the ABI. */
fp = (struct sigframe_siginfo *)(((unsigned long)sp & ~15) - 8);
- /*
- * Don't bother copying out FP state if there is none.
- */
- if (l->l_md.md_flags & MDL_USEDFPU)
- tocopy = sizeof (struct sigframe_siginfo);
- else
- tocopy = sizeof (struct sigframe_siginfo) -
- sizeof (frame.sf_uc.uc_mcontext.__fpregs);
-
frame.sf_ra = (uint64_t)ps->sa_sigdesc[sig].sd_tramp;
frame.sf_si._info = ksi->ksi_info;
frame.sf_uc.uc_flags = _UC_SIGMASK;
@@ -614,7 +602,8 @@
mutex_exit(p->p_lock);
cpu_getmcontext(l, &frame.sf_uc.uc_mcontext, &frame.sf_uc.uc_flags);
- error = copyout(&frame, fp, tocopy);
+ /* Copyout all the fp regs, the signal handler might expect them. */
+ error = copyout(&frame, fp, sizeof frame);
mutex_enter(p->p_lock);
if (error != 0) {
@@ -1329,23 +1318,13 @@
struct pcb *pcb = lwp_getpcb(l);
struct trapframe *tf;
- /* If we were using the FPU, forget about it. */
- if (pcb->pcb_fpcpu != NULL) {
- fpusave_lwp(l, false);
- }
-
#ifdef USER_LDT
pmap_ldt_cleanup(l);
#endif
- l->l_md.md_flags &= ~MDL_USEDFPU;
+ fpu_save_area_clear(l, pack->ep_osversion >= 699002600
+ ? __NetBSD_NPXCW__ : __NetBSD_COMPAT_NPXCW__);
pcb->pcb_flags = 0;
- if (pack->ep_osversion >= 699002600)
- pcb->pcb_savefpu.sv_xmm.fx_cw = __NetBSD_NPXCW__;
- else
- pcb->pcb_savefpu.sv_xmm.fx_cw = __NetBSD_COMPAT_NPXCW__;
- pcb->pcb_savefpu.sv_xmm.fx_mxcsr = __INITIAL_MXCSR__;
- pcb->pcb_savefpu.sv_xmm.fx_mxcsr_mask = __INITIAL_MXCSR_MASK__;
l->l_proc->p_flag &= ~PK_32;
@@ -1917,6 +1896,7 @@
cpu_getmcontext(struct lwp *l, mcontext_t *mcp, unsigned int *flags)
{
const struct trapframe *tf = l->l_md.md_regs;
+ struct pcb *pcb;
__greg_t ras_rip;
/* Copy general registers member by member */
@@ -1933,16 +1913,11 @@
mcp->_mc_tlsbase = (uintptr_t)l->l_private;;
*flags |= _UC_TLSBASE;
- if ((l->l_md.md_flags & MDL_USEDFPU) != 0) {
- struct pcb *pcb = lwp_getpcb(l);
+ pcb = lwp_getpcb(l);
- if (pcb->pcb_fpcpu) {
- fpusave_lwp(l, true);
- }
- memcpy(mcp->__fpregs, &pcb->pcb_savefpu.sv_xmm,
- sizeof (mcp->__fpregs));
- *flags |= _UC_FPU;
- }
+ fpusave_lwp(l, true);
+ memcpy(mcp->__fpregs, &pcb->pcb_savefpu.sv_xmm, sizeof (mcp->__fpregs));
+ *flags |= _UC_FPU;
}
int
@@ -1991,13 +1966,10 @@
l->l_md.md_flags |= MDL_IRET;
}
- if (pcb->pcb_fpcpu != NULL)
+ if ((flags & _UC_FPU) != 0) {
fpusave_lwp(l, false);
-
- if ((flags & _UC_FPU) != 0) {
memcpy(&pcb->pcb_savefpu.sv_xmm, mcp->__fpregs,
sizeof (mcp->__fpregs));
- l->l_md.md_flags |= MDL_USEDFPU;
}
if ((flags & _UC_TLSBASE) != 0)
diff -r a315fc716355 -r f43f4dcf7ee1 sys/arch/amd64/amd64/netbsd32_machdep.c
--- a/sys/arch/amd64/amd64/netbsd32_machdep.c Sat Feb 15 09:43:02 2014 +0000
+++ b/sys/arch/amd64/amd64/netbsd32_machdep.c Sat Feb 15 10:11:14 2014 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: netbsd32_machdep.c,v 1.90 2014/02/11 20:17:16 dsl Exp $ */
+/* $NetBSD: netbsd32_machdep.c,v 1.91 2014/02/15 10:11:14 dsl Exp $ */
/*
* Copyright (c) 2001 Wasabi Systems, Inc.
@@ -36,7 +36,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: netbsd32_machdep.c,v 1.90 2014/02/11 20:17:16 dsl Exp $");
+__KERNEL_RCSID(0, "$NetBSD: netbsd32_machdep.c,v 1.91 2014/02/15 10:11:14 dsl Exp $");
#ifdef _KERNEL_OPT
#include "opt_compat_netbsd.h"
@@ -128,26 +128,17 @@
pcb = lwp_getpcb(l);
- /* If we were using the FPU, forget about it. */
- if (pcb->pcb_fpcpu != NULL) {
- fpusave_lwp(l, false);
- }
-
#if defined(USER_LDT) && 0
pmap_ldt_cleanup(p);
#endif
netbsd32_adjust_limits(p);
- l->l_md.md_flags &= ~MDL_USEDFPU;
l->l_md.md_flags |= MDL_COMPAT32; /* Force iret not sysret */
pcb->pcb_flags = PCB_COMPAT32;
- if (pack->ep_osversion >= 699002600)
- pcb->pcb_savefpu.sv_xmm.fx_cw = __NetBSD_NPXCW__;
- else
- pcb->pcb_savefpu.sv_xmm.fx_cw = __NetBSD_COMPAT_NPXCW__;
- pcb->pcb_savefpu.sv_xmm.fx_mxcsr = __INITIAL_MXCSR__;
- pcb->pcb_savefpu.sv_xmm.fx_mxcsr_mask = __INITIAL_MXCSR_MASK__;
+
+ fpu_save_area_clear(l, pack->ep_osversion >= 699002600
+ ? __NetBSD_NPXCW__ : __NetBSD_COMPAT_NPXCW__);
p->p_flag |= PK_32;
@@ -263,8 +254,8 @@
tf->tf_fs = GSEL(GUDATA32_SEL, SEL_UPL);
tf->tf_gs = GSEL(GUDATA32_SEL, SEL_UPL);
- /* Ensure FP state is reset, if FP is used. */
- l->l_md.md_flags &= ~MDL_USEDFPU;
+ /* Ensure FP state is sane. */
+ fpu_save_area_reset(l);
tf->tf_rip = (uint64_t)catcher;
tf->tf_cs = GSEL(GUCODE32_SEL, SEL_UPL);
@@ -366,8 +357,8 @@
tf->tf_rsp = (uint64_t)fp;
tf->tf_ss = GSEL(GUDATA32_SEL, SEL_UPL);
- /* Ensure FP state is reset, if FP is used. */
- l->l_md.md_flags &= ~MDL_USEDFPU;
+ /* Ensure FP state is sane. */
+ fpu_save_area_reset(l);
/* Remember that we're now on the signal stack. */
if (onstack)
@@ -820,13 +811,9 @@
/*
* If we were using the FPU, forget that we were.
*/
- if (pcb->pcb_fpcpu != NULL) {
- fpusave_lwp(l, false);
- }
+ fpusave_lwp(l, false);
memcpy(&pcb->pcb_savefpu.sv_xmm, &mcp->__fpregs,
sizeof (pcb->pcb_savefpu.sv_xmm));
- /* If not set already. */
- l->l_md.md_flags |= MDL_USEDFPU;
}
mutex_enter(p->p_lock);
@@ -845,6 +832,7 @@
const struct trapframe *tf = l->l_md.md_regs;
__greg32_t *gr = mcp->__gregs;
__greg32_t ras_eip;
+ struct pcb *pcb;
/* Save register context. */
gr[_REG32_GS] = tf->tf_gs;
@@ -876,17 +864,12 @@
mcp->_mc_tlsbase = (uint32_t)(uintptr_t)l->l_private;
*flags |= _UC_TLSBASE;
- /* Save floating point register context, if any. */
- if ((l->l_md.md_flags & MDL_USEDFPU) != 0) {
- struct pcb *pcb = lwp_getpcb(l);
-
- if (pcb->pcb_fpcpu) {
- fpusave_lwp(l, true);
- }
- memcpy(&mcp->__fpregs, &pcb->pcb_savefpu.sv_xmm,
- sizeof (pcb->pcb_savefpu.sv_xmm));
- *flags |= _UC_FPU;
- }
+ /* Save floating point register context. */
+ fpusave_lwp(l, true);
+ pcb = lwp_getpcb(l);
+ memcpy(&mcp->__fpregs, &pcb->pcb_savefpu.sv_xmm,
+ sizeof (pcb->pcb_savefpu.sv_xmm));
+ *flags |= _UC_FPU;
}
void
diff -r a315fc716355 -r f43f4dcf7ee1 sys/arch/amd64/amd64/process_machdep.c
--- a/sys/arch/amd64/amd64/process_machdep.c Sat Feb 15 09:43:02 2014 +0000
+++ b/sys/arch/amd64/amd64/process_machdep.c Sat Feb 15 10:11:14 2014 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: process_machdep.c,v 1.27 2014/02/11 20:17:16 dsl Exp $ */
+/* $NetBSD: process_machdep.c,v 1.28 2014/02/15 10:11:14 dsl Exp $ */
/*-
* Copyright (c) 1998, 2000 The NetBSD Foundation, Inc.
@@ -53,7 +53,7 @@
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: process_machdep.c,v 1.27 2014/02/11 20:17:16 dsl Exp $");
+__KERNEL_RCSID(0, "$NetBSD: process_machdep.c,v 1.28 2014/02/15 10:11:14 dsl Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@@ -103,34 +103,12 @@
}
int
-process_read_fpregs(struct lwp *l, struct fpreg *regs,size_t *sz)
+process_read_fpregs(struct lwp *l, struct fpreg *regs, size_t *sz)
{
Home |
Main Index |
Thread Index |
Old Index