Skip to contentSkip to conversation

KVM: Trace exception injection

PATCH In review Avi Kivity 2 participants 5 messages Mar 11, 2010

Subsystems (3)
lore
Share & tools
lore

Avi Kivity

author
#0 lore raw

PATCH 1/1 KVM: Trace exception injection

Often an exception can help point out where things start to go wrong.

---
 arch/x86/kvm/trace.h |   32 ++++++++++++++++++++++++++++++++
 arch/x86/kvm/x86.c   |    3 +++
 2 files changed, 35 insertions(+), 0 deletions(-)
arch/x86/kvm/trace.h +32 -0
index d10b359..32c912c 100644
@@ -219,6 +219,38 @@ TRACE_EVENT(kvm_inj_virq,
 	TP_printk("irq %u", __entry->irq)
 );
 
+#define EXS(x) { x##_VECTOR, "#" #x }
+
+#define kvm_trace_sym_exc						\
+	EXS(DE), EXS(DB), EXS(BP), EXS(OF), EXS(BR), EXS(UD), EXS(NM),	\
+	EXS(DF), EXS(TS), EXS(NP), EXS(SS), EXS(GP), EXS(PF),		\
+	EXS(MF), EXS(MC)
+
+/*
+ * Tracepoint for kvm interrupt injection:
+ */
+TRACE_EVENT(kvm_inj_exception,
+	TP_PROTO(unsigned exception, bool has_error, unsigned error_code),
+	TP_ARGS(exception, has_error, error_code),
+
+	TP_STRUCT__entry(
+		__field(	u8,	exception	)
+		__field(	u8,	has_error	)
+		__field(	u32,	error_code	)
+	),
+
+	TP_fast_assign(
+		__entry->exception	= exception;
+		__entry->has_error	= has_error;
+		__entry->error_code	= error_code;
+	),
+
+	TP_printk("%s (0x%x)",
+		  __print_symbolic(__entry->exception, kvm_trace_sym_exc),
+		  /* FIXME: don't print error_code if not present */
+		  __entry->has_error ? __entry->error_code : 0)
+);
+
 /*
  * Tracepoint for page fault.
  */
arch/x86/kvm/x86.c +3 -0
index 66609f6..bcf52d1 100644
@@ -4231,6 +4231,9 @@ static void inject_pending_event(struct kvm_vcpu *vcpu)
 {
 	/* try to reinject previous events if any */
 	if (vcpu->arch.exception.pending) {
+		trace_kvm_inj_exception(vcpu->arch.exception.nr,
+					vcpu->arch.exception.has_error_code,
+					vcpu->arch.exception.error_code);
 		kvm_x86_ops->queue_exception(vcpu, vcpu->arch.exception.nr,
 					  vcpu->arch.exception.has_error_code,
 					  vcpu->arch.exception.error_code);
Signature · 1 line
1.7.0.2
#1 lore raw
Quoted 2 lines · Avi Kivity

Often an exception can help point out where things start to go wrong.

Adding guest rip where exception happened will be useful too.

Quoted 70 lines
---
 arch/x86/kvm/trace.h |   32 ++++++++++++++++++++++++++++++++
 arch/x86/kvm/x86.c   |    3 +++
 2 files changed, 35 insertions(+), 0 deletions(-)
arch/x86/kvm/trace.h +32 -0
index d10b359..32c912c 100644
@@ -219,6 +219,38 @@ TRACE_EVENT(kvm_inj_virq,
 	TP_printk("irq %u", __entry->irq)
 );
 
+#define EXS(x) { x##_VECTOR, "#" #x }
+
+#define kvm_trace_sym_exc						\
+	EXS(DE), EXS(DB), EXS(BP), EXS(OF), EXS(BR), EXS(UD), EXS(NM),	\
+	EXS(DF), EXS(TS), EXS(NP), EXS(SS), EXS(GP), EXS(PF),		\
+	EXS(MF), EXS(MC)
+
+/*
+ * Tracepoint for kvm interrupt injection:
+ */
+TRACE_EVENT(kvm_inj_exception,
+	TP_PROTO(unsigned exception, bool has_error, unsigned error_code),
+	TP_ARGS(exception, has_error, error_code),
+
+	TP_STRUCT__entry(
+		__field(	u8,	exception	)
+		__field(	u8,	has_error	)
+		__field(	u32,	error_code	)
+	),
+
+	TP_fast_assign(
+		__entry->exception	= exception;
+		__entry->has_error	= has_error;
+		__entry->error_code	= error_code;
+	),
+
+	TP_printk("%s (0x%x)",
+		  __print_symbolic(__entry->exception, kvm_trace_sym_exc),
+		  /* FIXME: don't print error_code if not present */
+		  __entry->has_error ? __entry->error_code : 0)
+);
+
 /*
  * Tracepoint for page fault.
  */
arch/x86/kvm/x86.c +3 -0
index 66609f6..bcf52d1 100644
@@ -4231,6 +4231,9 @@ static void inject_pending_event(struct kvm_vcpu *vcpu)
 {
 	/* try to reinject previous events if any */
 	if (vcpu->arch.exception.pending) {
+		trace_kvm_inj_exception(vcpu->arch.exception.nr,
+					vcpu->arch.exception.has_error_code,
+					vcpu->arch.exception.error_code);
 		kvm_x86_ops->queue_exception(vcpu, vcpu->arch.exception.nr,
 					  vcpu->arch.exception.has_error_code,
 					  vcpu->arch.exception.error_code);
Signature · 6 lines
1.7.0.2

--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html

--
Gleb.

author
#2 lore raw
Quoted 7 lines · Gleb Natapov
Quoted 3 lines · Avi Kivity

Often an exception can help point out where things start to go wrong.

Adding guest rip where exception happened will be useful too.

You get that from the previous kvm_exit trace.

Signature · 1 line
error compiling committee.c: too many arguments to function
#3 lore raw
Quoted 8 lines · Avi Kivity
Quoted 4 lines · Gleb Natapov
Quoted 2 lines · Avi Kivity

Often an exception can help point out where things start to go wrong.

Adding guest rip where exception happened will be useful too.

You get that from the previous kvm_exit trace.

Not in a case of emulation ;)

--
Gleb.

author
#4 lore raw
Quoted 9 lines · Gleb Natapov
Quoted 7 lines · Avi Kivity
Quoted 5 lines · Gleb Natapov
Quoted 3 lines · Avi Kivity

Often an exception can help point out where things start to go wrong.

Quoted 7 lines
Quoted 5 lines
Quoted 2 lines

Adding guest rip where exception happened will be useful too.

You get that from the previous kvm_exit trace.

Not in a case of emulation ;)

Then we need an emulator trace. I have it in a branch somewhere, will reactivate it after your stuff goes in.

Signature · 1 line
error compiling committee.c: too many arguments to function