From 3f5bf1224dd12430510150460e7f462c426ec84f Mon Sep 17 00:00:00 2001 From: Pete Swain Date: Sat, 3 Sep 2022 12:32:35 -0700 Subject: [PATCH] Read backported klp capabilities from 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 , 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 , 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 --- kpatch-build/kpatch-build | 4 ++++ test/integration/kpatch-test | 2 ++ 2 files changed, 6 insertions(+) diff --git a/kpatch-build/kpatch-build b/kpatch-build/kpatch-build index a49831369..c723625f1 100755 --- a/kpatch-build/kpatch-build +++ b/kpatch-build/kpatch-build @@ -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 @@ -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 diff --git a/test/integration/kpatch-test b/test/integration/kpatch-test index 688ab1dea..bfa1b3d23 100755 --- a/test/integration/kpatch-test +++ b/test/integration/kpatch-test @@ -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