int hvmemul_cpuid(uint32_t leaf, uint32_t subleaf,
struct cpuid_leaf *res, struct x86_emulate_ctxt *ctxt)
{
- /*
- * x86_emulate uses this function to query CPU features for its own internal
- * use. Make sure we're actually emulating CPUID before emulating CPUID
- * faulting.
- */
- if ( ctxt->opcode == X86EMUL_OPC(0x0f, 0xa2) &&
- hvm_check_cpuid_faulting(current) )
- return X86EMUL_EXCEPTION;
-
guest_cpuid(current, leaf, subleaf, res);
return X86EMUL_OKAY;
}
int pv_emul_cpuid(uint32_t leaf, uint32_t subleaf,
struct cpuid_leaf *res, struct x86_emulate_ctxt *ctxt)
{
- const struct vcpu *curr = current;
-
- /*
- * x86_emulate uses this function to query CPU features for its own
- * internal use. Make sure we're actually emulating CPUID before checking
- * for emulated CPUID faulting.
- */
- if ( ctxt->opcode == X86EMUL_OPC(0x0f, 0xa2) )
- {
-
- /* If cpuid faulting is enabled and CPL>0 leave the #GP untouched. */
- if ( curr->arch.cpuid_faulting &&
- !guest_kernel_mode(curr, ctxt->regs) )
- return X86EMUL_EXCEPTION;
- }
-
- guest_cpuid(curr, leaf, subleaf, res);
+ guest_cpuid(current, leaf, subleaf, res);
return X86EMUL_OKAY;
}
break;
case X86EMUL_OPC(0x0f, 0xa2): /* cpuid */
+ msr_val = 0;
fail_if(ops->cpuid == NULL);
+
+ /* Speculatively read MSR_INTEL_MISC_FEATURES_ENABLES. */
+ if ( ops->read_msr && !mode_ring0() &&
+ (rc = ops->read_msr(MSR_INTEL_MISC_FEATURES_ENABLES,
+ &msr_val, ctxt)) == X86EMUL_EXCEPTION )
+ {
+ /* Not implemented. Squash the exception and proceed normally. */
+ x86_emul_reset_event(ctxt);
+ rc = X86EMUL_OKAY;
+ }
+ if ( rc != X86EMUL_OKAY )
+ goto done;
+
+ generate_exception_if((msr_val & MSR_MISC_FEATURES_CPUID_FAULTING),
+ EXC_GP, 0); /* Faulting active? (Inc. CPL test) */
+
rc = ops->cpuid(_regs._eax, _regs._ecx, &cpuid_leaf, ctxt);
- generate_exception_if(rc == X86EMUL_EXCEPTION,
- EXC_GP, 0); /* CPUID Faulting? */
if ( rc != X86EMUL_OKAY )
goto done;
_regs.r(ax) = cpuid_leaf.a;
int (*wbinvd)(
struct x86_emulate_ctxt *ctxt);
- /*
- * cpuid: Emulate CPUID via given set of EAX-EDX inputs/outputs.
- *
- * May return X86EMUL_EXCEPTION, which causes the emulator to inject
- * #GP[0]. Used to implement CPUID faulting.
- */
+ /* cpuid: Emulate CPUID via given set of EAX-EDX inputs/outputs. */
int (*cpuid)(
uint32_t leaf,
uint32_t subleaf,