All of lore.kernel.org
 help / color / mirror / Atom feed
From: Krish Sadhukhan <krish.sadhukhan@oracle.com>
To: kvm@vger.kernel.org
Cc: pbonzini@redhat.com, jmattson@google.com, seanjc@google.com,
	vkuznets@redhat.com, wanpengli@tencent.com, joro@8bytes.org
Subject: [PATCH] KVM: nVMX: nSVM: Show guest mode in kvm_{entry,exit} tracepoints
Date: Mon, 21 Jun 2021 16:43:45 -0400	[thread overview]
Message-ID: <20210621204345.124480-2-krish.sadhukhan@oracle.com> (raw)
In-Reply-To: <20210621204345.124480-1-krish.sadhukhan@oracle.com>

From debugging point of view, KVM entry and exit tracepoints are important
in that they indicate when a guest starts and exits. When L1 runs L2, there
is no way we can determine from KVM tracing when L1 starts/exits and when
L2 starts/exits as there is no marker in place today in those tracepoints.
Debugging becomes even more difficult when more than one L2 run in an L1 and
there is no way of determining which L2 from which L1 made the entries/exits.
Therefore, showing guest mode in the entry and exit tracepoints
will make debugging much easier. If an L1 runs multiple L2s, though we can
not identify the specific L2 from the entry and exit tracepoints, we still
will be able to determine whether it was L1 or an L2 that made the
entries and the exits. With this patch KVM entry and exit tracepoints will
show "guest_mode = 0" if it is a guest and "guest_mode = 1" if it is a
nested guest.

Signed-off-by: Krish Sdhukhan <krish.sadhukhan@oracle.com>
---
 arch/x86/kvm/trace.h | 16 +++++++++++-----
 1 file changed, 11 insertions(+), 5 deletions(-)

diff --git a/arch/x86/kvm/trace.h b/arch/x86/kvm/trace.h
index b484141ea15b..44dba26c6be2 100644
--- a/arch/x86/kvm/trace.h
+++ b/arch/x86/kvm/trace.h
@@ -21,14 +21,17 @@ TRACE_EVENT(kvm_entry,
 	TP_STRUCT__entry(
 		__field(	unsigned int,	vcpu_id		)
 		__field(	unsigned long,	rip		)
+		__field(        bool,           guest_mode      )
 	),
 
 	TP_fast_assign(
 		__entry->vcpu_id        = vcpu->vcpu_id;
 		__entry->rip		= kvm_rip_read(vcpu);
+		__entry->guest_mode     = is_guest_mode(vcpu);
 	),
 
-	TP_printk("vcpu %u, rip 0x%lx", __entry->vcpu_id, __entry->rip)
+	TP_printk("vcpu %u, rip 0x%lx, guest_mode %d", __entry->vcpu_id,
+		  __entry->rip, __entry->guest_mode)
 );
 
 /*
@@ -285,6 +288,7 @@ TRACE_EVENT(name,							     \
 		__field(	u32,	        intr_info	)	     \
 		__field(	u32,	        error_code	)	     \
 		__field(	unsigned int,	vcpu_id         )	     \
+		__field(        bool,           guest_mode      )            \
 	),								     \
 									     \
 	TP_fast_assign(							     \
@@ -295,15 +299,17 @@ TRACE_EVENT(name,							     \
 		static_call(kvm_x86_get_exit_info)(vcpu, &__entry->info1,    \
 					  &__entry->info2,		     \
 					  &__entry->intr_info,		     \
-					  &__entry->error_code);	     \
+					  &__entry->error_code);     	     \
+		__entry->guest_mode      = is_guest_mode(vcpu);		     \
 	),								     \
 									     \
 	TP_printk("vcpu %u reason %s%s%s rip 0x%lx info1 0x%016llx "	     \
-		  "info2 0x%016llx intr_info 0x%08x error_code 0x%08x",	     \
-		  __entry->vcpu_id,					     \
+		  "info2 0x%016llx intr_info 0x%08x error_code 0x%08x "	     \
+		  "guest_mode = %d", __entry->vcpu_id,          	     \
 		  kvm_print_exit_reason(__entry->exit_reason, __entry->isa), \
 		  __entry->guest_rip, __entry->info1, __entry->info2,	     \
-		  __entry->intr_info, __entry->error_code)		     \
+		  __entry->intr_info, __entry->error_code,                   \
+		  __entry->guest_mode)               			     \
 )
 
 /*
-- 
2.27.0


  reply	other threads:[~2021-06-21 21:34 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-06-21 20:43 [PATCH] KVM: nVMX: nSVM: Show guest mode in kvm_{entry,exit} tracepoints Krish Sadhukhan
2021-06-21 20:43 ` Krish Sadhukhan [this message]
2021-07-30 19:37   ` Sean Christopherson
2021-08-02 14:18   ` Paolo Bonzini
2021-08-02 16:34     ` Sean Christopherson
2021-08-02 16:39       ` Paolo Bonzini
2021-08-02 22:21         ` Krish Sadhukhan
2021-08-02 23:20           ` Jim Mattson
2021-08-03  0:03             ` Sean Christopherson

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210621204345.124480-2-krish.sadhukhan@oracle.com \
    --to=krish.sadhukhan@oracle.com \
    --cc=jmattson@google.com \
    --cc=joro@8bytes.org \
    --cc=kvm@vger.kernel.org \
    --cc=pbonzini@redhat.com \
    --cc=seanjc@google.com \
    --cc=vkuznets@redhat.com \
    --cc=wanpengli@tencent.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.