[<prev] [next>] [day] [month] [year] [list]
Message-Id: <20250111-ftrace-selftest-livepatch-v2-1-9f4ff90f251a@gmail.com>
Date: Sat, 11 Jan 2025 15:42:27 -0300
From: Filipe Xavier <felipeaggger@...il.com>
To: Marcos Paulo de Souza <mpdesouza@...e.com>,
Josh Poimboeuf <jpoimboe@...nel.org>, Jiri Kosina <jikos@...nel.org>,
Miroslav Benes <mbenes@...e.cz>, Petr Mladek <pmladek@...e.com>,
Joe Lawrence <joe.lawrence@...hat.com>, Shuah Khan <shuah@...nel.org>
Cc: live-patching@...r.kernel.org, linux-kselftest@...r.kernel.org,
linux-kernel@...r.kernel.org, Felipe Xavier <felipe_life@...e.com>,
Filipe Xavier <felipeaggger@...il.com>
Subject: [PATCH v2] selftests: livepatch: test if ftrace can trace a
livepatched function
This new test makes sure that ftrace can trace a
function that was introduced by a livepatch.
Signed-off-by: Filipe Xavier <felipeaggger@...il.com>
---
Changes in v2:
- functions.sh: added reset tracing on push and pop_config.
- test-ftrace.sh: enabled tracing_on before test init.
- nitpick: added double quotations on filenames and fixed some wording.
- Link to v1: https://lore.kernel.org/r/20250102-ftrace-selftest-livepatch-v1-1-84880baefc1b@gmail.com
---
tools/testing/selftests/livepatch/functions.sh | 14 ++++++++++
tools/testing/selftests/livepatch/test-ftrace.sh | 33 ++++++++++++++++++++++++
2 files changed, 47 insertions(+)
diff --git a/tools/testing/selftests/livepatch/functions.sh b/tools/testing/selftests/livepatch/functions.sh
index e5d06fb402335d85959bafe099087effc6ddce12..e6c13514002dae5f8d7461f90b8241ab43024ea4 100644
--- a/tools/testing/selftests/livepatch/functions.sh
+++ b/tools/testing/selftests/livepatch/functions.sh
@@ -62,6 +62,9 @@ function push_config() {
awk -F'[: ]' '{print "file " $1 " line " $2 " " $4}')
FTRACE_ENABLED=$(sysctl --values kernel.ftrace_enabled)
KPROBE_ENABLED=$(cat "$SYSFS_KPROBES_DIR/enabled")
+ TRACING_ON=$(cat "$SYSFS_DEBUG_DIR/tracing/tracing_on")
+ CURRENT_TRACER=$(cat "$SYSFS_DEBUG_DIR/tracing/current_tracer")
+ FTRACE_FILTER=$(cat "$SYSFS_DEBUG_DIR/tracing/set_ftrace_filter")
}
function pop_config() {
@@ -74,6 +77,17 @@ function pop_config() {
if [[ -n "$KPROBE_ENABLED" ]]; then
echo "$KPROBE_ENABLED" > "$SYSFS_KPROBES_DIR/enabled"
fi
+ if [[ -n "$TRACING_ON" ]]; then
+ echo "$TRACING_ON" > "$SYSFS_DEBUG_DIR/tracing/tracing_on"
+ fi
+ if [[ -n "$CURRENT_TRACER" ]]; then
+ echo "$CURRENT_TRACER" > "$SYSFS_DEBUG_DIR/tracing/current_tracer"
+ fi
+ if [[ "$FTRACE_FILTER" == *"#"* ]]; then
+ echo > "$SYSFS_DEBUG_DIR/tracing/set_ftrace_filter"
+ elif [[ -n "$FTRACE_FILTER" ]]; then
+ echo "$FTRACE_FILTER" > "$SYSFS_DEBUG_DIR/tracing/set_ftrace_filter"
+ fi
}
function set_dynamic_debug() {
diff --git a/tools/testing/selftests/livepatch/test-ftrace.sh b/tools/testing/selftests/livepatch/test-ftrace.sh
index fe14f248913acbec46fb6c0fec38a2fc84209d39..66af5d726c52e48e5177804e182b4ff31784d5ac 100755
--- a/tools/testing/selftests/livepatch/test-ftrace.sh
+++ b/tools/testing/selftests/livepatch/test-ftrace.sh
@@ -61,4 +61,37 @@ livepatch: '$MOD_LIVEPATCH': unpatching complete
% rmmod $MOD_LIVEPATCH"
+# - verify livepatch can load
+# - check if traces have a patched function
+# - unload livepatch and reset trace
+
+start_test "trace livepatched function and check that the live patch remains in effect"
+
+TRACE_FILE="$SYSFS_DEBUG_DIR/tracing/trace"
+FUNCTION_NAME="livepatch_cmdline_proc_show"
+
+load_lp $MOD_LIVEPATCH
+
+echo 1 > "$SYSFS_DEBUG_DIR/tracing/tracing_on"
+echo $FUNCTION_NAME > "$SYSFS_DEBUG_DIR/tracing/set_ftrace_filter"
+echo "function" > "$SYSFS_DEBUG_DIR/tracing/current_tracer"
+echo "" > "$TRACE_FILE"
+
+if [[ "$(cat /proc/cmdline)" != "$MOD_LIVEPATCH: this has been live patched" ]] ; then
+ echo -e "FAIL\n\n"
+ die "livepatch kselftest(s) failed"
+fi
+
+grep -q $FUNCTION_NAME "$TRACE_FILE"
+FOUND=$?
+
+disable_lp $MOD_LIVEPATCH
+unload_lp $MOD_LIVEPATCH
+
+if [ "$FOUND" -eq 1 ]; then
+ echo -e "FAIL\n\n"
+ die "livepatch kselftest(s) failed"
+fi
+
+
exit 0
---
base-commit: fc033cf25e612e840e545f8d5ad2edd6ba613ed5
change-id: 20250101-ftrace-selftest-livepatch-161fb77dbed8
Best regards,
--
Filipe Xavier <felipeaggger@...il.com>
Powered by blists - more mailing lists