qemu-e2k/target-i386
Michael Chapman 4cae9c9796 target-i386: kvm: clear unusable segments' flags in migration
This commit fixes migration of a QEMU/KVM guest from kernel >= v3.9 to
kernel <= v3.7 (e.g. from RHEL 7 to RHEL 6). Without this commit a guest
migrated across these kernel versions fails to resume on the target host
as its segment descriptors are invalid.

Two separate kernel commits combined together to result in this bug:

  commit f0495f9b9992f80f82b14306946444b287193390
  Author: Avi Kivity <avi@redhat.com>
  Date:   Thu Jun 7 17:06:10 2012 +0300

      KVM: VMX: Relax check on unusable segment

      Some userspace (e.g. QEMU 1.1) munge the d and g bits of segment
      descriptors, causing us not to recognize them as unusable segments
      with emulate_invalid_guest_state=1.  Relax the check by testing for
      segment not present (a non-present segment cannot be usable).

      Signed-off-by: Avi Kivity <avi@redhat.com>

  commit 25391454e73e3156202264eb3c473825afe4bc94
  Author: Gleb Natapov <gleb@redhat.com>
  Date:   Mon Jan 21 15:36:46 2013 +0200

      KVM: VMX: don't clobber segment AR of unusable segments.

      Usability is returned in unusable field, so not need to clobber entire
      AR. Callers have to know how to deal with unusable segments already
      since if emulate_invalid_guest_state=true AR is not zeroed.

      Signed-off-by: Gleb Natapov <gleb@redhat.com>
      Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>

The first commit changed the KVM_SET_SREGS ioctl so that it did no treat
segment flags == 0 as an unusable segment, instead only looking at the
"present" flag.

The second commit changed KVM_GET_SREGS so that it did not clear the
flags of an unusable segment.

Since QEMU does not itself maintain the "unusable" flag across a
migration, the end result is that unusable segments read from a kernel
with these commits and loaded into a kernel without these commits are
not properly recognised as being unusable.

This commit updates both get_seg and set_seg so that the problem is
avoided even when migrating to or migrating from a QEMU without this
commit. In get_seg, we clear the segment flags if the segment is marked
unusable. In set_seg, we mark the segment unusable if the segment's
"present" flag is not set.

Signed-off-by: Michael Chapman <mike@very.puzzling.org>
Message-Id: <1449464047-17467-1-git-send-email-mike@very.puzzling.org>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2015-12-17 17:33:49 +01:00
..
arch_dump.c x86: Fuse g_malloc(); memset() into g_malloc0() 2014-12-15 12:21:02 +01:00
arch_memory_mapping.c Switch non-CPU callers from ld/st*_phys to address_space_ld/st* 2015-04-26 16:49:24 +01:00
bpt_helper.c target-i386: Ensure always-1 bits on DR6 can't be cleared 2015-10-23 12:59:27 -02:00
cc_helper_template.h
cc_helper.c target-i386: exception handling for other helper functions 2015-09-15 12:31:59 -07:00
cpu-qom.h target-i386/kvm: Hyper-V SynIC timers MSR's support 2015-12-17 15:24:35 +01:00
cpu.c kvm: x86: add support for KVM_CAP_SPLIT_IRQCHIP 2015-12-17 17:33:47 +01:00
cpu.h target-i386/kvm: Hyper-V SynIC timers MSR's support 2015-12-17 15:24:35 +01:00
excp_helper.c target-i386: introduce new raise_exception functions 2015-09-15 12:28:16 -07:00
fpu_helper.c target-i386: exception handling for FPU instructions 2015-09-15 12:28:16 -07:00
gdbstub.c target-i386: update fp status fix 2014-09-18 17:06:12 +02:00
helper.c target-i386: Move breakpoint related functions to new file 2015-10-02 16:22:01 -03:00
helper.h target-i386: Check CR4[DE] for processing DR4/DR5 2015-10-23 12:59:27 -02:00
hyperv.c target-i386/hyperv: Hyper-V SynIC SINT routing and vcpu exit 2015-12-17 15:24:34 +01:00
hyperv.h target-i386/hyperv: Hyper-V SynIC SINT routing and vcpu exit 2015-12-17 15:24:34 +01:00
int_helper.c target-i386: exception handling for div instructions 2015-09-15 12:28:16 -07:00
kvm_i386.h kvm: x86: add support for KVM_CAP_SPLIT_IRQCHIP 2015-12-17 17:33:47 +01:00
kvm-stub.c pc: add SMM property 2015-07-06 18:39:59 +02:00
kvm.c target-i386: kvm: clear unusable segments' flags in migration 2015-12-17 17:33:49 +01:00
machine.c target-i386/kvm: Hyper-V SynIC timers MSR's support 2015-12-17 15:24:35 +01:00
Makefile.objs target-i386/hyperv: Hyper-V SynIC SINT routing and vcpu exit 2015-12-17 15:24:34 +01:00
mem_helper.c target-i386: exception handling for memory helpers 2015-09-15 12:31:49 -07:00
misc_helper.c target-i386: Move breakpoint related functions to new file 2015-10-02 16:22:01 -03:00
monitor.c hmp: implemented io apic dump state for TCG 2015-09-25 12:04:42 +02:00
ops_sse_header.h
ops_sse.h target-i386: fix pcmpxstrx equal-ordered (strstr) mode 2015-11-04 15:02:30 +01:00
seg_helper.c target-i386: Introduce cpu_x86_update_dr7 2015-10-23 12:59:27 -02:00
shift_helper_template.h
smm_helper.c target-i386: allow any alignment for SMBASE 2015-10-23 12:59:26 -02:00
svm_helper.c target-i386: Use correct memory attributes for memory accesses 2015-06-05 17:10:00 +02:00
svm.h
TODO
translate.c target-i386: Fix mulx for identical target regs 2015-11-17 17:05:59 -02:00