From 6da63c63e21ddba78b3b04cc10d69c81188cdb86 Mon Sep 17 00:00:00 2001 From: Hongyu Ning Date: Mon, 14 Sep 2026 14:43:25 +0800 Subject: [PATCH] BM/tdx-host: restrict ftrace profiling to Dynamic PAMT functions Configure the function profiler to trace only PAMT add and remove operations, and validate that both functions are available before starting Dynamic PAMT accounting. Co-authored-by: GitHub Copilot Signed-off-by: Hongyu Ning (cherry picked from commit 41579cc73b11a8fe9650b608458f0fa0281df168) --- BM/tdx-host/tdx_dpamt_test.sh | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/BM/tdx-host/tdx_dpamt_test.sh b/BM/tdx-host/tdx_dpamt_test.sh index 52db5a51..70d469c8 100755 --- a/BM/tdx-host/tdx_dpamt_test.sh +++ b/BM/tdx-host/tdx_dpamt_test.sh @@ -144,13 +144,24 @@ get_dpamt_kb() { # function to start function profiling for a testcase dpamt_profile_start() { - local profile=/sys/kernel/tracing/function_profile_enabled - - if [ ! -w "$profile" ]; then - die "Function profiler control $profile is not writable." - fi + local trace=/sys/kernel/tracing + local profile="$trace/function_profile_enabled" + local filter="$trace/set_ftrace_filter" + local available="$trace/available_filter_functions" + local function + + for function in tdh_phymem_pamt_add tdh_phymem_pamt_remove; do + grep -qw "$function" "$available" || \ + die "Function $function is unavailable for ftrace." + done echo 0 > "$profile" || die "Failed to reset function profiling." + echo nop > "$trace/current_tracer" || die "Failed to select the nop tracer." + : > "$filter" || die "Failed to clear the ftrace function filter." + echo tdh_phymem_pamt_add > "$filter" || \ + die "Failed to add tdh_phymem_pamt_add to the ftrace function filter." + echo tdh_phymem_pamt_remove >> "$filter" || \ + die "Failed to add tdh_phymem_pamt_remove to the ftrace function filter." echo 1 > "$profile" || die "Failed to enable function profiling." trap dpamt_profile_stop EXIT test_print_trc "Function profiling enabled for dynamic PAMT accounting"