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");
58