live-patching.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/1] selftests: livepatch: add test cases of stack_order sysfs
@ 2024-10-08  7:52 Wardenjohn
  2024-10-08  7:52 ` [PATCH 1/1] selftests: livepatch: add test cases of stack_order sysfs interface Wardenjohn
  0 siblings, 1 reply; 8+ messages in thread
From: Wardenjohn @ 2024-10-08  7:52 UTC (permalink / raw)
  To: jpoimboe, mbenes, jikos, pmladek, joe.lawrence
  Cc: live-patching, linux-kernel

This patch add self test cases to 'stack_order' sysfs interface.

Reuse test module of 'test_klp_livepatch'. However, some module in test_module
have '.replace' enable. So, I set the replace value of the stack_order test 
module to false.

Regards.
Wardenjohn.

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

* [PATCH 1/1] selftests: livepatch: add test cases of stack_order sysfs interface
  2024-10-08  7:52 [PATCH 0/1] selftests: livepatch: add test cases of stack_order sysfs Wardenjohn
@ 2024-10-08  7:52 ` Wardenjohn
  2024-10-10 12:31   ` Marcos Paulo de Souza
  0 siblings, 1 reply; 8+ messages in thread
From: Wardenjohn @ 2024-10-08  7:52 UTC (permalink / raw)
  To: jpoimboe, mbenes, jikos, pmladek, joe.lawrence
  Cc: live-patching, linux-kernel, Wardenjohn

Add selftest test cases to sysfs attribute 'stack_order'.

Signed-off-by: Wardenjohn <zhangwarden@gmail.com>
---
 .../testing/selftests/livepatch/test-sysfs.sh | 71 +++++++++++++++++++
 .../selftests/livepatch/test_modules/Makefile |  5 +-
 .../test_klp_livepatch_noreplace.c            | 53 ++++++++++++++
 .../test_klp_livepatch_noreplace2.c           | 53 ++++++++++++++
 .../test_klp_livepatch_noreplace3.c           | 53 ++++++++++++++
 5 files changed, 234 insertions(+), 1 deletion(-)
 create mode 100644 tools/testing/selftests/livepatch/test_modules/test_klp_livepatch_noreplace.c
 create mode 100644 tools/testing/selftests/livepatch/test_modules/test_klp_livepatch_noreplace2.c
 create mode 100644 tools/testing/selftests/livepatch/test_modules/test_klp_livepatch_noreplace3.c

diff --git a/tools/testing/selftests/livepatch/test-sysfs.sh b/tools/testing/selftests/livepatch/test-sysfs.sh
index 05a14f5a7bfb..a086b62fb488 100755
--- a/tools/testing/selftests/livepatch/test-sysfs.sh
+++ b/tools/testing/selftests/livepatch/test-sysfs.sh
@@ -5,6 +5,9 @@
 . $(dirname $0)/functions.sh
 
 MOD_LIVEPATCH=test_klp_livepatch
+MOD_LIVEPATCH_NOREPLACE=test_klp_livepatch_noreplace
+MOD_LIVEPATCH_NOREPLACE2=test_klp_livepatch_noreplace2
+MOD_LIVEPATCH_NOREPLACE3=test_klp_livepatch_noreplace3
 
 setup_config
 
@@ -131,4 +134,72 @@ livepatch: '$MOD_LIVEPATCH': completing unpatching transition
 livepatch: '$MOD_LIVEPATCH': unpatching complete
 % rmmod $MOD_LIVEPATCH"
 
+start_test "sysfs test stack_order read"
+
+load_lp $MOD_LIVEPATCH_NOREPLACE
+
+check_sysfs_rights "$MOD_LIVEPATCH_NOREPLACE" "stack_order" "-r--r--r--"
+check_sysfs_value  "$MOD_LIVEPATCH_NOREPLACE" "stack_order" "1"
+
+load_lp $MOD_LIVEPATCH_NOREPLACE2
+
+check_sysfs_rights "$MOD_LIVEPATCH_NOREPLACE2" "stack_order" "-r--r--r--"
+check_sysfs_value  "$MOD_LIVEPATCH_NOREPLACE2" "stack_order" "2"
+
+load_lp $MOD_LIVEPATCH_NOREPLACE3
+
+check_sysfs_rights "$MOD_LIVEPATCH_NOREPLACE3" "stack_order" "-r--r--r--"
+check_sysfs_value  "$MOD_LIVEPATCH_NOREPLACE3" "stack_order" "3"
+
+disable_lp $MOD_LIVEPATCH_NOREPLACE2
+unload_lp $MOD_LIVEPATCH_NOREPLACE2
+
+check_sysfs_rights "$MOD_LIVEPATCH_NOREPLACE" "stack_order" "-r--r--r--"
+check_sysfs_value  "$MOD_LIVEPATCH_NOREPLACE" "stack_order" "1"
+check_sysfs_rights "$MOD_LIVEPATCH_NOREPLACE3" "stack_order" "-r--r--r--"
+check_sysfs_value  "$MOD_LIVEPATCH_NOREPLACE3" "stack_order" "2"
+
+disable_lp $MOD_LIVEPATCH_NOREPLACE3
+unload_lp $MOD_LIVEPATCH_NOREPLACE3
+
+disable_lp $MOD_LIVEPATCH_NOREPLACE
+unload_lp $MOD_LIVEPATCH_NOREPLACE
+
+check_result "% insmod test_modules/$MOD_LIVEPATCH_NOREPLACE.ko
+livepatch: enabling patch '$MOD_LIVEPATCH_NOREPLACE'
+livepatch: '$MOD_LIVEPATCH_NOREPLACE': initializing patching transition
+livepatch: '$MOD_LIVEPATCH_NOREPLACE': starting patching transition
+livepatch: '$MOD_LIVEPATCH_NOREPLACE': completing patching transition
+livepatch: '$MOD_LIVEPATCH_NOREPLACE': patching complete
+% insmod test_modules/$MOD_LIVEPATCH_NOREPLACE2.ko
+livepatch: enabling patch '$MOD_LIVEPATCH_NOREPLACE2'
+livepatch: '$MOD_LIVEPATCH_NOREPLACE2': initializing patching transition
+livepatch: '$MOD_LIVEPATCH_NOREPLACE2': starting patching transition
+livepatch: '$MOD_LIVEPATCH_NOREPLACE2': completing patching transition
+livepatch: '$MOD_LIVEPATCH_NOREPLACE2': patching complete
+% insmod test_modules/$MOD_LIVEPATCH_NOREPLACE3.ko
+livepatch: enabling patch '$MOD_LIVEPATCH_NOREPLACE3'
+livepatch: '$MOD_LIVEPATCH_NOREPLACE3': initializing patching transition
+livepatch: '$MOD_LIVEPATCH_NOREPLACE3': starting patching transition
+livepatch: '$MOD_LIVEPATCH_NOREPLACE3': completing patching transition
+livepatch: '$MOD_LIVEPATCH_NOREPLACE3': patching complete
+% echo 0 > /sys/kernel/livepatch/$MOD_LIVEPATCH_NOREPLACE2/enabled
+livepatch: '$MOD_LIVEPATCH_NOREPLACE2': initializing unpatching transition
+livepatch: '$MOD_LIVEPATCH_NOREPLACE2': starting unpatching transition
+livepatch: '$MOD_LIVEPATCH_NOREPLACE2': completing unpatching transition
+livepatch: '$MOD_LIVEPATCH_NOREPLACE2': unpatching complete
+% rmmod $MOD_LIVEPATCH_NOREPLACE2
+% echo 0 > /sys/kernel/livepatch/$MOD_LIVEPATCH_NOREPLACE3/enabled
+livepatch: '$MOD_LIVEPATCH_NOREPLACE3': initializing unpatching transition
+livepatch: '$MOD_LIVEPATCH_NOREPLACE3': starting unpatching transition
+livepatch: '$MOD_LIVEPATCH_NOREPLACE3': completing unpatching transition
+livepatch: '$MOD_LIVEPATCH_NOREPLACE3': unpatching complete
+% rmmod $MOD_LIVEPATCH_NOREPLACE3
+% echo 0 > /sys/kernel/livepatch/$MOD_LIVEPATCH_NOREPLACE/enabled
+livepatch: '$MOD_LIVEPATCH_NOREPLACE': initializing unpatching transition
+livepatch: '$MOD_LIVEPATCH_NOREPLACE': starting unpatching transition
+livepatch: '$MOD_LIVEPATCH_NOREPLACE': completing unpatching transition
+livepatch: '$MOD_LIVEPATCH_NOREPLACE': unpatching complete
+% rmmod $MOD_LIVEPATCH_NOREPLACE"
+
 exit 0
diff --git a/tools/testing/selftests/livepatch/test_modules/Makefile b/tools/testing/selftests/livepatch/test_modules/Makefile
index e6e638c4bcba..dad6ca00d3e6 100644
--- a/tools/testing/selftests/livepatch/test_modules/Makefile
+++ b/tools/testing/selftests/livepatch/test_modules/Makefile
@@ -11,7 +11,10 @@ obj-m += test_klp_atomic_replace.o \
 	test_klp_state2.o \
 	test_klp_state3.o \
 	test_klp_shadow_vars.o \
-	test_klp_syscall.o
+	test_klp_syscall.o \
+	test_klp_livepatch_noreplace.o \
+	test_klp_livepatch_noreplace2.o \
+	test_klp_livepatch_noreplace3.o \
 
 # Ensure that KDIR exists, otherwise skip the compilation
 modules:
diff --git a/tools/testing/selftests/livepatch/test_modules/test_klp_livepatch_noreplace.c b/tools/testing/selftests/livepatch/test_modules/test_klp_livepatch_noreplace.c
new file mode 100644
index 000000000000..ead609aeac67
--- /dev/null
+++ b/tools/testing/selftests/livepatch/test_modules/test_klp_livepatch_noreplace.c
@@ -0,0 +1,53 @@
+// SPDX-License-Identifier: GPL-2.0
+// Copyright (C) 2014 Seth Jennings <sjenning@redhat.com>
+
+#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
+
+#include <linux/module.h>
+#include <linux/kernel.h>
+#include <linux/livepatch.h>
+
+#include <linux/seq_file.h>
+static int livepatch_cmdline_proc_show(struct seq_file *m, void *v)
+{
+	seq_printf(m, "%s: %s\n", THIS_MODULE->name,
+		   "this has been live patched with number 1");
+	return 0;
+}
+
+static struct klp_func funcs[] = {
+	{
+		.old_name = "cmdline_proc_show",
+		.new_func = livepatch_cmdline_proc_show,
+	}, { }
+};
+
+static struct klp_object objs[] = {
+	{
+		/* name being NULL means vmlinux */
+		.funcs = funcs,
+	}, { }
+};
+
+static struct klp_patch patch = {
+	.mod = THIS_MODULE,
+	.objs = objs,
+	.replace = false,
+};
+
+static int test_klp_livepatch_init(void)
+{
+	return klp_enable_patch(&patch);
+}
+
+static void test_klp_livepatch_exit(void)
+{
+}
+
+module_init(test_klp_livepatch_init);
+module_exit(test_klp_livepatch_exit);
+MODULE_LICENSE("GPL");
+MODULE_INFO(livepatch, "Y");
+MODULE_AUTHOR("Seth Jennings <sjenning@redhat.com>");
+MODULE_AUTHOR("Wardenjohn <zhangwarden@gmail.com>");
+MODULE_DESCRIPTION("Livepatch test: livepatch module");
diff --git a/tools/testing/selftests/livepatch/test_modules/test_klp_livepatch_noreplace2.c b/tools/testing/selftests/livepatch/test_modules/test_klp_livepatch_noreplace2.c
new file mode 100644
index 000000000000..8d54b0976be1
--- /dev/null
+++ b/tools/testing/selftests/livepatch/test_modules/test_klp_livepatch_noreplace2.c
@@ -0,0 +1,53 @@
+// SPDX-License-Identifier: GPL-2.0
+// Copyright (C) 2014 Seth Jennings <sjenning@redhat.com>
+
+#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
+
+#include <linux/module.h>
+#include <linux/kernel.h>
+#include <linux/livepatch.h>
+
+#include <linux/seq_file.h>
+static int livepatch_cmdline_proc_show(struct seq_file *m, void *v)
+{
+	seq_printf(m, "%s: %s\n", THIS_MODULE->name,
+		   "this has been live patched with number 2");
+	return 0;
+}
+
+static struct klp_func funcs[] = {
+	{
+		.old_name = "cmdline_proc_show",
+		.new_func = livepatch_cmdline_proc_show,
+	}, { }
+};
+
+static struct klp_object objs[] = {
+	{
+		/* name being NULL means vmlinux */
+		.funcs = funcs,
+	}, { }
+};
+
+static struct klp_patch patch = {
+	.mod = THIS_MODULE,
+	.objs = objs,
+	.replace = false,
+};
+
+static int test_klp_livepatch_init(void)
+{
+	return klp_enable_patch(&patch);
+}
+
+static void test_klp_livepatch_exit(void)
+{
+}
+
+module_init(test_klp_livepatch_init);
+module_exit(test_klp_livepatch_exit);
+MODULE_LICENSE("GPL");
+MODULE_INFO(livepatch, "Y");
+MODULE_AUTHOR("Seth Jennings <sjenning@redhat.com>");
+MODULE_AUTHOR("Wardenjohn <zhangwarden@gmail.com>");
+MODULE_DESCRIPTION("Livepatch test: livepatch module");
diff --git a/tools/testing/selftests/livepatch/test_modules/test_klp_livepatch_noreplace3.c b/tools/testing/selftests/livepatch/test_modules/test_klp_livepatch_noreplace3.c
new file mode 100644
index 000000000000..a267c58e07d4
--- /dev/null
+++ b/tools/testing/selftests/livepatch/test_modules/test_klp_livepatch_noreplace3.c
@@ -0,0 +1,53 @@
+// SPDX-License-Identifier: GPL-2.0
+// Copyright (C) 2014 Seth Jennings <sjenning@redhat.com>
+
+#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
+
+#include <linux/module.h>
+#include <linux/kernel.h>
+#include <linux/livepatch.h>
+
+#include <linux/seq_file.h>
+static int livepatch_cmdline_proc_show(struct seq_file *m, void *v)
+{
+	seq_printf(m, "%s: %s\n", THIS_MODULE->name,
+		   "this has been live patched with number 3");
+	return 0;
+}
+
+static struct klp_func funcs[] = {
+	{
+		.old_name = "cmdline_proc_show",
+		.new_func = livepatch_cmdline_proc_show,
+	}, { }
+};
+
+static struct klp_object objs[] = {
+	{
+		/* name being NULL means vmlinux */
+		.funcs = funcs,
+	}, { }
+};
+
+static struct klp_patch patch = {
+	.mod = THIS_MODULE,
+	.objs = objs,
+	.replace = false,
+};
+
+static int test_klp_livepatch_init(void)
+{
+	return klp_enable_patch(&patch);
+}
+
+static void test_klp_livepatch_exit(void)
+{
+}
+
+module_init(test_klp_livepatch_init);
+module_exit(test_klp_livepatch_exit);
+MODULE_LICENSE("GPL");
+MODULE_INFO(livepatch, "Y");
+MODULE_AUTHOR("Seth Jennings <sjenning@redhat.com>");
+MODULE_AUTHOR("Wardenjohn <zhangwarden@gmail.com>");
+MODULE_DESCRIPTION("Livepatch test: livepatch module");
-- 
2.43.5


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

* Re: [PATCH 1/1] selftests: livepatch: add test cases of stack_order sysfs interface
  2024-10-08  7:52 ` [PATCH 1/1] selftests: livepatch: add test cases of stack_order sysfs interface Wardenjohn
