On Tue, Feb 17, 2026 at 11:06:40AM -0500, Joe Lawrence wrote:
> The klp-build script overrides the kernel's setlocalversion script to
> freeze the version string. This prevents the build system from appending
> "+" or "-dirty" suffixes between original and patched kernel builds.
>
> However, a version mismatch may still occur when running successive
> klp-build commands using the short-circuit option (-S 2):
>
> - Initial Run (-T): The real setlocalversion runs once. It is then
> replaced by a fixed-string copy. On exit, the original script is
> restored.
> - Subsequent Runs (-S 2): The tree contains the original setlocalversion
> script again. When set_kernelversion() is called, it may generate a
> different version string because the tree state has changed (e.g.,
> include/config/auto.conf now exists). This causes patched kernel
> builds to use a version string that differs from the original.
>
> Fix this by restoring the saved override when SHORT_CIRCUIT >= 2. This
> ensures that subsequent patched builds reuse the localversion from the
> initial klp-build run.
>
> Signed-off-by: Joe Lawrence <[email protected]>
> ---
> scripts/livepatch/klp-build | 9 +++++++++
> 1 file changed, 9 insertions(+)
>
> diff --git a/scripts/livepatch/klp-build b/scripts/livepatch/klp-build
> index 60c7635e65c1..6d3adadfc394 100755
> --- a/scripts/livepatch/klp-build
> +++ b/scripts/livepatch/klp-build
> @@ -291,17 +291,26 @@ set_module_name() {
>
> # Hardcode the value printed by the localversion script to prevent patch
> # application from appending it with '+' due to a dirty working tree.
> +# When short-circuiting at step 2 or later, restore the saved override from
> +# a prior run instead of recomputing (avoids version mismatch with orig
> objects).
> set_kernelversion() {
> local file="$SRC/scripts/setlocalversion"
> local localversion
>
> stash_file "$file"
> + if (( SHORT_CIRCUIT >= 2 )); then
> + [[ ! -f "$TMP_DIR/setlocalversion.override" ]] && \
> + die "previous setlocalversion.override not found"
> + cp -f "$TMP_DIR/setlocalversion.override"
> "$SRC/scripts/setlocalversion"
> + return 0
> + fi
>
> localversion="$(cd "$SRC" && make --no-print-directory kernelversion)"
> localversion="$(cd "$SRC" && KERNELVERSION="$localversion"
> ./scripts/setlocalversion)"
> [[ -z "$localversion" ]] && die "setlocalversion failed"
>
> sed -i "2i echo $localversion; exit 0" scripts/setlocalversion
> + cp -f "$SRC/scripts/setlocalversion" "$TMP_DIR/setlocalversion.override"
> }
>
> get_patch_input_files() {
> --
> 2.53.0
>
>
Maybe I'm starting to see things, but when running 'S 2' builds, I keep
getting "vmlinux.o: changed function: override_release". It could be
considered benign for quick development work, or confusing. Seems easy
enough to stash and avoid.
Repro:
Start with a clean source tree, setup some basic configs for klp-build:
$ make clean && make mrproper
$ vng --kconfig
$ ./scripts/config --file .config \
--set-val CONFIG_FTRACE y \
--set-val CONFIG_KALLSYMS_ALL y \
--set-val CONFIG_FUNCTION_TRACER y \
--set-val CONFIG_DYNAMIC_FTRACE y \
--set-val CONFIG_DYNAMIC_DEBUG y \
--set-val CONFIG_LIVEPATCH y
$ make olddefconfig
Build the first patch, save klp-tmp/ (note the added DEBUG that dumps
the localversion after assignment in set_kernelversion):
$ ./scripts/livepatch/klp-build -T ~/cmdline-string.patch
DEBUG: localversion=6.19.0-gc998cd490c02 <<
Validating patch(es)
Building original kernel
Copying original object files
Fixing patch(es)
Building patched kernel
Copying patched object files
Diffing objects
vmlinux.o: changed function: cmdline_proc_show
BMuilding patch module: livepatch-cmdline-string.ko
SgUCCESS
c
Buield a second patch, short-circuit to step 2 (build patched kernel):
$ ./scripts/livepatch/klp-build -T -S 2 ~/cmdline-string.patch
DEBUG: localversion=6.19.0+ <<
Fixing patch(es)
Building patched kernel
Copying patched object files
Diffing objects
vmlinux.o: changed function: override_release <<
vmlinux.o: changed function: cmdline_proc_show
Building patch module: livepatch-cmdline-string.ko
SUCCESS
--
Joe