[kpatch] [PATCH] livepatch-patch-hook: make callbacks addition depend on the kernel version

Mike Rapoport rppt at linux.vnet.ibm.com
Thu Apr 12 16:19:47 UTC 2018


Since commit 926e4e0c7d14b43896f9814da236b4d6408c8ff0 ("kmod: add support
for in-kernel livepatch hooks") livepatch-patch-hook.c unconditionally
creates callbacks. This causes build error for kernels older than 4.15:

make -C /home/rppt/git/linux M=/home/rppt/.kpatch/tmp/patch livepatch-proc-vmalloc-live.ko
make[1]: Entering directory '/home/rppt/git/linux'
  CC [M]  /home/rppt/.kpatch/tmp/patch/patch-hook.o
In file included from /home/rppt/.kpatch/tmp/patch/patch-hook.c:21:0:
/home/rppt/.kpatch/tmp/patch/livepatch-patch-hook.c:82:23: error: field ‘callbacks’ has incomplete type
  struct klp_callbacks callbacks;
                       ^
/home/rppt/.kpatch/tmp/patch/livepatch-patch-hook.c: In function ‘patch_init’:
/home/rppt/.kpatch/tmp/patch/livepatch-patch-hook.c:395:10: error: ‘struct klp_object’ has no member named ‘callbacks’
   lobject->callbacks = object->callbacks;
          ^
scripts/Makefile.build:302: recipe for target '/home/rppt/.kpatch/tmp/patch/patch-hook.o' failed
make[2]: *** [/home/rppt/.kpatch/tmp/patch/patch-hook.o] Error 1
Makefile:1687: recipe for target 'livepatch-proc-vmalloc-live.ko' failed
make[1]: *** [livepatch-proc-vmalloc-live.ko] Error 2
make[1]: Leaving directory '/home/rppt/git/linux'
Makefile:20: recipe for target 'livepatch-proc-vmalloc-live.ko' failed
make: *** [livepatch-proc-vmalloc-live.ko] Error 2

Introduce HAVE_LIVEPATCH_CALLBACKS to allow conditional compilation of the
callbacks addition.

Signed-off-by: Mike Rapoport <rppt at linux.vnet.ibm.com>
---
 kmod/patch/livepatch-patch-hook.c | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)

diff --git a/kmod/patch/livepatch-patch-hook.c b/kmod/patch/livepatch-patch-hook.c
index f9e9f06..ecd00b2 100644
--- a/kmod/patch/livepatch-patch-hook.c
+++ b/kmod/patch/livepatch-patch-hook.c
@@ -53,6 +53,14 @@
 #define HAVE_IMMEDIATE
 #endif
 
+#ifdef RHEL_RELEASE_CODE
+# if RHEL_RELEASE_CODE >= RHEL_RELEASE_VERSION(7, 5)
+#  define HAVE_LIVEPATCH_CALLBACKS
+# endif
+#elif LINUX_VERSION_CODE >= KERNEL_VERSION(4, 15, 0)
+# define HAVE_LIVEPATCH_CALLBACKS
+#endif
+
 /*
  * There are quite a few similar structures at play in this file:
  * - livepatch.h structs prefixed with klp_*
@@ -79,7 +87,9 @@ struct patch_object {
 	struct list_head list;
 	struct list_head funcs;
 	struct list_head relocs;
+#ifdef HAS_LIVEPATCH_CALLBACKS
 	struct klp_callbacks callbacks;
+#endif
 	const char *name;
 	int funcs_nr, relocs_nr;
 };
@@ -211,6 +221,7 @@ static void patch_free_livepatch(struct klp_patch *patch)
 	}
 }
 
+#ifdef HAS_LIVEPATCH_CALLBACKS
 extern struct kpatch_pre_patch_callback __kpatch_callbacks_pre_patch[], __kpatch_callbacks_pre_patch_end[];
 extern struct kpatch_post_patch_callback __kpatch_callbacks_post_patch[], __kpatch_callbacks_post_patch_end[];
 extern struct kpatch_pre_unpatch_callback __kpatch_callbacks_pre_unpatch[], __kpatch_callbacks_pre_unpatch_end[];
@@ -286,6 +297,9 @@ static int add_callbacks_to_patch_objects(void)
 
 	return 0;
 }
+#else /* HAS_LIVEPATCH_CALLBACKS */
+static inline int add_callbacks_to_patch_objects(void) { return 0; }
+#endif /* HAS_LIVEPATCH_CALLBACKS */
 
 extern struct kpatch_patch_func __kpatch_funcs[], __kpatch_funcs_end[];
 #ifndef HAVE_ELF_RELOCS
@@ -392,7 +406,9 @@ static int __init patch_init(void)
 		}
 #endif /* HAVE_ELF_RELOCS */
 
+#ifdef HAVE_LIVEPATCH_CALLBACKS
 		lobject->callbacks = object->callbacks;
+#endif
 
 		i++;
 	}
-- 
2.7.4




More information about the kpatch mailing list