hvf: Fetch cr4 before evaluating CPUID(1)
PATCH 1/1 hvf: Fetch cr4 before evaluating CPUID(1)
The CPUID function 1 has a bit called OSXSAVE which tells user space the status of the CR4.OSXSAVE bit. Our generic CPUID function injects that bit based on the status of CR4.
With Hypervisor.framework, we do not synchronize full CPU state often enough for this function to see the CR4 update before guest user space asks for it.
To be on the save side, let's just always synchronize it when we receive a CPUID(1) request. That way we can set the bit with real confidence.
--- target/i386/hvf/hvf.c | 4 ++++ 1 file changed, 4 insertions(+)
target/i386/hvf/hvf.c +4 -0
@@ -426,6 +426,10 @@ int hvf_vcpu_exec(CPUState *cpu)uint32_t rcx = (uint32_t )rreg (cpu->hvf->fd,HV_X86_RCX );uint32_t rdx = (uint32_t )rreg (cpu->hvf->fd,HV_X86_RDX ); +if (rax ==1 ) { +/* CPUID1.ecx.OSXSAVE needs to know CR4 */ + env->cr[4 ] =rvmcs (cpu->hvf->fd,VMCS_GUEST_CR4 ); + }cpu_x86_cpuid (env, rax, rcx, &rax, &rbx, &rcx, &rdx);wreg (cpu->hvf->fd,HV_X86_RAX , rax);
Signature · 1 line
2.24.3 (Apple Git-128)
Quoted 34 lines · Alexander Graf
The CPUID function 1 has a bit called OSXSAVE which tells user space the status of the CR4.OSXSAVE bit. Our generic CPUID function injects that bit based on the status of CR4.
With Hypervisor.framework, we do not synchronize full CPU state often enough for this function to see the CR4 update before guest user space asks for it.
To be on the save side, let's just always synchronize it when we receive a CPUID(1) request. That way we can set the bit with real confidence.
Reported-by Asad Ali <[email protected]>Signed-off-by Alexander Graf <[email protected]>--- target/i386/hvf/hvf.c | 4 ++++ 1 file changed, 4 insertions(+)target/i386/hvf/hvf.c +4
-0@@ -426,6 +426,10 @@ int hvf_vcpu_exec(CPUState *cpu)uint32_t rcx = (uint32_t )rreg (cpu->hvf->fd,HV_X86_RCX );uint32_t rdx = (uint32_t )rreg (cpu->hvf->fd,HV_X86_RDX ); +if (rax ==1 ) { +/* CPUID1.ecx.OSXSAVE needs to know CR4 */ + env->cr[4 ] =rvmcs (cpu->hvf->fd,VMCS_GUEST_CR4 ); + }cpu_x86_cpuid (env, rax, rcx, &rax, &rbx, &rcx, &rdx);wreg (cpu->hvf->fd,HV_X86_RAX , rax);Signature · 1 line
2.24.3 (Apple Git-128)
The fix is based off hvf-arm patch series and doesn't build on master branch because of "cpu->hvf->fd" has to be "cpu->hvf_fd". I've corrected the issue and resolved conflicts with another patch in hvf-queue. So, it's been queued.
Thanks,
Roman