live-patching.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] selftests/livepatch: Check if CONFIG_LIVEPATCH is enabled
@ 2024-11-06 17:41 Siddharth Menon
  2024-11-15 10:13 ` Miroslav Benes
  2024-11-15 17:14 ` Petr Mladek
  0 siblings, 2 replies; 4+ messages in thread
From: Siddharth Menon @ 2024-11-06 17:41 UTC (permalink / raw)
  To: shuah, jpoimboe, jikos, mbenes, pmladek
  Cc: Siddharth Menon, Shuah Khan, live-patching, linux-kselftest

When CONFIG_LIVEPATCH is disabled, compilation fails due to the
required structs from the livepatch header file being undefined.
This checks for CONFIG_LIVEPATCH in order to verify that
it is enabled before compiling livepatch self-tests.

Reviewed-by: Shuah Khan <skhan@linuxfoundation.org>
Signed-off-by: Siddharth Menon <simeddon@gmail.com>
---
 tools/testing/selftests/livepatch/test_modules/Makefile | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/tools/testing/selftests/livepatch/test_modules/Makefile b/tools/testing/selftests/livepatch/test_modules/Makefile
index e6e638c4bcba..b34b80544709 100644
--- a/tools/testing/selftests/livepatch/test_modules/Makefile
+++ b/tools/testing/selftests/livepatch/test_modules/Makefile
@@ -1,5 +1,6 @@
 TESTMODS_DIR := $(realpath $(dir $(abspath $(lastword $(MAKEFILE_LIST)))))
 KDIR ?= /lib/modules/$(shell uname -r)/build
+CONFIG_LIVEPATCH := $(shell cd $(KDIR) && scripts/config --state CONFIG_LIVEPATCH)
 
 obj-m += test_klp_atomic_replace.o \
 	test_klp_callbacks_busy.o \
@@ -13,10 +14,15 @@ obj-m += test_klp_atomic_replace.o \
 	test_klp_shadow_vars.o \
 	test_klp_syscall.o
 
-# Ensure that KDIR exists, otherwise skip the compilation
+
+# Ensure that KDIR exists and CONFIG_LIVEPATCH is enabled, else skip compilation
 modules:
 ifneq ("$(wildcard $(KDIR))", "")
+ifneq ($(filter y m,$(CONFIG_LIVEPATCH)),)
 	$(Q)$(MAKE) -C $(KDIR) modules KBUILD_EXTMOD=$(TESTMODS_DIR)
+else
+    $(warning CONFIG_LIVEPATCH is not enabled in the kernel config file.)
+endif
 endif
 
 # Ensure that KDIR exists, otherwise skip the clean target
-- 
2.39.5


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

* Re: [PATCH] selftests/livepatch: Check if CONFIG_LIVEPATCH is enabled
  2024-11-06 17:41 [PATCH] selftests/livepatch: Check if CONFIG_LIVEPATCH is enabled Siddharth Menon
@ 2024-11-15 10:13 ` Miroslav Benes
  2024-11-15 17:14 ` Petr Mladek
  1 sibling, 0 replies; 4+ messages in thread
From: Miroslav Benes @ 2024-11-15 10:13 UTC (permalink / raw)
  To: Siddharth Menon
  Cc: shuah, jpoimboe, jikos, pmladek, Shuah Khan, live-patching,
	linux-kselftest, mpdesouza

Hi,

On Wed, 6 Nov 2024, Siddharth Menon wrote:

> When CONFIG_LIVEPATCH is disabled, compilation fails due to the
> required structs from the livepatch header file being undefined.
> This checks for CONFIG_LIVEPATCH in order to verify that
> it is enabled before compiling livepatch self-tests.
> 
> Reviewed-by: Shuah Khan <skhan@linuxfoundation.org>
> Signed-off-by: Siddharth Menon <simeddon@gmail.com>
> ---
>  tools/testing/selftests/livepatch/test_modules/Makefile | 8 +++++++-
>  1 file changed, 7 insertions(+), 1 deletion(-)

thank you for the patch.

tools/testing/selftests/livepatch/config contains

CONFIG_LIVEPATCH=y
CONFIG_DYNAMIC_DEBUG=y

I assumed that these prerequisites are respected but apparently not for 
building the test modules if I understand it correctly.

Is it possible to fix it in the way that the config file is respected? Or 
how do kselftests work with that?

Regards,
Miroslav

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

