Have them be a machine option instead of a CPU one, to have something available, even if not ideal...
The existing Hyper-V enlightenments configuration mechanism is part of per-CPU configuration, which happens too late for this. Signed-off-by: Mohamed Mediouni <[email protected]> --- accel/whpx/whpx-common.c | 43 ++++++++++++++++++++++++++++++++++ include/system/whpx-internal.h | 4 ++++ target/i386/whpx/whpx-all.c | 20 +++++++++------- 3 files changed, 58 insertions(+), 9 deletions(-) diff --git a/accel/whpx/whpx-common.c b/accel/whpx/whpx-common.c index 4863fc8663..a75d4338e2 100644 --- a/accel/whpx/whpx-common.c +++ b/accel/whpx/whpx-common.c @@ -25,6 +25,7 @@ #include "qapi/qapi-visit-common.h" #include "migration/blocker.h" #include "accel/accel-cpu-target.h" +#include "qemu/target-info.h" #include <winerror.h> #include "system/whpx-internal.h" @@ -470,6 +471,40 @@ static void whpx_set_kernel_irqchip(Object *obj, Visitor *v, } } +static void whpx_set_hyperv(Object *obj, Visitor *v, + const char *name, void *opaque, + Error **errp) +{ + struct whpx_state *whpx = &whpx_global; + OnOffAuto mode; + + if (!visit_type_OnOffAuto(v, name, &mode, errp)) { + return; + } + + switch (mode) { + case ON_OFF_AUTO_ON: + whpx->hyperv_enlightenments_allowed = true; + whpx->hyperv_enlightenments_required = true; + break; + + case ON_OFF_AUTO_OFF: + whpx->hyperv_enlightenments_allowed = false; + whpx->hyperv_enlightenments_required = false; + break; + + case ON_OFF_AUTO_AUTO: + whpx->hyperv_enlightenments_allowed = true; + whpx->hyperv_enlightenments_required = false; + default: + /* + * The value was checked in visit_type_OnOffAuto() above. If + * we get here, then something is wrong in QEMU. + */ + abort(); + } +} + static void whpx_cpu_accel_class_init(ObjectClass *oc, const void *data) { AccelCPUClass *acc = ACCEL_CPU_CLASS(oc); @@ -498,6 +533,11 @@ static void whpx_accel_class_init(ObjectClass *oc, const void *data) NULL, NULL); object_class_property_set_description(oc, "kernel-irqchip", "Configure WHPX in-kernel irqchip"); + object_class_property_add(oc, "hyperv", "OnOffAuto", + NULL, whpx_set_hyperv, + NULL, NULL); + object_class_property_set_description(oc, "hyperv", + "Configure Hyper-V enlightenments"); } static void whpx_accel_instance_init(Object *obj) @@ -507,6 +547,9 @@ static void whpx_accel_instance_init(Object *obj) memset(whpx, 0, sizeof(struct whpx_state)); /* Turn on kernel-irqchip, by default */ whpx->kernel_irqchip_allowed = true; + + whpx->hyperv_enlightenments_allowed = true; + whpx->hyperv_enlightenments_required = false; } static const TypeInfo whpx_accel_type = { diff --git a/include/system/whpx-internal.h b/include/system/whpx-internal.h index e7b915ccbf..abea3ddeee 100644 --- a/include/system/whpx-internal.h +++ b/include/system/whpx-internal.h @@ -41,6 +41,10 @@ struct whpx_state { bool kernel_irqchip_allowed; bool kernel_irqchip_required; + + bool hyperv_enlightenments_allowed; + bool hyperv_enlightenments_required; + }; extern struct whpx_state whpx_global; diff --git a/target/i386/whpx/whpx-all.c b/target/i386/whpx/whpx-all.c index 915d79152e..4968a5a3e4 100644 --- a/target/i386/whpx/whpx-all.c +++ b/target/i386/whpx/whpx-all.c @@ -2219,15 +2219,17 @@ int whpx_accel_init(AccelState *as, MachineState *ms) synthetic_features.Bank0.DirectSyntheticTimers = 1; } - hr = whp_dispatch.WHvSetPartitionProperty( - whpx->partition, - WHvPartitionPropertyCodeSyntheticProcessorFeaturesBanks, - &synthetic_features, - sizeof(WHV_SYNTHETIC_PROCESSOR_FEATURES_BANKS)); - if (FAILED(hr)) { - error_report("WHPX: Failed to set synthetic features, hr=%08lx", hr); - ret = -EINVAL; - goto error; + if (whpx->hyperv_enlightenments_allowed) { + hr = whp_dispatch.WHvSetPartitionProperty( + whpx->partition, + WHvPartitionPropertyCodeSyntheticProcessorFeaturesBanks, + &synthetic_features, + sizeof(WHV_SYNTHETIC_PROCESSOR_FEATURES_BANKS)); + if (FAILED(hr)) { + error_report("WHPX: Failed to set synthetic features, hr=%08lx", hr); + ret = -EINVAL; + goto error; + } } /* Register for MSR and CPUID exits */ -- 2.50.1 (Apple Git-155)
