hulk inclusion category: feature bugzilla: https://gitee.com/openeuler/kernel/issues/I7W46D
--------------------------------
Signed-off-by: Zheng Yejian zhengyejian1@huawei.com --- samples/Kconfig | 2 +- samples/livepatch/Makefile | 2 ++ samples/livepatch/livepatch-sample.c | 36 ++++++++++++++++++++++++++++ 3 files changed, 39 insertions(+), 1 deletion(-)
diff --git a/samples/Kconfig b/samples/Kconfig index 10d2fe4d8f83..b2db430bd3ff 100644 --- a/samples/Kconfig +++ b/samples/Kconfig @@ -130,7 +130,7 @@ config SAMPLE_RPMSG_CLIENT
config SAMPLE_LIVEPATCH tristate "Build live patching samples -- loadable modules only" - depends on LIVEPATCH_FTRACE && m + depends on LIVEPATCH && m help Build sample live patch demonstrations.
diff --git a/samples/livepatch/Makefile b/samples/livepatch/Makefile index 9f853eeb6140..1e384d50c73f 100644 --- a/samples/livepatch/Makefile +++ b/samples/livepatch/Makefile @@ -1,8 +1,10 @@ # SPDX-License-Identifier: GPL-2.0-only obj-$(CONFIG_SAMPLE_LIVEPATCH) += livepatch-sample.o +ifeq ($(CONFIG_LIVEPATCH_FTRACE), y) obj-$(CONFIG_SAMPLE_LIVEPATCH) += livepatch-shadow-mod.o obj-$(CONFIG_SAMPLE_LIVEPATCH) += livepatch-shadow-fix1.o obj-$(CONFIG_SAMPLE_LIVEPATCH) += livepatch-shadow-fix2.o obj-$(CONFIG_SAMPLE_LIVEPATCH) += livepatch-callbacks-demo.o obj-$(CONFIG_SAMPLE_LIVEPATCH) += livepatch-callbacks-mod.o obj-$(CONFIG_SAMPLE_LIVEPATCH) += livepatch-callbacks-busymod.o +endif diff --git a/samples/livepatch/livepatch-sample.c b/samples/livepatch/livepatch-sample.c index cd76d7ebe598..6649e7fb9149 100644 --- a/samples/livepatch/livepatch-sample.c +++ b/samples/livepatch/livepatch-sample.c @@ -30,6 +30,31 @@ */
#include <linux/seq_file.h> + +#ifdef CONFIG_LIVEPATCH_WO_FTRACE +void load_hook(void) +{ + pr_info("load_hook\n"); +} + +void unload_hook(void) +{ + pr_info("unload_hook\n"); +} + +static struct klp_hook hooks_load[] = { + { + .hook = load_hook + }, { } +}; + +static struct klp_hook hooks_unload[] = { + { + .hook = unload_hook + }, { } +}; +#endif /* CONFIG_LIVEPATCH_WO_FTRACE */ + static int livepatch_cmdline_proc_show(struct seq_file *m, void *v) { seq_printf(m, "%s\n", "this has been live patched"); @@ -47,6 +72,10 @@ static struct klp_object objs[] = { { /* name being NULL means vmlinux */ .funcs = funcs, +#ifdef CONFIG_LIVEPATCH_WO_FTRACE + .hooks_load = hooks_load, + .hooks_unload = hooks_unload, +#endif }, { } };
@@ -57,11 +86,18 @@ static struct klp_patch patch = {
static int livepatch_init(void) { +#ifdef CONFIG_LIVEPATCH_WO_FTRACE + return klp_register_patch(&patch); +#else return klp_enable_patch(&patch); +#endif }
static void livepatch_exit(void) { +#ifdef CONFIG_LIVEPATCH_WO_FTRACE + WARN_ON(klp_unregister_patch(&patch)); +#endif }
module_init(livepatch_init);