@ 2024-10-10 12:31   ` Marcos Paulo de Souza
  2024-10-10 15:11     ` zhang warden
  0 siblings, 1 reply; 8+ messages in thread
From: Marcos Paulo de Souza @ 2024-10-10 12:31 UTC (permalink / raw)
  To: Wardenjohn, jpoimboe, mbenes, jikos, pmladek, joe.lawrence
  Cc: live-patching, linux-kernel

On Tue, 2024-10-08 at 15:52 +0800, Wardenjohn wrote:
> Add selftest test cases to sysfs attribute 'stack_order'.
> 
> Signed-off-by: Wardenjohn <zhangwarden@gmail.com>
> ---
>  .../testing/selftests/livepatch/test-sysfs.sh | 71
> +++++++++++++++++++
>  .../selftests/livepatch/test_modules/Makefile |  5 +-
>  .../test_klp_livepatch_noreplace.c            | 53 ++++++++++++++
>  .../test_klp_livepatch_noreplace2.c           | 53 ++++++++++++++
>  .../test_klp_livepatch_noreplace3.c           | 53 ++++++++++++++
>  5 files changed, 234 insertions(+), 1 deletion(-)
>  create mode 100644
> tools/testing/selftests/livepatch/test_modules/test_klp_livepatch_nor
> eplace.c
>  create mode 100644
> tools/testing/selftests/livepatch/test_modules/test_klp_livepatch_nor
> eplace2.c
>  create mode 100644
> tools/testing/selftests/livepatch/test_modules/test_klp_livepatch_nor
> eplace3.c

