Skip to content

Commit 3f5bf12

Browse files
committed
Read backported klp capabilities from <linux/livepatch.h>
Normally kpatch-build infers a kernel's klp API's properties from KERNEL_VERSION, for patch-generation strategy decisions like support_klp_replace() and use_klp_arch(), and possibly other future developments. There's already one exception to this, for RHEL kernels, and as the support for more distros clutters kpatch-build, some of them may also diverge from the version-indicated semantics and need special handling. Site-specific builds (aka frankenkernels) may also require such adaption, which can complicate maintenance, or force per-version forks of kpatch. To avoid this, read optional override hints about backported klp capabilities from <linux/livepatch.h>, when a simple version check would give the wrong answer. Such annotations would never be needed for kernels which inherit their klp implementation from upstream, just for custom codebases which extend it, by backport or otherwise. For example, some of google's kernels report 4.15 but have 5.8ish klp semantics. This allows kpatch to avoid forking for such cases, and the target kernel is always the source of truth. But rather than just inferring from its KERNEL_VERSION, hints from its <linux/livepatch.h>, used by nothing but kpatch, steer its logic. I'm not suggesting RHEL-specific logic be dropped, merely avoiding further unnecessary coupling between two changesets (kernel & kpatch) when such API evolution happens in the future. The proliferation of distro-specific build-from-source cases is less avoidable, but is more localized, so less problematic. Signed-off-by: Pete Swain <swine@google.com>
1 parent f73277f commit 3f5bf12

File tree

2 files changed

+6
-0
lines changed

2 files changed

+6
-0
lines changed

kpatch-build/kpatch-build

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,8 @@ use_klp_arch()
224224
{
225225
if kernel_is_rhel; then
226226
! rhel_kernel_version_gte 4.18.0-284.el8
227+
elif grep -Esq '^#define\s*NO_KLP_ARCH' include/linux/livepatch.h; then
228+
false # kernel needs no .klp.arch sections
227229
else
228230
! kernel_version_gte 5.8.0
229231
fi
@@ -233,6 +235,8 @@ support_klp_replace()
233235
{
234236
if kernel_is_rhel; then
235237
rhel_kernel_version_gte 4.18.0-193.el8
238+
elif grep -Esq '^#define\s*HAVE_KLP_REPLACE' include/linux/livepatch.h; then
239+
true # kernel explicitly indicates support
236240
else
237241
kernel_version_gte 5.1.0
238242
fi

test/integration/kpatch-test

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,8 @@ support_klp_replace()
317317
{
318318
if kernel_is_rhel; then
319319
rhel_kernel_version_gte 4.18.0-193.el8
320+
elif grep -Esq '^#define\s*HAVE_KLP_REPLACE' include/linux/livepatch.h; then
321+
true # kernel explicitly indicates support
320322
else
321323
kernel_version_gte 5.1.0
322324
fi

0 commit comments

Comments
 (0)