From patchwork Wed May 26 03:34:54 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zachary Amsden X-Patchwork-Id: 102330 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 o4Q3Yx3T018410 for ; Wed, 26 May 2010 03:34:59 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1759164Ab0EZDe5 (ORCPT ); Tue, 25 May 2010 23:34:57 -0400 Received: from mx1.redhat.com ([209.132.183.28]:3882 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753919Ab0EZDe5 (ORCPT ); Tue, 25 May 2010 23:34:57 -0400 Received: from int-mx03.intmail.prod.int.phx2.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id o4Q3Yuwf014368 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Tue, 25 May 2010 23:34:56 -0400 Received: from [10.11.10.106] (vpn-10-106.rdu.redhat.com [10.11.10.106]) by int-mx03.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id o4Q3Ysgi025874; Tue, 25 May 2010 23:34:55 -0400 Message-ID: <4BFC96DE.7040702@redhat.com> Date: Tue, 25 May 2010 17:34:54 -1000 From: Zachary Amsden User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.1.9) Gecko/20100430 Fedora/3.0.4-3.fc13 Thunderbird/3.0.4 MIME-Version: 1.0 To: kvm , Jan Kiszka , Avi Kivity , Gleb Natapov Subject: [PATCH 2/4] Fix FPU interface changes X-Scanned-By: MIMEDefang 2.67 on 10.5.11.16 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]); Wed, 26 May 2010 03:34:59 +0000 (UTC) diff --git a/x86/external-module-compat.h b/x86/external-module-compat.h index 09bf232..316f7ff 100644 --- a/x86/external-module-compat.h +++ b/x86/external-module-compat.h @@ -788,3 +788,87 @@ struct kvm_pvclock_vcpu_time_info { #else #define kvm_pvclock_vcpu_time_info pvclock_vcpu_time_info #endif + +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,34) +#include +#include +struct _fpu { + struct i387_fxsave_struct fxsave; + struct i387_fxsave_struct host_fx_image; +}; + +struct fpu { + struct _fpu *state; + struct _fpu state_static; +}; + +static inline bool fpu_allocated(struct fpu *fpu) +{ + fpu->state = &fpu->state_static; + return true; +} + +static inline int fpu_alloc(struct fpu *fpu) +{ + fpu->state = &fpu->state_static; + return 0; +} + +static inline void fpu_free(struct fpu *fpu) +{ +} + +static inline void kvm_fx_finit(void) +{ + asm("finit"); +} + +static inline void kvm_fx_save(struct i387_fxsave_struct *image) +{ + asm("fxsave (%0)":: "r" (image)); +} + +static inline void kvm_fx_restore(struct i387_fxsave_struct *image) +{ + asm("fxrstor (%0)":: "r" (image)); +} + +static inline void fpu_finit(struct fpu *fpu) +{ + unsigned after_mxcsr_mask; + + /* + * Touch the fpu the first time in non atomic context as if + * this is the first fpu instruction the exception handler + * will fire before the instruction returns and it'll have to + * allocate ram with GFP_KERNEL. + */ + if (!used_math()) + kvm_fx_save(&fpu->state->host_fx_image); + + /* Initialize guest FPU by resetting ours and saving into guest's */ + preempt_disable(); + kvm_fx_save(&fpu->state->host_fx_image); + kvm_fx_finit(); + kvm_fx_save(&fpu->state->fxsave); + kvm_fx_restore(&fpu->state->host_fx_image); + preempt_enable(); + + after_mxcsr_mask = offsetof(struct i387_fxsave_struct, st_space); + fpu->state->fxsave.mxcsr = 0x1f80; + memset((void *)&fpu->state->fxsave + after_mxcsr_mask, + 0, sizeof(struct i387_fxsave_struct) - after_mxcsr_mask); +} + +static inline void fpu_restore_checking(struct fpu *fpu) +{ + kvm_fx_save(&fpu->state->host_fx_image); + kvm_fx_restore(&fpu->state->fxsave); +} + +static inline void fpu_save_init(struct fpu *fpu) +{ + kvm_fx_save(&fpu->state->fxsave); + kvm_fx_restore(&fpu->state->host_fx_image); +} +#endif