All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/2] KVM: VMX: Fix and a cleanup for VM-Exit tracing
@ 2020-05-08 23:53 Sean Christopherson
  2020-05-08 23:53 ` [PATCH 1/2] KVM: VMX: Invoke kvm_exit tracepoint on VM-Exit due to failed VM-Enter Sean Christopherson
  2020-05-08 23:53 ` [PATCH 2/2] KVM: x86: Print symbolic names of VMX VM-Exit flags in traces Sean Christopherson
  0 siblings, 2 replies; 7+ messages in thread
From: Sean Christopherson @ 2020-05-08 23:53 UTC (permalink / raw)
  To: Paolo Bonzini
  Cc: Sean Christopherson, Vitaly Kuznetsov, Wanpeng Li, Jim Mattson,
	Joerg Roedel, kvm, linux-kernel

Fix for a recently introduced bug where KVM no longer traces failed
VM-Enter, and a previously posted patch for printing symbolic names of
VM-Exit flags, e.g. the flag set on failed VM-Enter.

Sean Christopherson (2):
  KVM: VMX: Invoke kvm_exit tracepoint on VM-Exit due to failed VM-Enter
  KVM: x86: Print symbolic names of VMX VM-Exit flags in traces

 arch/x86/include/uapi/asm/vmx.h |  3 +++
 arch/x86/kvm/trace.h            | 32 +++++++++++++++++---------------
 arch/x86/kvm/vmx/vmx.c          |  4 ++--
 3 files changed, 22 insertions(+), 17 deletions(-)

-- 
2.26.0


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH 1/2] KVM: VMX: Invoke kvm_exit tracepoint on VM-Exit due to failed VM-Enter
  2020-05-08 23:53 [PATCH 0/2] KVM: VMX: Fix and a cleanup for VM-Exit tracing Sean Christopherson
@ 2020-05-08 23:53 ` Sean Christopherson
  2020-05-09 12:54   ` Paolo Bonzini
  2020-05-08 23:53 ` [PATCH 2/2] KVM: x86: Print symbolic names of VMX VM-Exit flags in traces Sean Christopherson
  1 sibling, 1 reply; 7+ messages in thread
From: Sean Christopherson @ 2020-05-08 23:53 UTC (permalink / raw)
  To: Paolo Bonzini
  Cc: Sean Christopherson, Vitaly Kuznetsov, Wanpeng Li, Jim Mattson,
	Joerg Roedel, kvm, linux-kernel

Restore the pre-fastpath behavior of tracing all VM-Exits, including
those due to failed VM-Enter.

Fixes: 032e5dcbcb443 ("KVM: VMX: Introduce generic fastpath handler")
Signed-off-by: Sean Christopherson <sean.j.christopherson@intel.com>
---
 arch/x86/kvm/vmx/vmx.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/arch/x86/kvm/vmx/vmx.c b/arch/x86/kvm/vmx/vmx.c
index bc5e5cf1d4cc8..a6d108bfc7132 100644
--- a/arch/x86/kvm/vmx/vmx.c
+++ b/arch/x86/kvm/vmx/vmx.c
@@ -6801,6 +6801,8 @@ static fastpath_t vmx_vcpu_run(struct kvm_vcpu *vcpu)
 	if (unlikely((u16)vmx->exit_reason == EXIT_REASON_MCE_DURING_VMENTRY))
 		kvm_machine_check();
 
+	trace_kvm_exit(vmx->exit_reason, vcpu, KVM_ISA_VMX);
+
 	if (unlikely(vmx->exit_reason & VMX_EXIT_REASONS_FAILED_VMENTRY))
 		return EXIT_FASTPATH_NONE;
 
@@ -6810,8 +6812,6 @@ static fastpath_t vmx_vcpu_run(struct kvm_vcpu *vcpu)
 	vmx_recover_nmi_blocking(vmx);
 	vmx_complete_interrupts(vmx);
 
-	trace_kvm_exit(vmx->exit_reason, vcpu, KVM_ISA_VMX);
-
 	if (is_guest_mode(vcpu))
 		return EXIT_FASTPATH_NONE;
 
-- 
2.26.0


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH 2/2] KVM: x86: Print symbolic names of VMX VM-Exit flags in traces
  2020-05-08 23:53 [PATCH 0/2] KVM: VMX: Fix and a cleanup for VM-Exit tracing Sean Christopherson
  2020-05-08 23:53 ` [PATCH 1/2] KVM: VMX: Invoke kvm_exit tracepoint on VM-Exit due to failed VM-Enter Sean Christopherson
