whpx: i386: small random fixes
v2 cover whpx: i386: small random fixes
Also has a small arm64 patch for enabling Hyper-V enlightenments if asked for, which depends on another (common code) patch in the series
Mohamed Mediouni (6):
whpx: i386: do not enable nested virt when kernel-irqchip=off target/i386: emulate: LA57 fix
whpx: i386: enable some more enlightenments
whpx: make Hyper-V enlightenments configurable
whpx: arm64: enable enlightenments if asked for
whpx: i386: remove SIPI trapping
accel/whpx/whpx-common.c | 43 ++++++++++++ include/system/whpx-internal.h | 4 ++ target/arm/whpx/whpx-all.c | 37 ++++++++++ target/i386/emulate/x86_mmu.c | 2 +- target/i386/whpx/whpx-all.c | 122 ++++----------------------------- 5 files changed, 100 insertions(+), 108 deletions(-)
Signature · 1 line
2.50.1 (Apple Git-155)
PATCH v2 1/6 whpx: i386: do not enable nested virt when kernel-irqchip=off
This combination is not allowed as of build 26300.7939 and results in:
qemu-system-x86_64.exe: WHPX: Failed to setup partition, hr=c0350005 qemu-system-x86_64.exe: failed to initialize whpx: Invalid argument
--- target/i386/whpx/whpx-all.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
target/i386/whpx/whpx-all.c +1 -1
@@ -2147,7 +2147,7 @@ int whpx_accel_init(AccelState *as, MachineState *ms) goto error; } -if (processor_features.Bank1.NestedVirtSupport) { +if (whpx_irqchip_in_kernel () && processor_features.Bank1.NestedVirtSupport) {memset (&prop,0 ,sizeof (WHV_PARTITION_PROPERTY )); prop.NestedVirtualization =1 ; hr = whp_dispatch.WHvSetPartitionProperty(
Signature · 1 line
2.50.1 (Apple Git-155)
PATCH v2 2/6 target/i386: emulate: LA57 fix
In reply to Mohamed MediouniSeen on a Sapphire Rapids box with LA57.
--- target/i386/emulate/x86_mmu.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
target/i386/emulate/x86_mmu.c +1 -1
@@ -56,7 +56,7 @@ static bool is_user(CPUState *cpu)struct gpt_translation {target_ulong gva;uint64_t gpa; -uint64_t pte[5 ]; +uint64_t pte[6 ]; };static int gpt_top_level (CPUState *cpu,bool pae)
Signature · 1 line
2.50.1 (Apple Git-155)
PATCH v2 3/6 whpx: i386: enable some more enlightenments
In reply to Mohamed Mediouni--- target/i386/whpx/whpx-all.c | 3 +++ 1 file changed, 3 insertions(+)
target/i386/whpx/whpx-all.c +3 -0
@@ -2201,9 +2201,12 @@ int whpx_accel_init(AccelState *as, MachineState *ms) synthetic_features.Bank0.HypervisorPresent =1 ; synthetic_features.Bank0.Hv1 =1 ; + synthetic_features.Bank0.AccessVpRunTimeReg =1 ; synthetic_features.Bank0.AccessPartitionReferenceCounter =1 ; synthetic_features.Bank0.AccessPartitionReferenceTsc =1 ; + synthetic_features.Bank0.AccessHypercallRegs =1 ; synthetic_features.Bank0.AccessFrequencyRegs =1 ; + synthetic_features.Bank0.EnableExtendedGvaRangesForFlushVirtualAddressList =1 ; synthetic_features.Bank0.AccessVpIndex =1 ; synthetic_features.Bank0.AccessHypercallRegs =1 ; synthetic_features.Bank0.TbFlushHypercalls =1 ;
Signature · 1 line
2.50.1 (Apple Git-155)
PATCH v2 4/6 whpx: make Hyper-V enlightenments configurable
In reply to Mohamed MediouniHave 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.
--- 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(-)
accel/whpx/whpx-common.c +43 -0
@@ -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 = {
include/system/whpx-internal.h +4 -0
@@ -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;
target/i386/whpx/whpx-all.c +11 -9
@@ -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 */
Signature · 1 line
2.50.1 (Apple Git-155)
PATCH v2 5/6 whpx: arm64: enable enlightenments if asked for
In reply to Mohamed Mediouni--- target/arm/whpx/whpx-all.c | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+)
target/arm/whpx/whpx-all.c +37 -0
@@ -947,6 +947,43 @@ int whpx_accel_init(AccelState *as, MachineState *ms) goto error; } +/* Enable synthetic processor features */ +WHV_SYNTHETIC_PROCESSOR_FEATURES_BANKS synthetic_features; +memset (&synthetic_features,0 ,sizeof (WHV_SYNTHETIC_PROCESSOR_FEATURES_BANKS )); + synthetic_features.BanksCount =1 ; + + synthetic_features.Bank0.HypervisorPresent =1 ; + synthetic_features.Bank0.Hv1 =1 ; + synthetic_features.Bank0.AccessVpRunTimeReg =1 ; + synthetic_features.Bank0.AccessPartitionReferenceCounter =1 ; + synthetic_features.Bank0.AccessPartitionReferenceTsc =1 ; + synthetic_features.Bank0.AccessHypercallRegs =1 ; + synthetic_features.Bank0.AccessVpIndex =1 ; + synthetic_features.Bank0.AccessHypercallRegs =1 ; + synthetic_features.Bank0.TbFlushHypercalls =1 ; + synthetic_features.Bank0.AccessSynicRegs =1 ; + synthetic_features.Bank0.AccessSyntheticTimerRegs =1 ; + synthetic_features.Bank0.AccessIntrCtrlRegs =1 ; + synthetic_features.Bank0.SyntheticClusterIpi =1 ; + synthetic_features.Bank0.DirectSyntheticTimers =1 ; + +/* +* On ARM64, have enlightenments off by default +* as they're not needed for performance. +*/ +if (whpx->hyperv_enlightenments_required) { + 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; + } + } + hr = whp_dispatch.WHvSetupPartition (whpx->partition);if (FAILED (hr)) {error_report ("WHPX: Failed to setup partition, hr=%08lx" , hr);
Signature · 1 line
2.50.1 (Apple Git-155)
PATCH v2 6/6 whpx: i386: remove SIPI trapping
In reply to Mohamed MediouniThe implementation in Hyper-V works fine and the code currently present doesn't handle x2APIC correctly anyway, so remove it and use the implementation in Hyper-V.
--- target/i386/whpx/whpx-all.c | 97 ------------------------------------- 1 file changed, 97 deletions(-)
target/i386/whpx/whpx-all.c +0 -97
@@ -1679,100 +1679,6 @@ int whpx_vcpu_run(CPUState *cpu) ret =whpx_handle_halt (cpu);break ; -case WHvRunVpExitReasonX64ApicInitSipiTrap: { -WHV_INTERRUPT_CONTROL ipi = {0 }; -uint64_t icr = vcpu->exit_ctx.ApicInitSipi.ApicIcr; -uint32_t delivery_mode = - (icr &APIC_ICR_DELIV_MOD ) >>APIC_ICR_DELIV_MOD_SHIFT ; -int dest_shorthand = - (icr &APIC_ICR_DEST_SHORT ) >>APIC_ICR_DEST_SHORT_SHIFT ; -bool broadcast = false; -bool include_self = false; -uint32_t i; - -/* We only registered for INIT and SIPI exits. */ -if ((delivery_mode !=APIC_DM_INIT ) && - (delivery_mode !=APIC_DM_SIPI )) { -error_report ( -"WHPX: Unexpected APIC exit that is not a INIT or SIPI" ); -break ; - } - -if (delivery_mode ==APIC_DM_INIT ) { - ipi.Type = WHvX64InterruptTypeInit; - }else { - ipi.Type = WHvX64InterruptTypeSipi; - } - - ipi.DestinationMode = - ((icr &APIC_ICR_DEST_MOD ) >>APIC_ICR_DEST_MOD_SHIFT ) ? - WHvX64InterruptDestinationModeLogical : - WHvX64InterruptDestinationModePhysical; - - ipi.TriggerMode = - ((icr &APIC_ICR_TRIGGER_MOD ) >>APIC_ICR_TRIGGER_MOD_SHIFT ) ? - WHvX64InterruptTriggerModeLevel : - WHvX64InterruptTriggerModeEdge; - - ipi.Vector = icr &APIC_VECTOR_MASK ; -switch (dest_shorthand) { -/* no shorthand. Bits 56-63 contain the destination. */ -case 0 : - ipi.Destination = (icr >>56 ) &APIC_VECTOR_MASK ; - hr = whp_dispatch.WHvRequestInterrupt (whpx->partition, - &ipi,sizeof (ipi)); -if (FAILED (hr)) { -error_report ("WHPX: Failed to request interrupt hr=%08lx" , - hr); - } - -break ; - -/* self */ -case 1 : - include_self = true; -break ; - -/* broadcast, including self */ -case 2 : - broadcast = true; - include_self = true; -break ; - -/* broadcast, excluding self */ -case 3 : - broadcast = true; -break ; - } - -if (!broadcast && !include_self) { -break ; - } - -for (i =0 ; i <= max_vcpu_index; i++) { -if (i == cpu->cpu_index && !include_self) { -continue ; - } - -/* -* Assuming that APIC Ids are identity mapped since -* WHvX64RegisterApicId & WHvX64RegisterInitialApicId registers -* are not handled yet and the hypervisor doesn't allow the -* guest to modify the APIC ID. -*/ - ipi.Destination = i; - hr = whp_dispatch.WHvRequestInterrupt (whpx->partition, - &ipi,sizeof (ipi)); -if (FAILED (hr)) { -error_report ( -"WHPX: Failed to request SIPI for %d, hr=%08lx" , - i, hr); - } - } - -break ; - } -case WHvRunVpExitReasonCanceled:if (exclusive_step_mode !=WHPX_STEP_NONE ) {/*
@@ -2236,9 +2142,6 @@ int whpx_accel_init(AccelState *as, MachineState *ms)memset (&prop,0 ,sizeof (WHV_PARTITION_PROPERTY )); prop.ExtendedVmExits.X64MsrExit =1 ; prop.ExtendedVmExits.ExceptionExit =1 ; -if (whpx_irqchip_in_kernel ()) { - prop.ExtendedVmExits.X64ApicInitSipiExitTrap =1 ; - } hr = whp_dispatch.WHvSetPartitionProperty( whpx->partition,
Signature · 1 line
2.50.1 (Apple Git-155)