whpx: i386: even more changes
cover whpx: i386: even more changes
This one is pretty small:
- the first patch is a fixup for "whpx: x86: kick out of HLT manually when using the kernel-irqchip"
It can be squashed with it and fixes the "sti; hlt" KVM unit test case.
- enable all supported host features
This enables the nested virt capability too when marked as supported (although without nested virt enlightenments).
- enable synthetic processor features
QEMU assumes that those are a property of the CPU, but Hyper-V needs that info at partition init time, so just enable them unconditionally for now.
- warn on unsupported MSR accesses
This applies on top of the "whpx: x86 updates (2026-02)" and "whpx: i386: interrupt-related updates" series.
Mohamed Mediouni (4):
whpx: i386: move whpx_vcpu_kick_out_of_hlt() invocation to interrupt
raise time
whpx: i386: enable all supported host features
whpx: i386: enable synthetic processor features
whpx: i386: warn on unsupported MSR access instead of failing silently
target/i386/whpx/whpx-all.c | 126 ++++++++++++++++++++++++++++-------- 1 file changed, 98 insertions(+), 28 deletions(-)
Signature · 1 line
2.50.1 (Apple Git-155)
PATCH 1/4 whpx: i386: move whpx_vcpu_kick_out_of_hlt() invocation to interrupt raise time
This fixes the sti followed by hlt kvm_unit_tests.
--- target/i386/whpx/whpx-all.c | 49 ++++++++++++++++--------------------- 1 file changed, 21 insertions(+), 28 deletions(-)
target/i386/whpx/whpx-all.c +21 -28
@@ -1308,6 +1308,16 @@ static int whpx_handle_halt(CPUState *cpu)return ret; } +static void whpx_vcpu_kick_out_of_hlt (CPUState *cpu) +{ +WHV_REGISTER_VALUE reg; +whpx_get_reg (cpu, WHvRegisterInternalActivityState, ®); +if (reg.InternalActivity.HaltSuspend) { + reg.InternalActivity.HaltSuspend =0 ; +whpx_set_reg (cpu, WHvRegisterInternalActivityState, reg); + } +} +static void whpx_vcpu_pre_run (CPUState *cpu) {HRESULT hr;
@@ -1391,6 +1401,17 @@ static void whpx_vcpu_pre_run(CPUState *cpu) .Vector = irq, }; reg_count +=1 ; +/* +* When the Hyper-V APIC is enabled, to get out of HLT we +* either have to request an interrupt or manually get it away +* from HLT. +* +* We also manually do inject some interrupts via WHvRegisterPendingEvent +* instead of WHVRequestInterrupt, which does not reset the HLT state. +*/ +if (whpx_irqchip_in_kernel ()) { +whpx_vcpu_kick_out_of_hlt (cpu); + } } }
@@ -1453,15 +1474,6 @@ static void whpx_vcpu_post_run(CPUState *cpu) !vcpu->exit_ctx.VpContext.ExecutionState.InterruptShadow; } -static void whpx_vcpu_kick_out_of_hlt (CPUState *cpu) -{ -WHV_REGISTER_VALUE reg; -whpx_get_reg (cpu, WHvRegisterInternalActivityState, ®); -if (reg.InternalActivity.HaltSuspend) { - reg.InternalActivity.HaltSuspend =0 ; -whpx_set_reg (cpu, WHvRegisterInternalActivityState, reg); - } -}static void whpx_vcpu_process_async_events (CPUState *cpu) {
@@ -1770,25 +1782,6 @@ int whpx_vcpu_run(CPUState *cpu) cpu->exception_index =EXCP_INTERRUPT ; ret =1 ; } -/* -* When the Hyper-V APIC is enabled, to get out of HLT we -* either have to request an interrupt or manually get it away -* from HLT. -* -* We also manually do inject some interrupts via WHvRegisterPendingEvent -* instead of WHVRequestInterrupt, which does not reset the HLT state. -* -* However, even with this done, if the guest does an HLT without -* interrupts enabled (which the test_sti_inhibit KVM unit test does) -* then the guest will stay in HLT forever. -* -* Keep it this way for now, with perhaps adding a heartbeat later -* so that we get the CPU time savings from having Hyper-V handle HLT -* instead of going away from it as soon as possible. -*/ -if (whpx_irqchip_in_kernel ()) { -whpx_vcpu_kick_out_of_hlt (cpu); - }break ;case WHvRunVpExitReasonX64MsrAccess: {WHV_REGISTER_VALUE reg_values[3 ] = {0 };
Signature · 1 line
2.50.1 (Apple Git-155)
PATCH 2/4 whpx: i386: enable all supported host features
In reply to Mohamed Mediouni--- target/i386/whpx/whpx-all.c | 40 +++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+)
target/i386/whpx/whpx-all.c +40 -0
@@ -2007,6 +2007,7 @@ int whpx_accel_init(AccelState *as, MachineState *ms)UINT32 whpx_cap_size;WHV_PARTITION_PROPERTY prop;WHV_CAPABILITY_FEATURES features = {0 }; +WHV_PROCESSOR_FEATURES_BANKS processor_features; whpx = &whpx_global;
@@ -2112,6 +2113,45 @@ int whpx_accel_init(AccelState *as, MachineState *ms) } } +/* Set all the supported features, to follow the MSHV example */ +memset (&processor_features,0 ,sizeof (WHV_PROCESSOR_FEATURES_BANKS )); + processor_features.BanksCount =2 ; + + hr = whp_dispatch.WHvGetCapability ( + WHvCapabilityCodeProcessorFeaturesBanks, &processor_features, +sizeof (WHV_PROCESSOR_FEATURES_BANKS ), &whpx_cap_size); +if (FAILED (hr)) { +error_report ("WHPX: Failed to get processor features, hr=%08lx" , hr); + ret = -ENOSPC ; + goto error; + } + +if (processor_features.Bank1.NestedVirtSupport) { +memset (&prop,0 ,sizeof (WHV_PARTITION_PROPERTY )); + prop.NestedVirtualization =1 ; + hr = whp_dispatch.WHvSetPartitionProperty ( + whpx->partition, + WHvPartitionPropertyCodeNestedVirtualization, + &prop, +sizeof (WHV_PARTITION_PROPERTY )); +if (FAILED (hr)) { +error_report ("WHPX: Failed to enable nested virtualization, hr=%08lx" , hr); + ret = -EINVAL ; + goto error; + } + } + + hr = whp_dispatch.WHvSetPartitionProperty ( + whpx->partition, + WHvPartitionPropertyCodeProcessorFeaturesBanks, + &processor_features, +sizeof (WHV_PROCESSOR_FEATURES_BANKS )); +if (FAILED (hr)) { +error_report ("WHPX: Failed to set processor features, hr=%08lx" , hr); + ret = -EINVAL ; + goto error; + } +/* Register for MSR and CPUID exits */ memset (&prop,0 ,sizeof (WHV_PARTITION_PROPERTY )); prop.ExtendedVmExits.X64MsrExit =1 ;
Signature · 1 line
2.50.1 (Apple Git-155)
PATCH 3/4 whpx: i386: enable synthetic processor features
In reply to Mohamed MediouniAt the point in time in which we setup the partition, the vCPUs aren't available yet.
So enable them by default for now like what the MSHV backend does.
AccessFrequencyRegs is shared for both the LAPIC frequency reporting and the TSC frequency.
To still benefit from the fixed TSC frequency reporting when kernel-irqchip=off, still enable AccessFrequencyRegs anyway.
--- target/i386/whpx/whpx-all.c | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+)
target/i386/whpx/whpx-all.c +34 -0
@@ -2152,6 +2152,40 @@ 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.AccessPartitionReferenceCounter =1 ; + synthetic_features.Bank0.AccessPartitionReferenceTsc =1 ; +/* if kernel-irqchip=off, HV_X64_MSR_APIC_FREQUENCY = 0. */ + synthetic_features.Bank0.AccessFrequencyRegs =1 ; + synthetic_features.Bank0.AccessVpIndex =1 ; + synthetic_features.Bank0.AccessHypercallRegs =1 ; + synthetic_features.Bank0.TbFlushHypercalls =1 ; + +if (whpx_irqchip_in_kernel ()) { + 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 ; + } + + 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 */ memset (&prop,0 ,sizeof (WHV_PARTITION_PROPERTY )); prop.ExtendedVmExits.X64MsrExit =1 ;
Signature · 1 line
2.50.1 (Apple Git-155)
PATCH 4/4 whpx: i386: warn on unsupported MSR access instead of failing silently
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
@@ -1804,6 +1804,9 @@ int whpx_vcpu_run(CPUState *cpu) reg_count = vcpu->exit_ctx.MsrAccess.AccessInfo.IsWrite ?1 :3 ; +warn_report ("WHPX: Unsupported MSR access (0x%x), IsWrite=%i" , + vcpu->exit_ctx.MsrAccess.MsrNumber, vcpu->exit_ctx.MsrAccess.AccessInfo.IsWrite); + hr = whp_dispatch.WHvSetVirtualProcessorRegisters( whpx->partition, cpu->cpu_index,
Signature · 1 line
2.50.1 (Apple Git-155)