linux-kselftest.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/2] selftests: livepatch: test if ftrace can trace a livepatched function
@ 2025-03-06 21:51 Filipe Xavier
  2025-03-06 21:51 ` [PATCH PATCH 1/2] selftests: livepatch: add new ftrace helpers functions Filipe Xavier
                   ` (2 more replies)
  0 siblings, 3 replies; 8+ messages in thread
From: Filipe Xavier @ 2025-03-06 21:51 UTC (permalink / raw)
  To: Josh Poimboeuf, Jiri Kosina, Miroslav Benes, Petr Mladek,
	Joe Lawrence, Shuah Khan, Marcos Paulo de Souza
  Cc: live-patching, linux-kselftest, linux-kernel, felipe_life,
	Filipe Xavier

This patchset add ftrace helpers functions and
add a new test makes sure that ftrace can trace
a function that was introduced by a livepatch.

Signed-off-by: Filipe Xavier <felipeaggger@gmail.com>
---
Filipe Xavier (2):
      selftests: livepatch: add new ftrace helpers functions
      selftests: livepatch: test if ftrace can trace a livepatched function

 tools/testing/selftests/livepatch/functions.sh   | 45 ++++++++++++++++++++++++
 tools/testing/selftests/livepatch/test-ftrace.sh | 35 ++++++++++++++++++
 2 files changed, 80 insertions(+)
---
base-commit: 848e076317446f9c663771ddec142d7c2eb4cb43
change-id: 20250306-ftrace-sftest-livepatch-60d9dc472235

Best regards,
-- 
Filipe Xavier <felipeaggger@gmail.com>


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [PATCH PATCH 1/2] selftests: livepatch: add new ftrace helpers functions
  2025-03-06 21:51 [PATCH 0/2] selftests: livepatch: test if ftrace can trace a livepatched function Filipe Xavier
@ 2025-03-06 21:51 ` Filipe Xavier
  2025-03-06 21:51 ` [PATCH PATCH 2/2] selftests: livepatch: test if ftrace can trace a livepatched function Filipe Xavier
  2025-03-12  1:53 ` [PATCH 0/2] " Marcos Paulo de Souza
  2 siblings, 0 replies; 8+ messages in thread
From: Filipe Xavier @ 2025-03-06 21:51 UTC (permalink / raw)
  To: Josh Poimboeuf, Jiri Kosina, Miroslav Benes, Petr Mladek,
	Joe Lawrence, Shuah Khan, Marcos Paulo de Souza
  Cc: live-patching, linux-kselftest, linux-kernel, felipe_life,
	Filipe Xavier

Add new ftrace helpers functions cleanup_tracing, trace_function and
check_traced_function.

Signed-off-by: Filipe Xavier <felipeaggger@gmail.com>
---
 tools/testing/selftests/livepatch/functions.sh | 45 ++++++++++++++++++++++++++
 1 file changed, 45 insertions(+)

diff --git a/tools/testing/selftests/livepatch/functions.sh b/tools/testing/selftests/livepatch/functions.sh
index 15601402dee6567837c2c49ba342eb357e410d18..512ab3a9c20cc5691bbf0863d837ffa0d40a15e9 100644
--- a/tools/testing/selftests/livepatch/functions.sh
+++ b/tools/testing/selftests/livepatch/functions.sh
@@ -10,6 +10,7 @@ SYSFS_KERNEL_DIR="/sys/kernel"
 SYSFS_KLP_DIR="$SYSFS_KERNEL_DIR/livepatch"
 SYSFS_DEBUG_DIR="$SYSFS_KERNEL_DIR/debug"
 SYSFS_KPROBES_DIR="$SYSFS_DEBUG_DIR/kprobes"
+SYSFS_TRACING_DIR="$SYSFS_DEBUG_DIR/tracing"
 
 # Kselftest framework requirement - SKIP code is 4
 ksft_skip=4
@@ -62,6 +63,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_TRACING_DIR/tracing_on")
+	CURRENT_TRACER=$(cat "$SYSFS_TRACING_DIR/current_tracer")
+	FTRACE_FILTER=$(cat "$SYSFS_TRACING_DIR/set_ftrace_filter")
 }
 
 function pop_config() {
@@ -74,6 +78,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_TRACING_DIR/tracing_on"
+	fi
+	if [[ -n "$CURRENT_TRACER" ]]; then
+		echo "$CURRENT_TRACER" > "$SYSFS_TRACING_DIR/current_tracer"
+	fi
+	if [[ -n "$FTRACE_FILTER" ]]; then
+		echo "$FTRACE_FILTER" \
+			| sed -e "/#### all functions enabled ####/d"
+			> "$SYSFS_TRACING_DIR/set_ftrace_filter"
+	fi
 }
 
 function set_dynamic_debug() {
@@ -352,3 +367,33 @@ function check_sysfs_value() {
 		die "Unexpected value in $path: $expected_value vs. $value"
 	fi
 }
+
+# cleanup_tracing() - stop and clean up function tracing
+function cleanup_tracing() {
+	echo 0 > "$SYSFS_TRACING_DIR/tracing_on"
+	echo "" > "$SYSFS_TRACING_DIR/set_ftrace_filter"
+	echo "nop" > "$SYSFS_TRACING_DIR/current_tracer"
+	echo "" > "$SYSFS_TRACING_DIR/trace"
+}
+
+# trace_function(function) - start tracing of a function
+#	function - to be traced function
+function trace_function() {
+	local function="$1"; shift
+
+	cleanup_tracing
+
+	echo "function" > "$SYSFS_TRACING_DIR/current_tracer"
+	echo "$function" > "$SYSFS_TRACING_DIR/set_ftrace_filter"
+	echo 1 > "$SYSFS_TRACING_DIR/tracing_on"
+}
+
+# check_traced_function(function) - check whether function appeared in trace log
+#	function - to be traced function
+function check_traced_function() {
+	local function="$1"; shift
+
+	if ! grep -q "$function" "$SYSFS_TRACING_DIR/trace" ; then
+		die "Function ($function) did not appear in the trace"
+	fi
+}

-- 
2.46.2


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH PATCH 2/2] selftests: livepatch: test if ftrace can trace a livepatched function
  2025-03-06 21:51 [PATCH 0/2] selftests: livepatch: test if ftrace can trace a livepatched function Filipe Xavier
  2025-03-06 21:51 ` [PATCH PATCH 1/2] selftests: livepatch: add new ftrace helpers functions Filipe Xavier
@ 2025-03-06 21:51 ` Filipe Xavier
  2025-03-14 13:14   ` Miroslav Benes
  2025-03-12  1:53 ` [PATCH 0/2] " Marcos Paulo de Souza
  2 siblings, 1 reply; 8+ messages in thread
From: Filipe Xavier @ 2025-03-06 21:51 UTC (permalink / raw)
  To: Josh Poimboeuf, Jiri Kosina, Miroslav Benes, Petr Mladek,
	Joe Lawrence, Shuah Khan, Marcos Paulo de Souza
  Cc: live-patching, linux-kselftest, linux-kernel, felipe_life,
	Filipe Xavier

This new test makes sure that ftrace can trace a
function that was introduced by a livepatch.

Signed-off-by: Filipe Xavier <felipeaggger@gmail.com>
---
 tools/testing/selftests/livepatch/test-ftrace.sh | 35 ++++++++++++++++++++++++
 1 file changed, 35 insertions(+)

diff --git a/tools/testing/selftests/livepatch/test-ftrace.sh b/tools/testing/selftests/livepatch/test-ftrace.sh
index fe14f248913acbec46fb6c0fec38a2fc84209d39..35774c42e239b466599052d6a9cc3cf75b78d63d 100755
--- a/tools/testing/selftests/livepatch/test-ftrace.sh
+++ b/tools/testing/selftests/livepatch/test-ftrace.sh
@@ -61,4 +61,39 @@ livepatch: '$MOD_LIVEPATCH': unpatching complete
 % rmmod $MOD_LIVEPATCH"
 
 
+# - verify livepatch can load
+# - check if traces have a patched function
+# - reset trace and unload livepatch
+
+start_test "trace livepatched function and check that the live patch remains in effect"
+
+FUNCTION_NAME="livepatch_cmdline_proc_show"
+
+load_lp $MOD_LIVEPATCH
+trace_function "$FUNCTION_NAME"
+
+if [[ "$(cat /proc/cmdline)" == "$MOD_LIVEPATCH: this has been live patched" ]] ; then
+	log "livepatch: ok"
+fi
+
+check_traced_function "$FUNCTION_NAME"
+
+cleanup_tracing
+disable_lp $MOD_LIVEPATCH
+unload_lp $MOD_LIVEPATCH
+
+check_result "% insmod test_modules/$MOD_LIVEPATCH.ko
+livepatch: enabling patch '$MOD_LIVEPATCH'
+livepatch: '$MOD_LIVEPATCH': initializing patching transition
+livepatch: '$MOD_LIVEPATCH': starting patching transition
+livepatch: '$MOD_LIVEPATCH': completing patching transition
+livepatch: '$MOD_LIVEPATCH': patching complete
+livepatch: ok
+% echo 0 > /sys/kernel/livepatch/$MOD_LIVEPATCH/enabled
+livepatch: '$MOD_LIVEPATCH': initializing unpatching transition
+livepatch: '$MOD_LIVEPATCH': starting unpatching transition
+livepatch: '$MOD_LIVEPATCH': completing unpatching transition
+livepatch: '$MOD_LIVEPATCH': unpatching complete
+% rmmod $MOD_LIVEPATCH"
+
 exit 0

-- 
2.46.2


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* Re: [PATCH 0/2] selftests: livepatch: test if ftrace can trace a livepatched function
  2025-03-06 21:51 [PATCH 0/2] selftests: livepatch: test if ftrace can trace a livepatched function Filipe Xavier
  2025-03-06 21:51 ` [PATCH PATCH 1/2] selftests: livepatch: add new ftrace helpers functions Filipe Xavier
  2025-03-06 21:51 ` [PATCH PATCH 2/2] selftests: livepatch: test if ftrace can trace a livepatched function Filipe Xavier
@ 2025-03-12  1:53 ` Marcos Paulo de Souza
  2 siblings, 0 replies; 8+ messages in thread
