Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 4 Jan 2013 19:29:23 +0000 (UTC)
From:      Peter Grehan <grehan@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-9@freebsd.org
Subject:   svn commit: r245046 - in stable/9/sys/amd64: amd64 include
Message-ID:  <201301041929.r04JTNkM005991@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: grehan
Date: Fri Jan  4 19:29:23 2013
New Revision: 245046
URL: http://svnweb.freebsd.org/changeset/base/245046

Log:
  MFC r244144
  
  Implement an API to allow a hypervisor to save/restore
  guest floating point state without having to know the
  size of floating-point state.
  
  Unstaticize fpurestore to allow the hypervisor to
  save/restore guest state using fpusave/fpurestore
  on the allocated FPU state area.

Modified:
  stable/9/sys/amd64/amd64/fpu.c
  stable/9/sys/amd64/include/fpu.h
Directory Properties:
  stable/9/sys/   (props changed)

Modified: stable/9/sys/amd64/amd64/fpu.c
==============================================================================
--- stable/9/sys/amd64/amd64/fpu.c	Fri Jan  4 19:28:32 2013	(r245045)
+++ stable/9/sys/amd64/amd64/fpu.c	Fri Jan  4 19:29:23 2013	(r245046)
@@ -47,6 +47,7 @@ __FBSDID("$FreeBSD$");
 #include <machine/bus.h>
 #include <sys/rman.h>
 #include <sys/signalvar.h>
+#include <vm/uma.h>
 
 #include <machine/cputypes.h>
 #include <machine/frame.h>
@@ -134,6 +135,7 @@ SYSCTL_INT(_hw, HW_FLOATINGPT, floatingp
 static int use_xsaveopt;
 int use_xsave;			/* non-static for cpu_switch.S */
 uint64_t xsave_mask;		/* the same */
+static	uma_zone_t fpu_save_area_zone;
 static	struct savefpu *fpu_initialstate;
 
 struct xsave_area_elm_descr {
@@ -151,7 +153,7 @@ fpusave(void *addr)
 		fxsave((char *)addr);
 }
 
-static void
+void
 fpurestore(void *addr)
 {
 
@@ -312,6 +314,10 @@ fpuinitstate(void *arg __unused)
 		}
 	}
 
+	fpu_save_area_zone = uma_zcreate("FPU_save_area",
+	    cpu_max_ext_state_size, NULL, NULL, NULL, NULL,
+	    XSAVE_AREA_ALIGN - 1, 0);
+
 	start_emulating();
 	intr_restore(saveintr);
 }
@@ -980,3 +986,27 @@ is_fpu_kern_thread(u_int flags)
 		return (0);
 	return ((curpcb->pcb_flags & PCB_KERNFPU) != 0);
 }
+
+/*
+ * FPU save area alloc/free/init utility routines
+ */
+struct savefpu *
+fpu_save_area_alloc(void)
+{
+
+	return (uma_zalloc(fpu_save_area_zone, 0));
+}
+
+void
+fpu_save_area_free(struct savefpu *fsa)
+{
+
+	uma_zfree(fpu_save_area_zone, fsa);
+}
+
+void
+fpu_save_area_reset(struct savefpu *fsa)
+{
+
+	bcopy(fpu_initialstate, fsa, cpu_max_ext_state_size);
+}

Modified: stable/9/sys/amd64/include/fpu.h
==============================================================================
--- stable/9/sys/amd64/include/fpu.h	Fri Jan  4 19:28:32 2013	(r245045)
+++ stable/9/sys/amd64/include/fpu.h	Fri Jan  4 19:29:23 2013	(r245046)
@@ -140,6 +140,7 @@ void	fpuexit(struct thread *td);
 int	fpuformat(void);
 int	fpugetregs(struct thread *td);
 void	fpuinit(void);
+void	fpurestore(void *addr);
 void	fpusave(void *addr);
 int	fpusetregs(struct thread *td, struct savefpu *addr,
 	    char *xfpustate, size_t xfpustate_size);
@@ -156,6 +157,10 @@ int	fpu_kern_leave(struct thread *td, st
 int	fpu_kern_thread(u_int flags);
 int	is_fpu_kern_thread(u_int flags);
 
+struct savefpu	*fpu_save_area_alloc(void);
+void	fpu_save_area_free(struct savefpu *fsa);
+void	fpu_save_area_reset(struct savefpu *fsa);
+
 /*
  * Flags for fpu_kern_alloc_ctx(), fpu_kern_enter() and fpu_kern_thread().
  */



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201301041929.r04JTNkM005991>