IIUC, you only need to test the stack order by loading LP modules. In
this case you could use our currently existing LP testing module for
that, right? That's what we currently do when testing different sysfs
attributes.

> 
> diff --git a/tools/testing/selftests/livepatch/test-sysfs.sh
> b/tools/testing/selftests/livepatch/test-sysfs.sh
> index 05a14f5a7bfb..a086b62fb488 100755
> --- a/tools/testing/selftests/livepatch/test-sysfs.sh
> +++ b/tools/testing/selftests/livepatch/test-sysfs.sh
> @@ -5,6 +5,9 @@
>  . $(dirname $0)/functions.sh
>  
>  MOD_LIVEPATCH=test_klp_livepatch
> +MOD_LIVEPATCH_NOREPLACE=test_klp_livepatch_noreplace
> +MOD_LIVEPATCH_NOREPLACE2=test_klp_livepatch_noreplace2
> +MOD_LIVEPATCH_NOREPLACE3=test_klp_livepatch_noreplace3
>  
>  setup_config
>  
> @@ -131,4 +134,72 @@ livepatch: '$MOD_LIVEPATCH': completing
> unpatching transition
>  livepatch: '$MOD_LIVEPATCH': unpatching complete
>  % rmmod $MOD_LIVEPATCH"
>  
> +start_test "sysfs test stack_order read"
> +
> +load_lp $MOD_LIVEPATCH_NOREPLACE
> +
> +check_sysfs_rights "$MOD_LIVEPATCH_NOREPLACE" "stack_order" "-r--r--
> r--"
> +check_sysfs_value  "$MOD_LIVEPATCH_NOREPLACE" "stack_order" "1"
> +
> +load_lp $MOD_LIVEPATCH_NOREPLACE2
> +
> +check_sysfs_rights "$MOD_LIVEPATCH_NOREPLACE2" "stack_order" "-r--r-
> -r--"
> +check_sysfs_value  "$MOD_LIVEPATCH_NOREPLACE2" "stack_order" "2"
> +
> +load_lp $MOD_LIVEPATCH_NOREPLACE3
> +
> +check_sysfs_rights "$MOD_LIVEPATCH_NOREPLACE3" "stack_order" "-r--r-
> -r--"
> +check_sysfs_value  "$MOD_LIVEPATCH_NOREPLACE3" "stack_order" "3"
> +
> +disable_lp $MOD_LIVEPATCH_NOREPLACE2
> +unload_lp $MOD_LIVEPATCH_NOREPLACE2
> +
> +check_sysfs_rights "$MOD_LIVEPATCH_NOREPLACE" "stack_order" "-r--r--
> r--"
> +check_sysfs_value  "$MOD_LIVEPATCH_NOREPLACE" "stack_order" "1"
> +check_sysfs_rights "$MOD_LIVEPATCH_NOREPLACE3" "stack_order" "-r--r-
> -r--"
> +check_sysfs_value  "$MOD_LIVEPATCH_NOREPLACE3" "stack_order" "2"
> +
> +disable_lp $MOD_LIVEPATCH_NOREPLACE3
> +unload_lp $MOD_LIVEPATCH_NOREPLACE3
> +
> +disable_lp $MOD_LIVEPATCH_NOREPLACE
> +unload_lp $MOD_LIVEPATCH_NOREPLACE
> +
> +check_result "% insmod test_modules/$MOD_LIVEPATCH_NOREPLACE.ko
> +livepatch: enabling patch '$MOD_LIVEPATCH_NOREPLACE'
> +livepatch: '$MOD_LIVEPATCH_NOREPLACE': initializing patching
> transition
> +livepatch: '$MOD_LIVEPATCH_NOREPLACE': starting patching transition
> +livepatch: '$MOD_LIVEPATCH_NOREPLACE': completing patching
> transition
> +livepatch: '$MOD_LIVEPATCH_NOREPLACE': patching complete
> +% insmod test_modules/$MOD_LIVEPATCH_NOREPLACE2.ko
> +livepatch: enabling patch '$MOD_LIVEPATCH_NOREPLACE2'
> +livepatch: '$MOD_LIVEPATCH_NOREPLACE2': initializing patching
> transition
> +livepatch: '$MOD_LIVEPATCH_NOREPLACE2': starting patching transition
> +livepatch: '$MOD_LIVEPATCH_NOREPLACE2': completing patching
> transition
> +livepatch: '$MOD_LIVEPATCH_NOREPLACE2': patching complete
> +% insmod test_modules/$MOD_LIVEPATCH_NOREPLACE3.ko
> +livepatch: enabling patch '$MOD_LIVEPATCH_NOREPLACE3'
> +livepatch: '$MOD_LIVEPATCH_NOREPLACE3': initializing patching
> transition
> +livepatch: '$MOD_LIVEPATCH_NOREPLACE3': starting patching transition
> +livepatch: '$MOD_LIVEPATCH_NOREPLACE3': completing patching
> transition
> +livepatch: '$MOD_LIVEPATCH_NOREPLACE3': patching complete
> +% echo 0 > /sys/kernel/livepatch/$MOD_LIVEPATCH_NOREPLACE2/enabled
> +livepatch: '$MOD_LIVEPATCH_NOREPLACE2': initializing unpatching
> transition
> +livepatch: '$MOD_LIVEPATCH_NOREPLACE2': starting unpatching
> transition
> +livepatch: '$MOD_LIVEPATCH_NOREPLACE2': completing unpatching
> transition
> +livepatch: '$MOD_LIVEPATCH_NOREPLACE2': unpatching complete
> +% rmmod $MOD_LIVEPATCH_NOREPLACE2
> +% echo 0 > /sys/kernel/livepatch/$MOD_LIVEPATCH_NOREPLACE3/enabled
> +livepatch: '$MOD_LIVEPATCH_NOREPLACE3': initializing unpatching
> transition
> +livepatch: '$MOD_LIVEPATCH_NOREPLACE3': starting unpatching
> transition
> +livepatch: '$MOD_LIVEPATCH_NOREPLACE3': completing unpatching
> transition
> +livepatch: '$MOD_LIVEPATCH_NOREPLACE3': unpatching complete
> +% rmmod $MOD_LIVEPATCH_NOREPLACE3
> +% echo 0 > /sys/kernel/livepatch/$MOD_LIVEPATCH_NOREPLACE/enabled
> +livepatch: '$MOD_LIVEPATCH_NOREPLACE': initializing unpatching
> transition
> +livepatch: '$MOD_LIVEPATCH_NOREPLACE': starting unpatching
> transition
> +livepatch: '$MOD_LIVEPATCH_NOREPLACE': completing unpatching
> transition
> +livepatch: '$MOD_LIVEPATCH_NOREPLACE': unpatching complete
> +% rmmod $MOD_LIVEPATCH_NOREPLACE"
> +
>  exit 0
> diff --git a/tools/testing/selftests/livepatch/test_modules/Makefile
> b/tools/testing/selftests/livepatch/test_modules/Makefile
> index e6e638c4bcba..dad6ca00d3e6 100644
> --- a/tools/testing/selftests/livepatch/test_modules/Makefile
> +++ b/tools/testing/selftests/livepatch/test_modules/Makefile
> @@ -11,7 +11,10 @@ obj-m += test_klp_atomic_replace.o \
>  	test_klp_state2.o \
>  	test_klp_state3.o \
>  	test_klp_shadow_vars.o \
> -	test_klp_syscall.o
> +	test_klp_syscall.o \
> +	test_klp_livepatch_noreplace.o \
> +	test_klp_livepatch_noreplace2.o \
> +	test_klp_livepatch_noreplace3.o \
>  
>  # Ensure that KDIR exists, otherwise skip the compilation
>  modules:
> diff --git
> a/tools/testing/selftests/livepatch/test_modules/test_klp_livepatch_n
> oreplace.c
> b/tools/testing/selftests/livepatch/test_modules/test_klp_livepatch_n
> oreplace.c
> new file mode 100644
> index 000000000000..ead609aeac67
> --- /dev/null
> +++
> b/tools/testing/selftests/livepatch/test_modules/test_klp_livepatch_n
> oreplace.c
> @@ -0,0 +1,53 @@
> +// SPDX-License-Identifier: GPL-2.0
> +// Copyright (C) 2014 Seth Jennings <sjenning@redhat.com>
> +
> +#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
> +
> +#include <linux/module.h>
> +#include <linux/kernel.h>
> +#include <linux/livepatch.h>
> +
> +#include <linux/seq_file.h>
> +static int livepatch_cmdline_proc_show(struct seq_file *m, void *v)
> +{
> +	seq_printf(m, "%s: %s\n", THIS_MODULE->name,
> +		   "this has been live patched with number 1");
> +	return 0;
> +}
> +
> +static struct klp_func funcs[] = {
> +	{
> +		.old_name = "cmdline_proc_show",
> +		.new_func = livepatch_cmdline_proc_show,
> +	}, { }
> +};
> +
> +static struct klp_object objs[] = {
> +	{
> +		/* name being NULL means vmlinux */
> +		.funcs = funcs,
> +	}, { }
> +};
> +
> +static struct klp_patch patch = {
> +	.mod = THIS_MODULE,
> +	.objs = objs,
> +	.replace = false,
> +};
> +
> +static int test_klp_livepatch_init(void)
> +{
> +	return klp_enable_patch(&patch);
> +}
> +
> +static void test_klp_livepatch_exit(void)
> +{
> +}
> +
> +module_init(test_klp_livepatch_init);
> +module_exit(test_klp_livepatch_exit);
> +MODULE_LICENSE("GPL");
> +MODULE_INFO(livepatch, "Y");
> +MODULE_AUTHOR("Seth Jennings <sjenning@redhat.com>");
> +MODULE_AUTHOR("Wardenjohn <zhangwarden@gmail.com>");
> +MODULE_DESCRIPTION("Livepatch test: livepatch module");
> diff --git
> a/tools/testing/selftests/livepatch/test_modules/test_klp_livepatch_n
> oreplace2.c
> b/tools/testing/selftests/livepatch/test_modules/test_klp_livepatch_n
> oreplace2.c
> new file mode 100644
> index 000000000000..8d54b0976be1
> --- /dev/null
> +++
> b/tools/testing/selftests/livepatch/test_modules/test_klp_livepatch_n
> oreplace2.c
> @@ -0,0 +1,53 @@
> +// SPDX-License-Identifier: GPL-2.0
> +// Copyright (C) 2014 Seth Jennings <sjenning@redhat.com>
> +
> +#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
> +
> +#include <linux/module.h>
> +#include <linux/kernel.h>
> +#include <linux/livepatch.h>
> +
> +#include <linux/seq_file.h>
> +static int livepatch_cmdline_proc_show(struct seq_file *m, void *v)
> +{
> +	seq_printf(m, "%s: %s\n", THIS_MODULE->name,
> +		   "this has been live patched with number 2");
> +	return 0;
> +}
> +
> +static struct klp_func funcs[] = {
> +	{
> +		.old_name = "cmdline_proc_show",
> +		.new_func = livepatch_cmdline_proc_show,
> +	}, { }
> +};
> +
> +static struct klp_object objs[] = {
> +	{
> +		/* name being NULL means vmlinux */
> +		.funcs = funcs,
> +	}, { }
> +};
> +
> +static struct klp_patch patch = {
> +	.mod = THIS_MODULE,
> +	.objs = objs,
> +	.replace = false,
> +};
> +
> +static int test_klp_livepatch_init(void)
> +{
> +	return klp_enable_patch(&patch);
> +}
> +
> +static void test_klp_livepatch_exit(void)
> +{
> +}
> +
> +module_init(test_klp_livepatch_init);
> +module_exit(test_klp_livepatch_exit);
> +MODULE_LICENSE("GPL");
> +MODULE_INFO(livepatch, "Y");
> +MODULE_AUTHOR("Seth Jennings <sjenning@redhat.com>");
> +MODULE_AUTHOR("Wardenjohn <zhangwarden@gmail.com>");
> +MODULE_DESCRIPTION("Livepatch test: livepatch module");
> diff --git
> a/tools/testing/selftests/livepatch/test_modules/test_klp_livepatch_n
> oreplace3.c
> b/tools/testing/selftests/livepatch/test_modules/test_klp_livepatch_n
> oreplace3.c
> new file mode 100644
> index 000000000000..a267c58e07d4
> --- /dev/null
> +++
> b/tools/testing/selftests/livepatch/test_modules/test_klp_livepatch_n
> oreplace3.c
> @@ -0,0 +1,53 @@
> +// SPDX-License-Identifier: GPL-2.0
> +// Copyright (C) 2014 Seth Jennings <sjenning@redhat.com>
> +
> +#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
> +
> +#include <linux/module.h>
> +#include <linux/kernel.h>
> +#include <linux/livepatch.h>
> +
> +#include <linux/seq_file.h>
> +static int livepatch_cmdline_proc_show(struct seq_file *m, void *v)
> +{
> +	seq_printf(m, "%s: %s\n", THIS_MODULE->name,
> +		   "this has been live patched with number 3");
> +	return 0;
> +}
> +
> +static struct klp_func funcs[] = {
> +	{
> +		.old_name = "cmdline_proc_show",
> +		.new_func = livepatch_cmdline_proc_show,
> +	}, { }
> +};
> +
> +static struct klp_object objs[] = {
> +	{
> +		/* name being NULL means vmlinux */
> +		.funcs = funcs,
> +	}, { }
> +};
> +
> +static struct klp_patch patch = {
> +	.mod = THIS_MODULE,
> +	.objs = objs,
> +	.replace = false,
> +};
> +
> +static int test_klp_livepatch_init(void)
> +{
> +	return klp_enable_patch(&patch);
> +}
> +
> +static void test_klp_livepatch_exit(void)
> +{
> +}
> +
> +module_init(test_klp_livepatch_init);
> +module_exit(test_klp_livepatch_exit);
> +MODULE_LICENSE("GPL");
> +MODULE_INFO(livepatch, "Y");
> +MODULE_AUTHOR("Seth Jennings <sjenning@redhat.com>");
> +MODULE_AUTHOR("Wardenjohn <zhangwarden@gmail.com>");
> +MODULE_DESCRIPTION("Livepatch test: livepatch module");


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

