aboutsummaryrefslogtreecommitdiffstats
path: root/lib/livepatch/test_klp_atomic_replace.c
diff options
context:
space:
mode:
authorJoe Lawrence <joe.lawrence@redhat.com>2019-01-09 07:43:29 -0500
committerJiri Kosina <jkosina@suse.cz>2019-01-11 14:51:24 -0500
commita2818ee4dce575b299d8a7f46b393bc2b02ef1f4 (patch)
tree0f616177ebf9e8d2f00023f8db89a89374e65c94 /lib/livepatch/test_klp_atomic_replace.c
parentd67a53720966f2ef5be5c8f238d13512b8260868 (diff)
selftests/livepatch: introduce tests
Add a few livepatch modules and simple target modules that the included regression suite can run tests against: - basic livepatching (multiple patches, atomic replace) - pre/post (un)patch callbacks - shadow variable API Signed-off-by: Joe Lawrence <joe.lawrence@redhat.com> Signed-off-by: Petr Mladek <pmladek@suse.com> Tested-by: Miroslav Benes <mbenes@suse.cz> Tested-by: Alice Ferrazzi <alice.ferrazzi@gmail.com> Acked-by: Joe Lawrence <joe.lawrence@redhat.com> Acked-by: Josh Poimboeuf <jpoimboe@redhat.com> Signed-off-by: Jiri Kosina <jkosina@suse.cz>
Diffstat (limited to 'lib/livepatch/test_klp_atomic_replace.c')
-rw-r--r--lib/livepatch/test_klp_atomic_replace.c57
1 files changed, 57 insertions, 0 deletions
diff --git a/lib/livepatch/test_klp_atomic_replace.c b/lib/livepatch/test_klp_atomic_replace.c
new file mode 100644
index 000000000000..5af7093ca00c
--- /dev/null
+++ b/lib/livepatch/test_klp_atomic_replace.c
@@ -0,0 +1,57 @@
1// SPDX-License-Identifier: GPL-2.0
2// Copyright (C) 2018 Joe Lawrence <joe.lawrence@redhat.com>
3
4#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
5
6#include <linux/module.h>
7#include <linux/kernel.h>
8#include <linux/livepatch.h>
9
10static int replace;
11module_param(replace, int, 0644);
12MODULE_PARM_DESC(replace, "replace (default=0)");
13
14#include <linux/seq_file.h>
15static int livepatch_meminfo_proc_show(struct seq_file *m, void *v)
16{
17 seq_printf(m, "%s: %s\n", THIS_MODULE->name,
18 "this has been live patched");
19 return 0;
20}
21
22static struct klp_func funcs[] = {
23 {
24 .old_name = "meminfo_proc_show",
25 .new_func = livepatch_meminfo_proc_show,
26 }, {}
27};
28
29static struct klp_object objs[] = {
30 {
31 /* name being NULL means vmlinux */
32 .funcs = funcs,
33 }, {}
34};
35
36static struct klp_patch patch = {
37 .mod = THIS_MODULE,
38 .objs = objs,
39 /* set .replace in the init function below for demo purposes */
40};
41
42static int test_klp_atomic_replace_init(void)
43{
44 patch.replace = replace;
45 return klp_enable_patch(&patch);
46}
47
48static void test_klp_atomic_replace_exit(void)
49{
50}
51
52module_init(test_klp_atomic_replace_init);
53module_exit(test_klp_atomic_replace_exit);
54MODULE_LICENSE("GPL");
55MODULE_INFO(livepatch, "Y");
56MODULE_AUTHOR("Joe Lawrence <joe.lawrence@redhat.com>");
57MODULE_DESCRIPTION("Livepatch test: atomic replace");