[PATCH v1 2/3] KVM: arm64: Add guest_hvc hyp event

Vincent Donnefort vdonnefort at google.com
Fri Oct 9 01:45:28 PDT 2026


Add a guest_hvc hypervisor trace event to log protected VM HVC call IDs,
return values, and whether the call was handled by the hypervisor.

Signed-off-by: Vincent Donnefort <vdonnefort at google.com>
---
 arch/arm64/include/asm/kvm_hypevents.h | 16 ++++++++++++++++
 arch/arm64/kvm/hyp/nvhe/pkvm.c         |  7 ++++++-
 2 files changed, 22 insertions(+), 1 deletion(-)

diff --git a/arch/arm64/include/asm/kvm_hypevents.h b/arch/arm64/include/asm/kvm_hypevents.h
index 96985c93a15e..c1239d78c8f9 100644
--- a/arch/arm64/include/asm/kvm_hypevents.h
+++ b/arch/arm64/include/asm/kvm_hypevents.h
@@ -59,4 +59,20 @@ HYP_EVENT(selftest,
 	),
 	RE_PRINTK("id=%llu", __entry->id)
 );
+
+HYP_EVENT(guest_hvc,
+	HE_PROTO(u32 id, u64 val, u8 handled),
+	HE_STRUCT(
+		he_field(u8, handled)
+		he_field(u32, id)
+		he_field(u64, val)
+	),
+	HE_ASSIGN(
+		__entry->id = id;
+		__entry->val = val;
+		__entry->handled = handled;
+	),
+	HE_PRINTK("id=0x%x val=0x%llx handled=%u",
+		  __entry->id, __entry->val, __entry->handled)
+);
 #endif
diff --git a/arch/arm64/kvm/hyp/nvhe/pkvm.c b/arch/arm64/kvm/hyp/nvhe/pkvm.c
index 6290c4b62659..0deed0622677 100644
--- a/arch/arm64/kvm/hyp/nvhe/pkvm.c
+++ b/arch/arm64/kvm/hyp/nvhe/pkvm.c
@@ -10,6 +10,7 @@
 #include <linux/mm.h>
 
 #include <asm/kvm_emulate.h>
+#include <asm/kvm_hypevents.h>
 
 #include <nvhe/mem_protect.h>
 #include <nvhe/memory.h>
@@ -1142,9 +1143,10 @@ static void pkvm_memunshare_call(u64 *ret, struct kvm_vcpu *vcpu)
 bool kvm_handle_pvm_hvc64(struct kvm_vcpu *vcpu, u64 *exit_code)
 {
 	u64 val[4] = { SMCCC_RET_INVALID_PARAMETER };
+	u32 fn = smccc_get_function(vcpu);
 	bool handled = true;
 
-	switch (smccc_get_function(vcpu)) {
+	switch (fn) {
 	case ARM_SMCCC_VENDOR_HYP_KVM_FEATURES_FUNC_ID:
 		val[0] = BIT(ARM_SMCCC_KVM_FUNC_FEATURES);
 		val[0] |= BIT(ARM_SMCCC_KVM_FUNC_HYP_MEMINFO);
@@ -1183,5 +1185,8 @@ bool kvm_handle_pvm_hvc64(struct kvm_vcpu *vcpu, u64 *exit_code)
 
 	if (handled)
 		smccc_set_retval(vcpu, val[0], val[1], val[2], val[3]);
+
+	trace_guest_hvc(fn, val[0], handled);
+
 	return handled;
 }
-- 
2.56.0.385.gd3acb90ef8-goog




More information about the linux-arm-kernel mailing list