All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/8] MIPS: KVM: Debug & trace event improvements
@ 2016-06-14  8:40 James Hogan
  2016-06-14  8:40 ` [PATCH 1/8] MIPS: KVM: Generalise fpu_inuse for other state James Hogan
                   ` (7 more replies)
  0 siblings, 8 replies; 19+ messages in thread
From: James Hogan @ 2016-06-14  8:40 UTC (permalink / raw)
  To: Paolo Bonzini
  Cc: James Hogan, Radim Krčmář,
	Ralf Baechle, Steven Rostedt, Ingo Molnar, linux-mips, kvm

These patches improve debugging and trace events in MIPS KVM.

They are are based on my previous two MIPS KVM patchsets:

[PATCH 0/4] MIPS: KVM: Module + non dynamic translating fixes
[PATCH 00/18] MIPS: KVM: Miscellaneous clean-ups

Patch 1 is just a rename (in preparation for later VZ support), and is
included so that patch 2 doesn't have inconsistent naming or need
changing again later.

Patches 2-6 add and clean up KVM trace events:
- kvm_exit trace event cleaned up
- Add kvm_aux, kvm_asid_change, kvm_enter, kvm_reenter, kvm_out,
  kvm_hwr trace events.

Finally Patches 7-8 make a few minor tweaks for debugging purposes.

James Hogan (8):
  MIPS: KVM: Generalise fpu_inuse for other state
  MIPS: KVM: Add kvm_aux trace event
  MIPS: KVM: Clean up kvm_exit trace event
  MIPS: KVM: Add kvm_asid_change trace event
  MIPS: KVM: Add guest mode switch trace events
  MIPS: KVM: Trace guest register access emulation
  MIPS: KVM: Dump guest tlbs if kvm_get_inst() fails
  MIPS: KVM: Print unknown load/store encodings

 arch/mips/include/asm/kvm_host.h |  30 +----
 arch/mips/kvm/emulate.c          |  56 +++++----
 arch/mips/kvm/mips.c             |  70 +++++------
 arch/mips/kvm/mmu.c              |   1 +
 arch/mips/kvm/stats.c            |  21 ----
 arch/mips/kvm/trace.h            | 248 ++++++++++++++++++++++++++++++++++++++-
 6 files changed, 318 insertions(+), 108 deletions(-)

Cc: Paolo Bonzini <pbonzini@redhat.com>
Cc: Radim Krčmář <rkrcmar@redhat.com>
Cc: Ralf Baechle <ralf@linux-mips.org>
Cc: Steven Rostedt <rostedt@goodmis.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: linux-mips@linux-mips.org
Cc: kvm@vger.kernel.org
-- 
2.4.10

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

* [PATCH 1/8] MIPS: KVM: Generalise fpu_inuse for other state
  2016-06-14  8:40 [PATCH 0/8] MIPS: KVM: Debug & trace event improvements James Hogan
@ 2016-06-14  8:40 ` James Hogan
  2016-06-14  8:40 ` [PATCH 2/8] MIPS: KVM: Add kvm_aux trace event James Hogan
                   ` (6 subsequent siblings)
  7 siblings, 0 replies; 19+ messages in thread
From: James Hogan @ 2016-06-14  8:40 UTC (permalink / raw)
  To: Paolo Bonzini
  Cc: James Hogan, Ralf Baechle, Radim Krčmář, linux-mips, kvm

Rename fpu_inuse and the related definitions to aux_inuse so it can be
used for lazy context management of other auxiliary processor state too,
such as VZ guest timer, watchpoints and performance counters.

Signed-off-by: James Hogan <james.hogan@imgtec.com>
Cc: Ralf Baechle <ralf@linux-mips.org>
Cc: Paolo Bonzini <pbonzini@redhat.com>
Cc: Radim Krčmář <rkrcmar@redhat.com>
Cc: linux-mips@linux-mips.org
Cc: kvm@vger.kernel.org
---
 arch/mips/include/asm/kvm_host.h |  8 ++++----
 arch/mips/kvm/emulate.c          |  8 ++++----
 arch/mips/kvm/mips.c             | 38 +++++++++++++++++++-------------------
 3 files changed, 27 insertions(+), 27 deletions(-)

diff --git a/arch/mips/include/asm/kvm_host.h b/arch/mips/include/asm/kvm_host.h
index d0432b5f2343..e6273850bab6 100644
--- a/arch/mips/include/asm/kvm_host.h
+++ b/arch/mips/include/asm/kvm_host.h
@@ -323,8 +323,8 @@ struct kvm_mips_tlb {
 	long tlb_lo[2];
 };
 
-#define KVM_MIPS_FPU_FPU	0x1
-#define KVM_MIPS_FPU_MSA	0x2
+#define KVM_MIPS_AUX_FPU	0x1
+#define KVM_MIPS_AUX_MSA	0x2
 
 #define KVM_MIPS_GUEST_TLB_SIZE	64
 struct kvm_vcpu_arch {
@@ -346,8 +346,8 @@ struct kvm_vcpu_arch {
 
 	/* FPU State */
 	struct mips_fpu_struct fpu;
-	/* Which FPU state is loaded (KVM_MIPS_FPU_*) */
-	unsigned int fpu_inuse;
+	/* Which auxiliary state is loaded (KVM_MIPS_AUX_*) */
+	unsigned int aux_inuse;
 
 	/* COP0 State */
 	struct mips_coproc *cop0;
diff --git a/arch/mips/kvm/emulate.c b/arch/mips/kvm/emulate.c
index 5b89c0803405..8647bd97b934 100644
--- a/arch/mips/kvm/emulate.c
+++ b/arch/mips/kvm/emulate.c
@@ -1154,7 +1154,7 @@ enum emulation_result kvm_mips_emulate_CP0(u32 inst, u32 *opc, u32 cause,
 				 * it first.
 				 */
 				if (change & ST0_CU1 && !(val & ST0_FR) &&
-				    vcpu->arch.fpu_inuse & KVM_MIPS_FPU_MSA)
+				    vcpu->arch.aux_inuse & KVM_MIPS_AUX_MSA)
 					kvm_lose_fpu(vcpu);
 
 				/*
@@ -1165,7 +1165,7 @@ enum emulation_result kvm_mips_emulate_CP0(u32 inst, u32 *opc, u32 cause,
 				 * the near future.
 				 */
 				if (change & ST0_CU1 &&
-				    vcpu->arch.fpu_inuse & KVM_MIPS_FPU_FPU)
+				    vcpu->arch.aux_inuse & KVM_MIPS_AUX_FPU)
 					change_c0_status(ST0_CU1, val);
 
 				preempt_enable();
@@ -1200,7 +1200,7 @@ enum emulation_result kvm_mips_emulate_CP0(u32 inst, u32 *opc, u32 cause,
 				 * context is already loaded.
 				 */
 				if (change & MIPS_CONF5_FRE &&
-				    vcpu->arch.fpu_inuse & KVM_MIPS_FPU_FPU)
+				    vcpu->arch.aux_inuse & KVM_MIPS_AUX_FPU)
 					change_c0_config5(MIPS_CONF5_FRE, val);
 
 				/*
@@ -1210,7 +1210,7 @@ enum emulation_result kvm_mips_emulate_CP0(u32 inst, u32 *opc, u32 cause,
 				 * quickly enabled again in the near future.
 				 */
 				if (change & MIPS_CONF5_MSAEN &&
-				    vcpu->arch.fpu_inuse & KVM_MIPS_FPU_MSA)
+				    vcpu->arch.aux_inuse & KVM_MIPS_AUX_MSA)
 					change_c0_config5(MIPS_CONF5_MSAEN,
 							  val);
 
diff --git a/arch/mips/kvm/mips.c b/arch/mips/kvm/mips.c
index 6e753761b5d6..9093262ff3ce 100644
--- a/arch/mips/kvm/mips.c
+++ b/arch/mips/kvm/mips.c
@@ -1447,7 +1447,7 @@ void kvm_own_fpu(struct kvm_vcpu *vcpu)
 	 * not to clobber the status register directly via the commpage.
 	 */
 	if (cpu_has_msa && sr & ST0_CU1 && !(sr & ST0_FR) &&
-	    vcpu->arch.fpu_inuse & KVM_MIPS_FPU_MSA)
+	    vcpu->arch.aux_inuse & KVM_MIPS_AUX_MSA)
 		kvm_lose_fpu(vcpu);
 
 	/*
@@ -1462,9 +1462,9 @@ void kvm_own_fpu(struct kvm_vcpu *vcpu)
 	enable_fpu_hazard();
 
 	/* If guest FPU state not active, restore it now */
-	if (!(vcpu->arch.fpu_inuse & KVM_MIPS_FPU_FPU)) {
+	if (!(vcpu->arch.aux_inuse & KVM_MIPS_AUX_FPU)) {
 		__kvm_restore_fpu(&vcpu->arch);
-		vcpu->arch.fpu_inuse |= KVM_MIPS_FPU_FPU;
+		vcpu->arch.aux_inuse |= KVM_MIPS_AUX_FPU;
 	}
 
 	preempt_enable();
@@ -1491,8 +1491,8 @@ void kvm_own_msa(struct kvm_vcpu *vcpu)
 		 * interacts with MSA state, so play it safe and save it first.
 		 */
 		if (!(sr & ST0_FR) &&
-		    (vcpu->arch.fpu_inuse & (KVM_MIPS_FPU_FPU |
-				KVM_MIPS_FPU_MSA)) == KVM_MIPS_FPU_FPU)
+		    (vcpu->arch.aux_inuse & (KVM_MIPS_AUX_FPU |
+				KVM_MIPS_AUX_MSA)) == KVM_MIPS_AUX_FPU)
 			kvm_lose_fpu(vcpu);
 
 		change_c0_status(ST0_CU1 | ST0_FR, sr);
@@ -1506,20 +1506,20 @@ void kvm_own_msa(struct kvm_vcpu *vcpu)
 	set_c0_config5(MIPS_CONF5_MSAEN);
 	enable_fpu_hazard();
 
-	switch (vcpu->arch.fpu_inuse & (KVM_MIPS_FPU_FPU | KVM_MIPS_FPU_MSA)) {
-	case KVM_MIPS_FPU_FPU:
+	switch (vcpu->arch.aux_inuse & (KVM_MIPS_AUX_FPU | KVM_MIPS_AUX_MSA)) {
+	case KVM_MIPS_AUX_FPU:
 		/*
 		 * Guest FPU state already loaded, only restore upper MSA state
 		 */
 		__kvm_restore_msa_upper(&vcpu->arch);
-		vcpu->arch.fpu_inuse |= KVM_MIPS_FPU_MSA;
+		vcpu->arch.aux_inuse |= KVM_MIPS_AUX_MSA;
 		break;
 	case 0:
 		/* Neither FPU or MSA already active, restore full MSA state */
 		__kvm_restore_msa(&vcpu->arch);
-		vcpu->arch.fpu_inuse |= KVM_MIPS_FPU_MSA;
+		vcpu->arch.aux_inuse |= KVM_MIPS_AUX_MSA;
 		if (kvm_mips_guest_has_fpu(&vcpu->arch))
-			vcpu->arch.fpu_inuse |= KVM_MIPS_FPU_FPU;
+			vcpu->arch.aux_inuse |= KVM_MIPS_AUX_FPU;
 		break;
 	default:
 		break;
@@ -1533,13 +1533,13 @@ void kvm_own_msa(struct kvm_vcpu *vcpu)
 void kvm_drop_fpu(struct kvm_vcpu *vcpu)
 {
 	preempt_disable();
-	if (cpu_has_msa && vcpu->arch.fpu_inuse & KVM_MIPS_FPU_MSA) {
+	if (cpu_has_msa && vcpu->arch.aux_inuse & KVM_MIPS_AUX_MSA) {
 		disable_msa();
-		vcpu->arch.fpu_inuse &= ~KVM_MIPS_FPU_MSA;
+		vcpu->arch.aux_inuse &= ~KVM_MIPS_AUX_MSA;
 	}
-	if (vcpu->arch.fpu_inuse & KVM_MIPS_FPU_FPU) {
+	if (vcpu->arch.aux_inuse & KVM_MIPS_AUX_FPU) {
 		clear_c0_status(ST0_CU1 | ST0_FR);
-		vcpu->arch.fpu_inuse &= ~KVM_MIPS_FPU_FPU;
+		vcpu->arch.aux_inuse &= ~KVM_MIPS_AUX_FPU;
 	}
 	preempt_enable();
 }
@@ -1555,7 +1555,7 @@ void kvm_lose_fpu(struct kvm_vcpu *vcpu)
 	 */
 
 	preempt_disable();
-	if (cpu_has_msa && vcpu->arch.fpu_inuse & KVM_MIPS_FPU_MSA) {
+	if (cpu_has_msa && vcpu->arch.aux_inuse & KVM_MIPS_AUX_MSA) {
 		set_c0_config5(MIPS_CONF5_MSAEN);
 		enable_fpu_hazard();
 
@@ -1563,17 +1563,17 @@ void kvm_lose_fpu(struct kvm_vcpu *vcpu)
 
 		/* Disable MSA & FPU */
 		disable_msa();
-		if (vcpu->arch.fpu_inuse & KVM_MIPS_FPU_FPU) {
+		if (vcpu->arch.aux_inuse & KVM_MIPS_AUX_FPU) {
 			clear_c0_status(ST0_CU1 | ST0_FR);
 			disable_fpu_hazard();
 		}
-		vcpu->arch.fpu_inuse &= ~(KVM_MIPS_FPU_FPU | KVM_MIPS_FPU_MSA);
-	} else if (vcpu->arch.fpu_inuse & KVM_MIPS_FPU_FPU) {
+		vcpu->arch.aux_inuse &= ~(KVM_MIPS_AUX_FPU | KVM_MIPS_AUX_MSA);
+	} else if (vcpu->arch.aux_inuse & KVM_MIPS_AUX_FPU) {
 		set_c0_status(ST0_CU1);
 		enable_fpu_hazard();
 
 		__kvm_save_fpu(&vcpu->arch);
-		vcpu->arch.fpu_inuse &= ~KVM_MIPS_FPU_FPU;
+		vcpu->arch.aux_inuse &= ~KVM_MIPS_AUX_FPU;
 
 		/* Disable FPU */
 		clear_c0_status(ST0_CU1 | ST0_FR);
-- 
2.4.10

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

* [PATCH 2/8] MIPS: KVM: Add kvm_aux trace event
  2016-06-14  8:40 [PATCH 0/8] MIPS: KVM: Debug & trace event improvements James Hogan
  2016-06-14  8:40 ` [PATCH 1/8] MIPS: KVM: Generalise fpu_inuse for other state James Hogan
