From mboxrd@z Thu Jan 1 00:00:00 1970 From: Jan Kiszka Subject: Re: [PATCH -v2] Add savevm/loadvm support for MCE Date: Tue, 02 Mar 2010 09:09:21 +0100 Message-ID: <4B8CC7B1.4050609@web.de> References: <1267508413.1640.88.camel@yhuang-dev.sh.intel.com> Mime-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="------------enigC5C571799D144CC8384336AC" Cc: Avi Kivity , Anthony Liguori , Andi Kleen , "kvm@vger.kernel.org" To: Huang Ying Return-path: Received: from fmmailgate02.web.de ([217.72.192.227]:49357 "EHLO fmmailgate02.web.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753500Ab0CBIJY (ORCPT ); Tue, 2 Mar 2010 03:09:24 -0500 In-Reply-To: <1267508413.1640.88.camel@yhuang-dev.sh.intel.com> Sender: kvm-owner@vger.kernel.org List-ID: This is an OpenPGP/MIME signed message (RFC 2440 and 3156) --------------enigC5C571799D144CC8384336AC Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Huang Ying wrote: > MCE registers are saved/load into/from CPUState in > kvm_arch_save/load_regs. To simulate the MCG_STATUS clearing upon > reset, MSR_MCG_STATUS is set to 0 for KVM_PUT_RESET_STATE. >=20 > v2: >=20 > - Rebased on new CPU registers save/load framework. Yep, much closer. :) >=20 > Signed-off-by: Huang Ying > --- > qemu-kvm-x86.c | 43 +++++++++++++++++++++++++++++++++++++++++++ > 1 file changed, 43 insertions(+) >=20 > --- a/qemu-kvm-x86.c > +++ b/qemu-kvm-x86.c > @@ -979,11 +979,33 @@ void kvm_arch_load_regs(CPUState *env, i > set_msr_entry(&msrs[n++], MSR_KVM_SYSTEM_TIME, env->system_tim= e_msr); > set_msr_entry(&msrs[n++], MSR_KVM_WALL_CLOCK, env->wall_clock_= msr); > } > +#ifdef KVM_CAP_MCE > + if (env->mcg_cap && level =3D=3D KVM_PUT_RESET_STATE) { > + /* > + * MCG_STATUS should reset to 0 after reset, while other MCE > + * registers should be unchanged > + */ > + set_msr_entry(&msrs[n++], MSR_MCG_STATUS, 0); For the sake of consistency, just write mcg_status here (it's properly updated in cpu_reset). > + } > +#endif > =20 > rc =3D kvm_set_msrs(env, msrs, n); > if (rc =3D=3D -1) > perror("kvm_set_msrs FAILED"); > =20 > +#ifdef KVM_CAP_MCE > + if (env->mcg_cap && level =3D=3D KVM_PUT_FULL_STATE) { > + n =3D 0; > + set_msr_entry(&msrs[n++], MSR_MCG_STATUS, env->mcg_status); > + set_msr_entry(&msrs[n++], MSR_MCG_CTL, env->mcg_ctl); You can move this block up, reusing the kvm_set_msrs above. But... > + for (i =3D 0; i < (env->mcg_cap & 0xff); i++) =2E..this requires some care. We have space for writing up to 100 registers in our msrs array. You may have to extend it unless this number is much smaller in reality. > + set_msr_entry(&msrs[n++], MSR_MC0_CTL + i, env->mce_banks[= i]); > + rc =3D kvm_set_msrs(env, msrs, n); > + if (rc =3D=3D -1) > + perror("kvm_set_msrs FAILED"); > + } > +#endif > + > if (level >=3D KVM_PUT_RESET_STATE) { > kvm_arch_load_mpstate(env); > kvm_load_lapic(env); > @@ -1155,6 +1177,27 @@ void kvm_arch_save_regs(CPUState *env) > return; > } > } > + > +#ifdef KVM_CAP_MCE > + if (env->mcg_cap) { No need to check for msg_cap, the kernel will ignore unknown MSRs. > + msrs[0].index =3D MSR_MCG_STATUS; > + msrs[1].index =3D MSR_MCG_CTL; > + n =3D (env->mcg_cap & 0xff) * 4; > + for (i =3D 0; i < n; i++) Same are above, we may run out of array space. > + msrs[2 + i].index =3D MSR_MC0_CTL + i; > + > + rc =3D kvm_get_msrs(env, msrs, n + 2); > + if (rc =3D=3D -1) > + perror("kvm_get_msrs FAILED"); > + else { > + env->mcg_status =3D msrs[0].data; > + env->mcg_ctl =3D msrs[1].data; > + for (i =3D 0; i < n; i++) > + env->mce_banks[i] =3D msrs[2 + i].data; > + } Please split this block into setup and MSR transfer, and then merge it into the existing MSR readout to avoid calling kvm_get_msrs twice. > + } > +#endif > + > kvm_arch_save_mpstate(env); > kvm_save_lapic(env); > kvm_get_vcpu_events(env); >=20 >=20 Thanks, Jan --------------enigC5C571799D144CC8384336AC 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 iEYEARECAAYFAkuMx7EACgkQitSsb3rl5xTTBACgnh2Yl46NCObC9XEU0NY2zWz4 USoAni8irw8auib1kRyFhuEXULBJ3Pqd =FwlH -----END PGP SIGNATURE----- --------------enigC5C571799D144CC8384336AC--