Re: [PATCH] qemu-kvm: Replace kvm_set/get_fpu() with upstream version.

Jan Kiszka
2010-06-17T13:27:18Z

Sheng Yang wrote:
> Signed-off-by: Sheng Yang <sheng@linux.intel.com>
> ---
>
> Would send out XSAVE patch after the upstream ones have been merged, since the
> patch would be affected by the merge.
>
> qemu-kvm-x86.c | 23 ++---------------------
> qemu-kvm.c | 10 ----------
> qemu-kvm.h | 30 ------------------------------
> target-i386/kvm.c | 5 ++++-
> 4 files changed, 6 insertions(+), 62 deletions(-)
>
> diff --git a/qemu-kvm-x86.c b/qemu-kvm-x86.c
> index 3c33e64..49218ae 100644
> --- a/qemu-kvm-x86.c
> +++ b/qemu-kvm-x86.c
> @@ -775,7 +775,6 @@ static void get_seg(SegmentCache *lhs, const struct kvm_segment *rhs)
> void kvm_arch_load_regs(CPUState *env, int level)
> {
> struct kvm_regs regs;
> - struct kvm_fpu fpu;
> struct kvm_sregs sregs;
> struct kvm_msr_entry msrs[100];
> int rc, n, i;
> @@ -806,16 +805,7 @@ void kvm_arch_load_regs(CPUState *env, int level)
>
> kvm_set_regs(env, &regs);
>
> - memset(&fpu, 0, sizeof fpu);
> - fpu.fsw = env->fpus & ~(7 << 11);
> - fpu.fsw |= (env->fpstt & 7) << 11;
> - fpu.fcw = env->fpuc;
> - for (i = 0; i < 8; ++i)
> - fpu.ftwx |= (!env->fptags[i]) << i;
> - memcpy(fpu.fpr, env->fpregs, sizeof env->fpregs);
> - memcpy(fpu.xmm, env->xmm_regs, sizeof env->xmm_regs);
> - fpu.mxcsr = env->mxcsr;
> - kvm_set_fpu(env, &fpu);
> + kvm_put_fpu(env);
>
> memset(sregs.interrupt_bitmap, 0, sizeof(sregs.interrupt_bitmap));
> if (env->interrupt_injected >= 0) {
> @@ -933,7 +923,6 @@ void kvm_arch_load_regs(CPUState *env, int level)
> void kvm_arch_save_regs(CPUState *env)
> {
> struct kvm_regs regs;
> - struct kvm_fpu fpu;
> struct kvm_sregs sregs;
> struct kvm_msr_entry msrs[100];
> uint32_t hflags;
> @@ -965,15 +954,7 @@ void kvm_arch_save_regs(CPUState *env)
> env->eflags = regs.rflags;
> env->eip = regs.rip;
>
> - kvm_get_fpu(env, &fpu);
> - env->fpstt = (fpu.fsw >> 11) & 7;
> - env->fpus = fpu.fsw;
> - env->fpuc = fpu.fcw;
> - for (i = 0; i < 8; ++i)
> - env->fptags[i] = !((fpu.ftwx >> i) & 1);
> - memcpy(env->fpregs, fpu.fpr, sizeof env->fpregs);
> - memcpy(env->xmm_regs, fpu.xmm, sizeof env->xmm_regs);
> - env->mxcsr = fpu.mxcsr;
> + kvm_get_fpu(env);
>
> kvm_get_sregs(env, &sregs);
>
> diff --git a/qemu-kvm.c b/qemu-kvm.c
> index 96d458c..114cb5e 100644
> --- a/qemu-kvm.c
> +++ b/qemu-kvm.c
> @@ -461,16 +461,6 @@ int kvm_set_regs(CPUState *env, struct kvm_regs *regs)
> return kvm_vcpu_ioctl(env, KVM_SET_REGS, regs);
> }
>
> -int kvm_get_fpu(CPUState *env, struct kvm_fpu *fpu)
> -{
> - return kvm_vcpu_ioctl(env, KVM_GET_FPU, fpu);
> -}
> -
> -int kvm_set_fpu(CPUState *env, struct kvm_fpu *fpu)
> -{
> - return kvm_vcpu_ioctl(env, KVM_SET_FPU, fpu);
> -}
> -
> int kvm_get_sregs(CPUState *env, struct kvm_sregs *sregs)
> {
> return kvm_vcpu_ioctl(env, KVM_GET_SREGS, sregs);
> diff --git a/qemu-kvm.h b/qemu-kvm.h
> index 6f6c6d8..ebe7893 100644
> --- a/qemu-kvm.h
> +++ b/qemu-kvm.h
> @@ -222,36 +222,6 @@ int kvm_get_regs(CPUState *env, struct kvm_regs *regs);
> * \return 0 on success
> */
> int kvm_set_regs(CPUState *env, struct kvm_regs *regs);
> -/*!
> - * \brief Read VCPU fpu registers
> - *
> - * This gets the FPU registers from the VCPU and outputs them
> - * into a kvm_fpu structure
> - *
> - * \note This function returns a \b copy of the VCPUs registers.\n
> - * If you wish to modify the VCPU FPU registers, you should call kvm_set_fpu()
> - *
> - * \param kvm Pointer to the current kvm_context
> - * \param vcpu Which virtual CPU should get dumped
> - * \param fpu Pointer to a kvm_fpu which will be populated with the VCPUs
> - * fpu registers values
> - * \return 0 on success
> - */
> -int kvm_get_fpu(CPUState *env, struct kvm_fpu *fpu);
> -
> -/*!
> - * \brief Write VCPU fpu registers
> - *
> - * This sets the FPU registers on the VCPU from a kvm_fpu structure
> - *
> - * \note When this function returns, the fpu pointer and the data it points to
> - * can be discarded
> - * \param kvm Pointer to the current kvm_context
> - * \param vcpu Which virtual CPU should get dumped
> - * \param fpu Pointer to a kvm_fpu which holds the new vcpu fpu state
> - * \return 0 on success
> - */
> -int kvm_set_fpu(CPUState *env, struct kvm_fpu *fpu);
>
> /*!
> * \brief Read VCPU system registers
> diff --git a/target-i386/kvm.c b/target-i386/kvm.c
> index 9cb9cf4..9c13f62 100644
> --- a/target-i386/kvm.c
> +++ b/target-i386/kvm.c
> @@ -488,6 +488,7 @@ static int kvm_getput_regs(CPUState *env, int set)
>
> return ret;
> }
> +#endif /* KVM_UPSTREAM */
>
> static int kvm_put_fpu(CPUState *env)
> {
> @@ -507,6 +508,7 @@ static int kvm_put_fpu(CPUState *env)
> return kvm_vcpu_ioctl(env, KVM_SET_FPU, &fpu);
> }
>
> +#ifdef KVM_UPSTREAM
> static int kvm_put_sregs(CPUState *env)
> {
> struct kvm_sregs sregs;
> @@ -605,7 +607,7 @@ static int kvm_put_msrs(CPUState *env, int level)
> return kvm_vcpu_ioctl(env, KVM_SET_MSRS, &msr_data);
>
> }
> -
> +#endif /* KVM_UPSTREAM */
>
> static int kvm_get_fpu(CPUState *env)
> {
> @@ -628,6 +630,7 @@ static int kvm_get_fpu(CPUState *env)
> return 0;
> }
>
> +#ifdef KVM_UPSTREAM
> static int kvm_get_sregs(CPUState *env)
> {
> struct kvm_sregs sregs;

Perfect, another step forward towards upstream!

Thanks,
Jan

--
Siemens AG, Corporate Technology, CT T DE IT 1
Corporate Competence Center Embedded Linux