@ 2016-06-14  8:40 ` James Hogan
  2016-06-14  8:55   ` James Hogan
  2016-06-14  8:40 ` [PATCH 3/8] MIPS: KVM: Clean up kvm_exit " James Hogan
                   ` (5 subsequent siblings)
  7 siblings, 1 reply; 19+ messages in thread
From: James Hogan @ 2016-06-14  8:40 UTC (permalink / raw)
  To: Paolo Bonzini
  Cc: James Hogan, Radim Krčmář,
	Ralf Baechle, Steven Rostedt, Ingo Molnar, linux-mips, kvm

Add a MIPS specific trace event for auxiliary context operations
(notably FPU and MSA). Unfortunately the generic kvm_fpu trace event
isn't flexible enough to handle the range of interesting things that can
happen with FPU and MSA context.

The type of state being operated on is traced:
- FPU: Just the FPU registers.
- MSA: Just the upper half of the MSA vector registers (low half already
       loaded with FPU state).
- FPU & MSA: Full MSA vector state (includes FPU state).

As is the type of operation:
- Restore: State was enabled and restored.
- Save: State was saved and disabled.
- Enable: State was enabled (already loaded).
- Disable: State was disabled (kept loaded).
- Discard: State was discarded and disabled.

Signed-off-by: James Hogan <james.hogan@imgtec.com>
Cc: Paolo Bonzini <pbonzini@redhat.com>
Cc: Radim Krčmář <rkrcmar@redhat.com>
Cc: Ralf Baechle <ralf@linux-mips.org>
Cc: Steven Rostedt <rostedt@goodmis.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: linux-mips@linux-mips.org
Cc: kvm@vger.kernel.org
---
 arch/mips/kvm/mips.c  | 11 +++++++++++
 arch/mips/kvm/trace.h | 46 ++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 57 insertions(+)

diff --git a/arch/mips/kvm/mips.c b/arch/mips/kvm/mips.c
index 9093262ff3ce..c0e8f8640f2b 100644
--- a/arch/mips/kvm/mips.c
+++ b/arch/mips/kvm/mips.c
@@ -1465,6 +1465,9 @@ void kvm_own_fpu(struct kvm_vcpu *vcpu)
 	if (!(vcpu->arch.aux_inuse & KVM_MIPS_AUX_FPU)) {
 		__kvm_restore_fpu(&vcpu->arch);
 		vcpu->arch.aux_inuse |= KVM_MIPS_AUX_FPU;
+		trace_kvm_aux(vcpu, KVM_TRACE_AUX_RESTORE, KVM_TRACE_AUX_FPU);
+	} else {
+		trace_kvm_aux(vcpu, KVM_TRACE_AUX_ENABLE, KVM_TRACE_AUX_FPU);
 	}
 
 	preempt_enable();
@@ -1513,6 +1516,7 @@ void kvm_own_msa(struct kvm_vcpu *vcpu)
 		 */
 		__kvm_restore_msa_upper(&vcpu->arch);
 		vcpu->arch.aux_inuse |= KVM_MIPS_AUX_MSA;
+		trace_kvm_aux(vcpu, KVM_TRACE_AUX_RESTORE, KVM_TRACE_AUX_MSA);
 		break;
 	case 0:
 		/* Neither FPU or MSA already active, restore full MSA state */
@@ -1520,8 +1524,11 @@ void kvm_own_msa(struct kvm_vcpu *vcpu)
 		vcpu->arch.aux_inuse |= KVM_MIPS_AUX_MSA;
 		if (kvm_mips_guest_has_fpu(&vcpu->arch))
 			vcpu->arch.aux_inuse |= KVM_MIPS_AUX_FPU;
+		trace_kvm_aux(vcpu, KVM_TRACE_AUX_RESTORE,
+			      KVM_TRACE_AUX_FPU_MSA);
 		break;
 	default:
+		trace_kvm_aux(vcpu, KVM_TRACE_AUX_ENABLE, KVM_TRACE_AUX_MSA);
 		break;
 	}
 
@@ -1535,10 +1542,12 @@ void kvm_drop_fpu(struct kvm_vcpu *vcpu)
 	preempt_disable();
 	if (cpu_has_msa && vcpu->arch.aux_inuse & KVM_MIPS_AUX_MSA) {
 		disable_msa();
+		trace_kvm_aux(vcpu, KVM_TRACE_AUX_DISCARD, KVM_TRACE_AUX_MSA);
 		vcpu->arch.aux_inuse &= ~KVM_MIPS_AUX_MSA;
 	}
 	if (vcpu->arch.aux_inuse & KVM_MIPS_AUX_FPU) {
 		clear_c0_status(ST0_CU1 | ST0_FR);
+		trace_kvm_aux(vcpu, KVM_TRACE_AUX_DISCARD, KVM_TRACE_AUX_FPU);
 		vcpu->arch.aux_inuse &= ~KVM_MIPS_AUX_FPU;
 	}
 	preempt_enable();
@@ -1560,6 +1569,7 @@ void kvm_lose_fpu(struct kvm_vcpu *vcpu)
 		enable_fpu_hazard();
 
 		__kvm_save_msa(&vcpu->arch);
+		trace_kvm_aux(vcpu, KVM_TRACE_AUX_SAVE, KVM_TRACE_AUX_FPU_MSA);
 
 		/* Disable MSA & FPU */
 		disable_msa();
@@ -1574,6 +1584,7 @@ void kvm_lose_fpu(struct kvm_vcpu *vcpu)
 
 		__kvm_save_fpu(&vcpu->arch);
 		vcpu->arch.aux_inuse &= ~KVM_MIPS_AUX_FPU;
+		trace_kvm_aux(vcpu, KVM_TRACE_AUX_SAVE, KVM_TRACE_AUX_FPU);
 
 		/* Disable FPU */
 		clear_c0_status(ST0_CU1 | ST0_FR);
diff --git a/arch/mips/kvm/trace.h b/arch/mips/kvm/trace.h
index bd6437f67dc0..32ac7cc82e13 100644
--- a/arch/mips/kvm/trace.h
+++ b/arch/mips/kvm/trace.h
@@ -38,6 +38,52 @@ TRACE_EVENT(kvm_exit,
 		      __entry->pc)
 );
 
+#define KVM_TRACE_AUX_RESTORE		0
+#define KVM_TRACE_AUX_SAVE		1
+#define KVM_TRACE_AUX_ENABLE		2
+#define KVM_TRACE_AUX_DISABLE		3
+#define KVM_TRACE_AUX_DISCARD		4
+
+#define KVM_TRACE_AUX_FPU		1
+#define KVM_TRACE_AUX_MSA		2
+#define KVM_TRACE_AUX_FPU_MSA		3
+
+#define kvm_trace_symbol_fpu_msa_op		\
+	{ KVM_TRACE_AUX_RESTORE, "restore" },	\
+	{ KVM_TRACE_AUX_SAVE,    "save" },	\
+	{ KVM_TRACE_AUX_ENABLE,  "enable" },	\
+	{ KVM_TRACE_AUX_DISABLE, "disable" },	\
+	{ KVM_TRACE_AUX_DISCARD, "discard" }
+
+#define kvm_trace_symbol_fpu_msa_state		\
+	{ KVM_TRACE_AUX_FPU,     "FPU" },	\
+	{ KVM_TRACE_AUX_MSA,     "MSA" },	\
+	{ KVM_TRACE_AUX_FPU_MSA, "FPU & MSA" }
+
+TRACE_EVENT(kvm_aux,
+	    TP_PROTO(struct kvm_vcpu *vcpu, unsigned int op,
+		     unsigned int state),
+	    TP_ARGS(vcpu, op, state),
+	    TP_STRUCT__entry(
+			__field(unsigned long, pc)
+			__field(u8, op)
+			__field(u8, state)
+	    ),
+
+	    TP_fast_assign(
+			__entry->pc = vcpu->arch.pc;
+			__entry->op = op;
+			__entry->state = state;
+	    ),
+
+	    TP_printk("%s %s PC: 0x%08lx",
+		      __print_symbolic(__entry->op,
+				       kvm_trace_symbol_fpu_msa_op),
+		      __print_symbolic(__entry->state,
+				       kvm_trace_symbol_fpu_msa_state),
+		      __entry->pc)
+);
+
 #endif /* _TRACE_KVM_H */
 
 /* This part must be outside protection */
-- 
2.4.10

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

* [PATCH 3/8] MIPS: KVM: Clean up kvm_exit trace event
  2016-06-14  8:40 [PATCH 0/8] MIPS: KVM: Debug & trace event improvements James Hogan
  2016-06-14  8:40 ` [PATCH 1/8] MIPS: KVM: Generalise fpu_inuse for other state James Hogan
  2016-06-14  8:40 ` [PATCH 2/8] MIPS: KVM: Add kvm_aux trace event James Hogan
@ 2016-06-14  8:40 ` James Hogan
  2016-06-17 14:10   ` Steven Rostedt
  2016-06-14  8:40 ` [PATCH 4/8] MIPS: KVM: Add kvm_asid_change " James Hogan
                   ` (4 subsequent siblings)
  7 siblings, 1 reply; 19+ messages in thread
From: James Hogan @ 2016-06-14  8:40 UTC (permalink / raw)
  To: Paolo Bonzini
  Cc: James Hogan, Radim Krčmář,
	Ralf Baechle, Steven Rostedt, Ingo Molnar, kvm, linux-mips