From: Marcos Paulo de Souza @ 2025-03-12  1:53 UTC (permalink / raw)
  To: Filipe Xavier, Josh Poimboeuf, Jiri Kosina, Miroslav Benes,
	Petr Mladek, Joe Lawrence, Shuah Khan
  Cc: live-patching, linux-kselftest, linux-kernel, felipe_life

On Thu, 2025-03-06 at 18:51 -0300, Filipe Xavier wrote:
> This patchset add ftrace helpers functions and
> add a new test makes sure that ftrace can trace
> a function that was introduced by a livepatch.
> 
> Signed-off-by: Filipe Xavier <felipeaggger@gmail.com>
> ---
> Filipe Xavier (2):
>       selftests: livepatch: add new ftrace helpers functions
>       selftests: livepatch: test if ftrace can trace a livepatched
> function
> 
>  tools/testing/selftests/livepatch/functions.sh   | 45
> ++++++++++++++++++++++++
>  tools/testing/selftests/livepatch/test-ftrace.sh | 35
> ++++++++++++++++++
>  2 files changed, 80 insertions(+)
> 

Thanks for sending this new version! One interesting thing is that you
created a new patchset, instead of iterating on the same one, and this
triggered a bug on b4[1]!

You also missed the changelog since v2, but AFAICS you addressed all
comments from me, Joe and Petr, per [2].

For the two patches:

Reviewed-by: Marcos Paulo de Souza <mpdesouza@suse.com>

[1]: https://github.com/mricon/b4/issues/58
[2]:
https://lore.kernel.org/live-patching/b2637bad-9022-496a-9b83-0d348a6350b4@gmail.com/T/#m14bc5c118490c1b17e782a0f0173c1fb70d187c7

