[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH v13 23/60] i386/xen: handle VCPUOP_register_runstate_memory_area
From: |
David Woodhouse |
Subject: |
[PATCH v13 23/60] i386/xen: handle VCPUOP_register_runstate_memory_area |
Date: |
Thu, 23 Feb 2023 12:45:36 +0000 |
From: Joao Martins <joao.m.martins@oracle.com>
Allow guest to setup the vcpu runstates which is used as
steal clock.
Signed-off-by: Joao Martins <joao.m.martins@oracle.com>
Signed-off-by: David Woodhouse <dwmw@amazon.co.uk>
Reviewed-by: Paul Durrant <paul@xen.org>
---
target/i386/cpu.h | 1 +
target/i386/kvm/xen-emu.c | 57 +++++++++++++++++++++++++++++++++++++++
target/i386/machine.c | 1 +
3 files changed, 59 insertions(+)
diff --git a/target/i386/cpu.h b/target/i386/cpu.h
index 96c2d0d5cb..bf44a87ddb 100644
--- a/target/i386/cpu.h
+++ b/target/i386/cpu.h
@@ -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;
diff --git a/target/i386/kvm/xen-emu.c b/target/i386/kvm/xen-emu.c
index 0b3bd0b889..f5c8b6d20c 100644
--- a/target/i386/kvm/xen-emu.c
+++ b/target/i386/kvm/xen-emu.c
@@ -160,6 +160,7 @@ int kvm_xen_init_vcpu(CPUState *cs)
env->xen_vcpu_info_gpa = INVALID_GPA;
env->xen_vcpu_info_default_gpa = INVALID_GPA;
env->xen_vcpu_time_info_gpa = INVALID_GPA;
+ env->xen_vcpu_runstate_gpa = INVALID_GPA;
return 0;
}
@@ -254,6 +255,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 void do_vcpu_soft_reset(CPUState *cs, run_on_cpu_data data)
{
X86CPU *cpu = X86_CPU(cs);
@@ -262,10 +274,14 @@ static void do_vcpu_soft_reset(CPUState *cs,
run_on_cpu_data data)
env->xen_vcpu_info_gpa = INVALID_GPA;
env->xen_vcpu_info_default_gpa = INVALID_GPA;
env->xen_vcpu_time_info_gpa = INVALID_GPA;
+ env->xen_vcpu_runstate_gpa = INVALID_GPA;
kvm_xen_set_vcpu_attr(cs, KVM_XEN_VCPU_ATTR_TYPE_VCPU_INFO, INVALID_GPA);
kvm_xen_set_vcpu_attr(cs, KVM_XEN_VCPU_ATTR_TYPE_VCPU_TIME_INFO,
INVALID_GPA);
+ kvm_xen_set_vcpu_attr(cs, KVM_XEN_VCPU_ATTR_TYPE_RUNSTATE_ADDR,
+ INVALID_GPA);
+
}
static int xen_set_shared_info(uint64_t gfn)
@@ -517,6 +533,35 @@ 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;
+
+ /* No need for 32/64 compat handling */
+ qemu_build_assert(sizeof(rma) == 8);
+ /* The runstate area actually does change size, but Linux copes. */
+
+ if (!target) {
+ return -ENOENT;
+ }
+
+ if (kvm_copy_from_gva(cs, arg, &rma, sizeof(rma))) {
+ return -EFAULT;
+ }
+
+ /* As with vcpu_time_info, Xen actually uses the GVA but KVM doesn't. */
+ if (!kvm_gva_to_gpa(cs, rma.addr.p, &gpa, &len, false)) {
+ 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)
{
@@ -525,6 +570,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;
@@ -730,6 +778,15 @@ int kvm_put_xen_state(CPUState *cs)
}
}
+ gpa = env->xen_vcpu_runstate_gpa;
+ if (gpa != INVALID_GPA) {
+ ret = kvm_xen_set_vcpu_attr(cs, KVM_XEN_VCPU_ATTR_TYPE_RUNSTATE_ADDR,
+ gpa);
+ if (ret < 0) {
+ return ret;
+ }
+ }
+
return 0;
}
diff --git a/target/i386/machine.c b/target/i386/machine.c
index eb657907ca..3f3d436aaa 100644
--- a/target/i386/machine.c
+++ b/target/i386/machine.c
@@ -1273,6 +1273,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()
}
};
--
2.39.0
- [PATCH v13 34/60] hw/xen: Implement EVTCHNOP_send, (continued)
- [PATCH v13 34/60] hw/xen: Implement EVTCHNOP_send, David Woodhouse, 2023/02/23
- [PATCH v13 16/60] i386/xen: manage and save/restore Xen guest long_mode setting, David Woodhouse, 2023/02/23
- [PATCH v13 29/60] hw/xen: Implement EVTCHNOP_status, David Woodhouse, 2023/02/23
- [PATCH v13 26/60] i386/xen: implement HVMOP_set_param, David Woodhouse, 2023/02/23
- [PATCH v13 14/60] xen: Permit --xen-domid argument when accel is KVM, David Woodhouse, 2023/02/23
- [PATCH v13 04/60] i386/kvm: Add xen-version KVM accelerator property and init KVM Xen support, David Woodhouse, 2023/02/23
- [PATCH v13 60/60] hw/xen: Subsume xen_be_register_common() into xen_be_init(), David Woodhouse, 2023/02/23
- [PATCH v13 43/60] hw/xen: Add xen_gnttab device for grant table emulation, David Woodhouse, 2023/02/23
- [PATCH v13 21/60] i386/xen: handle VCPUOP_register_vcpu_info, David Woodhouse, 2023/02/23
- [PATCH v13 02/60] xen: add CONFIG_XEN_BUS and CONFIG_XEN_EMU options for Xen emulation, David Woodhouse, 2023/02/23
- [PATCH v13 23/60] i386/xen: handle VCPUOP_register_runstate_memory_area,
David Woodhouse <=
- [PATCH v13 32/60] hw/xen: Implement EVTCHNOP_bind_virq, David Woodhouse, 2023/02/23
- [PATCH v13 58/60] kvm/i386: Add xen-evtchn-max-pirq property, David Woodhouse, 2023/02/23
- [PATCH v13 59/60] i386/xen: Document Xen HVM emulation, David Woodhouse, 2023/02/23
- [PATCH v13 01/60] include: import Xen public headers to hw/xen/interface, David Woodhouse, 2023/02/23
- [PATCH v13 13/60] hw/xen: Add xen_overlay device for emulating shared xenheap pages, David Woodhouse, 2023/02/23
- [PATCH v13 27/60] hw/xen: Add xen_evtchn device for event channel emulation, David Woodhouse, 2023/02/23
- [PATCH v13 41/60] hw/xen: Support HVM_PARAM_CALLBACK_TYPE_PCI_INTX callback, David Woodhouse, 2023/02/23
- [PATCH v13 39/60] i386/xen: add monitor commands to test event injection, David Woodhouse, 2023/02/23
- [PATCH v13 40/60] hw/xen: Support HVM_PARAM_CALLBACK_TYPE_GSI callback, David Woodhouse, 2023/02/23
- [PATCH v13 57/60] hw/xen: Support MSI mapping to PIRQ, David Woodhouse, 2023/02/23