mbox series

[0/6] KVM: x86: CPUID emulation and tracing fixes

Message ID 20200302195736.24777-1-sean.j.christopherson@intel.com (mailing list archive)
Headers show
Series KVM: x86: CPUID emulation and tracing fixes | expand

Message

Sean Christopherson March 2, 2020, 7:57 p.m. UTC
Two fixes related to out-of-range CPUID emulation and related cleanup on
top.

I have a unit test and also manually verified a few interesting cases.
I'm not planning on posting the unit test at this time because I haven't
figured out how to avoid false positives, e.g. if a random in-bounds
leaf just happens to match the output of a max basic leaf.  It might be
doable by hardcoding the cpu model?

Sean Christopherson (6):
  KVM: x86: Fix tracing of CPUID.function when function is out-of-range
  KVM: x86: Fix CPUID range check for Centaur and Hypervisor ranges
  KVM: x86: Add dedicated emulator helper for grabbing CPUID.maxphyaddr
  KVM: x86: Drop return value from kvm_cpuid()
  KVM: x86: Rename "found" variable in kvm_cpuid() to
    "exact_entry_exists"
  KVM: x86: Add requested index to the CPUID tracepoint

 arch/x86/include/asm/kvm_emulate.h |  3 ++-
 arch/x86/kvm/cpuid.c               | 26 ++++++++++++--------------
 arch/x86/kvm/cpuid.h               |  2 +-
 arch/x86/kvm/emulate.c             | 10 +---------
 arch/x86/kvm/trace.h               | 13 ++++++++-----
 arch/x86/kvm/x86.c                 | 10 ++++++++--
 6 files changed, 32 insertions(+), 32 deletions(-)

Comments

Paolo Bonzini March 3, 2020, 8:48 a.m. UTC | #1
On 02/03/20 20:57, Sean Christopherson wrote:
> Two fixes related to out-of-range CPUID emulation and related cleanup on
> top.
> 
> I have a unit test and also manually verified a few interesting cases.
> I'm not planning on posting the unit test at this time because I haven't
> figured out how to avoid false positives, e.g. if a random in-bounds
> leaf just happens to match the output of a max basic leaf.  It might be
> doable by hardcoding the cpu model?

It would be best suited for selftests rather than kvm-unit-tests.  But I 
don't really see the benefit of anything more than just

diff --git a/arch/x86/kvm/cpuid.c b/arch/x86/kvm/cpuid.c
index b1c469446b07..c1abf5de4461 100644
--- a/arch/x86/kvm/cpuid.c
+++ b/arch/x86/kvm/cpuid.c
@@ -1001,6 +1001,7 @@ bool kvm_cpuid(struct kvm_vcpu *vcpu, u32 *eax, u32 *ebx,
 	       u32 *ecx, u32 *edx, bool check_limit)
 {
 	u32 function = *eax, index = *ecx;
+	u32 orig_function = function;
 	struct kvm_cpuid_entry2 *entry;
 	struct kvm_cpuid_entry2 *max;
 	bool found;
@@ -1049,7 +1050,7 @@ bool kvm_cpuid(struct kvm_vcpu *vcpu, u32 *eax, u32 *ebx,
 			}
 		}
 	}
-	trace_kvm_cpuid(function, *eax, *ebx, *ecx, *edx, found);
+	trace_kvm_cpuid(orig_function, *eax, *ebx, *ecx, *edx, found);
 	return found;
 }
 EXPORT_SYMBOL_GPL(kvm_cpuid);
Sean Christopherson March 3, 2020, 4:38 p.m. UTC | #2
On Tue, Mar 03, 2020 at 09:48:44AM +0100, Paolo Bonzini wrote:
> On 02/03/20 20:57, Sean Christopherson wrote:
> > Two fixes related to out-of-range CPUID emulation and related cleanup on
> > top.
> > 
> > I have a unit test and also manually verified a few interesting cases.
> > I'm not planning on posting the unit test at this time because I haven't
> > figured out how to avoid false positives, e.g. if a random in-bounds
> > leaf just happens to match the output of a max basic leaf.  It might be
> > doable by hardcoding the cpu model?
> 
> It would be best suited for selftests rather than kvm-unit-tests.  But I 
> don't really see the benefit of anything more than just

Gotta save those stack bytes?

I got a bit confused by the "max" variable; I thought it would hold the
max basic leaf, not CPUID.0x0.  Removing it seemed easier than trying to
come up with a better name :-)
 
> diff --git a/arch/x86/kvm/cpuid.c b/arch/x86/kvm/cpuid.c
> index b1c469446b07..c1abf5de4461 100644
> --- a/arch/x86/kvm/cpuid.c
> +++ b/arch/x86/kvm/cpuid.c
> @@ -1001,6 +1001,7 @@ bool kvm_cpuid(struct kvm_vcpu *vcpu, u32 *eax, u32 *ebx,
>  	       u32 *ecx, u32 *edx, bool check_limit)
>  {
>  	u32 function = *eax, index = *ecx;
> +	u32 orig_function = function;
>  	struct kvm_cpuid_entry2 *entry;
>  	struct kvm_cpuid_entry2 *max;
>  	bool found;
> @@ -1049,7 +1050,7 @@ bool kvm_cpuid(struct kvm_vcpu *vcpu, u32 *eax, u32 *ebx,
>  			}
>  		}
>  	}
> -	trace_kvm_cpuid(function, *eax, *ebx, *ecx, *edx, found);
> +	trace_kvm_cpuid(orig_function, *eax, *ebx, *ecx, *edx, found);
>  	return found;
>  }
>  EXPORT_SYMBOL_GPL(kvm_cpuid);
>