Clean up the MIPS kvm_exit trace event so that the exit reasons are
specified in a trace friendly way (via __print_symbolic), and so that
the exit reasons that derive straight from Cause.ExcCode values map
directly, allowing a single trace_kvm_exit() call to replace a bunch of
individual ones.

Signed-off-by: James Hogan <james.hogan@imgtec.com>
Cc: Paolo Bonzini <pbonzini@redhat.com>
Cc: Radim Krčmář <rkrcmar@redhat.com>
Cc: Ralf Baechle <ralf@linux-mips.org>
Cc: Steven Rostedt <rostedt@goodmis.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: kvm@vger.kernel.org
Cc: linux-mips@linux-mips.org
---
 arch/mips/include/asm/kvm_host.h | 22 --------------------
 arch/mips/kvm/emulate.c          |  4 ++--
 arch/mips/kvm/mips.c             | 17 ++--------------
 arch/mips/kvm/stats.c            | 21 -------------------
 arch/mips/kvm/trace.h            | 44 +++++++++++++++++++++++++++++++++++++---
 5 files changed, 45 insertions(+), 63 deletions(-)

diff --git a/arch/mips/include/asm/kvm_host.h b/arch/mips/include/asm/kvm_host.h
index e6273850bab6..b8cb74270746 100644
--- a/arch/mips/include/asm/kvm_host.h
+++ b/arch/mips/include/asm/kvm_host.h
@@ -125,28 +125,6 @@ struct kvm_vcpu_stat {
 	u32 halt_wakeup;
 };
 
-enum kvm_mips_exit_types {
-	WAIT_EXITS,
-	CACHE_EXITS,
-	SIGNAL_EXITS,
-	INT_EXITS,
-	COP_UNUSABLE_EXITS,
-	TLBMOD_EXITS,
-	TLBMISS_LD_EXITS,
-	TLBMISS_ST_EXITS,
-	ADDRERR_ST_EXITS,
-	ADDRERR_LD_EXITS,
-	SYSCALL_EXITS,
-	RESVD_INST_EXITS,
-	BREAK_INST_EXITS,
-	TRAP_INST_EXITS,
-	MSA_FPE_EXITS,
-	FPE_EXITS,
-	MSA_DISABLED_EXITS,
-	FLUSH_DCACHE_EXITS,
-	MAX_KVM_MIPS_EXIT_TYPES
-};
-
 struct kvm_arch_memory_slot {
 };
 
diff --git a/arch/mips/kvm/emulate.c b/arch/mips/kvm/emulate.c
index 8647bd97b934..fce08bda9ebc 100644
--- a/arch/mips/kvm/emulate.c
+++ b/arch/mips/kvm/emulate.c
@@ -775,7 +775,7 @@ enum emulation_result kvm_mips_emul_wait(struct kvm_vcpu *vcpu)
 		  vcpu->arch.pending_exceptions);
 
 	++vcpu->stat.wait_exits;
-	trace_kvm_exit(vcpu, WAIT_EXITS);
+	trace_kvm_exit(vcpu, KVM_TRACE_EXIT_WAIT);
 	if (!vcpu->arch.pending_exceptions) {
 		vcpu->arch.wait = 1;
 		kvm_vcpu_block(vcpu);
@@ -1718,7 +1718,7 @@ enum emulation_result kvm_mips_emulate_inst(u32 cause, u32 *opc,
 
 	case cache_op:
 		++vcpu->stat.cache_exits;
-		trace_kvm_exit(vcpu, CACHE_EXITS);
+		trace_kvm_exit(vcpu, KVM_TRACE_EXIT_CACHE);
 		er = kvm_mips_emulate_cache(inst, opc, cause, run, vcpu);
 		break;
 
diff --git a/arch/mips/kvm/mips.c b/arch/mips/kvm/mips.c
index c0e8f8640f2b..e9e40b9dd9be 100644
--- a/arch/mips/kvm/mips.c
+++ b/arch/mips/kvm/mips.c
@@ -1257,6 +1257,7 @@ int kvm_mips_handle_exit(struct kvm_run *run, struct kvm_vcpu *vcpu)
 
 	kvm_debug("kvm_mips_handle_exit: cause: %#x, PC: %p, kvm_run: %p, kvm_vcpu: %p\n",
 			cause, opc, run, vcpu);
+	trace_kvm_exit(vcpu, exccode);
 
 	/*
 	 * Do a privilege check, if in UM most of these exit conditions end up
@@ -1276,7 +1277,6 @@ int kvm_mips_handle_exit(struct kvm_run *run, struct kvm_vcpu *vcpu)
 		kvm_debug("[%d]EXCCODE_INT @ %p\n", vcpu->vcpu_id, opc);
 
 		++vcpu->stat.int_exits;
-		trace_kvm_exit(vcpu, INT_EXITS);
 
 		if (need_resched())
 			cond_resched();
@@ -1288,7 +1288,6 @@ int kvm_mips_handle_exit(struct kvm_run *run, struct kvm_vcpu *vcpu)
 		kvm_debug("EXCCODE_CPU: @ PC: %p\n", opc);
 
 		++vcpu->stat.cop_unusable_exits;
-		trace_kvm_exit(vcpu, COP_UNUSABLE_EXITS);
 		ret = kvm_mips_callbacks->handle_cop_unusable(vcpu);
 		/* XXXKYMA: Might need to return to user space */
 		if (run->exit_reason == KVM_EXIT_IRQ_WINDOW_OPEN)
@@ -1297,7 +1296,6 @@ int kvm_mips_handle_exit(struct kvm_run *run, struct kvm_vcpu *vcpu)
 
 	case EXCCODE_MOD:
 		++vcpu->stat.tlbmod_exits;
-		trace_kvm_exit(vcpu, TLBMOD_EXITS);
 		ret = kvm_mips_callbacks->handle_tlb_mod(vcpu);
 		break;
 
@@ -1307,7 +1305,6 @@ int kvm_mips_handle_exit(struct kvm_run *run, struct kvm_vcpu *vcpu)
 			  badvaddr);
 
 		++vcpu->stat.tlbmiss_st_exits;
-		trace_kvm_exit(vcpu, TLBMISS_ST_EXITS);
 		ret = kvm_mips_callbacks->handle_tlb_st_miss(vcpu);
 		break;
 
@@ -1316,61 +1313,51 @@ int kvm_mips_handle_exit(struct kvm_run *run, struct kvm_vcpu *vcpu)
 			  cause, opc, badvaddr);
 
 		++vcpu->stat.tlbmiss_ld_exits;
-		trace_kvm_exit(vcpu, TLBMISS_LD_EXITS);
 		ret = kvm_mips_callbacks->handle_tlb_ld_miss(vcpu);
 		break;
 
 	case EXCCODE_ADES:
 		++vcpu->stat.addrerr_st_exits;
-		trace_kvm_exit(vcpu, ADDRERR_ST_EXITS);
 		ret = kvm_mips_callbacks->handle_addr_err_st(vcpu);
 		break;
 
 	case EXCCODE_ADEL:
 		++vcpu->stat.addrerr_ld_exits;
-		trace_kvm_exit(vcpu, ADDRERR_LD_EXITS);
 		ret = kvm_mips_callbacks->handle_addr_err_ld(vcpu);
 		break;
 
 	case EXCCODE_SYS:
 		++vcpu->stat.syscall_exits;
-		trace_kvm_exit(vcpu, SYSCALL_EXITS);
 		ret = kvm_mips_callbacks->handle_syscall(vcpu);
 		break;
 
 	case EXCCODE_RI:
 		++vcpu->stat.resvd_inst_exits;
-		trace_kvm_exit(vcpu, RESVD_INST_EXITS);
 		ret = kvm_mips_callbacks->handle_res_inst(vcpu);
 		break;
 
 	case EXCCODE_BP:
 		++vcpu->stat.break_inst_exits;
-		trace_kvm_exit(vcpu, BREAK_INST_EXITS);
 		ret = kvm_mips_callbacks->handle_break(vcpu);
 		break;
 
 	case EXCCODE_TR:
 		++vcpu->stat.trap_inst_exits;
-		trace_kvm_exit(vcpu, TRAP_INST_EXITS);
 		ret = kvm_mips_callbacks->handle_trap(vcpu);
 		break;
 
 	case EXCCODE_MSAFPE:
 		++vcpu->stat.msa_fpe_exits;
-		trace_kvm_exit(vcpu, MSA_FPE_EXITS);
 		ret = kvm_mips_callbacks->handle_msa_fpe(vcpu);
 		break;
 
 	case EXCCODE_FPE:
 		++vcpu->stat.fpe_exits;
-		trace_kvm_exit(vcpu, FPE_EXITS);
 		ret = kvm_mips_callbacks->handle_fpe(vcpu);
 		break;
 
 	case EXCCODE_MSADIS:
 		++vcpu->stat.msa_disabled_exits;
-		trace_kvm_exit(vcpu, MSA_DISABLED_EXITS);
 		ret = kvm_mips_callbacks->handle_msa_disabled(vcpu);
 		break;
 
@@ -1397,7 +1384,7 @@ skip_emul:
 			run->exit_reason = KVM_EXIT_INTR;
 			ret = (-EINTR << 2) | RESUME_HOST;
 			++vcpu->stat.signal_exits;
-			trace_kvm_exit(vcpu, SIGNAL_EXITS);
+			trace_kvm_exit(vcpu, KVM_TRACE_EXIT_SIGNAL);
 		}
 	}
 
diff --git a/arch/mips/kvm/stats.c b/arch/mips/kvm/stats.c
index 888bb67070ac..53f851a61554 100644
--- a/arch/mips/kvm/stats.c
+++ b/arch/mips/kvm/stats.c
@@ -11,27 +11,6 @@
 
 #include <linux/kvm_host.h>
 
