|
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [RFC 0/5] Introduce dynamic tracer using Livepatch
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
|
![]() |
Lists.xenproject.org is hosted with RackSpace, monitoring our |