linux-trace-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [RFC PATCH 00/11] Tracefs support for pKVM
@ 2024-08-05 17:32 Vincent Donnefort
  2024-08-05 17:32 ` [RFC PATCH 01/11] ring-buffer: Check for empty ring-buffer with rb_num_of_entries() Vincent Donnefort
                   ` (11 more replies)
  0 siblings, 12 replies; 22+ messages in thread
From: Vincent Donnefort @ 2024-08-05 17:32 UTC (permalink / raw)
  To: rostedt, mhiramat, linux-trace-kernel, maz, oliver.upton
  Cc: kvmarm, will, qperret, kernel-team, Vincent Donnefort

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 introduces a method to create events and to generate them
from the hypervisor (hyp_enter/hyp_exit given as an example) as well as
a Tracefs user-space interface to read them.

A presentation was given on this matter during the tracing summit in
2022. [1]

1. ring-buffer
--------------

To setup the per-cpu ring-buffers, a new interface is created:

  ring_buffer_writer:	Describes what the kernel needs to know about the
			writer, that is, the set of pages forming the
			ring-buffer and a callback for the reader/head
			swapping (enables consuming read)

  ring_buffer_reader():	Creates a read-only ring-buffer from a
			ring_buffer_writer.

To keep the internals of `struct ring_buffer` in sync with the writer,
the meta-page is used. It was originally introduced to enable user-space
mapping of the ring-buffer [1]. In this case, the kernel is not the
producer anymore but the reader. The function to read that meta-page is:

  ring_buffer_poll_writer():
			Update `struct ring_buffer` based on the writer
			meta-page. Wake-up readers if necessary.

The kernel has to poll the meta-page to be notified of newly written
events.

2. Tracefs interface
--------------------

The interface is a hyp/ folder at the root of the tracefs mount point.
This folder is like an instance and you'll find there a subset of the
regular Tracefs user-space interface:

  hyp/
     buffer_size_kb
     trace_pipe
     trace_pipe_raw
     trace
     per_cpu/
             cpuX/
                 trace_pipe
                 trace_pipe_raw
     events/
            hyp/
                hyp_enter/
                          enable
                          id

Behind the scenes, kvm/hyp_trace.c must rebuild the tracing hierarchy
without relying on kernel/trace/trace.c. This is due to fundamental
differences:

  * Hypervisor tracing doesn't support trace_array's system-specific
    features (snapshots, tracers, etc.).

  * Logged event formats differ (e.g., no PID in hypervisor
    events).

  * Buffer operations require specific hypervisor interactions.

3. Events
---------

In the hypervisor, "hyp events" can be generated with trace_<event_name>
in a similar fashion to what the kernel does. They're also created with
similar macros than the kernel (see kvm_hypevents.h)

HYP_EVENT("foboar",
	HE_PROTO(void),
	HE_STRUCT(),
	HE_ASSIGN(),
	HE_PRINTK(" ")
)

Despite the apparent similarities with TRACE_EVENT(), those macros
internally differs: they must be used in parallel between the hypervisor
(for the writing part) and the kernel (for the reading part) which makes
it difficult to share anything with their kernel counterpart.

Also, events directory isn't using eventfs.

4. Few limitations:
-------------------

Non consuming reading of the buffer isn't supported (i.e. cat trace) due
to the lack of support in the ring-buffer meta-page.

Tracing must be stopped for the buffer to be reset. i.e. (echo 0 >
tracing_on; echo 0 > trace)

[1] https://tracingsummit.org/ts/2022/hypervisortracing/
[2] https://lore.kernel.org/all/20240510140435.3550353-1-vdonnefort@google.com/

