Live Patching
 help / color / mirror / Atom feed
From: Song Liu <song@kernel.org>
To: live-patching@vger.kernel.org, linux-kselftest@vger.kernel.org
Cc: jpoimboe@kernel.org, jikos@kernel.org, mbenes@suse.cz,
	pmladek@suse.com, joe.lawrence@redhat.com, shuah@kernel.org,
	linux-kernel@vger.kernel.org, Song Liu <song@kernel.org>
Subject: [PATCH v2 02/12] klp-build: Process the patches before building the original kernel
Date: Wed, 28 Oct 2026 14:45:24 -0700	[thread overview]
Message-ID: <20261028214534.1919398-3-song@kernel.org> (raw)
In-Reply-To: <20261028214534.1919398-1-song@kernel.org>

klp-build validates the patches before building the original kernel,
but only combines them and adds #line directives after the build, which
applies and reverts them a second time.  Nothing in the second step
needs the original build, but the errors it finds, like patches with no
net effect, only show up after a full kernel build.

Do both in one step, before the build.  process_patches() checks for
patches to unsupported files, then applies the patches in order, which
also catches patches that don't apply and warns about those which apply
with fuzz, and combines them.

Suggested-by: Josh Poimboeuf <jpoimboe@kernel.org>
Assisted-by: Claude:claude-opus-5
Signed-off-by: Song Liu <song@kernel.org>
---
 scripts/livepatch/klp-build | 24 ++++++++----------------
 1 file changed, 8 insertions(+), 16 deletions(-)

diff --git a/scripts/livepatch/klp-build b/scripts/livepatch/klp-build
index a0bfc40093f9..28c3bf6b6418 100755
--- a/scripts/livepatch/klp-build
+++ b/scripts/livepatch/klp-build
@@ -395,11 +395,10 @@ revert_patch() {
 }
 
 apply_patches() {
-	local extra_args=("$@")
 	local patch
 
 	for patch in "${PATCHES[@]}"; do
-		apply_patch "$patch" "${extra_args[@]}"
+		apply_patch "$patch"
 	done
 }
 
@@ -413,12 +412,6 @@ revert_patches() {
 	APPLIED_PATCHES=()
 }
 
-validate_patches() {
-	check_unsupported_patches
-	apply_patches
-	revert_patches
-}
-
 do_init() {
 	# We're not yet smart enough to handle anything other than in-tree
 	# builds in pwd.
@@ -478,7 +471,7 @@ combine_patches() {
 	# Diff the orig source files against the patched ones in place to make a
 	# clean patch.  Use /dev/null for created and deleted files.
 	: > "$outfile"
-	apply_patches "--silent"
+	apply_patches
 	for file in "${files[@]}"; do
 		local old="$tmpdir/$file"
 		local new="$file"
@@ -504,12 +497,13 @@ combine_patches() {
 	revert_patches
 }
 
-# Combine the patches into $COMBINED_PATCH, and fix its lines so as not to
-# affect the __LINE__ macro for otherwise unchanged functions further down the
-# file.
+# Validate the patches, combine them into $COMBINED_PATCH, and fix its lines so
+# as not to affect the __LINE__ macro for otherwise unchanged functions further
+# down the file.
 process_patches() {
 	local tmp_patch="$TMP_DIR/tmp.patch"
 
+	check_unsupported_patches
 	combine_patches "$tmp_patch"
 	[[ ! -s "$tmp_patch" ]] && die "no changes detected"
 
@@ -889,8 +883,8 @@ process_args "$@"
 do_init
 
 if (( SHORT_CIRCUIT <= 2 )); then
-	status "Validating patch(es)"
-	validate_patches
+	status "Processing patch(es)"
+	process_patches
 fi
 
 if (( SHORT_CIRCUIT <= 1 )); then
@@ -902,8 +896,6 @@ if (( SHORT_CIRCUIT <= 1 )); then
 fi
 
 if (( SHORT_CIRCUIT <= 2 )); then
-	status "Processing patch(es)"
-	process_patches
 	apply_patch "$COMBINED_PATCH" "--silent"
 	status "Building patched kernel"
 	build_kernel "patched"
-- 
2.53.0-Meta


  parent reply	other threads:[~2026-10-28 21:45 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-28 21:45 [PATCH v2 00/12] klp-build: Fix dependent patches, add selftests Song Liu
2026-10-28 21:45 ` [PATCH v2 01/12] klp-build: Fix dependent patches in a series Song Liu
2026-10-28 21:45 ` Song Liu [this message]
2026-10-28 21:45 ` [PATCH v2 03/12] klp-build: Move patch processing to klp-prepare-patch Song Liu
2026-10-28 21:45 ` [PATCH v2 04/12] selftests/livepatch: Add tests for klp-prepare-patch Song Liu
2026-10-28 21:45 ` [PATCH v2 05/12] selftests/livepatch: Test klp-prepare-patch with dependent patches Song Liu
2026-10-28 21:45 ` [PATCH v2 06/12] selftests/livepatch: Test klp-prepare-patch with independent patches Song Liu
2026-10-28 21:45 ` [PATCH v2 07/12] selftests/livepatch: Test klp-prepare-patch with patches which cancel out Song Liu
2026-10-28 21:45 ` [PATCH v2 08/12] selftests/livepatch: Test klp-prepare-patch with created and deleted files Song Liu
2026-10-28 21:45 ` [PATCH v2 09/12] selftests/livepatch: Test where klp-prepare-patch adds #line directives Song Liu
2026-10-28 21:45 ` [PATCH v2 10/12] selftests/livepatch: Test klp-prepare-patch with unsupported files Song Liu
2026-10-28 21:45 ` [PATCH v2 11/12] selftests/livepatch: Test klp-prepare-patch with patches which don't apply Song Liu
2026-10-28 21:45 ` [PATCH v2 12/12] selftests/livepatch: Test klp-prepare-patch with offset and fuzz Song Liu

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=20261028214534.1919398-3-song@kernel.org \
    --to=song@kernel.org \
    --cc=jikos@kernel.org \
    --cc=joe.lawrence@redhat.com \
    --cc=jpoimboe@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=live-patching@vger.kernel.org \
    --cc=mbenes@suse.cz \
    --cc=pmladek@suse.com \
    --cc=shuah@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