KVM: x86: CPUID tracepoint enhancements
cover KVM: x86: CPUID tracepoint enhancements
Two enhancements to the CPUID tracepoint. Patch 01 was originally in the CPUID ranges series, but I unintentionally dropped it in v2.
The final output looks like:
kvm_cpuid: func 0 idx 0 rax d rbx 68747541 rcx 444d4163 rdx 69746e65, cpuid entry found
kvm_cpuid: func d idx 444d4163 rax 0 rbx 0 rcx 0 rdx 0, cpuid entry not found
kvm_cpuid: func 80000023 idx 1 rax f rbx 240 rcx 0 rdx 0, cpuid entry not found, used max basic
kvm_cpuid: func 80000023 idx 2 rax 100 rbx 240 rcx 0 rdx 0, cpuid entry not found, used max basic
I also considered appending "exact" to the "found" case, which is more directly what Jan suggested, but IMO "found exact" implies there's also a "found inexact", which is not true. AIUI, calling out that KVM is using the max basic leaf values is what's really important to avoid confusion.
Ideally, the function of the max basic leaf would also be displayed, but doing that without printing garbage for the other cases is a lot of ugly code for marginal value.
Sean Christopherson (2):
KVM: x86: Add requested index to the CPUID tracepoint
KVM: x86: Add blurb to CPUID tracepoint when using max basic leaf
values
arch/x86/kvm/cpuid.c | 9 ++++++--- arch/x86/kvm/trace.h | 18 ++++++++++++------ 2 files changed, 18 insertions(+), 9 deletions(-)
Signature · 1 line
2.24.1
PATCH 1/2 KVM: x86: Add requested index to the CPUID tracepoint
Output the requested index when tracing CPUID emulation; it's basically mandatory for leafs where the index is meaningful, and is helpful for verifying KVM correctness even when the index isn't meaningful, e.g. the trace for a Linux guest's hypervisor_cpuid_base() probing appears to be broken (returns all zeroes) at first glance, but is correct because the index is non-zero, i.e. the output values correspond to a random index in the maximum basic leaf.
--- arch/x86/kvm/cpuid.c | 2 +- arch/x86/kvm/trace.h | 13 ++++++++----- 2 files changed, 9 insertions(+), 6 deletions(-)
arch/x86/kvm/cpuid.c +1 -1
@@ -1026,7 +1026,7 @@ bool kvm_cpuid(struct kvm_vcpu *vcpu, u32 *eax, u32 *ebx, } } } -trace_kvm_cpuid (orig_function, *eax, *ebx, *ecx, *edx, exact); +trace_kvm_cpuid (orig_function, index, *eax, *ebx, *ecx, *edx, exact);return exact; }EXPORT_SYMBOL_GPL (kvm_cpuid);
arch/x86/kvm/trace.h +8 -5
@@ -151,12 +151,14 @@ TRACE_EVENT(kvm_fast_mmio,* Tracepoint for cpuid. */ TRACE_EVENT(kvm_cpuid, - TP_PROTO(unsigned int function, unsigned long rax, unsigned long rbx, - unsigned long rcx, unsigned long rdx, bool found), - TP_ARGS(function, rax, rbx, rcx, rdx, found), + TP_PROTO(unsigned int function, unsigned int index, unsigned long rax, + unsigned long rbx, unsigned long rcx, unsigned long rdx, + bool found), + TP_ARGS(function, index, rax, rbx, rcx, rdx, found), TP_STRUCT__entry( __field( unsigned int, function ) + __field( unsigned int, index ) __field( unsigned long, rax ) __field( unsigned long, rbx ) __field( unsigned long, rcx )
@@ -166,6 +168,7 @@ TRACE_EVENT(kvm_cpuid,TP_fast_assign ( __entry->function = function; + __entry->index = index; __entry->rax = rax; __entry->rbx = rbx; __entry->rcx = rcx;
@@ -173,8 +176,8 @@ TRACE_EVENT(kvm_cpuid, __entry->found = found; ), -TP_printk ("func %x rax %lx rbx %lx rcx %lx rdx %lx, cpuid entry %s" , - __entry->function, __entry->rax, +TP_printk ("func %x idx %x rax %lx rbx %lx rcx %lx rdx %lx, cpuid entry %s" , + __entry->function, __entry->index, __entry->rax, __entry->rbx, __entry->rcx, __entry->rdx, __entry->found ?"found" :"not found" ) );
Signature · 1 line
2.24.1
PATCH 2/2 KVM: x86: Add blurb to CPUID tracepoint when using max basic leaf values
In reply to Sean ChristophersonTack on "used max basic" at the end of the CPUID tracepoint when the output values correspond to the max basic leaf, i.e. when emulating Intel's out-of-range CPUID behavior. Observing "cpuid entry not found" in the tracepoint with non-zero output values is confusing for users that aren't familiar with the out-of-range semantics, and qualifying the "not found" case hopefully makes it clear that "found" means "found the exact entry".
--- arch/x86/kvm/cpuid.c | 9 ++++++--- arch/x86/kvm/trace.h | 11 +++++++---- 2 files changed, 13 insertions(+), 7 deletions(-)
arch/x86/kvm/cpuid.c +6 -3
@@ -990,13 +990,15 @@ bool kvm_cpuid(struct kvm_vcpu *vcpu, u32 *eax, u32 *ebx, {u32 orig_function = *eax, function = *eax, index = *ecx;struct kvm_cpuid_entry2 *entry; -bool exact; +bool exact, used_max_basic = false; entry =kvm_find_cpuid_entry (vcpu, function, index); exact = !!entry; -if (!entry && !exact_only) +if (!entry && !exact_only) { entry =get_out_of_range_cpuid_entry (vcpu, &function, index); + used_max_basic = !!entry; + }if (entry) { *eax = entry->eax;
@@ -1026,7 +1028,8 @@ bool kvm_cpuid(struct kvm_vcpu *vcpu, u32 *eax, u32 *ebx, } } } -trace_kvm_cpuid (orig_function, index, *eax, *ebx, *ecx, *edx, exact); +trace_kvm_cpuid (orig_function, index, *eax, *ebx, *ecx, *edx, exact, + used_max_basic);return exact; }EXPORT_SYMBOL_GPL (kvm_cpuid);
arch/x86/kvm/trace.h +7 -4
@@ -153,8 +153,8 @@ TRACE_EVENT(kvm_fast_mmio, TRACE_EVENT(kvm_cpuid, TP_PROTO(unsigned int function, unsigned int index, unsigned long rax, unsigned long rbx, unsigned long rcx, unsigned long rdx, - bool found), - TP_ARGS(function, index, rax, rbx, rcx, rdx, found), + bool found, bool used_max_basic), + TP_ARGS(function, index, rax, rbx, rcx, rdx, found, used_max_basic), TP_STRUCT__entry( __field( unsigned int, function )
@@ -164,6 +164,7 @@ TRACE_EVENT(kvm_cpuid, __field( unsigned long, rcx ) __field( unsigned long, rdx ) __field( bool, found ) + __field( bool, used_max_basic ) ), TP_fast_assign(
@@ -174,12 +175,14 @@ TRACE_EVENT(kvm_cpuid, __entry->rcx = rcx; __entry->rdx = rdx; __entry->found = found; + __entry->used_max_basic = used_max_basic; ), -TP_printk ("func %x idx %x rax %lx rbx %lx rcx %lx rdx %lx, cpuid entry %s" , +TP_printk ("func %x idx %x rax %lx rbx %lx rcx %lx rdx %lx, cpuid entry %s%s" , __entry->function, __entry->index, __entry->rax, __entry->rbx, __entry->rcx, __entry->rdx, - __entry->found ?"found" :"not found" ) + __entry->found ?"found" :"not found" , + __entry->used_max_basic ?", used max basic" :"" ) );#define AREG (x) { APIC_##x, "APIC_" #x }
Signature · 1 line
2.24.1
Quoted 19 lines · Sean Christopherson
Two enhancements to the CPUID tracepoint. Patch 01 was originally in the CPUID ranges series, but I unintentionally dropped it in v2.
The final output looks like:
kvm_cpuid: func 0 idx 0 rax d rbx 68747541 rcx444d4163rdx69746e65, cpuid entry found
kvm_cpuid: func d idx444d4163rax 0 rbx 0 rcx 0 rdx 0, cpuid entry not found
kvm_cpuid: func 80000023 idx 1 rax f rbx 240 rcx 0 rdx 0, cpuid entry not found, used max basic
kvm_cpuid: func 80000023 idx 2 rax 100 rbx 240 rcx 0 rdx 0, cpuid entry not found, used max basicI also considered appending "exact" to the "found" case, which is more directly what Jan suggested, but IMO "found exact" implies there's also a "found inexact", which is not true. AIUI, calling out that KVM is using the max basic leaf values is what's really important to avoid confusion.
Ideally, the function of the max basic leaf would also be displayed, but doing that without printing garbage for the other cases is a lot of ugly code for marginal value.
Quoted 9 lines
Sean Christopherson (2):
KVM: x86: Add requested index to the CPUID tracepoint
KVM: x86: Add blurb to CPUID tracepoint when using max basic leaf
valuesarch/x86/kvm/cpuid.c | 9 ++++++--- arch/x86/kvm/trace.h | 18 ++++++++++++------ 2 files changed, 18 insertions(+), 9 deletions(-)
Queued, thanks.
Paolo