Skip to content

Commit 7b7e584

Browse files
bibo-maochenhuacai
authored andcommitted
LoongArch: KVM: Add mmio trace events support
Add mmio trace events support, currently generic mmio events KVM_TRACE_MMIO_WRITE/xxx_READ/xx_READ_UNSATISFIED are added here. Also vcpu id field is added for all kvm trace events, since perf KVM tool parses vcpu id information for kvm entry event. Signed-off-by: Bibo Mao <[email protected]> Signed-off-by: Huacai Chen <[email protected]>
1 parent 163e9fc commit 7b7e584

File tree

2 files changed

+22
-6
lines changed

2 files changed

+22
-6
lines changed

arch/loongarch/kvm/exit.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include <linux/module.h>
1010
#include <linux/preempt.h>
1111
#include <linux/vmalloc.h>
12+
#include <trace/events/kvm.h>
1213
#include <asm/fpu.h>
1314
#include <asm/inst.h>
1415
#include <asm/loongarch.h>
@@ -441,6 +442,8 @@ int kvm_emu_mmio_read(struct kvm_vcpu *vcpu, larch_inst inst)
441442
vcpu->arch.io_gpr = rd;
442443
run->mmio.is_write = 0;
443444
vcpu->mmio_is_write = 0;
445+
trace_kvm_mmio(KVM_TRACE_MMIO_READ_UNSATISFIED, run->mmio.len,
446+
run->mmio.phys_addr, NULL);
444447
} else {
445448
kvm_err("Read not supported Inst=0x%08x @%lx BadVaddr:%#lx\n",
446449
inst.word, vcpu->arch.pc, vcpu->arch.badv);
@@ -487,6 +490,9 @@ int kvm_complete_mmio_read(struct kvm_vcpu *vcpu, struct kvm_run *run)
487490
break;
488491
}
489492

493+
trace_kvm_mmio(KVM_TRACE_MMIO_READ, run->mmio.len,
494+
run->mmio.phys_addr, run->mmio.data);
495+
490496
return er;
491497
}
492498

@@ -588,6 +594,8 @@ int kvm_emu_mmio_write(struct kvm_vcpu *vcpu, larch_inst inst)
588594
run->mmio.is_write = 1;
589595
vcpu->mmio_needed = 1;
590596
vcpu->mmio_is_write = 1;
597+
trace_kvm_mmio(KVM_TRACE_MMIO_WRITE, run->mmio.len,
598+
run->mmio.phys_addr, data);
591599
} else {
592600
vcpu->arch.pc = curr_pc;
593601
kvm_err("Write not supported Inst=0x%08x @%lx BadVaddr:%#lx\n",

arch/loongarch/kvm/trace.h

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,16 @@ DECLARE_EVENT_CLASS(kvm_transition,
1919
TP_PROTO(struct kvm_vcpu *vcpu),
2020
TP_ARGS(vcpu),
2121
TP_STRUCT__entry(
22+
__field(unsigned int, vcpu_id)
2223
__field(unsigned long, pc)
2324
),
2425

2526
TP_fast_assign(
27+
__entry->vcpu_id = vcpu->vcpu_id;
2628
__entry->pc = vcpu->arch.pc;
2729
),
2830

29-
TP_printk("PC: 0x%08lx", __entry->pc)
31+
TP_printk("vcpu %u PC: 0x%08lx", __entry->vcpu_id, __entry->pc)
3032
);
3133

3234
DEFINE_EVENT(kvm_transition, kvm_enter,
@@ -54,19 +56,22 @@ DECLARE_EVENT_CLASS(kvm_exit,
5456
TP_PROTO(struct kvm_vcpu *vcpu, unsigned int reason),
5557
TP_ARGS(vcpu, reason),
5658
TP_STRUCT__entry(
59+
__field(unsigned int, vcpu_id)
5760
__field(unsigned long, pc)
5861
__field(unsigned int, reason)
5962
),
6063

6164
TP_fast_assign(
65+
__entry->vcpu_id = vcpu->vcpu_id;
6266
__entry->pc = vcpu->arch.pc;
6367
__entry->reason = reason;
6468
),
6569

66-
TP_printk("[%s]PC: 0x%08lx",
67-
__print_symbolic(__entry->reason,
68-
kvm_trace_symbol_exit_types),
69-
__entry->pc)
70+
TP_printk("vcpu %u [%s] PC: 0x%08lx",
71+
__entry->vcpu_id,
72+
__print_symbolic(__entry->reason,
73+
kvm_trace_symbol_exit_types),
74+
__entry->pc)
7075
);
7176

7277
DEFINE_EVENT(kvm_exit, kvm_exit_idle,
@@ -85,14 +90,17 @@ TRACE_EVENT(kvm_exit_gspr,
8590
TP_PROTO(struct kvm_vcpu *vcpu, unsigned int inst_word),
8691
TP_ARGS(vcpu, inst_word),
8792
TP_STRUCT__entry(
93+
__field(unsigned int, vcpu_id)
8894
__field(unsigned int, inst_word)
8995
),
9096

9197
TP_fast_assign(
98+
__entry->vcpu_id = vcpu->vcpu_id;
9299
__entry->inst_word = inst_word;
93100
),
94101

95-
TP_printk("Inst word: 0x%08x", __entry->inst_word)
102+
TP_printk("vcpu %u Inst word: 0x%08x", __entry->vcpu_id,
103+
__entry->inst_word)
96104
);
97105

98106
#define KVM_TRACE_AUX_SAVE 0

0 commit comments

Comments
 (0)