Skip to content

Commit

Permalink
Read backported klp capabilities from <linux/livepatch.h>
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
swine committed Oct 12, 2022
1 parent f73277f commit 3f5bf12
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
4 changes: 4 additions & 0 deletions kpatch-build/kpatch-build
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,8 @@ use_klp_arch()
{
if kernel_is_rhel; then
! rhel_kernel_version_gte 4.18.0-284.el8
elif grep -Esq '^#define\s*NO_KLP_ARCH' include/linux/livepatch.h; then
false # kernel needs no .klp.arch sections
else
! kernel_version_gte 5.8.0
fi
Expand All @@ -233,6 +235,8 @@ support_klp_replace()
{
if kernel_is_rhel; then
rhel_kernel_version_gte 4.18.0-193.el8
elif grep -Esq '^#define\s*HAVE_KLP_REPLACE' include/linux/livepatch.h; then
true # kernel explicitly indicates support
else
kernel_version_gte 5.1.0
fi
Expand Down
2 changes: 2 additions & 0 deletions test/integration/kpatch-test
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,8 @@ support_klp_replace()
{
if kernel_is_rhel; then
rhel_kernel_version_gte 4.18.0-193.el8
elif grep -Esq '^#define\s*HAVE_KLP_REPLACE' include/linux/livepatch.h; then
true # kernel explicitly indicates support
else
kernel_version_gte 5.1.0
fi
Expand Down

0 comments on commit 3f5bf12

Please sign in to comment.