From owner-svn-src-all@FreeBSD.ORG Wed Dec 12 08:35:33 2012 Return-Path: Delivered-To: svn-src-all@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id 6A96A58B; Wed, 12 Dec 2012 08:35:33 +0000 (UTC) (envelope-from grehan@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) by mx1.freebsd.org (Postfix) with ESMTP id 4F1B88FC0A; Wed, 12 Dec 2012 08:35:33 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.5/8.14.5) with ESMTP id qBC8ZXD2000249; Wed, 12 Dec 2012 08:35:33 GMT (envelope-from grehan@svn.freebsd.org) Received: (from grehan@localhost) by svn.freebsd.org (8.14.5/8.14.5/Submit) id qBC8ZWeL000247; Wed, 12 Dec 2012 08:35:32 GMT (envelope-from grehan@svn.freebsd.org) Message-Id: <201212120835.qBC8ZWeL000247@svn.freebsd.org> From: Peter Grehan Date: Wed, 12 Dec 2012 08:35:32 +0000 (UTC) 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 X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 12 Dec 2012 08:35:33 -0000 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 #include #include +#include #include #include @@ -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(). */