Vincent Donnefort (11):
  ring-buffer: Check for empty ring-buffer with rb_num_of_entries()
  ring-buffer: Introducing ring-buffer writer
  ring-buffer: Expose buffer_data_page material
  timekeeping: Export the boot clock in snapshots
  KVM: arm64: Support unaligned fixmap in the nVHE hyp
  KVM: arm64: Add clock support in the nVHE hyp
  KVM: arm64: Add tracing support for the pKVM hyp
  KVM: arm64: Add hyp tracing to tracefs
  KVM: arm64: Add raw interface for hyp tracefs
  KVM: arm64: Add support for hyp events
  KVM: arm64: Add kselftest for tracefs hyp tracefs

 arch/arm64/include/asm/kvm_asm.h              |   6 +
 arch/arm64/include/asm/kvm_define_hypevents.h |  60 ++
 arch/arm64/include/asm/kvm_hyp.h              |   6 +
 arch/arm64/include/asm/kvm_hypevents.h        |  41 +
 arch/arm64/include/asm/kvm_hypevents_defs.h   |  41 +
 arch/arm64/include/asm/kvm_hyptrace.h         |  38 +
 arch/arm64/kernel/image-vars.h                |   4 +
 arch/arm64/kernel/vmlinux.lds.S               |  18 +
 arch/arm64/kvm/Kconfig                        |   9 +
 arch/arm64/kvm/Makefile                       |   2 +
 arch/arm64/kvm/arm.c                          |   6 +
 arch/arm64/kvm/hyp/hyp-constants.c            |   4 +
 arch/arm64/kvm/hyp/include/nvhe/arm-smccc.h   |  13 +
 arch/arm64/kvm/hyp/include/nvhe/clock.h       |  15 +
 .../kvm/hyp/include/nvhe/define_events.h      |  21 +
 arch/arm64/kvm/hyp/include/nvhe/trace.h       |  55 ++
 arch/arm64/kvm/hyp/nvhe/Makefile              |   1 +
 arch/arm64/kvm/hyp/nvhe/clock.c               |  42 +
 arch/arm64/kvm/hyp/nvhe/events.c              |  35 +
 arch/arm64/kvm/hyp/nvhe/ffa.c                 |   2 +-
 arch/arm64/kvm/hyp/nvhe/hyp-main.c            |  64 ++
 arch/arm64/kvm/hyp/nvhe/hyp.lds.S             |   4 +
 arch/arm64/kvm/hyp/nvhe/mm.c                  |   2 +-
 arch/arm64/kvm/hyp/nvhe/psci-relay.c          |  14 +-
 arch/arm64/kvm/hyp/nvhe/switch.c              |   5 +-
 arch/arm64/kvm/hyp/nvhe/trace.c               | 594 ++++++++++++
 arch/arm64/kvm/hyp_events.c                   | 164 ++++
 arch/arm64/kvm/hyp_trace.c                    | 854 ++++++++++++++++++
 arch/arm64/kvm/hyp_trace.h                    |  15 +
 include/linux/ring_buffer.h                   | 124 ++-
 include/linux/timekeeping.h                   |   6 +
 kernel/time/timekeeping.c                     |   9 +
 kernel/trace/ring_buffer.c                    | 244 +++--
 tools/testing/selftests/hyp-trace/Makefile    |   6 +
 tools/testing/selftests/hyp-trace/config      |   4 +
 .../selftests/hyp-trace/hyp-trace-test        | 161 ++++
 36 files changed, 2591 insertions(+), 98 deletions(-)
 create mode 100644 arch/arm64/include/asm/kvm_define_hypevents.h
 create mode 100644 arch/arm64/include/asm/kvm_hypevents.h
 create mode 100644 arch/arm64/include/asm/kvm_hypevents_defs.h
 create mode 100644 arch/arm64/include/asm/kvm_hyptrace.h
 create mode 100644 arch/arm64/kvm/hyp/include/nvhe/arm-smccc.h
 create mode 100644 arch/arm64/kvm/hyp/include/nvhe/clock.h
 create mode 100644 arch/arm64/kvm/hyp/include/nvhe/define_events.h
 create mode 100644 arch/arm64/kvm/hyp/include/nvhe/trace.h
 create mode 100644 arch/arm64/kvm/hyp/nvhe/clock.c
 create mode 100644 arch/arm64/kvm/hyp/nvhe/events.c
 create mode 100644 arch/arm64/kvm/hyp/nvhe/trace.c
 create mode 100644 arch/arm64/kvm/hyp_events.c
 create mode 100644 arch/arm64/kvm/hyp_trace.c
 create mode 100644 arch/arm64/kvm/hyp_trace.h
 create mode 100644 tools/testing/selftests/hyp-trace/Makefile
 create mode 100644 tools/testing/selftests/hyp-trace/config
 create mode 100644 tools/testing/selftests/hyp-trace/hyp-trace-test


base-commit: e4fc196f5ba36eb7b9758cf2c73df49a44199895
-- 
2.46.0.rc2.264.g509ed76dc8-goog


^ permalink raw reply	[flat|nested] 22+ messages in thread

end of thread, other threads:[~2024-09-05 13:17 UTC | newest]

Thread overview: 22+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-08-05 17:32 [RFC PATCH 00/11] Tracefs support for pKVM Vincent Donnefort
2024-08-05 17:32 ` [RFC PATCH 01/11] ring-buffer: Check for empty ring-buffer with rb_num_of_entries() Vincent Donnefort
2024-08-05 17:32 ` [RFC PATCH 02/11] ring-buffer: Introducing ring-buffer writer Vincent Donnefort
2024-08-06 20:39   ` Steven Rostedt
2024-08-13 14:21     ` Vincent Donnefort
2024-08-13 14:35       ` Steven Rostedt
2024-08-05 17:32 ` [RFC PATCH 03/11] ring-buffer: Expose buffer_data_page material Vincent Donnefort
2024-08-05 17:32 ` [RFC PATCH 04/11] timekeeping: Export the boot clock in snapshots Vincent Donnefort
2024-08-22  9:13   ` Marc Zyngier
2024-09-05 13:04     ` Vincent Donnefort
2024-08-22 18:13   ` John Stultz
2024-08-22 21:41     ` Thomas Gleixner
2024-09-05 13:17     ` Vincent Donnefort
2024-08-05 17:32 ` [RFC PATCH 05/11] KVM: arm64: Support unaligned fixmap in the nVHE hyp Vincent Donnefort
2024-08-05 17:32 ` [RFC PATCH 06/11] KVM: arm64: Add clock support " Vincent Donnefort
2024-08-05 17:32 ` [RFC PATCH 07/11] KVM: arm64: Add tracing support for the pKVM hyp Vincent Donnefort
2024-08-05 17:32 ` [RFC PATCH 08/11] KVM: arm64: Add hyp tracing to tracefs Vincent Donnefort
2024-08-05 17:32 ` [RFC PATCH 09/11] KVM: arm64: Add raw interface for hyp tracefs Vincent Donnefort
2024-08-05 17:32 ` [RFC PATCH 10/11] KVM: arm64: Add support for hyp events Vincent Donnefort
2024-08-05 17:32 ` [RFC PATCH 11/11] KVM: arm64: Add kselftest for tracefs hyp tracefs Vincent Donnefort
2024-08-06 20:11 ` [RFC PATCH 00/11] Tracefs support for pKVM Steven Rostedt
2024-08-07 16:39   ` Vincent Donnefort

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).