whpx: make Hyper-V enlightenments configurable
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 <mohamed@unpredictable.fr> Link: https://lore.kernel.org/r/20260307181856.2209-8-mohamed@unpredictable.fr Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Mohamed Mediouni committed
Mar 7, 2026 at 19:18 UTC
ae9dcd6f26542080096d0e7081ae76c61e3ff9c6
3 files changed
+58
-9
accel/whpx/whpx-common.c
+43
@@ -470,6 +470,41 @@ static void whpx_set_kernel_irqchip(Object *obj, Visitor *v,
470
}
471
}
472
473
+static void whpx_set_hyperv(Object *obj, Visitor *v,
474
+ const char *name, void *opaque,
475
+ Error **errp)
476
+{
477
+ struct whpx_state *whpx = &whpx_global;
478
+ OnOffAuto mode;
479
+
480
+ if (!visit_type_OnOffAuto(v, name, &mode, errp)) {
481
+ return;
482
+ }
483
+
484
+ switch (mode) {
485
+ case ON_OFF_AUTO_ON:
486
+ whpx->hyperv_enlightenments_allowed = true;
487
+ whpx->hyperv_enlightenments_required = true;
488
+ break;
489
+
490
+ case ON_OFF_AUTO_OFF:
491
+ whpx->hyperv_enlightenments_allowed = false;
492
+ whpx->hyperv_enlightenments_required = false;
493
+ break;
494
+
495
+ case ON_OFF_AUTO_AUTO:
496
+ whpx->hyperv_enlightenments_allowed = true;
497
+ whpx->hyperv_enlightenments_required = false;
498
+ break;
499
+ default:
500
+ /*
501
+ * The value was checked in visit_type_OnOffAuto() above. If
502
+ * we get here, then something is wrong in QEMU.
503
+ */
504
+ abort();
505
+ }
506
+}
507
+
508
static void whpx_cpu_accel_class_init(ObjectClass *oc, const void *data)
509
{
510
AccelCPUClass *acc = ACCEL_CPU_CLASS(oc);
@@ -498,6 +533,11 @@ static void whpx_accel_class_init(ObjectClass *oc, const void *data)
533
NULL, NULL);
534
object_class_property_set_description(oc, "kernel-irqchip",
535
"Configure WHPX in-kernel irqchip");
536
+ object_class_property_add(oc, "hyperv", "OnOffAuto",
537
+ NULL, whpx_set_hyperv,
538
+ NULL, NULL);
539
+ object_class_property_set_description(oc, "hyperv",
540
+ "Configure Hyper-V enlightenments");
541
}
542
543
static void whpx_accel_instance_init(Object *obj)
@@ -507,6 +547,9 @@ static void whpx_accel_instance_init(Object *obj)
547
memset(whpx, 0, sizeof(struct whpx_state));
548
/* Turn on kernel-irqchip, by default */
549
whpx->kernel_irqchip_allowed = true;
550
+
551
+ whpx->hyperv_enlightenments_allowed = true;
552
+ whpx->hyperv_enlightenments_required = false;
553
}
554
555
static const TypeInfo whpx_accel_type = {
include/system/whpx-internal.h
+4
@@ -42,6 +42,10 @@ struct whpx_state {
42
43
bool kernel_irqchip_allowed;
44
bool kernel_irqchip_required;
45
+
46
+ bool hyperv_enlightenments_allowed;
47
+ bool hyperv_enlightenments_required;
48
+
49
};
50
51
extern struct whpx_state whpx_global;
target/i386/whpx/whpx-all.c
+11
-9
@@ -2232,15 +2232,17 @@ int whpx_accel_init(AccelState *as, MachineState *ms)
2232
synthetic_features.Bank0.DirectSyntheticTimers = 1;
2233
}
2234
2235
- hr = whp_dispatch.WHvSetPartitionProperty(
2236
- whpx->partition,
2237
- WHvPartitionPropertyCodeSyntheticProcessorFeaturesBanks,
2238
- &synthetic_features,
2239
- sizeof(WHV_SYNTHETIC_PROCESSOR_FEATURES_BANKS));
2240
- if (FAILED(hr)) {
2241
- error_report("WHPX: Failed to set synthetic features, hr=%08lx", hr);
2242
- ret = -EINVAL;
2243
- goto error;
2235
+ if (whpx->hyperv_enlightenments_allowed) {
2236
+ hr = whp_dispatch.WHvSetPartitionProperty(
2237
+ whpx->partition,
2238
+ WHvPartitionPropertyCodeSyntheticProcessorFeaturesBanks,
2239
+ &synthetic_features,
2240
+ sizeof(WHV_SYNTHETIC_PROCESSOR_FEATURES_BANKS));
2241
+ if (FAILED(hr)) {
2242
+ error_report("WHPX: Failed to set synthetic features, hr=%08lx", hr);
2243
+ ret = -EINVAL;
2244
+ goto error;
2245
+ }
2246
}
2247
2248
/* Register for MSR and CPUID exits */