qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] hvf: Fetch cr4 before evaluating CPUID(1)
@ 2021-01-23  0:41 Alexander Graf
  2021-02-09 10:14 ` Roman Bolshakov
  0 siblings, 1 reply; 2+ messages in thread
From: Alexander Graf @ 2021-01-23  0:41 UTC (permalink / raw)
  To: qemu-devel
  Cc: Eduardo Habkost, Asad Ali, Richard Henderson, Cameron Esfahani,
	Roman Bolshakov, Paolo Bonzini

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 <asad@osaro.com>
Signed-off-by: Alexander Graf <agraf@csgraf.de>
---
 target/i386/hvf/hvf.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/target/i386/hvf/hvf.c b/target/i386/hvf/hvf.c
index 08b4adecd9..f660b829ac 100644
--- a/target/i386/hvf/hvf.c
+++ b/target/i386/hvf/hvf.c
@@ -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);
-- 
2.24.3 (Apple Git-128)



^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2021-02-09 10:15 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-01-23  0:41 [PATCH] hvf: Fetch cr4 before evaluating CPUID(1) Alexander Graf
2021-02-09 10:14 ` Roman Bolshakov

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).