Loading samples/Kconfig +1 −1 Original line number Diff line number Diff line Loading @@ -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. Loading samples/livepatch/Makefile +2 −0 Original line number Diff line number Diff line # 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 samples/livepatch/livepatch-sample.c +36 −0 Original line number Diff line number Diff line Loading @@ -30,6 +30,31 @@ */ #include <linux/seq_file.h> #ifdef CONFIG_LIVEPATCH_WO_FTRACE void load_hook(void) { pr_info("loading\n"); } void unload_hook(void) { pr_info("unloading\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"); Loading @@ -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 }, { } }; Loading @@ -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); Loading Loading
samples/Kconfig +1 −1 Original line number Diff line number Diff line Loading @@ -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. Loading
samples/livepatch/Makefile +2 −0 Original line number Diff line number Diff line # 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
samples/livepatch/livepatch-sample.c +36 −0 Original line number Diff line number Diff line Loading @@ -30,6 +30,31 @@ */ #include <linux/seq_file.h> #ifdef CONFIG_LIVEPATCH_WO_FTRACE void load_hook(void) { pr_info("loading\n"); } void unload_hook(void) { pr_info("unloading\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"); Loading @@ -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 }, { } }; Loading @@ -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); Loading