Commit 680a04c3 authored by Vincent Donnefort's avatar Vincent Donnefort Committed by Marc Zyngier
Browse files

KVM: arm64: Add tracing capability for the nVHE/pKVM hyp



There is currently no way to inspect or log what's happening at EL2
when the nVHE or pKVM hypervisor is used. With the growing set of
features for pKVM, the need for tooling is more pressing. And tracefs,
by its reliability, versatility and support for user-space is fit for
purpose.

Add support to write into a tracefs compatible ring-buffer. There's no
way the hypervisor could log events directly into the host tracefs
ring-buffers. So instead let's use our own, where the hypervisor is the
writer and the host the reader.

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


Signed-off-by: default avatarMarc Zyngier <maz@kernel.org>
parent 4cdf8dec
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -89,6 +89,10 @@ enum __kvm_host_smccc_func {
	__KVM_HOST_SMCCC_FUNC___pkvm_vcpu_load,
	__KVM_HOST_SMCCC_FUNC___pkvm_vcpu_put,
	__KVM_HOST_SMCCC_FUNC___pkvm_tlb_flush_vmid,
	__KVM_HOST_SMCCC_FUNC___tracing_load,
	__KVM_HOST_SMCCC_FUNC___tracing_unload,
	__KVM_HOST_SMCCC_FUNC___tracing_enable,
	__KVM_HOST_SMCCC_FUNC___tracing_swap_reader,
};

#define DECLARE_KVM_VHE_SYM(sym)	extern char sym[]
+13 −0
Original line number Diff line number Diff line
/* SPDX-License-Identifier: GPL-2.0-only */
#ifndef __ARM64_KVM_HYPTRACE_H_
#define __ARM64_KVM_HYPTRACE_H_

#include <linux/ring_buffer.h>

struct hyp_trace_desc {
	unsigned long			bpages_backing_start;
	size_t				bpages_backing_size;
	struct trace_buffer_desc	trace_buffer_desc;

};
#endif
+5 −0
Original line number Diff line number Diff line
@@ -72,6 +72,11 @@ config NVHE_EL2_DEBUG

if NVHE_EL2_DEBUG

config NVHE_EL2_TRACING
	bool
	depends on TRACING
	default y

config PKVM_DISABLE_STAGE2_ON_PANIC
	bool "Disable the host stage-2 on panic"
	default n
+23 −0
Original line number Diff line number Diff line
/* SPDX-License-Identifier: GPL-2.0-only */
#ifndef __ARM64_KVM_HYP_NVHE_TRACE_H
#define __ARM64_KVM_HYP_NVHE_TRACE_H
#include <asm/kvm_hyptrace.h>

#ifdef CONFIG_NVHE_EL2_TRACING
void *tracing_reserve_entry(unsigned long length);
void tracing_commit_entry(void);

int __tracing_load(unsigned long desc_va, size_t desc_size);
void __tracing_unload(void);
int __tracing_enable(bool enable);
int __tracing_swap_reader(unsigned int cpu);
#else
static inline void *tracing_reserve_entry(unsigned long length) { return NULL; }
static inline void tracing_commit_entry(void) { }

static inline int __tracing_load(unsigned long desc_va, size_t desc_size) { return -ENODEV; }
static inline void __tracing_unload(void) { }
static inline int __tracing_enable(bool enable) { return -ENODEV; }
static inline int __tracing_swap_reader(unsigned int cpu) { return -ENODEV; }
#endif
#endif
+4 −1
Original line number Diff line number Diff line
@@ -29,9 +29,12 @@ hyp-obj-y += ../vgic-v3-sr.o ../aarch32.o ../vgic-v2-cpuif-proxy.o ../entry.o \
	 ../fpsimd.o ../hyp-entry.o ../exception.o ../pgtable.o
hyp-obj-y += ../../../kernel/smccc-call.o
hyp-obj-$(CONFIG_LIST_HARDENED) += list_debug.o
hyp-obj-$(CONFIG_NVHE_EL2_TRACING) += clock.o
hyp-obj-$(CONFIG_NVHE_EL2_TRACING) += clock.o trace.o
hyp-obj-y += $(lib-objs)

# Path to simple_ring_buffer.c
CFLAGS_trace.nvhe.o += -I$(objtree)/kernel/trace/

##
## Build rules for compiling nVHE hyp code
## Output of this folder is `kvm_nvhe.o`, a partially linked object
Loading