kselftests: livepatch: One new test and one fix for older bash
Subsystems (2)
cover kselftests: livepatch: One new test and one fix for older bash
I found the bash issue when running this new test on a SLE12-SP5. There are still other issues that would need to be addressed, but with this change, test-ftrace.sh can run on SLE12-SP5 withou issues.
---
Marcos Paulo de Souza (2):
selftests: livepatch: test-ftrace: livepatch a traced function
selftests: livepatch: functions.sh: Workaround heredoc on older bash
tools/testing/selftests/livepatch/functions.sh | 6 ++-- tools/testing/selftests/livepatch/test-ftrace.sh | 36 ++++++++++++++++++++++++ 2 files changed, 38 insertions(+), 4 deletions(-)
---
base-commit: 6d6ad32e22f028c525d5df471c5522616e645a6b
change-id: 20260220-lp-test-trace-73b2f607960a
Best regards,
Signature · 1 line
Marcos Paulo de Souza <[email protected]>
PATCH 1/2 selftests: livepatch: test-ftrace: livepatch a traced function
This is basically the inverse case of commit 474eecc882ae ("selftests: livepatch: test if ftrace can trace a livepatched function") but ensuring that livepatch would work on a traced function.
--- tools/testing/selftests/livepatch/test-ftrace.sh | 36 ++++++++++++++++++++++++ 1 file changed, 36 insertions(+)
tools/testing/selftests/livepatch/test-ftrace.sh +36 -0
@@ -95,4 +95,40 @@ livepatch: '$MOD_LIVEPATCH': completing unpatching transition livepatch: '$MOD_LIVEPATCH': unpatching complete % rmmod $MOD_LIVEPATCH" + +# - trace a function +# - verify livepatch can load targgeting no the same traced function +# - check if the livepatch is in effect +# - reset trace and unload livepatch + +start_test "livepatch a traced function and check that the live patch remains in effect" + +FUNCTION_NAME="cmdline_proc_show" + +trace_function "$FUNCTION_NAME" +load_lp $MOD_LIVEPATCH + +if [[ "$(cat /proc/cmdline)" == "$MOD_LIVEPATCH: this has been live patched" ]] ; then + log "livepatch: ok" +fi + +check_traced_functions "$FUNCTION_NAME" + +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 > $SYSFS_KLP_DIR/$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
Signature · 1 line
2.52.0
Re: [PATCH 1/2] selftests: livepatch: test-ftrace: livepatch a traced function
Quoted 14 lines · Marcos Paulo de Souza
This is basically the inverse case of commit
474eecc882ae("selftests: livepatch: test if ftrace can trace a livepatched function") but ensuring that livepatch would work on a traced function.Signed-off-by Marcos Paulo de Souza <[email protected]>--- tools/testing/selftests/livepatch/test-ftrace.sh | 36 ++++++++++++++++++++++++ 1 file changed, 36 insertions(+)tools/testing/selftests/livepatch/test-ftrace.sh +0
-0
tools/testing/selftests/livepatch/test-ftrace.sh livepatch: '$MOD_LIVEPATCH': completing unpatching transition · line 100
Quoted 6 lines
tools/testing/selftests/livepatch/test-ftrace.sh +3
-0@@ -95,4 +95,40 @@ livepatch: '$MOD_LIVEPATCH': completing unpatching transition livepatch: '$MOD_LIVEPATCH': unpatching complete % rmmod $MOD_LIVEPATCH" + +# - trace a function +# - verify livepatch can load targgeting no the same traced function
nitpick: s/targgeting no/targeting on/ ?
Otherwise LGTM,
--
Joe
Re: [PATCH 1/2] selftests: livepatch: test-ftrace: livepatch a traced function
In reply to Marcos Paulo de SouzaHi,
Quoted 5 lines · Marcos Paulo de Souza
This is basically the inverse case of commit
474eecc882ae("selftests: livepatch: test if ftrace can trace a livepatched function") but ensuring that livepatch would work on a traced function.Signed-off-by Marcos Paulo de Souza <[email protected]>
with the typo fix that Joe mentioned
M
Re: [PATCH 1/2] selftests: livepatch: test-ftrace: livepatch a traced function
In reply to Marcos Paulo de SouzaQuoted 5 lines · Marcos Paulo de Souza
This is basically the inverse case of commit
474eecc882ae("selftests: livepatch: test if ftrace can trace a livepatched function") but ensuring that livepatch would work on a traced function.Signed-off-by Marcos Paulo de Souza <[email protected]>
Looks and works fine to me:
Best Regards,
Petr
PS: I am going to fix the typo mentioned by Joe and push this patch.
PATCH 2/2 selftests: livepatch: functions.sh: Workaround heredoc on older bash
In reply to Marcos Paulo de SouzaWhen running current selftests on older distributions like SLE12-SP5 that contains an older bash trips over heredoc. Convert it to plain echo calls, which ends up with the same result.
--- tools/testing/selftests/livepatch/functions.sh | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-)
tools/testing/selftests/livepatch/functions.sh +2 -4
@@ -96,10 +96,8 @@ function pop_config() { } function set_dynamic_debug() { - cat <<-EOF > "$SYSFS_DEBUG_DIR/dynamic_debug/control" - file kernel/livepatch/* +p - func klp_try_switch_task -p - EOF + echo "file kernel/livepatch/* +p" > "$SYSFS_DEBUG_DIR/dynamic_debug/control" + echo "func klp_try_switch_task -p" > "$SYSFS_DEBUG_DIR/dynamic_debug/control" } function set_ftrace_enabled() {
Signature · 1 line
2.52.0
Re: [PATCH 2/2] selftests: livepatch: functions.sh: Workaround heredoc on older bash
Quoted 4 lines · Marcos Paulo de Souza
When running current selftests on older distributions like SLE12-SP5 that contains an older bash trips over heredoc. Convert it to plain echo calls, which ends up with the same result.
Just curious, what's the bash/heredoc issue? All I could find via google search was perhaps something to do with the temporary file implementation under the hood.
--
Joe
Quoted 26 lines
Signed-off-by Marcos Paulo de Souza <[email protected]>--- tools/testing/selftests/livepatch/functions.sh | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-)tools/testing/selftests/livepatch/functions.sh +2
-4@@ -96,10 +96,8 @@ function pop_config() { } function set_dynamic_debug() { - cat <<-EOF > "$SYSFS_DEBUG_DIR/dynamic_debug/control" - file kernel/livepatch/* +p - func klp_try_switch_task -p - EOF + echo "file kernel/livepatch/* +p" > "$SYSFS_DEBUG_DIR/dynamic_debug/control" + echo "func klp_try_switch_task -p" > "$SYSFS_DEBUG_DIR/dynamic_debug/control" } function set_ftrace_enabled() {Signature · 2 lines
-- 2.52.0
Re: [PATCH 2/2] selftests: livepatch: functions.sh: Workaround heredoc on older bash
Quoted 9 lines · Joe Lawrence
Quoted 5 lines · Marcos Paulo de Souza
When running current selftests on older distributions like SLE12- SP5 that
contains an older bash trips over heredoc. Convert it to plain echo calls, which ends up with the same result.Acked-by Joe Lawrence <[email protected]>
Thanks for the review Joe!
Quoted 4 lines
Just curious, what's the bash/heredoc issue? All I could find via google search was perhaps something to do with the temporary file implementation under the hood.
# ./test-ftrace.sh cat: -: No such file or directory TEST: livepatch interaction with ftrace_enabled sysctl ... ^CQEMU: Terminated
Somehow it doesn't understand the heredoc, but maybe I'm wrong... either way, the change has the same outcome, so I believe that it wasn't bad if we could change the cat for two echoes :)
Either way, if Petr or you think that this should be left as it is, it's fine by me as well, I was just testing the change with an older rootfs/kernels.
Quoted 33 lines
--
JoeQuoted 29 lines
Signed-off-by Marcos Paulo de Souza <[email protected]>---
tools/testing/selftests/livepatch/functions.sh | 6 ++----1 file changed, 2 insertions(+), 4 deletions(-)tools/testing/selftests/livepatch/functions.sh +0
-0@@ -96,10 +96,8 @@ function pop_config() { }
functionset_dynamic_debug(){
- cat <<-EOF> "$SYSFS_DEBUG_DIR/dynamic_debug/control"tools/testing/selftests/livepatch/functions.sh +1
-3- file kernel/livepatch/* +p - func klp_try_switch_task -p - EOF + echo "file kernel/livepatch/* +p" >"$SYSFS_DEBUG_DIR/dynamic_debug/control"
tools/testing/selftests/livepatch/functions.sh +1
-0+ echo "func klp_try_switch_task -p" >"$SYSFS_DEBUG_DIR/dynamic_debug/control"
}
functionset_ftrace_enabled(){Signature · 1 line
2.52.0
Miroslav Benes
maintainerRe: [PATCH 2/2] selftests: livepatch: functions.sh: Workaround heredoc on older bash
Hi,
Quoted 14 lines · Marcos Paulo de Souza
Quoted 9 lines · Joe Lawrence
Quoted 5 lines · Marcos Paulo de Souza
When running current selftests on older distributions like SLE12- SP5 that
contains an older bash trips over heredoc. Convert it to plain echo calls, which ends up with the same result.Acked-by Joe Lawrence <[email protected]>Thanks for the review Joe!
Quoted 1 line
Quoted 8 lines
Quoted 3 lines
Just curious, what's the bash/heredoc issue? All I could find via google search was perhaps something to do with the temporary file implementation under the hood.
# ./test-ftrace.sh cat: -: No such file or directory TEST: livepatch interaction with ftrace_enabled sysctl ... ^CQEMU: Terminated
I cannot reproduce it locally on SLE12-SP5. The patched test-ftrace.sh runs smoothly without 2/2.
linux:~/linux/tools/testing/selftests/livepatch # ./test-ftrace.sh
TEST: livepatch interaction with ftrace_enabled sysctl ... ok
TEST: trace livepatched function and check that the live patch remains in effect ... ok
TEST: livepatch a traced function and check that the live patch remains in effect ... ok
GNU bash, version 4.3.48(1)-release (x86_64-suse-linux-gnu)
Does "set -x" in the script give you anything interesting?
Miroslav
Re: [PATCH 2/2] selftests: livepatch: functions.sh: Workaround heredoc on older bash
Quoted 41 lines · Miroslav Benes
Hi,
Quoted 21 lines · Marcos Paulo de Souza
Quoted 11 lines · Joe Lawrence
Quoted 7 lines · Marcos Paulo de Souza
When running current selftests on older distributions like SLE12-
SP5 that
contains an older bash trips over heredoc. Convert it to plain echo
calls, which ends up with the same result.Acked-by Joe Lawrence <[email protected]>Thanks for the review Joe!
Quoted 5 lines
Just curious, what's the bash/heredoc issue? All I could find via
google search was perhaps something to do with the temporary file implementation under the hood.Quoted 4 lines
# ./test-ftrace.sh cat: -: No such file or directory TEST: livepatch interaction with ftrace_enabled sysctl ... ^CQEMU: TerminatedI cannot reproduce it locally on SLE12-SP5. The patched test-
ftrace.sh
runs smoothly without 2/2.linux:~/linux/tools/testing/selftests/livepatch # ./test-ftrace.sh
TEST: livepatch interaction withftrace_enabledsysctl ... ok
TEST: trace livepatched function and check that the live patch remains in effect ... ok
TEST: livepatch a traced function and check that the live patch remains in effect ... ok
Quoted 3 lines
GNU bash, version 4.3.48(1)-release (x86_64-suse-linux-gnu)
Does "set -x" in the script give you anything interesting?
Nope:
boot_livepatch:/mnt/tools/testing/selftests/livepatch # ./test-trace.sh
+ cat
cat: -: No such file or directory
+ set_ftrace_enabled 1
+ local can_fail=0
Same version here:
GNU bash, version 4.3.48(1)-release (x86_64-suse-linux-gnu)
I'm using virtme-ng, so I'm not sure if this is related. At the same time it works on SLE15-SP4, using the same virtme-ng, but with a different bash:
GNU bash, version 4.4.23(1)-release (x86_64-suse-linux-gnu)
So I was blaming bash for this issue...
Quoted 2 lines
Miroslav
Re: [PATCH 2/2] selftests: livepatch: functions.sh: Workaround heredoc on older bash
Quoted 62 lines · Marcos Paulo de Souza
Quoted 44 lines · Miroslav Benes
Hi,
Quoted 23 lines · Marcos Paulo de Souza
Quoted 11 lines · Joe Lawrence
Quoted 8 lines · Marcos Paulo de Souza
When running current selftests on older distributions like SLE12-
SP5 that
contains an older bash trips over heredoc. Convert it to plain
echo
calls, which ends up with the same result.Quoted 1 line
Acked-by Joe Lawrence <[email protected]>Thanks for the review Joe!
Quoted 6 lines
Just curious, what's the bash/heredoc issue? All I could find via
google search was perhaps something to do with the temporary file
implementation under the hood.Quoted 5 lines
# ./test-ftrace.sh cat: -: No such file or directory TEST: livepatch interaction with ftrace_enabled sysctl ... ^CQEMU: TerminatedI cannot reproduce it locally on SLE12-SP5. The patched test-
ftrace.sh
runs smoothly without 2/2.linux:~/linux/tools/testing/selftests/livepatch # ./test-ftrace.sh
TEST: livepatch interaction withftrace_enabledsysctl ... ok
TEST: trace livepatched function and check that the live patch remains in effect ... ok
TEST: livepatch a traced function and check that the live patch remains in effect ... okQuoted 3 lines
GNU bash, version 4.3.48(1)-release (x86_64-suse-linux-gnu)
Does "set -x" in the script give you anything interesting?
Nope:
boot_livepatch:/mnt/tools/testing/selftests/livepatch # ./test-
trace.sh
+ cat
cat: -: No such file or directory
+set_ftrace_enabled1
+ local can_fail=0Same version here:
GNU bash, version 4.3.48(1)-release (x86_64-suse-linux-gnu)
Quoted 6 lines
I'm using virtme-ng, so I'm not sure if this is related. At the same time it works on SLE15-SP4, using the same virtme-ng, but with a different bash:
GNU bash, version 4.4.23(1)-release (x86_64-suse-linux-gnu)So I was blaming bash for this issue...
This patch can be skipped. For the record, I discovered that it only happens when vng is called using --rw, making it to fail on older bash since it doesn't create overlays for /tmp. If the overlay is added the issue is gone.
So, this patch can be skipped. Thanks Miroslav for testing!
Quoted 3 lines
Quoted 3 lines
Miroslav
Re: [PATCH 2/2] selftests: livepatch: functions.sh: Workaround heredoc on older bash
In reply to Marcos Paulo de SouzaQuoted 14 lines · On Fri, 20 Feb 2026 11:12:34 -0300 Marcos Paulo de Souza <[email protected]>…
When running current selftests on older distributions like SLE12-SP5 that contains an older bash trips over heredoc. Convert it to plain echo calls, which ends up with the same result.
Signed-off-by Marcos Paulo de Souza <[email protected]>--- tools/testing/selftests/livepatch/functions.sh | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-)tools/testing/selftests/livepatch/functions.sh +0
-0
tools/testing/selftests/livepatch/functions.sh function pop_config() { · line 100
Quoted 9 lines
tools/testing/selftests/livepatch/functions.sh +2
-4@@ -96,10 +96,8 @@ function pop_config() { } function set_dynamic_debug() { - cat <<-EOF > "$SYSFS_DEBUG_DIR/dynamic_debug/control" - file kernel/livepatch/* +p - func klp_try_switch_task -p - EOF + echo "file kernel/livepatch/* +p" > "$SYSFS_DEBUG_DIR/dynamic_debug/control" + echo "func klp_try_switch_task -p" > "$SYSFS_DEBUG_DIR/dynamic_debug/control"
Use printf so you can write both lines in one command.
David
Quoted 4 lines
tools/testing/selftests/livepatch/functions.sh +0
-0} function set_ftrace_enabled() {
Petr Mladek
maintainerRe: [PATCH 2/2] selftests: livepatch: functions.sh: Workaround heredoc on older bash
In reply to Marcos Paulo de SouzaQuoted 5 lines · Marcos Paulo de Souza
When running current selftests on older distributions like SLE12-SP5 that contains an older bash trips over heredoc. Convert it to plain echo calls, which ends up with the same result.
Signed-off-by Marcos Paulo de Souza <[email protected]>
JFYI, the patch has been committed into livepatch.git, branch for-7.1/ftrace-test.
I have fixed the typo reported by Joe, see
https://git.kernel.org/pub/scm/linux/kernel/git/livepatching/livepatching.git/commit/?h=for-7.1/ftrace-test&id=920e5001f4beb38685d5b8cac061cb1d2760eeab
Best Regards,
Petr
Petr Mladek
maintainerRe: [PATCH 2/2] selftests: livepatch: functions.sh: Workaround heredoc on older bash
Quoted 5 lines · Petr Mladek
Quoted 4 lines · Marcos Paulo de Souza
When running current selftests on older distributions like SLE12-SP5 that contains an older bash trips over heredoc. Convert it to plain echo calls, which ends up with the same result.
Quoted 7 lines
Quoted 1 line
Signed-off-by Marcos Paulo de Souza <[email protected]>JFYI, the patch has been committed into livepatch.git, branch for-7.1/ftrace-test.
I have fixed the typo reported by Joe, see
https://git.kernel.org/pub/scm/linux/kernel/git/livepatching/livepatching.git/commit/?h=for-7.1/ftrace-test&id=920e5001f4beb38685d5b8cac061cb1d2760eeab
Grr, the above was meant for the 1st patch.
This 2nd patch was _not_ committed.
Best Regards,
Petr