Commit 2de32a25 authored by Marc Zyngier's avatar Marc Zyngier
Browse files

Merge branch kvm-arm64/hyp-tracing into kvmarm-master/next



* kvm-arm64/hyp-tracing: (40 commits)
  : .
  : EL2 tracing support, adding both 'remote' ring-buffer
  : infrastructure and the tracing itself, courtesy of
  : Vincent Donnefort. From the cover letter:
  :
  : "The growing set of features supported by the hypervisor in protected
  : mode necessitates debugging and profiling tools. Tracefs is the
  : ideal candidate for this task:
  :
  :   * It is simple to use and to script.
  :
  :   * It is supported by various tools, from the trace-cmd CLI to the
  :     Android web-based perfetto.
  :
  :   * The ring-buffer, where are stored trace events consists of linked
  :     pages, making it an ideal structure for sharing between kernel and
  :     hypervisor.
  :
  : This series first introduces a new generic way of creating remote events and
  : remote buffers. Then it adds support to the pKVM hypervisor."
  : .
  tracing: selftests: Extend hotplug testing for trace remotes
  tracing: Non-consuming read for trace remotes with an offline CPU
  tracing: Adjust cmd_check_undefined to show unexpected undefined symbols
  tracing: Restore accidentally removed SPDX tag
  KVM: arm64: avoid unused-variable warning
  tracing: Generate undef symbols allowlist for simple_ring_buffer
  KVM: arm64: tracing: add ftrace dependency
  tracing: add more symbols to whitelist
  tracing: Update undefined symbols allow list for simple_ring_buffer
  KVM: arm64: Fix out-of-tree build for nVHE/pKVM tracing
  tracing: selftests: Add hypervisor trace remote tests
  KVM: arm64: Add selftest event support to nVHE/pKVM hyp
  KVM: arm64: Add hyp_enter/hyp_exit events to nVHE/pKVM hyp
  KVM: arm64: Add event support to the nVHE/pKVM hyp and trace remote
  KVM: arm64: Add trace reset to the nVHE/pKVM hyp
  KVM: arm64: Sync boot clock with the nVHE/pKVM hyp
  KVM: arm64: Add trace remote for the nVHE/pKVM hyp
  KVM: arm64: Add tracing capability for the nVHE/pKVM hyp
  KVM: arm64: Support unaligned fixmap in the pKVM hyp
  KVM: arm64: Initialise hyp_nr_cpus for nVHE hyp
  ...

Signed-off-by: default avatarMarc Zyngier <maz@kernel.org>
parents f338e773 ec07906b
Loading
Loading
Loading
Loading
+11 −0
Original line number Diff line number Diff line
@@ -91,6 +91,17 @@ interactions.
   user_events
   uprobetracer

Remote Tracing
--------------

This section covers the framework to read compatible ring-buffers, written by
entities outside of the kernel (most likely firmware or hypervisor)

.. toctree::
   :maxdepth: 1

   remotes

Additional Resources
--------------------

+66 −0
Original line number Diff line number Diff line
.. SPDX-License-Identifier: GPL-2.0

===============
Tracing Remotes
===============

:Author: Vincent Donnefort <vdonnefort@google.com>

Overview
========
Firmware and hypervisors are black boxes to the kernel. Having a way to see what
they are doing can be useful to debug both. This is where remote tracing buffers
come in. A remote tracing buffer is a ring buffer executed by the firmware or
hypervisor into memory that is memory mapped to the host kernel. This is similar
to how user space memory maps the kernel ring buffer but in this case the kernel
is acting like user space and the firmware or hypervisor is the "kernel" side.
With a trace remote ring buffer, the firmware and hypervisor can record events
for which the host kernel can see and expose to user space.

Register a remote
=================
A remote must provide a set of callbacks `struct trace_remote_callbacks` whom
description can be found below. Those callbacks allows Tracefs to enable and
disable tracing and events, to load and unload a tracing buffer (a set of
ring-buffers) and to swap a reader page with the head page, which enables
consuming reading.

.. kernel-doc:: include/linux/trace_remote.h

Once registered, an instance will appear for this remote in the Tracefs
directory **remotes/**. Buffers can then be read using the usual Tracefs files
**trace_pipe** and **trace**.

Declare a remote event
======================
Macros are provided to ease the declaration of remote events, in a similar
fashion to in-kernel events. A declaration must provide an ID, a description of
the event arguments and how to print the event:

.. code-block:: c

	REMOTE_EVENT(foo, EVENT_FOO_ID,
		RE_STRUCT(
			re_field(u64, bar)
		),
		RE_PRINTK("bar=%lld", __entry->bar)
	);

Then those events must be declared in a C file with the following:

.. code-block:: c

	#define REMOTE_EVENT_INCLUDE_FILE foo_events.h
	#include <trace/define_remote_events.h>

This will provide a `struct remote_event remote_event_foo` that can be given to
`trace_remote_register`.

Registered events appear in the remote directory under **events/**.

Simple ring-buffer
==================
A simple implementation for a ring-buffer writer can be found in
kernel/trace/simple_ring_buffer.c.

.. kernel-doc:: include/linux/simple_ring_buffer.h
+8 −0
Original line number Diff line number Diff line
@@ -89,6 +89,14 @@ 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,
	__KVM_HOST_SMCCC_FUNC___tracing_update_clock,
	__KVM_HOST_SMCCC_FUNC___tracing_reset,
	__KVM_HOST_SMCCC_FUNC___tracing_enable_event,
	__KVM_HOST_SMCCC_FUNC___tracing_write_event,
};

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

#define REMOTE_EVENT_INCLUDE_FILE arch/arm64/include/asm/kvm_hypevents.h

#define REMOTE_EVENT_SECTION "_hyp_events"

#define HE_STRUCT(__args)		__args
#define HE_PRINTK(__args...)		__args
#define he_field			re_field

#define HYP_EVENT(__name, __proto, __struct, __assign, __printk) \
	REMOTE_EVENT(__name, 0, RE_STRUCT(__struct), RE_PRINTK(__printk))

#define HYP_EVENT_MULTI_READ
#include <trace/define_remote_events.h>
#undef HYP_EVENT_MULTI_READ
+3 −0
Original line number Diff line number Diff line
@@ -923,6 +923,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;
};

/*
Loading