* Re: [PATCH] selftests/livepatch: Check if CONFIG_LIVEPATCH is enabled
  2024-11-06 17:41 [PATCH] selftests/livepatch: Check if CONFIG_LIVEPATCH is enabled Siddharth Menon
  2024-11-15 10:13 ` Miroslav Benes
@ 2024-11-15 17:14 ` Petr Mladek
  2024-11-17 16:18   ` Sid
  1 sibling, 1 reply; 4+ messages in thread
From: Petr Mladek @ 2024-11-15 17:14 UTC (permalink / raw)
  To: Siddharth Menon
  Cc: shuah, jpoimboe, jikos, mbenes, Shuah Khan, live-patching,
	linux-kselftest

On Wed 2024-11-06 23:11:20, Siddharth Menon wrote:
> When CONFIG_LIVEPATCH is disabled, compilation fails due to the
> required structs from the livepatch header file being undefined.
> This checks for CONFIG_LIVEPATCH in order to verify that
> it is enabled before compiling livepatch self-tests.
> 
> Reviewed-by: Shuah Khan <skhan@linuxfoundation.org>
> Signed-off-by: Siddharth Menon <simeddon@gmail.com>
> ---
>  tools/testing/selftests/livepatch/test_modules/Makefile | 8 +++++++-
>  1 file changed, 7 insertions(+), 1 deletion(-)
> 
> diff --git a/tools/testing/selftests/livepatch/test_modules/Makefile b/tools/testing/selftests/livepatch/test_modules/Makefile
> index e6e638c4bcba..b34b80544709 100644
> --- a/tools/testing/selftests/livepatch/test_modules/Makefile
> +++ b/tools/testing/selftests/livepatch/test_modules/Makefile
> @@ -1,5 +1,6 @@
>  TESTMODS_DIR := $(realpath $(dir $(abspath $(lastword $(MAKEFILE_LIST)))))
>  KDIR ?= /lib/modules/$(shell uname -r)/build
> +CONFIG_LIVEPATCH := $(shell cd $(KDIR) && scripts/config --state CONFIG_LIVEPATCH)
>  
>  obj-m += test_klp_atomic_replace.o \
>  	test_klp_callbacks_busy.o \
> @@ -13,10 +14,15 @@ obj-m += test_klp_atomic_replace.o \
>  	test_klp_shadow_vars.o \
>  	test_klp_syscall.o
>  
> -# Ensure that KDIR exists, otherwise skip the compilation
> +
> +# Ensure that KDIR exists and CONFIG_LIVEPATCH is enabled, else skip compilation
>  modules:
>  ifneq ("$(wildcard $(KDIR))", "")
> +ifneq ($(filter y m,$(CONFIG_LIVEPATCH)),)
>  	$(Q)$(MAKE) -C $(KDIR) modules KBUILD_EXTMOD=$(TESTMODS_DIR)
> +else
> +    $(warning CONFIG_LIVEPATCH is not enabled in the kernel config file.)
> +endif
>  endif

This handles only the build of the modules.

It does not block building the test_klp-call_getpid binary.
Also it does not block running the tests, so I get:

tools/testing/selftests/livepatch # make run_tests 
  CC       test_klp-call_getpid
Makefile:24: CONFIG_LIVEPATCH is not enabled in the kernel config file.
make[1]: Nothing to be done for 'modules'.
TAP version 13
1..7
# timeout set to 0
# selftests: livepatch: test-livepatch.sh
# TEST: basic function patching ... ERROR: Can't find "test_modules/test_klp_livepatch.ko", try "make"
not ok 1 selftests: livepatch: test-livepatch.sh # exit=1
# timeout set to 0
# selftests: livepatch: test-callbacks.sh
# TEST: target module before livepatch ... ERROR: Can't find "test_modules/test_klp_callbacks_mod.ko", try "make"
not ok 2 selftests: livepatch: test-callbacks.sh # exit=1
...


I like idea mentioned in Miroslav's reply. I wonder if the check
could take into account all CONFIG_* variables mentioned
in tools/testing/selftests/livepatch/config.

And if it could be generic so that it works for all
tools/testing/selftests/<project> directories.

And for both build and run_tests.

Best Regards,
Petr

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

* Re: [PATCH] selftests/livepatch: Check if CONFIG_LIVEPATCH is enabled
  2024-11-15 17:14 ` Petr Mladek
@ 2024-11-17 16:18   ` Sid
  0 siblings, 0 replies; 4+ messages in thread
From: Sid @ 2024-11-17 16:18 UTC (permalink / raw)
  To: Petr Mladek
  Cc: shuah, jpoimboe, jikos, mbenes, Shuah Khan, live-patching,
	linux-kselftest

On Fri, 15 Nov 2024 at 22:44, Petr Mladek <pmladek@suse.com> wrote:
>
> I like idea mentioned in Miroslav's reply. I wonder if the check
> could take into account all CONFIG_* variables mentioned
> in tools/testing/selftests/livepatch/config.

Thanks for the feedback, I will create a new patch as suggested by Miroslav

> And if it could be generic so that it works for all
> tools/testing/selftests/<project> directories.
>
> And for both build and run_tests.

I will look into it

Sincerely,
Siddharth Menon

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

end of thread, other threads:[~2024-11-17 16:18 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-11-06 17:41 [PATCH] selftests/livepatch: Check if CONFIG_LIVEPATCH is enabled Siddharth Menon
2024-11-15 10:13 ` Miroslav Benes
2024-11-15 17:14 ` Petr Mladek
2024-11-17 16:18   ` Sid

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).