Re: [PATCH v2 59/62] livepatch/klp-build: Introduce klp-build script for generating livepatch modules
From: Josh Poimboeuf
Date: Tue Jun 10 2025 - 12:10:28 EST
On Mon, Jun 09, 2025 at 10:34:43PM -0400, Joe Lawrence wrote:
> On Fri, May 09, 2025 at 01:17:23PM -0700, Josh Poimboeuf wrote:
> > +revert_patch() {
> > + local patch="$1"
> > + shift
> > + local extra_args=("$@")
> > + local tmp=()
> > +
> > + ( cd "$SRC" && git apply --reverse "${extra_args[@]}" "$patch" )
> > + git_refresh "$patch"
> > +
> > + for p in "${APPLIED_PATCHES[@]}"; do
> > + [[ "$p" == "$patch" ]] && continue
> > + tmp+=("$p")
> > + done
> > +
> > + APPLIED_PATCHES=("${tmp[@]}")
> > +}
>
> You may consider a slight adjustment to revert_patch() to handle git
> format-patch generated .patches? The reversal trips up on the git
> version trailer:
>
> warning: recount: unexpected line: 2.47.1
Thanks. Looks like the normal apply with --recount also trips it up. I
have the below:
diff --git a/scripts/livepatch/klp-build b/scripts/livepatch/klp-build
index f689a4d143c6..1ff5e66f4c53 100755
--- a/scripts/livepatch/klp-build
+++ b/scripts/livepatch/klp-build
@@ -337,7 +337,14 @@ apply_patch() {
[[ ! -f "$patch" ]] && die "$patch doesn't exist"
- ( cd "$SRC" && git apply "${extra_args[@]}" "$patch" )
+ (
+ cd "$SRC"
+
+ # The sed removes the version signature from 'git format-patch',
+ # otherwise 'git apply --recount' warns.
+ sed -n '/^-- /q;p' "$patch" |
+ git apply "${extra_args[@]}"
+ )
APPLIED_PATCHES+=("$patch")
}
@@ -348,7 +355,12 @@ revert_patch() {
local extra_args=("$@")
local tmp=()
- ( cd "$SRC" && git apply --reverse "${extra_args[@]}" "$patch" )
+ (
+ cd "$SRC"
+
+ sed -n '/^-- /q;p' "$patch" |
+ git apply --reverse "${extra_args[@]}"
+ )
git_refresh "$patch"
for p in "${APPLIED_PATCHES[@]}"; do