Skip to content

Commit aec51dc

Browse files
committed
KVM: Trace mmio
Signed-off-by: Avi Kivity <[email protected]>
1 parent c323c0e commit aec51dc

File tree

2 files changed

+43
-1
lines changed

2 files changed

+43
-1
lines changed

arch/x86/kvm/x86.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@
3737
#include <linux/iommu.h>
3838
#include <linux/intel-iommu.h>
3939
#include <linux/cpufreq.h>
40+
#include <trace/events/kvm.h>
41+
#undef TRACE_INCLUDE_FILE
4042
#define CREATE_TRACE_POINTS
4143
#include "trace.h"
4244

@@ -2425,6 +2427,8 @@ static int emulator_read_emulated(unsigned long addr,
24252427

24262428
if (vcpu->mmio_read_completed) {
24272429
memcpy(val, vcpu->mmio_data, bytes);
2430+
trace_kvm_mmio(KVM_TRACE_MMIO_READ, bytes,
2431+
vcpu->mmio_phys_addr, *(u64 *)val);
24282432
vcpu->mmio_read_completed = 0;
24292433
return X86EMUL_CONTINUE;
24302434
}
@@ -2445,8 +2449,12 @@ static int emulator_read_emulated(unsigned long addr,
24452449
/*
24462450
* Is this MMIO handled locally?
24472451
*/
2448-
if (!vcpu_mmio_read(vcpu, gpa, bytes, val))
2452+
if (!vcpu_mmio_read(vcpu, gpa, bytes, val)) {
2453+
trace_kvm_mmio(KVM_TRACE_MMIO_READ, bytes, gpa, *(u64 *)val);
24492454
return X86EMUL_CONTINUE;
2455+
}
2456+
2457+
trace_kvm_mmio(KVM_TRACE_MMIO_READ_UNSATISFIED, bytes, gpa, 0);
24502458

24512459
vcpu->mmio_needed = 1;
24522460
vcpu->mmio_phys_addr = gpa;
@@ -2490,6 +2498,7 @@ static int emulator_write_emulated_onepage(unsigned long addr,
24902498
return X86EMUL_CONTINUE;
24912499

24922500
mmio:
2501+
trace_kvm_mmio(KVM_TRACE_MMIO_WRITE, bytes, gpa, *(u64 *)val);
24932502
/*
24942503
* Is this MMIO handled locally?
24952504
*/

include/trace/events/kvm.h

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,39 @@ TRACE_EVENT(kvm_ack_irq,
5656

5757

5858
#endif /* defined(__KVM_HAVE_IOAPIC) */
59+
60+
#define KVM_TRACE_MMIO_READ_UNSATISFIED 0
61+
#define KVM_TRACE_MMIO_READ 1
62+
#define KVM_TRACE_MMIO_WRITE 2
63+
64+
#define kvm_trace_symbol_mmio \
65+
{ KVM_TRACE_MMIO_READ_UNSATISFIED, "unsatisfied-read" }, \
66+
{ KVM_TRACE_MMIO_READ, "read" }, \
67+
{ KVM_TRACE_MMIO_WRITE, "write" }
68+
69+
TRACE_EVENT(kvm_mmio,
70+
TP_PROTO(int type, int len, u64 gpa, u64 val),
71+
TP_ARGS(type, len, gpa, val),
72+
73+
TP_STRUCT__entry(
74+
__field( u32, type )
75+
__field( u32, len )
76+
__field( u64, gpa )
77+
__field( u64, val )
78+
),
79+
80+
TP_fast_assign(
81+
__entry->type = type;
82+
__entry->len = len;
83+
__entry->gpa = gpa;
84+
__entry->val = val;
85+
),
86+
87+
TP_printk("mmio %s len %u gpa 0x%llx val 0x%llx",
88+
__print_symbolic(__entry->type, kvm_trace_symbol_mmio),
89+
__entry->len, __entry->gpa, __entry->val)
90+
);
91+
5992
#endif /* _TRACE_KVM_MAIN_H */
6093

6194
/* This part must be outside protection */

0 commit comments

Comments
 (0)