[PATCH v2 2/3] RISC-V: KVM: add tracepoints for guest page faults

wang.yechao255@zte.com.cn posted 1 patch 1 month, 2 weeks ago
arch/riscv/kvm/trace.h     | 25 +++++++++++++++++++++++++
arch/riscv/kvm/vcpu_exit.c |  3 +++
2 files changed, 28 insertions(+)
[PATCH v2 2/3] RISC-V: KVM: add tracepoints for guest page faults
Posted by wang.yechao255@zte.com.cn 1 month, 2 weeks ago
From: Wang Yechao <wang.yechao255@zte.com.cn>

Add the kvm_page_fault event tracepoints to count the number of KVM
guest page faults.

Signed-off-by: Wang Yechao <wang.yechao255@zte.com.cn>
---
 arch/riscv/kvm/trace.h     | 25 +++++++++++++++++++++++++
 arch/riscv/kvm/vcpu_exit.c |  3 +++
 2 files changed, 28 insertions(+)

diff --git a/arch/riscv/kvm/trace.h b/arch/riscv/kvm/trace.h
index 3d54175d805c..9056cc9883cf 100644
--- a/arch/riscv/kvm/trace.h
+++ b/arch/riscv/kvm/trace.h
@@ -56,6 +56,31 @@ TRACE_EVENT(kvm_exit,
 		__entry->htinst)
 );
 
+/*
+ * Tracepoint for page fault.
+ */
+TRACE_EVENT(kvm_page_fault,
+	TP_PROTO(struct kvm_vcpu *vcpu, u64 fault_address, u64 error_code),
+	TP_ARGS(vcpu, fault_address, error_code),
+
+	TP_STRUCT__entry(
+		__field(unsigned int,   vcpu_id)
+		__field(u64,            fault_address)
+		__field(u64,            error_code)
+	),
+
+	TP_fast_assign(
+		__entry->vcpu_id        = vcpu->vcpu_id;
+		__entry->fault_address  = fault_address;
+		__entry->error_code     = error_code;
+	),
+
+	TP_printk("vcpu %u address 0x%016llx error_code 0x%llx",
+		__entry->vcpu_id,
+		__entry->fault_address,
+		__entry->error_code)
+);
+
 #endif /* _TRACE_RSICV_KVM_H */
 
 #undef TRACE_INCLUDE_PATH
diff --git a/arch/riscv/kvm/vcpu_exit.c b/arch/riscv/kvm/vcpu_exit.c
index 0bb0c51e3c89..0cfb0149da9f 100644
--- a/arch/riscv/kvm/vcpu_exit.c
+++ b/arch/riscv/kvm/vcpu_exit.c
@@ -11,6 +11,7 @@
 #include <asm/insn-def.h>
 #include <asm/kvm_mmu.h>
 #include <asm/kvm_nacl.h>
+#include "trace.h"
 
 static int gstage_page_fault(struct kvm_vcpu *vcpu, struct kvm_run *run,
 			     struct kvm_cpu_trap *trap)
@@ -43,6 +44,8 @@ static int gstage_page_fault(struct kvm_vcpu *vcpu, struct kvm_run *run,
 		};
 	}
 
+	trace_kvm_page_fault(vcpu, fault_addr, trap->scause);
+
 	ret = kvm_riscv_mmu_map(vcpu, memslot, fault_addr, hva,
 				(trap->scause == EXC_STORE_GUEST_PAGE_FAULT) ? true : false,
 				&host_map);
-- 
2.43.5
Re:  [PATCH v2 2/3] RISC-V: KVM: add tracepoints for guest page faults
Posted by Anup Patel 2 weeks, 1 day ago
On Wed, Apr 29, 2026 at 3:05 PM <wang.yechao255@zte.com.cn> wrote:
>
> From: Wang Yechao <wang.yechao255@zte.com.cn>
>
>
> Add the kvm_page_fault event tracepoints to count the number of KVM
>
> guest page faults.
>
>
> Signed-off-by: Wang Yechao <wang.yechao255@zte.com.cn>

