WHPX introduce changes for Windows Insider SDK 17110
cover WHPX introduce changes for Windows Insider SDK 17110
This change set fixes two breaking changes that were introduced in the Windows Insider SDK 17110. First, a change to the WHvGetCapability function decl to include the 'out' WrittenSizeInBytes. Second, changes to the WHvSetPartitionProperty function decl and WHV_PARTITION_PROPERTY structure to directly pass the PropertyCode at invocation.
Lastly, it introduces a major performance improvement in whpx_vcpu_post_run using the VpContext exit structure rather than another round trip call to WHvGetVirtualProcessorRegisters to synchronize vp state.
QEMU compiled against this SDK (17110+) is expected to work on all Windows Insider Builds (17115+).
Thanks,
Justin Terry
Justin Terry (VM) (3):
WHPX fix WHvGetCapability out WrittenSizeInBytes WHPX fix WHvSetPartitionProperty in PropertyCode WHPX improve vcpu_post_run perf
configure | 4 +++- target/i386/whpx-all.c | 46 ++++++++++++++-------------------------------- 2 files changed, 17 insertions(+), 33 deletions(-)
Signature · 1 line
2.13.6
PATCH 1/3 WHPX fix WHvGetCapability out WrittenSizeInBytes
This fixes a breaking change to WHvGetCapability to include the 'out' WrittenSizeInBytes introduced in Windows Insider SDK 17110.
This specifies on return the safe length to read into the WHV_CAPABILITY structure passed to the call.
--- configure | 4 +++- target/i386/whpx-all.c | 3 ++- 2 files changed, 5 insertions(+), 2 deletions(-)
configure +3 -1
@@ -2491,7 +2491,9 @@ if test "$whpx" != "no" ; then #include <WinHvEmulation.h> int main(void) { WHV_CAPABILITY whpx_cap; - WHvGetCapability(WHvCapabilityCodeFeatures, &whpx_cap, sizeof(whpx_cap)); + UINT32 writtenSize; + WHvGetCapability(WHvCapabilityCodeFeatures, &whpx_cap, sizeof(whpx_cap), + &writtenSize); return 0; } EOF
target/i386/whpx-all.c +2 -1
@@ -1254,6 +1254,7 @@ static int whpx_accel_init(MachineState *ms)int ret;HRESULT hr;WHV_CAPABILITY whpx_cap; +UINT32 whpx_cap_size;WHV_PARTITION_PROPERTY prop; whpx = &whpx_global;
@@ -1262,7 +1263,7 @@ static int whpx_accel_init(MachineState *ms) whpx->mem_quota = ms->ram_size; hr =WHvGetCapability (WHvCapabilityCodeHypervisorPresent, &whpx_cap, -sizeof (whpx_cap)); +sizeof (whpx_cap), &whpx_cap_size);if (FAILED (hr) || !whpx_cap.HypervisorPresent) {error_report ("WHPX: No accelerator found, hr=%08lx" , hr); ret = -ENOSPC ;
Signature · 1 line
2.13.6
PATCH 2/3 WHPX fix WHvSetPartitionProperty in PropertyCode
In reply to Justin Terry (VM)This fixes a breaking change to WHvSetPartitionProperty to pass the 'in' PropertyCode on function invocation introduced in Windows Insider SDK 17110. Usage of this indicates the PropertyCode of the opaque PropertyBuffer passed in on function invocation.
Also fixes the removal of the PropertyCode parameter from the WHV_PARTITION_PROPERTY struct as it is now passed to the function directly.
--- target/i386/whpx-all.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
target/i386/whpx-all.c +1 -1
@@ -1278,9 +1278,9 @@ static int whpx_accel_init(MachineState *ms) }memset (&prop,0 ,sizeof (WHV_PARTITION_PROPERTY )); - prop.PropertyCode = WHvPartitionPropertyCodeProcessorCount; prop.ProcessorCount = smp_cpus; hr =WHvSetPartitionProperty (whpx->partition, + WHvPartitionPropertyCodeProcessorCount, &prop,sizeof (WHV_PARTITION_PROPERTY ));
Signature · 1 line
2.13.6
PATCH 3/3 WHPX improve vcpu_post_run perf
In reply to Justin Terry (VM)This removes the additional call to WHvGetVirtualProcessorRegisters in whpx_vcpu_post_run now that the WHV_VP_EXIT_CONTEXT is returned in all WHV_RUN_VP_EXIT_CONTEXT structures.
--- target/i386/whpx-all.c | 41 +++++++++++------------------------------ 1 file changed, 11 insertions(+), 30 deletions(-)
target/i386/whpx-all.c +11 -30
@@ -153,7 +153,7 @@ struct whpx_vcpu {bool interruptable;uint64_t tpr;uint64_t apic_base; -WHV_X64_PENDING_INTERRUPTION_REGISTER interrupt_in_flight; +bool interruption_pending;/* Must be the last field as it may have a tail */ WHV_RUN_VP_EXIT_CONTEXT exit_ctx;
@@ -695,7 +695,7 @@ static void whpx_vcpu_pre_run(CPUState *cpu)qemu_mutex_lock_iothread ();/* Inject NMI */ -if (!vcpu->interrupt_in_flight.InterruptionPending && +if (!vcpu->interruption_pending && cpu->interrupt_request & (CPU_INTERRUPT_NMI |CPU_INTERRUPT_SMI )) {if (cpu->interrupt_request &CPU_INTERRUPT_NMI ) { cpu->interrupt_request &= ~CPU_INTERRUPT_NMI ;
@@ -724,7 +724,7 @@ static void whpx_vcpu_pre_run(CPUState *cpu) }/* Get pending hard interruption or replay one that was overwritten */ -if (!vcpu->interrupt_in_flight.InterruptionPending && +if (!vcpu->interruption_pending && vcpu->interruptable && (env->eflags &IF_MASK )) {assert (!new_int.InterruptionPending);if (cpu->interrupt_request &CPU_INTERRUPT_HARD ) {
@@ -781,44 +781,25 @@ static void whpx_vcpu_pre_run(CPUState *cpu)static void whpx_vcpu_post_run (CPUState *cpu) { -HRESULT hr; -struct whpx_state *whpx = &whpx_global;struct whpx_vcpu *vcpu =get_whpx_vcpu (cpu);struct CPUX86State *env = (CPUArchState *)(cpu->env_ptr);X86CPU *x86_cpu =X86_CPU (cpu); -WHV_REGISTER_VALUE reg_values[4 ]; -const WHV_REGISTER_NAME reg_names[4 ] = { - WHvX64RegisterRflags, - WHvX64RegisterCr8, - WHvRegisterPendingInterruption, - WHvRegisterInterruptState, - }; - hr =WHvGetVirtualProcessorRegisters (whpx->partition, cpu->cpu_index, - reg_names,4 , reg_values); -if (FAILED (hr)) { -error_report ("WHPX: Failed to get interrupt state regusters," -" hr=%08lx" , hr); - vcpu->interruptable = false; -return ; - } + env->eflags = vcpu->exit_ctx.VpContext.Rflags; -assert (reg_names[0 ] == WHvX64RegisterRflags); - env->eflags = reg_values[0 ].Reg64; - -assert (reg_names[1 ] == WHvX64RegisterCr8); -if (vcpu->tpr != reg_values[1 ].Reg64) { - vcpu->tpr = reg_values[1 ].Reg64; +uint64_t tpr = vcpu->exit_ctx.VpContext.Cr8; +if (vcpu->tpr != tpr) { + vcpu->tpr = tpr;qemu_mutex_lock_iothread ();cpu_set_apic_tpr (x86_cpu->apic_state, vcpu->tpr);qemu_mutex_unlock_iothread (); } -assert (reg_names[2 ] == WHvRegisterPendingInterruption); - vcpu->interrupt_in_flight = reg_values[2 ].PendingInterruption; + vcpu->interruption_pending = + vcpu->exit_ctx.VpContext.ExecutionState.InterruptionPending; -assert (reg_names[3 ] == WHvRegisterInterruptState); - vcpu->interruptable = !reg_values[3 ].InterruptState.InterruptShadow; + vcpu->interruptable = + !vcpu->exit_ctx.VpContext.ExecutionState.InterruptShadow;return ; }
Signature · 1 line
2.13.6
Paolo Bonzini
AppliedQuoted 16 lines · Justin Terry (VM)
This change set fixes two breaking changes that were introduced in the Windows Insider SDK 17110. First, a change to the WHvGetCapability function decl to include the 'out' WrittenSizeInBytes. Second, changes to the WHvSetPartitionProperty function decl and
WHV_PARTITION_PROPERTYstructure to directly pass the PropertyCode at invocation.Lastly, it introduces a major performance improvement in
whpx_vcpu_post_runusing the VpContext exit structure rather than another round trip call to WHvGetVirtualProcessorRegisters to synchronize vp state.QEMU compiled against this SDK (17110+) is expected to work on all Windows Insider Builds (17115+).
Thanks,
Justin Terry
Quoted 9 lines
Justin Terry (VM) (3):
WHPX fix WHvGetCapability out WrittenSizeInBytes WHPX fix WHvSetPartitionProperty in PropertyCode WHPX improvevcpu_post_runperfconfigure | 4 +++- target/i386/whpx-all.c | 46 ++++++++++++++-------------------------------- 2 files changed, 17 insertions(+), 33 deletions(-)
Queued, thanks.
Paolo
Am 14.03.2018 um 15:52 schrieb Justin Terry (VM) via Qemu-devel:
Quoted 10 lines
This change set fixes two breaking changes that were introduced in the Windows Insider SDK 17110. First, a change to the WHvGetCapability function decl to include the 'out' WrittenSizeInBytes. Second, changes to the WHvSetPartitionProperty function decl and
WHV_PARTITION_PROPERTYstructure to directly pass the PropertyCode at invocation.Lastly, it introduces a major performance improvement in
whpx_vcpu_post_runusing the VpContext exit structure rather than another round trip call to WHvGetVirtualProcessorRegisters to synchronize vp state.
Quoted 5 lines
QEMU compiled against this SDK (17110+) is expected to work on all Windows Insider Builds (17115+).
Thanks,
Justin Terry
Hi Justin,
as far as I know it still not possible to cross build a legal QEMU for Windows on a Linux machine due to the license limitations of the SDK which is needed. The header files needed for the QEMU build are "All rights reserved".
People often ask me to add WHPX support to the QEMU installer for Windows, but I have to tell them that I cannot do that currently.
This problem could be solved if the necessary header files were added to QEMU with a permissive license by someone who has the rights to do so.
Could you add WinHvEmulation.h and WinHvPlatform.h or am I allowed to make such files from the documentation at https://docs.microsoft.com/?
Thanks,
Stefan Weil
Hey Stefan,
Not trying to ignore you here. I have reached out to members of management on our side I just don’t have any responses yet on what we can do here. Will update as I learn more.
Thanks,
Justin Terry
Quoted 50 lines
-----Original Message-----
From: Stefan Weil <[email protected]>
Sent: Thursday, January 17, 2019 12:38 PM
To: Justin Terry (VM) <[email protected]>; [email protected]
Cc: [email protected]; [email protected]; [email protected]
Subject: Re: [Qemu-devel] [PATCH 0/3] WHPX introduce changes for Windows Insider SDK 17110Am 14.03.2018 um 15:52 schrieb Justin Terry (VM) via Qemu-devel:
Quoted 5 lines
This change set fixes two breaking changes that were introduced in the Windows Insider SDK 17110. First, a change to the WHvGetCapability function decl to include the 'out' WrittenSizeInBytes. Second, changes to the WHvSetPartitionProperty function decl and
WHV_PARTITION_PROPERTYstructure to directly pass the PropertyCode atinvocation.
Quoted 4 lines
Lastly, it introduces a major performance improvement in
whpx_vcpu_post_runusing the VpContext exit structure rather than another round trip call to WHvGetVirtualProcessorRegisters to synchronizevp state.
Quoted 6 lines
QEMU compiled against this SDK (17110+) is expected to work on all Windows Insider Builds (17115+).
Thanks,
Justin TerryHi Justin,
as far as I know it still not possible to cross build a legal QEMU for Windows on a Linux machine due to the license limitations of the SDK which is needed. The header files needed for the QEMU build are "All rights reserved".
People often ask me to add WHPX support to the QEMU installer for Windows, but I have to tell them that I cannot do that currently.
This problem could be solved if the necessary header files were added to QEMU with a permissive license by someone who has the rights to do so.
Could you add
WinHvEmulation.handWinHvPlatform.hor am I allowed to make such files from the documentation at
https://nam06.safelinks.protection.outlook.com/?url=https%3A%2F%2Fdocs
.microsoft.com%2F&data=02%7C01%7Cjuterry%40microsoft.com%7Cae d2532cd05b4f2a5a0208d67cbba58f%7C72f988bf86f141af91ab2d7cd011db47% 7C1%7C0%7C636833542719466921&sdata=%2FA7Kjkx5fnjMVnqezdmqi wgCZAFwoaNe2oCA%2BSdPbuo%3D&reserved=0?Thanks,
Stefan Weil
Is this useful at all for the Android Emulator? Does it break backward compatibility for older Windows versions?
Quoted 42 lines · Stefan Weil
Am 14.03.2018 um 15:52 schrieb Justin Terry (VM) via Qemu-devel:
Quoted 2 lines
This change set fixes two breaking changes that were introduced in the Windows Insider SDK 17110. First, a change to the WHvGetCapability
function
Quoted 2 lines
decl to include the 'out' WrittenSizeInBytes. Second, changes to the WHvSetPartitionProperty function decl and
WHV_PARTITION_PROPERTYstructure
Quoted 3 lines
to directly pass the PropertyCode at invocation.
Lastly, it introduces a major performance improvement in
whpx_vcpu_post_runQuoted 4 lines
using the VpContext exit structure rather than another round trip call to WHvGetVirtualProcessorRegisters to synchronize vp state.
QEMU compiled against this SDK (17110+) is expected to work on all
Windows
Quoted 4 lines
Insider Builds (17115+).
Thanks,
Justin TerryHi Justin,
as far as I know it still not possible to cross build a legal QEMU for Windows on a Linux machine due to the license limitations of the SDK which is needed. The header files needed for the QEMU build are "All rights reserved".
People often ask me to add WHPX support to the QEMU installer for Windows, but I have to tell them that I cannot do that currently.
This problem could be solved if the necessary header files were added to QEMU with a permissive license by someone who has the rights to do so.
Could you add
WinHvEmulation.handWinHvPlatform.hor am I allowed to make such files from the documentation at https://docs.microsoft.com/?Thanks,
Stefan Weil