dynup / kpatch

kpatch - live kernel patching
GNU General Public License v2.0
1.49k stars 304 forks source link

nowhere to find the definition of klp_register_patch #1377

Closed wardenjohn closed 8 months ago

wardenjohn commented 8 months ago

I can't find the definition of klp_register_patch function, neither in linux-net/kernel/livepatch nor kpatch-build. Is there any one can tell me how to invoke klp_register_patch in kpatch/kmod/patch/livepatch-patch-hook.c line 571 to line 577. I can't find where this function defined, and cannot figure out what is this function used for.

joe-lawrence commented 8 months ago

@wardenjohn : take a look at the HAVE_SIMPLE_ENABLE macro, lines 67-75:

#ifdef RHEL_RELEASE_CODE
# if (RHEL_RELEASE_CODE >= RHEL_RELEASE_VERSION(7, 8) &&                \
         RHEL_RELEASE_CODE < RHEL_RELEASE_VERSION(8, 0)) ||             \
      RHEL_RELEASE_CODE >= RHEL_RELEASE_VERSION(8, 2)
#  define HAVE_SIMPLE_ENABLE
# endif
#elif LINUX_VERSION_CODE >= KERNEL_VERSION(5, 1, 0)
# define HAVE_SIMPLE_ENABLE
#endif

Which means:

as not having the "simple livepatch registration API", and requiring an additional calls for klp_register_patch() and its counterpart klp_unregister_patch().

joe-lawrence commented 8 months ago

The livepatch registration calls were removed by this patchset: https://lore.kernel.org/all/20190109124329.21991-1-pmladek@suse.com/

wardenjohn commented 8 months ago

The livepatch registration calls were removed by this patchset: https://lore.kernel.org/all/20190109124329.21991-1-pmladek@suse.com/

My kernel is updated to upstream master branch but found no definition of klp_register_patch() and its counterpart. With this patch, can I comprehend this patch removed the function of klp_register_patch leading to no definition of this function? Because I grep -rn under linux kernel but found nothing. Is HAVE_SIMPLE_ENABLE macros still enabled in latest version of kpatch or livepatch?

joe-lawrence commented 8 months ago

Is there a particular reason why you need to directly invoke klp_register_patch()?

If you are running on a downstream distribution that already has 958ef1e39d24 (most likely), there is a chance that it needs to be added to those macros. Let us know if that is the case.

wardenjohn commented 8 months ago

Actually, although I work on a downstream distribution which is based on 4.19, there is still no strong reason for me to use klp_register_patch for now. I am very interesting in kpatch and livepatch, wanting to figure out how it works. When I try to figure out the working principle of what the system do when insmod a livepatch ko. I found klp_register_patch under macro HAVE_SIMPLE_ENABLE on, but found no definition in kpatch project neigther in linux kernel. That's why I come for help here! Thank you Joe! :)