Linux Trace Kernel
 help / color / mirror / Atom feed
From: Steven Rostedt <rostedt@goodmis.org>
To: Vincent Donnefort <vdonnefort@google.com>
Cc: mhiramat@kernel.org, mathieu.desnoyers@efficios.com,
	linux-trace-kernel@vger.kernel.org, maz@kernel.org,
	oliver.upton@linux.dev, joey.gouly@arm.com,
	suzuki.poulose@arm.com, yuzenghui@huawei.com,
	kvmarm@lists.linux.dev, linux-arm-kernel@lists.infradead.org,
	jstultz@google.com, qperret@google.com, will@kernel.org,
	kernel-team@android.com, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v4 00/24] Tracefs support for pKVM
Date: Wed, 14 May 2025 13:38:15 -0400	[thread overview]
Message-ID: <20250514133815.78bc2599@gandalf.local.home> (raw)
In-Reply-To: <20250506164820.515876-1-vdonnefort@google.com>

On Tue,  6 May 2025 17:47:56 +0100
Vincent Donnefort <vdonnefort@google.com> wrote:

> 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.
> 
> 1. ring-buffer
> --------------
> 
> To setup the per-cpu ring-buffers, a new interface is created:
> 
>   ring_buffer_remote:	Describes what the kernel needs to know about the
> 			remote writer, that is, the set of pages forming the
> 			ring-buffer and a callback for the reader/head
> 			swapping (enables consuming read)
> 
>   ring_buffer_remote():	Creates a read-only ring-buffer from a
> 			ring_buffer_remote.
> 
> To keep the internals of `struct ring_buffer` in sync with the remote,
> 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_remote():
> 			Update `struct ring_buffer` based on the remote
> 			meta-page. Wake-up readers if necessary.
> 
> The kernel has to poll the meta-page to be notified of newly written
> events.
> 
> 2. Tracefs
> ----------
> 
> This series introduce a new trace_remote that does the link between
> tracefs and the remote ring-buffer.
> 
> The interface is found in the remotes/ directory at the root of the
> tracefs mount point. Each remote is like an instance and you'll find
> there a subset of the regular Tracefs user-space interface:
> 
>   remotes/test/
>      buffer_size_kb
>      trace_clock
>      trace_pipe
>      trace
>      per_cpu/
>              cpuX/
>                  trace
>                  trace_pipe
>      events/
> 
>             test/
>                 selftest/
>                           enable
>                           id
> 
> Behind the scenes, kernel/trace/trace_remote.c creates this tracefs
> hierarchy without relying on kernel/trace/trace.c. This is due to
> fundamental differences:
> 
>   * Remote tracing doesn't support trace_array's system-specific
>     features (snapshots, tracers, etc.).
> 
>   * Logged event formats differ (e.g., no PID for remote events).
> 
>   * Buffer operations require specific remote interactions.
> 
> 3. Simple Ring-Buffer
> ---------------------
> 
> As the current ring-buffer.c implementation has too many dependencies to
> be used directly by the pKVM hypervisor. A new simple implementation is
> created and can be found in kernel/trace/simple-ring-buffer.c.
> 
> This implementation is write-only and is used by both the pKVM
> hypervisor and a trace_remote test module.
> 
> 4. Events
> ---------
> 
> A new REMOTE_EVENT() macro is added to simplify the creation of events
> on the kernel side. As remote tracing buffer are read only, only the
> event structure and a way of printing must be declared. The prototype of
> the macro is very similar to the well-known TRACE_EVENT()
> 
>  REMOTE_EVENT(my_event, id,
>      RE_STRUCT(
>          re_field(u64, foobar)
>      ),
>      RE_PRINTK("foobar=%lld", __entry->foobar)
>      )
>   )
> 
> 5. pKVM
> -------
> 
> The pKVM support simply creates a "hypervisor" trace_remote on the
> kernel side and inherits from simple-ring-buffer.c on the hypervisor
> side.
> 
> A new event macro is created HYP_EVENT() that is under the hood re-using
> REMOTE_EVENT() (defined in the previous paragaph) as well as generate
> hypervisor specific struct and trace_<event>() functions.
> 
> 5. Limitations:
> ---------------
> 
> Non-consuming reading of the buffer isn't supported (i.e. cat trace ->
> -EPERM) due to current the lack of support in the ring-buffer meta-page.
> 
> [1] https://tracingsummit.org/ts/2022/hypervisortracing/
> [2] https://lore.kernel.org/all/20240510140435.3550353-1-vdonnefort@google.com/
> 