@ 2020-05-08 23:53 ` Sean Christopherson
  2020-05-09 12:55   ` Paolo Bonzini
  1 sibling, 1 reply; 7+ messages in thread
From: Sean Christopherson @ 2020-05-08 23:53 UTC (permalink / raw)
  To: Paolo Bonzini
  Cc: Sean Christopherson, Vitaly Kuznetsov, Wanpeng Li, Jim Mattson,
	Joerg Roedel, kvm, linux-kernel

Use __print_flags() to display the names of VMX flags in VM-Exit traces
and strip the flags when printing the basic exit reason, e.g. so that a
failed VM-Entry due to invalid guest state gets recorded as
"INVALID_STATE FAILED_VMENTRY" instead of "0x80000021".

Opportunstically fix misaligned variables in the kvm_exit and
kvm_nested_vmexit_inject tracepoints.

Reviewed-by: Vitaly Kuznetsov <vkuznets@redhat.com>
Signed-off-by: Sean Christopherson <sean.j.christopherson@intel.com>
---
 arch/x86/include/uapi/asm/vmx.h |  3 +++
 arch/x86/kvm/trace.h            | 32 +++++++++++++++++---------------
 2 files changed, 20 insertions(+), 15 deletions(-)

diff --git a/arch/x86/include/uapi/asm/vmx.h b/arch/x86/include/uapi/asm/vmx.h
index e95b72ec19bc0..b8ff9e8ac0d51 100644
--- a/arch/x86/include/uapi/asm/vmx.h
+++ b/arch/x86/include/uapi/asm/vmx.h
@@ -150,6 +150,9 @@
 	{ EXIT_REASON_UMWAIT,                "UMWAIT" }, \
 	{ EXIT_REASON_TPAUSE,                "TPAUSE" }
 
+#define VMX_EXIT_REASON_FLAGS \
+	{ VMX_EXIT_REASONS_FAILED_VMENTRY,	"FAILED_VMENTRY" }
+
 #define VMX_ABORT_SAVE_GUEST_MSR_FAIL        1
 #define VMX_ABORT_LOAD_HOST_PDPTE_FAIL       2
 #define VMX_ABORT_LOAD_HOST_MSR_FAIL         4
diff --git a/arch/x86/kvm/trace.h b/arch/x86/kvm/trace.h
index 249062f24b940..54a10c98d7466 100644
--- a/arch/x86/kvm/trace.h
+++ b/arch/x86/kvm/trace.h
@@ -225,6 +225,14 @@ TRACE_EVENT(kvm_apic,
 #define KVM_ISA_VMX   1
 #define KVM_ISA_SVM   2
 
+#define kvm_print_exit_reason(exit_reason, isa)				\
+	(isa == KVM_ISA_VMX) ?						\
+	__print_symbolic(exit_reason & 0xffff, VMX_EXIT_REASONS) :	\
+	__print_symbolic(exit_reason, SVM_EXIT_REASONS),		\
+	(isa == KVM_ISA_VMX && exit_reason & ~0xffff) ? " " : "",	\
+	(isa == KVM_ISA_VMX) ?						\
+	__print_flags(exit_reason & ~0xffff, " ", VMX_EXIT_REASON_FLAGS) : ""
+
 /*
  * Tracepoint for kvm guest exit:
  */
@@ -250,12 +258,10 @@ TRACE_EVENT(kvm_exit,
 					   &__entry->info2);
 	),
 
