1*4882a593Smuzhiyun // SPDX-License-Identifier: GPL-2.0
2*4882a593Smuzhiyun // Copyright (C) 2018 Joe Lawrence <joe.lawrence@redhat.com>
3*4882a593Smuzhiyun
4*4882a593Smuzhiyun #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
5*4882a593Smuzhiyun
6*4882a593Smuzhiyun #include <linux/module.h>
7*4882a593Smuzhiyun #include <linux/kernel.h>
8*4882a593Smuzhiyun #include <linux/livepatch.h>
9*4882a593Smuzhiyun
10*4882a593Smuzhiyun static int replace;
11*4882a593Smuzhiyun module_param(replace, int, 0644);
12*4882a593Smuzhiyun MODULE_PARM_DESC(replace, "replace (default=0)");
13*4882a593Smuzhiyun
14*4882a593Smuzhiyun #include <linux/seq_file.h>
livepatch_meminfo_proc_show(struct seq_file * m,void * v)15*4882a593Smuzhiyun static int livepatch_meminfo_proc_show(struct seq_file *m, void *v)
16*4882a593Smuzhiyun {
17*4882a593Smuzhiyun seq_printf(m, "%s: %s\n", THIS_MODULE->name,
18*4882a593Smuzhiyun "this has been live patched");
19*4882a593Smuzhiyun return 0;
20*4882a593Smuzhiyun }
21*4882a593Smuzhiyun
22*4882a593Smuzhiyun static struct klp_func funcs[] = {
23*4882a593Smuzhiyun {
24*4882a593Smuzhiyun .old_name = "meminfo_proc_show",
25*4882a593Smuzhiyun .new_func = livepatch_meminfo_proc_show,
26*4882a593Smuzhiyun }, {}
27*4882a593Smuzhiyun };
28*4882a593Smuzhiyun
29*4882a593Smuzhiyun static struct klp_object objs[] = {
30*4882a593Smuzhiyun {
31*4882a593Smuzhiyun /* name being NULL means vmlinux */
32*4882a593Smuzhiyun .funcs = funcs,
33*4882a593Smuzhiyun }, {}
34*4882a593Smuzhiyun };
35*4882a593Smuzhiyun
36*4882a593Smuzhiyun static struct klp_patch patch = {
37*4882a593Smuzhiyun .mod = THIS_MODULE,
38*4882a593Smuzhiyun .objs = objs,
39*4882a593Smuzhiyun /* set .replace in the init function below for demo purposes */
40*4882a593Smuzhiyun };
41*4882a593Smuzhiyun
test_klp_atomic_replace_init(void)42*4882a593Smuzhiyun static int test_klp_atomic_replace_init(void)
43*4882a593Smuzhiyun {
44*4882a593Smuzhiyun patch.replace = replace;
45*4882a593Smuzhiyun return klp_enable_patch(&patch);
46*4882a593Smuzhiyun }
47*4882a593Smuzhiyun
test_klp_atomic_replace_exit(void)48*4882a593Smuzhiyun static void test_klp_atomic_replace_exit(void)
49*4882a593Smuzhiyun {
50*4882a593Smuzhiyun }
51*4882a593Smuzhiyun
52*4882a593Smuzhiyun module_init(test_klp_atomic_replace_init);
53*4882a593Smuzhiyun module_exit(test_klp_atomic_replace_exit);
54*4882a593Smuzhiyun MODULE_LICENSE("GPL");
55*4882a593Smuzhiyun MODULE_INFO(livepatch, "Y");
56*4882a593Smuzhiyun MODULE_AUTHOR("Joe Lawrence <joe.lawrence@redhat.com>");
57*4882a593Smuzhiyun MODULE_DESCRIPTION("Livepatch test: atomic replace");
58