2020-03-02 19:58:16

by Sean Christopherson

[permalink] [raw]
Subject: [PATCH 6/6] 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 random index
in the maximum basic leaf.

Suggested-by: Xiaoyao Li <[email protected]>
Cc: Jan Kiszka <[email protected]>
Signed-off-by: Sean Christopherson <[email protected]>
---
arch/x86/kvm/cpuid.c | 3 ++-
arch/x86/kvm/trace.h | 13 ++++++++-----
2 files changed, 10 insertions(+), 6 deletions(-)

diff --git a/arch/x86/kvm/cpuid.c b/arch/x86/kvm/cpuid.c
index b0a4f3c17932..a3c9f6bf43f3 100644
--- a/arch/x86/kvm/cpuid.c
+++ b/arch/x86/kvm/cpuid.c
@@ -1047,7 +1047,8 @@ void kvm_cpuid(struct kvm_vcpu *vcpu, u32 *eax, u32 *ebx,
}
}
}
- trace_kvm_cpuid(function, *eax, *ebx, *ecx, *edx, exact_entry_exists);
+ trace_kvm_cpuid(function, index, *eax, *ebx, *ecx, *edx,
+ exact_entry_exists);
}
EXPORT_SYMBOL_GPL(kvm_cpuid);

diff --git a/arch/x86/kvm/trace.h b/arch/x86/kvm/trace.h
index f194dd058470..aa372d0119f0 100644
--- a/arch/x86/kvm/trace.h
+++ b/arch/x86/kvm/trace.h
@@ -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")
);
--
2.24.1


2020-03-07 09:50:38

by Jan Kiszka

[permalink] [raw]
Subject: Re: [PATCH 6/6] KVM: x86: Add requested index to the CPUID tracepoint

On 02.03.20 20:57, Sean Christopherson wrote:
> 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 random index
> in the maximum basic leaf.
>
> Suggested-by: Xiaoyao Li <[email protected]>
> Cc: Jan Kiszka <[email protected]>
> Signed-off-by: Sean Christopherson <[email protected]>
> ---
> arch/x86/kvm/cpuid.c | 3 ++-
> arch/x86/kvm/trace.h | 13 ++++++++-----
> 2 files changed, 10 insertions(+), 6 deletions(-)
>
> diff --git a/arch/x86/kvm/cpuid.c b/arch/x86/kvm/cpuid.c
> index b0a4f3c17932..a3c9f6bf43f3 100644
> --- a/arch/x86/kvm/cpuid.c
> +++ b/arch/x86/kvm/cpuid.c
> @@ -1047,7 +1047,8 @@ void kvm_cpuid(struct kvm_vcpu *vcpu, u32 *eax, u32 *ebx,
> }
> }
> }
> - trace_kvm_cpuid(function, *eax, *ebx, *ecx, *edx, exact_entry_exists);
> + trace_kvm_cpuid(function, index, *eax, *ebx, *ecx, *edx,
> + exact_entry_exists);
> }
> EXPORT_SYMBOL_GPL(kvm_cpuid);
>
> diff --git a/arch/x86/kvm/trace.h b/arch/x86/kvm/trace.h
> index f194dd058470..aa372d0119f0 100644
> --- a/arch/x86/kvm/trace.h
> +++ b/arch/x86/kvm/trace.h
> @@ -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")
> );
>

What happened to this patch in your v2 round?

Jan

2020-03-10 04:01:05

by Sean Christopherson

[permalink] [raw]
Subject: Re: [PATCH 6/6] KVM: x86: Add requested index to the CPUID tracepoint

On Sat, Mar 07, 2020 at 10:48:25AM +0100, Jan Kiszka wrote:
> On 02.03.20 20:57, Sean Christopherson wrote:
> >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 random index
> >in the maximum basic leaf.
> >
> >Suggested-by: Xiaoyao Li <[email protected]>
> >Cc: Jan Kiszka <[email protected]>
> >Signed-off-by: Sean Christopherson <[email protected]>
> >---
> > arch/x86/kvm/cpuid.c | 3 ++-
> > arch/x86/kvm/trace.h | 13 ++++++++-----
> > 2 files changed, 10 insertions(+), 6 deletions(-)
> >
> >diff --git a/arch/x86/kvm/cpuid.c b/arch/x86/kvm/cpuid.c
> >index b0a4f3c17932..a3c9f6bf43f3 100644
> >--- a/arch/x86/kvm/cpuid.c
> >+++ b/arch/x86/kvm/cpuid.c
> >@@ -1047,7 +1047,8 @@ void kvm_cpuid(struct kvm_vcpu *vcpu, u32 *eax, u32 *ebx,
> > }
> > }
> > }
> >- trace_kvm_cpuid(function, *eax, *ebx, *ecx, *edx, exact_entry_exists);
> >+ trace_kvm_cpuid(function, index, *eax, *ebx, *ecx, *edx,
> >+ exact_entry_exists);
> > }
> > EXPORT_SYMBOL_GPL(kvm_cpuid);
> >
> >diff --git a/arch/x86/kvm/trace.h b/arch/x86/kvm/trace.h
> >index f194dd058470..aa372d0119f0 100644
> >--- a/arch/x86/kvm/trace.h
> >+++ b/arch/x86/kvm/trace.h
> >@@ -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")
> > );
> >
>
> What happened to this patch in your v2 round?

I completely forgot about it...