|
|
ec3a16 |
From f38c64b7e490c6de1208f277d767bd7b8029edcc Mon Sep 17 00:00:00 2001
|
|
|
ec3a16 |
From: Josh Poimboeuf <jpoimboe@redhat.com>
|
|
|
ec3a16 |
Date: Mon, 13 Mar 2023 13:51:01 -0700
|
|
|
f6c393 |
Subject: [PATCH 108/112] kpatch-build: Fix setlocalversion issue with 6.3
|
|
|
f6c393 |
kernel
|
|
|
ec3a16 |
|
|
|
ec3a16 |
The kernel has a VERMAGIC_STRING, e.g. "6.2.0". The module loader uses
|
|
|
ec3a16 |
that string to ensure that all loaded modules' version strings match the
|
|
|
ec3a16 |
kernel's.
|
|
|
ec3a16 |
|
|
|
ec3a16 |
If the kernel source is in a git tree, and if there are uncommitted
|
|
|
ec3a16 |
changes, the version string will have a '+' or "-dirty" appended to it,
|
|
|
ec3a16 |
like "6.1.0+" or "6.2.0-dirty". This dirty tree detection is done by
|
|
|
ec3a16 |
the setlocalversion script.
|
|
|
ec3a16 |
|
|
|
ec3a16 |
This affects kpatch-build in a few ways. When it builds the original
|
|
|
ec3a16 |
kernel, in some cases there are uncommitted changes to the makefiles.
|
|
|
ec3a16 |
When it builds the patched kernel, there are additional uncommitted
|
|
|
ec3a16 |
changes due to the .patch file being applied.
|
|
|
ec3a16 |
|
|
|
ec3a16 |
We want to avoid the VERMAGIC_STRING changing between builds. Otherwise
|
|
|
ec3a16 |
it would cause problems:
|
|
|
ec3a16 |
|
|
|
ec3a16 |
- object code which uses that string would change unnecessarily,
|
|
|
ec3a16 |
causing a false positive change detected by create-diff-object
|
|
|
ec3a16 |
|
|
|
ec3a16 |
- the linked patch module would report the wrong version, resulting in
|
|
|
ec3a16 |
the module failing to load due to version mismatch.
|
|
|
ec3a16 |
|
|
|
ec3a16 |
Up until now, the version was prevented from changing by running
|
|
|
ec3a16 |
`setlocalversion --save-scmversion` before the build. That command
|
|
|
ec3a16 |
hard-codes the version by saving it to a file which is then
|
|
|
ec3a16 |
automatically read later during future invocations of the kernel build.
|
|
|
ec3a16 |
|
|
|
ec3a16 |
Unfortunately that feature was removed in the 6.3 merge window with
|
|
|
ec3a16 |
commit f6e09b07cc12 ("kbuild: do not put .scmversion into the source
|
|
|
ec3a16 |
tarball"). So we need to come up with a new approach.
|
|
|
ec3a16 |
|
|
|
ec3a16 |
Fix it by temporarily replacing the setlocalversion script with a
|
|
|
ec3a16 |
one-liner which just echo's the original version. I think this is
|
|
|
ec3a16 |
unfortunately the best we can do, as we really can't handle
|
|
|
ec3a16 |
VERMAGIC_STRING changing, either during/between kernel builds or during
|
|
|
ec3a16 |
the module link.
|
|
|
ec3a16 |
|
|
|
ec3a16 |
Fixes #1335.
|
|
|
ec3a16 |
|
|
|
ec3a16 |
Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
|
|
|
ec3a16 |
(cherry picked from commit 629b5acf3dab0311e1bebbffec4908999273d58d)
|
|
|
ec3a16 |
---
|
|
|
ec3a16 |
kpatch-build/kpatch-build | 25 +++++++++++++++++++++----
|
|
|
ec3a16 |
1 file changed, 21 insertions(+), 4 deletions(-)
|
|
|
ec3a16 |
|
|
|
ec3a16 |
diff --git a/kpatch-build/kpatch-build b/kpatch-build/kpatch-build
|
|
|
ec3a16 |
index 938e88f..429f214 100755
|
|
|
ec3a16 |
--- a/kpatch-build/kpatch-build
|
|
|
ec3a16 |
+++ b/kpatch-build/kpatch-build
|
|
|
ec3a16 |
@@ -166,11 +166,9 @@ remove_patches() {
|
|
|
ec3a16 |
}
|
|
|
ec3a16 |
|
|
|
ec3a16 |
cleanup() {
|
|
|
ec3a16 |
- rm -f "$BUILDDIR/.scmversion"
|
|
|
ec3a16 |
-
|
|
|
ec3a16 |
remove_patches
|
|
|
ec3a16 |
|
|
|
ec3a16 |
- # restore original vmlinux if it was overwritten by sourcedir build
|
|
|
ec3a16 |
+ # restore any files that were modified for the build
|
|
|
ec3a16 |
[[ -e "$TEMPDIR/vmlinux" ]] && mv -f "$TEMPDIR/vmlinux" "$KERNEL_SRCDIR/"
|
|
|
ec3a16 |
|
|
|
ec3a16 |
# restore any files that were modified for the build
|
|
|
ec3a16 |
@@ -178,6 +176,7 @@ cleanup() {
|
|
|
ec3a16 |
[[ -e "$TEMPDIR/Makefile.modfinal" ]] && mv -f "$TEMPDIR/Makefile.modfinal" "$KERNEL_SRCDIR/scripts"
|
|
|
ec3a16 |
[[ -e "$TEMPDIR/Makefile.build" ]] && mv -f "$TEMPDIR/Makefile.build" "$KERNEL_SRCDIR/scripts"
|
|
|
ec3a16 |
[[ -e "$TEMPDIR/Makefile" ]] && mv -f "$TEMPDIR/Makefile" "$KERNEL_SRCDIR"
|
|
|
ec3a16 |
+ [[ -e "$TEMPDIR/setlocalversion" ]] && mv -f "$TEMPDIR/setlocalversion" "$KERNEL_SRCDIR/scripts"
|
|
|
ec3a16 |
|
|
|
ec3a16 |
[[ "$DEBUG" -eq 0 ]] && rm -rf "$TEMPDIR"
|
|
|
ec3a16 |
rm -rf "$RPMTOPDIR"
|
|
|
ec3a16 |
@@ -994,6 +993,25 @@ if [[ -z "$OOT_MODULE" && ! "$CONFIGFILE" -ef "$KERNEL_SRCDIR"/.config ]] ; then
|
|
|
ec3a16 |
cp -f "$CONFIGFILE" "$KERNEL_SRCDIR/.config" || die
|
|
|
ec3a16 |
fi
|
|
|
ec3a16 |
|
|
|
ec3a16 |
+# When the kernel source is in a git repo, applying the patch (plus the
|
|
|
ec3a16 |
+# Makefile sed hacks we do) can cause it to be built with "+" or "dirty"
|
|
|
ec3a16 |
+# appended to the kernel version string (VERMAGIC_STRING), even if the original
|
|
|
ec3a16 |
+# kernel was not dirty. That can complicate both the build (create-diff-object
|
|
|
ec3a16 |
+# false positive changes) and the patch module link (module version mismatch
|
|
|
ec3a16 |
+# load failures).
|
|
|
ec3a16 |
+#
|
|
|
ec3a16 |
+# Prevent that by replacing the original setlocalversion with a friendlier one
|
|
|
ec3a16 |
+# which just echo's the original version. This should be done before any
|
|
|
ec3a16 |
+# changes to the source.
|
|
|
ec3a16 |
+if [[ -n "$USERSRCDIR" && -e "$KERNEL_SRCDIR/.git" ]]; then
|
|
|
ec3a16 |
+ cd "$KERNEL_SRCDIR" || die
|
|
|
ec3a16 |
+ cp -f scripts/setlocalversion "$TEMPDIR" || die
|
|
|
ec3a16 |
+ LOCALVERSION="$(make kernelversion)"
|
|
|
ec3a16 |
+ LOCALVERSION="$(KERNELVERSION="$LOCALVERSION" ./scripts/setlocalversion)"
|
|
|
ec3a16 |
+ [[ -n "$LOCALVERSION" ]] || die "setlocalversion failed"
|
|
|
ec3a16 |
+ echo "echo $LOCALVERSION" > scripts/setlocalversion
|
|
|
ec3a16 |
+fi
|
|
|
ec3a16 |
+
|
|
|
ec3a16 |
# kernel option checking
|
|
|
ec3a16 |
|
|
|
ec3a16 |
trace_off "reading .config"
|
|
|
ec3a16 |
@@ -1131,7 +1149,6 @@ fi
|
|
|
ec3a16 |
save_env
|
|
|
ec3a16 |
|
|
|
ec3a16 |
echo "Building original source"
|
|
|
ec3a16 |
-[[ -n "$OOT_MODULE" ]] || ./scripts/setlocalversion --save-scmversion || die
|
|
|
ec3a16 |
unset KPATCH_GCC_TEMPDIR
|
|
|
ec3a16 |
|
|
|
ec3a16 |
KPATCH_CC_PREFIX="$TOOLSDIR/kpatch-cc "
|
|
|
ec3a16 |
--
|
|
|
f6c393 |
2.45.1
|
|
|
ec3a16 |
|