> ---
> base-commit: 848e076317446f9c663771ddec142d7c2eb4cb43
> change-id: 20250306-ftrace-sftest-livepatch-60d9dc472235
> 
> Best regards,


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH PATCH 2/2] selftests: livepatch: test if ftrace can trace a livepatched function
  2025-03-06 21:51 ` [PATCH PATCH 2/2] selftests: livepatch: test if ftrace can trace a livepatched function Filipe Xavier
@ 2025-03-14 13:14   ` Miroslav Benes
  2025-03-14 19:00     ` Filipe Xavier
  0 siblings, 1 reply; 8+ messages in thread
From: Miroslav Benes @ 2025-03-14 13:14 UTC (permalink / raw)
  To: Filipe Xavier
  Cc: Josh Poimboeuf, Jiri Kosina, Petr Mladek, Joe Lawrence,
	Shuah Khan, Marcos Paulo de Souza, live-patching, linux-kselftest,
	linux-kernel, felipe_life

Hi,

> +start_test "trace livepatched function and check that the live patch remains in effect"
> +
> +FUNCTION_NAME="livepatch_cmdline_proc_show"
> +
> +load_lp $MOD_LIVEPATCH
> +trace_function "$FUNCTION_NAME"

trace_funtion() calls cleanup_ftrace() to prepare the test. Ok.

> +if [[ "$(cat /proc/cmdline)" == "$MOD_LIVEPATCH: this has been live patched" ]] ; then
> +	log "livepatch: ok"
> +fi
> +
> +check_traced_function "$FUNCTION_NAME"
> +
> +cleanup_tracing

Here, I suppose, cleanup_tracing() is called to clean up after the check 
above so that nothing stays and more tests can be added later. Right? 
Would it make sense then to call cleanup_tracing() in 
check_traced_function()? I think it would less error prone. 
If needed, check_traced_function() can always be upgraded so that it 
checks for more traced functions.

Miroslav

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH PATCH 2/2] selftests: livepatch: test if ftrace can trace a livepatched function
  2025-03-14 13:14   ` Miroslav Benes
@ 2025-03-14 19:00     ` Filipe Xavier
  2025-03-17  9:07       ` Miroslav Benes
  0 siblings, 1 reply; 8+ messages in thread
From: Filipe Xavier @ 2025-03-14 19:00 UTC (permalink / raw)
  To: Miroslav Benes
  Cc: Josh Poimboeuf, Jiri Kosina, Petr Mladek, Joe Lawrence,
	Shuah Khan, Marcos Paulo de Souza, live-patching, linux-kselftest,
	linux-kernel, felipe_life

On 3/14/25 10:14 AM, Miroslav Benes wrote:

> Hi,
>
>> +start_test "trace livepatched function and check that the live patch remains in effect"
>> +
>> +FUNCTION_NAME="livepatch_cmdline_proc_show"
>> +
>> +load_lp $MOD_LIVEPATCH
>> +trace_function "$FUNCTION_NAME"
> trace_funtion() calls cleanup_ftrace() to prepare the test. Ok.
>
>> +if [[ "$(cat /proc/cmdline)" == "$MOD_LIVEPATCH: this has been live patched" ]] ; then
>> +	log "livepatch: ok"
>> +fi
>> +
>> +check_traced_function "$FUNCTION_NAME"
>> +
>> +cleanup_tracing
> Here, I suppose, cleanup_tracing() is called to clean up after the check
> above so that nothing stays and more tests can be added later. Right?
> Would it make sense then to call cleanup_tracing() in
> check_traced_function()? I think it would less error prone.
> If needed, check_traced_function() can always be upgraded so that it
> checks for more traced functions.

In cases where we need to check two or more functions with 
check_traced_function,

if there is cleanup_tracing, it will not be possible, make sense?

e.g: function1 call -> function2 call -> function3.

>
> Miroslav

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH PATCH 2/2] selftests: livepatch: test if ftrace can trace a livepatched function
  2025-03-14 19:00     ` Filipe Xavier
@ 2025-03-17  9:07       ` Miroslav Benes
  2025-03-18 12:31         ` Filipe Xavier
  0 siblings, 1 reply; 8+ messages in thread
From: Miroslav Benes @ 2025-03-17  9:07 UTC (permalink / raw)
  To: Filipe Xavier
  Cc: Josh Poimboeuf, Jiri Kosina, Petr Mladek, Joe Lawrence,
	Shuah Khan, Marcos Paulo de Souza, live-patching, linux-kselftest,
	linux-kernel, felipe_life

On Fri, 14 Mar 2025, Filipe Xavier wrote:

> On 3/14/25 10:14 AM, Miroslav Benes wrote:
> 
> > Hi,
> >
> >> +start_test "trace livepatched function and check that the live patch
> >> remains in effect"
> >> +
> >> +FUNCTION_NAME="livepatch_cmdline_proc_show"
> >> +
> >> +load_lp $MOD_LIVEPATCH
> >> +trace_function "$FUNCTION_NAME"
> > trace_funtion() calls cleanup_ftrace() to prepare the test. Ok.
> >
> >> +if [[ "$(cat /proc/cmdline)" == "$MOD_LIVEPATCH: this has been live
> >> patched" ]] ; then
> >> +	log "livepatch: ok"
> >> +fi
> >> +
> >> +check_traced_function "$FUNCTION_NAME"
> >> +
> >> +cleanup_tracing
> > Here, I suppose, cleanup_tracing() is called to clean up after the check
> > above so that nothing stays and more tests can be added later. Right?
> > Would it make sense then to call cleanup_tracing() in
> > check_traced_function()? I think it would less error prone.
> > If needed, check_traced_function() can always be upgraded so that it
> > checks for more traced functions.
> 
> In cases where we need to check two or more functions with
> check_traced_function,
> 
> if there is cleanup_tracing, it will not be possible, make sense?
> 
> e.g: function1 call -> function2 call -> function3.

I meant... check_traced_function() (or check_traced_functions() in this 
case) can have multiple arguments. You would loop over them inside and 
then clean up. Or did I misunderstood?

Miroslav

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH PATCH 2/2] selftests: livepatch: test if ftrace can trace a livepatched function
  2025-03-17  9:07       ` Miroslav Benes
