Merge tag 'block-5.11-2021-01-16' of git://git.kernel.dk/linux-block
[linux/fpc-iii.git] / lib / livepatch / test_klp_atomic_replace.c
blob5af7093ca00c45518bc824ccb51f407b4c49c2b4
1 // SPDX-License-Identifier: GPL-2.0
2 // Copyright (C) 2018 Joe Lawrence <joe.lawrence@redhat.com>
4 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
6 #include <linux/module.h>
7 #include <linux/kernel.h>
8 #include <linux/livepatch.h>
10 static int replace;
11 module_param(replace, int, 0644);
12 MODULE_PARM_DESC(replace, "replace (default=0)");
14 #include <linux/seq_file.h>
15 static int livepatch_meminfo_proc_show(struct seq_file *m, void *v)
17 seq_printf(m, "%s: %s\n", THIS_MODULE->name,
18 "this has been live patched");
19 return 0;
22 static struct klp_func funcs[] = {
24 .old_name = "meminfo_proc_show",
25 .new_func = livepatch_meminfo_proc_show,
26 }, {}
29 static struct klp_object objs[] = {
31 /* name being NULL means vmlinux */
32 .funcs = funcs,
33 }, {}
36 static struct klp_patch patch = {
37 .mod = THIS_MODULE,
38 .objs = objs,
39 /* set .replace in the init function below for demo purposes */
42 static int test_klp_atomic_replace_init(void)
44 patch.replace = replace;
45 return klp_enable_patch(&patch);
48 static void test_klp_atomic_replace_exit(void)
52 module_init(test_klp_atomic_replace_init);
53 module_exit(test_klp_atomic_replace_exit);
54 MODULE_LICENSE("GPL");
55 MODULE_INFO(livepatch, "Y");
56 MODULE_AUTHOR("Joe Lawrence <joe.lawrence@redhat.com>");
57 MODULE_DESCRIPTION("Livepatch test: atomic replace");