-char *kvm_mips_exit_types_str[MAX_KVM_MIPS_EXIT_TYPES] = {
-	"WAIT",
-	"CACHE",
-	"Signal",
-	"Interrupt",
-	"COP0/1 Unusable",
-	"TLB Mod",
-	"TLB Miss (LD)",
-	"TLB Miss (ST)",
-	"Address Err (ST)",
-	"Address Error (LD)",
-	"System Call",
-	"Reserved Inst",
-	"Break Inst",
-	"Trap Inst",
-	"MSA FPE",
-	"FPE",
-	"MSA Disabled",
-	"D-Cache Flushes",
-};
-
 char *kvm_cop0_str[N_MIPS_COPROC_REGS] = {
 	"Index",
 	"Random",
diff --git a/arch/mips/kvm/trace.h b/arch/mips/kvm/trace.h
index 32ac7cc82e13..9a1212e09435 100644
--- a/arch/mips/kvm/trace.h
+++ b/arch/mips/kvm/trace.h
@@ -17,8 +17,45 @@
 #define TRACE_INCLUDE_PATH .
 #define TRACE_INCLUDE_FILE trace
 
-/* Tracepoints for VM eists */
-extern char *kvm_mips_exit_types_str[MAX_KVM_MIPS_EXIT_TYPES];
+/* The first 32 exit reasons correspond to Cause.ExcCode */
+#define KVM_TRACE_EXIT_INT		 0
+#define KVM_TRACE_EXIT_TLBMOD		 1
+#define KVM_TRACE_EXIT_TLBMISS_LD	 2
+#define KVM_TRACE_EXIT_TLBMISS_ST	 3
+#define KVM_TRACE_EXIT_ADDRERR_LD	 4
+#define KVM_TRACE_EXIT_ADDRERR_ST	 5
+#define KVM_TRACE_EXIT_SYSCALL		 8
+#define KVM_TRACE_EXIT_BREAK_INST	 9
+#define KVM_TRACE_EXIT_RESVD_INST	10
+#define KVM_TRACE_EXIT_COP_UNUSABLE	11
+#define KVM_TRACE_EXIT_TRAP_INST	13
+#define KVM_TRACE_EXIT_MSA_FPE		14
+#define KVM_TRACE_EXIT_FPE		15
+#define KVM_TRACE_EXIT_MSA_DISABLED	21
+/* Further exit reasons */
+#define KVM_TRACE_EXIT_WAIT		32
+#define KVM_TRACE_EXIT_CACHE		33
+#define KVM_TRACE_EXIT_SIGNAL		34
+
+/* Tracepoints for VM exits */
+#define kvm_trace_symbol_exit_types				\
+	{ KVM_TRACE_EXIT_INT,		"Interrupt" },		\
+	{ KVM_TRACE_EXIT_TLBMOD,	"TLB Mod" },		\
+	{ KVM_TRACE_EXIT_TLBMISS_LD,	"TLB Miss (LD)" },	\
+	{ KVM_TRACE_EXIT_TLBMISS_ST,	"TLB Miss (ST)" },	\
+	{ KVM_TRACE_EXIT_ADDRERR_LD,	"Address Error (LD)" },	\
+	{ KVM_TRACE_EXIT_ADDRERR_ST,	"Address Err (ST)" },	\
+	{ KVM_TRACE_EXIT_SYSCALL,	"System Call" },	\
+	{ KVM_TRACE_EXIT_BREAK_INST,	"Break Inst" },		\
+	{ KVM_TRACE_EXIT_RESVD_INST,	"Reserved Inst" },	\
+	{ KVM_TRACE_EXIT_COP_UNUSABLE,	"COP0/1 Unusable" },	\
+	{ KVM_TRACE_EXIT_TRAP_INST,	"Trap Inst" },		\
+	{ KVM_TRACE_EXIT_MSA_FPE,	"MSA FPE" },		\
+	{ KVM_TRACE_EXIT_FPE,		"FPE" },		\
+	{ KVM_TRACE_EXIT_MSA_DISABLED,	"MSA Disabled" },	\
+	{ KVM_TRACE_EXIT_WAIT,		"WAIT" },		\
+	{ KVM_TRACE_EXIT_CACHE,		"CACHE" },		\
+	{ KVM_TRACE_EXIT_SIGNAL,	"Signal" }
 
 TRACE_EVENT(kvm_exit,
 	    TP_PROTO(struct kvm_vcpu *vcpu, unsigned int reason),
@@ -34,7 +71,8 @@ TRACE_EVENT(kvm_exit,
 	    ),
 
 	    TP_printk("[%s]PC: 0x%08lx",
-		      kvm_mips_exit_types_str[__entry->reason],
+		      __print_symbolic(__entry->reason,
+				       kvm_trace_symbol_exit_types),
 		      __entry->pc)
 );
 
-- 
2.4.10

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

* [PATCH 4/8] MIPS: KVM: Add kvm_asid_change trace event
  2016-06-14  8:40 [PATCH 0/8] MIPS: KVM: Debug & trace event improvements James Hogan
                   ` (2 preceding siblings ...)
  2016-06-14  8:40 ` [PATCH 3/8] MIPS: KVM: Clean up kvm_exit " James Hogan
@ 2016-06-14  8:40 ` James Hogan
  2016-06-14  8:40 ` [PATCH 5/8] MIPS: KVM: Add guest mode switch trace events James Hogan
                   ` (3 subsequent siblings)
  7 siblings, 0 replies; 19+ messages in thread
From: James Hogan @ 2016-06-14  8:40 UTC (permalink / raw)
  To: Paolo Bonzini
  Cc: James Hogan, Radim Krčmář,
	Ralf Baechle, Steven Rostedt, Ingo Molnar, kvm, linux-mips

Add a trace event for guest ASID changes, replacing the existing
kvm_debug call.

Signed-off-by: James Hogan <james.hogan@imgtec.com>
Cc: Paolo Bonzini <pbonzini@redhat.com>
Cc: Radim Krčmář <rkrcmar@redhat.com>
Cc: Ralf Baechle <ralf@linux-mips.org>
Cc: Steven Rostedt <rostedt@goodmis.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: kvm@vger.kernel.org
Cc: linux-mips@linux-mips.org
---
 arch/mips/kvm/emulate.c |  7 +++----
 arch/mips/kvm/trace.h   | 22 ++++++++++++++++++++++
 2 files changed, 25 insertions(+), 4 deletions(-)

diff --git a/arch/mips/kvm/emulate.c b/arch/mips/kvm/emulate.c
index fce08bda9ebc..ee0e61d2b6fb 100644
--- a/arch/mips/kvm/emulate.c
+++ b/arch/mips/kvm/emulate.c
@@ -1082,11 +1082,10 @@ enum emulation_result kvm_mips_emulate_CP0(u32 inst, u32 *opc, u32 cause,
 				if ((KSEGX(vcpu->arch.gprs[rt]) != CKSEG0) &&
 				    ((kvm_read_c0_guest_entryhi(cop0) &
 				      KVM_ENTRYHI_ASID) != nasid)) {
-					kvm_debug("MTCz, change ASID from %#lx to %#lx\n",
+					trace_kvm_asid_change(vcpu,
 						kvm_read_c0_guest_entryhi(cop0)
-						& KVM_ENTRYHI_ASID,
-						vcpu->arch.gprs[rt]
-						& KVM_ENTRYHI_ASID);
+							& KVM_ENTRYHI_ASID,
+						nasid);
 
 					/* Blow away the shadow host TLBs */
 					kvm_mips_flush_host_tlb(1);
diff --git a/arch/mips/kvm/trace.h b/arch/mips/kvm/trace.h
index 9a1212e09435..1d67d9e0f340 100644
--- a/arch/mips/kvm/trace.h
+++ b/arch/mips/kvm/trace.h
@@ -122,6 +122,28 @@ TRACE_EVENT(kvm_aux,
 		      __entry->pc)
 );
 
+TRACE_EVENT(kvm_asid_change,
+	    TP_PROTO(struct kvm_vcpu *vcpu, unsigned int old_asid,
+		     unsigned int new_asid),
+	    TP_ARGS(vcpu, old_asid, new_asid),
+	    TP_STRUCT__entry(
+			__field(unsigned long, pc)
+			__field(u8, old_asid)
+			__field(u8, new_asid)
+	    ),
+
+	    TP_fast_assign(
+			__entry->pc = vcpu->arch.pc;
+			__entry->old_asid = old_asid;
+			__entry->new_asid = new_asid;
+	    ),
+
+	    TP_printk("PC: 0x%08lx old: 0x%02x new: 0x%02x",
+		      __entry->pc,
+		      __entry->old_asid,
+		      __entry->new_asid)
+);
+
 #endif /* _TRACE_KVM_H */
 
 /* This part must be outside protection */
-- 
2.4.10

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

* [PATCH 5/8] MIPS: KVM: Add guest mode switch trace events
  2016-06-14  8:40 [PATCH 0/8] MIPS: KVM: Debug & trace event improvements James Hogan
                   ` (3 preceding siblings ...)
  2016-06-14  8:40 ` [PATCH 4/8] MIPS: KVM: Add kvm_asid_change " James Hogan
@ 2016-06-14  8:40 ` James Hogan
  2016-06-17 14:08   ` Steven Rostedt
  2016-06-14  8:40 ` [PATCH 6/8] MIPS: KVM: Trace guest register access emulation James Hogan
                   ` (2 subsequent siblings)
  7 siblings, 1 reply; 19+ messages in thread
From: James Hogan @ 2016-06-14  8:40 UTC (permalink / raw)
  To: Paolo Bonzini
  Cc: James Hogan, Radim Krčmář,
	Ralf Baechle, Steven Rostedt, Ingo Molnar, kvm, linux-mips

Add a few trace events for entering and coming out of guest mode, as well
as re-entering it from a guest exit exception.

Signed-off-by: James Hogan <james.hogan@imgtec.com>
Cc: Paolo Bonzini <pbonzini@redhat.com>
Cc: Radim Krčmář <rkrcmar@redhat.com>
Cc: Ralf Baechle <ralf@linux-mips.org>
Cc: Steven Rostedt <rostedt@goodmis.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: kvm@vger.kernel.org
Cc: linux-mips@linux-mips.org
---
 arch/mips/kvm/mips.c  |  4 ++++
 arch/mips/kvm/trace.h | 48 ++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 52 insertions(+)

diff --git a/arch/mips/kvm/mips.c b/arch/mips/kvm/mips.c
index e9e40b9dd9be..b5ad2ba1847a 100644
--- a/arch/mips/kvm/mips.c
+++ b/arch/mips/kvm/mips.c
@@ -410,7 +410,9 @@ int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *run)
 	/* Disable hardware page table walking while in guest */
 	htw_stop();
 
+	trace_kvm_enter(vcpu);
 	r = vcpu->arch.vcpu_run(run, vcpu);
+	trace_kvm_out(vcpu);
 
 	/* Re-enable HTW before enabling interrupts */
 	htw_start();
@@ -1389,6 +1391,8 @@ skip_emul:
 	}
 
 	if (ret == RESUME_GUEST) {
+		trace_kvm_reenter(vcpu);
+
 		/*
 		 * If FPU / MSA are enabled (i.e. the guest's FPU / MSA context
 		 * is live), restore FCR31 / MSACSR.
diff --git a/arch/mips/kvm/trace.h b/arch/mips/kvm/trace.h
index 1d67d9e0f340..5b5dbd8eacb0 100644
--- a/arch/mips/kvm/trace.h
+++ b/arch/mips/kvm/trace.h
@@ -17,6 +17,54 @@
 #define TRACE_INCLUDE_PATH .
 #define TRACE_INCLUDE_FILE trace
 
+/*
+ * Tracepoints for VM enters
+ */
+TRACE_EVENT(kvm_enter,
+	    TP_PROTO(struct kvm_vcpu *vcpu),
+	    TP_ARGS(vcpu),
+	    TP_STRUCT__entry(
+			__field(unsigned long, pc)
+	    ),
+
+	    TP_fast_assign(
+			__entry->pc = vcpu->arch.pc;
+	    ),
+
+	    TP_printk("PC: 0x%08lx",
+		      __entry->pc)
+);
+
+TRACE_EVENT(kvm_reenter,
+	    TP_PROTO(struct kvm_vcpu *vcpu),
+	    TP_ARGS(vcpu),
+	    TP_STRUCT__entry(
+			__field(unsigned long, pc)
+	    ),
+
+	    TP_fast_assign(
+			__entry->pc = vcpu->arch.pc;
+	    ),
+
+	    TP_printk("PC: 0x%08lx",
+		      __entry->pc)
+);
+
+TRACE_EVENT(kvm_out,
+	    TP_PROTO(struct kvm_vcpu *vcpu),
+	    TP_ARGS(vcpu),
+	    TP_STRUCT__entry(
+			__field(unsigned long, pc)
+	    ),
+
+	    TP_fast_assign(
+			__entry->pc = vcpu->arch.pc;
+	    ),
+
+	    TP_printk("PC: 0x%08lx",
+		      __entry->pc)
+);
+
 /* The first 32 exit reasons correspond to Cause.ExcCode */
 #define KVM_TRACE_EXIT_INT		 0
 #define KVM_TRACE_EXIT_TLBMOD		 1
-- 
2.4.10

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

* [PATCH 6/8] MIPS: KVM: Trace guest register access emulation
  2016-06-14  8:40 [PATCH 0/8] MIPS: KVM: Debug & trace event improvements James Hogan
                   ` (4 preceding siblings ...)
  2016-06-14  8:40 ` [PATCH 5/8] MIPS: KVM: Add guest mode switch trace events James Hogan
@ 2016-06-14  8:40 ` James Hogan
  2016-06-14  8:40 ` [PATCH 7/8] MIPS: KVM: Dump guest tlbs if kvm_get_inst() fails James Hogan
  2016-06-14  8:40 ` [PATCH 8/8] MIPS: KVM: Print unknown load/store encodings James Hogan
  7 siblings, 0 replies; 19+ messages in thread
From: James Hogan @ 2016-06-14  8:40 UTC (permalink / raw)
  To: Paolo Bonzini
  Cc: James Hogan, Radim Krčmář,
	Ralf Baechle, Steven Rostedt, Ingo Molnar, linux-mips, kvm

Trace emulation of guest access to various registers via
MFC0/MTC0/DMFC0/DMTC0 instructions (coprocessor 0) and the RDHWR
instruction (hardware registers exposed to userland), replacing some
existing kvm_debug calls. Trace events are much more practical for this
kind of debug output.

Signed-off-by: James Hogan <james.hogan@imgtec.com>
Cc: Paolo Bonzini <pbonzini@redhat.com>
Cc: Radim Krčmář <rkrcmar@redhat.com>
Cc: Ralf Baechle <ralf@linux-mips.org>
Cc: Steven Rostedt <rostedt@goodmis.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: linux-mips@linux-mips.org
Cc: kvm@vger.kernel.org
---
 arch/mips/kvm/emulate.c | 31 ++++++++++-------
 arch/mips/kvm/trace.h   | 88 +++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 107 insertions(+), 12 deletions(-)

diff --git a/arch/mips/kvm/emulate.c b/arch/mips/kvm/emulate.c
index ee0e61d2b6fb..2004e35288d0 100644
--- a/arch/mips/kvm/emulate.c
+++ b/arch/mips/kvm/emulate.c
@@ -979,7 +979,6 @@ enum emulation_result kvm_mips_emulate_CP0(u32 inst, u32 *opc, u32 cause,
 	struct mips_coproc *cop0 = vcpu->arch.cop0;
 	enum emulation_result er = EMULATE_DONE;
 	u32 rt, rd, copz, sel, co_bit, op;
-	unsigned long pc = vcpu->arch.pc;
 	unsigned long curr_pc;
 
 	/*
@@ -1046,20 +1045,27 @@ enum emulation_result kvm_mips_emulate_CP0(u32 inst, u32 *opc, u32 cause,
 #endif
 			}
 
-			kvm_debug
-			    ("[%#lx] MFCz[%d][%d], vcpu->arch.gprs[%d]: %#lx\n",
-			     pc, rd, sel, rt, vcpu->arch.gprs[rt]);
-
+			trace_kvm_hwr(vcpu, KVM_TRACE_MFC0,
+				      KVM_TRACE_COP0(rd, sel),
+				      vcpu->arch.gprs[rt]);
 			break;
 
 		case dmfc_op:
 			vcpu->arch.gprs[rt] = cop0->reg[rd][sel];
+
+			trace_kvm_hwr(vcpu, KVM_TRACE_DMFC0,
+				      KVM_TRACE_COP0(rd, sel),
+				      vcpu->arch.gprs[rt]);
 			break;
 
 		case mtc_op:
 #ifdef CONFIG_KVM_MIPS_DEBUG_COP0_COUNTERS
 			cop0->stat[rd][sel]++;
 #endif
+			trace_kvm_hwr(vcpu, KVM_TRACE_MTC0,
+				      KVM_TRACE_COP0(rd, sel),
+				      vcpu->arch.gprs[rt]);
+
 			if ((rd == MIPS_CP0_TLB_INDEX)
 			    && (vcpu->arch.gprs[rt] >=
 				KVM_MIPS_GUEST_TLB_SIZE)) {
@@ -1098,10 +1104,6 @@ enum emulation_result kvm_mips_emulate_CP0(u32 inst, u32 *opc, u32 cause,
 				kvm_mips_write_count(vcpu, vcpu->arch.gprs[rt]);
 				goto done;
 			} else if ((rd == MIPS_CP0_COMPARE) && (sel == 0)) {
-				kvm_debug("[%#lx] MTCz, COMPARE %#lx <- %#lx\n",
-					  pc, kvm_read_c0_guest_compare(cop0),
-					  vcpu->arch.gprs[rt]);
-
 				/* If we are writing to COMPARE */
 				/* Clear pending timer interrupt, if any */
 				kvm_mips_write_compare(vcpu,
@@ -1237,14 +1239,14 @@ enum emulation_result kvm_mips_emulate_CP0(u32 inst, u32 *opc, u32 cause,
 				kvm_mips_trans_mtc0(inst, opc, vcpu);
 #endif
 			}
-
-			kvm_debug("[%#lx] MTCz, cop0->reg[%d][%d]: %#lx\n", pc,
-				  rd, sel, cop0->reg[rd][sel]);
 			break;
 
 		case dmtc_op:
 			kvm_err("!!!!!!![%#lx]dmtc_op: rt: %d, rd: %d, sel: %d!!!!!!\n",
 				vcpu->arch.pc, rt, rd, sel);
+			trace_kvm_hwr(vcpu, KVM_TRACE_DMTC0,
+				      KVM_TRACE_COP0(rd, sel),
+				      vcpu->arch.gprs[rt]);
 			er = EMULATE_FAIL;
 			break;
 
@@ -2307,6 +2309,8 @@ enum emulation_result kvm_mips_handle_ri(u32 cause, u32 *opc,
 		int usermode = !KVM_GUEST_KERNEL_MODE(vcpu);
 		int rd = (inst & RD) >> 11;
 		int rt = (inst & RT) >> 16;
+		int sel = (inst >> 6) & 0x7;
+
 		/* If usermode, check RDHWR rd is allowed by guest HWREna */
 		if (usermode && !(kvm_read_c0_guest_hwrena(cop0) & BIT(rd))) {
 			kvm_debug("RDHWR %#x disallowed by HWREna @ %p\n",
@@ -2342,6 +2346,9 @@ enum emulation_result kvm_mips_handle_ri(u32 cause, u32 *opc,
 			kvm_debug("RDHWR %#x not supported @ %p\n", rd, opc);
 			goto emulate_ri;
 		}
+
+		trace_kvm_hwr(vcpu, KVM_TRACE_RDHWR, KVM_TRACE_HWR(rd, sel),
+			      vcpu->arch.gprs[rt]);
 	} else {
 		kvm_debug("Emulate RI not supported @ %p: %#x\n", opc, inst);
 		goto emulate_ri;
diff --git a/arch/mips/kvm/trace.h b/arch/mips/kvm/trace.h
index 5b5dbd8eacb0..90941a33e5ed 100644
--- a/arch/mips/kvm/trace.h
+++ b/arch/mips/kvm/trace.h
@@ -124,6 +124,94 @@ TRACE_EVENT(kvm_exit,
 		      __entry->pc)
 );
 
+#define KVM_TRACE_MFC0		0
+#define KVM_TRACE_MTC0		1
+#define KVM_TRACE_DMFC0		2
+#define KVM_TRACE_DMTC0		3
+#define KVM_TRACE_RDHWR		4
+
+#define KVM_TRACE_HWR_COP0	0
+#define KVM_TRACE_HWR_HWR	1
+
+#define KVM_TRACE_COP0(REG, SEL)	((KVM_TRACE_HWR_COP0 << 8) |	\
+					 ((REG) << 3) | (SEL))
+#define KVM_TRACE_HWR(REG, SEL)		((KVM_TRACE_HWR_HWR  << 8) |	\
+					 ((REG) << 3) | (SEL))
+
+#define kvm_trace_symbol_hwr_ops				\
+	{ KVM_TRACE_MFC0,		"MFC0" },		\
+	{ KVM_TRACE_MTC0,		"MTC0" },		\
+	{ KVM_TRACE_DMFC0,		"DMFC0" },		\
+	{ KVM_TRACE_DMTC0,		"DMTC0" },		\
+	{ KVM_TRACE_RDHWR,		"RDHWR" }
+
+#define kvm_trace_symbol_hwr_cop				\
+	{ KVM_TRACE_HWR_COP0,		"COP0" },		\
+	{ KVM_TRACE_HWR_HWR,		"HWR" }
+
+#define kvm_trace_symbol_hwr_regs				\
+	{ KVM_TRACE_COP0( 0, 0),	"Index" },		\
+	{ KVM_TRACE_COP0( 2, 0),	"EntryLo0" },		\
+	{ KVM_TRACE_COP0( 3, 0),	"EntryLo1" },		\
+	{ KVM_TRACE_COP0( 4, 0),	"Context" },		\
+	{ KVM_TRACE_COP0( 4, 2),	"UserLocal" },		\
+	{ KVM_TRACE_COP0( 5, 0),	"PageMask" },		\
+	{ KVM_TRACE_COP0( 6, 0),	"Wired" },		\
+	{ KVM_TRACE_COP0( 7, 0),	"HWREna" },		\
+	{ KVM_TRACE_COP0( 8, 0),	"BadVAddr" },		\
+	{ KVM_TRACE_COP0( 9, 0),	"Count" },		\
+	{ KVM_TRACE_COP0(10, 0),	"EntryHi" },		\
+	{ KVM_TRACE_COP0(11, 0),	"Compare" },		\
+	{ KVM_TRACE_COP0(12, 0),	"Status" },		\
+	{ KVM_TRACE_COP0(12, 1),	"IntCtl" },		\
+	{ KVM_TRACE_COP0(12, 2),	"SRSCtl" },		\
+	{ KVM_TRACE_COP0(13, 0),	"Cause" },		\
+	{ KVM_TRACE_COP0(14, 0),	"EPC" },		\
+	{ KVM_TRACE_COP0(15, 0),	"PRId" },		\
+	{ KVM_TRACE_COP0(15, 1),	"EBase" },		\
+	{ KVM_TRACE_COP0(16, 0),	"Config" },		\
+	{ KVM_TRACE_COP0(16, 1),	"Config1" },		\
+	{ KVM_TRACE_COP0(16, 2),	"Config2" },		\
+	{ KVM_TRACE_COP0(16, 3),	"Config3" },		\
+	{ KVM_TRACE_COP0(16, 4),	"Config4" },		\
+	{ KVM_TRACE_COP0(16, 5),	"Config5" },		\
+	{ KVM_TRACE_COP0(16, 7),	"Config7" },		\
+	{ KVM_TRACE_COP0(26, 0),	"ECC" },		\
+	{ KVM_TRACE_COP0(30, 0),	"ErrorEPC" },		\
+	{ KVM_TRACE_HWR( 0, 0),		"CPUNum" },		\
+	{ KVM_TRACE_HWR( 1, 0),		"SYNCI_Step" },		\
+	{ KVM_TRACE_HWR( 2, 0),		"CC" },			\
+	{ KVM_TRACE_HWR( 3, 0),		"CCRes" },		\
+	{ KVM_TRACE_HWR(29, 0),		"ULR" }
+
+TRACE_EVENT(kvm_hwr,
+	    TP_PROTO(struct kvm_vcpu *vcpu, unsigned int op, unsigned int reg,
+		     unsigned long val),
+	    TP_ARGS(vcpu, op, reg, val),
+	    TP_STRUCT__entry(
+			__field(unsigned long, val)
+			__field(u16, reg)
+			__field(u8, op)
+	    ),
+
+	    TP_fast_assign(
+			__entry->val = val;
+			__entry->reg = reg;
+			__entry->op = op;
+	    ),
+
+	    TP_printk("%s %s (%s:%u:%u) 0x%08lx",
+		      __print_symbolic(__entry->op,
+				       kvm_trace_symbol_hwr_ops),
+		      __print_symbolic(__entry->reg,
+				       kvm_trace_symbol_hwr_regs),
+		      __print_symbolic(__entry->reg >> 8,
+				       kvm_trace_symbol_hwr_cop),
+		      (__entry->reg >> 3) & 0x1f,
+		      __entry->reg & 0x7,
+		      __entry->val)
+);
+
 #define KVM_TRACE_AUX_RESTORE		0
 #define KVM_TRACE_AUX_SAVE		1
 #define KVM_TRACE_AUX_ENABLE		2
-- 
2.4.10

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

* [PATCH 7/8] MIPS: KVM: Dump guest tlbs if kvm_get_inst() fails
  2016-06-14  8:40 [PATCH 0/8] MIPS: KVM: Debug & trace event improvements James Hogan
                   ` (5 preceding siblings ...)
  2016-06-14  8:40 ` [PATCH 6/8] MIPS: KVM: Trace guest register access emulation James Hogan
@ 2016-06-14  8:40 ` James Hogan
  2016-06-14  8:40 ` [PATCH 8/8] MIPS: KVM: Print unknown load/store encodings James Hogan
  7 siblings, 0 replies; 19+ messages in thread
From: James Hogan @ 2016-06-14  8:40 UTC (permalink / raw)
  To: Paolo Bonzini
  Cc: James Hogan, Radim Krčmář, Ralf Baechle, kvm, linux-mips

If kvm_get_inst() fails to find a guest TLB mapping for the guest PC
then dump the guest TLB entries. The contents of the guest TLB is likely
to be more interesting than the host TLB entries.

Signed-off-by: James Hogan <james.hogan@imgtec.com>
Cc: Paolo Bonzini <pbonzini@redhat.com>
Cc: Radim Krčmář <rkrcmar@redhat.com>
Cc: Ralf Baechle <ralf@linux-mips.org>
Cc: kvm@vger.kernel.org
Cc: linux-mips@linux-mips.org
---
 arch/mips/kvm/mmu.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/arch/mips/kvm/mmu.c b/arch/mips/kvm/mmu.c
index 208f70409ccb..2f494ec5c939 100644
--- a/arch/mips/kvm/mmu.c
+++ b/arch/mips/kvm/mmu.c
@@ -346,6 +346,7 @@ u32 kvm_get_inst(u32 *opc, struct kvm_vcpu *vcpu)
 				kvm_err("%s: get_user_failed for %p, vcpu: %p, ASID: %#lx\n",
 					__func__, opc, vcpu, read_c0_entryhi());
 				kvm_mips_dump_host_tlbs();
+				kvm_mips_dump_guest_tlbs(vcpu);
 				local_irq_restore(flags);
 				return KVM_INVALID_INST;
 			}
-- 
2.4.10

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

* [PATCH 8/8] MIPS: KVM: Print unknown load/store encodings
  2016-06-14  8:40 [PATCH 0/8] MIPS: KVM: Debug & trace event improvements James Hogan
                   ` (6 preceding siblings ...)
  2016-06-14  8:40 ` [PATCH 7/8] MIPS: KVM: Dump guest tlbs if kvm_get_inst() fails James Hogan
@ 2016-06-14  8:40 ` James Hogan
  7 siblings, 0 replies; 19+ messages in thread
From: James Hogan @ 2016-06-14  8:40 UTC (permalink / raw)
  To: Paolo Bonzini
  Cc: James Hogan, Radim Krčmář, Ralf Baechle, linux-mips, kvm

When trying to emulate an unrecognised load or store instruction, print
the encoding to aid debug.

Signed-off-by: James Hogan <james.hogan@imgtec.com>
Cc: Paolo Bonzini <pbonzini@redhat.com>
Cc: Radim Krčmář <rkrcmar@redhat.com>
Cc: Ralf Baechle <ralf@linux-mips.org>
Cc: linux-mips@linux-mips.org
Cc: kvm@vger.kernel.org
---
 arch/mips/kvm/emulate.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/arch/mips/kvm/emulate.c b/arch/mips/kvm/emulate.c
index 2004e35288d0..ff4072c2b25e 100644
--- a/arch/mips/kvm/emulate.c
+++ b/arch/mips/kvm/emulate.c
@@ -1412,7 +1412,8 @@ enum emulation_result kvm_mips_emulate_store(u32 inst, u32 cause,
 		break;
 
 	default:
-		kvm_err("Store not yet supported");
+		kvm_err("Store not yet supported (inst=0x%08x)\n",
+			inst);
 		er = EMULATE_FAIL;
 		break;
 	}
@@ -1522,7 +1523,8 @@ enum emulation_result kvm_mips_emulate_load(u32 inst, u32 cause,
 		break;
 
 	default:
-		kvm_err("Load not yet supported");
+		kvm_err("Load not yet supported (inst=0x%08x)\n",
+			inst);
 		er = EMULATE_FAIL;
 		break;
 	}
-- 
2.4.10

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

* Re: [PATCH 2/8] MIPS: KVM: Add kvm_aux trace event
  2016-06-14  8:40 ` [PATCH 2/8] MIPS: KVM: Add kvm_aux trace event James Hogan
@ 2016-06-14  8:55   ` James Hogan
  2016-06-14  9:15     ` Paolo Bonzini
  0 siblings, 1 reply; 19+ messages in thread
From: James Hogan @ 2016-06-14  8:55 UTC (permalink / raw)
  To: Paolo Bonzini
  Cc: Radim Krčmář,
	Ralf Baechle, Steven Rostedt, Ingo Molnar, linux-mips, kvm

[-- Attachment #1: Type: text/plain, Size: 5693 bytes --]

On Tue, Jun 14, 2016 at 09:40:11AM +0100, James Hogan wrote:
> Add a MIPS specific trace event for auxiliary context operations
> (notably FPU and MSA). Unfortunately the generic kvm_fpu trace event
> isn't flexible enough to handle the range of interesting things that can
> happen with FPU and MSA context.
> 
> The type of state being operated on is traced:
> - FPU: Just the FPU registers.
> - MSA: Just the upper half of the MSA vector registers (low half already
>        loaded with FPU state).
> - FPU & MSA: Full MSA vector state (includes FPU state).
> 
> As is the type of operation:
> - Restore: State was enabled and restored.
> - Save: State was saved and disabled.
> - Enable: State was enabled (already loaded).
> - Disable: State was disabled (kept loaded).
> - Discard: State was discarded and disabled.
> 
> Signed-off-by: James Hogan <james.hogan@imgtec.com>
> Cc: Paolo Bonzini <pbonzini@redhat.com>
> Cc: Radim Krčmář <rkrcmar@redhat.com>
> Cc: Ralf Baechle <ralf@linux-mips.org>
> Cc: Steven Rostedt <rostedt@goodmis.org>
> Cc: Ingo Molnar <mingo@redhat.com>
> Cc: linux-mips@linux-mips.org
> Cc: kvm@vger.kernel.org
> ---
>  arch/mips/kvm/mips.c  | 11 +++++++++++
>  arch/mips/kvm/trace.h | 46 ++++++++++++++++++++++++++++++++++++++++++++++
>  2 files changed, 57 insertions(+)
> 
> diff --git a/arch/mips/kvm/mips.c b/arch/mips/kvm/mips.c
> index 9093262ff3ce..c0e8f8640f2b 100644
> --- a/arch/mips/kvm/mips.c
> +++ b/arch/mips/kvm/mips.c
> @@ -1465,6 +1465,9 @@ void kvm_own_fpu(struct kvm_vcpu *vcpu)
>  	if (!(vcpu->arch.aux_inuse & KVM_MIPS_AUX_FPU)) {
>  		__kvm_restore_fpu(&vcpu->arch);
>  		vcpu->arch.aux_inuse |= KVM_MIPS_AUX_FPU;
> +		trace_kvm_aux(vcpu, KVM_TRACE_AUX_RESTORE, KVM_TRACE_AUX_FPU);
> +	} else {
> +		trace_kvm_aux(vcpu, KVM_TRACE_AUX_ENABLE, KVM_TRACE_AUX_FPU);
>  	}
>  
>  	preempt_enable();
> @@ -1513,6 +1516,7 @@ void kvm_own_msa(struct kvm_vcpu *vcpu)
>  		 */
>  		__kvm_restore_msa_upper(&vcpu->arch);
>  		vcpu->arch.aux_inuse |= KVM_MIPS_AUX_MSA;
> +		trace_kvm_aux(vcpu, KVM_TRACE_AUX_RESTORE, KVM_TRACE_AUX_MSA);
>  		break;
>  	case 0:
>  		/* Neither FPU or MSA already active, restore full MSA state */
> @@ -1520,8 +1524,11 @@ void kvm_own_msa(struct kvm_vcpu *vcpu)
>  		vcpu->arch.aux_inuse |= KVM_MIPS_AUX_MSA;
>  		if (kvm_mips_guest_has_fpu(&vcpu->arch))
>  			vcpu->arch.aux_inuse |= KVM_MIPS_AUX_FPU;
> +		trace_kvm_aux(vcpu, KVM_TRACE_AUX_RESTORE,
> +			      KVM_TRACE_AUX_FPU_MSA);
>  		break;
>  	default:
> +		trace_kvm_aux(vcpu, KVM_TRACE_AUX_ENABLE, KVM_TRACE_AUX_MSA);
>  		break;
>  	}
>  
> @@ -1535,10 +1542,12 @@ void kvm_drop_fpu(struct kvm_vcpu *vcpu)
>  	preempt_disable();
>  	if (cpu_has_msa && vcpu->arch.aux_inuse & KVM_MIPS_AUX_MSA) {
>  		disable_msa();
> +		trace_kvm_aux(vcpu, KVM_TRACE_AUX_DISCARD, KVM_TRACE_AUX_MSA);
>  		vcpu->arch.aux_inuse &= ~KVM_MIPS_AUX_MSA;
>  	}
>  	if (vcpu->arch.aux_inuse & KVM_MIPS_AUX_FPU) {
>  		clear_c0_status(ST0_CU1 | ST0_FR);
> +		trace_kvm_aux(vcpu, KVM_TRACE_AUX_DISCARD, KVM_TRACE_AUX_FPU);
>  		vcpu->arch.aux_inuse &= ~KVM_MIPS_AUX_FPU;
>  	}
>  	preempt_enable();
> @@ -1560,6 +1569,7 @@ void kvm_lose_fpu(struct kvm_vcpu *vcpu)
>  		enable_fpu_hazard();
>  
>  		__kvm_save_msa(&vcpu->arch);
> +		trace_kvm_aux(vcpu, KVM_TRACE_AUX_SAVE, KVM_TRACE_AUX_FPU_MSA);
>  
>  		/* Disable MSA & FPU */
>  		disable_msa();
> @@ -1574,6 +1584,7 @@ void kvm_lose_fpu(struct kvm_vcpu *vcpu)
>  
>  		__kvm_save_fpu(&vcpu->arch);
>  		vcpu->arch.aux_inuse &= ~KVM_MIPS_AUX_FPU;
> +		trace_kvm_aux(vcpu, KVM_TRACE_AUX_SAVE, KVM_TRACE_AUX_FPU);
>  
>  		/* Disable FPU */
>  		clear_c0_status(ST0_CU1 | ST0_FR);
> diff --git a/arch/mips/kvm/trace.h b/arch/mips/kvm/trace.h
> index bd6437f67dc0..32ac7cc82e13 100644
> --- a/arch/mips/kvm/trace.h
> +++ b/arch/mips/kvm/trace.h
> @@ -38,6 +38,52 @@ TRACE_EVENT(kvm_exit,
>  		      __entry->pc)
>  );
>  
> +#define KVM_TRACE_AUX_RESTORE		0
> +#define KVM_TRACE_AUX_SAVE		1
> +#define KVM_TRACE_AUX_ENABLE		2
> +#define KVM_TRACE_AUX_DISABLE		3
> +#define KVM_TRACE_AUX_DISCARD		4
> +
> +#define KVM_TRACE_AUX_FPU		1
> +#define KVM_TRACE_AUX_MSA		2
> +#define KVM_TRACE_AUX_FPU_MSA		3
> +
> +#define kvm_trace_symbol_fpu_msa_op		\
> +	{ KVM_TRACE_AUX_RESTORE, "restore" },	\
> +	{ KVM_TRACE_AUX_SAVE,    "save" },	\
> +	{ KVM_TRACE_AUX_ENABLE,  "enable" },	\
> +	{ KVM_TRACE_AUX_DISABLE, "disable" },	\
> +	{ KVM_TRACE_AUX_DISCARD, "discard" }
> +
> +#define kvm_trace_symbol_fpu_msa_state		\
> +	{ KVM_TRACE_AUX_FPU,     "FPU" },	\
> +	{ KVM_TRACE_AUX_MSA,     "MSA" },	\
> +	{ KVM_TRACE_AUX_FPU_MSA, "FPU & MSA" }
> +
> +TRACE_EVENT(kvm_aux,
> +	    TP_PROTO(struct kvm_vcpu *vcpu, unsigned int op,
> +		     unsigned int state),
> +	    TP_ARGS(vcpu, op, state),
> +	    TP_STRUCT__entry(
> +			__field(unsigned long, pc)
> +			__field(u8, op)
> +			__field(u8, state)
> +	    ),
> +
> +	    TP_fast_assign(
> +			__entry->pc = vcpu->arch.pc;
> +			__entry->op = op;
> +			__entry->state = state;
> +	    ),
> +
> +	    TP_printk("%s %s PC: 0x%08lx",
> +		      __print_symbolic(__entry->op,
> +				       kvm_trace_symbol_fpu_msa_op),
> +		      __print_symbolic(__entry->state,
> +				       kvm_trace_symbol_fpu_msa_state),

hmm, sorry, I don't know how i didn't spot when I checked these over
that fpu_msa is still referred to here instead of aux. I'll post a V2 of
this patch with s/fpu_msa/aux/.

Cheers
James

> +		      __entry->pc)
> +);
> +
>  #endif /* _TRACE_KVM_H */
>  
>  /* This part must be outside protection */
> -- 
> 2.4.10
> 

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 819 bytes --]

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

