diff --git a/target/i386/kvm.c b/target/i386/kvm.c index a6613e19f2..6db7783edc 100644 --- a/target/i386/kvm.c +++ b/target/i386/kvm.c @@ -2444,8 +2444,10 @@ static int kvm_put_vcpu_events(X86CPU *cpu, int level) } if (level >= KVM_PUT_RESET_STATE) { - events.flags |= - KVM_VCPUEVENT_VALID_NMI_PENDING | KVM_VCPUEVENT_VALID_SIPI_VECTOR; + events.flags |= KVM_VCPUEVENT_VALID_NMI_PENDING; + if (env->mp_state == KVM_MP_STATE_SIPI_RECEIVED) { + events.flags |= KVM_VCPUEVENT_VALID_SIPI_VECTOR; + } } return kvm_vcpu_ioctl(CPU(cpu), KVM_SET_VCPU_EVENTS, &events); @@ -2633,6 +2635,10 @@ int kvm_arch_put_registers(CPUState *cpu, int level) if (ret < 0) { return ret; } + ret = kvm_put_vcpu_events(x86_cpu, level); + if (ret < 0) { + return ret; + } if (level >= KVM_PUT_RESET_STATE) { ret = kvm_put_mp_state(x86_cpu); if (ret < 0) { @@ -2644,11 +2650,6 @@ int kvm_arch_put_registers(CPUState *cpu, int level) if (ret < 0) { return ret; } - - ret = kvm_put_vcpu_events(x86_cpu, level); - if (ret < 0) { - return ret; - } ret = kvm_put_debugregs(x86_cpu); if (ret < 0) { return ret; @@ -2668,6 +2669,18 @@ int kvm_arch_get_registers(CPUState *cs) assert(cpu_is_stopped(cs) || qemu_cpu_is_self(cs)); + ret = kvm_get_vcpu_events(cpu); + if (ret < 0) { + goto out; + } + /* + * KVM_GET_MPSTATE can modify CS and RIP, call it before + * KVM_GET_REGS and KVM_GET_SREGS. + */ + ret = kvm_get_mp_state(cpu); + if (ret < 0) { + goto out; + } ret = kvm_getput_regs(cpu, 0); if (ret < 0) { goto out; @@ -2688,18 +2701,10 @@ int kvm_arch_get_registers(CPUState *cs) if (ret < 0) { goto out; } - ret = kvm_get_mp_state(cpu); - if (ret < 0) { - goto out; - } ret = kvm_get_apic(cpu); if (ret < 0) { goto out; } - ret = kvm_get_vcpu_events(cpu); - if (ret < 0) { - goto out; - } ret = kvm_get_debugregs(cpu); if (ret < 0) { goto out;