BTW,  I tried to build this series and it fails.

  CALL    /work/git/test-linux.git/scripts/checksyscalls.sh
  CC      kernel/trace/simple_ring_buffer.o
In file included from ./arch/x86/include/generated/asm/rwonce.h:1,
                 from /work/git/test-linux.git/include/linux/compiler.h:390,
                 from /work/git/test-linux.git/arch/x86/include/asm/atomic.h:5,
                 from /work/git/test-linux.git/include/linux/atomic.h:7,
                 from /work/git/test-linux.git/kernel/trace/simple_ring_buffer.c:7:
/work/git/test-linux.git/kernel/trace/simple_ring_buffer.c: In function ‘simple_rb_move_tail’:
/work/git/test-linux.git/include/asm-generic/rwonce.h:55:37: error: assignment to ‘struct list_head *’ from ‘long unsigned int’ makes pointer from integer without a cast [-Wint-conversion]
   55 |         *(volatile typeof(x) *)&(x) = (val);                            \
      |                                     ^
/work/git/test-linux.git/include/asm-generic/rwonce.h:61:9: note: in expansion of macro ‘__WRITE_ONCE’
   61 |         __WRITE_ONCE(x, val);                                           \
      |         ^~~~~~~~~~~~
/work/git/test-linux.git/arch/x86/include/asm/barrier.h:63:9: note: in expansion of macro ‘WRITE_ONCE’
   63 |         WRITE_ONCE(*p, v);                                              \
      |         ^~~~~~~~~~
/work/git/test-linux.git/include/asm-generic/barrier.h:172:55: note: in expansion of macro ‘__smp_store_release’
  172 | #define smp_store_release(p, v) do { kcsan_release(); __smp_store_release(p, v); } while (0)
      |                                                       ^~~~~~~~~~~~~~~~~~~