Lot of redundant newlines in this patch. Looks like this patch
was not sent using "git send-email".

Regards,
Anup


>
> ---
>
>  arch/riscv/kvm/trace.h     | 25 +++++++++++++++++++++++++
>
>  arch/riscv/kvm/vcpu_exit.c |  3 +++
>
>  2 files changed, 28 insertions(+)
>
>
> diff --git a/arch/riscv/kvm/trace.h b/arch/riscv/kvm/trace.h
>
> index 3d54175d805c..9056cc9883cf 100644
>
> --- a/arch/riscv/kvm/trace.h
>
> +++ b/arch/riscv/kvm/trace.h
>
> @@ -56,6 +56,31 @@ TRACE_EVENT(kvm_exit,
>
>   __entry->htinst)
>
>  );
>
>
>
> +/*
>
> + * Tracepoint for page fault.
>
> + */
>
> +TRACE_EVENT(kvm_page_fault,
>
> + TP_PROTO(struct kvm_vcpu *vcpu, u64 fault_address, u64 error_code),
>
> + TP_ARGS(vcpu, fault_address, error_code),
>
> +
>
> + TP_STRUCT__entry(
>
> + __field(unsigned int,   vcpu_id)
>
> + __field(u64,            fault_address)
>
> + __field(u64,            error_code)
>
> + ),
>
> +
>
> + TP_fast_assign(
>
> + __entry->vcpu_id        = vcpu->vcpu_id;
>
> + __entry->fault_address  = fault_address;
>
> + __entry->error_code     = error_code;
>
> + ),
>
> +
>
> + TP_printk("vcpu %u address 0x%016llx error_code 0x%llx",
>
> + __entry->vcpu_id,
>
> + __entry->fault_address,
>
> + __entry->error_code)
>
> +);
>
> +
>
>  #endif /* _TRACE_RSICV_KVM_H */
>
>
>
>  #undef TRACE_INCLUDE_PATH
>
> diff --git a/arch/riscv/kvm/vcpu_exit.c b/arch/riscv/kvm/vcpu_exit.c
>
> index 0bb0c51e3c89..0cfb0149da9f 100644
>
> --- a/arch/riscv/kvm/vcpu_exit.c
>
> +++ b/arch/riscv/kvm/vcpu_exit.c
>
> @@ -11,6 +11,7 @@
>
>  #include <asm/insn-def.h>
>
>  #include <asm/kvm_mmu.h>
>
>  #include <asm/kvm_nacl.h>
>
> +#include "trace.h"
>
>
>
>  static int gstage_page_fault(struct kvm_vcpu *vcpu, struct kvm_run *run,
>
>        struct kvm_cpu_trap *trap)
>
> @@ -43,6 +44,8 @@ static int gstage_page_fault(struct kvm_vcpu *vcpu, struct kvm_run *run,
>
>   };
>
>   }
>
>
>
> + trace_kvm_page_fault(vcpu, fault_addr, trap->scause);
>
> +
>
>   ret = kvm_riscv_mmu_map(vcpu, memslot, fault_addr, hva,
>
>   (trap->scause == EXC_STORE_GUEST_PAGE_FAULT) ? true : false,
>
>   &host_map);
>
> --
>
> 2.43.5
>
>
>
>
>
>
Re:  [PATCH v2 2/3] RISC-V: KVM: add tracepoints for guest page faults
Posted by wang.yechao255@zte.com.cn 2 weeks, 1 day ago
> > From: Wang Yechao <wang.yechao255@zte.com.cn>
> >
> >
> > Add the kvm_page_fault event tracepoints to count the number of KVM
> >
> > guest page faults.
> >
> >
> > Signed-off-by: Wang Yechao <wang.yechao255@zte.com.cn>
> 
> Lot of redundant newlines in this patch. Looks like this patch
> was not sent using "git send-email".
> 
Sorry for the messy formatting. I'll resend the patch properly with git send-email
in the next version.

Best regards,
Yechao

> Regards,
> Anup