* Re: [PATCH 1/1] selftests: livepatch: add test cases of stack_order sysfs interface
  2024-10-10 12:31   ` Marcos Paulo de Souza
@ 2024-10-10 15:11     ` zhang warden
  2024-10-10 15:51       ` Josh Poimboeuf
  0 siblings, 1 reply; 8+ messages in thread
From: zhang warden @ 2024-10-10 15:11 UTC (permalink / raw)
  To: Marcos Paulo de Souza
  Cc: Josh Poimboeuf, Miroslav Benes, Jiri Kosina, Petr Mladek,
	Joe Lawrence, live-patching, linux-kernel


Hi, Marcos!
> On Oct 10, 2024, at 20:31, Marcos Paulo de Souza <mpdesouza@suse.com> wrote:
> 
> On Tue, 2024-10-08 at 15:52 +0800, Wardenjohn wrote:
>> Add selftest test cases to sysfs attribute 'stack_order'.
>> 
>> Signed-off-by: Wardenjohn <zhangwarden@gmail.com>
>> ---
>>  .../testing/selftests/livepatch/test-sysfs.sh | 71
>> +++++++++++++++++++
>>  .../selftests/livepatch/test_modules/Makefile |  5 +-
>>  .../test_klp_livepatch_noreplace.c            | 53 ++++++++++++++
>>  .../test_klp_livepatch_noreplace2.c           | 53 ++++++++++++++
>>  .../test_klp_livepatch_noreplace3.c           | 53 ++++++++++++++
>>  5 files changed, 234 insertions(+), 1 deletion(-)
>>  create mode 100644
>> tools/testing/selftests/livepatch/test_modules/test_klp_livepatch_nor
>> eplace.c
>>  create mode 100644
>> tools/testing/selftests/livepatch/test_modules/test_klp_livepatch_nor
>> eplace2.c
>>  create mode 100644
>> tools/testing/selftests/livepatch/test_modules/test_klp_livepatch_nor
>> eplace3.c
> 
> IIUC, you only need to test the stack order by loading LP modules. In
> this case you could use our currently existing LP testing module for
> that, right? That's what we currently do when testing different sysfs
> attributes.
> 

Yes, in fact, those three module I submitted is reuse the existing LP
testing module of 'test_klp_livepatch'. Because I found some module
in test module set "klp_replace" attribute true. If a module set this
attribute true, it will disable the previous module. 

What's more, testing this 'stack_order' attribute need more than one
module, hoping to change the same function. And breaking the '.replace'
value of existing module may not be a good way. So I decided to copy 
more test module with '.replace=false' and this module is changing 
the same function.

Regards.
Wardenjohn.

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

* Re: [PATCH 1/1] selftests: livepatch: add test cases of stack_order sysfs interface
  2024-10-10 15:11     ` zhang warden