/work/git/test-linux.git/kernel/trace/simple_ring_buffer.c:129:17: note: in expansion of macro ‘smp_store_release’
  129 |                 smp_store_release(&new_tail->list.next,
      |                 ^~~~~~~~~~~~~~~~~
make[5]: *** [/work/git/test-linux.git/scripts/Makefile.build:203: kernel/trace/simple_ring_buffer.o] Error 1
make[4]: *** [/work/git/test-linux.git/scripts/Makefile.build:461: kernel/trace] Error 2
make[3]: *** [/work/git/test-linux.git/scripts/Makefile.build:461: kernel] Error 2
make[2]: *** [/work/git/test-linux.git/Makefile:2004: .] Error 2
make[1]: *** [/work/git/test-linux.git/Makefile:248: __sub-make] Error 2
make[1]: Leaving directory '/work/build/trace/nobackup/debiantesting-x86-64'

Even when I fixed this, it then failed with the building of the sample module.

I think you need something like:

obj-$(CONFIG_TRACE_REMOTE_TEST) += remote_test_mod.o

remote_test_mod-y := simple_ring_buffer.o remote_test.o trace_remote.o

If the module needs more than one object file. Then the module should be
called something that doesn't have a .c file and use that name with ".o" to
add all the objects.

I think this could work, but this still had issues with functions not exported.

-- Steve

  parent reply	other threads:[~2025-05-14 17:37 UTC|newest]

Thread overview: 36+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-05-06 16:47 [PATCH v4 00/24] Tracefs support for pKVM Vincent Donnefort
2025-05-06 16:47 ` [PATCH v4 01/24] ring-buffer: Introduce ring-buffer remotes Vincent Donnefort
2025-05-07 23:47   ` Steven Rostedt
2025-05-08  9:10     ` Vincent Donnefort
2025-05-08 14:05       ` Steven Rostedt
2025-05-06 16:47 ` [PATCH v4 02/24] tracing: Introduce trace remotes Vincent Donnefort
2025-05-08  0:24   ` Steven Rostedt
2025-05-08  9:14     ` Vincent Donnefort
2025-05-06 16:47 ` [PATCH v4 03/24] tracing: Add reset to " Vincent Donnefort
2025-05-06 16:48 ` [PATCH v4 04/24] tracing: Add init callback " Vincent Donnefort
2025-05-06 16:48 ` [PATCH v4 05/24] tracing: Add events " Vincent Donnefort
2025-05-09 19:47   ` Steven Rostedt
2025-05-12  7:55     ` Vincent Donnefort
2025-05-06 16:48 ` [PATCH v4 06/24] tracing: Add events/ root files " Vincent Donnefort
2025-05-06 16:48 ` [PATCH v4 07/24] tracing: Add helpers to create trace remote events Vincent Donnefort
2025-05-06 16:48 ` [PATCH v4 08/24] ring-buffer: Expose buffer_data_page material Vincent Donnefort
2025-05-09 19:54   ` Steven Rostedt
2025-05-06 16:48 ` [PATCH v4 09/24] tracing: Introduce simple_ring_buffer Vincent Donnefort
2025-05-06 16:48 ` [PATCH v4 10/24] tracing: Add a trace remote module for testing Vincent Donnefort
2025-05-06 16:48 ` [PATCH v4 11/24] tracing: selftests: Add trace remote tests Vincent Donnefort
2025-05-06 16:48 ` [PATCH v4 12/24] tracing: load/unload page callbacks for simple_ring_buffer Vincent Donnefort
2025-05-06 16:48 ` [PATCH v4 13/24] tracing: Check for undefined symbols in simple_ring_buffer Vincent Donnefort
2025-05-06 16:48 ` [PATCH v4 14/24] KVM: arm64: Support unaligned fixmap in the nVHE hyp Vincent Donnefort
2025-05-06 16:48 ` [PATCH v4 15/24] KVM: arm64: Add .hyp.data section Vincent Donnefort
2025-05-06 16:48 ` [PATCH v4 16/24] KVM: arm64: Add clock support for the pKVM hyp Vincent Donnefort
2025-05-06 16:48 ` [PATCH v4 17/24] KVM: arm64: Add tracing capability " Vincent Donnefort
2025-05-06 16:48 ` [PATCH v4 18/24] KVM: arm64: Add trace remote " Vincent Donnefort
2025-05-06 16:48 ` [PATCH v4 19/24] KVM: arm64: Sync boot clock with " Vincent Donnefort
2025-05-06 16:48 ` [PATCH v4 20/24] KVM: arm64: Add trace reset to " Vincent Donnefort
2025-05-06 16:48 ` [PATCH v4 21/24] KVM: arm64: Add event support to the pKVM hyp and trace remote Vincent Donnefort
2025-05-06 16:48 ` [PATCH v4 22/24] KVM: arm64: Add hyp_enter/hyp_exit events to pKVM hyp Vincent Donnefort
2025-05-06 16:48 ` [PATCH v4 23/24] KVM: arm64: Add selftest event support " Vincent Donnefort
2025-05-06 16:48 ` [PATCH v4 24/24] tracing: selftests: Add pKVM trace remote tests Vincent Donnefort
2025-05-14 17:38 ` Steven Rostedt [this message]
2025-05-14 18:13   ` [PATCH v4 00/24] Tracefs support for pKVM Vincent Donnefort
2025-05-14 18:28     ` Steven Rostedt

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20250514133815.78bc2599@gandalf.local.home \
    --to=rostedt@goodmis.org \
    --cc=joey.gouly@arm.com \
    --cc=jstultz@google.com \
    --cc=kernel-team@android.com \
    --cc=kvmarm@lists.linux.dev \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-trace-kernel@vger.kernel.org \
    --cc=mathieu.desnoyers@efficios.com \
    --cc=maz@kernel.org \
    --cc=mhiramat@kernel.org \
    --cc=oliver.upton@linux.dev \
    --cc=qperret@google.com \
    --cc=suzuki.poulose@arm.com \
    --cc=vdonnefort@google.com \
    --cc=will@kernel.org \
    --cc=yuzenghui@huawei.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox