livepatch-patch-hook: make callbacks addition depend on the kernel version

Since commit 926e4e0c7d ("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_CALLBACKS to allow conditional compilation of the callbacks
addition.

Signed-off-by: Mike Rapoport <rppt@linux.vnet.ibm.com>
This commit is contained in:
Mike Rapoport 2018-04-12 18:03:03 +03:00
parent 9b5ade5c12
commit dd1bfbecd5

View File

@ -53,6 +53,14 @@
#define HAVE_IMMEDIATE
#endif
#ifdef RHEL_RELEASE_CODE
# if RHEL_RELEASE_CODE >= RHEL_RELEASE_VERSION(7, 5)
# define HAVE_CALLBACKS
# endif
#elif LINUX_VERSION_CODE >= KERNEL_VERSION(4, 15, 0)
# define HAVE_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 HAVE_CALLBACKS
struct klp_callbacks callbacks;
#endif
const char *name;
int funcs_nr, relocs_nr;
};
@ -216,6 +226,7 @@ extern struct kpatch_post_patch_callback __kpatch_callbacks_post_patch[], __kpat
extern struct kpatch_pre_unpatch_callback __kpatch_callbacks_pre_unpatch[], __kpatch_callbacks_pre_unpatch_end[];
extern struct kpatch_post_unpatch_callback __kpatch_callbacks_post_unpatch[], __kpatch_callbacks_post_unpatch_end[];
#ifdef HAVE_CALLBACKS
static int add_callbacks_to_patch_objects(void)
{
struct kpatch_pre_patch_callback *p_pre_patch_callback;
@ -286,6 +297,24 @@ static int add_callbacks_to_patch_objects(void)
return 0;
}
#else /* HAVE_CALLBACKS */
static inline int add_callbacks_to_patch_objects(void)
{
if (__kpatch_callbacks_pre_patch !=
__kpatch_callbacks_pre_patch_end ||
__kpatch_callbacks_post_patch !=
__kpatch_callbacks_post_patch_end ||
__kpatch_callbacks_pre_unpatch !=
__kpatch_callbacks_pre_unpatch_end ||
__kpatch_callbacks_post_unpatch !=
__kpatch_callbacks_post_unpatch_end) {
pr_err("patch callbacks are not supported\n");
return -EINVAL;
}
return 0;
}
#endif /* HAVE_CALLBACKS */
extern struct kpatch_patch_func __kpatch_funcs[], __kpatch_funcs_end[];
#ifndef HAVE_ELF_RELOCS
@ -392,7 +421,9 @@ static int __init patch_init(void)
}
#endif /* HAVE_ELF_RELOCS */
#ifdef HAVE_CALLBACKS
lobject->callbacks = object->callbacks;
#endif
i++;
}