arm64: KVM: Add trapped system register access tracepoint
authorMarc Zyngier <marc.zyngier@arm.com>
Tue, 4 Dec 2018 10:44:22 +0000 (10:44 +0000)
committerMarc Zyngier <marc.zyngier@arm.com>
Wed, 19 Dec 2018 17:47:08 +0000 (17:47 +0000)
We're pretty blind when it comes to system register tracing,
and rely on the ESR value displayed by kvm_handle_sys, which
isn't much.

Instead, let's add an actual name to the sysreg entries, so that
we can finally print it as we're about to perform the access
itself.

The new tracepoint is conveniently called kvm_sys_access.

Signed-off-by: Marc Zyngier <marc.zyngier@arm.com>
arch/arm64/kvm/sys_regs.c
arch/arm64/kvm/sys_regs.h
arch/arm64/kvm/trace.h

index 965c6f1..a1f57fc 100644 (file)
@@ -1850,6 +1850,8 @@ static void perform_access(struct kvm_vcpu *vcpu,
                           struct sys_reg_params *params,
                           const struct sys_reg_desc *r)
 {
+       trace_kvm_sys_access(*vcpu_pc(vcpu), params, r);
+
        /*
         * Not having an accessor means that we have configured a trap
         * that we don't know how to handle. This certainly qualifies
index cd710f8..3b1bc7f 100644 (file)
@@ -35,6 +35,9 @@ struct sys_reg_params {
 };
 
 struct sys_reg_desc {
+       /* Sysreg string for debug */
+       const char *name;
+
        /* MRS/MSR instruction which accesses it. */
        u8      Op0;
        u8      Op1;
@@ -130,6 +133,7 @@ const struct sys_reg_desc *find_reg_by_id(u64 id,
 #define Op2(_x)        .Op2 = _x
 
 #define SYS_DESC(reg)                                  \
+       .name = #reg,                                   \
        Op0(sys_reg_Op0(reg)), Op1(sys_reg_Op1(reg)),   \
        CRn(sys_reg_CRn(reg)), CRm(sys_reg_CRm(reg)),   \
        Op2(sys_reg_Op2(reg))
index 3b82fb1..eab91ad 100644 (file)
@@ -3,6 +3,7 @@
 #define _TRACE_ARM64_KVM_H
 
 #include <linux/tracepoint.h>
+#include "sys_regs.h"
 
 #undef TRACE_SYSTEM
 #define TRACE_SYSTEM kvm
@@ -152,6 +153,40 @@ TRACE_EVENT(kvm_handle_sys_reg,
        TP_printk("HSR 0x%08lx", __entry->hsr)
 );
 
+TRACE_EVENT(kvm_sys_access,
+       TP_PROTO(unsigned long vcpu_pc, struct sys_reg_params *params, const struct sys_reg_desc *reg),
+       TP_ARGS(vcpu_pc, params, reg),
+
+       TP_STRUCT__entry(
+               __field(unsigned long,                  vcpu_pc)
+               __field(bool,                           is_write)
+               __field(const char *,                   name)
+               __field(u8,                             Op0)
+               __field(u8,                             Op1)
+               __field(u8,                             CRn)
+               __field(u8,                             CRm)
+               __field(u8,                             Op2)
+       ),
+
+       TP_fast_assign(
+               __entry->vcpu_pc = vcpu_pc;
+               __entry->is_write = params->is_write;
+               __entry->name = reg->name;
+               __entry->Op0 = reg->Op0;
+               __entry->Op0 = reg->Op0;
+               __entry->Op1 = reg->Op1;
+               __entry->CRn = reg->CRn;
+               __entry->CRm = reg->CRm;
+               __entry->Op2 = reg->Op2;
+       ),
+
+       TP_printk("PC: %lx %s (%d,%d,%d,%d,%d) %s",
+                 __entry->vcpu_pc, __entry->name ?: "UNKN",
+                 __entry->Op0, __entry->Op1, __entry->CRn,
+                 __entry->CRm, __entry->Op2,
+                 __entry->is_write ? "write" : "read")
+);
+
 TRACE_EVENT(kvm_set_guest_debug,
        TP_PROTO(struct kvm_vcpu *vcpu, __u32 guest_debug),
        TP_ARGS(vcpu, guest_debug),