[PATCH v2 4/5] KVM: arm64: Add guest_hvc hyp event

Vincent Donnefort vdonnefort at google.com
Wed Nov 4 06:06:11 PST 2026


Protected VMs issue HVCs that are fully handled by the hypervisor. This
makes a failure hard to debug solely based on host information. Create a
guest_hvc hypervisor event for hypervisor handled HVCs and log the
return value, stored in x0.

Signed-off-by: Vincent Donnefort <vdonnefort at google.com>
---
 arch/arm64/include/asm/kvm_hypevents.h | 13 +++++++++++++
 arch/arm64/kvm/hyp/nvhe/pkvm.c         | 12 ++++++++++--
 2 files changed, 23 insertions(+), 2 deletions(-)

diff --git a/arch/arm64/include/asm/kvm_hypevents.h b/arch/arm64/include/asm/kvm_hypevents.h
index 7486d95455c5..63d98dd92cb0 100644
--- a/arch/arm64/include/asm/kvm_hypevents.h
+++ b/arch/arm64/include/asm/kvm_hypevents.h
@@ -66,6 +66,19 @@ HYP_EVENT(selftest,
 	RE_PRINTK("id=%llu", __entry->id)
 );
 
+HYP_EVENT(guest_hvc,
+	HE_PROTO(u32 id, u64 x0),
+	HE_STRUCT(
+		he_field(u32, id)
+		he_field(u64, x0)
+	),
+	HE_ASSIGN(
+		__entry->id = id;
+		__entry->x0 = x0;
+	),
+	HE_PRINTK("id=0x%x x0=0x%llx", __entry->id, __entry->x0)
+);
+
 /*
  * trace_hyp_printk() has too many specificities to be declared with HYP_EVENT().
  * However, we can use a REMOTE_EVENT macro to automatically do the declaration
diff --git a/arch/arm64/kvm/hyp/nvhe/pkvm.c b/arch/arm64/kvm/hyp/nvhe/pkvm.c
index fc0475f0877d..df7bd34325de 100644
--- a/arch/arm64/kvm/hyp/nvhe/pkvm.c
+++ b/arch/arm64/kvm/hyp/nvhe/pkvm.c
@@ -11,6 +11,7 @@
 #include <linux/mm.h>
 
 #include <asm/kvm_emulate.h>
+#include <asm/kvm_hypevents.h>
 #include <asm/spectre.h>
 
 #include <nvhe/alloc.h>
@@ -1445,11 +1446,12 @@ bool kvm_handle_pvm_hvc64(struct kvm_vcpu *vcpu, u64 *exit_code)
 {
 	struct pkvm_hyp_vcpu *hyp_vcpu = container_of(vcpu, struct pkvm_hyp_vcpu, vcpu);
 	u64 val[4] = { SMCCC_RET_INVALID_PARAMETER };
+	u32 fn = smccc_get_function(vcpu);
 	bool handled = true;
 	u32 feature;
 	uuid_t uuid;
 
-	switch (smccc_get_function(vcpu)) {
+	switch (fn) {
 	case ARM_SMCCC_VERSION_FUNC_ID:
 		/* Nothing to be handled by the host. Go back to the guest. */
 		val[0] = ARM_SMCCC_VERSION_1_1;
@@ -1542,10 +1544,16 @@ bool kvm_handle_pvm_hvc64(struct kvm_vcpu *vcpu, u64 *exit_code)
 		pkvm_memunshare_call(val, vcpu);
 		break;
 	default:
-		return pkvm_handle_psci(hyp_vcpu);
+		handled = pkvm_handle_psci(hyp_vcpu);
+		goto out;
 	}
 
 	if (handled)
 		smccc_set_retval(vcpu, val[0], val[1], val[2], val[3]);
+
+out:
+	if (handled)
+		trace_guest_hvc(fn, vcpu_get_reg(vcpu, 0));
+
 	return handled;
 }
-- 
2.56.0.455.g6c5a503b38-goog




More information about the linux-arm-kernel mailing list