* Re: [PATCH 2/8] MIPS: KVM: Add kvm_aux trace event
  2016-06-14  8:55   ` James Hogan
@ 2016-06-14  9:15     ` Paolo Bonzini
  2016-06-14  9:17       ` James Hogan
  0 siblings, 1 reply; 19+ messages in thread
From: Paolo Bonzini @ 2016-06-14  9:15 UTC (permalink / raw)
  To: James Hogan
  Cc: Radim Krčmář,
	Ralf Baechle, Steven Rostedt, Ingo Molnar, linux-mips, kvm



On 14/06/2016 10:55, James Hogan wrote:
> hmm, sorry, I don't know how i didn't spot when I checked these over
> that fpu_msa is still referred to here instead of aux. I'll post a V2 of
> this patch with s/fpu_msa/aux/.

I can fix it up to kvm_trace_symbol_aux_op and kvm_trace_symbol_aux_state.

diff --git a/arch/mips/kvm/trace.h b/arch/mips/kvm/trace.h
index 32ac7cc82e13..f3ada591ca25 100644
--- a/arch/mips/kvm/trace.h
+++ b/arch/mips/kvm/trace.h
@@ -48,14 +48,14 @@ TRACE_EVENT(kvm_exit,
 #define KVM_TRACE_AUX_MSA		2
 #define KVM_TRACE_AUX_FPU_MSA		3
 
-#define kvm_trace_symbol_fpu_msa_op		\
+#define kvm_trace_symbol_aux_op		\
 	{ KVM_TRACE_AUX_RESTORE, "restore" },	\
 	{ KVM_TRACE_AUX_SAVE,    "save" },	\
 	{ KVM_TRACE_AUX_ENABLE,  "enable" },	\
 	{ KVM_TRACE_AUX_DISABLE, "disable" },	\
 	{ KVM_TRACE_AUX_DISCARD, "discard" }
 
-#define kvm_trace_symbol_fpu_msa_state		\
+#define kvm_trace_symbol_aux_state		\
 	{ KVM_TRACE_AUX_FPU,     "FPU" },	\
 	{ KVM_TRACE_AUX_MSA,     "MSA" },	\
 	{ KVM_TRACE_AUX_FPU_MSA, "FPU & MSA" }
@@ -78,9 +78,9 @@ TRACE_EVENT(kvm_aux,
 
 	    TP_printk("%s %s PC: 0x%08lx",
 		      __print_symbolic(__entry->op,
-				       kvm_trace_symbol_fpu_msa_op),
+				       kvm_trace_symbol_aux_op),
 		      __print_symbolic(__entry->state,
-				       kvm_trace_symbol_fpu_msa_state),
+				       kvm_trace_symbol_aux_state),
 		      __entry->pc)
 );
 

Paolo

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

* Re: [PATCH 2/8] MIPS: KVM: Add kvm_aux trace event
  2016-06-14  9:15     ` Paolo Bonzini
