whpx: x2apic emulation for kernel-irqchip=off follow-up
cover whpx: x2apic emulation for kernel-irqchip=off follow-up
Small follow up for "whpx: i386: x2apic emulation for kernel-irqchip=off, feature probing" , depends on that series.
https://patchew.org/QEMU/[email protected]/
Based-on: <[email protected]>
Mohamed Mediouni (2):
whpx: i386: enable x2apic by default for user-mode LAPIC
whpx: i386: reintroduce enlightenments for Windows 10
target/i386/whpx/whpx-all.c | 71 ++++++++++++++++++++++++++++++++----- 1 file changed, 63 insertions(+), 8 deletions(-)
Signature · 1 line
2.50.1 (Apple Git-155)
PATCH 1/2 whpx: i386: enable x2apic by default for user-mode LAPIC
--- target/i386/whpx/whpx-all.c | 7 +++++++ 1 file changed, 7 insertions(+)
target/i386/whpx/whpx-all.c +7 -0
@@ -2269,11 +2269,18 @@ error:return ret; } +static PropValue whpx_default_props[] = { + {"x2apic" ,"on" }, + {NULL ,NULL }, +}; + +void whpx_cpu_instance_init (CPUState *cs) {X86CPU *cpu =X86_CPU (cs);host_cpu_instance_init (cpu); +x86_cpu_apply_props (cpu, whpx_default_props); }/*
Signature · 1 line
2.50.1 (Apple Git-155)
PATCH 2/2 whpx: i386: reintroduce enlightenments for Windows 10
In reply to Mohamed MediouniWas removed in 2c08624 but it's still useful for Windows 10 so reintroduce it there.
And this time, actually make it work by reporting the hypervisor bit in CPUID.
Also pretend to be KVM, with the only capability reported being X2APIC support.
Although looks like Linux doesn't use that vmware leaf...
--- target/i386/whpx/whpx-all.c | 64 ++++++++++++++++++++++++++++++++----- 1 file changed, 56 insertions(+), 8 deletions(-)
target/i386/whpx/whpx-all.c +56 -8
@@ -2071,15 +2071,45 @@ int whpx_vcpu_run(CPUState *cpu) vcpu->exit_ctx.VpContext.Rip + vcpu->exit_ctx.VpContext.InstructionLength; - reg_values[1 ].Reg64 = vcpu->exit_ctx.CpuidAccess.DefaultResultRax; - reg_values[2 ].Reg64 = vcpu->exit_ctx.CpuidAccess.DefaultResultRcx; - reg_values[3 ].Reg64 = vcpu->exit_ctx.CpuidAccess.DefaultResultRdx; - reg_values[4 ].Reg64 = vcpu->exit_ctx.CpuidAccess.DefaultResultRbx; - -if (vcpu->exit_ctx.CpuidAccess.Rax ==1 ) { -if (cpu_has_x2apic_feature (env)) { - reg_values[2 ].Reg64 |=CPUID_EXT_X2APIC ; +if (whpx_is_legacy_os ()) { + reg_values[1 ].Reg64 = vcpu->exit_ctx.CpuidAccess.DefaultResultRax; + reg_values[2 ].Reg64 = vcpu->exit_ctx.CpuidAccess.DefaultResultRcx; + reg_values[3 ].Reg64 = vcpu->exit_ctx.CpuidAccess.DefaultResultRdx; + reg_values[4 ].Reg64 = vcpu->exit_ctx.CpuidAccess.DefaultResultRbx; +switch (vcpu->exit_ctx.CpuidAccess.Rax) { +case 1 : +if (cpu_has_x2apic_feature (env)) { + reg_values[2 ].Reg64 |=CPUID_EXT_X2APIC ; + } + reg_values[2 ].Reg64 |=CPUID_EXT_HYPERVISOR ; +break ; +case 0x40000000 : +/* report KVM */ +if (x86_cpu->vmware_cpuid_freq) { + reg_values[1 ].Reg64 =0x40000010 ; + }else { + reg_values[1 ].Reg64 =0x40000001 ; + } + reg_values[4 ].Reg64 =0x4b4d564b ; + reg_values[2 ].Reg64 =0x564b4d56 ; + reg_values[3 ].Reg64 =0x4d ; +break ; +case 0x40000001 : +/* report X2APIC */ + reg_values[1 ].Reg64 = reg_values[4 ].Reg64 = reg_values[2 ].Reg64 =1 <<15 ; +break ; +case 0x40000010 : +if (x86_cpu->vmware_cpuid_freq) { + reg_values[1 ].Reg64 = env->tsc_khz; + reg_values[4 ].Reg64 = env->apic_bus_freq /1000 ;/* Hz to KHz */ + } +break ; } + }else { +cpu_x86_cpuid (env, vcpu->exit_ctx.CpuidAccess.Rax,0 , + (UINT32 *)®_values[1 ].Reg32, + (UINT32 *)®_values[4 ].Reg32, (UINT32 *)®_values[2 ].Reg32, + (UINT32 *)®_values[3 ].Reg32); } hr = whp_dispatch.WHvSetVirtualProcessorRegisters(
@@ -2253,6 +2283,24 @@ int whpx_init_vcpu(CPUState *cpu) env->apic_bus_freq =1000000000 ; } +/* Windows 10 doesn't provide Hyper-V enlightenments. */ +if (whpx_is_legacy_os ()) { +UINT32 cpuidExitList[] = {1 ,0x40000000 ,0x40000001 ,0x40000010 }; + + hr = whp_dispatch.WHvSetPartitionProperty ( + whpx->partition, + WHvPartitionPropertyCodeCpuidExitList, + cpuidExitList, +RTL_NUMBER_OF (cpuidExitList) *sizeof (UINT32 )); + +if (FAILED (hr)) { +error_report ("WHPX: Failed to set partition CpuidExitList hr=%08lx" , + hr); + ret = -EINVAL ; + goto error; + } + } + vcpu->interruptable = true; cpu->vcpu_dirty = true; cpu->accel = vcpu;
Signature · 1 line
2.50.1 (Apple Git-155)