[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[RFC 0/5] Introduce dynamic tracer using Livepatch


  • To: xen-devel@xxxxxxxxxxxxxxxxxxxx
  • From: Ryo Takakura <takakura@xxxxxxxxxxxxx>
  • Date: Fri, 23 Oct 2026 13:48:09 +0900
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=valinux.co.jp; dmarc=pass action=none header.from=valinux.co.jp; dkim=pass header.d=valinux.co.jp; arc=none
  • Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=KwHOlk5cGD/ygVVQmfIA8/k+P+ZJhK+XztwkDguMums=; b=KWzlNkNDmYPvQ5omI8Jtnr7eVNI9y89Nxdjbl0KiKJQ5uSBhasyaO+yYpJh7nWyBa9oGBNPWzUHOM3n8TUma431Ji+cS27UoI1q13vri5cEWl5I5Qk/gL528ubWIGle2hZuYzqNPNZ3Vgt1GoVMzyRrxkKqqkNtyQsCTLlx1x1bTaziLZhawNk6ueqZmaN9x80KmrSJr9uLhZKxY80hoi4dx1yx+XjFuDLVgKIChiEkkAWfgup3KwnSqJ3WSpeHbJ16C6qlt3XKS8CRBXBzyl5A8Pxq9tVm6MmlMshmv9Legh0HbvrpweXOirmBmxA8qChm55/DE8U3PVjrGs2tawA==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=nwuKZQ01gcMAnezMGltDUUaqrnwtnoz0R/cawn/hLIcGlkmOOEr7WFnqqLd7C+T+fcgGuSK6jkGCFMC8IwHs0THiV3BHA7oVCw2MvWxKytY1DLKOW6HZUpRq3SdwyzH4565OGssaJqlQuB6n/CBZocWFCvTsjp6giHLm6lItDyWF8N9pJxyvHugbmE+GwonLMC6mOhKdRPYusPXoZagFSMgxG2Awfq13asD0uL/WqcPal6yLbCx28d/XFJ+EhkLWX7fBmq5GqBdssK3A5ybPMsz8xa0xjpNKEEFmRHdPm/ROGmHVNTzyoroI1JmOj6mDBxS9B5YXZMYVp6AHl9UJdw==
  • Authentication-results: eu.smtp.expurgate.cloud; dkim=pass header.s=selector1 header.d=valinux.co.jp header.i="@valinux.co.jp" header.h="From:Date:Subject:Message-Id:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck"
  • Authentication-results: mx.microsoft.com 1; dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=valinux.co.jp;
  • Cc: Ryo Takakura <takakura@xxxxxxxxxxxxx>
  • Delivery-date: Fri, 23 Oct 2026 04:48:50 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

Hello!

This RFC introduces a dynamic function tracing feature
which I proposed at Xen Summit in September:
https://xensummit2026.sched.com/event/2RDr8/improving-xen-traceability-more-than-just-livepatching

The goal is to improve debugging/tracing by making Xen possible to attach
callbacks to its functions. This series implements the infrastructure for
attaching callbacks using Livepatch on x86 and arm64, as well as
HypFS interface for controlling tracers. It is inspired by Linux ftrace:
https://docs.kernel.org/trace/ftrace.html

I appreciate any feedback on the implementation, as well as
your experience trying it out. Thanks!

# Implementation
The implementation follows Linux ftrace's approach of reserving
function entries that can be later patched for tracing at runtime.
Those entries get patched with a branch instruction to a trampoline,
which preserves registers before calling function callbacks.

Livepatch is used for patching those reserved function entries.
Since Livepatch operates on struct payload, it prepares a dedicated
payload which can be used by tracers for requesting livepatch of the
target function. Please see patch 2 and 3 for the detail.

New tracers can be added by defining a struct tracer and
registering it during Xen initialization. Each tracer can provide
a function callback for tracing and optional callbacks for managing
its state and output through the HypFS interface under /tracing.
Please see patch 4 for an example implementation.

# Configuration
In addition to Livepatch and HypFS:

CONFIG_LIVEPATCH=y
CONFIG_HYPFS=y

Enable the following configs:

CONFIG_ARM64_PATCHABLE_FUNCTION_ENTRY=y
or
CONFIG_X86_PATCHABLE_FUNCTION_ENTRY=y

CONFIG_LIVEPATCH_TRACER=y

# Usage
The interface is exposed HypFS /tracing directory.
It follows the naming and usage of Linux ftrace:
https://www.kernel.org/doc/html/latest/trace/ftrace.html#the-file-system

available_tracers     List registered tracers.
current_tracer        Read or select the active tracer.
available_functions   List functions available for tracing.
set_function_filter   Read, select, or clear the target function.
tracing_on            Enable or disable recording.
trace                 Read or clear recorded output.

## Example
// List the tracable functions.
xenhypfs cat /tracing/available_functions

// List the available tracers. Currently "nop" and "function" tracers are 
available.
xenhypfs cat /tracing/available_tracers

// Select the function to trace.
xenhypfs write /tracing/set_function_filter xen_extra_version

// Select the tracer.
xenhypfs write /tracing/current_tracer function

// Record calls to the selected function.
xenhypfs write /tracing/tracing_on 1

// Call xen_extra_version().
cat /sys/hypervisor/version/extra

// Stop recording and read the output.
xenhypfs write /tracing/tracing_on 0
xenhypfs cat /tracing/trace

// Reset.
xenhypfs write /tracing/set_function_filter ""
xenhypfs write /tracing/current_tracer nop
xenhypfs write /tracing/trace ""

Sincerely,
Ryo Takakura

Ryo Takakura (5):
  xen/arm64: livepatch: enable attaching callbacks
  xen/livepatch: Allow tracers to schedule livepatch
  xen/tracing: prepare a livepatch payload and its controling interface
  xen/tracing: Add a function tracer
  xen/x86: livepatch: enable attaching callbacks

 xen/arch/arm/Kconfig                  |  13 +
 xen/arch/arm/arch.mk                  |   3 +
 xen/arch/arm/arm64/Makefile           |   1 +
 xen/arch/arm/arm64/insn.c             |   5 +
 xen/arch/arm/arm64/livepatch-asm.S    |  68 +++
 xen/arch/arm/arm64/livepatch.c        |  39 ++
 xen/arch/arm/include/asm/arm64/insn.h |   1 +
 xen/arch/arm/xen.lds.S                |   5 +
 xen/arch/x86/Kconfig                  |  13 +
 xen/arch/x86/Makefile                 |   1 +
 xen/arch/x86/arch.mk                  |   3 +
 xen/arch/x86/livepatch-asm.S          |  60 +++
 xen/arch/x86/livepatch.c              |  33 ++
 xen/arch/x86/xen.lds.S                |   5 +
 xen/common/Kconfig                    |  12 +
 xen/common/Makefile                   |   6 +
 xen/common/function_trace.c           | 274 ++++++++++
 xen/common/hypfs_trace.c              | 743 ++++++++++++++++++++++++++
 xen/common/livepatch.c                | 137 ++++-
 xen/include/xen/hypfs_trace.h         |  42 ++
 xen/include/xen/livepatch.h           |  14 +
 xen/include/xen/livepatch_payload.h   |   7 +-
 22 files changed, 1478 insertions(+), 7 deletions(-)
 create mode 100644 xen/arch/arm/arm64/livepatch-asm.S
 create mode 100644 xen/arch/x86/livepatch-asm.S
 create mode 100644 xen/common/function_trace.c
 create mode 100644 xen/common/hypfs_trace.c
 create mode 100644 xen/include/xen/hypfs_trace.h

-- 
2.34.1




 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.