From mboxrd@z Thu Jan 1 00:00:00 1970 From: Jan Kiszka Subject: Re: [PATCH 4/4] qemu-kvm: Enable XSAVE live migration support Date: Thu, 17 Jun 2010 10:44:54 +0200 Message-ID: <4C19E086.9010801@web.de> References: <1276759096-29104-1-git-send-email-sheng@linux.intel.com> <1276759096-29104-5-git-send-email-sheng@linux.intel.com> <4C19D1B7.50006@web.de> <201006171632.50192.sheng@linux.intel.com> Mime-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="------------enigE506DA84734335CCC99B0F57" Cc: Marcelo Tosatti , Avi Kivity , Anthony Liguori , kvm@vger.kernel.org, qemu-devel@nongnu.org To: Sheng Yang Return-path: Received: from fmmailgate03.web.de ([217.72.192.234]:40712 "EHLO fmmailgate03.web.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932663Ab0FQIo5 (ORCPT ); Thu, 17 Jun 2010 04:44:57 -0400 In-Reply-To: <201006171632.50192.sheng@linux.intel.com> Sender: kvm-owner@vger.kernel.org List-ID: This is an OpenPGP/MIME signed message (RFC 2440 and 3156) --------------enigE506DA84734335CCC99B0F57 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Sheng Yang wrote: > On Thursday 17 June 2010 15:41:43 Jan Kiszka wrote: >> Sheng Yang wrote: >>> Based on upstream xsave related fields. >>> >>> Signed-off-by: Sheng Yang >>> --- >>> >>> qemu-kvm-x86.c | 95 >>> +++++++++++++++++++++++++++++++++++++++++++++++++++++++- qemu-kvm.c = =20 >>> | 24 ++++++++++++++ >>> qemu-kvm.h | 28 ++++++++++++++++ >>> 3 files changed, 146 insertions(+), 1 deletions(-) >>> >>> diff --git a/qemu-kvm-x86.c b/qemu-kvm-x86.c >>> index 3c33e64..dcef8b5 100644 >>> --- a/qemu-kvm-x86.c >>> +++ b/qemu-kvm-x86.c >>> @@ -772,10 +772,26 @@ static void get_seg(SegmentCache *lhs, const st= ruct >>> kvm_segment *rhs) >>> >>> | (rhs->avl * DESC_AVL_MASK); >>> =20 >>> } >>> >>> +#ifdef KVM_CAP_XSAVE >>> +#define XSAVE_CWD_RIP 2 >>> +#define XSAVE_CWD_RDP 4 >>> +#define XSAVE_MXCSR 6 >>> +#define XSAVE_ST_SPACE 8 >>> +#define XSAVE_XMM_SPACE 40 >>> +#define XSAVE_XSTATE_BV 128 >>> +#define XSAVE_YMMH_SPACE 144 >>> +#endif >>> + >>> >>> void kvm_arch_load_regs(CPUState *env, int level) >>> { >>> =20 >>> struct kvm_regs regs; >>> struct kvm_fpu fpu; >>> >>> +#ifdef KVM_CAP_XSAVE >>> + struct kvm_xsave* xsave; >>> +#endif >>> +#ifdef KVM_CAP_XCRS >>> + struct kvm_xcrs xcrs; >>> +#endif >>> >>> struct kvm_sregs sregs; >>> struct kvm_msr_entry msrs[100]; >>> int rc, n, i; >>> >>> @@ -806,16 +822,53 @@ void kvm_arch_load_regs(CPUState *env, int leve= l) >>> >>> kvm_set_regs(env, ®s); >>> >>> +#ifdef KVM_CAP_XSAVE >>> + if (kvm_check_extension(kvm_state, KVM_CAP_XSAVE)) { >>> + uint16_t cwd, swd, twd, fop; >>> + >>> + xsave =3D qemu_memalign(4096, sizeof(struct kvm_xsave)); >>> + memset(xsave, 0, sizeof(struct kvm_xsave)); >>> + cwd =3D swd =3D twd =3D fop =3D 0; >>> + swd =3D env->fpus & ~(7 << 11); >>> + swd |=3D (env->fpstt & 7) << 11; >>> + cwd =3D env->fpuc; >>> + for (i =3D 0; i < 8; ++i) >>> + twd |=3D (!env->fptags[i]) << i; >>> + xsave->region[0] =3D (uint32_t)(swd << 16) + cwd; >>> + xsave->region[1] =3D (uint32_t)(fop << 16) + twd; >>> + memcpy(&xsave->region[XSAVE_ST_SPACE], env->fpregs, >>> + sizeof env->fpregs); >>> + memcpy(&xsave->region[XSAVE_XMM_SPACE], env->xmm_regs, >>> + sizeof env->xmm_regs); >>> + xsave->region[XSAVE_MXCSR] =3D env->mxcsr; >>> + *(uint64_t *)&xsave->region[XSAVE_XSTATE_BV] =3D env->xstate= _bv; >>> + memcpy(&xsave->region[XSAVE_YMMH_SPACE], env->ymmh_regs, >>> + sizeof env->ymmh_regs); >>> + kvm_set_xsave(env, xsave); >>> +#ifdef KVM_CAP_XCRS >>> + if (kvm_check_extension(kvm_state, KVM_CAP_XCRS)) { >>> + xcrs.nr_xcrs =3D 1; >>> + xcrs.flags =3D 0; >>> + xcrs.xcrs[0].xcr =3D 0; >>> + xcrs.xcrs[0].value =3D env->xcr0; >>> + kvm_set_xcrs(env, &xcrs); >>> + } >>> +#endif /* KVM_CAP_XCRS */ >>> + } else { >>> +#endif /* KVM_CAP_XSAVE */ >> Why not reusing kvm_put/get_xsave as defined for upstream? There shoul= d >> be enough examples for that pattern. The result will be a tiny qemu-kv= m >> patch. >=20 > Still lots of codes in kvm_arch_load/save_regs() duplicate with ones in= kvm.c,=20 > e.g. kvm_get/put_sregs, kvm_get/put_msrs. So would like to wait for mer= ging. That we still have some legacy here is no good reason to increase it. Just check how debugregs were introduced. Jan --------------enigE506DA84734335CCC99B0F57 Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.9 (GNU/Linux) Comment: Using GnuPG with SUSE - http://enigmail.mozdev.org iEYEARECAAYFAkwZ4IYACgkQitSsb3rl5xSaeQCgwYAfaVPFGCX0ivHhlxJH4ffA eMcAn0UbFCO5dtfPtwyFbUuM/BwBP9CY =4RKk -----END PGP SIGNATURE----- --------------enigE506DA84734335CCC99B0F57--