-	TP_printk("vcpu %u reason %s rip 0x%lx info %llx %llx",
+	TP_printk("vcpu %u reason %s%s%s rip 0x%lx info %llx %llx",
 		  __entry->vcpu_id,
-		 (__entry->isa == KVM_ISA_VMX) ?
-		 __print_symbolic(__entry->exit_reason, VMX_EXIT_REASONS) :
-		 __print_symbolic(__entry->exit_reason, SVM_EXIT_REASONS),
-		 __entry->guest_rip, __entry->info1, __entry->info2)
+		  kvm_print_exit_reason(__entry->exit_reason, __entry->isa),
+		  __entry->guest_rip, __entry->info1, __entry->info2)
 );
 
 /*
@@ -588,12 +594,10 @@ TRACE_EVENT(kvm_nested_vmexit,
 		__entry->exit_int_info_err	= exit_int_info_err;
 		__entry->isa			= isa;
 	),
-	TP_printk("rip: 0x%016llx reason: %s ext_inf1: 0x%016llx "
+	TP_printk("rip: 0x%016llx reason: %s%s%s ext_inf1: 0x%016llx "
 		  "ext_inf2: 0x%016llx ext_int: 0x%08x ext_int_err: 0x%08x",
 		  __entry->rip,
-		 (__entry->isa == KVM_ISA_VMX) ?
-		 __print_symbolic(__entry->exit_code, VMX_EXIT_REASONS) :
-		 __print_symbolic(__entry->exit_code, SVM_EXIT_REASONS),
+		  kvm_print_exit_reason(__entry->exit_code, __entry->isa),
 		  __entry->exit_info1, __entry->exit_info2,
 		  __entry->exit_int_info, __entry->exit_int_info_err)
 );
@@ -626,13 +630,11 @@ TRACE_EVENT(kvm_nested_vmexit_inject,
 		__entry->isa			= isa;
 	),
 
-	TP_printk("reason: %s ext_inf1: 0x%016llx "
+	TP_printk("reason: %s%s%s ext_inf1: 0x%016llx "
 		  "ext_inf2: 0x%016llx ext_int: 0x%08x ext_int_err: 0x%08x",
-		 (__entry->isa == KVM_ISA_VMX) ?
-		 __print_symbolic(__entry->exit_code, VMX_EXIT_REASONS) :
-		 __print_symbolic(__entry->exit_code, SVM_EXIT_REASONS),
-		__entry->exit_info1, __entry->exit_info2,
-		__entry->exit_int_info, __entry->exit_int_info_err)
+		  kvm_print_exit_reason(__entry->exit_code, __entry->isa),
+		  __entry->exit_info1, __entry->exit_info2,
+		  __entry->exit_int_info, __entry->exit_int_info_err)
 );
 
 /*
-- 
2.26.0


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [PATCH 1/2] KVM: VMX: Invoke kvm_exit tracepoint on VM-Exit due to failed VM-Enter
  2020-05-08 23:53 ` [PATCH 1/2] KVM: VMX: Invoke kvm_exit tracepoint on VM-Exit due to failed VM-Enter Sean Christopherson
@ 2020-05-09 12:54   ` Paolo Bonzini
  2020-05-11 17:08     ` Sean Christopherson
  0 siblings, 1 reply; 7+ messages in thread
From: Paolo Bonzini @ 2020-05-09 12:54 UTC (permalink / raw)
  To: Sean Christopherson
  Cc: Vitaly Kuznetsov, Wanpeng Li, Jim Mattson, Joerg Roedel, kvm,
	linux-kernel

On 09/05/20 01:53, Sean Christopherson wrote:
> Restore the pre-fastpath behavior of tracing all VM-Exits, including
> those due to failed VM-Enter.
> 
> Fixes: 032e5dcbcb443 ("KVM: VMX: Introduce generic fastpath handler")
> Signed-off-by: Sean Christopherson <sean.j.christopherson@intel.com>
> ---
>  arch/x86/kvm/vmx/vmx.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)

Squashed, thanks.  Though is it really the right "Fixes"?

Paolo


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH 2/2] KVM: x86: Print symbolic names of VMX VM-Exit flags in traces
  2020-05-08 23:53 ` [PATCH 2/2] KVM: x86: Print symbolic names of VMX VM-Exit flags in traces Sean Christopherson
@ 2020-05-09 12:55   ` Paolo Bonzini
  0 siblings, 0 replies; 7+ messages in thread
From: Paolo Bonzini @ 2020-05-09 12:55 UTC (permalink / raw)
  To: Sean Christopherson
  Cc: Vitaly Kuznetsov, Wanpeng Li, Jim Mattson, Joerg Roedel, kvm,
	linux-kernel

On 09/05/20 01:53, Sean Christopherson wrote:
> Use __print_flags() to display the names of VMX flags in VM-Exit traces
> and strip the flags when printing the basic exit reason, e.g. so that a
> failed VM-Entry due to invalid guest state gets recorded as
> "INVALID_STATE FAILED_VMENTRY" instead of "0x80000021".
> 
> Opportunstically fix misaligned variables in the kvm_exit and
> kvm_nested_vmexit_inject tracepoints.
> 
> Reviewed-by: Vitaly Kuznetsov <vkuznets@redhat.com>
> Signed-off-by: Sean Christopherson <sean.j.christopherson@intel.com>
> ---
>  arch/x86/include/uapi/asm/vmx.h |  3 +++
>  arch/x86/kvm/trace.h            | 32 +++++++++++++++++---------------
>  2 files changed, 20 insertions(+), 15 deletions(-)
> 
> diff --git a/arch/x86/include/uapi/asm/vmx.h b/arch/x86/include/uapi/asm/vmx.h
> index e95b72ec19bc0..b8ff9e8ac0d51 100644
> --- a/arch/x86/include/uapi/asm/vmx.h
> +++ b/arch/x86/include/uapi/asm/vmx.h
> @@ -150,6 +150,9 @@
>  	{ EXIT_REASON_UMWAIT,                "UMWAIT" }, \
>  	{ EXIT_REASON_TPAUSE,                "TPAUSE" }
>  
> +#define VMX_EXIT_REASON_FLAGS \
> +	{ VMX_EXIT_REASONS_FAILED_VMENTRY,	"FAILED_VMENTRY" }
> +
>  #define VMX_ABORT_SAVE_GUEST_MSR_FAIL        1
>  #define VMX_ABORT_LOAD_HOST_PDPTE_FAIL       2
>  #define VMX_ABORT_LOAD_HOST_MSR_FAIL         4
> diff --git a/arch/x86/kvm/trace.h b/arch/x86/kvm/trace.h
> index 249062f24b940..54a10c98d7466 100644
> --- a/arch/x86/kvm/trace.h
> +++ b/arch/x86/kvm/trace.h
> @@ -225,6 +225,14 @@ TRACE_EVENT(kvm_apic,
>  #define KVM_ISA_VMX   1
>  #define KVM_ISA_SVM   2
>  
> +#define kvm_print_exit_reason(exit_reason, isa)				\
> +	(isa == KVM_ISA_VMX) ?						\
> +	__print_symbolic(exit_reason & 0xffff, VMX_EXIT_REASONS) :	\
> +	__print_symbolic(exit_reason, SVM_EXIT_REASONS),		\
> +	(isa == KVM_ISA_VMX && exit_reason & ~0xffff) ? " " : "",	\
> +	(isa == KVM_ISA_VMX) ?						\
> +	__print_flags(exit_reason & ~0xffff, " ", VMX_EXIT_REASON_FLAGS) : ""
> +
>  /*
>   * Tracepoint for kvm guest exit:
>   */
> @@ -250,12 +258,10 @@ TRACE_EVENT(kvm_exit,
>  					   &__entry->info2);
>  	),
>  
> -	TP_printk("vcpu %u reason %s rip 0x%lx info %llx %llx",
> +	TP_printk("vcpu %u reason %s%s%s rip 0x%lx info %llx %llx",
>  		  __entry->vcpu_id,
> -		 (__entry->isa == KVM_ISA_VMX) ?
> -		 __print_symbolic(__entry->exit_reason, VMX_EXIT_REASONS) :
> -		 __print_symbolic(__entry->exit_reason, SVM_EXIT_REASONS),
> -		 __entry->guest_rip, __entry->info1, __entry->info2)
> +		  kvm_print_exit_reason(__entry->exit_reason, __entry->isa),
> +		  __entry->guest_rip, __entry->info1, __entry->info2)
>  );
>  
>  /*
> @@ -588,12 +594,10 @@ TRACE_EVENT(kvm_nested_vmexit,
>  		__entry->exit_int_info_err	= exit_int_info_err;
>  		__entry->isa			= isa;
>  	),
> -	TP_printk("rip: 0x%016llx reason: %s ext_inf1: 0x%016llx "
> +	TP_printk("rip: 0x%016llx reason: %s%s%s ext_inf1: 0x%016llx "
>  		  "ext_inf2: 0x%016llx ext_int: 0x%08x ext_int_err: 0x%08x",
>  		  __entry->rip,
> -		 (__entry->isa == KVM_ISA_VMX) ?
> -		 __print_symbolic(__entry->exit_code, VMX_EXIT_REASONS) :
> -		 __print_symbolic(__entry->exit_code, SVM_EXIT_REASONS),
> +		  kvm_print_exit_reason(__entry->exit_code, __entry->isa),
>  		  __entry->exit_info1, __entry->exit_info2,
>  		  __entry->exit_int_info, __entry->exit_int_info_err)
>  );
> @@ -626,13 +630,11 @@ TRACE_EVENT(kvm_nested_vmexit_inject,
>  		__entry->isa			= isa;
>  	),
>  
> -	TP_printk("reason: %s ext_inf1: 0x%016llx "
> +	TP_printk("reason: %s%s%s ext_inf1: 0x%016llx "
>  		  "ext_inf2: 0x%016llx ext_int: 0x%08x ext_int_err: 0x%08x",
> -		 (__entry->isa == KVM_ISA_VMX) ?
> -		 __print_symbolic(__entry->exit_code, VMX_EXIT_REASONS) :
> -		 __print_symbolic(__entry->exit_code, SVM_EXIT_REASONS),
> -		__entry->exit_info1, __entry->exit_info2,
> -		__entry->exit_int_info, __entry->exit_int_info_err)
> +		  kvm_print_exit_reason(__entry->exit_code, __entry->isa),
> +		  __entry->exit_info1, __entry->exit_info2,
> +		  __entry->exit_int_info, __entry->exit_int_info_err)
>  );
>  
>  /*
> 

Queued, thanks.

Paolo


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH 1/2] KVM: VMX: Invoke kvm_exit tracepoint on VM-Exit due to failed VM-Enter
  2020-05-09 12:54   ` Paolo Bonzini
@ 2020-05-11 17:08     ` Sean Christopherson
  2020-05-11 17:29       ` Paolo Bonzini
  0 siblings, 1 reply; 7+ messages in thread
From: Sean Christopherson @ 2020-05-11 17:08 UTC (permalink / raw)
  To: Paolo Bonzini
  Cc: Vitaly Kuznetsov, Wanpeng Li, Jim Mattson, Joerg Roedel, kvm,
	linux-kernel

On Sat, May 09, 2020 at 02:54:42PM +0200, Paolo Bonzini wrote:
> On 09/05/20 01:53, Sean Christopherson wrote:
> > Restore the pre-fastpath behavior of tracing all VM-Exits, including
> > those due to failed VM-Enter.
> > 
> > Fixes: 032e5dcbcb443 ("KVM: VMX: Introduce generic fastpath handler")
> > Signed-off-by: Sean Christopherson <sean.j.christopherson@intel.com>
> > ---
> >  arch/x86/kvm/vmx/vmx.c | 4 ++--
> >  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> Squashed, thanks.  Though is it really the right "Fixes"?

Pretty sure, that's the commit that moved trace_kvm_exit() from
vmx_handle_exit() to vmx_vcpu_run().  Prior to that, all fastpaths still
flowed through vmx_handle_exit().

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH 1/2] KVM: VMX: Invoke kvm_exit tracepoint on VM-Exit due to failed VM-Enter
  2020-05-11 17:08     ` Sean Christopherson
@ 2020-05-11 17:29       ` Paolo Bonzini
  0 siblings, 0 replies; 7+ messages in thread
From: Paolo Bonzini @ 2020-05-11 17:29 UTC (permalink / raw)
  To: Sean Christopherson
  Cc: Vitaly Kuznetsov, Wanpeng Li, Jim Mattson, Joerg Roedel, kvm,
	linux-kernel

On 11/05/20 19:08, Sean Christopherson wrote:
> On Sat, May 09, 2020 at 02:54:42PM +0200, Paolo Bonzini wrote:
>> On 09/05/20 01:53, Sean Christopherson wrote:
>>> Restore the pre-fastpath behavior of tracing all VM-Exits, including
>>> those due to failed VM-Enter.
>>>
>>> Fixes: 032e5dcbcb443 ("KVM: VMX: Introduce generic fastpath handler")
>>> Signed-off-by: Sean Christopherson <sean.j.christopherson@intel.com>
>>> ---
>>>  arch/x86/kvm/vmx/vmx.c | 4 ++--
>>>  1 file changed, 2 insertions(+), 2 deletions(-)
>>
>> Squashed, thanks.  Though is it really the right "Fixes"?
> 
> Pretty sure, that's the commit that moved trace_kvm_exit() from
> vmx_handle_exit() to vmx_vcpu_run().  Prior to that, all fastpaths still
> flowed through vmx_handle_exit().
> 

Indeed, fast path was never handled in vcpu_enter_guest.

Paolo


^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2020-05-11 17:29 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-05-08 23:53 [PATCH 0/2] KVM: VMX: Fix and a cleanup for VM-Exit tracing Sean Christopherson
2020-05-08 23:53 ` [PATCH 1/2] KVM: VMX: Invoke kvm_exit tracepoint on VM-Exit due to failed VM-Enter Sean Christopherson
2020-05-09 12:54   ` Paolo Bonzini
2020-05-11 17:08     ` Sean Christopherson
2020-05-11 17:29       ` Paolo Bonzini
2020-05-08 23:53 ` [PATCH 2/2] KVM: x86: Print symbolic names of VMX VM-Exit flags in traces Sean Christopherson
2020-05-09 12:55   ` Paolo Bonzini

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.