From patchwork Fri May 14 03:16:51 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sheng Yang X-Patchwork-Id: 99524 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter.kernel.org (8.14.3/8.14.3) with ESMTP id o4E3JV48013314 for ; Fri, 14 May 2010 03:19:31 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754478Ab0ENDSW (ORCPT ); Thu, 13 May 2010 23:18:22 -0400 Received: from mga11.intel.com ([192.55.52.93]:3164 "EHLO mga11.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752192Ab0ENDSU (ORCPT ); Thu, 13 May 2010 23:18:20 -0400 Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by fmsmga102.fm.intel.com with ESMTP; 13 May 2010 20:16:11 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="4.53,226,1272870000"; d="scan'208";a="567057705" Received: from syang10-desktop.sh.intel.com (HELO syang10-desktop) ([10.239.36.64]) by fmsmga002.fm.intel.com with ESMTP; 13 May 2010 20:17:30 -0700 Received: from yasker by syang10-desktop with local (Exim 4.71) (envelope-from ) id 1OClOW-0001Fo-3w; Fri, 14 May 2010 11:17:00 +0800 From: Sheng Yang To: Avi Kivity , Marcelo Tosatti Cc: Ingo Molnar , "H. Peter Anvin" , kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Sheng Yang Subject: [PATCH 1/3] x86: Split fpu_save_init() to fpu_save() and fpu_clear() Date: Fri, 14 May 2010 11:16:51 +0800 Message-Id: <1273807013-4792-2-git-send-email-sheng@linux.intel.com> X-Mailer: git-send-email 1.7.0.4 In-Reply-To: <1273807013-4792-1-git-send-email-sheng@linux.intel.com> References: <1273807013-4792-1-git-send-email-sheng@linux.intel.com> Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.3 (demeter.kernel.org [140.211.167.41]); Fri, 14 May 2010 03:19:31 +0000 (UTC) diff --git a/arch/x86/include/asm/i387.h b/arch/x86/include/asm/i387.h index 1a8cca3..989d3b7 100644 --- a/arch/x86/include/asm/i387.h +++ b/arch/x86/include/asm/i387.h @@ -180,13 +180,17 @@ static inline void fpu_fxsave(struct fpu *fpu) #endif } -static inline void fpu_save_init(struct fpu *fpu) +static inline void fpu_save(struct fpu *fpu) { if (use_xsave()) fpu_xsave(fpu); else fpu_fxsave(fpu); +} +static inline void fpu_save_init(struct fpu *fpu) +{ + fpu_save(fpu); fpu_clear(fpu); } @@ -237,19 +241,41 @@ static inline int fxrstor_checking(struct i387_fxsave_struct *fx) /* * These must be called with preempt disabled */ -static inline void fpu_save_init(struct fpu *fpu) +static inline void fpu_fxsave(struct fpu *fpu) { - if (use_xsave()) { - struct xsave_struct *xstate = &fpu->state->xsave; - struct i387_fxsave_struct *fx = &fpu->state->fxsave; + /* Use more nops than strictly needed in case the compiler + varies code */ + alternative_input( + "fnsave %[fx] ;fwait;" GENERIC_NOP8 GENERIC_NOP4, + "fxsave %[fx]\n" + "bt $7,%[fsw] ; jnc 1f ; fnclex\n1:", + X86_FEATURE_FXSR, + [fx] "m" (fpu->state->fxsave), + [fsw] "m" (fpu->state->fxsave.swd) : "memory"); +} +static inline void fpu_save(struct fpu *fpu) +{ + if (use_xsave()) fpu_xsave(fpu); + else + fpu_fxsave(fpu); +} + +/* AMD K7/K8 CPUs don't save/restore FDP/FIP/FOP unless an exception + is pending. Clear the x87 state here by setting it to fixed + values. safe_address is a random variable that should be in L1 */ +static inline void fpu_clear(struct fpu *fpu) +{ + struct xsave_struct *xstate = &fpu->state->xsave; + struct i387_fxsave_struct *fx = &fpu->state->fxsave; + if (use_xsave()) { /* * xsave header may indicate the init state of the FP. */ if (!(xstate->xsave_hdr.xstate_bv & XSTATE_FP)) - goto end; + return; if (unlikely(fx->swd & X87_FSW_ES)) asm volatile("fnclex"); @@ -257,30 +283,19 @@ static inline void fpu_save_init(struct fpu *fpu) /* * we can do a simple return here or be paranoid :) */ - goto clear_state; } + alternative_input( + GENERIC_NOP8 GENERIC_NOP2, + "emms\n\t" /* clear stack tags */ + "fildl %[addr]", /* set F?P to defined value */ + X86_FEATURE_FXSAVE_LEAK, + [addr] "m" (safe_address)); +} - /* Use more nops than strictly needed in case the compiler - varies code */ - alternative_input( - "fnsave %[fx] ;fwait;" GENERIC_NOP8 GENERIC_NOP4, - "fxsave %[fx]\n" - "bt $7,%[fsw] ; jnc 1f ; fnclex\n1:", - X86_FEATURE_FXSR, - [fx] "m" (fpu->state->fxsave), - [fsw] "m" (fpu->state->fxsave.swd) : "memory"); -clear_state: - /* AMD K7/K8 CPUs don't save/restore FDP/FIP/FOP unless an exception - is pending. Clear the x87 state here by setting it to fixed - values. safe_address is a random variable that should be in L1 */ - alternative_input( - GENERIC_NOP8 GENERIC_NOP2, - "emms\n\t" /* clear stack tags */ - "fildl %[addr]", /* set F?P to defined value */ - X86_FEATURE_FXSAVE_LEAK, - [addr] "m" (safe_address)); -end: - ; +static inline void fpu_save_init(struct fpu *fpu) +{ + fpu_save(fpu); + fpu_clear(fpu); } static inline void __save_init_fpu(struct task_struct *tsk)