From: Joe Lawrence <joe.lawrence@redhat.com>
To: live-patching@vger.kernel.org
Cc: Josh Poimboeuf <jpoimboe@kernel.org>, Song Liu <song@kernel.org>,
Jiri Kosina <jikos@kernel.org>, Miroslav Benes <mbenes@suse.cz>,
Petr Mladek <pmladek@suse.com>
Subject: [PATCH v4 03/12] livepatch/klp-build: support patches that add/remove files
Date: Tue, 10 Mar 2026 16:37:42 -0400 [thread overview]
Message-ID: <20260310203751.1479229-4-joe.lawrence@redhat.com> (raw)
In-Reply-To: <20260310203751.1479229-1-joe.lawrence@redhat.com>
The klp-build script prepares a clean patch by populating two temporary
directories ('a' and 'b') with source files and diffing the result.
However, this process fails when a patch introduces a new source file,
as the script attempts to copy files that do not yet exist in the
original source tree. Likewise, it fails when a patch removes a source
file and the script attempts to copy a file that no longer exists.
Refactor the file-gathering logic to distinguish between original input
files and patched output files:
- Split get_patch_files() into get_patch_input_files() and
get_patch_output_files() to identify which files exist before and
after patch application.
- Filter out "/dev/null" from both to handle file creation/deletion.
- Update refresh_patch() to only copy existing input files to the 'a'
directory and the resulting output files to the 'b' directory.
Acked-by: Song Liu <song@kernel.org>
Signed-off-by: Joe Lawrence <joe.lawrence@redhat.com>
---
scripts/livepatch/klp-build | 34 +++++++++++++++++++++++++++-------
1 file changed, 27 insertions(+), 7 deletions(-)
diff --git a/scripts/livepatch/klp-build b/scripts/livepatch/klp-build
index 809e198a561d..94ed3b4a91d8 100755
--- a/scripts/livepatch/klp-build
+++ b/scripts/livepatch/klp-build
@@ -296,15 +296,33 @@ set_kernelversion() {
sed -i "2i echo $localversion; exit 0" scripts/setlocalversion
}
-get_patch_files() {
+get_patch_input_files() {
+ local patch="$1"
+
+ grep0 -E '^--- ' "$patch" \
+ | gawk '{print $2}' \
+ | grep0 -v '^/dev/null$' \
+ | sed 's|^[^/]*/||' \
+ | sort -u
+}
+
+get_patch_output_files() {
local patch="$1"
- grep0 -E '^(--- |\+\+\+ )' "$patch" \
+ grep0 -E '^\+\+\+ ' "$patch" \
| gawk '{print $2}' \
+ | grep0 -v '^/dev/null$' \
| sed 's|^[^/]*/||' \
| sort -u
}
+get_patch_files() {
+ local patch="$1"
+
+ { get_patch_input_files "$patch"; get_patch_output_files "$patch"; } \
+ | sort -u
+}
+
# Make sure git re-stats the changed files
git_refresh() {
local patch="$1"
@@ -312,7 +330,7 @@ git_refresh() {
[[ ! -e "$SRC/.git" ]] && return
- get_patch_files "$patch" | mapfile -t files
+ get_patch_input_files "$patch" | mapfile -t files
(
cd "$SRC"
@@ -426,21 +444,23 @@ do_init() {
refresh_patch() {
local patch="$1"
local tmpdir="$PATCH_TMP_DIR"
- local files=()
+ local input_files=()
+ local output_files=()
rm -rf "$tmpdir"
mkdir -p "$tmpdir/a"
mkdir -p "$tmpdir/b"
# Get all source files affected by the patch
- get_patch_files "$patch" | mapfile -t files
+ get_patch_input_files "$patch" | mapfile -t input_files
+ get_patch_output_files "$patch" | mapfile -t output_files
# Copy orig source files to 'a'
- ( cd "$SRC" && echo "${files[@]}" | xargs cp --parents --target-directory="$tmpdir/a" )
+ ( cd "$SRC" && echo "${input_files[@]}" | xargs cp --parents --target-directory="$tmpdir/a" )
# Copy patched source files to 'b'
apply_patch "$patch" --recount
- ( cd "$SRC" && echo "${files[@]}" | xargs cp --parents --target-directory="$tmpdir/b" )
+ ( cd "$SRC" && echo "${output_files[@]}" | xargs cp --parents --target-directory="$tmpdir/b" )
revert_patch "$patch" --recount
# Diff 'a' and 'b' to make a clean patch
--
2.53.0
next prev parent reply other threads:[~2026-03-10 20:38 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-10 20:37 [PATCH v4 00/12] livepatch-klp-build: small fixups and enhancements Joe Lawrence
2026-03-10 20:37 ` [PATCH v4 01/12] objtool/klp: fix data alignment in __clone_symbol() Joe Lawrence
2026-03-10 20:37 ` [PATCH v4 02/12] objtool/klp: fix mkstemp() failure with long paths Joe Lawrence
2026-03-10 20:37 ` Joe Lawrence [this message]
2026-03-10 20:37 ` [PATCH v4 04/12] livepatch/klp-build: switch to GNU patch and recountdiff Joe Lawrence
2026-03-11 22:20 ` Song Liu
2026-03-10 20:37 ` [PATCH v4 05/12] livepatch/klp-build: add grep-override function Joe Lawrence
2026-03-10 20:37 ` [PATCH v4 06/12] livepatch/klp-build: add Makefile with check target Joe Lawrence
2026-03-10 20:37 ` [PATCH v4 07/12] livepatch/klp-build: fix shellcheck complaints Joe Lawrence
2026-03-10 20:37 ` [PATCH v4 08/12] livepatch/klp-build: improve short-circuit validation Joe Lawrence
2026-03-10 20:37 ` [PATCH v4 09/12] livepatch/klp-build: Fix inconsistent kernel version Joe Lawrence
2026-03-11 22:23 ` Song Liu
2026-03-10 20:37 ` [PATCH v4 10/12] livepatch/klp-build: provide friendlier error messages Joe Lawrence
2026-03-10 20:37 ` [PATCH v4 11/12] livepatch/klp-build: add terminal color output Joe Lawrence
2026-03-10 20:37 ` [PATCH v4 12/12] livepatch/klp-build: report patch validation fuzz Joe Lawrence
2026-03-11 22:22 ` Song Liu
2026-03-16 22:23 ` [PATCH v4 00/12] livepatch-klp-build: small fixups and enhancements Josh Poimboeuf
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260310203751.1479229-4-joe.lawrence@redhat.com \
--to=joe.lawrence@redhat.com \
--cc=jikos@kernel.org \
--cc=jpoimboe@kernel.org \
--cc=live-patching@vger.kernel.org \
--cc=mbenes@suse.cz \
--cc=pmladek@suse.com \
--cc=song@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox