Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 12 Dec 2012 08:35:32 +0000 (UTC)
From:      Peter Grehan <grehan@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r244144 - in head/sys/amd64: amd64 include
Message-ID:  <201212120835.qBC8ZWeL000247@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: grehan
Date: Wed Dec 12 08:35:32 2012
New Revision: 244144
URL: http://svnweb.freebsd.org/changeset/base/244144

Log:
  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.
  
  Reviewed by:	kib
  Obtained from:	NetApp/bhyve
  MFC after:	1 week

Modified:
  head/sys/amd64/amd64/fpu.c
  head/sys/amd64/include/fpu.h

Modified: head/sys/amd64/amd64/fpu.c
==============================================================================
--- head/sys/amd64/amd64/fpu.c	Wed Dec 12 07:29:38 2012	(r244143)
+++ head/sys/amd64/amd64/fpu.c	Wed Dec 12 08:35:32 2012	(r244144)
@@ -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: head/sys/amd64/include/fpu.h
==============================================================================
--- head/sys/amd64/include/fpu.h	Wed Dec 12 07:29:38 2012	(r244143)
+++ head/sys/amd64/include/fpu.h	Wed Dec 12 08:35:32 2012	(r244144)
@@ -57,6 +57,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);
@@ -73,6 +74,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?201212120835.qBC8ZWeL000247>