[PATCH] livepatch/klp-build: Fix klp-build vs CONFIG_MODULE_SRCVERSION_ALL

Josh Poimboeuf posted 1 patch 1 week, 4 days ago
There is a newer version of this series
scripts/livepatch/klp-build | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
[PATCH] livepatch/klp-build: Fix klp-build vs CONFIG_MODULE_SRCVERSION_ALL
Posted by Josh Poimboeuf 1 week, 4 days ago
When building a patch to a single-file kernel module with
CONFIG_MODULE_SRCVERSION_ALL enabled, the klp-build module link fails in
modpost:

  Diffing objects
  drivers/md/raid0.o: changed function: raid0_run
  Building patch module: livepatch-0001-patch-raid0_run.ko
  drivers/md/raid0.c: No such file or directory
  ...

The problem here is that klp-build copied drivers/md/.raid0.o.cmd to the
module build directory, but it didn't also copy over the input source
file listed in the .cmd file:

  source_drivers/md/raid0.o := drivers/md/raid0.c

So modpost dies due to the missing .c file which is needed for
calculating checksums for CONFIG_MODULE_SRCVERSION_ALL.

Instead of copying the original .cmd file, just create an empty one.
Modpost only requires that it exists.  The original object's build
dependencies are irrelevant for the frankenobjects used by klp-build.

Fixes: 24ebfcd65a87 ("livepatch/klp-build: Introduce klp-build script for generating livepatch modules")
Reported-by: Song Liu <song@kernel.org>
Signed-off-by: Josh Poimboeuf <jpoimboe@kernel.org>
---
 scripts/livepatch/klp-build | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/scripts/livepatch/klp-build b/scripts/livepatch/klp-build
index 882272120c9e..a73515a82272 100755
--- a/scripts/livepatch/klp-build
+++ b/scripts/livepatch/klp-build
@@ -555,13 +555,11 @@ copy_orig_objects() {
 		local file_dir="$(dirname "$file")"
 		local orig_file="$ORIG_DIR/$rel_file"
 		local orig_dir="$(dirname "$orig_file")"
-		local cmd_file="$file_dir/.$(basename "$file").cmd"
 
 		[[ ! -f "$file" ]] && die "missing $(basename "$file") for $_file"
 
 		mkdir -p "$orig_dir"
 		cp -f "$file" "$orig_dir"
-		[[ -e "$cmd_file" ]] && cp -f "$cmd_file" "$orig_dir"
 	done
 	xtrace_restore
 
@@ -740,15 +738,17 @@ build_patch_module() {
 		local orig_dir="$(dirname "$orig_file")"
 		local kmod_file="$KMOD_DIR/$rel_file"
 		local kmod_dir="$(dirname "$kmod_file")"
-		local cmd_file="$orig_dir/.$(basename "$file").cmd"
+		local cmd_file="$kmod_dir/.$(basename "$file").cmd"
 
 		mkdir -p "$kmod_dir"
 		cp -f "$file" "$kmod_dir"
-		[[ -e "$cmd_file" ]] && cp -f "$cmd_file" "$kmod_dir"
 
 		# Tell kbuild this is a prebuilt object
 		cp -f "$file" "${kmod_file}_shipped"
 
+		# Make modpost happy
+		touch "$cmd_file"
+
 		echo -n " $rel_file" >> "$makefile"
 	done
 
-- 
2.52.0
Re: [PATCH] livepatch/klp-build: Fix klp-build vs CONFIG_MODULE_SRCVERSION_ALL
Posted by Song Liu 1 week, 4 days ago
On Mon, Jan 26, 2026 at 3:56 PM Josh Poimboeuf <jpoimboe@kernel.org> wrote:
>
> When building a patch to a single-file kernel module with
> CONFIG_MODULE_SRCVERSION_ALL enabled, the klp-build module link fails in
> modpost:
>
>   Diffing objects
>   drivers/md/raid0.o: changed function: raid0_run
>   Building patch module: livepatch-0001-patch-raid0_run.ko
>   drivers/md/raid0.c: No such file or directory
>   ...
>
> The problem here is that klp-build copied drivers/md/.raid0.o.cmd to the
> module build directory, but it didn't also copy over the input source
> file listed in the .cmd file:
>
>   source_drivers/md/raid0.o := drivers/md/raid0.c
>
> So modpost dies due to the missing .c file which is needed for
> calculating checksums for CONFIG_MODULE_SRCVERSION_ALL.
>
> Instead of copying the original .cmd file, just create an empty one.
> Modpost only requires that it exists.  The original object's build
> dependencies are irrelevant for the frankenobjects used by klp-build.
>
> Fixes: 24ebfcd65a87 ("livepatch/klp-build: Introduce klp-build script for generating livepatch modules")
> Reported-by: Song Liu <song@kernel.org>
> Signed-off-by: Josh Poimboeuf <jpoimboe@kernel.org>

Tested-by: Song Liu <song@kernel.org>

Thanks for the fix!