@@ -1791,6 +1791,7 @@ typedef struct CPUArchState {
uint64_t xen_vcpu_info_gpa;
uint64_t xen_vcpu_info_default_gpa;
uint64_t xen_vcpu_time_info_gpa;
+ uint64_t xen_vcpu_runstate_gpa;
#endif
#if defined(CONFIG_HVF)
HVFX86LazyFlags hvf_lflags;
@@ -1814,6 +1814,7 @@ int kvm_arch_init_vcpu(CPUState *cs)
env->xen_vcpu_info_gpa = UINT64_MAX;
env->xen_vcpu_info_default_gpa = UINT64_MAX;
env->xen_vcpu_time_info_gpa = UINT64_MAX;
+ env->xen_vcpu_runstate_gpa = UINT64_MAX;
xen_version = kvm_arch_xen_version(MACHINE(qdev_get_machine()));
if (xen_version) {
@@ -4753,6 +4754,14 @@ int kvm_arch_put_registers(CPUState *cpu, int level)
return ret;
}
}
+
+ gpa = x86_cpu->env.xen_vcpu_runstate_gpa;
+ if (gpa != UINT64_MAX) {
+ ret = kvm_xen_set_vcpu_attr(cpu, KVM_XEN_VCPU_ATTR_TYPE_RUNSTATE_ADDR, gpa);
+ if (ret < 0) {
+ return ret;
+ }
+ }
}
#endif
@@ -1264,7 +1264,8 @@ static bool xen_vcpu_needed(void *opaque)
return (env->xen_vcpu_info_gpa != UINT64_MAX ||
env->xen_vcpu_info_default_gpa != UINT64_MAX ||
- env->xen_vcpu_time_info_gpa != UINT64_MAX);
+ env->xen_vcpu_time_info_gpa != UINT64_MAX ||
+ env->xen_vcpu_runstate_gpa != UINT64_MAX);
}
static const VMStateDescription vmstate_xen_vcpu = {
@@ -1276,6 +1277,7 @@ static const VMStateDescription vmstate_xen_vcpu = {
VMSTATE_UINT64(env.xen_vcpu_info_gpa, X86CPU),
VMSTATE_UINT64(env.xen_vcpu_info_default_gpa, X86CPU),
VMSTATE_UINT64(env.xen_vcpu_time_info_gpa, X86CPU),
+ VMSTATE_UINT64(env.xen_vcpu_runstate_gpa, X86CPU),
VMSTATE_END_OF_LIST()
}
};
@@ -190,6 +190,17 @@ static void do_set_vcpu_time_info_gpa(CPUState *cs, run_on_cpu_data data)
env->xen_vcpu_time_info_gpa);
}
+static void do_set_vcpu_runstate_gpa(CPUState *cs, run_on_cpu_data data)
+{
+ X86CPU *cpu = X86_CPU(cs);
+ CPUX86State *env = &cpu->env;
+
+ env->xen_vcpu_runstate_gpa = data.host_ulong;
+
+ kvm_xen_set_vcpu_attr(cs, KVM_XEN_VCPU_ATTR_TYPE_RUNSTATE_ADDR,
+ env->xen_vcpu_runstate_gpa);
+}
+
static int xen_set_shared_info(CPUState *cs, uint64_t gfn)
{
uint64_t gpa = gfn << TARGET_PAGE_BITS;
@@ -303,6 +314,27 @@ static int vcpuop_register_vcpu_time_info(CPUState *cs, CPUState *target,
return 0;
}
+static int vcpuop_register_runstate_info(CPUState *cs, CPUState *target,
+ uint64_t arg)
+{
+ struct vcpu_register_runstate_memory_area rma;
+ uint64_t gpa;
+ size_t len;
+
+ if (kvm_copy_from_gva(cs, arg, &rma, sizeof(*rma.addr.v))) {
+ return -EFAULT;
+ }
+
+ if (!kvm_gva_to_gpa(cs, rma.addr.p, &gpa, &len, false) ||
+ len < sizeof(struct vcpu_time_info)) {
+ return -EFAULT;
+ }
+
+ async_run_on_cpu(target, do_set_vcpu_runstate_gpa,
+ RUN_ON_CPU_HOST_ULONG(gpa));
+ return 0;
+}
+
static bool kvm_xen_hcall_vcpu_op(struct kvm_xen_exit *exit, X86CPU *cpu,
int cmd, int vcpu_id, uint64_t arg)
{
@@ -311,6 +343,9 @@ static bool kvm_xen_hcall_vcpu_op(struct kvm_xen_exit *exit, X86CPU *cpu,
int err;
switch (cmd) {
+ case VCPUOP_register_runstate_memory_area:
+ err = vcpuop_register_runstate_info(cs, dest, arg);
+ break;
case VCPUOP_register_vcpu_time_memory_area:
err = vcpuop_register_vcpu_time_info(cs, dest, arg);
break;