@ 2024-10-10 15:51       ` Josh Poimboeuf
  2024-10-11  1:51         ` zhang warden
  0 siblings, 1 reply; 8+ messages in thread
From: Josh Poimboeuf @ 2024-10-10 15:51 UTC (permalink / raw)
  To: zhang warden
  Cc: Marcos Paulo de Souza, Miroslav Benes, Jiri Kosina, Petr Mladek,
	Joe Lawrence, live-patching, linux-kernel

On Thu, Oct 10, 2024 at 11:11:56PM +0800, zhang warden wrote:
> > IIUC, you only need to test the stack order by loading LP modules. In
> > this case you could use our currently existing LP testing module for
> > that, right? That's what we currently do when testing different sysfs
> > attributes.
> > 
> 
> Yes, in fact, those three module I submitted is reuse the existing LP
> testing module of 'test_klp_livepatch'. Because I found some module
> in test module set "klp_replace" attribute true. If a module set this
> attribute true, it will disable the previous module. 
> 
> What's more, testing this 'stack_order' attribute need more than one
> module, hoping to change the same function. And breaking the '.replace'
> value of existing module may not be a good way. So I decided to copy 
> more test module with '.replace=false' and this module is changing 
> the same function.

Maybe add a replace=[true|false] module parameter.

-- 
Josh

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

