Commit 696dfec2 authored by Vincent Donnefort's avatar Vincent Donnefort Committed by Marc Zyngier
Browse files

KVM: arm64: Add hyp_enter/hyp_exit events to nVHE/pKVM hyp



The hyp_enter and hyp_exit events are logged by the hypervisor any time
it is entered and exited.

Signed-off-by: default avatarVincent Donnefort <vdonnefort@google.com>
Link: https://patch.msgid.link/20260309162516.2623589-29-vdonnefort@google.com


Signed-off-by: default avatarMarc Zyngier <maz@kernel.org>
parent 0a90fbc8
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -920,6 +920,9 @@ struct kvm_vcpu_arch {

	/* Per-vcpu TLB for VNCR_EL2 -- NULL when !NV */
	struct vncr_tlb	*vncr_tlb;

	/* Hyp-readable copy of kvm_vcpu::pid */
	pid_t pid;
};

/*
+39 −0
Original line number Diff line number Diff line
@@ -7,4 +7,43 @@
#include <nvhe/trace.h>
#endif

#ifndef __HYP_ENTER_EXIT_REASON
#define __HYP_ENTER_EXIT_REASON
enum hyp_enter_exit_reason {
	HYP_REASON_SMC,
	HYP_REASON_HVC,
	HYP_REASON_PSCI,
	HYP_REASON_HOST_ABORT,
	HYP_REASON_GUEST_EXIT,
	HYP_REASON_ERET_HOST,
	HYP_REASON_ERET_GUEST,
	HYP_REASON_UNKNOWN	/* Must be last */
};
#endif

HYP_EVENT(hyp_enter,
	HE_PROTO(struct kvm_cpu_context *host_ctxt, u8 reason),
	HE_STRUCT(
		he_field(u8, reason)
		he_field(pid_t, vcpu)
	),
	HE_ASSIGN(
		__entry->reason = reason;
		__entry->vcpu = __tracing_get_vcpu_pid(host_ctxt);
	),
	HE_PRINTK("reason=%s vcpu=%d", __hyp_enter_exit_reason_str(__entry->reason), __entry->vcpu)
);

HYP_EVENT(hyp_exit,
	HE_PROTO(struct kvm_cpu_context *host_ctxt, u8 reason),
	HE_STRUCT(
		he_field(u8, reason)
		he_field(pid_t, vcpu)
	),
	HE_ASSIGN(
		__entry->reason = reason;
		__entry->vcpu = __tracing_get_vcpu_pid(host_ctxt);
	),
	HE_PRINTK("reason=%s vcpu=%d", __hyp_enter_exit_reason_str(__entry->reason), __entry->vcpu)
);
#endif
+2 −0
Original line number Diff line number Diff line
@@ -707,6 +707,8 @@ void kvm_arch_vcpu_load(struct kvm_vcpu *vcpu, int cpu)

	if (!cpumask_test_cpu(cpu, vcpu->kvm->arch.supported_cpus))
		vcpu_set_on_unsupported_cpu(vcpu);

	vcpu->arch.pid = pid_nr(vcpu->pid);
}

void kvm_arch_vcpu_put(struct kvm_vcpu *vcpu)
+23 −0
Original line number Diff line number Diff line
/* SPDX-License-Identifier: GPL-2.0-only */
#ifndef __ARM64_KVM_HYP_NVHE_ARM_SMCCC_H__
#define __ARM64_KVM_HYP_NVHE_ARM_SMCCC_H__

#include <asm/kvm_hypevents.h>

#include <linux/arm-smccc.h>

#define hyp_smccc_1_1_smc(...)					\
	do {							\
		trace_hyp_exit(NULL, HYP_REASON_SMC);		\
		arm_smccc_1_1_smc(__VA_ARGS__);			\
		trace_hyp_enter(NULL, HYP_REASON_SMC);		\
	} while (0)

#define hyp_smccc_1_2_smc(...)					\
	do {							\
		trace_hyp_exit(NULL, HYP_REASON_SMC);		\
		arm_smccc_1_2_smc(__VA_ARGS__);			\
		trace_hyp_enter(NULL, HYP_REASON_SMC);		\
	} while (0)

#endif /* __ARM64_KVM_HYP_NVHE_ARM_SMCCC_H__ */
+12 −0
Original line number Diff line number Diff line
@@ -6,6 +6,18 @@

#include <asm/kvm_hyptrace.h>

static inline pid_t __tracing_get_vcpu_pid(struct kvm_cpu_context *host_ctxt)
{
	struct kvm_vcpu *vcpu;

	if (!host_ctxt)
		host_ctxt = host_data_ptr(host_ctxt);

	vcpu = host_ctxt->__hyp_running_vcpu;

	return vcpu ? vcpu->arch.pid : 0;
}

#define HE_PROTO(__args...)	__args
#define HE_ASSIGN(__args...)	__args
#define HE_STRUCT		RE_STRUCT
Loading