2016-01-26 21:17:03 +03:00
|
|
|
#include "qemu/osdep.h"
|
2016-03-15 18:58:45 +03:00
|
|
|
#include "qemu-common.h"
|
|
|
|
#include "cpu.h"
|
2016-03-15 15:18:37 +03:00
|
|
|
#include "exec/exec-all.h"
|
2008-05-04 17:11:44 +04:00
|
|
|
#include "hw/hw.h"
|
|
|
|
#include "hw/boards.h"
|
2013-02-05 20:06:20 +04:00
|
|
|
#include "hw/i386/pc.h"
|
|
|
|
#include "hw/isa/isa.h"
|
2016-03-15 14:51:18 +03:00
|
|
|
#include "migration/cpu.h"
|
2008-05-04 17:11:44 +04:00
|
|
|
|
2012-12-17 21:20:04 +04:00
|
|
|
#include "sysemu/kvm.h"
|
2008-05-04 17:11:44 +04:00
|
|
|
|
2015-11-24 06:33:57 +03:00
|
|
|
#include "qemu/error-report.h"
|
|
|
|
|
2009-09-30 00:49:01 +04:00
|
|
|
static const VMStateDescription vmstate_segment = {
|
|
|
|
.name = "segment",
|
|
|
|
.version_id = 1,
|
|
|
|
.minimum_version_id = 1,
|
2014-04-16 17:32:32 +04:00
|
|
|
.fields = (VMStateField[]) {
|
2009-09-30 00:49:01 +04:00
|
|
|
VMSTATE_UINT32(selector, SegmentCache),
|
|
|
|
VMSTATE_UINTTL(base, SegmentCache),
|
|
|
|
VMSTATE_UINT32(limit, SegmentCache),
|
|
|
|
VMSTATE_UINT32(flags, SegmentCache),
|
|
|
|
VMSTATE_END_OF_LIST()
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2009-09-30 00:49:08 +04:00
|
|
|
#define VMSTATE_SEGMENT(_field, _state) { \
|
|
|
|
.name = (stringify(_field)), \
|
|
|
|
.size = sizeof(SegmentCache), \
|
|
|
|
.vmsd = &vmstate_segment, \
|
|
|
|
.flags = VMS_STRUCT, \
|
|
|
|
.offset = offsetof(_state, _field) \
|
|
|
|
+ type_check(SegmentCache,typeof_field(_state, _field)) \
|
2008-05-04 17:11:44 +04:00
|
|
|
}
|
|
|
|
|
2009-09-30 00:49:08 +04:00
|
|
|
#define VMSTATE_SEGMENT_ARRAY(_field, _state, _n) \
|
|
|
|
VMSTATE_STRUCT_ARRAY(_field, _state, _n, 0, vmstate_segment, SegmentCache)
|
2008-05-04 17:11:44 +04:00
|
|
|
|
2009-09-30 00:49:04 +04:00
|
|
|
static const VMStateDescription vmstate_xmm_reg = {
|
|
|
|
.name = "xmm_reg",
|
|
|
|
.version_id = 1,
|
|
|
|
.minimum_version_id = 1,
|
2014-04-16 17:32:32 +04:00
|
|
|
.fields = (VMStateField[]) {
|
2015-11-26 22:14:32 +03:00
|
|
|
VMSTATE_UINT64(ZMM_Q(0), ZMMReg),
|
|
|
|
VMSTATE_UINT64(ZMM_Q(1), ZMMReg),
|
2009-09-30 00:49:04 +04:00
|
|
|
VMSTATE_END_OF_LIST()
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2014-10-24 12:18:38 +04:00
|
|
|
#define VMSTATE_XMM_REGS(_field, _state, _start) \
|
|
|
|
VMSTATE_STRUCT_SUB_ARRAY(_field, _state, _start, CPU_NB_REGS, 0, \
|
2015-11-19 21:12:40 +03:00
|
|
|
vmstate_xmm_reg, ZMMReg)
|
2009-09-30 00:49:04 +04:00
|
|
|
|
2014-10-24 11:50:21 +04:00
|
|
|
/* YMMH format is the same as XMM, but for bits 128-255 */
|
2010-06-17 13:53:07 +04:00
|
|
|
static const VMStateDescription vmstate_ymmh_reg = {
|
|
|
|
.name = "ymmh_reg",
|
|
|
|
.version_id = 1,
|
|
|
|
.minimum_version_id = 1,
|
2014-04-16 17:32:32 +04:00
|
|
|
.fields = (VMStateField[]) {
|
2015-11-26 22:14:32 +03:00
|
|
|
VMSTATE_UINT64(ZMM_Q(2), ZMMReg),
|
|
|
|
VMSTATE_UINT64(ZMM_Q(3), ZMMReg),
|
2010-06-17 13:53:07 +04:00
|
|
|
VMSTATE_END_OF_LIST()
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2014-10-24 12:18:38 +04:00
|
|
|
#define VMSTATE_YMMH_REGS_VARS(_field, _state, _start, _v) \
|
|
|
|
VMSTATE_STRUCT_SUB_ARRAY(_field, _state, _start, CPU_NB_REGS, _v, \
|
2015-11-19 21:12:40 +03:00
|
|
|
vmstate_ymmh_reg, ZMMReg)
|
2010-06-17 13:53:07 +04:00
|
|
|
|
2014-10-23 07:02:43 +04:00
|
|
|
static const VMStateDescription vmstate_zmmh_reg = {
|
|
|
|
.name = "zmmh_reg",
|
|
|
|
.version_id = 1,
|
|
|
|
.minimum_version_id = 1,
|
|
|
|
.fields = (VMStateField[]) {
|
2015-11-26 22:14:32 +03:00
|
|
|
VMSTATE_UINT64(ZMM_Q(4), ZMMReg),
|
|
|
|
VMSTATE_UINT64(ZMM_Q(5), ZMMReg),
|
|
|
|
VMSTATE_UINT64(ZMM_Q(6), ZMMReg),
|
|
|
|
VMSTATE_UINT64(ZMM_Q(7), ZMMReg),
|
2014-10-23 07:02:43 +04:00
|
|
|
VMSTATE_END_OF_LIST()
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2014-10-24 12:18:38 +04:00
|
|
|
#define VMSTATE_ZMMH_REGS_VARS(_field, _state, _start) \
|
|
|
|
VMSTATE_STRUCT_SUB_ARRAY(_field, _state, _start, CPU_NB_REGS, 0, \
|
2015-11-19 21:12:40 +03:00
|
|
|
vmstate_zmmh_reg, ZMMReg)
|
2014-10-23 07:02:43 +04:00
|
|
|
|
|
|
|
#ifdef TARGET_X86_64
|
|
|
|
static const VMStateDescription vmstate_hi16_zmm_reg = {
|
|
|
|
.name = "hi16_zmm_reg",
|
|
|
|
.version_id = 1,
|
|
|
|
.minimum_version_id = 1,
|
|
|
|
.fields = (VMStateField[]) {
|
2015-11-26 22:14:32 +03:00
|
|
|
VMSTATE_UINT64(ZMM_Q(0), ZMMReg),
|
|
|
|
VMSTATE_UINT64(ZMM_Q(1), ZMMReg),
|
|
|
|
VMSTATE_UINT64(ZMM_Q(2), ZMMReg),
|
|
|
|
VMSTATE_UINT64(ZMM_Q(3), ZMMReg),
|
|
|
|
VMSTATE_UINT64(ZMM_Q(4), ZMMReg),
|
|
|
|
VMSTATE_UINT64(ZMM_Q(5), ZMMReg),
|
|
|
|
VMSTATE_UINT64(ZMM_Q(6), ZMMReg),
|
|
|
|
VMSTATE_UINT64(ZMM_Q(7), ZMMReg),
|
2014-10-23 07:02:43 +04:00
|
|
|
VMSTATE_END_OF_LIST()
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2014-10-24 12:18:38 +04:00
|
|
|
#define VMSTATE_Hi16_ZMM_REGS_VARS(_field, _state, _start) \
|
|
|
|
VMSTATE_STRUCT_SUB_ARRAY(_field, _state, _start, CPU_NB_REGS, 0, \
|
2015-11-19 21:12:40 +03:00
|
|
|
vmstate_hi16_zmm_reg, ZMMReg)
|
2014-10-23 07:02:43 +04:00
|
|
|
#endif
|
|
|
|
|
2013-12-05 04:32:12 +04:00
|
|
|
static const VMStateDescription vmstate_bnd_regs = {
|
|
|
|
.name = "bnd_regs",
|
|
|
|
.version_id = 1,
|
|
|
|
.minimum_version_id = 1,
|
2014-04-16 17:32:32 +04:00
|
|
|
.fields = (VMStateField[]) {
|
2013-12-05 04:32:12 +04:00
|
|
|
VMSTATE_UINT64(lb, BNDReg),
|
|
|
|
VMSTATE_UINT64(ub, BNDReg),
|
|
|
|
VMSTATE_END_OF_LIST()
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
#define VMSTATE_BND_REGS(_field, _state, _n) \
|
|
|
|
VMSTATE_STRUCT_ARRAY(_field, _state, _n, 0, vmstate_bnd_regs, BNDReg)
|
|
|
|
|
2009-09-30 00:49:05 +04:00
|
|
|
static const VMStateDescription vmstate_mtrr_var = {
|
|
|
|
.name = "mtrr_var",
|
|
|
|
.version_id = 1,
|
|
|
|
.minimum_version_id = 1,
|
2014-04-16 17:32:32 +04:00
|
|
|
.fields = (VMStateField[]) {
|
2009-09-30 00:49:05 +04:00
|
|
|
VMSTATE_UINT64(base, MTRRVar),
|
|
|
|
VMSTATE_UINT64(mask, MTRRVar),
|
|
|
|
VMSTATE_END_OF_LIST()
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2009-09-30 00:49:08 +04:00
|
|
|
#define VMSTATE_MTRR_VARS(_field, _state, _n, _v) \
|
|
|
|
VMSTATE_STRUCT_ARRAY(_field, _state, _n, _v, vmstate_mtrr_var, MTRRVar)
|
2009-09-30 00:49:05 +04:00
|
|
|
|
2017-04-05 22:00:23 +03:00
|
|
|
typedef struct x86_FPReg_tmp {
|
|
|
|
FPReg *parent;
|
|
|
|
uint64_t tmp_mant;
|
|
|
|
uint16_t tmp_exp;
|
|
|
|
} x86_FPReg_tmp;
|
|
|
|
|
2017-07-03 13:12:16 +03:00
|
|
|
static void cpu_get_fp80(uint64_t *pmant, uint16_t *pexp, floatx80 f)
|
|
|
|
{
|
|
|
|
CPU_LDoubleU temp;
|
|
|
|
|
|
|
|
temp.d = f;
|
|
|
|
*pmant = temp.l.lower;
|
|
|
|
*pexp = temp.l.upper;
|
|
|
|
}
|
|
|
|
|
|
|
|
static floatx80 cpu_set_fp80(uint64_t mant, uint16_t upper)
|
|
|
|
{
|
|
|
|
CPU_LDoubleU temp;
|
|
|
|
|
|
|
|
temp.l.upper = upper;
|
|
|
|
temp.l.lower = mant;
|
|
|
|
return temp.d;
|
|
|
|
}
|
|
|
|
|
2017-09-25 14:29:12 +03:00
|
|
|
static int fpreg_pre_save(void *opaque)
|
2009-09-30 00:49:06 +04:00
|
|
|
{
|
2017-04-05 22:00:23 +03:00
|
|
|
x86_FPReg_tmp *tmp = opaque;
|
2009-09-30 00:49:06 +04:00
|
|
|
|
2017-04-05 22:00:23 +03:00
|
|
|
/* we save the real CPU data (in case of MMX usage only 'mant'
|
|
|
|
contains the MMX register */
|
|
|
|
cpu_get_fp80(&tmp->tmp_mant, &tmp->tmp_exp, tmp->parent->d);
|
2017-09-25 14:29:12 +03:00
|
|
|
|
|
|
|
return 0;
|
2009-09-30 00:49:06 +04:00
|
|
|
}
|
|
|
|
|
2017-04-05 22:00:23 +03:00
|
|
|
static int fpreg_post_load(void *opaque, int version)
|
2009-09-30 00:49:06 +04:00
|
|
|
{
|
2017-04-05 22:00:23 +03:00
|
|
|
x86_FPReg_tmp *tmp = opaque;
|
2017-01-19 22:00:50 +03:00
|
|
|
|
2017-04-05 22:00:23 +03:00
|
|
|
tmp->parent->d = cpu_set_fp80(tmp->tmp_mant, tmp->tmp_exp);
|
2017-01-19 22:00:50 +03:00
|
|
|
return 0;
|
2009-09-30 00:49:06 +04:00
|
|
|
}
|
|
|
|
|
2017-04-05 22:00:23 +03:00
|
|
|
static const VMStateDescription vmstate_fpreg_tmp = {
|
|
|
|
.name = "fpreg_tmp",
|
|
|
|
.post_load = fpreg_post_load,
|
|
|
|
.pre_save = fpreg_pre_save,
|
|
|
|
.fields = (VMStateField[]) {
|
|
|
|
VMSTATE_UINT64(tmp_mant, x86_FPReg_tmp),
|
|
|
|
VMSTATE_UINT16(tmp_exp, x86_FPReg_tmp),
|
|
|
|
VMSTATE_END_OF_LIST()
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
static const VMStateDescription vmstate_fpreg = {
|
2009-09-30 00:49:08 +04:00
|
|
|
.name = "fpreg",
|
2017-04-05 22:00:23 +03:00
|
|
|
.fields = (VMStateField[]) {
|
|
|
|
VMSTATE_WITH_TMP(FPReg, x86_FPReg_tmp, vmstate_fpreg_tmp),
|
|
|
|
VMSTATE_END_OF_LIST()
|
|
|
|
}
|
2009-09-30 00:49:08 +04:00
|
|
|
};
|
|
|
|
|
2017-09-25 14:29:12 +03:00
|
|
|
static int cpu_pre_save(void *opaque)
|
2008-05-04 17:11:44 +04:00
|
|
|
{
|
2013-02-02 16:38:08 +04:00
|
|
|
X86CPU *cpu = opaque;
|
|
|
|
CPUX86State *env = &cpu->env;
|
2009-11-06 21:39:24 +03:00
|
|
|
int i;
|
2008-05-04 17:11:44 +04:00
|
|
|
|
|
|
|
/* FPU */
|
2009-09-30 00:48:51 +04:00
|
|
|
env->fpus_vmstate = (env->fpus & ~0x3800) | (env->fpstt & 0x7) << 11;
|
2009-09-30 00:48:52 +04:00
|
|
|
env->fptag_vmstate = 0;
|
2008-05-04 17:11:44 +04:00
|
|
|
for(i = 0; i < 8; i++) {
|
2009-09-30 00:48:52 +04:00
|
|
|
env->fptag_vmstate |= ((!env->fptags[i]) << i);
|
2008-05-04 17:11:44 +04:00
|
|
|
}
|
|
|
|
|
2009-09-30 00:48:54 +04:00
|
|
|
env->fpregs_format_vmstate = 0;
|
2013-07-22 21:29:42 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Real mode guest segments register DPL should be zero.
|
|
|
|
* Older KVM version were setting it wrongly.
|
|
|
|
* Fixing it will allow live migration to host with unrestricted guest
|
|
|
|
* support (otherwise the migration will fail with invalid guest state
|
|
|
|
* error).
|
|
|
|
*/
|
|
|
|
if (!(env->cr[0] & CR0_PE_MASK) &&
|
|
|
|
(env->segs[R_CS].flags >> DESC_DPL_SHIFT & 3) != 0) {
|
|
|
|
env->segs[R_CS].flags &= ~(env->segs[R_CS].flags & DESC_DPL_MASK);
|
|
|
|
env->segs[R_DS].flags &= ~(env->segs[R_DS].flags & DESC_DPL_MASK);
|
|
|
|
env->segs[R_ES].flags &= ~(env->segs[R_ES].flags & DESC_DPL_MASK);
|
|
|
|
env->segs[R_FS].flags &= ~(env->segs[R_FS].flags & DESC_DPL_MASK);
|
|
|
|
env->segs[R_GS].flags &= ~(env->segs[R_GS].flags & DESC_DPL_MASK);
|
|
|
|
env->segs[R_SS].flags &= ~(env->segs[R_SS].flags & DESC_DPL_MASK);
|
|
|
|
}
|
|
|
|
|
2017-09-25 14:29:12 +03:00
|
|
|
return 0;
|
2009-09-30 00:49:02 +04:00
|
|
|
}
|
|
|
|
|
2009-09-30 00:49:03 +04:00
|
|
|
static int cpu_post_load(void *opaque, int version_id)
|
|
|
|
{
|
2013-02-02 16:38:08 +04:00
|
|
|
X86CPU *cpu = opaque;
|
2013-09-02 18:57:02 +04:00
|
|
|
CPUState *cs = CPU(cpu);
|
2013-02-02 16:38:08 +04:00
|
|
|
CPUX86State *env = &cpu->env;
|
2009-09-30 00:49:03 +04:00
|
|
|
int i;
|
|
|
|
|
2015-11-24 06:33:57 +03:00
|
|
|
if (env->tsc_khz && env->user_tsc_khz &&
|
|
|
|
env->tsc_khz != env->user_tsc_khz) {
|
|
|
|
error_report("Mismatch between user-specified TSC frequency and "
|
|
|
|
"migrated TSC frequency");
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
2017-04-05 22:00:22 +03:00
|
|
|
if (env->fpregs_format_vmstate) {
|
|
|
|
error_report("Unsupported old non-softfloat CPU state");
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
2013-07-22 21:29:41 +04:00
|
|
|
/*
|
|
|
|
* Real mode guest segments register DPL should be zero.
|
|
|
|
* Older KVM version were setting it wrongly.
|
|
|
|
* Fixing it will allow live migration from such host that don't have
|
|
|
|
* restricted guest support to a host with unrestricted guest support
|
|
|
|
* (otherwise the migration will fail with invalid guest state
|
|
|
|
* error).
|
|
|
|
*/
|
|
|
|
if (!(env->cr[0] & CR0_PE_MASK) &&
|
|
|
|
(env->segs[R_CS].flags >> DESC_DPL_SHIFT & 3) != 0) {
|
|
|
|
env->segs[R_CS].flags &= ~(env->segs[R_CS].flags & DESC_DPL_MASK);
|
|
|
|
env->segs[R_DS].flags &= ~(env->segs[R_DS].flags & DESC_DPL_MASK);
|
|
|
|
env->segs[R_ES].flags &= ~(env->segs[R_ES].flags & DESC_DPL_MASK);
|
|
|
|
env->segs[R_FS].flags &= ~(env->segs[R_FS].flags & DESC_DPL_MASK);
|
|
|
|
env->segs[R_GS].flags &= ~(env->segs[R_GS].flags & DESC_DPL_MASK);
|
|
|
|
env->segs[R_SS].flags &= ~(env->segs[R_SS].flags & DESC_DPL_MASK);
|
|
|
|
}
|
|
|
|
|
2014-05-14 12:38:18 +04:00
|
|
|
/* Older versions of QEMU incorrectly used CS.DPL as the CPL when
|
|
|
|
* running under KVM. This is wrong for conforming code segments.
|
|
|
|
* Luckily, in our implementation the CPL field of hflags is redundant
|
|
|
|
* and we can get the right value from the SS descriptor privilege level.
|
|
|
|
*/
|
|
|
|
env->hflags &= ~HF_CPL_MASK;
|
|
|
|
env->hflags |= (env->segs[R_SS].flags >> DESC_DPL_SHIFT) & HF_CPL_MASK;
|
|
|
|
|
2009-09-30 00:49:03 +04:00
|
|
|
env->fpstt = (env->fpus_vmstate >> 11) & 7;
|
|
|
|
env->fpus = env->fpus_vmstate & ~0x3800;
|
|
|
|
env->fptag_vmstate ^= 0xff;
|
|
|
|
for(i = 0; i < 8; i++) {
|
|
|
|
env->fptags[i] = (env->fptag_vmstate >> i) & 1;
|
|
|
|
}
|
2017-07-03 13:12:19 +03:00
|
|
|
if (tcg_enabled()) {
|
2017-07-03 13:12:22 +03:00
|
|
|
target_ulong dr7;
|
2017-07-03 13:12:19 +03:00
|
|
|
update_fp_status(env);
|
|
|
|
update_mxcsr_status(env);
|
2009-09-30 00:49:03 +04:00
|
|
|
|
2017-07-03 13:12:22 +03:00
|
|
|
cpu_breakpoint_remove_all(cs, BP_CPU);
|
|
|
|
cpu_watchpoint_remove_all(cs, BP_CPU);
|
|
|
|
|
2015-09-15 21:45:08 +03:00
|
|
|
/* Indicate all breakpoints disabled, as they are, then
|
|
|
|
let the helper re-enable them. */
|
2017-07-03 13:12:22 +03:00
|
|
|
dr7 = env->dr[7];
|
2015-09-15 21:45:08 +03:00
|
|
|
env->dr[7] = dr7 & ~(DR7_GLOBAL_BP_MASK | DR7_LOCAL_BP_MASK);
|
|
|
|
cpu_x86_update_dr7(env, dr7);
|
2013-01-15 09:39:55 +04:00
|
|
|
}
|
2016-11-14 17:17:28 +03:00
|
|
|
tlb_flush(cs);
|
2009-10-05 22:30:32 +04:00
|
|
|
return 0;
|
2009-09-30 00:49:03 +04:00
|
|
|
}
|
|
|
|
|
2010-10-24 16:27:55 +04:00
|
|
|
static bool async_pf_msr_needed(void *opaque)
|
|
|
|
{
|
2013-02-02 16:38:08 +04:00
|
|
|
X86CPU *cpu = opaque;
|
2010-10-24 16:27:55 +04:00
|
|
|
|
2013-02-02 16:38:08 +04:00
|
|
|
return cpu->env.async_pf_en_msr != 0;
|
2010-10-24 16:27:55 +04:00
|
|
|
}
|
|
|
|
|
2012-08-28 21:43:56 +04:00
|
|
|
static bool pv_eoi_msr_needed(void *opaque)
|
|
|
|
{
|
2013-02-02 16:38:08 +04:00
|
|
|
X86CPU *cpu = opaque;
|
2012-08-28 21:43:56 +04:00
|
|
|
|
2013-02-02 16:38:08 +04:00
|
|
|
return cpu->env.pv_eoi_en_msr != 0;
|
2012-08-28 21:43:56 +04:00
|
|
|
}
|
|
|
|
|
2013-02-20 06:27:20 +04:00
|
|
|
static bool steal_time_msr_needed(void *opaque)
|
|
|
|
{
|
2013-09-04 01:55:16 +04:00
|
|
|
X86CPU *cpu = opaque;
|
2013-02-20 06:27:20 +04:00
|
|
|
|
2013-09-04 01:55:16 +04:00
|
|
|
return cpu->env.steal_time_msr != 0;
|
2013-02-20 06:27:20 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static const VMStateDescription vmstate_steal_time_msr = {
|
|
|
|
.name = "cpu/steal_time_msr",
|
|
|
|
.version_id = 1,
|
|
|
|
.minimum_version_id = 1,
|
2014-09-23 16:09:54 +04:00
|
|
|
.needed = steal_time_msr_needed,
|
2014-04-16 17:32:32 +04:00
|
|
|
.fields = (VMStateField[]) {
|
2013-09-04 01:55:16 +04:00
|
|
|
VMSTATE_UINT64(env.steal_time_msr, X86CPU),
|
2013-02-20 06:27:20 +04:00
|
|
|
VMSTATE_END_OF_LIST()
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2010-10-24 16:27:55 +04:00
|
|
|
static const VMStateDescription vmstate_async_pf_msr = {
|
|
|
|
.name = "cpu/async_pf_msr",
|
|
|
|
.version_id = 1,
|
|
|
|
.minimum_version_id = 1,
|
2014-09-23 16:09:54 +04:00
|
|
|
.needed = async_pf_msr_needed,
|
2014-04-16 17:32:32 +04:00
|
|
|
.fields = (VMStateField[]) {
|
2013-02-02 16:38:08 +04:00
|
|
|
VMSTATE_UINT64(env.async_pf_en_msr, X86CPU),
|
2010-10-24 16:27:55 +04:00
|
|
|
VMSTATE_END_OF_LIST()
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2012-08-28 21:43:56 +04:00
|
|
|
static const VMStateDescription vmstate_pv_eoi_msr = {
|
|
|
|
.name = "cpu/async_pv_eoi_msr",
|
|
|
|
.version_id = 1,
|
|
|
|
.minimum_version_id = 1,
|
2014-09-23 16:09:54 +04:00
|
|
|
.needed = pv_eoi_msr_needed,
|
2014-04-16 17:32:32 +04:00
|
|
|
.fields = (VMStateField[]) {
|
2013-02-02 16:38:08 +04:00
|
|
|
VMSTATE_UINT64(env.pv_eoi_en_msr, X86CPU),
|
2012-08-28 21:43:56 +04:00
|
|
|
VMSTATE_END_OF_LIST()
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2011-06-15 17:17:26 +04:00
|
|
|
static bool fpop_ip_dp_needed(void *opaque)
|
|
|
|
{
|
2013-02-02 16:38:08 +04:00
|
|
|
X86CPU *cpu = opaque;
|
|
|
|
CPUX86State *env = &cpu->env;
|
2011-06-15 17:17:26 +04:00
|
|
|
|
|
|
|
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,
|
2014-09-23 16:09:54 +04:00
|
|
|
.needed = fpop_ip_dp_needed,
|
2014-04-16 17:32:32 +04:00
|
|
|
.fields = (VMStateField[]) {
|
2013-02-02 16:38:08 +04:00
|
|
|
VMSTATE_UINT16(env.fpop, X86CPU),
|
|
|
|
VMSTATE_UINT64(env.fpip, X86CPU),
|
|
|
|
VMSTATE_UINT64(env.fpdp, X86CPU),
|
2011-06-15 17:17:26 +04:00
|
|
|
VMSTATE_END_OF_LIST()
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2012-11-27 09:32:18 +04:00
|
|
|
static bool tsc_adjust_needed(void *opaque)
|
|
|
|
{
|
2013-02-02 16:38:08 +04:00
|
|
|
X86CPU *cpu = opaque;
|
|
|
|
CPUX86State *env = &cpu->env;
|
2012-11-27 09:32:18 +04:00
|
|
|
|
|
|
|
return env->tsc_adjust != 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const VMStateDescription vmstate_msr_tsc_adjust = {
|
|
|
|
.name = "cpu/msr_tsc_adjust",
|
|
|
|
.version_id = 1,
|
|
|
|
.minimum_version_id = 1,
|
2014-09-23 16:09:54 +04:00
|
|
|
.needed = tsc_adjust_needed,
|
2014-04-16 17:32:32 +04:00
|
|
|
.fields = (VMStateField[]) {
|
2013-02-02 16:38:08 +04:00
|
|
|
VMSTATE_UINT64(env.tsc_adjust, X86CPU),
|
2012-11-27 09:32:18 +04:00
|
|
|
VMSTATE_END_OF_LIST()
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2018-02-27 13:22:12 +03:00
|
|
|
static bool msr_smi_count_needed(void *opaque)
|
|
|
|
{
|
|
|
|
X86CPU *cpu = opaque;
|
|
|
|
CPUX86State *env = &cpu->env;
|
|
|
|
|
|
|
|
return env->msr_smi_count != 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const VMStateDescription vmstate_msr_smi_count = {
|
|
|
|
.name = "cpu/msr_smi_count",
|
|
|
|
.version_id = 1,
|
|
|
|
.minimum_version_id = 1,
|
|
|
|
.needed = msr_smi_count_needed,
|
|
|
|
.fields = (VMStateField[]) {
|
|
|
|
VMSTATE_UINT64(env.msr_smi_count, X86CPU),
|
|
|
|
VMSTATE_END_OF_LIST()
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2011-10-05 23:52:32 +04:00
|
|
|
static bool tscdeadline_needed(void *opaque)
|
|
|
|
{
|
2013-02-02 16:38:08 +04:00
|
|
|
X86CPU *cpu = opaque;
|
|
|
|
CPUX86State *env = &cpu->env;
|
2011-10-05 23:52:32 +04:00
|
|
|
|
|
|
|
return env->tsc_deadline != 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const VMStateDescription vmstate_msr_tscdeadline = {
|
|
|
|
.name = "cpu/msr_tscdeadline",
|
|
|
|
.version_id = 1,
|
|
|
|
.minimum_version_id = 1,
|
2014-09-23 16:09:54 +04:00
|
|
|
.needed = tscdeadline_needed,
|
2014-04-16 17:32:32 +04:00
|
|
|
.fields = (VMStateField[]) {
|
2013-02-02 16:38:08 +04:00
|
|
|
VMSTATE_UINT64(env.tsc_deadline, X86CPU),
|
2011-10-05 23:52:32 +04:00
|
|
|
VMSTATE_END_OF_LIST()
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2011-10-04 18:26:35 +04:00
|
|
|
static bool misc_enable_needed(void *opaque)
|
|
|
|
{
|
2013-02-02 16:38:08 +04:00
|
|
|
X86CPU *cpu = opaque;
|
|
|
|
CPUX86State *env = &cpu->env;
|
2011-10-04 18:26:35 +04:00
|
|
|
|
|
|
|
return env->msr_ia32_misc_enable != MSR_IA32_MISC_ENABLE_DEFAULT;
|
|
|
|
}
|
|
|
|
|
2013-07-07 19:13:37 +04:00
|
|
|
static bool feature_control_needed(void *opaque)
|
|
|
|
{
|
|
|
|
X86CPU *cpu = opaque;
|
|
|
|
CPUX86State *env = &cpu->env;
|
|
|
|
|
|
|
|
return env->msr_ia32_feature_control != 0;
|
|
|
|
}
|
|
|
|
|
2011-10-04 18:26:35 +04:00
|
|
|
static const VMStateDescription vmstate_msr_ia32_misc_enable = {
|
|
|
|
.name = "cpu/msr_ia32_misc_enable",
|
|
|
|
.version_id = 1,
|
|
|
|
.minimum_version_id = 1,
|
2014-09-23 16:09:54 +04:00
|
|
|
.needed = misc_enable_needed,
|
2014-04-16 17:32:32 +04:00
|
|
|
.fields = (VMStateField[]) {
|
2013-02-02 16:38:08 +04:00
|
|
|
VMSTATE_UINT64(env.msr_ia32_misc_enable, X86CPU),
|
2011-10-04 18:26:35 +04:00
|
|
|
VMSTATE_END_OF_LIST()
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2013-07-07 19:13:37 +04:00
|
|
|
static const VMStateDescription vmstate_msr_ia32_feature_control = {
|
|
|
|
.name = "cpu/msr_ia32_feature_control",
|
|
|
|
.version_id = 1,
|
|
|
|
.minimum_version_id = 1,
|
2014-09-23 16:09:54 +04:00
|
|
|
.needed = feature_control_needed,
|
2014-04-16 17:32:32 +04:00
|
|
|
.fields = (VMStateField[]) {
|
2013-07-07 19:13:37 +04:00
|
|
|
VMSTATE_UINT64(env.msr_ia32_feature_control, X86CPU),
|
|
|
|
VMSTATE_END_OF_LIST()
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2013-07-25 19:05:22 +04:00
|
|
|
static bool pmu_enable_needed(void *opaque)
|
|
|
|
{
|
|
|
|
X86CPU *cpu = opaque;
|
|
|
|
CPUX86State *env = &cpu->env;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
if (env->msr_fixed_ctr_ctrl || env->msr_global_ctrl ||
|
|
|
|
env->msr_global_status || env->msr_global_ovf_ctrl) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
for (i = 0; i < MAX_FIXED_COUNTERS; i++) {
|
|
|
|
if (env->msr_fixed_counters[i]) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for (i = 0; i < MAX_GP_COUNTERS; i++) {
|
|
|
|
if (env->msr_gp_counters[i] || env->msr_gp_evtsel[i]) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const VMStateDescription vmstate_msr_architectural_pmu = {
|
|
|
|
.name = "cpu/msr_architectural_pmu",
|
|
|
|
.version_id = 1,
|
|
|
|
.minimum_version_id = 1,
|
2014-09-23 16:09:54 +04:00
|
|
|
.needed = pmu_enable_needed,
|
2014-04-16 17:32:32 +04:00
|
|
|
.fields = (VMStateField[]) {
|
2013-07-25 19:05:22 +04:00
|
|
|
VMSTATE_UINT64(env.msr_fixed_ctr_ctrl, X86CPU),
|
|
|
|
VMSTATE_UINT64(env.msr_global_ctrl, X86CPU),
|
|
|
|
VMSTATE_UINT64(env.msr_global_status, X86CPU),
|
|
|
|
VMSTATE_UINT64(env.msr_global_ovf_ctrl, X86CPU),
|
|
|
|
VMSTATE_UINT64_ARRAY(env.msr_fixed_counters, X86CPU, MAX_FIXED_COUNTERS),
|
|
|
|
VMSTATE_UINT64_ARRAY(env.msr_gp_counters, X86CPU, MAX_GP_COUNTERS),
|
|
|
|
VMSTATE_UINT64_ARRAY(env.msr_gp_evtsel, X86CPU, MAX_GP_COUNTERS),
|
|
|
|
VMSTATE_END_OF_LIST()
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2013-12-05 04:32:12 +04:00
|
|
|
static bool mpx_needed(void *opaque)
|
|
|
|
{
|
|
|
|
X86CPU *cpu = opaque;
|
|
|
|
CPUX86State *env = &cpu->env;
|
|
|
|
unsigned int i;
|
|
|
|
|
|
|
|
for (i = 0; i < 4; i++) {
|
|
|
|
if (env->bnd_regs[i].lb || env->bnd_regs[i].ub) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (env->bndcs_regs.cfgu || env->bndcs_regs.sts) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return !!env->msr_bndcfgs;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const VMStateDescription vmstate_mpx = {
|
|
|
|
.name = "cpu/mpx",
|
|
|
|
.version_id = 1,
|
|
|
|
.minimum_version_id = 1,
|
2014-09-23 16:09:54 +04:00
|
|
|
.needed = mpx_needed,
|
2014-04-16 17:32:32 +04:00
|
|
|
.fields = (VMStateField[]) {
|
2013-12-05 04:32:12 +04:00
|
|
|
VMSTATE_BND_REGS(env.bnd_regs, X86CPU, 4),
|
|
|
|
VMSTATE_UINT64(env.bndcs_regs.cfgu, X86CPU),
|
|
|
|
VMSTATE_UINT64(env.bndcs_regs.sts, X86CPU),
|
|
|
|
VMSTATE_UINT64(env.msr_bndcfgs, X86CPU),
|
|
|
|
VMSTATE_END_OF_LIST()
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2014-01-23 17:40:47 +04:00
|
|
|
static bool hyperv_hypercall_enable_needed(void *opaque)
|
|
|
|
{
|
|
|
|
X86CPU *cpu = opaque;
|
|
|
|
CPUX86State *env = &cpu->env;
|
|
|
|
|
|
|
|
return env->msr_hv_hypercall != 0 || env->msr_hv_guest_os_id != 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const VMStateDescription vmstate_msr_hypercall_hypercall = {
|
|
|
|
.name = "cpu/msr_hyperv_hypercall",
|
|
|
|
.version_id = 1,
|
|
|
|
.minimum_version_id = 1,
|
2014-09-23 16:09:54 +04:00
|
|
|
.needed = hyperv_hypercall_enable_needed,
|
2014-04-16 17:32:32 +04:00
|
|
|
.fields = (VMStateField[]) {
|
2014-01-23 17:40:47 +04:00
|
|
|
VMSTATE_UINT64(env.msr_hv_guest_os_id, X86CPU),
|
2014-04-02 19:33:02 +04:00
|
|
|
VMSTATE_UINT64(env.msr_hv_hypercall, X86CPU),
|
2014-01-23 17:40:47 +04:00
|
|
|
VMSTATE_END_OF_LIST()
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2014-01-23 17:40:48 +04:00
|
|
|
static bool hyperv_vapic_enable_needed(void *opaque)
|
|
|
|
{
|
|
|
|
X86CPU *cpu = opaque;
|
|
|
|
CPUX86State *env = &cpu->env;
|
|
|
|
|
|
|
|
return env->msr_hv_vapic != 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const VMStateDescription vmstate_msr_hyperv_vapic = {
|
|
|
|
.name = "cpu/msr_hyperv_vapic",
|
|
|
|
.version_id = 1,
|
|
|
|
.minimum_version_id = 1,
|
2014-09-23 16:09:54 +04:00
|
|
|
.needed = hyperv_vapic_enable_needed,
|
2014-04-16 17:32:32 +04:00
|
|
|
.fields = (VMStateField[]) {
|
2014-01-23 17:40:48 +04:00
|
|
|
VMSTATE_UINT64(env.msr_hv_vapic, X86CPU),
|
|
|
|
VMSTATE_END_OF_LIST()
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2014-01-23 17:40:49 +04:00
|
|
|
static bool hyperv_time_enable_needed(void *opaque)
|
|
|
|
{
|
|
|
|
X86CPU *cpu = opaque;
|
|
|
|
CPUX86State *env = &cpu->env;
|
|
|
|
|
|
|
|
return env->msr_hv_tsc != 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const VMStateDescription vmstate_msr_hyperv_time = {
|
|
|
|
.name = "cpu/msr_hyperv_time",
|
|
|
|
.version_id = 1,
|
|
|
|
.minimum_version_id = 1,
|
2014-09-23 16:09:54 +04:00
|
|
|
.needed = hyperv_time_enable_needed,
|
2014-04-16 17:32:32 +04:00
|
|
|
.fields = (VMStateField[]) {
|
2014-01-23 17:40:49 +04:00
|
|
|
VMSTATE_UINT64(env.msr_hv_tsc, X86CPU),
|
|
|
|
VMSTATE_END_OF_LIST()
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2015-09-09 15:41:30 +03:00
|
|
|
static bool hyperv_crash_enable_needed(void *opaque)
|
|
|
|
{
|
|
|
|
X86CPU *cpu = opaque;
|
|
|
|
CPUX86State *env = &cpu->env;
|
|
|
|
int i;
|
|
|
|
|
2017-07-13 23:15:21 +03:00
|
|
|
for (i = 0; i < HV_CRASH_PARAMS; i++) {
|
2015-09-09 15:41:30 +03:00
|
|
|
if (env->msr_hv_crash_params[i]) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const VMStateDescription vmstate_msr_hyperv_crash = {
|
|
|
|
.name = "cpu/msr_hyperv_crash",
|
|
|
|
.version_id = 1,
|
|
|
|
.minimum_version_id = 1,
|
|
|
|
.needed = hyperv_crash_enable_needed,
|
|
|
|
.fields = (VMStateField[]) {
|
2017-07-13 23:15:21 +03:00
|
|
|
VMSTATE_UINT64_ARRAY(env.msr_hv_crash_params, X86CPU, HV_CRASH_PARAMS),
|
2015-09-09 15:41:30 +03:00
|
|
|
VMSTATE_END_OF_LIST()
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2015-09-16 12:59:44 +03:00
|
|
|
static bool hyperv_runtime_enable_needed(void *opaque)
|
|
|
|
{
|
|
|
|
X86CPU *cpu = opaque;
|
|
|
|
CPUX86State *env = &cpu->env;
|
|
|
|
|
target-i386/machine: fix migrate faile because of Hyper-V HV_X64_MSR_VP_RUNTIME
Hyper-V HV_X64_MSR_VP_RUNTIME was introduced in linux-4.4 + qemu-2.5.
As long as the KVM module supports, qemu will save / load the
vmstate_msr_hyperv_runtime register during the migration.
Regardless of whether the hyperv_runtime configuration of x86_cpu_properties is
enabled.
The qemu-2.3 does not support this feature, of course, failed to migrate.
linux-BGSfqC:/home/qemu # ./x86_64-softmmu/qemu-system-x86_64 --enable-kvm \
-nodefaults -machine pc-i440fx-2.3,accel=kvm,usb=off -smp 4 -m 4096 -drive \
file=/work/suse/sles11sp3.img.bak,format=raw,if=none,id=drive-virtio-disk0,cache=none \
-device virtio-blk-pci,scsi=off,bus=pci.0,addr=0x5,drive=drive-virtio-disk0,id=virtio-disk0 \
-vnc :99 -device cirrus-vga,id=video0,vgamem_mb=8,bus=pci.0,addr=0x2 -monitor vc
save_section_header:se->section_id=3,se->idstr:ram,se->instance_id=0,se->version_id=4
save_section_header:se->section_id=0,se->idstr:timer,se->instance_id=0,se->version_id=2
save_section_header:se->section_id=4,se->idstr:cpu_common,se->instance_id=0,se->version_id=1
save_section_header:se->section_id=5,se->idstr:cpu,se->instance_id=0,se->version_id=12
vmstate_subsection_save:vmsd->name:cpu/async_pf_msr
hyperv_runtime_enable_needed:env->msr_hv_runtime=128902811
vmstate_subsection_save:vmsd->name:cpu/msr_hyperv_runtime
Since hyperv_runtime is false, vm will not use hv->runtime_offset, then
vmstate_msr_hyperv_runtime is no need to transfer while migrating.
Signed-off-by: ann.zhuangyanying@huawei.com
Message-Id: <1478247398-5016-1-git-send-email-ann.zhuangyanying@huawei.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2016-11-04 11:16:38 +03:00
|
|
|
if (!cpu->hyperv_runtime) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-09-16 12:59:44 +03:00
|
|
|
return env->msr_hv_runtime != 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const VMStateDescription vmstate_msr_hyperv_runtime = {
|
|
|
|
.name = "cpu/msr_hyperv_runtime",
|
|
|
|
.version_id = 1,
|
|
|
|
.minimum_version_id = 1,
|
|
|
|
.needed = hyperv_runtime_enable_needed,
|
|
|
|
.fields = (VMStateField[]) {
|
|
|
|
VMSTATE_UINT64(env.msr_hv_runtime, X86CPU),
|
|
|
|
VMSTATE_END_OF_LIST()
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2015-11-11 13:18:38 +03:00
|
|
|
static bool hyperv_synic_enable_needed(void *opaque)
|
|
|
|
{
|
|
|
|
X86CPU *cpu = opaque;
|
|
|
|
CPUX86State *env = &cpu->env;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
if (env->msr_hv_synic_control != 0 ||
|
|
|
|
env->msr_hv_synic_evt_page != 0 ||
|
|
|
|
env->msr_hv_synic_msg_page != 0) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < ARRAY_SIZE(env->msr_hv_synic_sint); i++) {
|
|
|
|
if (env->msr_hv_synic_sint[i] != 0) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const VMStateDescription vmstate_msr_hyperv_synic = {
|
|
|
|
.name = "cpu/msr_hyperv_synic",
|
|
|
|
.version_id = 1,
|
|
|
|
.minimum_version_id = 1,
|
|
|
|
.needed = hyperv_synic_enable_needed,
|
|
|
|
.fields = (VMStateField[]) {
|
|
|
|
VMSTATE_UINT64(env.msr_hv_synic_control, X86CPU),
|
|
|
|
VMSTATE_UINT64(env.msr_hv_synic_evt_page, X86CPU),
|
|
|
|
VMSTATE_UINT64(env.msr_hv_synic_msg_page, X86CPU),
|
2017-07-13 23:15:21 +03:00
|
|
|
VMSTATE_UINT64_ARRAY(env.msr_hv_synic_sint, X86CPU, HV_SINT_COUNT),
|
2015-11-11 13:18:38 +03:00
|
|
|
VMSTATE_END_OF_LIST()
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2015-11-25 18:21:25 +03:00
|
|
|
static bool hyperv_stimer_enable_needed(void *opaque)
|
|
|
|
{
|
|
|
|
X86CPU *cpu = opaque;
|
|
|
|
CPUX86State *env = &cpu->env;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < ARRAY_SIZE(env->msr_hv_stimer_config); i++) {
|
|
|
|
if (env->msr_hv_stimer_config[i] || env->msr_hv_stimer_count[i]) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const VMStateDescription vmstate_msr_hyperv_stimer = {
|
|
|
|
.name = "cpu/msr_hyperv_stimer",
|
|
|
|
.version_id = 1,
|
|
|
|
.minimum_version_id = 1,
|
|
|
|
.needed = hyperv_stimer_enable_needed,
|
|
|
|
.fields = (VMStateField[]) {
|
2017-07-13 23:15:21 +03:00
|
|
|
VMSTATE_UINT64_ARRAY(env.msr_hv_stimer_config, X86CPU,
|
|
|
|
HV_STIMER_COUNT),
|
|
|
|
VMSTATE_UINT64_ARRAY(env.msr_hv_stimer_count, X86CPU, HV_STIMER_COUNT),
|
2015-11-25 18:21:25 +03:00
|
|
|
VMSTATE_END_OF_LIST()
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2018-04-11 14:50:36 +03:00
|
|
|
static bool hyperv_reenlightenment_enable_needed(void *opaque)
|
|
|
|
{
|
|
|
|
X86CPU *cpu = opaque;
|
|
|
|
CPUX86State *env = &cpu->env;
|
|
|
|
|
|
|
|
return env->msr_hv_reenlightenment_control != 0 ||
|
|
|
|
env->msr_hv_tsc_emulation_control != 0 ||
|
|
|
|
env->msr_hv_tsc_emulation_status != 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const VMStateDescription vmstate_msr_hyperv_reenlightenment = {
|
|
|
|
.name = "cpu/msr_hyperv_reenlightenment",
|
|
|
|
.version_id = 1,
|
|
|
|
.minimum_version_id = 1,
|
|
|
|
.needed = hyperv_reenlightenment_enable_needed,
|
|
|
|
.fields = (VMStateField[]) {
|
|
|
|
VMSTATE_UINT64(env.msr_hv_reenlightenment_control, X86CPU),
|
|
|
|
VMSTATE_UINT64(env.msr_hv_tsc_emulation_control, X86CPU),
|
|
|
|
VMSTATE_UINT64(env.msr_hv_tsc_emulation_status, X86CPU),
|
|
|
|
VMSTATE_END_OF_LIST()
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2014-10-23 07:02:43 +04:00
|
|
|
static bool avx512_needed(void *opaque)
|
|
|
|
{
|
|
|
|
X86CPU *cpu = opaque;
|
|
|
|
CPUX86State *env = &cpu->env;
|
|
|
|
unsigned int i;
|
|
|
|
|
|
|
|
for (i = 0; i < NB_OPMASK_REGS; i++) {
|
|
|
|
if (env->opmask_regs[i]) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < CPU_NB_REGS; i++) {
|
2015-11-26 22:14:32 +03:00
|
|
|
#define ENV_XMM(reg, field) (env->xmm_regs[reg].ZMM_Q(field))
|
2014-10-24 11:50:21 +04:00
|
|
|
if (ENV_XMM(i, 4) || ENV_XMM(i, 6) ||
|
|
|
|
ENV_XMM(i, 5) || ENV_XMM(i, 7)) {
|
2014-10-23 07:02:43 +04:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
#ifdef TARGET_X86_64
|
2014-10-24 11:50:21 +04:00
|
|
|
if (ENV_XMM(i+16, 0) || ENV_XMM(i+16, 1) ||
|
|
|
|
ENV_XMM(i+16, 2) || ENV_XMM(i+16, 3) ||
|
|
|
|
ENV_XMM(i+16, 4) || ENV_XMM(i+16, 5) ||
|
|
|
|
ENV_XMM(i+16, 6) || ENV_XMM(i+16, 7)) {
|
2014-10-23 07:02:43 +04:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const VMStateDescription vmstate_avx512 = {
|
|
|
|
.name = "cpu/avx512",
|
|
|
|
.version_id = 1,
|
|
|
|
.minimum_version_id = 1,
|
2014-09-23 16:09:54 +04:00
|
|
|
.needed = avx512_needed,
|
2014-10-23 07:02:43 +04:00
|
|
|
.fields = (VMStateField[]) {
|
|
|
|
VMSTATE_UINT64_ARRAY(env.opmask_regs, X86CPU, NB_OPMASK_REGS),
|
2014-10-24 11:50:21 +04:00
|
|
|
VMSTATE_ZMMH_REGS_VARS(env.xmm_regs, X86CPU, 0),
|
2014-10-23 07:02:43 +04:00
|
|
|
#ifdef TARGET_X86_64
|
2014-10-24 11:50:21 +04:00
|
|
|
VMSTATE_Hi16_ZMM_REGS_VARS(env.xmm_regs, X86CPU, 16),
|
2014-10-23 07:02:43 +04:00
|
|
|
#endif
|
|
|
|
VMSTATE_END_OF_LIST()
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2014-12-03 05:36:23 +03:00
|
|
|
static bool xss_needed(void *opaque)
|
|
|
|
{
|
|
|
|
X86CPU *cpu = opaque;
|
|
|
|
CPUX86State *env = &cpu->env;
|
|
|
|
|
|
|
|
return env->xss != 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const VMStateDescription vmstate_xss = {
|
|
|
|
.name = "cpu/xss",
|
|
|
|
.version_id = 1,
|
|
|
|
.minimum_version_id = 1,
|
2014-09-23 16:09:54 +04:00
|
|
|
.needed = xss_needed,
|
2014-12-03 05:36:23 +03:00
|
|
|
.fields = (VMStateField[]) {
|
|
|
|
VMSTATE_UINT64(env.xss, X86CPU),
|
|
|
|
VMSTATE_END_OF_LIST()
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2015-11-18 05:20:15 +03:00
|
|
|
#ifdef TARGET_X86_64
|
|
|
|
static bool pkru_needed(void *opaque)
|
|
|
|
{
|
|
|
|
X86CPU *cpu = opaque;
|
|
|
|
CPUX86State *env = &cpu->env;
|
|
|
|
|
|
|
|
return env->pkru != 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const VMStateDescription vmstate_pkru = {
|
|
|
|
.name = "cpu/pkru",
|
|
|
|
.version_id = 1,
|
|
|
|
.minimum_version_id = 1,
|
|
|
|
.needed = pkru_needed,
|
|
|
|
.fields = (VMStateField[]){
|
|
|
|
VMSTATE_UINT32(env.pkru, X86CPU),
|
|
|
|
VMSTATE_END_OF_LIST()
|
|
|
|
}
|
|
|
|
};
|
|
|
|
#endif
|
|
|
|
|
2015-11-24 06:33:57 +03:00
|
|
|
static bool tsc_khz_needed(void *opaque)
|
|
|
|
{
|
|
|
|
X86CPU *cpu = opaque;
|
|
|
|
CPUX86State *env = &cpu->env;
|
|
|
|
MachineClass *mc = MACHINE_GET_CLASS(qdev_get_machine());
|
|
|
|
PCMachineClass *pcmc = PC_MACHINE_CLASS(mc);
|
|
|
|
return env->tsc_khz && pcmc->save_tsc_khz;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const VMStateDescription vmstate_tsc_khz = {
|
|
|
|
.name = "cpu/tsc_khz",
|
|
|
|
.version_id = 1,
|
|
|
|
.minimum_version_id = 1,
|
|
|
|
.needed = tsc_khz_needed,
|
|
|
|
.fields = (VMStateField[]) {
|
|
|
|
VMSTATE_INT64(env.tsc_khz, X86CPU),
|
|
|
|
VMSTATE_END_OF_LIST()
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2016-06-22 09:56:21 +03:00
|
|
|
static bool mcg_ext_ctl_needed(void *opaque)
|
|
|
|
{
|
|
|
|
X86CPU *cpu = opaque;
|
|
|
|
CPUX86State *env = &cpu->env;
|
|
|
|
return cpu->enable_lmce && env->mcg_ext_ctl;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const VMStateDescription vmstate_mcg_ext_ctl = {
|
|
|
|
.name = "cpu/mcg_ext_ctl",
|
|
|
|
.version_id = 1,
|
|
|
|
.minimum_version_id = 1,
|
|
|
|
.needed = mcg_ext_ctl_needed,
|
|
|
|
.fields = (VMStateField[]) {
|
|
|
|
VMSTATE_UINT64(env.mcg_ext_ctl, X86CPU),
|
|
|
|
VMSTATE_END_OF_LIST()
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2018-01-09 18:45:14 +03:00
|
|
|
static bool spec_ctrl_needed(void *opaque)
|
|
|
|
{
|
|
|
|
X86CPU *cpu = opaque;
|
|
|
|
CPUX86State *env = &cpu->env;
|
|
|
|
|
|
|
|
return env->spec_ctrl != 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const VMStateDescription vmstate_spec_ctrl = {
|
|
|
|
.name = "cpu/spec_ctrl",
|
|
|
|
.version_id = 1,
|
|
|
|
.minimum_version_id = 1,
|
|
|
|
.needed = spec_ctrl_needed,
|
|
|
|
.fields = (VMStateField[]){
|
|
|
|
VMSTATE_UINT64(env.spec_ctrl, X86CPU),
|
|
|
|
VMSTATE_END_OF_LIST()
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2018-03-04 19:48:36 +03:00
|
|
|
static bool intel_pt_enable_needed(void *opaque)
|
|
|
|
{
|
|
|
|
X86CPU *cpu = opaque;
|
|
|
|
CPUX86State *env = &cpu->env;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
if (env->msr_rtit_ctrl || env->msr_rtit_status ||
|
|
|
|
env->msr_rtit_output_base || env->msr_rtit_output_mask ||
|
|
|
|
env->msr_rtit_cr3_match) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < MAX_RTIT_ADDRS; i++) {
|
|
|
|
if (env->msr_rtit_addrs[i]) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const VMStateDescription vmstate_msr_intel_pt = {
|
|
|
|
.name = "cpu/intel_pt",
|
|
|
|
.version_id = 1,
|
|
|
|
.minimum_version_id = 1,
|
|
|
|
.needed = intel_pt_enable_needed,
|
|
|
|
.fields = (VMStateField[]) {
|
|
|
|
VMSTATE_UINT64(env.msr_rtit_ctrl, X86CPU),
|
|
|
|
VMSTATE_UINT64(env.msr_rtit_status, X86CPU),
|
|
|
|
VMSTATE_UINT64(env.msr_rtit_output_base, X86CPU),
|
|
|
|
VMSTATE_UINT64(env.msr_rtit_output_mask, X86CPU),
|
|
|
|
VMSTATE_UINT64(env.msr_rtit_cr3_match, X86CPU),
|
|
|
|
VMSTATE_UINT64_ARRAY(env.msr_rtit_addrs, X86CPU, MAX_RTIT_ADDRS),
|
|
|
|
VMSTATE_END_OF_LIST()
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2018-05-22 00:54:24 +03:00
|
|
|
static bool virt_ssbd_needed(void *opaque)
|
|
|
|
{
|
|
|
|
X86CPU *cpu = opaque;
|
|
|
|
CPUX86State *env = &cpu->env;
|
|
|
|
|
|
|
|
return env->virt_ssbd != 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const VMStateDescription vmstate_msr_virt_ssbd = {
|
|
|
|
.name = "cpu/virt_ssbd",
|
|
|
|
.version_id = 1,
|
|
|
|
.minimum_version_id = 1,
|
|
|
|
.needed = virt_ssbd_needed,
|
|
|
|
.fields = (VMStateField[]){
|
|
|
|
VMSTATE_UINT64(env.virt_ssbd, X86CPU),
|
|
|
|
VMSTATE_END_OF_LIST()
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2014-05-14 23:30:09 +04:00
|
|
|
VMStateDescription vmstate_x86_cpu = {
|
2009-09-30 00:49:08 +04:00
|
|
|
.name = "cpu",
|
2013-02-02 16:38:08 +04:00
|
|
|
.version_id = 12,
|
2017-04-05 22:00:24 +03:00
|
|
|
.minimum_version_id = 11,
|
2009-09-30 00:49:08 +04:00
|
|
|
.pre_save = cpu_pre_save,
|
|
|
|
.post_load = cpu_post_load,
|
2014-04-16 17:32:32 +04:00
|
|
|
.fields = (VMStateField[]) {
|
2013-02-02 16:38:08 +04:00
|
|
|
VMSTATE_UINTTL_ARRAY(env.regs, X86CPU, CPU_NB_REGS),
|
|
|
|
VMSTATE_UINTTL(env.eip, X86CPU),
|
|
|
|
VMSTATE_UINTTL(env.eflags, X86CPU),
|
|
|
|
VMSTATE_UINT32(env.hflags, X86CPU),
|
2009-09-30 00:49:08 +04:00
|
|
|
/* FPU */
|
2013-02-02 16:38:08 +04:00
|
|
|
VMSTATE_UINT16(env.fpuc, X86CPU),
|
|
|
|
VMSTATE_UINT16(env.fpus_vmstate, X86CPU),
|
|
|
|
VMSTATE_UINT16(env.fptag_vmstate, X86CPU),
|
|
|
|
VMSTATE_UINT16(env.fpregs_format_vmstate, X86CPU),
|
2017-04-05 22:00:22 +03:00
|
|
|
|
|
|
|
VMSTATE_STRUCT_ARRAY(env.fpregs, X86CPU, 8, 0, vmstate_fpreg, FPReg),
|
2013-02-02 16:38:08 +04:00
|
|
|
|
|
|
|
VMSTATE_SEGMENT_ARRAY(env.segs, X86CPU, 6),
|
|
|
|
VMSTATE_SEGMENT(env.ldt, X86CPU),
|
|
|
|
VMSTATE_SEGMENT(env.tr, X86CPU),
|
|
|
|
VMSTATE_SEGMENT(env.gdt, X86CPU),
|
|
|
|
VMSTATE_SEGMENT(env.idt, X86CPU),
|
|
|
|
|
|
|
|
VMSTATE_UINT32(env.sysenter_cs, X86CPU),
|
|
|
|
VMSTATE_UINTTL(env.sysenter_esp, X86CPU),
|
|
|
|
VMSTATE_UINTTL(env.sysenter_eip, X86CPU),
|
2008-05-04 17:11:44 +04:00
|
|
|
|
2013-02-02 16:38:08 +04:00
|
|
|
VMSTATE_UINTTL(env.cr[0], X86CPU),
|
|
|
|
VMSTATE_UINTTL(env.cr[2], X86CPU),
|
|
|
|
VMSTATE_UINTTL(env.cr[3], X86CPU),
|
|
|
|
VMSTATE_UINTTL(env.cr[4], X86CPU),
|
|
|
|
VMSTATE_UINTTL_ARRAY(env.dr, X86CPU, 8),
|
2009-09-30 00:49:08 +04:00
|
|
|
/* MMU */
|
2013-02-02 16:38:08 +04:00
|
|
|
VMSTATE_INT32(env.a20_mask, X86CPU),
|
2009-09-30 00:49:08 +04:00
|
|
|
/* XMM */
|
2013-02-02 16:38:08 +04:00
|
|
|
VMSTATE_UINT32(env.mxcsr, X86CPU),
|
2014-10-24 12:18:38 +04:00
|
|
|
VMSTATE_XMM_REGS(env.xmm_regs, X86CPU, 0),
|
2008-05-04 17:11:44 +04:00
|
|
|
|
|
|
|
#ifdef TARGET_X86_64
|
2013-02-02 16:38:08 +04:00
|
|
|
VMSTATE_UINT64(env.efer, X86CPU),
|
|
|
|
VMSTATE_UINT64(env.star, X86CPU),
|
|
|
|
VMSTATE_UINT64(env.lstar, X86CPU),
|
|
|
|
VMSTATE_UINT64(env.cstar, X86CPU),
|
|
|
|
VMSTATE_UINT64(env.fmask, X86CPU),
|
|
|
|
VMSTATE_UINT64(env.kernelgsbase, X86CPU),
|
2008-05-04 17:11:44 +04:00
|
|
|
#endif
|
2017-04-05 22:00:24 +03:00
|
|
|
VMSTATE_UINT32(env.smbase, X86CPU),
|
|
|
|
|
|
|
|
VMSTATE_UINT64(env.pat, X86CPU),
|
|
|
|
VMSTATE_UINT32(env.hflags2, X86CPU),
|
|
|
|
|
|
|
|
VMSTATE_UINT64(env.vm_hsave, X86CPU),
|
|
|
|
VMSTATE_UINT64(env.vm_vmcb, X86CPU),
|
|
|
|
VMSTATE_UINT64(env.tsc_offset, X86CPU),
|
|
|
|
VMSTATE_UINT64(env.intercept, X86CPU),
|
|
|
|
VMSTATE_UINT16(env.intercept_cr_read, X86CPU),
|
|
|
|
VMSTATE_UINT16(env.intercept_cr_write, X86CPU),
|
|
|
|
VMSTATE_UINT16(env.intercept_dr_read, X86CPU),
|
|
|
|
VMSTATE_UINT16(env.intercept_dr_write, X86CPU),
|
|
|
|
VMSTATE_UINT32(env.intercept_exceptions, X86CPU),
|
|
|
|
VMSTATE_UINT8(env.v_tpr, X86CPU),
|
2009-01-29 20:02:17 +03:00
|
|
|
/* MTRRs */
|
2017-04-05 22:00:24 +03:00
|
|
|
VMSTATE_UINT64_ARRAY(env.mtrr_fixed, X86CPU, 11),
|
|
|
|
VMSTATE_UINT64(env.mtrr_deftype, X86CPU),
|
2014-08-15 01:39:27 +04:00
|
|
|
VMSTATE_MTRR_VARS(env.mtrr_var, X86CPU, MSR_MTRRcap_VCNT, 8),
|
2009-09-30 00:49:08 +04:00
|
|
|
/* KVM-related states */
|
2017-04-05 22:00:24 +03:00
|
|
|
VMSTATE_INT32(env.interrupt_injected, X86CPU),
|
|
|
|
VMSTATE_UINT32(env.mp_state, X86CPU),
|
|
|
|
VMSTATE_UINT64(env.tsc, X86CPU),
|
|
|
|
VMSTATE_INT32(env.exception_injected, X86CPU),
|
|
|
|
VMSTATE_UINT8(env.soft_interrupt, X86CPU),
|
|
|
|
VMSTATE_UINT8(env.nmi_injected, X86CPU),
|
|
|
|
VMSTATE_UINT8(env.nmi_pending, X86CPU),
|
|
|
|
VMSTATE_UINT8(env.has_error_code, X86CPU),
|
|
|
|
VMSTATE_UINT32(env.sipi_vector, X86CPU),
|
2009-09-30 00:49:08 +04:00
|
|
|
/* MCE */
|
2017-04-05 22:00:24 +03:00
|
|
|
VMSTATE_UINT64(env.mcg_cap, X86CPU),
|
|
|
|
VMSTATE_UINT64(env.mcg_status, X86CPU),
|
|
|
|
VMSTATE_UINT64(env.mcg_ctl, X86CPU),
|
|
|
|
VMSTATE_UINT64_ARRAY(env.mce_banks, X86CPU, MCE_BANKS_DEF * 4),
|
2009-09-30 00:49:08 +04:00
|
|
|
/* rdtscp */
|
2017-04-05 22:00:24 +03:00
|
|
|
VMSTATE_UINT64(env.tsc_aux, X86CPU),
|
2009-10-22 16:26:56 +04:00
|
|
|
/* KVM pvclock msr */
|
2017-04-05 22:00:24 +03:00
|
|
|
VMSTATE_UINT64(env.system_time_msr, X86CPU),
|
|
|
|
VMSTATE_UINT64(env.wall_clock_msr, X86CPU),
|
2010-06-17 13:53:07 +04:00
|
|
|
/* XSAVE related fields */
|
2013-02-02 16:38:08 +04:00
|
|
|
VMSTATE_UINT64_V(env.xcr0, X86CPU, 12),
|
|
|
|
VMSTATE_UINT64_V(env.xstate_bv, X86CPU, 12),
|
2014-10-24 11:50:21 +04:00
|
|
|
VMSTATE_YMMH_REGS_VARS(env.xmm_regs, X86CPU, 0, 12),
|
2009-09-30 00:49:08 +04:00
|
|
|
VMSTATE_END_OF_LIST()
|
2009-11-25 02:33:03 +03:00
|
|
|
/* The above list is not sorted /wrt version numbers, watch out! */
|
2010-10-24 16:27:55 +04:00
|
|
|
},
|
2014-09-23 16:09:54 +04:00
|
|
|
.subsections = (const VMStateDescription*[]) {
|
|
|
|
&vmstate_async_pf_msr,
|
|
|
|
&vmstate_pv_eoi_msr,
|
|
|
|
&vmstate_steal_time_msr,
|
|
|
|
&vmstate_fpop_ip_dp,
|
|
|
|
&vmstate_msr_tsc_adjust,
|
|
|
|
&vmstate_msr_tscdeadline,
|
|
|
|
&vmstate_msr_ia32_misc_enable,
|
|
|
|
&vmstate_msr_ia32_feature_control,
|
|
|
|
&vmstate_msr_architectural_pmu,
|
|
|
|
&vmstate_mpx,
|
|
|
|
&vmstate_msr_hypercall_hypercall,
|
|
|
|
&vmstate_msr_hyperv_vapic,
|
|
|
|
&vmstate_msr_hyperv_time,
|
2015-09-09 15:41:30 +03:00
|
|
|
&vmstate_msr_hyperv_crash,
|
2015-09-16 12:59:44 +03:00
|
|
|
&vmstate_msr_hyperv_runtime,
|
2015-11-11 13:18:38 +03:00
|
|
|
&vmstate_msr_hyperv_synic,
|
2015-11-25 18:21:25 +03:00
|
|
|
&vmstate_msr_hyperv_stimer,
|
2018-04-11 14:50:36 +03:00
|
|
|
&vmstate_msr_hyperv_reenlightenment,
|
2014-09-23 16:09:54 +04:00
|
|
|
&vmstate_avx512,
|
|
|
|
&vmstate_xss,
|
2015-11-24 06:33:57 +03:00
|
|
|
&vmstate_tsc_khz,
|
2018-02-27 13:22:12 +03:00
|
|
|
&vmstate_msr_smi_count,
|
2015-11-18 05:20:15 +03:00
|
|
|
#ifdef TARGET_X86_64
|
|
|
|
&vmstate_pkru,
|
|
|
|
#endif
|
2018-01-09 18:45:14 +03:00
|
|
|
&vmstate_spec_ctrl,
|
2016-06-22 09:56:21 +03:00
|
|
|
&vmstate_mcg_ext_ctl,
|
2018-03-04 19:48:36 +03:00
|
|
|
&vmstate_msr_intel_pt,
|
2018-05-22 00:54:24 +03:00
|
|
|
&vmstate_msr_virt_ssbd,
|
2014-09-23 16:09:54 +04:00
|
|
|
NULL
|
2009-06-23 06:05:14 +04:00
|
|
|
}
|
2009-09-30 00:49:08 +04:00
|
|
|
};
|