* Re: [PATCH 1/1] selftests: livepatch: add test cases of stack_order sysfs interface
  2024-10-10 15:51       ` Josh Poimboeuf
@ 2024-10-11  1:51         ` zhang warden
  2024-10-11  4:09           ` Josh Poimboeuf
  2024-10-11  8:36           ` Petr Mladek
  0 siblings, 2 replies; 8+ messages in thread
From: zhang warden @ 2024-10-11  1:51 UTC (permalink / raw)
  To: Josh Poimboeuf
  Cc: Marcos Paulo de Souza, Miroslav Benes, Jiri Kosina, Petr Mladek,
	Joe Lawrence, live-patching, linux-kernel



> On Oct 10, 2024, at 23:51, Josh Poimboeuf <jpoimboe@kernel.org> wrote:
> 
> Maybe add a replace=[true|false] module parameter.
> 

How to do it? 
Isn't the way we build modules using make?
How to set this replace value?

Regards
Wardenjohn

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

* Re: [PATCH 1/1] selftests: livepatch: add test cases of stack_order sysfs interface
  2024-10-11  1:51         ` zhang warden
@ 2024-10-11  4:09           ` Josh Poimboeuf
  2024-10-11  8:36           ` Petr Mladek
  1 sibling, 0 replies; 8+ messages in thread
From: Josh Poimboeuf @ 2024-10-11  4:09 UTC (permalink / raw)
  To: zhang warden
  Cc: Marcos Paulo de Souza, Miroslav Benes, Jiri Kosina, Petr Mladek,
	Joe Lawrence, live-patching, linux-kernel

On Fri, Oct 11, 2024 at 09:51:07AM +0800, zhang warden wrote:
> 
> 
> > On Oct 10, 2024, at 23:51, Josh Poimboeuf <jpoimboe@kernel.org> wrote:
> > 
> > Maybe add a replace=[true|false] module parameter.
> > 
> 
> How to do it? 
> Isn't the way we build modules using make?
> How to set this replace value?

See for example what
  
  tools/testing/selftests/livepatch/test_modules/test_klp_atomic_replace.c

is already doing with its "replace" parameter.  Just add replace=0 to
the insmod args to disable replace mode.

-- 
Josh

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

* Re: [PATCH 1/1] selftests: livepatch: add test cases of stack_order sysfs interface
  2024-10-11  1:51         ` zhang warden
  2024-10-11  4:09           ` Josh Poimboeuf
@ 2024-10-11  8:36           ` Petr Mladek
  1 sibling, 0 replies; 8+ messages in thread