@ 2016-06-14  9:17       ` James Hogan
  0 siblings, 0 replies; 19+ messages in thread
From: James Hogan @ 2016-06-14  9:17 UTC (permalink / raw)
  To: Paolo Bonzini
  Cc: Radim Krčmář,
	Ralf Baechle, Steven Rostedt, Ingo Molnar, linux-mips, kvm

[-- Attachment #1: Type: text/plain, Size: 1653 bytes --]

On Tue, Jun 14, 2016 at 11:15:40AM +0200, Paolo Bonzini wrote:
> 
> 
> On 14/06/2016 10:55, James Hogan wrote:
> > hmm, sorry, I don't know how i didn't spot when I checked these over
> > that fpu_msa is still referred to here instead of aux. I'll post a V2 of
> > this patch with s/fpu_msa/aux/.
> 
> I can fix it up to kvm_trace_symbol_aux_op and kvm_trace_symbol_aux_state.

Great, thanks Paolo. Looks good.

Cheers
James

> 
> diff --git a/arch/mips/kvm/trace.h b/arch/mips/kvm/trace.h
> index 32ac7cc82e13..f3ada591ca25 100644
> --- a/arch/mips/kvm/trace.h
> +++ b/arch/mips/kvm/trace.h
> @@ -48,14 +48,14 @@ TRACE_EVENT(kvm_exit,
>  #define KVM_TRACE_AUX_MSA		2
>  #define KVM_TRACE_AUX_FPU_MSA		3
>  
> -#define kvm_trace_symbol_fpu_msa_op		\
> +#define kvm_trace_symbol_aux_op		\
>  	{ KVM_TRACE_AUX_RESTORE, "restore" },	\
>  	{ KVM_TRACE_AUX_SAVE,    "save" },	\
>  	{ KVM_TRACE_AUX_ENABLE,  "enable" },	\
>  	{ KVM_TRACE_AUX_DISABLE, "disable" },	\
>  	{ KVM_TRACE_AUX_DISCARD, "discard" }
>  
> -#define kvm_trace_symbol_fpu_msa_state		\
> +#define kvm_trace_symbol_aux_state		\
>  	{ KVM_TRACE_AUX_FPU,     "FPU" },	\
>  	{ KVM_TRACE_AUX_MSA,     "MSA" },	\
>  	{ KVM_TRACE_AUX_FPU_MSA, "FPU & MSA" }
> @@ -78,9 +78,9 @@ TRACE_EVENT(kvm_aux,
>  
>  	    TP_printk("%s %s PC: 0x%08lx",
>  		      __print_symbolic(__entry->op,
> -				       kvm_trace_symbol_fpu_msa_op),
> +				       kvm_trace_symbol_aux_op),
>  		      __print_symbolic(__entry->state,
> -				       kvm_trace_symbol_fpu_msa_state),
> +				       kvm_trace_symbol_aux_state),
>  		      __entry->pc)
>  );
>  
> 
> Paolo

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 819 bytes --]

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

* Re: [PATCH 5/8] MIPS: KVM: Add guest mode switch trace events
  2016-06-14  8:40 ` [PATCH 5/8] MIPS: KVM: Add guest mode switch trace events James Hogan
