* [PATCH] selftests: livepatch: Test atomic replace against multiple modules @ 2024-03-12 12:12 Marcos Paulo de Souza 2024-03-21 14:08 ` Joe Lawrence 0 siblings, 1 reply; 4+ messages in thread From: Marcos Paulo de Souza @ 2024-03-12 12:12 UTC (permalink / raw) To: Josh Poimboeuf, Jiri Kosina, Miroslav Benes, Petr Mladek, Joe Lawrence, Shuah Khan Cc: linux-kernel, live-patching, linux-kselftest, Marcos Paulo de Souza This new test checks if a livepatch with replace attribute set replaces all previously applied livepatches. Signed-off-by: Marcos Paulo de Souza <mpdesouza@suse.com> --- tools/testing/selftests/livepatch/Makefile | 3 +- .../selftests/livepatch/test-atomic-replace.sh | 71 ++++++++++++++++++++++ 2 files changed, 73 insertions(+), 1 deletion(-) diff --git a/tools/testing/selftests/livepatch/Makefile b/tools/testing/selftests/livepatch/Makefile index 35418a4790be..e92f61208d35 100644 --- a/tools/testing/selftests/livepatch/Makefile +++ b/tools/testing/selftests/livepatch/Makefile @@ -10,7 +10,8 @@ TEST_PROGS := \ test-state.sh \ test-ftrace.sh \ test-sysfs.sh \ - test-syscall.sh + test-syscall.sh \ + test-atomic-replace.sh TEST_FILES := settings diff --git a/tools/testing/selftests/livepatch/test-atomic-replace.sh b/tools/testing/selftests/livepatch/test-atomic-replace.sh new file mode 100755 index 000000000000..09a3dcdcb8de --- /dev/null +++ b/tools/testing/selftests/livepatch/test-atomic-replace.sh @@ -0,0 +1,71 @@ +#!/bin/bash +# SPDX-License-Identifier: GPL-2.0 +# +# Copyright (C) 2024 SUSE +# Author: Marcos Paulo de Souza <mpdesouza@suse.com> + +. $(dirname $0)/functions.sh + +MOD_REPLACE=test_klp_atomic_replace + +setup_config + +# - Load three livepatch modules. +# - Load one more livepatch with replace being set, and check that only one +# livepatch module is being listed. + +start_test "apply one liveptach to replace multiple livepatches" + +for mod in test_klp_livepatch test_klp_syscall test_klp_callbacks_demo; do + load_lp $mod +done + +nmods=$(ls /sys/kernel/livepatch | wc -l) +if [ $nmods -ne 3 ]; then + die "Expecting three modules listed, found $nmods" +fi + +load_lp $MOD_REPLACE replace=1 + +nmods=$(ls /sys/kernel/livepatch | wc -l) +if [ $nmods -ne 1 ]; then + die "Expecting only one moduled listed, found $nmods" +fi + +disable_lp $MOD_REPLACE +unload_lp $MOD_REPLACE + +check_result "% insmod test_modules/test_klp_livepatch.ko +livepatch: enabling patch 'test_klp_livepatch' +livepatch: 'test_klp_livepatch': initializing patching transition +livepatch: 'test_klp_livepatch': starting patching transition +livepatch: 'test_klp_livepatch': completing patching transition +livepatch: 'test_klp_livepatch': patching complete +% insmod test_modules/test_klp_syscall.ko +livepatch: enabling patch 'test_klp_syscall' +livepatch: 'test_klp_syscall': initializing patching transition +livepatch: 'test_klp_syscall': starting patching transition +livepatch: 'test_klp_syscall': completing patching transition +livepatch: 'test_klp_syscall': patching complete +% insmod test_modules/test_klp_callbacks_demo.ko +livepatch: enabling patch 'test_klp_callbacks_demo' +livepatch: 'test_klp_callbacks_demo': initializing patching transition +test_klp_callbacks_demo: pre_patch_callback: vmlinux +livepatch: 'test_klp_callbacks_demo': starting patching transition +livepatch: 'test_klp_callbacks_demo': completing patching transition +test_klp_callbacks_demo: post_patch_callback: vmlinux +livepatch: 'test_klp_callbacks_demo': patching complete +% insmod test_modules/test_klp_atomic_replace.ko replace=1 +livepatch: enabling patch 'test_klp_atomic_replace' +livepatch: 'test_klp_atomic_replace': initializing patching transition +livepatch: 'test_klp_atomic_replace': starting patching transition +livepatch: 'test_klp_atomic_replace': completing patching transition +livepatch: 'test_klp_atomic_replace': patching complete +% echo 0 > /sys/kernel/livepatch/test_klp_atomic_replace/enabled +livepatch: 'test_klp_atomic_replace': initializing unpatching transition +livepatch: 'test_klp_atomic_replace': starting unpatching transition +livepatch: 'test_klp_atomic_replace': completing unpatching transition +livepatch: 'test_klp_atomic_replace': unpatching complete +% rmmod test_klp_atomic_replace" + +exit 0 --- base-commit: efb3b8b2308470f08266a9ac9cbf42a0fd9ea572 change-id: 20240229-lp-selftest-new-test-e4de120f95c5 Best regards, -- Marcos Paulo de Souza <mpdesouza@suse.com> ^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] selftests: livepatch: Test atomic replace against multiple modules 2024-03-12 12:12 [PATCH] selftests: livepatch: Test atomic replace against multiple modules Marcos Paulo de Souza @ 2024-03-21 14:08 ` Joe Lawrence 2024-03-22 20:31 ` Marcos Paulo de Souza 0 siblings, 1 reply; 4+ messages in thread From: Joe Lawrence @ 2024-03-21 14:08 UTC (permalink / raw) To: Marcos Paulo de Souza, Josh Poimboeuf, Jiri Kosina, Miroslav Benes, Petr Mladek, Shuah Khan Cc: linux-kernel, live-patching, linux-kselftest On 3/12/24 08:12, Marcos Paulo de Souza wrote: > This new test checks if a livepatch with replace attribute set replaces > all previously applied livepatches. > > Signed-off-by: Marcos Paulo de Souza <mpdesouza@suse.com> > --- > tools/testing/selftests/livepatch/Makefile | 3 +- > .../selftests/livepatch/test-atomic-replace.sh | 71 ++++++++++++++++++++++ > 2 files changed, 73 insertions(+), 1 deletion(-) > > diff --git a/tools/testing/selftests/livepatch/Makefile b/tools/testing/selftests/livepatch/Makefile > index 35418a4790be..e92f61208d35 100644 > --- a/tools/testing/selftests/livepatch/Makefile > +++ b/tools/testing/selftests/livepatch/Makefile > @@ -10,7 +10,8 @@ TEST_PROGS := \ > test-state.sh \ > test-ftrace.sh \ > test-sysfs.sh \ > - test-syscall.sh > + test-syscall.sh \ > + test-atomic-replace.sh > > TEST_FILES := settings > > diff --git a/tools/testing/selftests/livepatch/test-atomic-replace.sh b/tools/testing/selftests/livepatch/test-atomic-replace.sh > new file mode 100755 > index 000000000000..09a3dcdcb8de > --- /dev/null > +++ b/tools/testing/selftests/livepatch/test-atomic-replace.sh > @@ -0,0 +1,71 @@ > +#!/bin/bash > +# SPDX-License-Identifier: GPL-2.0 > +# > +# Copyright (C) 2024 SUSE > +# Author: Marcos Paulo de Souza <mpdesouza@suse.com> > + > +. $(dirname $0)/functions.sh > + > +MOD_REPLACE=test_klp_atomic_replace > + > +setup_config > + > +# - Load three livepatch modules. > +# - Load one more livepatch with replace being set, and check that only one > +# livepatch module is being listed. > + > +start_test "apply one liveptach to replace multiple livepatches" > + > +for mod in test_klp_livepatch test_klp_syscall test_klp_callbacks_demo; do > + load_lp $mod > +done > + > +nmods=$(ls /sys/kernel/livepatch | wc -l) > +if [ $nmods -ne 3 ]; then > + die "Expecting three modules listed, found $nmods" > +fi > + > +load_lp $MOD_REPLACE replace=1 > + > +nmods=$(ls /sys/kernel/livepatch | wc -l) > +if [ $nmods -ne 1 ]; then > + die "Expecting only one moduled listed, found $nmods" > +fi > + > +disable_lp $MOD_REPLACE > +unload_lp $MOD_REPLACE > + > +check_result "% insmod test_modules/test_klp_livepatch.ko > +livepatch: enabling patch 'test_klp_livepatch' > +livepatch: 'test_klp_livepatch': initializing patching transition > +livepatch: 'test_klp_livepatch': starting patching transition > +livepatch: 'test_klp_livepatch': completing patching transition > +livepatch: 'test_klp_livepatch': patching complete > +% insmod test_modules/test_klp_syscall.ko > +livepatch: enabling patch 'test_klp_syscall' > +livepatch: 'test_klp_syscall': initializing patching transition > +livepatch: 'test_klp_syscall': starting patching transition > +livepatch: 'test_klp_syscall': completing patching transition > +livepatch: 'test_klp_syscall': patching complete > +% insmod test_modules/test_klp_callbacks_demo.ko > +livepatch: enabling patch 'test_klp_callbacks_demo' > +livepatch: 'test_klp_callbacks_demo': initializing patching transition > +test_klp_callbacks_demo: pre_patch_callback: vmlinux > +livepatch: 'test_klp_callbacks_demo': starting patching transition > +livepatch: 'test_klp_callbacks_demo': completing patching transition > +test_klp_callbacks_demo: post_patch_callback: vmlinux > +livepatch: 'test_klp_callbacks_demo': patching complete > +% insmod test_modules/test_klp_atomic_replace.ko replace=1 > +livepatch: enabling patch 'test_klp_atomic_replace' > +livepatch: 'test_klp_atomic_replace': initializing patching transition > +livepatch: 'test_klp_atomic_replace': starting patching transition > +livepatch: 'test_klp_atomic_replace': completing patching transition > +livepatch: 'test_klp_atomic_replace': patching complete > +% echo 0 > /sys/kernel/livepatch/test_klp_atomic_replace/enabled > +livepatch: 'test_klp_atomic_replace': initializing unpatching transition > +livepatch: 'test_klp_atomic_replace': starting unpatching transition > +livepatch: 'test_klp_atomic_replace': completing unpatching transition > +livepatch: 'test_klp_atomic_replace': unpatching complete > +% rmmod test_klp_atomic_replace" > + > +exit 0 > Hi Marcos, I'm not against adding a specific atomic replace test, but for a quick tl/dr what is the difference between this new test and test-livepatch.sh's "atomic replace livepatch" test? If this one provides better coverage, should we follow up with removing the existing one? -- Joe ^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] selftests: livepatch: Test atomic replace against multiple modules 2024-03-21 14:08 ` Joe Lawrence @ 2024-03-22 20:31 ` Marcos Paulo de Souza 2024-03-25 16:15 ` Joe Lawrence 0 siblings, 1 reply; 4+ messages in thread From: Marcos Paulo de Souza @ 2024-03-22 20:31 UTC (permalink / raw) To: Joe Lawrence, Josh Poimboeuf, Jiri Kosina, Miroslav Benes, Petr Mladek, Shuah Khan Cc: linux-kernel, live-patching, linux-kselftest On Thu, 2024-03-21 at 10:08 -0400, Joe Lawrence wrote: > On 3/12/24 08:12, Marcos Paulo de Souza wrote: > > This new test checks if a livepatch with replace attribute set > > replaces > > all previously applied livepatches. > > > > Signed-off-by: Marcos Paulo de Souza <mpdesouza@suse.com> > > --- > > tools/testing/selftests/livepatch/Makefile | 3 +- > > .../selftests/livepatch/test-atomic-replace.sh | 71 > > ++++++++++++++++++++++ > > 2 files changed, 73 insertions(+), 1 deletion(-) > > > > diff --git a/tools/testing/selftests/livepatch/Makefile > > b/tools/testing/selftests/livepatch/Makefile > > index 35418a4790be..e92f61208d35 100644 > > --- a/tools/testing/selftests/livepatch/Makefile > > +++ b/tools/testing/selftests/livepatch/Makefile > > @@ -10,7 +10,8 @@ TEST_PROGS := \ > > test-state.sh \ > > test-ftrace.sh \ > > test-sysfs.sh \ > > - test-syscall.sh > > + test-syscall.sh \ > > + test-atomic-replace.sh > > > > TEST_FILES := settings > > > > diff --git a/tools/testing/selftests/livepatch/test-atomic- > > replace.sh b/tools/testing/selftests/livepatch/test-atomic- > > replace.sh > > new file mode 100755 > > index 000000000000..09a3dcdcb8de > > --- /dev/null > > +++ b/tools/testing/selftests/livepatch/test-atomic-replace.sh > > @@ -0,0 +1,71 @@ > > +#!/bin/bash > > +# SPDX-License-Identifier: GPL-2.0 > > +# > > +# Copyright (C) 2024 SUSE > > +# Author: Marcos Paulo de Souza <mpdesouza@suse.com> > > + > > +. $(dirname $0)/functions.sh > > + > > +MOD_REPLACE=test_klp_atomic_replace > > + > > +setup_config > > + > > +# - Load three livepatch modules. > > +# - Load one more livepatch with replace being set, and check that > > only one > > +# livepatch module is being listed. > > + > > +start_test "apply one liveptach to replace multiple livepatches" > > + > > +for mod in test_klp_livepatch test_klp_syscall > > test_klp_callbacks_demo; do > > + load_lp $mod > > +done > > + > > +nmods=$(ls /sys/kernel/livepatch | wc -l) > > +if [ $nmods -ne 3 ]; then > > + die "Expecting three modules listed, found $nmods" > > +fi > > + > > +load_lp $MOD_REPLACE replace=1 > > + > > +nmods=$(ls /sys/kernel/livepatch | wc -l) > > +if [ $nmods -ne 1 ]; then > > + die "Expecting only one moduled listed, found $nmods" > > +fi > > + > > +disable_lp $MOD_REPLACE > > +unload_lp $MOD_REPLACE > > + > > +check_result "% insmod test_modules/test_klp_livepatch.ko > > +livepatch: enabling patch 'test_klp_livepatch' > > +livepatch: 'test_klp_livepatch': initializing patching transition > > +livepatch: 'test_klp_livepatch': starting patching transition > > +livepatch: 'test_klp_livepatch': completing patching transition > > +livepatch: 'test_klp_livepatch': patching complete > > +% insmod test_modules/test_klp_syscall.ko > > +livepatch: enabling patch 'test_klp_syscall' > > +livepatch: 'test_klp_syscall': initializing patching transition > > +livepatch: 'test_klp_syscall': starting patching transition > > +livepatch: 'test_klp_syscall': completing patching transition > > +livepatch: 'test_klp_syscall': patching complete > > +% insmod test_modules/test_klp_callbacks_demo.ko > > +livepatch: enabling patch 'test_klp_callbacks_demo' > > +livepatch: 'test_klp_callbacks_demo': initializing patching > > transition > > +test_klp_callbacks_demo: pre_patch_callback: vmlinux > > +livepatch: 'test_klp_callbacks_demo': starting patching transition > > +livepatch: 'test_klp_callbacks_demo': completing patching > > transition > > +test_klp_callbacks_demo: post_patch_callback: vmlinux > > +livepatch: 'test_klp_callbacks_demo': patching complete > > +% insmod test_modules/test_klp_atomic_replace.ko replace=1 > > +livepatch: enabling patch 'test_klp_atomic_replace' > > +livepatch: 'test_klp_atomic_replace': initializing patching > > transition > > +livepatch: 'test_klp_atomic_replace': starting patching transition > > +livepatch: 'test_klp_atomic_replace': completing patching > > transition > > +livepatch: 'test_klp_atomic_replace': patching complete > > +% echo 0 > /sys/kernel/livepatch/test_klp_atomic_replace/enabled > > +livepatch: 'test_klp_atomic_replace': initializing unpatching > > transition > > +livepatch: 'test_klp_atomic_replace': starting unpatching > > transition > > +livepatch: 'test_klp_atomic_replace': completing unpatching > > transition > > +livepatch: 'test_klp_atomic_replace': unpatching complete > > +% rmmod test_klp_atomic_replace" > > + > > +exit 0 > > > > Hi Marcos, > > I'm not against adding a specific atomic replace test, but for a > quick > tl/dr what is the difference between this new test and > test-livepatch.sh's "atomic replace livepatch" test? > > If this one provides better coverage, should we follow up with > removing > the existing one? Hi Joe, thanks for looking at it. To be honest I haven't checked the current use of atomic replace on test-livepatch.sh =/ yes, that's mostly the same case, but in mine I load three modules and then load the third one replacing the others, while in the test- livepatch.sh we have only one module that is loaded, replaced, and then we unload the replaced one. Do you see value in extending the test at test-livepatch.sh to load more than one LP moduled and the replace all of them with another one? I believe that it adds more coverage, while keeping the number of tests the same. Thanks! > ^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] selftests: livepatch: Test atomic replace against multiple modules 2024-03-22 20:31 ` Marcos Paulo de Souza @ 2024-03-25 16:15 ` Joe Lawrence 0 siblings, 0 replies; 4+ messages in thread From: Joe Lawrence @ 2024-03-25 16:15 UTC (permalink / raw) To: Marcos Paulo de Souza, Josh Poimboeuf, Jiri Kosina, Miroslav Benes, Petr Mladek, Shuah Khan Cc: linux-kernel, live-patching, linux-kselftest On 3/22/24 16:31, Marcos Paulo de Souza wrote: > On Thu, 2024-03-21 at 10:08 -0400, Joe Lawrence wrote: >> On 3/12/24 08:12, Marcos Paulo de Souza wrote: >>> This new test checks if a livepatch with replace attribute set >>> replaces >>> all previously applied livepatches. >>> >>> Signed-off-by: Marcos Paulo de Souza <mpdesouza@suse.com> >>> --- >>> tools/testing/selftests/livepatch/Makefile | 3 +- >>> .../selftests/livepatch/test-atomic-replace.sh | 71 >>> ++++++++++++++++++++++ >>> 2 files changed, 73 insertions(+), 1 deletion(-) >>> >>> diff --git a/tools/testing/selftests/livepatch/Makefile >>> b/tools/testing/selftests/livepatch/Makefile >>> index 35418a4790be..e92f61208d35 100644 >>> --- a/tools/testing/selftests/livepatch/Makefile >>> +++ b/tools/testing/selftests/livepatch/Makefile >>> @@ -10,7 +10,8 @@ TEST_PROGS := \ >>> test-state.sh \ >>> test-ftrace.sh \ >>> test-sysfs.sh \ >>> - test-syscall.sh >>> + test-syscall.sh \ >>> + test-atomic-replace.sh >>> >>> TEST_FILES := settings >>> >>> diff --git a/tools/testing/selftests/livepatch/test-atomic- >>> replace.sh b/tools/testing/selftests/livepatch/test-atomic- >>> replace.sh >>> new file mode 100755 >>> index 000000000000..09a3dcdcb8de >>> --- /dev/null >>> +++ b/tools/testing/selftests/livepatch/test-atomic-replace.sh >>> @@ -0,0 +1,71 @@ >>> +#!/bin/bash >>> +# SPDX-License-Identifier: GPL-2.0 >>> +# >>> +# Copyright (C) 2024 SUSE >>> +# Author: Marcos Paulo de Souza <mpdesouza@suse.com> >>> + >>> +. $(dirname $0)/functions.sh >>> + >>> +MOD_REPLACE=test_klp_atomic_replace >>> + >>> +setup_config >>> + >>> +# - Load three livepatch modules. >>> +# - Load one more livepatch with replace being set, and check that >>> only one >>> +# livepatch module is being listed. >>> + >>> +start_test "apply one liveptach to replace multiple livepatches" >>> + >>> +for mod in test_klp_livepatch test_klp_syscall >>> test_klp_callbacks_demo; do >>> + load_lp $mod >>> +done >>> + >>> +nmods=$(ls /sys/kernel/livepatch | wc -l) >>> +if [ $nmods -ne 3 ]; then >>> + die "Expecting three modules listed, found $nmods" >>> +fi >>> + >>> +load_lp $MOD_REPLACE replace=1 >>> + >>> +nmods=$(ls /sys/kernel/livepatch | wc -l) >>> +if [ $nmods -ne 1 ]; then >>> + die "Expecting only one moduled listed, found $nmods" >>> +fi >>> + >>> +disable_lp $MOD_REPLACE >>> +unload_lp $MOD_REPLACE >>> + >>> +check_result "% insmod test_modules/test_klp_livepatch.ko >>> +livepatch: enabling patch 'test_klp_livepatch' >>> +livepatch: 'test_klp_livepatch': initializing patching transition >>> +livepatch: 'test_klp_livepatch': starting patching transition >>> +livepatch: 'test_klp_livepatch': completing patching transition >>> +livepatch: 'test_klp_livepatch': patching complete >>> +% insmod test_modules/test_klp_syscall.ko >>> +livepatch: enabling patch 'test_klp_syscall' >>> +livepatch: 'test_klp_syscall': initializing patching transition >>> +livepatch: 'test_klp_syscall': starting patching transition >>> +livepatch: 'test_klp_syscall': completing patching transition >>> +livepatch: 'test_klp_syscall': patching complete >>> +% insmod test_modules/test_klp_callbacks_demo.ko >>> +livepatch: enabling patch 'test_klp_callbacks_demo' >>> +livepatch: 'test_klp_callbacks_demo': initializing patching >>> transition >>> +test_klp_callbacks_demo: pre_patch_callback: vmlinux >>> +livepatch: 'test_klp_callbacks_demo': starting patching transition >>> +livepatch: 'test_klp_callbacks_demo': completing patching >>> transition >>> +test_klp_callbacks_demo: post_patch_callback: vmlinux >>> +livepatch: 'test_klp_callbacks_demo': patching complete >>> +% insmod test_modules/test_klp_atomic_replace.ko replace=1 >>> +livepatch: enabling patch 'test_klp_atomic_replace' >>> +livepatch: 'test_klp_atomic_replace': initializing patching >>> transition >>> +livepatch: 'test_klp_atomic_replace': starting patching transition >>> +livepatch: 'test_klp_atomic_replace': completing patching >>> transition >>> +livepatch: 'test_klp_atomic_replace': patching complete >>> +% echo 0 > /sys/kernel/livepatch/test_klp_atomic_replace/enabled >>> +livepatch: 'test_klp_atomic_replace': initializing unpatching >>> transition >>> +livepatch: 'test_klp_atomic_replace': starting unpatching >>> transition >>> +livepatch: 'test_klp_atomic_replace': completing unpatching >>> transition >>> +livepatch: 'test_klp_atomic_replace': unpatching complete >>> +% rmmod test_klp_atomic_replace" >>> + >>> +exit 0 >>> >> >> Hi Marcos, >> >> I'm not against adding a specific atomic replace test, but for a >> quick >> tl/dr what is the difference between this new test and >> test-livepatch.sh's "atomic replace livepatch" test? >> >> If this one provides better coverage, should we follow up with >> removing >> the existing one? > > Hi Joe, > > thanks for looking at it. To be honest I haven't checked the current > use of atomic replace on test-livepatch.sh =/ > > yes, that's mostly the same case, but in mine I load three modules and > then load the third one replacing the others, while in the test- > livepatch.sh we have only one module that is loaded, replaced, and then > we unload the replaced one. > > Do you see value in extending the test at test-livepatch.sh to load > more than one LP moduled and the replace all of them with another one? > I believe that it adds more coverage, while keeping the number of tests > the same. > Yeah, it shouldn't be too hard to combine this test with the existing one by adding the 3 module load to the beginning of the test. Verifying the livepatch count is an interesting new wrinkle. (Do check out the shellcheck warning about leveraging the output of ls, though.) If atomic-replace was used throughout the test suite, I might say that load_mod should be aware and check accordingly, but it's not the default build mode, so counting the final livepatches in the test itself seems reasonable enough. -- Joe ^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2024-03-25 16:15 UTC | newest] Thread overview: 4+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2024-03-12 12:12 [PATCH] selftests: livepatch: Test atomic replace against multiple modules Marcos Paulo de Souza 2024-03-21 14:08 ` Joe Lawrence 2024-03-22 20:31 ` Marcos Paulo de Souza 2024-03-25 16:15 ` Joe Lawrence
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox