x86/Intel: virtualize support for cpuid faulting
authorKyle Huey <me@kylehuey.com>
Thu, 20 Oct 2016 13:44:28 +0000 (06:44 -0700)
committerAndrew Cooper <andrew.cooper3@citrix.com>
Thu, 20 Oct 2016 14:28:07 +0000 (15:28 +0100)
commit4abcd521bf460fb3a247a7754698f98526b39635
treed8a750ed60ffcc3108278184338fe04c630711b7
parent70c95ecd5c0ec2fc5cf2bb0c5f96814bbd10c5b3
x86/Intel: virtualize support for cpuid faulting

On HVM guests, the cpuid triggers a vm exit, so we can check the emulated
faulting state in vmx_do_cpuid and hvmemul_cpuid. A new function,
hvm_check_cpuid_fault will check if cpuid faulting is enabled and the CPL > 0.
When it returns true, the cpuid handling functions will inject a GP(0). Notably
explicit hardware support for faulting on cpuid is not necessary to emulate
support for an HVM guest.

On PV guests, hardware support is required so that userspace cpuid will trap
to Xen. Xen already enables cpuid faulting on supported CPUs for pv guests (that
aren't the control domain, see the comment in intel_ctxt_switch_levelling).
Every PV guest cpuid will trap via a GP(0) to emulate_privileged_op (via
do_general_protection). Once there we simply decline to emulate cpuid if the
CPL > 0 and faulting is enabled, leaving the GP(0) for the guest kernel to
handle.

Signed-off-by: Kyle Huey <khuey@kylehuey.com>
Reviewed-by: Kevin Tian <kevin.tian@intel.com>
Reviewed-by: Andrew Cooper <andrew.cooper3@citrix.com>
Release-acked-by: Wei Liu <wei.liu2@citrix.com>
xen/arch/x86/hvm/emulate.c
xen/arch/x86/hvm/hvm.c
xen/arch/x86/hvm/vmx/vmx.c
xen/arch/x86/traps.c
xen/include/asm-x86/domain.h
xen/include/asm-x86/hvm/hvm.h