kvm: x86: Save/restore FPU OP, IP and DP

These FPU states are properly maintained by KVM but not yet by TCG. So
far we unconditionally set them to 0 in the guest which may cause
state corruptions, though not with modern guests.

To avoid breaking backward migration, use a conditional subsection that
is only written if any of the three fields is non-zero. The guest's
FNINIT clears them frequently, and cleared IA32_MISC_ENABLE MSR[2]
reduces the probability of non-zero values further so that this
subsection is not expected to restrict migration in any common scenario.

Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
Signed-off-by: Avi Kivity <avi@redhat.com>
This commit is contained in:
Jan Kiszka 2011-06-15 15:17:26 +02:00 committed by Avi Kivity
parent eb47d7c5d9
commit 42cc8fa620
3 changed files with 42 additions and 5 deletions

View file

@ -290,6 +290,26 @@ static const VMStateDescription vmstate_async_pf_msr = {
}
};
static bool fpop_ip_dp_needed(void *opaque)
{
CPUState *env = opaque;
return env->fpop != 0 || env->fpip != 0 || env->fpdp != 0;
}
static const VMStateDescription vmstate_fpop_ip_dp = {
.name = "cpu/fpop_ip_dp",
.version_id = 1,
.minimum_version_id = 1,
.minimum_version_id_old = 1,
.fields = (VMStateField []) {
VMSTATE_UINT16_V(fpop, CPUState, 13),
VMSTATE_UINT64_V(fpip, CPUState, 13),
VMSTATE_UINT64_V(fpdp, CPUState, 13),
VMSTATE_END_OF_LIST()
}
};
static const VMStateDescription vmstate_cpu = {
.name = "cpu",
.version_id = CPU_SAVE_VERSION,
@ -397,6 +417,9 @@ static const VMStateDescription vmstate_cpu = {
{
.vmsd = &vmstate_async_pf_msr,
.needed = async_pf_msr_needed,
} , {
.vmsd = &vmstate_fpop_ip_dp,
.needed = fpop_ip_dp_needed,
} , {
/* empty */
}