@ 2025-03-18 12:31         ` Filipe Xavier
  0 siblings, 0 replies; 8+ messages in thread
From: Filipe Xavier @ 2025-03-18 12:31 UTC (permalink / raw)
  To: Miroslav Benes
  Cc: Josh Poimboeuf, Jiri Kosina, Petr Mladek, Joe Lawrence,
	Shuah Khan, Marcos Paulo de Souza, live-patching, linux-kselftest,
	linux-kernel, felipe_life

On 3/17/25 6:07 AM, Miroslav Benes wrote:

> On Fri, 14 Mar 2025, Filipe Xavier wrote:
>
>> On 3/14/25 10:14 AM, Miroslav Benes wrote:
>>
>>> Hi,
>>>
>>>> +start_test "trace livepatched function and check that the live patch
>>>> remains in effect"
>>>> +
>>>> +FUNCTION_NAME="livepatch_cmdline_proc_show"
>>>> +
>>>> +load_lp $MOD_LIVEPATCH
>>>> +trace_function "$FUNCTION_NAME"
>>> trace_funtion() calls cleanup_ftrace() to prepare the test. Ok.
>>>
>>>> +if [[ "$(cat /proc/cmdline)" == "$MOD_LIVEPATCH: this has been live
>>>> patched" ]] ; then
>>>> +	log "livepatch: ok"
>>>> +fi
>>>> +
>>>> +check_traced_function "$FUNCTION_NAME"
>>>> +
>>>> +cleanup_tracing
>>> Here, I suppose, cleanup_tracing() is called to clean up after the check
>>> above so that nothing stays and more tests can be added later. Right?
>>> Would it make sense then to call cleanup_tracing() in
>>> check_traced_function()? I think it would less error prone.
>>> If needed, check_traced_function() can always be upgraded so that it
>>> checks for more traced functions.
>> In cases where we need to check two or more functions with
>> check_traced_function,
>>
>> if there is cleanup_tracing, it will not be possible, make sense?
>>
>> e.g: function1 call -> function2 call -> function3.
> I meant... check_traced_function() (or check_traced_functions() in this
> case) can have multiple arguments. You would loop over them inside and
> then clean up. Or did I misunderstood?

I hadn't thought of it that way, it makes perfect sense. I'll send a new 
version with this adjustment.

>
> Miroslav

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2025-03-18 12:32 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-03-06 21:51 [PATCH 0/2] selftests: livepatch: test if ftrace can trace a livepatched function Filipe Xavier
2025-03-06 21:51 ` [PATCH PATCH 1/2] selftests: livepatch: add new ftrace helpers functions Filipe Xavier
2025-03-06 21:51 ` [PATCH PATCH 2/2] selftests: livepatch: test if ftrace can trace a livepatched function Filipe Xavier
2025-03-14 13:14   ` Miroslav Benes
2025-03-14 19:00     ` Filipe Xavier
2025-03-17  9:07       ` Miroslav Benes
2025-03-18 12:31         ` Filipe Xavier
2025-03-12  1:53 ` [PATCH 0/2] " Marcos Paulo de Souza

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).