@ 2016-06-17 14:08   ` Steven Rostedt
  2016-06-17 14:29     ` Paolo Bonzini
  0 siblings, 1 reply; 19+ messages in thread
From: Steven Rostedt @ 2016-06-17 14:08 UTC (permalink / raw)
  To: James Hogan
  Cc: Paolo Bonzini, Radim Krčmář,
	Ralf Baechle, Ingo Molnar, kvm, linux-mips

On Tue, 14 Jun 2016 09:40:14 +0100
James Hogan <james.hogan@imgtec.com> wrote:


> --- a/arch/mips/kvm/trace.h
> +++ b/arch/mips/kvm/trace.h
> @@ -17,6 +17,54 @@
>  #define TRACE_INCLUDE_PATH .
>  #define TRACE_INCLUDE_FILE trace
>  
> +/*
> + * Tracepoints for VM enters
> + */
> +TRACE_EVENT(kvm_enter,
> +	    TP_PROTO(struct kvm_vcpu *vcpu),
> +	    TP_ARGS(vcpu),
> +	    TP_STRUCT__entry(
> +			__field(unsigned long, pc)
> +	    ),
> +
> +	    TP_fast_assign(
> +			__entry->pc = vcpu->arch.pc;
> +	    ),
> +
> +	    TP_printk("PC: 0x%08lx",
> +		      __entry->pc)
> +);
> +
> +TRACE_EVENT(kvm_reenter,
> +	    TP_PROTO(struct kvm_vcpu *vcpu),
> +	    TP_ARGS(vcpu),
> +	    TP_STRUCT__entry(
> +			__field(unsigned long, pc)
> +	    ),
> +
> +	    TP_fast_assign(
> +			__entry->pc = vcpu->arch.pc;
> +	    ),
> +
> +	    TP_printk("PC: 0x%08lx",
> +		      __entry->pc)
> +);
> +
> +TRACE_EVENT(kvm_out,
> +	    TP_PROTO(struct kvm_vcpu *vcpu),
> +	    TP_ARGS(vcpu),
> +	    TP_STRUCT__entry(
> +			__field(unsigned long, pc)
> +	    ),
> +
> +	    TP_fast_assign(
> +			__entry->pc = vcpu->arch.pc;
> +	    ),
> +
> +	    TP_printk("PC: 0x%08lx",
> +		      __entry->pc)
> +);

Please combine the above TRACE_EVENT()s to use a single
DECLARE_EVENT_CLASS() and three DEFINE_EVENT()s.

-- Steve

> +
>  /* The first 32 exit reasons correspond to Cause.ExcCode */
>  #define KVM_TRACE_EXIT_INT		 0
>  #define KVM_TRACE_EXIT_TLBMOD		 1

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

* Re: [PATCH 3/8] MIPS: KVM: Clean up kvm_exit trace event
  2016-06-14  8:40 ` [PATCH 3/8] MIPS: KVM: Clean up kvm_exit " James Hogan
@ 2016-06-17 14:10   ` Steven Rostedt
  2016-06-17 14:47     ` James Hogan
  0 siblings, 1 reply; 19+ messages in thread
From: Steven Rostedt @ 2016-06-17 14:10 UTC (permalink / raw)
  To: James Hogan
  Cc: Paolo Bonzini, Radim Krčmář,
	Ralf Baechle, Ingo Molnar, kvm, linux-mips

On Tue, 14 Jun 2016 09:40:12 +0100
James Hogan <james.hogan@imgtec.com> wrote:


>  TRACE_EVENT(kvm_exit,
>  	    TP_PROTO(struct kvm_vcpu *vcpu, unsigned int reason),
> @@ -34,7 +71,8 @@ TRACE_EVENT(kvm_exit,
>  	    ),
>  
>  	    TP_printk("[%s]PC: 0x%08lx",
> -		      kvm_mips_exit_types_str[__entry->reason],
> +		      __print_symbolic(__entry->reason,
> +				       kvm_trace_symbol_exit_types),
>  		      __entry->pc)
>  );
>  

BTW, I'm curious. Can you show me what you see in:

 /sys/kernel/debug/tracing/events/kvm/kvm_exit/format

Thanks!

-- Steve

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

* Re: [PATCH 5/8] MIPS: KVM: Add guest mode switch trace events
  2016-06-17 14:08   ` Steven Rostedt
@ 2016-06-17 14:29     ` Paolo Bonzini
  2016-06-17 14:58       ` James Hogan
  0 siblings, 1 reply; 19+ messages in thread
From: Paolo Bonzini @ 2016-06-17 14:29 UTC (permalink / raw)
  To: Steven Rostedt, James Hogan
  Cc: Radim Krčmář, Ralf Baechle, Ingo Molnar, kvm, linux-mips