From: Petr Mladek @ 2024-10-11  8:36 UTC (permalink / raw)
  To: zhang warden
  Cc: Josh Poimboeuf, Marcos Paulo de Souza, Miroslav Benes,
	Jiri Kosina, Joe Lawrence, live-patching, linux-kernel

On Fri 2024-10-11 09:51:07, zhang warden wrote:
> 
> 
> > On Oct 10, 2024, at 23:51, Josh Poimboeuf <jpoimboe@kernel.org> wrote:
> > 
> > Maybe add a replace=[true|false] module parameter.
> > 
> 
> How to do it? 
> Isn't the way we build modules using make?
> How to set this replace value?

You could find inspiration in
tools/testing/selftests/livepatch/test-livepatch.sh, see

load_lp $MOD_REPLACE replace=0

vs.

load_lp $MOD_REPLACE replace=1

You could more or less copy the "multiple livepatches" and
"atomic replace livepatch" self-tests. The new tests
would check the "stack_order" sysfs value instread of checking
whether /proc/cmdline and /proc/meminfo are livepatched.

Best Regards,
Petr

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

end of thread, other threads:[~2024-10-11  8:36 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-10-08  7:52 [PATCH 0/1] selftests: livepatch: add test cases of stack_order sysfs Wardenjohn
2024-10-08  7:52 ` [PATCH 1/1] selftests: livepatch: add test cases of stack_order sysfs interface Wardenjohn
2024-10-10 12:31   ` Marcos Paulo de Souza
2024-10-10 15:11     ` zhang warden
2024-10-10 15:51       ` Josh Poimboeuf
2024-10-11  1:51         ` zhang warden
2024-10-11  4:09           ` Josh Poimboeuf
2024-10-11  8:36           ` Petr Mladek

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