On 17/06/2016 16:08, Steven Rostedt wrote:
>> > +/*
>> > + * Tracepoints for VM enters
>> > + */
>> > +TRACE_EVENT(kvm_enter,
>> > +	    TP_PROTO(struct kvm_vcpu *vcpu),
>> > +	    TP_ARGS(vcpu),
>> > +	    TP_STRUCT__entry(
>> > +			__field(unsigned long, pc)
>> > +	    ),
>> > +
>> > +	    TP_fast_assign(
>> > +			__entry->pc = vcpu->arch.pc;
>> > +	    ),
>> > +
>> > +	    TP_printk("PC: 0x%08lx",
>> > +		      __entry->pc)
>> > +);
>> > +
>> > +TRACE_EVENT(kvm_reenter,
>> > +	    TP_PROTO(struct kvm_vcpu *vcpu),
>> > +	    TP_ARGS(vcpu),
>> > +	    TP_STRUCT__entry(
>> > +			__field(unsigned long, pc)
>> > +	    ),
>> > +
>> > +	    TP_fast_assign(
>> > +			__entry->pc = vcpu->arch.pc;
>> > +	    ),
>> > +
>> > +	    TP_printk("PC: 0x%08lx",
>> > +		      __entry->pc)
>> > +);
>> > +
>> > +TRACE_EVENT(kvm_out,
>> > +	    TP_PROTO(struct kvm_vcpu *vcpu),
>> > +	    TP_ARGS(vcpu),
>> > +	    TP_STRUCT__entry(
>> > +			__field(unsigned long, pc)
>> > +	    ),
>> > +
>> > +	    TP_fast_assign(
>> > +			__entry->pc = vcpu->arch.pc;
>> > +	    ),
>> > +
>> > +	    TP_printk("PC: 0x%08lx",
>> > +		      __entry->pc)
>> > +);
> 
> Please combine the above TRACE_EVENT()s to use a single
> DECLARE_EVENT_CLASS() and three DEFINE_EVENT()s.

James,

I've committed the patch already, so please send a follow up.

Thanks,

Paolo

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

* Re: [PATCH 3/8] MIPS: KVM: Clean up kvm_exit trace event
  2016-06-17 14:10   ` Steven Rostedt
@ 2016-06-17 14:47     ` James Hogan
  2016-06-17 15:35       ` Steven Rostedt
  0 siblings, 1 reply; 19+ messages in thread
From: James Hogan @ 2016-06-17 14:47 UTC (permalink / raw)
  To: Steven Rostedt
  Cc: Paolo Bonzini, Radim Krčmář,
	Ralf Baechle, Ingo Molnar, kvm, linux-mips

[-- Attachment #1: Type: text/plain, Size: 1551 bytes --]

Hi Steven,

On Fri, Jun 17, 2016 at 10:10:25AM -0400, Steven Rostedt wrote:
> On Tue, 14 Jun 2016 09:40:12 +0100
> James Hogan <james.hogan@imgtec.com> wrote:
> 
> 
> >  TRACE_EVENT(kvm_exit,
> >  	    TP_PROTO(struct kvm_vcpu *vcpu, unsigned int reason),
> > @@ -34,7 +71,8 @@ TRACE_EVENT(kvm_exit,
> >  	    ),
> >  
> >  	    TP_printk("[%s]PC: 0x%08lx",
> > -		      kvm_mips_exit_types_str[__entry->reason],
> > +		      __print_symbolic(__entry->reason,
> > +				       kvm_trace_symbol_exit_types),
> >  		      __entry->pc)
> >  );
> >  
> 
> BTW, I'm curious. Can you show me what you see in:
> 
>  /sys/kernel/debug/tracing/events/kvm/kvm_exit/format

Sure:

name: kvm_exit
ID: 472
format:
	field:unsigned short common_type;	offset:0;	size:2;	signed:0;
	field:unsigned char common_flags;	offset:2;	size:1;	signed:0;
	field:unsigned char common_preempt_count;	offset:3;	size:1;	signed:0;
	field:int common_pid;	offset:4;	size:4;	signed:1;

	field:unsigned long pc;	offset:8;	size:4;	signed:0;
	field:unsigned int reason;	offset:12;	size:4;	signed:0;

print fmt: "[%s]PC: 0x%08lx", __print_symbolic(REC->reason, { 0, "Interrupt" }, { 1, "TLB Mod" }, { 2, "TLB Miss (LD)" }, { 3, "TLB Miss (ST)" }, { 4, "Address Error (LD)" }, { 5, "Address Err (ST)" }, { 8, "System Call" }, { 9, "Break Inst" }, { 10, "Reserved Inst" }, { 11, "COP0/1 Unusable" }, { 13, "Trap Inst" }, { 14, "MSA FPE" }, { 15, "FPE" }, { 21, "MSA Disabled" }, { 32, "WAIT" }, { 33, "CACHE" }, { 34, "Signal" }), REC->pc

Cheers
James

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 819 bytes --]

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

* Re: [PATCH 5/8] MIPS: KVM: Add guest mode switch trace events
  2016-06-17 14:29     ` Paolo Bonzini
@ 2016-06-17 14:58       ` James Hogan
  2016-06-17 15:35         ` Steven Rostedt
  0 siblings, 1 reply; 19+ messages in thread
From: James Hogan @ 2016-06-17 14:58 UTC (permalink / raw)
  To: Paolo Bonzini
  Cc: Steven Rostedt, Radim Krčmář,
	Ralf Baechle, Ingo Molnar, kvm, linux-mips

[-- Attachment #1: Type: text/plain, Size: 1662 bytes --]

On Fri, Jun 17, 2016 at 04:29:37PM +0200, Paolo Bonzini wrote:
> 
> 
> On 17/06/2016 16:08, Steven Rostedt wrote:
> >> > +/*
> >> > + * Tracepoints for VM enters
> >> > + */
> >> > +TRACE_EVENT(kvm_enter,
> >> > +	    TP_PROTO(struct kvm_vcpu *vcpu),
> >> > +	    TP_ARGS(vcpu),
> >> > +	    TP_STRUCT__entry(
> >> > +			__field(unsigned long, pc)
> >> > +	    ),
> >> > +
> >> > +	    TP_fast_assign(
> >> > +			__entry->pc = vcpu->arch.pc;
> >> > +	    ),
> >> > +
> >> > +	    TP_printk("PC: 0x%08lx",
> >> > +		      __entry->pc)
> >> > +);
> >> > +
> >> > +TRACE_EVENT(kvm_reenter,
> >> > +	    TP_PROTO(struct kvm_vcpu *vcpu),
> >> > +	    TP_ARGS(vcpu),
> >> > +	    TP_STRUCT__entry(
> >> > +			__field(unsigned long, pc)
> >> > +	    ),
> >> > +
> >> > +	    TP_fast_assign(
> >> > +			__entry->pc = vcpu->arch.pc;
> >> > +	    ),
> >> > +
> >> > +	    TP_printk("PC: 0x%08lx",
> >> > +		      __entry->pc)
> >> > +);
> >> > +
> >> > +TRACE_EVENT(kvm_out,
> >> > +	    TP_PROTO(struct kvm_vcpu *vcpu),
> >> > +	    TP_ARGS(vcpu),
> >> > +	    TP_STRUCT__entry(
> >> > +			__field(unsigned long, pc)
> >> > +	    ),
> >> > +
> >> > +	    TP_fast_assign(
> >> > +			__entry->pc = vcpu->arch.pc;
> >> > +	    ),
> >> > +
> >> > +	    TP_printk("PC: 0x%08lx",
> >> > +		      __entry->pc)
> >> > +);
> > 
> > Please combine the above TRACE_EVENT()s to use a single
> > DECLARE_EVENT_CLASS() and three DEFINE_EVENT()s.

Oh, neat. I did wonder if there was a nicer way to do that. Thanks!

> 
> James,
> 
> I've committed the patch already, so please send a follow up.

Will do,

Thanks
James

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 819 bytes --]

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

* Re: [PATCH 3/8] MIPS: KVM: Clean up kvm_exit trace event
  2016-06-17 14:47     ` James Hogan
@ 2016-06-17 15:35       ` Steven Rostedt
  0 siblings, 0 replies; 19+ messages in thread
From: Steven Rostedt @ 2016-06-17 15:35 UTC (permalink / raw)
  To: James Hogan
  Cc: Paolo Bonzini, Radim Krčmář,
	Ralf Baechle, Ingo Molnar, kvm, linux-mips

On Fri, 17 Jun 2016 15:47:46 +0100
James Hogan <james.hogan@imgtec.com> wrote:

> > BTW, I'm curious. Can you show me what you see in:
> > 
> >  /sys/kernel/debug/tracing/events/kvm/kvm_exit/format  
> 
> Sure:
> 
> name: kvm_exit
> ID: 472
> format:
> 	field:unsigned short common_type;	offset:0;	size:2;	signed:0;
> 	field:unsigned char common_flags;	offset:2;	size:1;	signed:0;
> 	field:unsigned char common_preempt_count;	offset:3;	size:1;	signed:0;
> 	field:int common_pid;	offset:4;	size:4;	signed:1;
> 
> 	field:unsigned long pc;	offset:8;	size:4;	signed:0;
> 	field:unsigned int reason;	offset:12;	size:4;	signed:0;
> 
> print fmt: "[%s]PC: 0x%08lx", __print_symbolic(REC->reason, { 0, "Interrupt" }, { 1, "TLB Mod" }, { 2, "TLB Miss (LD)" }, { 3, "TLB Miss (ST)" }, { 4, "Address Error (LD)" }, { 5, "Address Err (ST)" }, { 8, "System Call" }, { 9, "Break Inst" }, { 10, "Reserved Inst" }, { 11, "COP0/1 Unusable" }, { 13, "Trap Inst" }, { 14, "MSA FPE" }, { 15, "FPE" }, { 21, "MSA Disabled" }, { 32, "WAIT" }, { 33, "CACHE" }, { 34, "Signal" }), REC->pc

OK, cool. I just wanted to make sure that there were numbers there.
Otherwise you would need to use the TRACE_DEFINE_ENUM() trick like what
is done in include/trace/events/writeback.h

-- Steve

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

* Re: [PATCH 5/8] MIPS: KVM: Add guest mode switch trace events
  2016-06-17 14:58       ` James Hogan
@ 2016-06-17 15:35         ` Steven Rostedt
  0 siblings, 0 replies; 19+ messages in thread
From: Steven Rostedt @ 2016-06-17 15:35 UTC (permalink / raw)
  To: James Hogan
  Cc: Paolo Bonzini, Radim Krčmář,
	Ralf Baechle, Ingo Molnar, kvm, linux-mips

On Fri, 17 Jun 2016 15:58:19 +0100
James Hogan <james.hogan@imgtec.com> wrote:


> > > Please combine the above TRACE_EVENT()s to use a single
> > > DECLARE_EVENT_CLASS() and three DEFINE_EVENT()s.  
> 
> Oh, neat. I did wonder if there was a nicer way to do that. Thanks!

It also saves on duplicate code, and keeps the bloat down a bit.

> 
> > 
> > James,
> > 
> > I've committed the patch already, so please send a follow up.  
> 
> Will do,
> 

Great.

Thanks,

-- Steve

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

end of thread, other threads:[~2016-06-17 15:36 UTC | newest]

Thread overview: 19+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-06-14  8:40 [PATCH 0/8] MIPS: KVM: Debug & trace event improvements James Hogan
2016-06-14  8:40 ` [PATCH 1/8] MIPS: KVM: Generalise fpu_inuse for other state James Hogan
2016-06-14  8:40 ` [PATCH 2/8] MIPS: KVM: Add kvm_aux trace event James Hogan
2016-06-14  8:55   ` James Hogan
2016-06-14  9:15     ` Paolo Bonzini
2016-06-14  9:17       ` James Hogan
2016-06-14  8:40 ` [PATCH 3/8] MIPS: KVM: Clean up kvm_exit " James Hogan
2016-06-17 14:10   ` Steven Rostedt
2016-06-17 14:47     ` James Hogan
2016-06-17 15:35       ` Steven Rostedt
2016-06-14  8:40 ` [PATCH 4/8] MIPS: KVM: Add kvm_asid_change " James Hogan
2016-06-14  8:40 ` [PATCH 5/8] MIPS: KVM: Add guest mode switch trace events James Hogan
2016-06-17 14:08   ` Steven Rostedt
2016-06-17 14:29     ` Paolo Bonzini
2016-06-17 14:58       ` James Hogan
2016-06-17 15:35         ` Steven Rostedt
2016-06-14  8:40 ` [PATCH 6/8] MIPS: KVM: Trace guest register access emulation James Hogan
2016-06-14  8:40 ` [PATCH 7/8] MIPS: KVM: Dump guest tlbs if kvm_get_inst() fails James Hogan
2016-06-14  8:40 ` [PATCH 8/8] MIPS: KVM: Print unknown load/store encodings James Hogan

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.